Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing properties of networks.CreateOpts #2843

Open
pierreprinetti opened this issue Dec 5, 2023 · 11 comments
Open

Missing properties of networks.CreateOpts #2843

pierreprinetti opened this issue Dec 5, 2023 · 11 comments

Comments

@pierreprinetti
Copy link
Contributor

pierreprinetti commented Dec 5, 2023

Properties available in the API for create network and unavailable in networks.CreateOpts:

  • provider:network_type
  • provider:physical_network
  • provider:segmentation_id
  • is_default

UPDATE: I have removed from this list the fields I could add with the extensions, as pointed out by @kayrus

@kayrus
Copy link
Contributor

kayrus commented Dec 5, 2023

@pierreprinetti don't these options available through the extensions?

gophercloud$ ls -d openstack/networking/v2/extensions/*
openstack/networking/v2/extensions/agents                   openstack/networking/v2/extensions/portsbinding
openstack/networking/v2/extensions/attributestags           openstack/networking/v2/extensions/portsecurity
openstack/networking/v2/extensions/bgp                      openstack/networking/v2/extensions/provider
openstack/networking/v2/extensions/delegate.go              openstack/networking/v2/extensions/qos
openstack/networking/v2/extensions/dns                      openstack/networking/v2/extensions/quotas
openstack/networking/v2/extensions/external                 openstack/networking/v2/extensions/rbacpolicies
openstack/networking/v2/extensions/extradhcpopts            openstack/networking/v2/extensions/security
openstack/networking/v2/extensions/fwaas                    openstack/networking/v2/extensions/subnetpools
openstack/networking/v2/extensions/fwaas_v2                 openstack/networking/v2/extensions/testing
openstack/networking/v2/extensions/layer3                   openstack/networking/v2/extensions/trunk_details
openstack/networking/v2/extensions/lbaas                    openstack/networking/v2/extensions/trunks
openstack/networking/v2/extensions/lbaas_v2                 openstack/networking/v2/extensions/vlantransparent
openstack/networking/v2/extensions/mtu                      openstack/networking/v2/extensions/vpnaas
openstack/networking/v2/extensions/networkipavailabilities

https://github.com/gophercloud/gophercloud/blob/dca8ae6b2e5454d697de38cbd72faf0c8f5cb11d/docs/FAQ.md#custom-response-objects

The same applies for #2844

@pierreprinetti
Copy link
Contributor Author

... you are showing me an entire new world to explore

@pierreprinetti
Copy link
Contributor Author

hmm things get ugly pretty quickly with embedding. Gotta find a better way to combine those

		createOpts := dns.NetworkCreateOptsExt{
			CreateOptsBuilder: mtu.CreateOptsExt{
				CreateOptsBuilder: networks.CreateOpts{
					AdminStateUp:          resource.Spec.Resource.AdminStateUp,
					Name:                  resource.Spec.Resource.Name,
					Description:           resource.Spec.Resource.Description,
					Shared:                resource.Spec.Resource.Shared,
					TenantID:              resource.Spec.Resource.TenantID,
					ProjectID:             resource.Spec.Resource.ProjectID,
					AvailabilityZoneHints: resource.Spec.Resource.AvailabilityZoneHints,
				},
				MTU: int(resource.Spec.Resource.MTU),
			},
			DNSDomain: resource.Spec.Resource.DNSDomain,
		}

@pierreprinetti
Copy link
Contributor Author

OK I'm left with these four:

  • provider:network_type
  • provider:physical_network
  • provider:segmentation_id
  • is_default

The provider package exposes the provider fields under segments, but not at the network level AFAIK.

@kayrus
Copy link
Contributor

kayrus commented Dec 5, 2023

@pierreprinetti you may refer to this comment #2752 (comment):)
I guess the only element left is is_default. Not sure where should it go to, directly into the network package, or extension package.

@pierreprinetti
Copy link
Contributor Author

pierreprinetti commented Dec 5, 2023

Interesting. Well, that leaves me with:

type NetworkCreateOpts struct {
	AdminStateUp            *bool
	Name                    string
	Description             string
	Shared                  *bool
	TenantID                string
	ProjectID               string
	AvailabilityZoneHints   []string
	MTU                     int
	DNSDomain               string
	PortSecurityEnabled     *bool
	QoSPolicyID             string
	External                *bool
	ProviderPhysicalNetwork string
	ProviderNetworkType     string
	ProviderSegmentationID  int
	Segments                []provider.Segment
	VLANTransparent         *bool
	IsDefault               *bool
}

func (opts *NetworkCreateOpts) ToNetworkCreateMap() (map[string]interface{}, error) {
	segment := provider.Segment{
		PhysicalNetwork: opts.ProviderPhysicalNetwork,
		NetworkType:     opts.ProviderNetworkType,
		SegmentationID:  opts.ProviderSegmentationID,
	}
	base, err := vlantransparent.CreateOptsExt{
		CreateOptsBuilder: provider.CreateOptsExt{
			CreateOptsBuilder: external.CreateOptsExt{
				CreateOptsBuilder: policies.NetworkCreateOptsExt{
					CreateOptsBuilder: portsecurity.NetworkCreateOptsExt{
						CreateOptsBuilder: dns.NetworkCreateOptsExt{
							CreateOptsBuilder: mtu.CreateOptsExt{
								CreateOptsBuilder: networks.CreateOpts{
									AdminStateUp:          opts.AdminStateUp,
									Name:                  opts.Name,
									Description:           opts.Description,
									Shared:                opts.Shared,
									TenantID:              opts.TenantID,
									ProjectID:             opts.ProjectID,
									AvailabilityZoneHints: opts.AvailabilityZoneHints,
								},
								MTU: opts.MTU,
							},
							DNSDomain: opts.DNSDomain,
						},
						PortSecurityEnabled: opts.PortSecurityEnabled,
					},
					QoSPolicyID: opts.QoSPolicyID,
				},
				External: opts.External,
			},
			Segments: append([]provider.Segment{segment}, opts.Segments...),
		},
		VLANTransparent: opts.VLANTransparent,
	}.ToNetworkCreateMap()
	if err != nil {
		return nil, err
	}

	if opts.IsDefault != nil {
		providerMap := base["network"].(map[string]interface{})
		providerMap["is_default"] = opts.IsDefault
	}

	return base, nil
}

Thanks!

@pierreprinetti
Copy link
Contributor Author

Incidentally, I wonder if there is any advantage whatsoever in keeping these fields away from the main networks.CreateOpts struct.

@kayrus
Copy link
Contributor

kayrus commented Dec 5, 2023

I think it's done due to neutron pluggable extensions (can be listed via https://github.com/gophercloud/gophercloud/blob/master/openstack/networking/v2/extensions/delegate.go). E.g. an ability to explicitly POST/PUT nil to some API endpoints' objects...

@dulek
Copy link
Contributor

dulek commented Dec 6, 2023

Yep, the extensions might be disabled, so the fields might be unavailable.

@pierreprinetti
Copy link
Contributor Author

An aggressive use of omitempty (or custom marshaling) would probably allow users to use an hypothetical full object, while only filling in the fields their cloud supports.
Or am I missing something?

@dulek
Copy link
Contributor

dulek commented Dec 6, 2023

An aggressive use of omitempty (or custom marshaling) would probably allow users to use an hypothetical full object, while only filling in the fields their cloud supports. Or am I missing something?

I do think this would be doable on CreateOpts side. I'm not so sure on the actual representations of the resources - golang would initialize default values and users would have hard time telling if field is unset or just unsupported by the cloud.

On the other hand they now need to do extension discovery anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants