From a3e31a06234fb9b38c74c46e32b0ab63b3ba0b1a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Feb 2024 13:12:30 +0000 Subject: [PATCH 01/16] feat: Add Equinix Metal Load Balancer support - Add internal package for interacting with Equinix Metal Load Balancer API - packetcluster_controller creates load balancer and listener port and stores their ids in packetCluster annotations. - packetmachine_controller creates an origin pool and origin port for each machine and stores their IDs in the packetMachine annotations. - CPEMLBConfig and EMLBID added to the packet cloud client package to be able to provide a config for the CPEM loadBalancer setting in the emlb templates. - Memory request for the Cluster API Provider Packet controller increased to 300Mi to avoid OOMing while debugging. - EMLB added as a valid VIPManager enum type. Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- .golangci.yml | 5 +- api/v1beta1/packetcluster_types.go | 6 +- clusterctl-settings.json | 2 +- ...cture.cluster.x-k8s.io_packetclusters.yaml | 259 +++---- config/manager/manager.yaml | 4 +- controllers/packetcluster_controller.go | 81 ++- controllers/packetmachine_controller.go | 39 +- internal/emlb/emlb.go | 436 +++++++++++ internal/emlb/emlb_test.go | 67 ++ internal/emlb/token_exchanger.go | 58 ++ internal/lbaas/v1/.gitignore | 24 + internal/lbaas/v1/.openapi-generator-ignore | 23 + internal/lbaas/v1/.openapi-generator/FILES | 75 ++ internal/lbaas/v1/.openapi-generator/VERSION | 1 + internal/lbaas/v1/api_load_balancers.go | 328 +++++++++ internal/lbaas/v1/api_origins.go | 328 +++++++++ internal/lbaas/v1/api_pools.go | 543 ++++++++++++++ internal/lbaas/v1/api_ports.go | 547 ++++++++++++++ internal/lbaas/v1/api_projects.go | 453 ++++++++++++ internal/lbaas/v1/client.go | 686 ++++++++++++++++++ internal/lbaas/v1/configuration.go | 217 ++++++ internal/lbaas/v1/model_load_balancer.go | 403 ++++++++++ .../v1/model_load_balancer_collection.go | 144 ++++ .../lbaas/v1/model_load_balancer_create.go | 232 ++++++ .../lbaas/v1/model_load_balancer_location.go | 269 +++++++ internal/lbaas/v1/model_load_balancer_pool.go | 404 +++++++++++ .../v1/model_load_balancer_pool_collection.go | 144 ++++ .../v1/model_load_balancer_pool_create.go | 249 +++++++ ...odel_load_balancer_pool_create_protocol.go | 115 +++ .../v1/model_load_balancer_pool_origin.go | 348 +++++++++ ...el_load_balancer_pool_origin_collection.go | 144 ++++ .../model_load_balancer_pool_origin_create.go | 260 +++++++ ...l_load_balancer_pool_origin_port_number.go | 115 +++ .../model_load_balancer_pool_origin_update.go | 267 +++++++ .../v1/model_load_balancer_pool_protocol.go | 110 +++ .../v1/model_load_balancer_pool_short.go | 270 +++++++ .../v1/model_load_balancer_pool_update.go | 419 +++++++++++ internal/lbaas/v1/model_load_balancer_port.go | 383 ++++++++++ .../v1/model_load_balancer_port_collection.go | 144 ++++ .../v1/model_load_balancer_port_create.go | 212 ++++++ .../v1/model_load_balancer_port_update.go | 268 +++++++ .../lbaas/v1/model_load_balancer_short.go | 235 ++++++ .../lbaas/v1/model_load_balancer_update.go | 268 +++++++ internal/lbaas/v1/model_provider.go | 183 +++++ .../v1/model_resource_created_response.go | 268 +++++++ internal/lbaas/v1/response.go | 47 ++ internal/lbaas/v1/utils.go | 347 +++++++++ pkg/cloud/packet/client.go | 10 + templates/cluster-template-emlb.yaml | 243 +++++++ test/e2e/config/packet-ci.yaml | 14 + test/e2e/data/shared/v1beta1/metadata.yaml | 9 +- tilt-provider.json | 2 +- 52 files changed, 10525 insertions(+), 183 deletions(-) create mode 100644 internal/emlb/emlb.go create mode 100644 internal/emlb/emlb_test.go create mode 100644 internal/emlb/token_exchanger.go create mode 100644 internal/lbaas/v1/.gitignore create mode 100644 internal/lbaas/v1/.openapi-generator-ignore create mode 100644 internal/lbaas/v1/.openapi-generator/FILES create mode 100644 internal/lbaas/v1/.openapi-generator/VERSION create mode 100644 internal/lbaas/v1/api_load_balancers.go create mode 100644 internal/lbaas/v1/api_origins.go create mode 100644 internal/lbaas/v1/api_pools.go create mode 100644 internal/lbaas/v1/api_ports.go create mode 100644 internal/lbaas/v1/api_projects.go create mode 100644 internal/lbaas/v1/client.go create mode 100644 internal/lbaas/v1/configuration.go create mode 100644 internal/lbaas/v1/model_load_balancer.go create mode 100644 internal/lbaas/v1/model_load_balancer_collection.go create mode 100644 internal/lbaas/v1/model_load_balancer_create.go create mode 100644 internal/lbaas/v1/model_load_balancer_location.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_collection.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_create.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_create_protocol.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_origin.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_origin_collection.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_origin_create.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_origin_port_number.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_origin_update.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_protocol.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_short.go create mode 100644 internal/lbaas/v1/model_load_balancer_pool_update.go create mode 100644 internal/lbaas/v1/model_load_balancer_port.go create mode 100644 internal/lbaas/v1/model_load_balancer_port_collection.go create mode 100644 internal/lbaas/v1/model_load_balancer_port_create.go create mode 100644 internal/lbaas/v1/model_load_balancer_port_update.go create mode 100644 internal/lbaas/v1/model_load_balancer_short.go create mode 100644 internal/lbaas/v1/model_load_balancer_update.go create mode 100644 internal/lbaas/v1/model_provider.go create mode 100644 internal/lbaas/v1/model_resource_created_response.go create mode 100644 internal/lbaas/v1/response.go create mode 100644 internal/lbaas/v1/utils.go create mode 100644 templates/cluster-template-emlb.yaml diff --git a/.golangci.yml b/.golangci.yml index 4018d1461..10bfb97c9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -164,7 +164,6 @@ linters-settings: alias: infraexpv1 nolintlint: allow-unused: false - allow-leading-space: false require-specific: true revive: rules: @@ -314,3 +313,7 @@ issues: - gocritic text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop" path: _test\.go + - linters: + - bodyclose + path: .*(internal)/emlb/emlb.go + text: "response body must be closed" diff --git a/api/v1beta1/packetcluster_types.go b/api/v1beta1/packetcluster_types.go index 504977a60..cba2ca62d 100644 --- a/api/v1beta1/packetcluster_types.go +++ b/api/v1beta1/packetcluster_types.go @@ -26,7 +26,7 @@ const ( NetworkInfrastructureReadyCondition clusterv1.ConditionType = "NetworkInfrastructureReady" ) -// VIPManagerType describes if the VIP will be managed by CPEM or kube-vip. +// VIPManagerType describes if the VIP will be managed by CPEM or kube-vip or Equinix Metal Load Balancer. type VIPManagerType string // PacketClusterSpec defines the desired state of PacketCluster. @@ -46,9 +46,9 @@ type PacketClusterSpec struct { // +optional ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"` - // VIPManager represents whether this cluster uses CPEM or kube-vip to + // VIPManager represents whether this cluster uses CPEM or kube-vip or Equinix Metal Load Balancer to // manage its vip for the api server IP - // +kubebuilder:validation:Enum=CPEM;KUBE_VIP + // +kubebuilder:validation:Enum=CPEM;KUBE_VIP;EMLB // +kubebuilder:default:=CPEM VIPManager VIPManagerType `json:"vipManager"` } diff --git a/clusterctl-settings.json b/clusterctl-settings.json index 5a71401b4..a8117075e 100644 --- a/clusterctl-settings.json +++ b/clusterctl-settings.json @@ -2,7 +2,7 @@ "name": "infrastructure-packet", "config": { "componentsFile": "infrastructure-components.yaml", - "nextVersion": "v0.6.99" + "nextVersion": "v0.8.99" } } diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_packetclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_packetclusters.yaml index f6283277b..48eb07123 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_packetclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_packetclusters.yaml @@ -9,141 +9,146 @@ spec: group: infrastructure.cluster.x-k8s.io names: categories: - - cluster-api + - cluster-api kind: PacketCluster listKind: PacketClusterList plural: packetclusters shortNames: - - pcl + - pcl singular: packetcluster scope: Namespaced versions: - - additionalPrinterColumns: - - description: Cluster to which this PacketCluster belongs - jsonPath: .metadata.labels.cluster\.x-k8s\.io/cluster-name - name: Cluster - type: string - - description: PacketCluster ready status - jsonPath: .status.ready - name: Ready - type: string - name: v1beta1 - schema: - openAPIV3Schema: - description: PacketCluster is the Schema for the packetclusters API. - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: PacketClusterSpec defines the desired state of PacketCluster. - properties: - controlPlaneEndpoint: - description: ControlPlaneEndpoint represents the endpoint used to - communicate with the control plane. - properties: - host: - description: The hostname on which the API server is serving. - type: string - port: - description: The port on which the API server is serving. - format: int32 - type: integer - required: - - host - - port - type: object - facility: - description: Facility represents the Packet facility for this cluster - type: string - metro: - description: Metro represents the Packet metro for this cluster - type: string - projectID: - description: ProjectID represents the Packet Project where this cluster - will be placed into - type: string - vipManager: - default: CPEM - description: |- - VIPManager represents whether this cluster uses CPEM or kube-vip to - manage its vip for the api server IP - enum: - - CPEM - - KUBE_VIP - type: string - required: - - projectID - - vipManager - type: object - status: - description: PacketClusterStatus defines the observed state of PacketCluster. - properties: - conditions: - description: Conditions defines current service state of the PacketCluster. - items: - description: Condition defines an observation of a Cluster API resource - operational state. + - additionalPrinterColumns: + - description: Cluster to which this PacketCluster belongs + jsonPath: .metadata.labels.cluster\.x-k8s\.io/cluster-name + name: Cluster + type: string + - description: PacketCluster ready status + jsonPath: .status.ready + name: Ready + type: string + name: v1beta1 + schema: + openAPIV3Schema: + description: PacketCluster is the Schema for the packetclusters API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: PacketClusterSpec defines the desired state of PacketCluster. + properties: + controlPlaneEndpoint: + description: + ControlPlaneEndpoint represents the endpoint used to + communicate with the control plane. properties: - lastTransitionTime: - description: |- - Last time the condition transitioned from one status to another. - This should be when the underlying condition changed. If that is not known, then using the time when - the API field changed is acceptable. - format: date-time - type: string - message: - description: |- - A human readable message indicating details about the transition. - This field may be empty. - type: string - reason: - description: |- - The reason for the condition's last transition in CamelCase. - The specific API may choose whether or not this field is considered a guaranteed API. - This field may not be empty. - type: string - severity: - description: |- - Severity provides an explicit classification of Reason code, so the users or machines can immediately - understand the current situation and act accordingly. - The Severity field MUST be set only when Status=False. - type: string - status: - description: Status of the condition, one of True, False, Unknown. - type: string - type: - description: |- - Type of condition in CamelCase or in foo.example.com/CamelCase. - Many .condition.type values are consistent across resources like Available, but because arbitrary conditions - can be useful (see .node.status.conditions), the ability to deconflict is important. + host: + description: The hostname on which the API server is serving. type: string + port: + description: The port on which the API server is serving. + format: int32 + type: integer required: - - lastTransitionTime - - status - - type + - host + - port type: object - type: array - ready: - description: Ready denotes that the cluster (infrastructure) is ready. - type: boolean - type: object - type: object - served: true - storage: true - subresources: - status: {} + facility: + description: Facility represents the Packet facility for this cluster + type: string + metro: + description: Metro represents the Packet metro for this cluster + type: string + projectID: + description: + ProjectID represents the Packet Project where this cluster + will be placed into + type: string + vipManager: + default: CPEM + description: + VIPManager represents whether this cluster uses CPEM + or kube-vip or Equinix Metal Load Balancer to manage its vip for + the api server IP + enum: + - CPEM + - KUBE_VIP + - EMLB + type: string + required: + - projectID + - vipManager + type: object + status: + description: PacketClusterStatus defines the observed state of PacketCluster. + properties: + conditions: + description: Conditions defines current service state of the PacketCluster. + items: + description: + Condition defines an observation of a Cluster API resource + operational state. + properties: + lastTransitionTime: + description: |- + Last time the condition transitioned from one status to another. + This should be when the underlying condition changed. If that is not known, then using the time when + the API field changed is acceptable. + format: date-time + type: string + message: + description: |- + A human readable message indicating details about the transition. + This field may be empty. + type: string + reason: + description: |- + The reason for the condition's last transition in CamelCase. + The specific API may choose whether or not this field is considered a guaranteed API. + This field may not be empty. + type: string + severity: + description: |- + Severity provides an explicit classification of Reason code, so the users or machines can immediately + understand the current situation and act accordingly. + The Severity field MUST be set only when Status=False. + type: string + status: + description: Status of the condition, one of True, False, Unknown. + type: string + type: + description: |- + Type of condition in CamelCase or in foo.example.com/CamelCase. + Many .condition.type values are consistent across resources like Available, but because arbitrary conditions + can be useful (see .node.status.conditions), the ability to deconflict is important. + type: string + required: + - lastTransitionTime + - status + - type + type: object + type: array + ready: + description: Ready denotes that the cluster (infrastructure) is ready. + type: boolean + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index c515e14cd..7d928b154 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -42,10 +42,10 @@ spec: port: healthz resources: limits: - memory: 200Mi + memory: 300Mi requests: cpu: 100m - memory: 200Mi + memory: 300Mi securityContext: allowPrivilegeEscalation: false capabilities: diff --git a/controllers/packetcluster_controller.go b/controllers/packetcluster_controller.go index 1e89bd720..d615fe8d7 100644 --- a/controllers/packetcluster_controller.go +++ b/controllers/packetcluster_controller.go @@ -34,6 +34,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/handler" infrav1 "sigs.k8s.io/cluster-api-provider-packet/api/v1beta1" + "sigs.k8s.io/cluster-api-provider-packet/internal/emlb" packet "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet" "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet/scope" ) @@ -114,49 +115,63 @@ func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterSc packetCluster := clusterScope.PacketCluster - ipReserv, err := r.PacketClient.GetIPByClusterIdentifier(ctx, clusterScope.Namespace(), clusterScope.Name(), packetCluster.Spec.ProjectID) switch { - case errors.Is(err, packet.ErrControlPlanEndpointNotFound): - // Parse metro and facility from the cluster spec - var metro, facility string - - facility = packetCluster.Spec.Facility - metro = packetCluster.Spec.Metro - - // If both specified, metro takes precedence over facility - if metro != "" { - facility = "" + case packetCluster.Spec.VIPManager == "EMLB": + if !packetCluster.Spec.ControlPlaneEndpoint.IsValid() { + // Create new EMLB object + lb := emlb.NewEMLB(r.PacketClient.GetConfig().DefaultHeader["X-Auth-Token"], packetCluster.Spec.ProjectID, packetCluster.Spec.Metro) + + if err := lb.ReconcileLoadBalancer(ctx, clusterScope); err != nil { + log.Error(err, "Error Reconciling EMLB") + return err + } } - - // There is not an ElasticIP with the right tags, at this point we can create one - ip, err := r.PacketClient.CreateIP(ctx, clusterScope.Namespace(), clusterScope.Name(), packetCluster.Spec.ProjectID, facility, metro) - if err != nil { - log.Error(err, "error reserving an ip") + case packetCluster.Spec.VIPManager == "KUBE_VIP": + log.Info("KUBE_VIP VIPManager Detected") + if err := r.PacketClient.EnableProjectBGP(ctx, packetCluster.Spec.ProjectID); err != nil { + log.Error(err, "error enabling bgp for project") return err } - clusterScope.PacketCluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{ - Host: ip.To4().String(), - Port: 6443, - } - case err != nil: - log.Error(err, "error getting cluster IP") - return err - default: - // If there is an ElasticIP with the right tag just use it again - clusterScope.PacketCluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{ - Host: ipReserv.GetAddress(), - Port: 6443, - } } - if clusterScope.PacketCluster.Spec.VIPManager == "KUBE_VIP" { - if err := r.PacketClient.EnableProjectBGP(ctx, packetCluster.Spec.ProjectID); err != nil { - log.Error(err, "error enabling bgp for project") + if packetCluster.Spec.VIPManager != "EMLB" { + ipReserv, err := r.PacketClient.GetIPByClusterIdentifier(ctx, clusterScope.Namespace(), clusterScope.Name(), packetCluster.Spec.ProjectID) + switch { + case errors.Is(err, packet.ErrControlPlanEndpointNotFound): + // Parse metro and facility from the cluster spec + var metro, facility string + + facility = packetCluster.Spec.Facility + metro = packetCluster.Spec.Metro + + // If both specified, metro takes precedence over facility + if metro != "" { + facility = "" + } + + // There is not an ElasticIP with the right tags, at this point we can create one + ip, err := r.PacketClient.CreateIP(ctx, clusterScope.Namespace(), clusterScope.Name(), packetCluster.Spec.ProjectID, facility, metro) + if err != nil { + log.Error(err, "error reserving an ip") + return err + } + packetCluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{ + Host: ip.To4().String(), + Port: 6443, + } + case err != nil: + log.Error(err, "error getting cluster IP") return err + default: + // If there is an ElasticIP with the right tag just use it again + packetCluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{ + Host: ipReserv.GetAddress(), + Port: 6443, + } } } - clusterScope.PacketCluster.Status.Ready = true + packetCluster.Status.Ready = true conditions.MarkTrue(packetCluster, infrav1.NetworkInfrastructureReadyCondition) return nil diff --git a/controllers/packetmachine_controller.go b/controllers/packetmachine_controller.go index c5e887e53..3f49b4960 100644 --- a/controllers/packetmachine_controller.go +++ b/controllers/packetmachine_controller.go @@ -43,6 +43,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" infrav1 "sigs.k8s.io/cluster-api-provider-packet/api/v1beta1" + "sigs.k8s.io/cluster-api-provider-packet/internal/emlb" packet "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet" "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet/scope" clog "sigs.k8s.io/cluster-api/util/log" @@ -348,12 +349,16 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s // when a node is a control plane node we need the elastic IP // to template out the kube-vip deployment if machineScope.IsControlPlane() { - controlPlaneEndpoint, _ = r.PacketClient.GetIPByClusterIdentifier( - ctx, - machineScope.Cluster.Namespace, - machineScope.Cluster.Name, - machineScope.PacketCluster.Spec.ProjectID) - if machineScope.PacketCluster.Spec.VIPManager == "CPEM" { + var controlPlaneEndpointAddress string + var cpemLBConfig string + var emlbID string + switch { + case machineScope.PacketCluster.Spec.VIPManager == "CPEM": + controlPlaneEndpoint, _ = r.PacketClient.GetIPByClusterIdentifier( + ctx, + machineScope.Cluster.Namespace, + machineScope.Cluster.Name, + machineScope.PacketCluster.Spec.ProjectID) if len(controlPlaneEndpoint.Assignments) == 0 { a := corev1.NodeAddress{ Type: corev1.NodeExternalIP, @@ -361,10 +366,16 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s } addrs = append(addrs, a) } + controlPlaneEndpointAddress = controlPlaneEndpoint.GetAddress() + case machineScope.PacketCluster.Spec.VIPManager == "EMLB": + controlPlaneEndpointAddress = machineScope.Cluster.Spec.ControlPlaneEndpoint.Host + cpemLBConfig = "emlb:///" + machineScope.PacketCluster.Spec.Metro + emlbID = machineScope.PacketCluster.Annotations["equinix.com/loadbalancerID"] } - createDeviceReq.ControlPlaneEndpoint = controlPlaneEndpoint.GetAddress() + createDeviceReq.ControlPlaneEndpoint = controlPlaneEndpointAddress + createDeviceReq.CPEMLBConfig = cpemLBConfig + createDeviceReq.EMLBID = emlbID } - dev, err = r.PacketClient.NewDevice(ctx, createDeviceReq) switch { @@ -413,7 +424,8 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s case infrav1.PacketResourceStatusRunning: log.Info("Machine instance is active", "instance-id", machineScope.ProviderID()) - if machineScope.PacketCluster.Spec.VIPManager == "CPEM" { + switch { + case machineScope.PacketCluster.Spec.VIPManager == "CPEM": controlPlaneEndpoint, _ = r.PacketClient.GetIPByClusterIdentifier( ctx, machineScope.Cluster.Namespace, @@ -428,6 +440,15 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s return ctrl.Result{RequeueAfter: time.Second * 20}, nil } } + case machineScope.PacketCluster.Spec.VIPManager == "EMLB": + if machineScope.IsControlPlane() { + // Create new EMLB object + lb := emlb.NewEMLB(r.PacketClient.GetConfig().DefaultHeader["X-Auth-Token"], machineScope.PacketCluster.Spec.ProjectID, machineScope.PacketCluster.Spec.Metro) + + if err := lb.ReconcileVIPOrigin(ctx, machineScope, deviceAddr); err != nil { + return ctrl.Result{}, err + } + } } machineScope.SetReady() diff --git a/internal/emlb/emlb.go b/internal/emlb/emlb.go new file mode 100644 index 000000000..27b57bd5e --- /dev/null +++ b/internal/emlb/emlb.go @@ -0,0 +1,436 @@ +// Package emlb manages authentication to the Equinix Metal Load Balancer service. +package emlb + +import ( + "context" + "fmt" + "net" + "net/http" + "os" + "reflect" + "strconv" + + corev1 "k8s.io/api/core/v1" + lbaas "sigs.k8s.io/cluster-api-provider-packet/internal/lbaas/v1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + ctrl "sigs.k8s.io/controller-runtime" + + "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet/scope" +) + +const ( + // providerID is the provider id key used to talk to the Load Balancer as a Service API. + providerID = "loadpvd-gOB_-byp5ebFo7A3LHv2B" + // loadBalancerIDAnnotation is the anotation key representing the ID of the allocated LoadBalancer for a PacketCluster. + loadBalancerIDAnnotation = "equinix.com/loadbalancerID" + // loadBalancerPortNumberAnnotation is the anotation key representing the allocated listner port number for a PacketCluster. + loadBalancerPortNumberAnnotation = "equinix.com/loadbalancerPortNumber" + // loadBalancerMetroAnnotation is the anotation key representing the metro of the loadbalancer for a PacketCluster. + loadBalancerMetroAnnotation = "equinix.com/loadbalancerMetro" + // loadBalancerVIPPort is the port number of the API Server. + loadBalancerVIPPort = 6443 // TODO Change this to a env variable + // loadBalancerPoolIDAnnotation is the anotation key representing the ID of the origin pool for a PacketCluster. + loadBalancerPoolIDAnnotation = "equinix.com/loadbalancerpoolID" + // loadBalancerPoolOriginIDAnnotation is the anotation key representing the origin ID of a PacketMachine. + loadBalancerOriginIDAnnotation = "equinix.com/loadbalanceroriginID" +) + +var lbMetros = map[string]string{ + "am": "lctnloc-1ttCRz-P8aY0rda9BxOiL", + "da": "lctnloc--uxs0GLeAELHKV8GxO_AI", + "dc": "lctnloc-1lJjVT6Zp_Fs4UpW5LWQu", + "ny": "lctnloc-Vy-1Qpw31mPi6RJQwVf9A", + "sg": "lctnloc-AxCxpIrNUaaoGBkM02uuw", + "sv": "lctnloc-H5rl2M2VL5dcFmdxhbEKx", +} + +// Pools is a map of a port to Targets. +type Pools map[int32][]Target + +// Target is a struct containing an IP address and a port. +type Target struct { + IP string + Port int32 +} + +// EMLB is a client object for talking to the Equinix Metal Load Balancer API. +type EMLB struct { + client *lbaas.APIClient + metro string + projectID string + tokenExchanger *TokenExchanger +} + +// NewEMLB creates a new Equinix Metal Load Balancer API client object. +func NewEMLB(metalAPIKey, projectID, metro string) *EMLB { + manager := &EMLB{} + emlbConfig := lbaas.NewConfiguration() + emlbConfig.Debug = checkDebugEnabled() + + manager.client = lbaas.NewAPIClient(emlbConfig) + manager.tokenExchanger = &TokenExchanger{ + metalAPIKey: metalAPIKey, + client: manager.client.GetConfig().HTTPClient, + } + manager.projectID = projectID + manager.metro = metro + + return manager +} + +// ReconcileLoadBalancer creates a new Equinix Metal Load Balancer. +func (e *EMLB) ReconcileLoadBalancer(ctx context.Context, clusterScope *scope.ClusterScope) error { + log := ctrl.LoggerFrom(ctx) + + packetCluster := clusterScope.PacketCluster + clusterName := packetCluster.Name + + // See if the cluster already has an EMLB ID in its packetCluster annotations + lbID, exists := packetCluster.Annotations[loadBalancerIDAnnotation] + if !exists { + lbID = "" + } + + log.Info("Reconciling EMLB", "Cluster Metro", e.metro, "Cluster Name", clusterName, "Project ID", e.projectID, "Load Balancer ID", lbID) + + // Attempt to create the load balancer + lb, lbPort, err := e.ensureLoadBalancer(ctx, lbID, getResourceName(clusterName, "capp-vip"), loadBalancerVIPPort) + if err != nil { + log.Error(err, "Ensure Load Balancer failed.") + return err + } + + log.Info("EMLB ensured", "EMLB IP", lb.GetIps()[0], "EMLB ID", lb.GetId(), "EMLB Port", lbPort.GetNumber()) + + // Set the ControlPlaneEndpoint field on the PacketCluster object. + packetCluster.Spec.ControlPlaneEndpoint = clusterv1.APIEndpoint{ + Host: lb.GetIps()[0], + Port: loadBalancerVIPPort, + } + + // Get a string version of the EMLB Listener port number + portNumber := strconv.Itoa(int(lbPort.GetNumber())) + + // Set the packetcluster object's annotations with load balancer info for future reference + packetCluster.Annotations[loadBalancerIDAnnotation] = lb.GetId() + packetCluster.Annotations[loadBalancerPortNumberAnnotation] = portNumber + packetCluster.Annotations[loadBalancerMetroAnnotation] = e.metro + + return nil +} + +// ReconcileVIPOrigin adds the external IP of a new device to the EMLB Load balancer origin pool. +func (e *EMLB) ReconcileVIPOrigin(ctx context.Context, machineScope *scope.MachineScope, deviceAddr []corev1.NodeAddress) error { + log := ctrl.LoggerFrom(ctx) + + packetCluster := machineScope.PacketCluster + + // See if the cluster already has an EMLB ID in its packetCluster annotations. + lbID, exists := packetCluster.Annotations[loadBalancerIDAnnotation] + if !exists { + lbID = "" + } + if lbID == "" { + return fmt.Errorf("no Equinix Metal Load Balancer found in cluster's annotations") + } + + // Fetch the Load Balancer object. + lb, err := e.getLoadBalancer(ctx, lbID) + if err != nil { + return err + } + + // See if the EMLB already has a Port ID in its packetCluster annotations. + lbPortNumber, exists := packetCluster.Annotations[loadBalancerPortNumberAnnotation] + if !exists { + lbPortNumber = "" + } + if lbPortNumber == "" { + return fmt.Errorf("no Equinix Metal Load Balancer Port Numberfound in cluster's annotations") + } + + // Get an int version of the listener port number. + portNumber, err := strconv.ParseInt(lbPortNumber, 10, 32) + if err != nil { + return err + } + + // Get the entire listener port object. + lbPort, err := e.getLoadBalancerPort(ctx, lbID, int32(portNumber)) + if err != nil { + return err + } + + // Fetch the listener port id. + lbPortID := lbPort.GetId() + + // See if the cluster already has an EMLB Origin Pool ID in its packetCluster annotations. + lbPoolID, exists := machineScope.PacketMachine.Annotations[loadBalancerPoolIDAnnotation] + if !exists { + lbPoolID = "" + } + + // Get the Load Balancer pool or create it. + lbPool, err := e.ensureLoadBalancerPool(ctx, lbPoolID, lb.GetName()) + if err != nil { + log.Error(err, "LB Pool Creation/Validation Failed", "EMLB ID", lbID, "Pool ID", lbPoolID) + return err + } + + // Fetch the Pool ID. + lbPoolID = lbPool.GetId() + + // Note the new Origin Pool ID for future reference + machineScope.PacketMachine.Annotations[loadBalancerPoolIDAnnotation] = lbPoolID + + // See if the PacketMachine already has an EMLB Origin ID in its packetCluster annotations. + lbOriginID, exists := machineScope.PacketMachine.Annotations[loadBalancerOriginIDAnnotation] + if !exists { + lbOriginID = "" + } + + // Get the Load Balancer origin or create it. + lbOrigin, err := e.ensureLoadBalancerOrigin(ctx, lbOriginID, lbPoolID, lb.GetName(), deviceAddr) + if err != nil { + log.Error(err, "LB Pool Creation/Validation Failed", "EMLB ID", lbID, "Pool ID", lbPoolID, "Origin ID", lbOriginID) + return err + } + + // Fetch the Origin ID. + lbOriginID = lbOrigin.GetId() + + // Note the PacketMachine's new EMLB Origin ID for future reference + machineScope.PacketMachine.Annotations[loadBalancerOriginIDAnnotation] = lbOriginID + + // Update the Load Balancer's Listener Port to point at the pool + lbPort, err = e.updateListenerPort(ctx, lbPoolID, lbPortID) + if err != nil { + log.Error(err, "LB Port Update Failed", "EMLB ID", lbID, "Pool ID", lbPoolID, "Port ID", lbPort.GetId()) + return err + } + + return nil +} + +// getLoadBalancer Returns a Load Balancer object given an id. +func (e *EMLB) getLoadBalancer(ctx context.Context, id string) (*lbaas.LoadBalancer, error) { + ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger) + + LoadBalancer, _, err := e.client.LoadBalancersApi.GetLoadBalancer(ctx, id).Execute() + return LoadBalancer, err +} + +// getLoadBalancerPort Returns a Load Balancer Port object given an id. +func (e *EMLB) getLoadBalancerPort(ctx context.Context, id string, portNumber int32) (*lbaas.LoadBalancerPort, error) { + ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger) + + LoadBalancerPort, _, err := e.client.PortsApi.GetLoadBalancerPort(ctx, id, portNumber).Execute() + return LoadBalancerPort, err +} + +// EnsureLoadBalancerOrigin takes the devices list of IP addresses in a Load Balancer Origin Pool and ensures an origin +// for the first IPv4 address in the list exists. +func (e *EMLB) ensureLoadBalancerOrigin(ctx context.Context, originID, poolID, lbName string, deviceAddr []corev1.NodeAddress) (*lbaas.LoadBalancerPoolOrigin, error) { + ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger) + log := ctrl.LoggerFrom(ctx) + + if originID == "" { + target, err := getExternalIPv4Target(deviceAddr) + if err != nil { + return nil, err + } + originCreated, _, err := e.createOrigin(ctx, poolID, getResourceName(lbName, "origin"), target) + if err != nil { + return nil, err + } + + originID = originCreated.GetId() + } + + // Regardless of whether we just created it, fetch the loadbalancer pool object. + lbOrigins, _, err := e.client.PoolsApi.ListLoadBalancerPoolOrigins(ctx, poolID).Execute() + if err != nil { + return nil, err + } + + // Create a Origin pointer to return later + var found *lbaas.LoadBalancerPoolOrigin + + // Go through the full list of origins + for i, lbOrigin := range lbOrigins.Origins { + // Doesn't match the id, move to the next one + if lbOrigin.Id != originID { + continue + } + target, err := getExternalIPv4Target(deviceAddr) + if err != nil { + return nil, err + } + if lbOrigin.Target == target.IP { + if *lbOrigin.GetPortNumber().Int32 == target.Port { + found = &lbOrigins.Origins[i] + break + } + } + log.Info("Pool Origin with ID does not have correct IP address") + _, err = e.client.OriginsApi.DeleteLoadBalancerOrigin(ctx, lbOrigin.Id).Execute() + if err != nil { + return nil, err + } + break + } + return found, err +} + +// ensureLoadBalancerPool checks if the poolID exists and if not, creates it. +func (e *EMLB) ensureLoadBalancerPool(ctx context.Context, poolID, lbName string) (*lbaas.LoadBalancerPool, error) { + ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger) + + // Pool doesn't exist, so let's create it. + if poolID == "" { + poolCreated, _, err := e.createPool(ctx, getResourceName(lbName, "pool")) + if err != nil { + return nil, err + } + + poolID = poolCreated.GetId() + } + + // Regardless of whether we just created it, fetch the loadbalancer pool object. + lbPool, _, err := e.client.PoolsApi.GetLoadBalancerPool(ctx, poolID).Execute() + return lbPool, err +} + +// ensureLoadBalancer Takes a Load Balancer id and ensures those pools and ensures it exists. +func (e *EMLB) ensureLoadBalancer(ctx context.Context, lbID, lbname string, portNumber int32) (*lbaas.LoadBalancer, *lbaas.LoadBalancerPort, error) { + ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger) + + // EMLB doesn't exist, so let's create it. + if lbID == "" { + locationID, ok := lbMetros[e.metro] + if !ok { + return nil, nil, fmt.Errorf("could not determine load balancer location for metro %v; valid values are %v", e.metro, reflect.ValueOf(lbMetros).MapKeys()) + } + + lbCreated, _, err := e.createLoadBalancer(ctx, lbname, locationID, providerID) + if err != nil { + return nil, nil, err + } + + lbID = lbCreated.GetId() + if lbID == "" { + return nil, nil, fmt.Errorf("error creating Load Balancer") + } + + _, _, err = e.createListenerPort(ctx, lbID, getResourceName(lbname, "port"), portNumber) + if err != nil { + return nil, nil, err + } + } + + // Regardless of whether we just created it, fetch the loadbalancer object. + lb, err := e.getLoadBalancer(ctx, lbID) + if err != nil { + return nil, nil, err + } + lbPort, err := e.getLoadBalancerPort(ctx, lbID, portNumber) + if err != nil { + return nil, nil, err + } + return lb, lbPort, err +} + +func (e *EMLB) createLoadBalancer(ctx context.Context, lbName, locationID, providerID string) (*lbaas.ResourceCreatedResponse, *http.Response, error) { + lbCreateRequest := lbaas.LoadBalancerCreate{ + Name: lbName, + LocationId: locationID, + ProviderId: providerID, + } + + return e.client.ProjectsApi.CreateLoadBalancer(ctx, e.projectID).LoadBalancerCreate(lbCreateRequest).Execute() +} + +func (e *EMLB) createListenerPort(ctx context.Context, lbID, portName string, portNumber int32) (*lbaas.ResourceCreatedResponse, *http.Response, error) { + portRequest := lbaas.LoadBalancerPortCreate{ + Name: portName, + Number: portNumber, + } + + return e.client.PortsApi.CreateLoadBalancerPort(ctx, lbID).LoadBalancerPortCreate(portRequest).Execute() +} + +func (e *EMLB) createPool(ctx context.Context, name string) (*lbaas.ResourceCreatedResponse, *http.Response, error) { + createPoolRequest := lbaas.LoadBalancerPoolCreate{ + Name: name, + Protocol: lbaas.LoadBalancerPoolCreateProtocol{ + LoadBalancerPoolProtocol: lbaas.LOADBALANCERPOOLPROTOCOL_TCP.Ptr(), + }, + } + return e.client.ProjectsApi.CreatePool(ctx, e.projectID).LoadBalancerPoolCreate(createPoolRequest).Execute() +} + +func (e *EMLB) createOrigin(ctx context.Context, poolID, poolName string, target *Target) (*lbaas.ResourceCreatedResponse, *http.Response, error) { + createOriginRequest := lbaas.LoadBalancerPoolOriginCreate{ + Name: getResourceName(poolName, "origin"), + Target: target.IP, + PortNumber: lbaas.Int32AsLoadBalancerPoolOriginPortNumber(&target.Port), + Active: true, + PoolId: poolID, + } + return e.client.PoolsApi.CreateLoadBalancerPoolOrigin(ctx, poolID).LoadBalancerPoolOriginCreate(createOriginRequest).Execute() +} + +func (e *EMLB) updateListenerPort(ctx context.Context, poolID, lbPortID string) (*lbaas.LoadBalancerPort, error) { + ctx = context.WithValue(ctx, lbaas.ContextOAuth2, e.tokenExchanger) + + // Create a listener port update request that adds the provided load balancer origin pool to the listener port. + portUpdateRequest := lbaas.LoadBalancerPortUpdate{ + AddPoolIds: []string{poolID}, + } + + // Do the actual listener port update. + lbPort, _, err := e.client.PortsApi.UpdateLoadBalancerPort(ctx, lbPortID).LoadBalancerPortUpdate(portUpdateRequest).Execute() + if err != nil { + return nil, err + } + + return lbPort, nil +} + +func getResourceName[T any](loadBalancerName string, resourceType T) string { + return fmt.Sprintf("%v-%v", loadBalancerName, resourceType) +} + +func checkDebugEnabled() bool { + _, legacyVarIsSet := os.LookupEnv("PACKNGO_DEBUG") + return legacyVarIsSet +} + +func convertToTarget(devaddr corev1.NodeAddress) *Target { + target := &Target{ + IP: devaddr.Address, + Port: loadBalancerVIPPort, + } + + return target +} + +func getExternalIPv4Target(deviceAddr []corev1.NodeAddress) (*Target, error) { + // Find main external IPv4 address + // We make the assumption that the first External IPv4 address is the one we want. + for _, addr := range deviceAddr { + if addr.Type == corev1.NodeExternalIP { + ip := net.ParseIP(addr.Address) + if ip == nil { + // Invalid IP address in list, move on to the next one. + continue + } + if ip.To4() != nil { + return convertToTarget(addr), nil + } + } + } + + err := fmt.Errorf("no external IPv4 addresses found") + return nil, err +} diff --git a/internal/emlb/emlb_test.go b/internal/emlb/emlb_test.go new file mode 100644 index 000000000..09e3cc95d --- /dev/null +++ b/internal/emlb/emlb_test.go @@ -0,0 +1,67 @@ +// Package emlb manages authentication to the Equinix Metal Load Balancer service. +package emlb + +import ( + "reflect" + "testing" + + corev1 "k8s.io/api/core/v1" +) + +func Test_getExternalIPv4Target(t *testing.T) { + type args struct { + deviceAddr []corev1.NodeAddress + } + tests := []struct { + name string + args args + want *Target + wantErr bool + }{ + { + name: "Single Valid External Address", + args: args{ + []corev1.NodeAddress{ + { + Type: "InternalIP", + Address: "10.2.1.5", + }, + { + Type: "ExternalIP", + Address: "", + }, + { + Type: "ExternalIP", + Address: "1.2.3.4", + }, + }, + }, + want: &Target{ + IP: "1.2.3.4", + Port: loadBalancerVIPPort, + }, + }, + { + name: "Single Invalid External Address", + args: args{ + []corev1.NodeAddress{{ + Type: "ExternalIP", + Address: "ffff::0", + }}, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := getExternalIPv4Target(tt.args.deviceAddr) + if (err != nil) != tt.wantErr { + t.Errorf("getExternalIPv4Target() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("getExternalIPv4Target() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/internal/emlb/token_exchanger.go b/internal/emlb/token_exchanger.go new file mode 100644 index 000000000..04223896b --- /dev/null +++ b/internal/emlb/token_exchanger.go @@ -0,0 +1,58 @@ +package emlb + +import ( + "encoding/json" + "fmt" + "io" + "net/http" + "time" + + "golang.org/x/oauth2" +) + +// TokenExchanger is an client for authenticating to the Load Balancer API. +type TokenExchanger struct { + metalAPIKey string + client *http.Client +} + +// Token creates a Token object to authenticate with the Load Balancer API. +func (m *TokenExchanger) Token() (*oauth2.Token, error) { + tokenExchangeURL := "https://iam.metalctrl.io/api-keys/exchange" //nolint:gosec + tokenExchangeRequest, err := http.NewRequest(http.MethodPost, tokenExchangeURL, http.NoBody) //nolint:noctx // we can't find a way to get the ctx into here yet and just using context.Background adds no value that we can tell + if err != nil { + return nil, err + } + tokenExchangeRequest.Header.Add("Authorization", fmt.Sprintf("Bearer %v", m.metalAPIKey)) + + resp, err := m.client.Do(tokenExchangeRequest) + if err != nil { + return nil, err + } + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("token exchange request failed with status %v, body %v", resp.StatusCode, string(body)) + } + + token := oauth2.Token{} + err = json.Unmarshal(body, &token) + if err != nil { + fmt.Println(len(body)) + fmt.Println(token) + fmt.Println(err) + return nil, err + } + + expiresIn := token.Extra("expires_in") + if expiresIn != nil { + expiresInSeconds := expiresIn.(int) + token.Expiry = time.Now().Add(time.Second * time.Duration(expiresInSeconds)) + } + + return &token, nil +} diff --git a/internal/lbaas/v1/.gitignore b/internal/lbaas/v1/.gitignore new file mode 100644 index 000000000..daf913b1b --- /dev/null +++ b/internal/lbaas/v1/.gitignore @@ -0,0 +1,24 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*.prof diff --git a/internal/lbaas/v1/.openapi-generator-ignore b/internal/lbaas/v1/.openapi-generator-ignore new file mode 100644 index 000000000..7484ee590 --- /dev/null +++ b/internal/lbaas/v1/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/internal/lbaas/v1/.openapi-generator/FILES b/internal/lbaas/v1/.openapi-generator/FILES new file mode 100644 index 000000000..9a0a3dc60 --- /dev/null +++ b/internal/lbaas/v1/.openapi-generator/FILES @@ -0,0 +1,75 @@ +.gitignore +.openapi-generator-ignore +.travis.yml +README.md +api/openapi.yaml +api_load_balancers.go +api_origins.go +api_pools.go +api_ports.go +api_projects.go +client.go +configuration.go +docs/LoadBalancer.md +docs/LoadBalancerCollection.md +docs/LoadBalancerCreate.md +docs/LoadBalancerLocation.md +docs/LoadBalancerPool.md +docs/LoadBalancerPoolCollection.md +docs/LoadBalancerPoolCreate.md +docs/LoadBalancerPoolCreateProtocol.md +docs/LoadBalancerPoolOrigin.md +docs/LoadBalancerPoolOriginCollection.md +docs/LoadBalancerPoolOriginCreate.md +docs/LoadBalancerPoolOriginPortNumber.md +docs/LoadBalancerPoolOriginUpdate.md +docs/LoadBalancerPoolProtocol.md +docs/LoadBalancerPoolShort.md +docs/LoadBalancerPoolUpdate.md +docs/LoadBalancerPort.md +docs/LoadBalancerPortCollection.md +docs/LoadBalancerPortCreate.md +docs/LoadBalancerPortUpdate.md +docs/LoadBalancerShort.md +docs/LoadBalancerUpdate.md +docs/LoadBalancersApi.md +docs/OriginsApi.md +docs/PoolsApi.md +docs/PortsApi.md +docs/ProjectsApi.md +docs/Provider.md +docs/ResourceCreatedResponse.md +git_push.sh +go.mod +go.sum +model_load_balancer.go +model_load_balancer_collection.go +model_load_balancer_create.go +model_load_balancer_location.go +model_load_balancer_pool.go +model_load_balancer_pool_collection.go +model_load_balancer_pool_create.go +model_load_balancer_pool_create_protocol.go +model_load_balancer_pool_origin.go +model_load_balancer_pool_origin_collection.go +model_load_balancer_pool_origin_create.go +model_load_balancer_pool_origin_port_number.go +model_load_balancer_pool_origin_update.go +model_load_balancer_pool_protocol.go +model_load_balancer_pool_short.go +model_load_balancer_pool_update.go +model_load_balancer_port.go +model_load_balancer_port_collection.go +model_load_balancer_port_create.go +model_load_balancer_port_update.go +model_load_balancer_short.go +model_load_balancer_update.go +model_provider.go +model_resource_created_response.go +response.go +test/api_load_balancers_test.go +test/api_origins_test.go +test/api_pools_test.go +test/api_ports_test.go +test/api_projects_test.go +utils.go diff --git a/internal/lbaas/v1/.openapi-generator/VERSION b/internal/lbaas/v1/.openapi-generator/VERSION new file mode 100644 index 000000000..412252180 --- /dev/null +++ b/internal/lbaas/v1/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.0.0 \ No newline at end of file diff --git a/internal/lbaas/v1/api_load_balancers.go b/internal/lbaas/v1/api_load_balancers.go new file mode 100644 index 000000000..f4805d5fc --- /dev/null +++ b/internal/lbaas/v1/api_load_balancers.go @@ -0,0 +1,328 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + +// LoadBalancersApiService LoadBalancersApi service +type LoadBalancersApiService service + +type ApiDeleteLoadBalancerRequest struct { + ctx context.Context + ApiService *LoadBalancersApiService + loadBalancerID string +} + +func (r ApiDeleteLoadBalancerRequest) Execute() (*http.Response, error) { + return r.ApiService.DeleteLoadBalancerExecute(r) +} + +/* +DeleteLoadBalancer Delete a load balancer. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerID ID of the load balancer + @return ApiDeleteLoadBalancerRequest +*/ +func (a *LoadBalancersApiService) DeleteLoadBalancer(ctx context.Context, loadBalancerID string) ApiDeleteLoadBalancerRequest { + return ApiDeleteLoadBalancerRequest{ + ApiService: a, + ctx: ctx, + loadBalancerID: loadBalancerID, + } +} + +// Execute executes the request +func (a *LoadBalancersApiService) DeleteLoadBalancerExecute(r ApiDeleteLoadBalancerRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "LoadBalancersApiService.DeleteLoadBalancer") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/{loadBalancerID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerID, "loadBalancerID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiGetLoadBalancerRequest struct { + ctx context.Context + ApiService *LoadBalancersApiService + loadBalancerID string +} + +func (r ApiGetLoadBalancerRequest) Execute() (*LoadBalancer, *http.Response, error) { + return r.ApiService.GetLoadBalancerExecute(r) +} + +/* +GetLoadBalancer Gets a load balancer by ID + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerID ID of the load balancer + @return ApiGetLoadBalancerRequest +*/ +func (a *LoadBalancersApiService) GetLoadBalancer(ctx context.Context, loadBalancerID string) ApiGetLoadBalancerRequest { + return ApiGetLoadBalancerRequest{ + ApiService: a, + ctx: ctx, + loadBalancerID: loadBalancerID, + } +} + +// Execute executes the request +// +// @return LoadBalancer +func (a *LoadBalancersApiService) GetLoadBalancerExecute(r ApiGetLoadBalancerRequest) (*LoadBalancer, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancer + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "LoadBalancersApiService.GetLoadBalancer") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/{loadBalancerID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerID, "loadBalancerID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUpdateLoadBalancerRequest struct { + ctx context.Context + ApiService *LoadBalancersApiService + loadBalancerID string + loadBalancerUpdate *LoadBalancerUpdate +} + +func (r ApiUpdateLoadBalancerRequest) LoadBalancerUpdate(loadBalancerUpdate LoadBalancerUpdate) ApiUpdateLoadBalancerRequest { + r.loadBalancerUpdate = &loadBalancerUpdate + return r +} + +func (r ApiUpdateLoadBalancerRequest) Execute() (*ResourceCreatedResponse, *http.Response, error) { + return r.ApiService.UpdateLoadBalancerExecute(r) +} + +/* +UpdateLoadBalancer Update a load balancer. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerID ID of the load balancer + @return ApiUpdateLoadBalancerRequest +*/ +func (a *LoadBalancersApiService) UpdateLoadBalancer(ctx context.Context, loadBalancerID string) ApiUpdateLoadBalancerRequest { + return ApiUpdateLoadBalancerRequest{ + ApiService: a, + ctx: ctx, + loadBalancerID: loadBalancerID, + } +} + +// Execute executes the request +// +// @return ResourceCreatedResponse +func (a *LoadBalancersApiService) UpdateLoadBalancerExecute(r ApiUpdateLoadBalancerRequest) (*ResourceCreatedResponse, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPatch + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ResourceCreatedResponse + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "LoadBalancersApiService.UpdateLoadBalancer") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/{loadBalancerID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerID, "loadBalancerID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.loadBalancerUpdate == nil { + return localVarReturnValue, nil, reportError("loadBalancerUpdate is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.loadBalancerUpdate + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/internal/lbaas/v1/api_origins.go b/internal/lbaas/v1/api_origins.go new file mode 100644 index 000000000..a2a82c646 --- /dev/null +++ b/internal/lbaas/v1/api_origins.go @@ -0,0 +1,328 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + +// OriginsApiService OriginsApi service +type OriginsApiService service + +type ApiDeleteLoadBalancerOriginRequest struct { + ctx context.Context + ApiService *OriginsApiService + loadBalancerOriginID string +} + +func (r ApiDeleteLoadBalancerOriginRequest) Execute() (*http.Response, error) { + return r.ApiService.DeleteLoadBalancerOriginExecute(r) +} + +/* +DeleteLoadBalancerOrigin Delete a load balancer origin. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerOriginID ID of the load balancer origin + @return ApiDeleteLoadBalancerOriginRequest +*/ +func (a *OriginsApiService) DeleteLoadBalancerOrigin(ctx context.Context, loadBalancerOriginID string) ApiDeleteLoadBalancerOriginRequest { + return ApiDeleteLoadBalancerOriginRequest{ + ApiService: a, + ctx: ctx, + loadBalancerOriginID: loadBalancerOriginID, + } +} + +// Execute executes the request +func (a *OriginsApiService) DeleteLoadBalancerOriginExecute(r ApiDeleteLoadBalancerOriginRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "OriginsApiService.DeleteLoadBalancerOrigin") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/pools/origins/{loadBalancerOriginID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerOriginID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerOriginID, "loadBalancerOriginID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiGetLoadBalancerOriginRequest struct { + ctx context.Context + ApiService *OriginsApiService + loadBalancerOriginID string +} + +func (r ApiGetLoadBalancerOriginRequest) Execute() (*LoadBalancerPoolOrigin, *http.Response, error) { + return r.ApiService.GetLoadBalancerOriginExecute(r) +} + +/* +GetLoadBalancerOrigin Gets a load balancer origin by ID + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerOriginID ID of the load balancer origin + @return ApiGetLoadBalancerOriginRequest +*/ +func (a *OriginsApiService) GetLoadBalancerOrigin(ctx context.Context, loadBalancerOriginID string) ApiGetLoadBalancerOriginRequest { + return ApiGetLoadBalancerOriginRequest{ + ApiService: a, + ctx: ctx, + loadBalancerOriginID: loadBalancerOriginID, + } +} + +// Execute executes the request +// +// @return LoadBalancerPoolOrigin +func (a *OriginsApiService) GetLoadBalancerOriginExecute(r ApiGetLoadBalancerOriginRequest) (*LoadBalancerPoolOrigin, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancerPoolOrigin + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "OriginsApiService.GetLoadBalancerOrigin") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/pools/origins/{loadBalancerOriginID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerOriginID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerOriginID, "loadBalancerOriginID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUpdateLoadBalancerOriginRequest struct { + ctx context.Context + ApiService *OriginsApiService + loadBalancerOriginID string + loadBalancerPoolOriginUpdate *LoadBalancerPoolOriginUpdate +} + +func (r ApiUpdateLoadBalancerOriginRequest) LoadBalancerPoolOriginUpdate(loadBalancerPoolOriginUpdate LoadBalancerPoolOriginUpdate) ApiUpdateLoadBalancerOriginRequest { + r.loadBalancerPoolOriginUpdate = &loadBalancerPoolOriginUpdate + return r +} + +func (r ApiUpdateLoadBalancerOriginRequest) Execute() (*LoadBalancerPoolOrigin, *http.Response, error) { + return r.ApiService.UpdateLoadBalancerOriginExecute(r) +} + +/* +UpdateLoadBalancerOrigin Update a load balancer origin. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerOriginID ID of the load balancer origin + @return ApiUpdateLoadBalancerOriginRequest +*/ +func (a *OriginsApiService) UpdateLoadBalancerOrigin(ctx context.Context, loadBalancerOriginID string) ApiUpdateLoadBalancerOriginRequest { + return ApiUpdateLoadBalancerOriginRequest{ + ApiService: a, + ctx: ctx, + loadBalancerOriginID: loadBalancerOriginID, + } +} + +// Execute executes the request +// +// @return LoadBalancerPoolOrigin +func (a *OriginsApiService) UpdateLoadBalancerOriginExecute(r ApiUpdateLoadBalancerOriginRequest) (*LoadBalancerPoolOrigin, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPatch + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancerPoolOrigin + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "OriginsApiService.UpdateLoadBalancerOrigin") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/pools/origins/{loadBalancerOriginID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerOriginID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerOriginID, "loadBalancerOriginID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.loadBalancerPoolOriginUpdate == nil { + return localVarReturnValue, nil, reportError("loadBalancerPoolOriginUpdate is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.loadBalancerPoolOriginUpdate + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/internal/lbaas/v1/api_pools.go b/internal/lbaas/v1/api_pools.go new file mode 100644 index 000000000..bfd5908e1 --- /dev/null +++ b/internal/lbaas/v1/api_pools.go @@ -0,0 +1,543 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + +// PoolsApiService PoolsApi service +type PoolsApiService service + +type ApiCreateLoadBalancerPoolOriginRequest struct { + ctx context.Context + ApiService *PoolsApiService + loadBalancerPoolID string + loadBalancerPoolOriginCreate *LoadBalancerPoolOriginCreate +} + +func (r ApiCreateLoadBalancerPoolOriginRequest) LoadBalancerPoolOriginCreate(loadBalancerPoolOriginCreate LoadBalancerPoolOriginCreate) ApiCreateLoadBalancerPoolOriginRequest { + r.loadBalancerPoolOriginCreate = &loadBalancerPoolOriginCreate + return r +} + +func (r ApiCreateLoadBalancerPoolOriginRequest) Execute() (*ResourceCreatedResponse, *http.Response, error) { + return r.ApiService.CreateLoadBalancerPoolOriginExecute(r) +} + +/* +CreateLoadBalancerPoolOrigin Create a load balancer origin for a pool. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerPoolID ID of the load balancer pool to get + @return ApiCreateLoadBalancerPoolOriginRequest +*/ +func (a *PoolsApiService) CreateLoadBalancerPoolOrigin(ctx context.Context, loadBalancerPoolID string) ApiCreateLoadBalancerPoolOriginRequest { + return ApiCreateLoadBalancerPoolOriginRequest{ + ApiService: a, + ctx: ctx, + loadBalancerPoolID: loadBalancerPoolID, + } +} + +// Execute executes the request +// +// @return ResourceCreatedResponse +func (a *PoolsApiService) CreateLoadBalancerPoolOriginExecute(r ApiCreateLoadBalancerPoolOriginRequest) (*ResourceCreatedResponse, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ResourceCreatedResponse + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PoolsApiService.CreateLoadBalancerPoolOrigin") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/pools/{loadBalancerPoolID}/origins" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerPoolID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerPoolID, "loadBalancerPoolID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.loadBalancerPoolOriginCreate == nil { + return localVarReturnValue, nil, reportError("loadBalancerPoolOriginCreate is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.loadBalancerPoolOriginCreate + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiDeleteLoadBalancerPoolRequest struct { + ctx context.Context + ApiService *PoolsApiService + loadBalancerPoolID string +} + +func (r ApiDeleteLoadBalancerPoolRequest) Execute() (*http.Response, error) { + return r.ApiService.DeleteLoadBalancerPoolExecute(r) +} + +/* +DeleteLoadBalancerPool Delete a load balancer pool. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerPoolID ID of the load balancer pool to get + @return ApiDeleteLoadBalancerPoolRequest +*/ +func (a *PoolsApiService) DeleteLoadBalancerPool(ctx context.Context, loadBalancerPoolID string) ApiDeleteLoadBalancerPoolRequest { + return ApiDeleteLoadBalancerPoolRequest{ + ApiService: a, + ctx: ctx, + loadBalancerPoolID: loadBalancerPoolID, + } +} + +// Execute executes the request +func (a *PoolsApiService) DeleteLoadBalancerPoolExecute(r ApiDeleteLoadBalancerPoolRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PoolsApiService.DeleteLoadBalancerPool") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/pools/{loadBalancerPoolID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerPoolID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerPoolID, "loadBalancerPoolID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiGetLoadBalancerPoolRequest struct { + ctx context.Context + ApiService *PoolsApiService + loadBalancerPoolID string +} + +func (r ApiGetLoadBalancerPoolRequest) Execute() (*LoadBalancerPool, *http.Response, error) { + return r.ApiService.GetLoadBalancerPoolExecute(r) +} + +/* +GetLoadBalancerPool Gets a load balancer pool by ID + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerPoolID ID of the load balancer pool to get + @return ApiGetLoadBalancerPoolRequest +*/ +func (a *PoolsApiService) GetLoadBalancerPool(ctx context.Context, loadBalancerPoolID string) ApiGetLoadBalancerPoolRequest { + return ApiGetLoadBalancerPoolRequest{ + ApiService: a, + ctx: ctx, + loadBalancerPoolID: loadBalancerPoolID, + } +} + +// Execute executes the request +// +// @return LoadBalancerPool +func (a *PoolsApiService) GetLoadBalancerPoolExecute(r ApiGetLoadBalancerPoolRequest) (*LoadBalancerPool, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancerPool + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PoolsApiService.GetLoadBalancerPool") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/pools/{loadBalancerPoolID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerPoolID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerPoolID, "loadBalancerPoolID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiListLoadBalancerPoolOriginsRequest struct { + ctx context.Context + ApiService *PoolsApiService + loadBalancerPoolID string +} + +func (r ApiListLoadBalancerPoolOriginsRequest) Execute() (*LoadBalancerPoolOriginCollection, *http.Response, error) { + return r.ApiService.ListLoadBalancerPoolOriginsExecute(r) +} + +/* +ListLoadBalancerPoolOrigins Gets the origins for a pool. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerPoolID ID of the load balancer pool to get + @return ApiListLoadBalancerPoolOriginsRequest +*/ +func (a *PoolsApiService) ListLoadBalancerPoolOrigins(ctx context.Context, loadBalancerPoolID string) ApiListLoadBalancerPoolOriginsRequest { + return ApiListLoadBalancerPoolOriginsRequest{ + ApiService: a, + ctx: ctx, + loadBalancerPoolID: loadBalancerPoolID, + } +} + +// Execute executes the request +// +// @return LoadBalancerPoolOriginCollection +func (a *PoolsApiService) ListLoadBalancerPoolOriginsExecute(r ApiListLoadBalancerPoolOriginsRequest) (*LoadBalancerPoolOriginCollection, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancerPoolOriginCollection + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PoolsApiService.ListLoadBalancerPoolOrigins") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/pools/{loadBalancerPoolID}/origins" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerPoolID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerPoolID, "loadBalancerPoolID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUpdateLoadBalancerPoolRequest struct { + ctx context.Context + ApiService *PoolsApiService + loadBalancerPoolID string + loadBalancerPoolUpdate *LoadBalancerPoolUpdate +} + +func (r ApiUpdateLoadBalancerPoolRequest) LoadBalancerPoolUpdate(loadBalancerPoolUpdate LoadBalancerPoolUpdate) ApiUpdateLoadBalancerPoolRequest { + r.loadBalancerPoolUpdate = &loadBalancerPoolUpdate + return r +} + +func (r ApiUpdateLoadBalancerPoolRequest) Execute() (*LoadBalancerPool, *http.Response, error) { + return r.ApiService.UpdateLoadBalancerPoolExecute(r) +} + +/* +UpdateLoadBalancerPool Update a load balancer pool. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerPoolID ID of the load balancer pool to get + @return ApiUpdateLoadBalancerPoolRequest +*/ +func (a *PoolsApiService) UpdateLoadBalancerPool(ctx context.Context, loadBalancerPoolID string) ApiUpdateLoadBalancerPoolRequest { + return ApiUpdateLoadBalancerPoolRequest{ + ApiService: a, + ctx: ctx, + loadBalancerPoolID: loadBalancerPoolID, + } +} + +// Execute executes the request +// +// @return LoadBalancerPool +func (a *PoolsApiService) UpdateLoadBalancerPoolExecute(r ApiUpdateLoadBalancerPoolRequest) (*LoadBalancerPool, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPatch + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancerPool + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PoolsApiService.UpdateLoadBalancerPool") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/pools/{loadBalancerPoolID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerPoolID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerPoolID, "loadBalancerPoolID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.loadBalancerPoolUpdate == nil { + return localVarReturnValue, nil, reportError("loadBalancerPoolUpdate is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.loadBalancerPoolUpdate + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/internal/lbaas/v1/api_ports.go b/internal/lbaas/v1/api_ports.go new file mode 100644 index 000000000..58b7d927e --- /dev/null +++ b/internal/lbaas/v1/api_ports.go @@ -0,0 +1,547 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + +// PortsApiService PortsApi service +type PortsApiService service + +type ApiCreateLoadBalancerPortRequest struct { + ctx context.Context + ApiService *PortsApiService + loadBalancerID string + loadBalancerPortCreate *LoadBalancerPortCreate +} + +func (r ApiCreateLoadBalancerPortRequest) LoadBalancerPortCreate(loadBalancerPortCreate LoadBalancerPortCreate) ApiCreateLoadBalancerPortRequest { + r.loadBalancerPortCreate = &loadBalancerPortCreate + return r +} + +func (r ApiCreateLoadBalancerPortRequest) Execute() (*ResourceCreatedResponse, *http.Response, error) { + return r.ApiService.CreateLoadBalancerPortExecute(r) +} + +/* +CreateLoadBalancerPort Create a load balancer port. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerID ID of the load balancer + @return ApiCreateLoadBalancerPortRequest +*/ +func (a *PortsApiService) CreateLoadBalancerPort(ctx context.Context, loadBalancerID string) ApiCreateLoadBalancerPortRequest { + return ApiCreateLoadBalancerPortRequest{ + ApiService: a, + ctx: ctx, + loadBalancerID: loadBalancerID, + } +} + +// Execute executes the request +// +// @return ResourceCreatedResponse +func (a *PortsApiService) CreateLoadBalancerPortExecute(r ApiCreateLoadBalancerPortRequest) (*ResourceCreatedResponse, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ResourceCreatedResponse + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PortsApiService.CreateLoadBalancerPort") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/{loadBalancerID}/ports" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerID, "loadBalancerID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.loadBalancerPortCreate == nil { + return localVarReturnValue, nil, reportError("loadBalancerPortCreate is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.loadBalancerPortCreate + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiDeleteLoadBalancerPortRequest struct { + ctx context.Context + ApiService *PortsApiService + loadBalancerPortID string +} + +func (r ApiDeleteLoadBalancerPortRequest) Execute() (*http.Response, error) { + return r.ApiService.DeleteLoadBalancerPortExecute(r) +} + +/* +DeleteLoadBalancerPort Delete a load balancer port. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerPortID ID of the load balancer port + @return ApiDeleteLoadBalancerPortRequest +*/ +func (a *PortsApiService) DeleteLoadBalancerPort(ctx context.Context, loadBalancerPortID string) ApiDeleteLoadBalancerPortRequest { + return ApiDeleteLoadBalancerPortRequest{ + ApiService: a, + ctx: ctx, + loadBalancerPortID: loadBalancerPortID, + } +} + +// Execute executes the request +func (a *PortsApiService) DeleteLoadBalancerPortExecute(r ApiDeleteLoadBalancerPortRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PortsApiService.DeleteLoadBalancerPort") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/ports/{loadBalancerPortID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerPortID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerPortID, "loadBalancerPortID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiGetLoadBalancerPortRequest struct { + ctx context.Context + ApiService *PortsApiService + loadBalancerID string + portNumber int32 +} + +func (r ApiGetLoadBalancerPortRequest) Execute() (*LoadBalancerPort, *http.Response, error) { + return r.ApiService.GetLoadBalancerPortExecute(r) +} + +/* +GetLoadBalancerPort Gets a load balancer port by ID + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerID ID of the load balancer + @param portNumber Port number + @return ApiGetLoadBalancerPortRequest +*/ +func (a *PortsApiService) GetLoadBalancerPort(ctx context.Context, loadBalancerID string, portNumber int32) ApiGetLoadBalancerPortRequest { + return ApiGetLoadBalancerPortRequest{ + ApiService: a, + ctx: ctx, + loadBalancerID: loadBalancerID, + portNumber: portNumber, + } +} + +// Execute executes the request +// +// @return LoadBalancerPort +func (a *PortsApiService) GetLoadBalancerPortExecute(r ApiGetLoadBalancerPortRequest) (*LoadBalancerPort, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancerPort + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PortsApiService.GetLoadBalancerPort") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/{loadBalancerID}/ports/{portNumber}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerID, "loadBalancerID")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"portNumber"+"}", url.PathEscape(parameterValueToString(r.portNumber, "portNumber")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiListLoadBalancerPortsRequest struct { + ctx context.Context + ApiService *PortsApiService + loadBalancerID string +} + +func (r ApiListLoadBalancerPortsRequest) Execute() (*LoadBalancerPortCollection, *http.Response, error) { + return r.ApiService.ListLoadBalancerPortsExecute(r) +} + +/* +ListLoadBalancerPorts Gets the load balancer's ports. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerID ID of the load balancer + @return ApiListLoadBalancerPortsRequest +*/ +func (a *PortsApiService) ListLoadBalancerPorts(ctx context.Context, loadBalancerID string) ApiListLoadBalancerPortsRequest { + return ApiListLoadBalancerPortsRequest{ + ApiService: a, + ctx: ctx, + loadBalancerID: loadBalancerID, + } +} + +// Execute executes the request +// +// @return LoadBalancerPortCollection +func (a *PortsApiService) ListLoadBalancerPortsExecute(r ApiListLoadBalancerPortsRequest) (*LoadBalancerPortCollection, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancerPortCollection + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PortsApiService.ListLoadBalancerPorts") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/{loadBalancerID}/ports" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerID, "loadBalancerID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiUpdateLoadBalancerPortRequest struct { + ctx context.Context + ApiService *PortsApiService + loadBalancerPortID string + loadBalancerPortUpdate *LoadBalancerPortUpdate +} + +func (r ApiUpdateLoadBalancerPortRequest) LoadBalancerPortUpdate(loadBalancerPortUpdate LoadBalancerPortUpdate) ApiUpdateLoadBalancerPortRequest { + r.loadBalancerPortUpdate = &loadBalancerPortUpdate + return r +} + +func (r ApiUpdateLoadBalancerPortRequest) Execute() (*LoadBalancerPort, *http.Response, error) { + return r.ApiService.UpdateLoadBalancerPortExecute(r) +} + +/* +UpdateLoadBalancerPort Update a load balancer port. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param loadBalancerPortID ID of the load balancer port + @return ApiUpdateLoadBalancerPortRequest +*/ +func (a *PortsApiService) UpdateLoadBalancerPort(ctx context.Context, loadBalancerPortID string) ApiUpdateLoadBalancerPortRequest { + return ApiUpdateLoadBalancerPortRequest{ + ApiService: a, + ctx: ctx, + loadBalancerPortID: loadBalancerPortID, + } +} + +// Execute executes the request +// +// @return LoadBalancerPort +func (a *PortsApiService) UpdateLoadBalancerPortExecute(r ApiUpdateLoadBalancerPortRequest) (*LoadBalancerPort, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPatch + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancerPort + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "PortsApiService.UpdateLoadBalancerPort") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/loadbalancers/ports/{loadBalancerPortID}" + localVarPath = strings.Replace(localVarPath, "{"+"loadBalancerPortID"+"}", url.PathEscape(parameterValueToString(r.loadBalancerPortID, "loadBalancerPortID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.loadBalancerPortUpdate == nil { + return localVarReturnValue, nil, reportError("loadBalancerPortUpdate is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.loadBalancerPortUpdate + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/internal/lbaas/v1/api_projects.go b/internal/lbaas/v1/api_projects.go new file mode 100644 index 000000000..5808f96f2 --- /dev/null +++ b/internal/lbaas/v1/api_projects.go @@ -0,0 +1,453 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + +// ProjectsApiService ProjectsApi service +type ProjectsApiService service + +type ApiCreateLoadBalancerRequest struct { + ctx context.Context + ApiService *ProjectsApiService + projectID string + loadBalancerCreate *LoadBalancerCreate +} + +func (r ApiCreateLoadBalancerRequest) LoadBalancerCreate(loadBalancerCreate LoadBalancerCreate) ApiCreateLoadBalancerRequest { + r.loadBalancerCreate = &loadBalancerCreate + return r +} + +func (r ApiCreateLoadBalancerRequest) Execute() (*ResourceCreatedResponse, *http.Response, error) { + return r.ApiService.CreateLoadBalancerExecute(r) +} + +/* +CreateLoadBalancer Create a load balancer for project. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectID ID of project + @return ApiCreateLoadBalancerRequest +*/ +func (a *ProjectsApiService) CreateLoadBalancer(ctx context.Context, projectID string) ApiCreateLoadBalancerRequest { + return ApiCreateLoadBalancerRequest{ + ApiService: a, + ctx: ctx, + projectID: projectID, + } +} + +// Execute executes the request +// +// @return ResourceCreatedResponse +func (a *ProjectsApiService) CreateLoadBalancerExecute(r ApiCreateLoadBalancerRequest) (*ResourceCreatedResponse, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ResourceCreatedResponse + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ProjectsApiService.CreateLoadBalancer") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/projects/{projectID}/loadbalancers" + localVarPath = strings.Replace(localVarPath, "{"+"projectID"+"}", url.PathEscape(parameterValueToString(r.projectID, "projectID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.loadBalancerCreate == nil { + return localVarReturnValue, nil, reportError("loadBalancerCreate is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.loadBalancerCreate + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiCreatePoolRequest struct { + ctx context.Context + ApiService *ProjectsApiService + projectID string + loadBalancerPoolCreate *LoadBalancerPoolCreate +} + +func (r ApiCreatePoolRequest) LoadBalancerPoolCreate(loadBalancerPoolCreate LoadBalancerPoolCreate) ApiCreatePoolRequest { + r.loadBalancerPoolCreate = &loadBalancerPoolCreate + return r +} + +func (r ApiCreatePoolRequest) Execute() (*ResourceCreatedResponse, *http.Response, error) { + return r.ApiService.CreatePoolExecute(r) +} + +/* +CreatePool Create a load balancer pool for project. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectID ID of project + @return ApiCreatePoolRequest +*/ +func (a *ProjectsApiService) CreatePool(ctx context.Context, projectID string) ApiCreatePoolRequest { + return ApiCreatePoolRequest{ + ApiService: a, + ctx: ctx, + projectID: projectID, + } +} + +// Execute executes the request +// +// @return ResourceCreatedResponse +func (a *ProjectsApiService) CreatePoolExecute(r ApiCreatePoolRequest) (*ResourceCreatedResponse, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ResourceCreatedResponse + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ProjectsApiService.CreatePool") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/projects/{projectID}/loadbalancers/pools" + localVarPath = strings.Replace(localVarPath, "{"+"projectID"+"}", url.PathEscape(parameterValueToString(r.projectID, "projectID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.loadBalancerPoolCreate == nil { + return localVarReturnValue, nil, reportError("loadBalancerPoolCreate is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.loadBalancerPoolCreate + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiListLoadBalancersRequest struct { + ctx context.Context + ApiService *ProjectsApiService + projectID string +} + +func (r ApiListLoadBalancersRequest) Execute() (*LoadBalancerCollection, *http.Response, error) { + return r.ApiService.ListLoadBalancersExecute(r) +} + +/* +ListLoadBalancers Gets the load balancers for a project. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectID ID of project + @return ApiListLoadBalancersRequest +*/ +func (a *ProjectsApiService) ListLoadBalancers(ctx context.Context, projectID string) ApiListLoadBalancersRequest { + return ApiListLoadBalancersRequest{ + ApiService: a, + ctx: ctx, + projectID: projectID, + } +} + +// Execute executes the request +// +// @return LoadBalancerCollection +func (a *ProjectsApiService) ListLoadBalancersExecute(r ApiListLoadBalancersRequest) (*LoadBalancerCollection, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancerCollection + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ProjectsApiService.ListLoadBalancers") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/projects/{projectID}/loadbalancers" + localVarPath = strings.Replace(localVarPath, "{"+"projectID"+"}", url.PathEscape(parameterValueToString(r.projectID, "projectID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiListPoolsRequest struct { + ctx context.Context + ApiService *ProjectsApiService + projectID string +} + +func (r ApiListPoolsRequest) Execute() (*LoadBalancerPoolCollection, *http.Response, error) { + return r.ApiService.ListPoolsExecute(r) +} + +/* +ListPools Gets the pools for a project. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectID ID of project + @return ApiListPoolsRequest +*/ +func (a *ProjectsApiService) ListPools(ctx context.Context, projectID string) ApiListPoolsRequest { + return ApiListPoolsRequest{ + ApiService: a, + ctx: ctx, + projectID: projectID, + } +} + +// Execute executes the request +// +// @return LoadBalancerPoolCollection +func (a *ProjectsApiService) ListPoolsExecute(r ApiListPoolsRequest) (*LoadBalancerPoolCollection, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *LoadBalancerPoolCollection + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "ProjectsApiService.ListPools") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/v1/projects/{projectID}/loadbalancers/pools" + localVarPath = strings.Replace(localVarPath, "{"+"projectID"+"}", url.PathEscape(parameterValueToString(r.projectID, "projectID")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/internal/lbaas/v1/client.go b/internal/lbaas/v1/client.go new file mode 100644 index 000000000..2dddafb6d --- /dev/null +++ b/internal/lbaas/v1/client.go @@ -0,0 +1,686 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "golang.org/x/oauth2" +) + +var ( + jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) + xmlCheck = regexp.MustCompile(`(?i:(?:application|text)/xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer("%5B", "[", "%5D", "]") +) + +// APIClient manages communication with the Load Balancer Management API API v0.0.1 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + LoadBalancersApi *LoadBalancersApiService + + OriginsApi *OriginsApiService + + PoolsApi *PoolsApiService + + PortsApi *PortsApiService + + ProjectsApi *ProjectsApiService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = http.DefaultClient + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.LoadBalancersApi = (*LoadBalancersApiService)(&c.common) + c.OriginsApi = (*OriginsApiService)(&c.common) + c.PoolsApi = (*PoolsApiService)(&c.common) + c.PortsApi = (*PortsApiService)(&c.common) + c.ProjectsApi = (*ProjectsApiService)(&c.common) + + return c +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insensitive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.EqualFold(a, needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +func parameterValueToString(obj interface{}, key string) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + return fmt.Sprintf("%v", obj) + } + var param, ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap, err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} + +// parameterAddToHeaderOrQuery adds the provided object to the request header or url query +// supporting deep object syntax +func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t, ok := obj.(MappedNullable); ok { + dataMap, err := t.ToMap() + if err != nil { + return + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i := 0; i < lenIndValue; i++ { + var arrayValue = indValue.Index(i) + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, arrayValue.Interface(), collectionType) + } + return + + case reflect.Map: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + iter := indValue.MapRange() + for iter.Next() { + k, v := iter.Key(), iter.Value() + parameterAddToHeaderOrQuery(headerOrQueryParams, fmt.Sprintf("%s[%s]", keyPrefix, k.String()), v.Interface(), collectionType) + } + return + + case reflect.Interface: + fallthrough + case reflect.Ptr: + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, v.Elem().Interface(), collectionType) + return + + case reflect.Int, reflect.Int8, reflect.Int16, + reflect.Int32, reflect.Int64: + value = strconv.FormatInt(v.Int(), 10) + case reflect.Uint, reflect.Uint8, reflect.Uint16, + reflect.Uint32, reflect.Uint64, reflect.Uintptr: + value = strconv.FormatUint(v.Uint(), 10) + case reflect.Float32, reflect.Float64: + value = strconv.FormatFloat(v.Float(), 'g', -1, 32) + case reflect.Bool: + value = strconv.FormatBool(v.Bool()) + case reflect.String: + value = v.String() + default: + value = v.Type().String() + " value" + } + } + + switch valuesMap := headerOrQueryParams.(type) { + case url.Values: + if collectionType == "csv" && valuesMap.Get(keyPrefix) != "" { + valuesMap.Set(keyPrefix, valuesMap.Get(keyPrefix)+","+value) + } else { + valuesMap.Add(keyPrefix, value) + } + break + case map[string]string: + valuesMap[keyPrefix] = value + break + } +} + +// helper for converting interface{} parameters to json strings +func parameterToJson(obj interface{}) (string, error) { + jsonBuf, err := json.Marshal(obj) + if err != nil { + return "", err + } + return string(jsonBuf), err +} + +// callAPI do the request. +func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { + if c.cfg.Debug { + dump, err := httputil.DumpRequestOut(request, true) + if err != nil { + return nil, err + } + log.Printf("\n%s\n", string(dump)) + } + + resp, err := c.cfg.HTTPClient.Do(request) + if err != nil { + return resp, err + } + + if c.cfg.Debug { + dump, err := httputil.DumpResponse(resp, true) + if err != nil { + return resp, err + } + log.Printf("\n%s\n", string(dump)) + } + return resp, err +} + +// Allow modification of underlying config for alternate implementations and testing +// Caution: modifying the configuration while live can cause data races and potentially unwanted behavior +func (c *APIClient) GetConfig() *Configuration { + return c.cfg +} + +type formFile struct { + fileBytes []byte + fileName string + formFileName string +} + +// prepareRequest build the request +func (c *APIClient) prepareRequest( + ctx context.Context, + path string, method string, + postBody interface{}, + headerParams map[string]string, + queryParams url.Values, + formParams url.Values, + formFiles []formFile) (localVarRequest *http.Request, err error) { + + var body *bytes.Buffer + + // Detect postBody type and post. + if postBody != nil { + contentType := headerParams["Content-Type"] + if contentType == "" { + contentType = detectContentType(postBody) + headerParams["Content-Type"] = contentType + } + + body, err = setBody(postBody, contentType) + if err != nil { + return nil, err + } + } + + // add form parameters and file if available. + if strings.HasPrefix(headerParams["Content-Type"], "multipart/form-data") && len(formParams) > 0 || (len(formFiles) > 0) { + if body != nil { + return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + for _, formFile := range formFiles { + if len(formFile.fileBytes) > 0 && formFile.fileName != "" { + w.Boundary() + part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(formFile.fileBytes) + if err != nil { + return nil, err + } + } + } + + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { + if body != nil { + return nil, errors.New("Cannot specify postBody and x-www-form-urlencoded form at the same time.") + } + body = &bytes.Buffer{} + body.WriteString(formParams.Encode()) + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Override request host, if applicable + if c.cfg.Host != "" { + url.Host = c.cfg.Host + } + + // Override request scheme, if applicable + if c.cfg.Scheme != "" { + url.Scheme = c.cfg.Scheme + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string { + pieces := strings.Split(s, "=") + pieces[0] = queryDescape.Replace(pieces[0]) + return strings.Join(pieces, "=") + }) + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers[h] = []string{v} + } + localVarRequest.Header = headers + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + // OAuth2 authentication + if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { + // We were able to grab an oauth2 token from the context + var latestToken *oauth2.Token + if latestToken, err = tok.Token(); err != nil { + return nil, err + } + + latestToken.SetAuthHeader(localVarRequest) + } + + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + return localVarRequest, nil +} + +func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } + if s, ok := v.(*string); ok { + *s = string(b) + return nil + } + if f, ok := v.(*os.File); ok { + f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = f.Write(b) + if err != nil { + return + } + _, err = f.Seek(0, io.SeekStart) + err = os.Remove(f.Name()) + return + } + if f, ok := v.(**os.File); ok { + *f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = (*f).Write(b) + if err != nil { + return + } + _, err = (*f).Seek(0, io.SeekStart) + err = os.Remove((*f).Name()) + return + } + if xmlCheck.MatchString(contentType) { + if err = xml.Unmarshal(b, v); err != nil { + return err + } + return nil + } + if jsonCheck.MatchString(contentType) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return errors.New("Unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { // simple model + return err + } + return nil + } + return errors.New("undefined response type") +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(filepath.Clean(path)) + if err != nil { + return err + } + err = file.Close() + if err != nil { + return err + } + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if fp, ok := body.(*os.File); ok { + _, err = bodyBuf.ReadFrom(fp) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if s, ok := body.(*string); ok { + _, err = bodyBuf.WriteString(*s) + } else if jsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if xmlCheck.MatchString(contentType) { + var bs []byte + bs, err = xml.Marshal(body) + if err == nil { + bodyBuf.Write(bs) + } + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("invalid body type %s\n", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } else { + expires = now.Add(lifetime) + } + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) +} + +// GenericOpenAPIError Provides access to the body, error and model on returned errors. +type GenericOpenAPIError struct { + body []byte + error string + model interface{} +} + +// Error returns non-empty string if there was an error. +func (e GenericOpenAPIError) Error() string { + return e.error +} + +// Body returns the raw bytes of the response +func (e GenericOpenAPIError) Body() []byte { + return e.body +} + +// Model returns the unpacked model of the error +func (e GenericOpenAPIError) Model() interface{} { + return e.model +} + +// format error message using title and detail when model implements rfc7807 +func formatErrorMessage(status string, v interface{}) string { + str := "" + metaValue := reflect.ValueOf(v).Elem() + + if metaValue.Kind() == reflect.Struct { + field := metaValue.FieldByName("Title") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s", field.Interface()) + } + + field = metaValue.FieldByName("Detail") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s (%s)", str, field.Interface()) + } + } + + return strings.TrimSpace(fmt.Sprintf("%s %s", status, str)) +} diff --git a/internal/lbaas/v1/configuration.go b/internal/lbaas/v1/configuration.go new file mode 100644 index 000000000..cc055b006 --- /dev/null +++ b/internal/lbaas/v1/configuration.go @@ -0,0 +1,217 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "context" + "fmt" + "net/http" + "strings" +) + +// contextKeys are used to identify the type of value in the context. +// Since these are string, it is possible to get a short description of the +// context key for logging and debugging using key.String(). + +type contextKey string + +func (c contextKey) String() string { + return "auth " + string(c) +} + +var ( + // ContextOAuth2 takes an oauth2.TokenSource as authentication for the request. + ContextOAuth2 = contextKey("token") + + // ContextServerIndex uses a server configuration from the index. + ContextServerIndex = contextKey("serverIndex") + + // ContextOperationServerIndices uses a server configuration from the index mapping. + ContextOperationServerIndices = contextKey("serverOperationIndices") + + // ContextServerVariables overrides a server configuration variables. + ContextServerVariables = contextKey("serverVariables") + + // ContextOperationServerVariables overrides a server configuration variables using operation specific values. + ContextOperationServerVariables = contextKey("serverOperationVariables") +) + +// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth +type BasicAuth struct { + UserName string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` +} + +// APIKey provides API key based authentication to a request passed via context using ContextAPIKey +type APIKey struct { + Key string + Prefix string +} + +// ServerVariable stores the information about a server variable +type ServerVariable struct { + Description string + DefaultValue string + EnumValues []string +} + +// ServerConfiguration stores the information about a server +type ServerConfiguration struct { + URL string + Description string + Variables map[string]ServerVariable +} + +// ServerConfigurations stores multiple ServerConfiguration items +type ServerConfigurations []ServerConfiguration + +// Configuration stores the configuration of the API client +type Configuration struct { + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + Debug bool `json:"debug,omitempty"` + Servers ServerConfigurations + OperationServers map[string]ServerConfigurations + HTTPClient *http.Client +} + +// NewConfiguration returns a new Configuration object +func NewConfiguration() *Configuration { + cfg := &Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "metal-lbaas-go/0.22.2", + Debug: false, + Servers: ServerConfigurations{ + { + URL: "https://lb.metalctrl.io", + Description: "Production Server", + }, + }, + OperationServers: map[string]ServerConfigurations{}, + } + return cfg +} + +// AddDefaultHeader adds a new HTTP header to the default header in the request +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} + +// URL formats template on a index using given variables +func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { + if index < 0 || len(sc) <= index { + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) + } + server := sc[index] + url := server.URL + + // go through variables and replace placeholders + for name, variable := range server.Variables { + if value, ok := variables[name]; ok { + found := bool(len(variable.EnumValues) == 0) + for _, enumValue := range variable.EnumValues { + if value == enumValue { + found = true + } + } + if !found { + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + } + url = strings.Replace(url, "{"+name+"}", value, -1) + } else { + url = strings.Replace(url, "{"+name+"}", variable.DefaultValue, -1) + } + } + return url, nil +} + +// ServerURL returns URL based on server settings +func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error) { + return c.Servers.URL(index, variables) +} + +func getServerIndex(ctx context.Context) (int, error) { + si := ctx.Value(ContextServerIndex) + if si != nil { + if index, ok := si.(int); ok { + return index, nil + } + return 0, reportError("Invalid type %T should be int", si) + } + return 0, nil +} + +func getServerOperationIndex(ctx context.Context, endpoint string) (int, error) { + osi := ctx.Value(ContextOperationServerIndices) + if osi != nil { + if operationIndices, ok := osi.(map[string]int); !ok { + return 0, reportError("Invalid type %T should be map[string]int", osi) + } else { + index, ok := operationIndices[endpoint] + if ok { + return index, nil + } + } + } + return getServerIndex(ctx) +} + +func getServerVariables(ctx context.Context) (map[string]string, error) { + sv := ctx.Value(ContextServerVariables) + if sv != nil { + if variables, ok := sv.(map[string]string); ok { + return variables, nil + } + return nil, reportError("ctx value of ContextServerVariables has invalid type %T should be map[string]string", sv) + } + return nil, nil +} + +func getServerOperationVariables(ctx context.Context, endpoint string) (map[string]string, error) { + osv := ctx.Value(ContextOperationServerVariables) + if osv != nil { + if operationVariables, ok := osv.(map[string]map[string]string); !ok { + return nil, reportError("ctx value of ContextOperationServerVariables has invalid type %T should be map[string]map[string]string", osv) + } else { + variables, ok := operationVariables[endpoint] + if ok { + return variables, nil + } + } + } + return getServerVariables(ctx) +} + +// ServerURLWithContext returns a new server URL given an endpoint +func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error) { + sc, ok := c.OperationServers[endpoint] + if !ok { + sc = c.Servers + } + + if ctx == nil { + return sc.URL(0, nil) + } + + index, err := getServerOperationIndex(ctx, endpoint) + if err != nil { + return "", err + } + + variables, err := getServerOperationVariables(ctx, endpoint) + if err != nil { + return "", err + } + + return sc.URL(index, variables) +} diff --git a/internal/lbaas/v1/model_load_balancer.go b/internal/lbaas/v1/model_load_balancer.go new file mode 100644 index 000000000..793d399d8 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer.go @@ -0,0 +1,403 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "time" +) + +// checks if the LoadBalancer type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancer{} + +// LoadBalancer struct for LoadBalancer +type LoadBalancer struct { + // ID of the load balancer + Id string `json:"id"` + // Date and time of creation + CreatedAt time.Time `json:"created_at"` + // Date and time of last update + UpdatedAt time.Time `json:"updated_at"` + // A name for the load balancer + Name string `json:"name"` + Provider Provider `json:"provider"` + // A list of ports assigned to the load balancer + Ports []LoadBalancerPort `json:"ports"` + // A list of pool names and ids assigned to the load balancer + Pools [][]LoadBalancerPoolShort `json:"pools,omitempty"` + // A list of associated ip addresses + Ips []string `json:"ips,omitempty"` + Location *LoadBalancerLocation `json:"location,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancer LoadBalancer + +// NewLoadBalancer instantiates a new LoadBalancer object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancer(id string, createdAt time.Time, updatedAt time.Time, name string, provider Provider, ports []LoadBalancerPort) *LoadBalancer { + this := LoadBalancer{} + this.Id = id + this.CreatedAt = createdAt + this.UpdatedAt = updatedAt + this.Name = name + this.Provider = provider + this.Ports = ports + return &this +} + +// NewLoadBalancerWithDefaults instantiates a new LoadBalancer object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerWithDefaults() *LoadBalancer { + this := LoadBalancer{} + return &this +} + +// GetId returns the Id field value +func (o *LoadBalancer) GetId() string { + if o == nil { + var ret string + return ret + } + + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *LoadBalancer) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value +func (o *LoadBalancer) SetId(v string) { + o.Id = v +} + +// GetCreatedAt returns the CreatedAt field value +func (o *LoadBalancer) GetCreatedAt() time.Time { + if o == nil { + var ret time.Time + return ret + } + + return o.CreatedAt +} + +// GetCreatedAtOk returns a tuple with the CreatedAt field value +// and a boolean to check if the value has been set. +func (o *LoadBalancer) GetCreatedAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return &o.CreatedAt, true +} + +// SetCreatedAt sets field value +func (o *LoadBalancer) SetCreatedAt(v time.Time) { + o.CreatedAt = v +} + +// GetUpdatedAt returns the UpdatedAt field value +func (o *LoadBalancer) GetUpdatedAt() time.Time { + if o == nil { + var ret time.Time + return ret + } + + return o.UpdatedAt +} + +// GetUpdatedAtOk returns a tuple with the UpdatedAt field value +// and a boolean to check if the value has been set. +func (o *LoadBalancer) GetUpdatedAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return &o.UpdatedAt, true +} + +// SetUpdatedAt sets field value +func (o *LoadBalancer) SetUpdatedAt(v time.Time) { + o.UpdatedAt = v +} + +// GetName returns the Name field value +func (o *LoadBalancer) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *LoadBalancer) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *LoadBalancer) SetName(v string) { + o.Name = v +} + +// GetProvider returns the Provider field value +func (o *LoadBalancer) GetProvider() Provider { + if o == nil { + var ret Provider + return ret + } + + return o.Provider +} + +// GetProviderOk returns a tuple with the Provider field value +// and a boolean to check if the value has been set. +func (o *LoadBalancer) GetProviderOk() (*Provider, bool) { + if o == nil { + return nil, false + } + return &o.Provider, true +} + +// SetProvider sets field value +func (o *LoadBalancer) SetProvider(v Provider) { + o.Provider = v +} + +// GetPorts returns the Ports field value +func (o *LoadBalancer) GetPorts() []LoadBalancerPort { + if o == nil { + var ret []LoadBalancerPort + return ret + } + + return o.Ports +} + +// GetPortsOk returns a tuple with the Ports field value +// and a boolean to check if the value has been set. +func (o *LoadBalancer) GetPortsOk() ([]LoadBalancerPort, bool) { + if o == nil { + return nil, false + } + return o.Ports, true +} + +// SetPorts sets field value +func (o *LoadBalancer) SetPorts(v []LoadBalancerPort) { + o.Ports = v +} + +// GetPools returns the Pools field value if set, zero value otherwise. +func (o *LoadBalancer) GetPools() [][]LoadBalancerPoolShort { + if o == nil || IsNil(o.Pools) { + var ret [][]LoadBalancerPoolShort + return ret + } + return o.Pools +} + +// GetPoolsOk returns a tuple with the Pools field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancer) GetPoolsOk() ([][]LoadBalancerPoolShort, bool) { + if o == nil || IsNil(o.Pools) { + return nil, false + } + return o.Pools, true +} + +// HasPools returns a boolean if a field has been set. +func (o *LoadBalancer) HasPools() bool { + if o != nil && !IsNil(o.Pools) { + return true + } + + return false +} + +// SetPools gets a reference to the given []LoadBalancerPoolShort and assigns it to the Pools field. +func (o *LoadBalancer) SetPools(v [][]LoadBalancerPoolShort) { + o.Pools = v +} + +// GetIps returns the Ips field value if set, zero value otherwise. +func (o *LoadBalancer) GetIps() []string { + if o == nil || IsNil(o.Ips) { + var ret []string + return ret + } + return o.Ips +} + +// GetIpsOk returns a tuple with the Ips field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancer) GetIpsOk() ([]string, bool) { + if o == nil || IsNil(o.Ips) { + return nil, false + } + return o.Ips, true +} + +// HasIps returns a boolean if a field has been set. +func (o *LoadBalancer) HasIps() bool { + if o != nil && !IsNil(o.Ips) { + return true + } + + return false +} + +// SetIps gets a reference to the given []string and assigns it to the Ips field. +func (o *LoadBalancer) SetIps(v []string) { + o.Ips = v +} + +// GetLocation returns the Location field value if set, zero value otherwise. +func (o *LoadBalancer) GetLocation() LoadBalancerLocation { + if o == nil || IsNil(o.Location) { + var ret LoadBalancerLocation + return ret + } + return *o.Location +} + +// GetLocationOk returns a tuple with the Location field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancer) GetLocationOk() (*LoadBalancerLocation, bool) { + if o == nil || IsNil(o.Location) { + return nil, false + } + return o.Location, true +} + +// HasLocation returns a boolean if a field has been set. +func (o *LoadBalancer) HasLocation() bool { + if o != nil && !IsNil(o.Location) { + return true + } + + return false +} + +// SetLocation gets a reference to the given LoadBalancerLocation and assigns it to the Location field. +func (o *LoadBalancer) SetLocation(v LoadBalancerLocation) { + o.Location = &v +} + +func (o LoadBalancer) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancer) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["id"] = o.Id + toSerialize["created_at"] = o.CreatedAt + toSerialize["updated_at"] = o.UpdatedAt + toSerialize["name"] = o.Name + toSerialize["provider"] = o.Provider + toSerialize["ports"] = o.Ports + if !IsNil(o.Pools) { + toSerialize["pools"] = o.Pools + } + if !IsNil(o.Ips) { + toSerialize["ips"] = o.Ips + } + if !IsNil(o.Location) { + toSerialize["location"] = o.Location + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancer) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancer := _LoadBalancer{} + + err = json.Unmarshal(bytes, &varLoadBalancer) + + if err != nil { + return err + } + + *o = LoadBalancer(varLoadBalancer) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "id") + delete(additionalProperties, "created_at") + delete(additionalProperties, "updated_at") + delete(additionalProperties, "name") + delete(additionalProperties, "provider") + delete(additionalProperties, "ports") + delete(additionalProperties, "pools") + delete(additionalProperties, "ips") + delete(additionalProperties, "location") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancer struct { + value *LoadBalancer + isSet bool +} + +func (v NullableLoadBalancer) Get() *LoadBalancer { + return v.value +} + +func (v *NullableLoadBalancer) Set(val *LoadBalancer) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancer) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancer) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancer(val *LoadBalancer) *NullableLoadBalancer { + return &NullableLoadBalancer{value: val, isSet: true} +} + +func (v NullableLoadBalancer) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancer) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_collection.go b/internal/lbaas/v1/model_load_balancer_collection.go new file mode 100644 index 000000000..4159c5f83 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_collection.go @@ -0,0 +1,144 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerCollection type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerCollection{} + +// LoadBalancerCollection struct for LoadBalancerCollection +type LoadBalancerCollection struct { + Loadbalancers []LoadBalancer `json:"loadbalancers"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerCollection LoadBalancerCollection + +// NewLoadBalancerCollection instantiates a new LoadBalancerCollection object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerCollection(loadbalancers []LoadBalancer) *LoadBalancerCollection { + this := LoadBalancerCollection{} + this.Loadbalancers = loadbalancers + return &this +} + +// NewLoadBalancerCollectionWithDefaults instantiates a new LoadBalancerCollection object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerCollectionWithDefaults() *LoadBalancerCollection { + this := LoadBalancerCollection{} + return &this +} + +// GetLoadbalancers returns the Loadbalancers field value +func (o *LoadBalancerCollection) GetLoadbalancers() []LoadBalancer { + if o == nil { + var ret []LoadBalancer + return ret + } + + return o.Loadbalancers +} + +// GetLoadbalancersOk returns a tuple with the Loadbalancers field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerCollection) GetLoadbalancersOk() ([]LoadBalancer, bool) { + if o == nil { + return nil, false + } + return o.Loadbalancers, true +} + +// SetLoadbalancers sets field value +func (o *LoadBalancerCollection) SetLoadbalancers(v []LoadBalancer) { + o.Loadbalancers = v +} + +func (o LoadBalancerCollection) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerCollection) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["loadbalancers"] = o.Loadbalancers + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerCollection) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerCollection := _LoadBalancerCollection{} + + err = json.Unmarshal(bytes, &varLoadBalancerCollection) + + if err != nil { + return err + } + + *o = LoadBalancerCollection(varLoadBalancerCollection) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "loadbalancers") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerCollection struct { + value *LoadBalancerCollection + isSet bool +} + +func (v NullableLoadBalancerCollection) Get() *LoadBalancerCollection { + return v.value +} + +func (v *NullableLoadBalancerCollection) Set(val *LoadBalancerCollection) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerCollection) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerCollection) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerCollection(val *LoadBalancerCollection) *NullableLoadBalancerCollection { + return &NullableLoadBalancerCollection{value: val, isSet: true} +} + +func (v NullableLoadBalancerCollection) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerCollection) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_create.go b/internal/lbaas/v1/model_load_balancer_create.go new file mode 100644 index 000000000..23f3564d7 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_create.go @@ -0,0 +1,232 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerCreate type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerCreate{} + +// LoadBalancerCreate struct for LoadBalancerCreate +type LoadBalancerCreate struct { + // Name of load balancer + Name string `json:"name"` + // ID of location load balancer to be deployed in + LocationId string `json:"location_id"` + // Port IDs to associate with load balancer + PortIds []string `json:"port_ids"` + // ID of load balancer provider + ProviderId string `json:"provider_id"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerCreate LoadBalancerCreate + +// NewLoadBalancerCreate instantiates a new LoadBalancerCreate object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerCreate(name string, locationId string, portIds []string, providerId string) *LoadBalancerCreate { + this := LoadBalancerCreate{} + this.Name = name + this.LocationId = locationId + this.PortIds = portIds + this.ProviderId = providerId + return &this +} + +// NewLoadBalancerCreateWithDefaults instantiates a new LoadBalancerCreate object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerCreateWithDefaults() *LoadBalancerCreate { + this := LoadBalancerCreate{} + return &this +} + +// GetName returns the Name field value +func (o *LoadBalancerCreate) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerCreate) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *LoadBalancerCreate) SetName(v string) { + o.Name = v +} + +// GetLocationId returns the LocationId field value +func (o *LoadBalancerCreate) GetLocationId() string { + if o == nil { + var ret string + return ret + } + + return o.LocationId +} + +// GetLocationIdOk returns a tuple with the LocationId field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerCreate) GetLocationIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.LocationId, true +} + +// SetLocationId sets field value +func (o *LoadBalancerCreate) SetLocationId(v string) { + o.LocationId = v +} + +// GetPortIds returns the PortIds field value +func (o *LoadBalancerCreate) GetPortIds() []string { + if o == nil { + var ret []string + return ret + } + + return o.PortIds +} + +// GetPortIdsOk returns a tuple with the PortIds field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerCreate) GetPortIdsOk() ([]string, bool) { + if o == nil { + return nil, false + } + return o.PortIds, true +} + +// SetPortIds sets field value +func (o *LoadBalancerCreate) SetPortIds(v []string) { + o.PortIds = v +} + +// GetProviderId returns the ProviderId field value +func (o *LoadBalancerCreate) GetProviderId() string { + if o == nil { + var ret string + return ret + } + + return o.ProviderId +} + +// GetProviderIdOk returns a tuple with the ProviderId field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerCreate) GetProviderIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProviderId, true +} + +// SetProviderId sets field value +func (o *LoadBalancerCreate) SetProviderId(v string) { + o.ProviderId = v +} + +func (o LoadBalancerCreate) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerCreate) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["name"] = o.Name + toSerialize["location_id"] = o.LocationId + toSerialize["port_ids"] = o.PortIds + toSerialize["provider_id"] = o.ProviderId + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerCreate) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerCreate := _LoadBalancerCreate{} + + err = json.Unmarshal(bytes, &varLoadBalancerCreate) + + if err != nil { + return err + } + + *o = LoadBalancerCreate(varLoadBalancerCreate) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "name") + delete(additionalProperties, "location_id") + delete(additionalProperties, "port_ids") + delete(additionalProperties, "provider_id") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerCreate struct { + value *LoadBalancerCreate + isSet bool +} + +func (v NullableLoadBalancerCreate) Get() *LoadBalancerCreate { + return v.value +} + +func (v *NullableLoadBalancerCreate) Set(val *LoadBalancerCreate) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerCreate) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerCreate) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerCreate(val *LoadBalancerCreate) *NullableLoadBalancerCreate { + return &NullableLoadBalancerCreate{value: val, isSet: true} +} + +func (v NullableLoadBalancerCreate) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerCreate) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_location.go b/internal/lbaas/v1/model_load_balancer_location.go new file mode 100644 index 000000000..f266f8401 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_location.go @@ -0,0 +1,269 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "time" +) + +// checks if the LoadBalancerLocation type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerLocation{} + +// LoadBalancerLocation struct for LoadBalancerLocation +type LoadBalancerLocation struct { + // ID of a location + Id *string `json:"id,omitempty"` + // Date and time of creation + CreatedAt *time.Time `json:"created_at,omitempty"` + // Date and time of last update + UpdatedAt *time.Time `json:"updated_at,omitempty"` + // A name for the location + Name *string `json:"name,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerLocation LoadBalancerLocation + +// NewLoadBalancerLocation instantiates a new LoadBalancerLocation object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerLocation() *LoadBalancerLocation { + this := LoadBalancerLocation{} + return &this +} + +// NewLoadBalancerLocationWithDefaults instantiates a new LoadBalancerLocation object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerLocationWithDefaults() *LoadBalancerLocation { + this := LoadBalancerLocation{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *LoadBalancerLocation) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerLocation) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *LoadBalancerLocation) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *LoadBalancerLocation) SetId(v string) { + o.Id = &v +} + +// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise. +func (o *LoadBalancerLocation) GetCreatedAt() time.Time { + if o == nil || IsNil(o.CreatedAt) { + var ret time.Time + return ret + } + return *o.CreatedAt +} + +// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerLocation) GetCreatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.CreatedAt) { + return nil, false + } + return o.CreatedAt, true +} + +// HasCreatedAt returns a boolean if a field has been set. +func (o *LoadBalancerLocation) HasCreatedAt() bool { + if o != nil && !IsNil(o.CreatedAt) { + return true + } + + return false +} + +// SetCreatedAt gets a reference to the given time.Time and assigns it to the CreatedAt field. +func (o *LoadBalancerLocation) SetCreatedAt(v time.Time) { + o.CreatedAt = &v +} + +// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise. +func (o *LoadBalancerLocation) GetUpdatedAt() time.Time { + if o == nil || IsNil(o.UpdatedAt) { + var ret time.Time + return ret + } + return *o.UpdatedAt +} + +// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerLocation) GetUpdatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.UpdatedAt) { + return nil, false + } + return o.UpdatedAt, true +} + +// HasUpdatedAt returns a boolean if a field has been set. +func (o *LoadBalancerLocation) HasUpdatedAt() bool { + if o != nil && !IsNil(o.UpdatedAt) { + return true + } + + return false +} + +// SetUpdatedAt gets a reference to the given time.Time and assigns it to the UpdatedAt field. +func (o *LoadBalancerLocation) SetUpdatedAt(v time.Time) { + o.UpdatedAt = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *LoadBalancerLocation) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerLocation) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *LoadBalancerLocation) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *LoadBalancerLocation) SetName(v string) { + o.Name = &v +} + +func (o LoadBalancerLocation) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerLocation) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.CreatedAt) { + toSerialize["created_at"] = o.CreatedAt + } + if !IsNil(o.UpdatedAt) { + toSerialize["updated_at"] = o.UpdatedAt + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerLocation) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerLocation := _LoadBalancerLocation{} + + err = json.Unmarshal(bytes, &varLoadBalancerLocation) + + if err != nil { + return err + } + + *o = LoadBalancerLocation(varLoadBalancerLocation) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "id") + delete(additionalProperties, "created_at") + delete(additionalProperties, "updated_at") + delete(additionalProperties, "name") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerLocation struct { + value *LoadBalancerLocation + isSet bool +} + +func (v NullableLoadBalancerLocation) Get() *LoadBalancerLocation { + return v.value +} + +func (v *NullableLoadBalancerLocation) Set(val *LoadBalancerLocation) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerLocation) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerLocation) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerLocation(val *LoadBalancerLocation) *NullableLoadBalancerLocation { + return &NullableLoadBalancerLocation{value: val, isSet: true} +} + +func (v NullableLoadBalancerLocation) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerLocation) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool.go b/internal/lbaas/v1/model_load_balancer_pool.go new file mode 100644 index 000000000..3e828ef70 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool.go @@ -0,0 +1,404 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "time" +) + +// checks if the LoadBalancerPool type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPool{} + +// LoadBalancerPool struct for LoadBalancerPool +type LoadBalancerPool struct { + // ID of the pool + Id string `json:"id"` + // Date and time of creation + CreatedAt time.Time `json:"created_at"` + // Date and time of last update + UpdatedAt time.Time `json:"updated_at"` + // A name for the pool + Name string `json:"name"` + Protocol LoadBalancerPoolProtocol `json:"protocol"` + // ID of project pool is assigned to + ProjectId string `json:"project_id"` + // A list of ports associated with the pool + Ports []LoadBalancerPort `json:"ports,omitempty"` + // A list of origins assigned to the pool + Origins []LoadBalancerPoolOrigin `json:"origins,omitempty"` + // A list of load balancers assigned to the pool + Loadbalancers []LoadBalancerShort `json:"loadbalancers,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPool LoadBalancerPool + +// NewLoadBalancerPool instantiates a new LoadBalancerPool object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPool(id string, createdAt time.Time, updatedAt time.Time, name string, protocol LoadBalancerPoolProtocol, projectId string) *LoadBalancerPool { + this := LoadBalancerPool{} + this.Id = id + this.CreatedAt = createdAt + this.UpdatedAt = updatedAt + this.Name = name + this.Protocol = protocol + this.ProjectId = projectId + return &this +} + +// NewLoadBalancerPoolWithDefaults instantiates a new LoadBalancerPool object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPoolWithDefaults() *LoadBalancerPool { + this := LoadBalancerPool{} + return &this +} + +// GetId returns the Id field value +func (o *LoadBalancerPool) GetId() string { + if o == nil { + var ret string + return ret + } + + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPool) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value +func (o *LoadBalancerPool) SetId(v string) { + o.Id = v +} + +// GetCreatedAt returns the CreatedAt field value +func (o *LoadBalancerPool) GetCreatedAt() time.Time { + if o == nil { + var ret time.Time + return ret + } + + return o.CreatedAt +} + +// GetCreatedAtOk returns a tuple with the CreatedAt field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPool) GetCreatedAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return &o.CreatedAt, true +} + +// SetCreatedAt sets field value +func (o *LoadBalancerPool) SetCreatedAt(v time.Time) { + o.CreatedAt = v +} + +// GetUpdatedAt returns the UpdatedAt field value +func (o *LoadBalancerPool) GetUpdatedAt() time.Time { + if o == nil { + var ret time.Time + return ret + } + + return o.UpdatedAt +} + +// GetUpdatedAtOk returns a tuple with the UpdatedAt field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPool) GetUpdatedAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return &o.UpdatedAt, true +} + +// SetUpdatedAt sets field value +func (o *LoadBalancerPool) SetUpdatedAt(v time.Time) { + o.UpdatedAt = v +} + +// GetName returns the Name field value +func (o *LoadBalancerPool) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPool) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *LoadBalancerPool) SetName(v string) { + o.Name = v +} + +// GetProtocol returns the Protocol field value +func (o *LoadBalancerPool) GetProtocol() LoadBalancerPoolProtocol { + if o == nil { + var ret LoadBalancerPoolProtocol + return ret + } + + return o.Protocol +} + +// GetProtocolOk returns a tuple with the Protocol field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPool) GetProtocolOk() (*LoadBalancerPoolProtocol, bool) { + if o == nil { + return nil, false + } + return &o.Protocol, true +} + +// SetProtocol sets field value +func (o *LoadBalancerPool) SetProtocol(v LoadBalancerPoolProtocol) { + o.Protocol = v +} + +// GetProjectId returns the ProjectId field value +func (o *LoadBalancerPool) GetProjectId() string { + if o == nil { + var ret string + return ret + } + + return o.ProjectId +} + +// GetProjectIdOk returns a tuple with the ProjectId field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPool) GetProjectIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ProjectId, true +} + +// SetProjectId sets field value +func (o *LoadBalancerPool) SetProjectId(v string) { + o.ProjectId = v +} + +// GetPorts returns the Ports field value if set, zero value otherwise. +func (o *LoadBalancerPool) GetPorts() []LoadBalancerPort { + if o == nil || IsNil(o.Ports) { + var ret []LoadBalancerPort + return ret + } + return o.Ports +} + +// GetPortsOk returns a tuple with the Ports field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPool) GetPortsOk() ([]LoadBalancerPort, bool) { + if o == nil || IsNil(o.Ports) { + return nil, false + } + return o.Ports, true +} + +// HasPorts returns a boolean if a field has been set. +func (o *LoadBalancerPool) HasPorts() bool { + if o != nil && !IsNil(o.Ports) { + return true + } + + return false +} + +// SetPorts gets a reference to the given []LoadBalancerPort and assigns it to the Ports field. +func (o *LoadBalancerPool) SetPorts(v []LoadBalancerPort) { + o.Ports = v +} + +// GetOrigins returns the Origins field value if set, zero value otherwise. +func (o *LoadBalancerPool) GetOrigins() []LoadBalancerPoolOrigin { + if o == nil || IsNil(o.Origins) { + var ret []LoadBalancerPoolOrigin + return ret + } + return o.Origins +} + +// GetOriginsOk returns a tuple with the Origins field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPool) GetOriginsOk() ([]LoadBalancerPoolOrigin, bool) { + if o == nil || IsNil(o.Origins) { + return nil, false + } + return o.Origins, true +} + +// HasOrigins returns a boolean if a field has been set. +func (o *LoadBalancerPool) HasOrigins() bool { + if o != nil && !IsNil(o.Origins) { + return true + } + + return false +} + +// SetOrigins gets a reference to the given []LoadBalancerPoolOrigin and assigns it to the Origins field. +func (o *LoadBalancerPool) SetOrigins(v []LoadBalancerPoolOrigin) { + o.Origins = v +} + +// GetLoadbalancers returns the Loadbalancers field value if set, zero value otherwise. +func (o *LoadBalancerPool) GetLoadbalancers() []LoadBalancerShort { + if o == nil || IsNil(o.Loadbalancers) { + var ret []LoadBalancerShort + return ret + } + return o.Loadbalancers +} + +// GetLoadbalancersOk returns a tuple with the Loadbalancers field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPool) GetLoadbalancersOk() ([]LoadBalancerShort, bool) { + if o == nil || IsNil(o.Loadbalancers) { + return nil, false + } + return o.Loadbalancers, true +} + +// HasLoadbalancers returns a boolean if a field has been set. +func (o *LoadBalancerPool) HasLoadbalancers() bool { + if o != nil && !IsNil(o.Loadbalancers) { + return true + } + + return false +} + +// SetLoadbalancers gets a reference to the given []LoadBalancerShort and assigns it to the Loadbalancers field. +func (o *LoadBalancerPool) SetLoadbalancers(v []LoadBalancerShort) { + o.Loadbalancers = v +} + +func (o LoadBalancerPool) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPool) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["id"] = o.Id + toSerialize["created_at"] = o.CreatedAt + toSerialize["updated_at"] = o.UpdatedAt + toSerialize["name"] = o.Name + toSerialize["protocol"] = o.Protocol + toSerialize["project_id"] = o.ProjectId + if !IsNil(o.Ports) { + toSerialize["ports"] = o.Ports + } + if !IsNil(o.Origins) { + toSerialize["origins"] = o.Origins + } + if !IsNil(o.Loadbalancers) { + toSerialize["loadbalancers"] = o.Loadbalancers + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPool) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPool := _LoadBalancerPool{} + + err = json.Unmarshal(bytes, &varLoadBalancerPool) + + if err != nil { + return err + } + + *o = LoadBalancerPool(varLoadBalancerPool) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "id") + delete(additionalProperties, "created_at") + delete(additionalProperties, "updated_at") + delete(additionalProperties, "name") + delete(additionalProperties, "protocol") + delete(additionalProperties, "project_id") + delete(additionalProperties, "ports") + delete(additionalProperties, "origins") + delete(additionalProperties, "loadbalancers") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPool struct { + value *LoadBalancerPool + isSet bool +} + +func (v NullableLoadBalancerPool) Get() *LoadBalancerPool { + return v.value +} + +func (v *NullableLoadBalancerPool) Set(val *LoadBalancerPool) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPool) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPool(val *LoadBalancerPool) *NullableLoadBalancerPool { + return &NullableLoadBalancerPool{value: val, isSet: true} +} + +func (v NullableLoadBalancerPool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_collection.go b/internal/lbaas/v1/model_load_balancer_pool_collection.go new file mode 100644 index 000000000..5b9eee7ee --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_collection.go @@ -0,0 +1,144 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerPoolCollection type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPoolCollection{} + +// LoadBalancerPoolCollection struct for LoadBalancerPoolCollection +type LoadBalancerPoolCollection struct { + Pools []LoadBalancerPool `json:"pools"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPoolCollection LoadBalancerPoolCollection + +// NewLoadBalancerPoolCollection instantiates a new LoadBalancerPoolCollection object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPoolCollection(pools []LoadBalancerPool) *LoadBalancerPoolCollection { + this := LoadBalancerPoolCollection{} + this.Pools = pools + return &this +} + +// NewLoadBalancerPoolCollectionWithDefaults instantiates a new LoadBalancerPoolCollection object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPoolCollectionWithDefaults() *LoadBalancerPoolCollection { + this := LoadBalancerPoolCollection{} + return &this +} + +// GetPools returns the Pools field value +func (o *LoadBalancerPoolCollection) GetPools() []LoadBalancerPool { + if o == nil { + var ret []LoadBalancerPool + return ret + } + + return o.Pools +} + +// GetPoolsOk returns a tuple with the Pools field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolCollection) GetPoolsOk() ([]LoadBalancerPool, bool) { + if o == nil { + return nil, false + } + return o.Pools, true +} + +// SetPools sets field value +func (o *LoadBalancerPoolCollection) SetPools(v []LoadBalancerPool) { + o.Pools = v +} + +func (o LoadBalancerPoolCollection) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPoolCollection) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["pools"] = o.Pools + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPoolCollection) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPoolCollection := _LoadBalancerPoolCollection{} + + err = json.Unmarshal(bytes, &varLoadBalancerPoolCollection) + + if err != nil { + return err + } + + *o = LoadBalancerPoolCollection(varLoadBalancerPoolCollection) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "pools") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPoolCollection struct { + value *LoadBalancerPoolCollection + isSet bool +} + +func (v NullableLoadBalancerPoolCollection) Get() *LoadBalancerPoolCollection { + return v.value +} + +func (v *NullableLoadBalancerPoolCollection) Set(val *LoadBalancerPoolCollection) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolCollection) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolCollection) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolCollection(val *LoadBalancerPoolCollection) *NullableLoadBalancerPoolCollection { + return &NullableLoadBalancerPoolCollection{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolCollection) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolCollection) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_create.go b/internal/lbaas/v1/model_load_balancer_pool_create.go new file mode 100644 index 000000000..966e95c49 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_create.go @@ -0,0 +1,249 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerPoolCreate type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPoolCreate{} + +// LoadBalancerPoolCreate struct for LoadBalancerPoolCreate +type LoadBalancerPoolCreate struct { + // Name of the load balancer pool + Name string `json:"name"` + Protocol LoadBalancerPoolCreateProtocol `json:"protocol"` + // Port ids to associate with pool + PortIds []string `json:"port_ids,omitempty"` + // Origin ids to associate with pool + OriginIds []string `json:"origin_ids,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPoolCreate LoadBalancerPoolCreate + +// NewLoadBalancerPoolCreate instantiates a new LoadBalancerPoolCreate object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPoolCreate(name string, protocol LoadBalancerPoolCreateProtocol) *LoadBalancerPoolCreate { + this := LoadBalancerPoolCreate{} + this.Name = name + this.Protocol = protocol + return &this +} + +// NewLoadBalancerPoolCreateWithDefaults instantiates a new LoadBalancerPoolCreate object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPoolCreateWithDefaults() *LoadBalancerPoolCreate { + this := LoadBalancerPoolCreate{} + return &this +} + +// GetName returns the Name field value +func (o *LoadBalancerPoolCreate) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolCreate) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *LoadBalancerPoolCreate) SetName(v string) { + o.Name = v +} + +// GetProtocol returns the Protocol field value +func (o *LoadBalancerPoolCreate) GetProtocol() LoadBalancerPoolCreateProtocol { + if o == nil { + var ret LoadBalancerPoolCreateProtocol + return ret + } + + return o.Protocol +} + +// GetProtocolOk returns a tuple with the Protocol field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolCreate) GetProtocolOk() (*LoadBalancerPoolCreateProtocol, bool) { + if o == nil { + return nil, false + } + return &o.Protocol, true +} + +// SetProtocol sets field value +func (o *LoadBalancerPoolCreate) SetProtocol(v LoadBalancerPoolCreateProtocol) { + o.Protocol = v +} + +// GetPortIds returns the PortIds field value if set, zero value otherwise. +func (o *LoadBalancerPoolCreate) GetPortIds() []string { + if o == nil || IsNil(o.PortIds) { + var ret []string + return ret + } + return o.PortIds +} + +// GetPortIdsOk returns a tuple with the PortIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolCreate) GetPortIdsOk() ([]string, bool) { + if o == nil || IsNil(o.PortIds) { + return nil, false + } + return o.PortIds, true +} + +// HasPortIds returns a boolean if a field has been set. +func (o *LoadBalancerPoolCreate) HasPortIds() bool { + if o != nil && !IsNil(o.PortIds) { + return true + } + + return false +} + +// SetPortIds gets a reference to the given []string and assigns it to the PortIds field. +func (o *LoadBalancerPoolCreate) SetPortIds(v []string) { + o.PortIds = v +} + +// GetOriginIds returns the OriginIds field value if set, zero value otherwise. +func (o *LoadBalancerPoolCreate) GetOriginIds() []string { + if o == nil || IsNil(o.OriginIds) { + var ret []string + return ret + } + return o.OriginIds +} + +// GetOriginIdsOk returns a tuple with the OriginIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolCreate) GetOriginIdsOk() ([]string, bool) { + if o == nil || IsNil(o.OriginIds) { + return nil, false + } + return o.OriginIds, true +} + +// HasOriginIds returns a boolean if a field has been set. +func (o *LoadBalancerPoolCreate) HasOriginIds() bool { + if o != nil && !IsNil(o.OriginIds) { + return true + } + + return false +} + +// SetOriginIds gets a reference to the given []string and assigns it to the OriginIds field. +func (o *LoadBalancerPoolCreate) SetOriginIds(v []string) { + o.OriginIds = v +} + +func (o LoadBalancerPoolCreate) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPoolCreate) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["name"] = o.Name + toSerialize["protocol"] = o.Protocol + if !IsNil(o.PortIds) { + toSerialize["port_ids"] = o.PortIds + } + if !IsNil(o.OriginIds) { + toSerialize["origin_ids"] = o.OriginIds + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPoolCreate) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPoolCreate := _LoadBalancerPoolCreate{} + + err = json.Unmarshal(bytes, &varLoadBalancerPoolCreate) + + if err != nil { + return err + } + + *o = LoadBalancerPoolCreate(varLoadBalancerPoolCreate) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "name") + delete(additionalProperties, "protocol") + delete(additionalProperties, "port_ids") + delete(additionalProperties, "origin_ids") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPoolCreate struct { + value *LoadBalancerPoolCreate + isSet bool +} + +func (v NullableLoadBalancerPoolCreate) Get() *LoadBalancerPoolCreate { + return v.value +} + +func (v *NullableLoadBalancerPoolCreate) Set(val *LoadBalancerPoolCreate) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolCreate) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolCreate) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolCreate(val *LoadBalancerPoolCreate) *NullableLoadBalancerPoolCreate { + return &NullableLoadBalancerPoolCreate{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolCreate) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolCreate) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_create_protocol.go b/internal/lbaas/v1/model_load_balancer_pool_create_protocol.go new file mode 100644 index 000000000..bf24e1b46 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_create_protocol.go @@ -0,0 +1,115 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "fmt" +) + +// LoadBalancerPoolCreateProtocol - Protocol to use for pool +type LoadBalancerPoolCreateProtocol struct { + LoadBalancerPoolProtocol *LoadBalancerPoolProtocol +} + +// LoadBalancerPoolProtocolAsLoadBalancerPoolCreateProtocol is a convenience function that returns LoadBalancerPoolProtocol wrapped in LoadBalancerPoolCreateProtocol +func LoadBalancerPoolProtocolAsLoadBalancerPoolCreateProtocol(v *LoadBalancerPoolProtocol) LoadBalancerPoolCreateProtocol { + return LoadBalancerPoolCreateProtocol{ + LoadBalancerPoolProtocol: v, + } +} + +// Unmarshal JSON data into one of the pointers in the struct +func (dst *LoadBalancerPoolCreateProtocol) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into LoadBalancerPoolProtocol + err = newStrictDecoder(data).Decode(&dst.LoadBalancerPoolProtocol) + if err == nil { + jsonLoadBalancerPoolProtocol, _ := json.Marshal(dst.LoadBalancerPoolProtocol) + if string(jsonLoadBalancerPoolProtocol) == "{}" { // empty struct + dst.LoadBalancerPoolProtocol = nil + } else { + match++ + } + } else { + dst.LoadBalancerPoolProtocol = nil + } + + if match > 1 { // more than 1 match + // reset to nil + dst.LoadBalancerPoolProtocol = nil + + return fmt.Errorf("data matches more than one schema in oneOf(LoadBalancerPoolCreateProtocol)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(LoadBalancerPoolCreateProtocol)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src LoadBalancerPoolCreateProtocol) MarshalJSON() ([]byte, error) { + if src.LoadBalancerPoolProtocol != nil { + return json.Marshal(&src.LoadBalancerPoolProtocol) + } + + return nil, nil // no data in oneOf schemas +} + +// Get the actual instance +func (obj *LoadBalancerPoolCreateProtocol) GetActualInstance() interface{} { + if obj == nil { + return nil + } + if obj.LoadBalancerPoolProtocol != nil { + return obj.LoadBalancerPoolProtocol + } + + // all schemas are nil + return nil +} + +type NullableLoadBalancerPoolCreateProtocol struct { + value *LoadBalancerPoolCreateProtocol + isSet bool +} + +func (v NullableLoadBalancerPoolCreateProtocol) Get() *LoadBalancerPoolCreateProtocol { + return v.value +} + +func (v *NullableLoadBalancerPoolCreateProtocol) Set(val *LoadBalancerPoolCreateProtocol) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolCreateProtocol) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolCreateProtocol) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolCreateProtocol(val *LoadBalancerPoolCreateProtocol) *NullableLoadBalancerPoolCreateProtocol { + return &NullableLoadBalancerPoolCreateProtocol{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolCreateProtocol) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolCreateProtocol) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_origin.go b/internal/lbaas/v1/model_load_balancer_pool_origin.go new file mode 100644 index 000000000..63e8e5355 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_origin.go @@ -0,0 +1,348 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "time" +) + +// checks if the LoadBalancerPoolOrigin type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPoolOrigin{} + +// LoadBalancerPoolOrigin struct for LoadBalancerPoolOrigin +type LoadBalancerPoolOrigin struct { + // ID of a port + Id string `json:"id"` + // Date and time of creation + CreatedAt time.Time `json:"created_at"` + // Date and time of last update + UpdatedAt time.Time `json:"updated_at"` + // A name for the origin + Name string `json:"name"` + // IP address of the origin + Target string `json:"target"` + PortNumber LoadBalancerPoolOriginPortNumber `json:"port_number"` + // If the origin is enabled + Active bool `json:"active"` + // ID of the pool the origin belongs to + PoolId string `json:"pool_id"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPoolOrigin LoadBalancerPoolOrigin + +// NewLoadBalancerPoolOrigin instantiates a new LoadBalancerPoolOrigin object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPoolOrigin(id string, createdAt time.Time, updatedAt time.Time, name string, target string, portNumber LoadBalancerPoolOriginPortNumber, active bool, poolId string) *LoadBalancerPoolOrigin { + this := LoadBalancerPoolOrigin{} + this.Id = id + this.CreatedAt = createdAt + this.UpdatedAt = updatedAt + this.Name = name + this.Target = target + this.PortNumber = portNumber + this.Active = active + this.PoolId = poolId + return &this +} + +// NewLoadBalancerPoolOriginWithDefaults instantiates a new LoadBalancerPoolOrigin object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPoolOriginWithDefaults() *LoadBalancerPoolOrigin { + this := LoadBalancerPoolOrigin{} + return &this +} + +// GetId returns the Id field value +func (o *LoadBalancerPoolOrigin) GetId() string { + if o == nil { + var ret string + return ret + } + + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOrigin) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value +func (o *LoadBalancerPoolOrigin) SetId(v string) { + o.Id = v +} + +// GetCreatedAt returns the CreatedAt field value +func (o *LoadBalancerPoolOrigin) GetCreatedAt() time.Time { + if o == nil { + var ret time.Time + return ret + } + + return o.CreatedAt +} + +// GetCreatedAtOk returns a tuple with the CreatedAt field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOrigin) GetCreatedAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return &o.CreatedAt, true +} + +// SetCreatedAt sets field value +func (o *LoadBalancerPoolOrigin) SetCreatedAt(v time.Time) { + o.CreatedAt = v +} + +// GetUpdatedAt returns the UpdatedAt field value +func (o *LoadBalancerPoolOrigin) GetUpdatedAt() time.Time { + if o == nil { + var ret time.Time + return ret + } + + return o.UpdatedAt +} + +// GetUpdatedAtOk returns a tuple with the UpdatedAt field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOrigin) GetUpdatedAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return &o.UpdatedAt, true +} + +// SetUpdatedAt sets field value +func (o *LoadBalancerPoolOrigin) SetUpdatedAt(v time.Time) { + o.UpdatedAt = v +} + +// GetName returns the Name field value +func (o *LoadBalancerPoolOrigin) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOrigin) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *LoadBalancerPoolOrigin) SetName(v string) { + o.Name = v +} + +// GetTarget returns the Target field value +func (o *LoadBalancerPoolOrigin) GetTarget() string { + if o == nil { + var ret string + return ret + } + + return o.Target +} + +// GetTargetOk returns a tuple with the Target field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOrigin) GetTargetOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Target, true +} + +// SetTarget sets field value +func (o *LoadBalancerPoolOrigin) SetTarget(v string) { + o.Target = v +} + +// GetPortNumber returns the PortNumber field value +func (o *LoadBalancerPoolOrigin) GetPortNumber() LoadBalancerPoolOriginPortNumber { + if o == nil { + var ret LoadBalancerPoolOriginPortNumber + return ret + } + + return o.PortNumber +} + +// GetPortNumberOk returns a tuple with the PortNumber field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOrigin) GetPortNumberOk() (*LoadBalancerPoolOriginPortNumber, bool) { + if o == nil { + return nil, false + } + return &o.PortNumber, true +} + +// SetPortNumber sets field value +func (o *LoadBalancerPoolOrigin) SetPortNumber(v LoadBalancerPoolOriginPortNumber) { + o.PortNumber = v +} + +// GetActive returns the Active field value +func (o *LoadBalancerPoolOrigin) GetActive() bool { + if o == nil { + var ret bool + return ret + } + + return o.Active +} + +// GetActiveOk returns a tuple with the Active field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOrigin) GetActiveOk() (*bool, bool) { + if o == nil { + return nil, false + } + return &o.Active, true +} + +// SetActive sets field value +func (o *LoadBalancerPoolOrigin) SetActive(v bool) { + o.Active = v +} + +// GetPoolId returns the PoolId field value +func (o *LoadBalancerPoolOrigin) GetPoolId() string { + if o == nil { + var ret string + return ret + } + + return o.PoolId +} + +// GetPoolIdOk returns a tuple with the PoolId field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOrigin) GetPoolIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.PoolId, true +} + +// SetPoolId sets field value +func (o *LoadBalancerPoolOrigin) SetPoolId(v string) { + o.PoolId = v +} + +func (o LoadBalancerPoolOrigin) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPoolOrigin) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["id"] = o.Id + toSerialize["created_at"] = o.CreatedAt + toSerialize["updated_at"] = o.UpdatedAt + toSerialize["name"] = o.Name + toSerialize["target"] = o.Target + toSerialize["port_number"] = o.PortNumber + toSerialize["active"] = o.Active + toSerialize["pool_id"] = o.PoolId + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPoolOrigin) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPoolOrigin := _LoadBalancerPoolOrigin{} + + err = json.Unmarshal(bytes, &varLoadBalancerPoolOrigin) + + if err != nil { + return err + } + + *o = LoadBalancerPoolOrigin(varLoadBalancerPoolOrigin) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "id") + delete(additionalProperties, "created_at") + delete(additionalProperties, "updated_at") + delete(additionalProperties, "name") + delete(additionalProperties, "target") + delete(additionalProperties, "port_number") + delete(additionalProperties, "active") + delete(additionalProperties, "pool_id") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPoolOrigin struct { + value *LoadBalancerPoolOrigin + isSet bool +} + +func (v NullableLoadBalancerPoolOrigin) Get() *LoadBalancerPoolOrigin { + return v.value +} + +func (v *NullableLoadBalancerPoolOrigin) Set(val *LoadBalancerPoolOrigin) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolOrigin) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolOrigin) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolOrigin(val *LoadBalancerPoolOrigin) *NullableLoadBalancerPoolOrigin { + return &NullableLoadBalancerPoolOrigin{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolOrigin) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolOrigin) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_origin_collection.go b/internal/lbaas/v1/model_load_balancer_pool_origin_collection.go new file mode 100644 index 000000000..5bc937fd2 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_origin_collection.go @@ -0,0 +1,144 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerPoolOriginCollection type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPoolOriginCollection{} + +// LoadBalancerPoolOriginCollection struct for LoadBalancerPoolOriginCollection +type LoadBalancerPoolOriginCollection struct { + Origins []LoadBalancerPoolOrigin `json:"origins"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPoolOriginCollection LoadBalancerPoolOriginCollection + +// NewLoadBalancerPoolOriginCollection instantiates a new LoadBalancerPoolOriginCollection object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPoolOriginCollection(origins []LoadBalancerPoolOrigin) *LoadBalancerPoolOriginCollection { + this := LoadBalancerPoolOriginCollection{} + this.Origins = origins + return &this +} + +// NewLoadBalancerPoolOriginCollectionWithDefaults instantiates a new LoadBalancerPoolOriginCollection object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPoolOriginCollectionWithDefaults() *LoadBalancerPoolOriginCollection { + this := LoadBalancerPoolOriginCollection{} + return &this +} + +// GetOrigins returns the Origins field value +func (o *LoadBalancerPoolOriginCollection) GetOrigins() []LoadBalancerPoolOrigin { + if o == nil { + var ret []LoadBalancerPoolOrigin + return ret + } + + return o.Origins +} + +// GetOriginsOk returns a tuple with the Origins field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOriginCollection) GetOriginsOk() ([]LoadBalancerPoolOrigin, bool) { + if o == nil { + return nil, false + } + return o.Origins, true +} + +// SetOrigins sets field value +func (o *LoadBalancerPoolOriginCollection) SetOrigins(v []LoadBalancerPoolOrigin) { + o.Origins = v +} + +func (o LoadBalancerPoolOriginCollection) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPoolOriginCollection) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["origins"] = o.Origins + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPoolOriginCollection) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPoolOriginCollection := _LoadBalancerPoolOriginCollection{} + + err = json.Unmarshal(bytes, &varLoadBalancerPoolOriginCollection) + + if err != nil { + return err + } + + *o = LoadBalancerPoolOriginCollection(varLoadBalancerPoolOriginCollection) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "origins") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPoolOriginCollection struct { + value *LoadBalancerPoolOriginCollection + isSet bool +} + +func (v NullableLoadBalancerPoolOriginCollection) Get() *LoadBalancerPoolOriginCollection { + return v.value +} + +func (v *NullableLoadBalancerPoolOriginCollection) Set(val *LoadBalancerPoolOriginCollection) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolOriginCollection) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolOriginCollection) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolOriginCollection(val *LoadBalancerPoolOriginCollection) *NullableLoadBalancerPoolOriginCollection { + return &NullableLoadBalancerPoolOriginCollection{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolOriginCollection) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolOriginCollection) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_origin_create.go b/internal/lbaas/v1/model_load_balancer_pool_origin_create.go new file mode 100644 index 000000000..5923b0c1f --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_origin_create.go @@ -0,0 +1,260 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerPoolOriginCreate type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPoolOriginCreate{} + +// LoadBalancerPoolOriginCreate struct for LoadBalancerPoolOriginCreate +type LoadBalancerPoolOriginCreate struct { + // A name for the origin + Name string `json:"name"` + // IP address of the origin + Target string `json:"target"` + PortNumber LoadBalancerPoolOriginPortNumber `json:"port_number"` + // If the origin is activated + Active bool `json:"active"` + // ID of the pool the origin belongs to + PoolId string `json:"pool_id"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPoolOriginCreate LoadBalancerPoolOriginCreate + +// NewLoadBalancerPoolOriginCreate instantiates a new LoadBalancerPoolOriginCreate object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPoolOriginCreate(name string, target string, portNumber LoadBalancerPoolOriginPortNumber, active bool, poolId string) *LoadBalancerPoolOriginCreate { + this := LoadBalancerPoolOriginCreate{} + this.Name = name + this.Target = target + this.PortNumber = portNumber + this.Active = active + this.PoolId = poolId + return &this +} + +// NewLoadBalancerPoolOriginCreateWithDefaults instantiates a new LoadBalancerPoolOriginCreate object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPoolOriginCreateWithDefaults() *LoadBalancerPoolOriginCreate { + this := LoadBalancerPoolOriginCreate{} + return &this +} + +// GetName returns the Name field value +func (o *LoadBalancerPoolOriginCreate) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOriginCreate) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *LoadBalancerPoolOriginCreate) SetName(v string) { + o.Name = v +} + +// GetTarget returns the Target field value +func (o *LoadBalancerPoolOriginCreate) GetTarget() string { + if o == nil { + var ret string + return ret + } + + return o.Target +} + +// GetTargetOk returns a tuple with the Target field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOriginCreate) GetTargetOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Target, true +} + +// SetTarget sets field value +func (o *LoadBalancerPoolOriginCreate) SetTarget(v string) { + o.Target = v +} + +// GetPortNumber returns the PortNumber field value +func (o *LoadBalancerPoolOriginCreate) GetPortNumber() LoadBalancerPoolOriginPortNumber { + if o == nil { + var ret LoadBalancerPoolOriginPortNumber + return ret + } + + return o.PortNumber +} + +// GetPortNumberOk returns a tuple with the PortNumber field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOriginCreate) GetPortNumberOk() (*LoadBalancerPoolOriginPortNumber, bool) { + if o == nil { + return nil, false + } + return &o.PortNumber, true +} + +// SetPortNumber sets field value +func (o *LoadBalancerPoolOriginCreate) SetPortNumber(v LoadBalancerPoolOriginPortNumber) { + o.PortNumber = v +} + +// GetActive returns the Active field value +func (o *LoadBalancerPoolOriginCreate) GetActive() bool { + if o == nil { + var ret bool + return ret + } + + return o.Active +} + +// GetActiveOk returns a tuple with the Active field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOriginCreate) GetActiveOk() (*bool, bool) { + if o == nil { + return nil, false + } + return &o.Active, true +} + +// SetActive sets field value +func (o *LoadBalancerPoolOriginCreate) SetActive(v bool) { + o.Active = v +} + +// GetPoolId returns the PoolId field value +func (o *LoadBalancerPoolOriginCreate) GetPoolId() string { + if o == nil { + var ret string + return ret + } + + return o.PoolId +} + +// GetPoolIdOk returns a tuple with the PoolId field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOriginCreate) GetPoolIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.PoolId, true +} + +// SetPoolId sets field value +func (o *LoadBalancerPoolOriginCreate) SetPoolId(v string) { + o.PoolId = v +} + +func (o LoadBalancerPoolOriginCreate) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPoolOriginCreate) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["name"] = o.Name + toSerialize["target"] = o.Target + toSerialize["port_number"] = o.PortNumber + toSerialize["active"] = o.Active + toSerialize["pool_id"] = o.PoolId + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPoolOriginCreate) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPoolOriginCreate := _LoadBalancerPoolOriginCreate{} + + err = json.Unmarshal(bytes, &varLoadBalancerPoolOriginCreate) + + if err != nil { + return err + } + + *o = LoadBalancerPoolOriginCreate(varLoadBalancerPoolOriginCreate) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "name") + delete(additionalProperties, "target") + delete(additionalProperties, "port_number") + delete(additionalProperties, "active") + delete(additionalProperties, "pool_id") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPoolOriginCreate struct { + value *LoadBalancerPoolOriginCreate + isSet bool +} + +func (v NullableLoadBalancerPoolOriginCreate) Get() *LoadBalancerPoolOriginCreate { + return v.value +} + +func (v *NullableLoadBalancerPoolOriginCreate) Set(val *LoadBalancerPoolOriginCreate) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolOriginCreate) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolOriginCreate) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolOriginCreate(val *LoadBalancerPoolOriginCreate) *NullableLoadBalancerPoolOriginCreate { + return &NullableLoadBalancerPoolOriginCreate{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolOriginCreate) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolOriginCreate) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_origin_port_number.go b/internal/lbaas/v1/model_load_balancer_pool_origin_port_number.go new file mode 100644 index 000000000..10acd5c03 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_origin_port_number.go @@ -0,0 +1,115 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "fmt" +) + +// LoadBalancerPoolOriginPortNumber - Listening port of the origin +type LoadBalancerPoolOriginPortNumber struct { + Int32 *int32 +} + +// int32AsLoadBalancerPoolOriginPortNumber is a convenience function that returns int32 wrapped in LoadBalancerPoolOriginPortNumber +func Int32AsLoadBalancerPoolOriginPortNumber(v *int32) LoadBalancerPoolOriginPortNumber { + return LoadBalancerPoolOriginPortNumber{ + Int32: v, + } +} + +// Unmarshal JSON data into one of the pointers in the struct +func (dst *LoadBalancerPoolOriginPortNumber) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into Int32 + err = newStrictDecoder(data).Decode(&dst.Int32) + if err == nil { + jsonInt32, _ := json.Marshal(dst.Int32) + if string(jsonInt32) == "{}" { // empty struct + dst.Int32 = nil + } else { + match++ + } + } else { + dst.Int32 = nil + } + + if match > 1 { // more than 1 match + // reset to nil + dst.Int32 = nil + + return fmt.Errorf("data matches more than one schema in oneOf(LoadBalancerPoolOriginPortNumber)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(LoadBalancerPoolOriginPortNumber)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src LoadBalancerPoolOriginPortNumber) MarshalJSON() ([]byte, error) { + if src.Int32 != nil { + return json.Marshal(&src.Int32) + } + + return nil, nil // no data in oneOf schemas +} + +// Get the actual instance +func (obj *LoadBalancerPoolOriginPortNumber) GetActualInstance() interface{} { + if obj == nil { + return nil + } + if obj.Int32 != nil { + return obj.Int32 + } + + // all schemas are nil + return nil +} + +type NullableLoadBalancerPoolOriginPortNumber struct { + value *LoadBalancerPoolOriginPortNumber + isSet bool +} + +func (v NullableLoadBalancerPoolOriginPortNumber) Get() *LoadBalancerPoolOriginPortNumber { + return v.value +} + +func (v *NullableLoadBalancerPoolOriginPortNumber) Set(val *LoadBalancerPoolOriginPortNumber) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolOriginPortNumber) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolOriginPortNumber) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolOriginPortNumber(val *LoadBalancerPoolOriginPortNumber) *NullableLoadBalancerPoolOriginPortNumber { + return &NullableLoadBalancerPoolOriginPortNumber{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolOriginPortNumber) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolOriginPortNumber) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_origin_update.go b/internal/lbaas/v1/model_load_balancer_pool_origin_update.go new file mode 100644 index 000000000..0aa26d89e --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_origin_update.go @@ -0,0 +1,267 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerPoolOriginUpdate type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPoolOriginUpdate{} + +// LoadBalancerPoolOriginUpdate struct for LoadBalancerPoolOriginUpdate +type LoadBalancerPoolOriginUpdate struct { + // A name for the origin + Name *string `json:"name,omitempty"` + // IP address of the origin + Target *string `json:"target,omitempty"` + PortNumber *LoadBalancerPoolOriginPortNumber `json:"port_number,omitempty"` + // If the origin is active + Active *bool `json:"active,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPoolOriginUpdate LoadBalancerPoolOriginUpdate + +// NewLoadBalancerPoolOriginUpdate instantiates a new LoadBalancerPoolOriginUpdate object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPoolOriginUpdate() *LoadBalancerPoolOriginUpdate { + this := LoadBalancerPoolOriginUpdate{} + return &this +} + +// NewLoadBalancerPoolOriginUpdateWithDefaults instantiates a new LoadBalancerPoolOriginUpdate object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPoolOriginUpdateWithDefaults() *LoadBalancerPoolOriginUpdate { + this := LoadBalancerPoolOriginUpdate{} + return &this +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *LoadBalancerPoolOriginUpdate) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOriginUpdate) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *LoadBalancerPoolOriginUpdate) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *LoadBalancerPoolOriginUpdate) SetName(v string) { + o.Name = &v +} + +// GetTarget returns the Target field value if set, zero value otherwise. +func (o *LoadBalancerPoolOriginUpdate) GetTarget() string { + if o == nil || IsNil(o.Target) { + var ret string + return ret + } + return *o.Target +} + +// GetTargetOk returns a tuple with the Target field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOriginUpdate) GetTargetOk() (*string, bool) { + if o == nil || IsNil(o.Target) { + return nil, false + } + return o.Target, true +} + +// HasTarget returns a boolean if a field has been set. +func (o *LoadBalancerPoolOriginUpdate) HasTarget() bool { + if o != nil && !IsNil(o.Target) { + return true + } + + return false +} + +// SetTarget gets a reference to the given string and assigns it to the Target field. +func (o *LoadBalancerPoolOriginUpdate) SetTarget(v string) { + o.Target = &v +} + +// GetPortNumber returns the PortNumber field value if set, zero value otherwise. +func (o *LoadBalancerPoolOriginUpdate) GetPortNumber() LoadBalancerPoolOriginPortNumber { + if o == nil || IsNil(o.PortNumber) { + var ret LoadBalancerPoolOriginPortNumber + return ret + } + return *o.PortNumber +} + +// GetPortNumberOk returns a tuple with the PortNumber field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOriginUpdate) GetPortNumberOk() (*LoadBalancerPoolOriginPortNumber, bool) { + if o == nil || IsNil(o.PortNumber) { + return nil, false + } + return o.PortNumber, true +} + +// HasPortNumber returns a boolean if a field has been set. +func (o *LoadBalancerPoolOriginUpdate) HasPortNumber() bool { + if o != nil && !IsNil(o.PortNumber) { + return true + } + + return false +} + +// SetPortNumber gets a reference to the given LoadBalancerPoolOriginPortNumber and assigns it to the PortNumber field. +func (o *LoadBalancerPoolOriginUpdate) SetPortNumber(v LoadBalancerPoolOriginPortNumber) { + o.PortNumber = &v +} + +// GetActive returns the Active field value if set, zero value otherwise. +func (o *LoadBalancerPoolOriginUpdate) GetActive() bool { + if o == nil || IsNil(o.Active) { + var ret bool + return ret + } + return *o.Active +} + +// GetActiveOk returns a tuple with the Active field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolOriginUpdate) GetActiveOk() (*bool, bool) { + if o == nil || IsNil(o.Active) { + return nil, false + } + return o.Active, true +} + +// HasActive returns a boolean if a field has been set. +func (o *LoadBalancerPoolOriginUpdate) HasActive() bool { + if o != nil && !IsNil(o.Active) { + return true + } + + return false +} + +// SetActive gets a reference to the given bool and assigns it to the Active field. +func (o *LoadBalancerPoolOriginUpdate) SetActive(v bool) { + o.Active = &v +} + +func (o LoadBalancerPoolOriginUpdate) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPoolOriginUpdate) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Target) { + toSerialize["target"] = o.Target + } + if !IsNil(o.PortNumber) { + toSerialize["port_number"] = o.PortNumber + } + if !IsNil(o.Active) { + toSerialize["active"] = o.Active + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPoolOriginUpdate) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPoolOriginUpdate := _LoadBalancerPoolOriginUpdate{} + + err = json.Unmarshal(bytes, &varLoadBalancerPoolOriginUpdate) + + if err != nil { + return err + } + + *o = LoadBalancerPoolOriginUpdate(varLoadBalancerPoolOriginUpdate) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "name") + delete(additionalProperties, "target") + delete(additionalProperties, "port_number") + delete(additionalProperties, "active") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPoolOriginUpdate struct { + value *LoadBalancerPoolOriginUpdate + isSet bool +} + +func (v NullableLoadBalancerPoolOriginUpdate) Get() *LoadBalancerPoolOriginUpdate { + return v.value +} + +func (v *NullableLoadBalancerPoolOriginUpdate) Set(val *LoadBalancerPoolOriginUpdate) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolOriginUpdate) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolOriginUpdate) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolOriginUpdate(val *LoadBalancerPoolOriginUpdate) *NullableLoadBalancerPoolOriginUpdate { + return &NullableLoadBalancerPoolOriginUpdate{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolOriginUpdate) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolOriginUpdate) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_protocol.go b/internal/lbaas/v1/model_load_balancer_pool_protocol.go new file mode 100644 index 000000000..b06edb0f7 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_protocol.go @@ -0,0 +1,110 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "fmt" +) + +// LoadBalancerPoolProtocol the model 'LoadBalancerPoolProtocol' +type LoadBalancerPoolProtocol string + +// List of LoadBalancerPoolProtocol +const ( + LOADBALANCERPOOLPROTOCOL_TCP LoadBalancerPoolProtocol = "tcp" + LOADBALANCERPOOLPROTOCOL_UDP LoadBalancerPoolProtocol = "udp" +) + +// All allowed values of LoadBalancerPoolProtocol enum +var AllowedLoadBalancerPoolProtocolEnumValues = []LoadBalancerPoolProtocol{ + "tcp", + "udp", +} + +func (v *LoadBalancerPoolProtocol) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := LoadBalancerPoolProtocol(value) + for _, existing := range AllowedLoadBalancerPoolProtocolEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid LoadBalancerPoolProtocol", value) +} + +// NewLoadBalancerPoolProtocolFromValue returns a pointer to a valid LoadBalancerPoolProtocol +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewLoadBalancerPoolProtocolFromValue(v string) (*LoadBalancerPoolProtocol, error) { + ev := LoadBalancerPoolProtocol(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for LoadBalancerPoolProtocol: valid values are %v", v, AllowedLoadBalancerPoolProtocolEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v LoadBalancerPoolProtocol) IsValid() bool { + for _, existing := range AllowedLoadBalancerPoolProtocolEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to LoadBalancerPoolProtocol value +func (v LoadBalancerPoolProtocol) Ptr() *LoadBalancerPoolProtocol { + return &v +} + +type NullableLoadBalancerPoolProtocol struct { + value *LoadBalancerPoolProtocol + isSet bool +} + +func (v NullableLoadBalancerPoolProtocol) Get() *LoadBalancerPoolProtocol { + return v.value +} + +func (v *NullableLoadBalancerPoolProtocol) Set(val *LoadBalancerPoolProtocol) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolProtocol) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolProtocol) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolProtocol(val *LoadBalancerPoolProtocol) *NullableLoadBalancerPoolProtocol { + return &NullableLoadBalancerPoolProtocol{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolProtocol) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolProtocol) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_short.go b/internal/lbaas/v1/model_load_balancer_pool_short.go new file mode 100644 index 000000000..41db6348a --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_short.go @@ -0,0 +1,270 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "time" +) + +// checks if the LoadBalancerPoolShort type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPoolShort{} + +// LoadBalancerPoolShort struct for LoadBalancerPoolShort +type LoadBalancerPoolShort struct { + // ID of a pool + Id string `json:"id,omitempty"` + // A name for the pool + Name *string `json:"name,omitempty"` + // Date and time of creation + CreatedAt *time.Time `json:"created_at,omitempty"` + // Date and time of last update + UpdatedAt *time.Time `json:"updated_at,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPoolShort LoadBalancerPoolShort + +// NewLoadBalancerPoolShort instantiates a new LoadBalancerPoolShort object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPoolShort() *LoadBalancerPoolShort { + this := LoadBalancerPoolShort{} + return &this +} + +// NewLoadBalancerPoolShortWithDefaults instantiates a new LoadBalancerPoolShort object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPoolShortWithDefaults() *LoadBalancerPoolShort { + this := LoadBalancerPoolShort{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *LoadBalancerPoolShort) GetId() string { + if o == nil { + var ret string + return ret + } + return o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *LoadBalancerPoolShort) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return &o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *LoadBalancerPoolShort) HasId() bool { + if o != nil && IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given interface{} and assigns it to the Id field. +func (o *LoadBalancerPoolShort) SetId(v string) { + o.Id = v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *LoadBalancerPoolShort) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolShort) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *LoadBalancerPoolShort) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *LoadBalancerPoolShort) SetName(v string) { + o.Name = &v +} + +// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise. +func (o *LoadBalancerPoolShort) GetCreatedAt() time.Time { + if o == nil || IsNil(o.CreatedAt) { + var ret time.Time + return ret + } + return *o.CreatedAt +} + +// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolShort) GetCreatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.CreatedAt) { + return nil, false + } + return o.CreatedAt, true +} + +// HasCreatedAt returns a boolean if a field has been set. +func (o *LoadBalancerPoolShort) HasCreatedAt() bool { + if o != nil && !IsNil(o.CreatedAt) { + return true + } + + return false +} + +// SetCreatedAt gets a reference to the given time.Time and assigns it to the CreatedAt field. +func (o *LoadBalancerPoolShort) SetCreatedAt(v time.Time) { + o.CreatedAt = &v +} + +// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise. +func (o *LoadBalancerPoolShort) GetUpdatedAt() time.Time { + if o == nil || IsNil(o.UpdatedAt) { + var ret time.Time + return ret + } + return *o.UpdatedAt +} + +// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolShort) GetUpdatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.UpdatedAt) { + return nil, false + } + return o.UpdatedAt, true +} + +// HasUpdatedAt returns a boolean if a field has been set. +func (o *LoadBalancerPoolShort) HasUpdatedAt() bool { + if o != nil && !IsNil(o.UpdatedAt) { + return true + } + + return false +} + +// SetUpdatedAt gets a reference to the given time.Time and assigns it to the UpdatedAt field. +func (o *LoadBalancerPoolShort) SetUpdatedAt(v time.Time) { + o.UpdatedAt = &v +} + +func (o LoadBalancerPoolShort) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPoolShort) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.CreatedAt) { + toSerialize["created_at"] = o.CreatedAt + } + if !IsNil(o.UpdatedAt) { + toSerialize["updated_at"] = o.UpdatedAt + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPoolShort) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPoolShort := _LoadBalancerPoolShort{} + + err = json.Unmarshal(bytes, &varLoadBalancerPoolShort) + + if err != nil { + return err + } + + *o = LoadBalancerPoolShort(varLoadBalancerPoolShort) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "id") + delete(additionalProperties, "name") + delete(additionalProperties, "created_at") + delete(additionalProperties, "updated_at") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPoolShort struct { + value *LoadBalancerPoolShort + isSet bool +} + +func (v NullableLoadBalancerPoolShort) Get() *LoadBalancerPoolShort { + return v.value +} + +func (v *NullableLoadBalancerPoolShort) Set(val *LoadBalancerPoolShort) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolShort) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolShort) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolShort(val *LoadBalancerPoolShort) *NullableLoadBalancerPoolShort { + return &NullableLoadBalancerPoolShort{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolShort) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolShort) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_pool_update.go b/internal/lbaas/v1/model_load_balancer_pool_update.go new file mode 100644 index 000000000..eaac0b31d --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_pool_update.go @@ -0,0 +1,419 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerPoolUpdate type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPoolUpdate{} + +// LoadBalancerPoolUpdate struct for LoadBalancerPoolUpdate +type LoadBalancerPoolUpdate struct { + // Name of the load balancer pool + Name *string `json:"name,omitempty"` + Protocol *LoadBalancerPoolCreateProtocol `json:"protocol,omitempty"` + // Add ports to load balancer pool + AddPortIds []string `json:"add_port_ids,omitempty"` + // Removed ports from load balancer pool + RemovePortIds []string `json:"remove_port_ids,omitempty"` + // Clear all ports from load balancer pool + ClearPorts *bool `json:"clear_ports,omitempty"` + // Add origins to load balancer pool + AddOriginIds []string `json:"add_origin_ids,omitempty"` + // Removed origins from load balancer pool + RemoveOriginIds []string `json:"remove_origin_ids,omitempty"` + // Clear all origins from load balancer pool + ClearOrigins *bool `json:"clear_origins,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPoolUpdate LoadBalancerPoolUpdate + +// NewLoadBalancerPoolUpdate instantiates a new LoadBalancerPoolUpdate object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPoolUpdate() *LoadBalancerPoolUpdate { + this := LoadBalancerPoolUpdate{} + return &this +} + +// NewLoadBalancerPoolUpdateWithDefaults instantiates a new LoadBalancerPoolUpdate object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPoolUpdateWithDefaults() *LoadBalancerPoolUpdate { + this := LoadBalancerPoolUpdate{} + return &this +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *LoadBalancerPoolUpdate) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolUpdate) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *LoadBalancerPoolUpdate) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *LoadBalancerPoolUpdate) SetName(v string) { + o.Name = &v +} + +// GetProtocol returns the Protocol field value if set, zero value otherwise. +func (o *LoadBalancerPoolUpdate) GetProtocol() LoadBalancerPoolCreateProtocol { + if o == nil || IsNil(o.Protocol) { + var ret LoadBalancerPoolCreateProtocol + return ret + } + return *o.Protocol +} + +// GetProtocolOk returns a tuple with the Protocol field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolUpdate) GetProtocolOk() (*LoadBalancerPoolCreateProtocol, bool) { + if o == nil || IsNil(o.Protocol) { + return nil, false + } + return o.Protocol, true +} + +// HasProtocol returns a boolean if a field has been set. +func (o *LoadBalancerPoolUpdate) HasProtocol() bool { + if o != nil && !IsNil(o.Protocol) { + return true + } + + return false +} + +// SetProtocol gets a reference to the given LoadBalancerPoolCreateProtocol and assigns it to the Protocol field. +func (o *LoadBalancerPoolUpdate) SetProtocol(v LoadBalancerPoolCreateProtocol) { + o.Protocol = &v +} + +// GetAddPortIds returns the AddPortIds field value if set, zero value otherwise. +func (o *LoadBalancerPoolUpdate) GetAddPortIds() []string { + if o == nil || IsNil(o.AddPortIds) { + var ret []string + return ret + } + return o.AddPortIds +} + +// GetAddPortIdsOk returns a tuple with the AddPortIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolUpdate) GetAddPortIdsOk() ([]string, bool) { + if o == nil || IsNil(o.AddPortIds) { + return nil, false + } + return o.AddPortIds, true +} + +// HasAddPortIds returns a boolean if a field has been set. +func (o *LoadBalancerPoolUpdate) HasAddPortIds() bool { + if o != nil && !IsNil(o.AddPortIds) { + return true + } + + return false +} + +// SetAddPortIds gets a reference to the given []string and assigns it to the AddPortIds field. +func (o *LoadBalancerPoolUpdate) SetAddPortIds(v []string) { + o.AddPortIds = v +} + +// GetRemovePortIds returns the RemovePortIds field value if set, zero value otherwise. +func (o *LoadBalancerPoolUpdate) GetRemovePortIds() []string { + if o == nil || IsNil(o.RemovePortIds) { + var ret []string + return ret + } + return o.RemovePortIds +} + +// GetRemovePortIdsOk returns a tuple with the RemovePortIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolUpdate) GetRemovePortIdsOk() ([]string, bool) { + if o == nil || IsNil(o.RemovePortIds) { + return nil, false + } + return o.RemovePortIds, true +} + +// HasRemovePortIds returns a boolean if a field has been set. +func (o *LoadBalancerPoolUpdate) HasRemovePortIds() bool { + if o != nil && !IsNil(o.RemovePortIds) { + return true + } + + return false +} + +// SetRemovePortIds gets a reference to the given []string and assigns it to the RemovePortIds field. +func (o *LoadBalancerPoolUpdate) SetRemovePortIds(v []string) { + o.RemovePortIds = v +} + +// GetClearPorts returns the ClearPorts field value if set, zero value otherwise. +func (o *LoadBalancerPoolUpdate) GetClearPorts() bool { + if o == nil || IsNil(o.ClearPorts) { + var ret bool + return ret + } + return *o.ClearPorts +} + +// GetClearPortsOk returns a tuple with the ClearPorts field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolUpdate) GetClearPortsOk() (*bool, bool) { + if o == nil || IsNil(o.ClearPorts) { + return nil, false + } + return o.ClearPorts, true +} + +// HasClearPorts returns a boolean if a field has been set. +func (o *LoadBalancerPoolUpdate) HasClearPorts() bool { + if o != nil && !IsNil(o.ClearPorts) { + return true + } + + return false +} + +// SetClearPorts gets a reference to the given bool and assigns it to the ClearPorts field. +func (o *LoadBalancerPoolUpdate) SetClearPorts(v bool) { + o.ClearPorts = &v +} + +// GetAddOriginIds returns the AddOriginIds field value if set, zero value otherwise. +func (o *LoadBalancerPoolUpdate) GetAddOriginIds() []string { + if o == nil || IsNil(o.AddOriginIds) { + var ret []string + return ret + } + return o.AddOriginIds +} + +// GetAddOriginIdsOk returns a tuple with the AddOriginIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolUpdate) GetAddOriginIdsOk() ([]string, bool) { + if o == nil || IsNil(o.AddOriginIds) { + return nil, false + } + return o.AddOriginIds, true +} + +// HasAddOriginIds returns a boolean if a field has been set. +func (o *LoadBalancerPoolUpdate) HasAddOriginIds() bool { + if o != nil && !IsNil(o.AddOriginIds) { + return true + } + + return false +} + +// SetAddOriginIds gets a reference to the given []string and assigns it to the AddOriginIds field. +func (o *LoadBalancerPoolUpdate) SetAddOriginIds(v []string) { + o.AddOriginIds = v +} + +// GetRemoveOriginIds returns the RemoveOriginIds field value if set, zero value otherwise. +func (o *LoadBalancerPoolUpdate) GetRemoveOriginIds() []string { + if o == nil || IsNil(o.RemoveOriginIds) { + var ret []string + return ret + } + return o.RemoveOriginIds +} + +// GetRemoveOriginIdsOk returns a tuple with the RemoveOriginIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolUpdate) GetRemoveOriginIdsOk() ([]string, bool) { + if o == nil || IsNil(o.RemoveOriginIds) { + return nil, false + } + return o.RemoveOriginIds, true +} + +// HasRemoveOriginIds returns a boolean if a field has been set. +func (o *LoadBalancerPoolUpdate) HasRemoveOriginIds() bool { + if o != nil && !IsNil(o.RemoveOriginIds) { + return true + } + + return false +} + +// SetRemoveOriginIds gets a reference to the given []string and assigns it to the RemoveOriginIds field. +func (o *LoadBalancerPoolUpdate) SetRemoveOriginIds(v []string) { + o.RemoveOriginIds = v +} + +// GetClearOrigins returns the ClearOrigins field value if set, zero value otherwise. +func (o *LoadBalancerPoolUpdate) GetClearOrigins() bool { + if o == nil || IsNil(o.ClearOrigins) { + var ret bool + return ret + } + return *o.ClearOrigins +} + +// GetClearOriginsOk returns a tuple with the ClearOrigins field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPoolUpdate) GetClearOriginsOk() (*bool, bool) { + if o == nil || IsNil(o.ClearOrigins) { + return nil, false + } + return o.ClearOrigins, true +} + +// HasClearOrigins returns a boolean if a field has been set. +func (o *LoadBalancerPoolUpdate) HasClearOrigins() bool { + if o != nil && !IsNil(o.ClearOrigins) { + return true + } + + return false +} + +// SetClearOrigins gets a reference to the given bool and assigns it to the ClearOrigins field. +func (o *LoadBalancerPoolUpdate) SetClearOrigins(v bool) { + o.ClearOrigins = &v +} + +func (o LoadBalancerPoolUpdate) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPoolUpdate) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Protocol) { + toSerialize["protocol"] = o.Protocol + } + if !IsNil(o.AddPortIds) { + toSerialize["add_port_ids"] = o.AddPortIds + } + if !IsNil(o.RemovePortIds) { + toSerialize["remove_port_ids"] = o.RemovePortIds + } + if !IsNil(o.ClearPorts) { + toSerialize["clear_ports"] = o.ClearPorts + } + if !IsNil(o.AddOriginIds) { + toSerialize["add_origin_ids"] = o.AddOriginIds + } + if !IsNil(o.RemoveOriginIds) { + toSerialize["remove_origin_ids"] = o.RemoveOriginIds + } + if !IsNil(o.ClearOrigins) { + toSerialize["clear_origins"] = o.ClearOrigins + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPoolUpdate) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPoolUpdate := _LoadBalancerPoolUpdate{} + + err = json.Unmarshal(bytes, &varLoadBalancerPoolUpdate) + + if err != nil { + return err + } + + *o = LoadBalancerPoolUpdate(varLoadBalancerPoolUpdate) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "name") + delete(additionalProperties, "protocol") + delete(additionalProperties, "add_port_ids") + delete(additionalProperties, "remove_port_ids") + delete(additionalProperties, "clear_ports") + delete(additionalProperties, "add_origin_ids") + delete(additionalProperties, "remove_origin_ids") + delete(additionalProperties, "clear_origins") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPoolUpdate struct { + value *LoadBalancerPoolUpdate + isSet bool +} + +func (v NullableLoadBalancerPoolUpdate) Get() *LoadBalancerPoolUpdate { + return v.value +} + +func (v *NullableLoadBalancerPoolUpdate) Set(val *LoadBalancerPoolUpdate) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPoolUpdate) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPoolUpdate) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPoolUpdate(val *LoadBalancerPoolUpdate) *NullableLoadBalancerPoolUpdate { + return &NullableLoadBalancerPoolUpdate{value: val, isSet: true} +} + +func (v NullableLoadBalancerPoolUpdate) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPoolUpdate) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_port.go b/internal/lbaas/v1/model_load_balancer_port.go new file mode 100644 index 000000000..78336830a --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_port.go @@ -0,0 +1,383 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "time" +) + +// checks if the LoadBalancerPort type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPort{} + +// LoadBalancerPort struct for LoadBalancerPort +type LoadBalancerPort struct { + // ID of a port + Id *string `json:"id,omitempty"` + // Date and time of creation + CreatedAt *time.Time `json:"created_at,omitempty"` + // Date and time of last update + UpdatedAt *time.Time `json:"updated_at,omitempty"` + // A name for the port + Name *string `json:"name,omitempty"` + // Port Number + Number *int32 `json:"number,omitempty"` + // ID of the load balancer this port is assigned to + LoadbalancerId *string `json:"loadbalancer_id,omitempty"` + // A list of pool IDs assigned to the port + PoolIds []string `json:"pool_ids,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPort LoadBalancerPort + +// NewLoadBalancerPort instantiates a new LoadBalancerPort object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPort() *LoadBalancerPort { + this := LoadBalancerPort{} + return &this +} + +// NewLoadBalancerPortWithDefaults instantiates a new LoadBalancerPort object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPortWithDefaults() *LoadBalancerPort { + this := LoadBalancerPort{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *LoadBalancerPort) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPort) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *LoadBalancerPort) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *LoadBalancerPort) SetId(v string) { + o.Id = &v +} + +// GetCreatedAt returns the CreatedAt field value if set, zero value otherwise. +func (o *LoadBalancerPort) GetCreatedAt() time.Time { + if o == nil || IsNil(o.CreatedAt) { + var ret time.Time + return ret + } + return *o.CreatedAt +} + +// GetCreatedAtOk returns a tuple with the CreatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPort) GetCreatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.CreatedAt) { + return nil, false + } + return o.CreatedAt, true +} + +// HasCreatedAt returns a boolean if a field has been set. +func (o *LoadBalancerPort) HasCreatedAt() bool { + if o != nil && !IsNil(o.CreatedAt) { + return true + } + + return false +} + +// SetCreatedAt gets a reference to the given time.Time and assigns it to the CreatedAt field. +func (o *LoadBalancerPort) SetCreatedAt(v time.Time) { + o.CreatedAt = &v +} + +// GetUpdatedAt returns the UpdatedAt field value if set, zero value otherwise. +func (o *LoadBalancerPort) GetUpdatedAt() time.Time { + if o == nil || IsNil(o.UpdatedAt) { + var ret time.Time + return ret + } + return *o.UpdatedAt +} + +// GetUpdatedAtOk returns a tuple with the UpdatedAt field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPort) GetUpdatedAtOk() (*time.Time, bool) { + if o == nil || IsNil(o.UpdatedAt) { + return nil, false + } + return o.UpdatedAt, true +} + +// HasUpdatedAt returns a boolean if a field has been set. +func (o *LoadBalancerPort) HasUpdatedAt() bool { + if o != nil && !IsNil(o.UpdatedAt) { + return true + } + + return false +} + +// SetUpdatedAt gets a reference to the given time.Time and assigns it to the UpdatedAt field. +func (o *LoadBalancerPort) SetUpdatedAt(v time.Time) { + o.UpdatedAt = &v +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *LoadBalancerPort) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPort) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *LoadBalancerPort) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *LoadBalancerPort) SetName(v string) { + o.Name = &v +} + +// GetNumber returns the Number field value if set, zero value otherwise. +func (o *LoadBalancerPort) GetNumber() int32 { + if o == nil || IsNil(o.Number) { + var ret int32 + return ret + } + return *o.Number +} + +// GetNumberOk returns a tuple with the Number field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPort) GetNumberOk() (*int32, bool) { + if o == nil || IsNil(o.Number) { + return nil, false + } + return o.Number, true +} + +// HasNumber returns a boolean if a field has been set. +func (o *LoadBalancerPort) HasNumber() bool { + if o != nil && !IsNil(o.Number) { + return true + } + + return false +} + +// SetNumber gets a reference to the given int32 and assigns it to the Number field. +func (o *LoadBalancerPort) SetNumber(v int32) { + o.Number = &v +} + +// GetLoadbalancerId returns the LoadbalancerId field value if set, zero value otherwise. +func (o *LoadBalancerPort) GetLoadbalancerId() string { + if o == nil || IsNil(o.LoadbalancerId) { + var ret string + return ret + } + return *o.LoadbalancerId +} + +// GetLoadbalancerIdOk returns a tuple with the LoadbalancerId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPort) GetLoadbalancerIdOk() (*string, bool) { + if o == nil || IsNil(o.LoadbalancerId) { + return nil, false + } + return o.LoadbalancerId, true +} + +// HasLoadbalancerId returns a boolean if a field has been set. +func (o *LoadBalancerPort) HasLoadbalancerId() bool { + if o != nil && !IsNil(o.LoadbalancerId) { + return true + } + + return false +} + +// SetLoadbalancerId gets a reference to the given string and assigns it to the LoadbalancerId field. +func (o *LoadBalancerPort) SetLoadbalancerId(v string) { + o.LoadbalancerId = &v +} + +// GetPoolIds returns the PoolIds field value if set, zero value otherwise. +func (o *LoadBalancerPort) GetPoolIds() []string { + if o == nil || IsNil(o.PoolIds) { + var ret []string + return ret + } + return o.PoolIds +} + +// GetPoolIdsOk returns a tuple with the PoolIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPort) GetPoolIdsOk() ([]string, bool) { + if o == nil || IsNil(o.PoolIds) { + return nil, false + } + return o.PoolIds, true +} + +// HasPoolIds returns a boolean if a field has been set. +func (o *LoadBalancerPort) HasPoolIds() bool { + if o != nil && !IsNil(o.PoolIds) { + return true + } + + return false +} + +// SetPoolIds gets a reference to the given []string and assigns it to the PoolIds field. +func (o *LoadBalancerPort) SetPoolIds(v []string) { + o.PoolIds = v +} + +func (o LoadBalancerPort) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPort) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.CreatedAt) { + toSerialize["created_at"] = o.CreatedAt + } + if !IsNil(o.UpdatedAt) { + toSerialize["updated_at"] = o.UpdatedAt + } + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Number) { + toSerialize["number"] = o.Number + } + if !IsNil(o.LoadbalancerId) { + toSerialize["loadbalancer_id"] = o.LoadbalancerId + } + if !IsNil(o.PoolIds) { + toSerialize["pool_ids"] = o.PoolIds + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPort) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPort := _LoadBalancerPort{} + + err = json.Unmarshal(bytes, &varLoadBalancerPort) + + if err != nil { + return err + } + + *o = LoadBalancerPort(varLoadBalancerPort) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "id") + delete(additionalProperties, "created_at") + delete(additionalProperties, "updated_at") + delete(additionalProperties, "name") + delete(additionalProperties, "number") + delete(additionalProperties, "loadbalancer_id") + delete(additionalProperties, "pool_ids") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPort struct { + value *LoadBalancerPort + isSet bool +} + +func (v NullableLoadBalancerPort) Get() *LoadBalancerPort { + return v.value +} + +func (v *NullableLoadBalancerPort) Set(val *LoadBalancerPort) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPort) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPort) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPort(val *LoadBalancerPort) *NullableLoadBalancerPort { + return &NullableLoadBalancerPort{value: val, isSet: true} +} + +func (v NullableLoadBalancerPort) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPort) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_port_collection.go b/internal/lbaas/v1/model_load_balancer_port_collection.go new file mode 100644 index 000000000..f47a22479 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_port_collection.go @@ -0,0 +1,144 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerPortCollection type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPortCollection{} + +// LoadBalancerPortCollection struct for LoadBalancerPortCollection +type LoadBalancerPortCollection struct { + Ports []LoadBalancerPort `json:"ports"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPortCollection LoadBalancerPortCollection + +// NewLoadBalancerPortCollection instantiates a new LoadBalancerPortCollection object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPortCollection(ports []LoadBalancerPort) *LoadBalancerPortCollection { + this := LoadBalancerPortCollection{} + this.Ports = ports + return &this +} + +// NewLoadBalancerPortCollectionWithDefaults instantiates a new LoadBalancerPortCollection object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPortCollectionWithDefaults() *LoadBalancerPortCollection { + this := LoadBalancerPortCollection{} + return &this +} + +// GetPorts returns the Ports field value +func (o *LoadBalancerPortCollection) GetPorts() []LoadBalancerPort { + if o == nil { + var ret []LoadBalancerPort + return ret + } + + return o.Ports +} + +// GetPortsOk returns a tuple with the Ports field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPortCollection) GetPortsOk() ([]LoadBalancerPort, bool) { + if o == nil { + return nil, false + } + return o.Ports, true +} + +// SetPorts sets field value +func (o *LoadBalancerPortCollection) SetPorts(v []LoadBalancerPort) { + o.Ports = v +} + +func (o LoadBalancerPortCollection) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPortCollection) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["ports"] = o.Ports + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPortCollection) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPortCollection := _LoadBalancerPortCollection{} + + err = json.Unmarshal(bytes, &varLoadBalancerPortCollection) + + if err != nil { + return err + } + + *o = LoadBalancerPortCollection(varLoadBalancerPortCollection) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "ports") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPortCollection struct { + value *LoadBalancerPortCollection + isSet bool +} + +func (v NullableLoadBalancerPortCollection) Get() *LoadBalancerPortCollection { + return v.value +} + +func (v *NullableLoadBalancerPortCollection) Set(val *LoadBalancerPortCollection) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPortCollection) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPortCollection) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPortCollection(val *LoadBalancerPortCollection) *NullableLoadBalancerPortCollection { + return &NullableLoadBalancerPortCollection{value: val, isSet: true} +} + +func (v NullableLoadBalancerPortCollection) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPortCollection) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_port_create.go b/internal/lbaas/v1/model_load_balancer_port_create.go new file mode 100644 index 000000000..8bc6202bb --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_port_create.go @@ -0,0 +1,212 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerPortCreate type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPortCreate{} + +// LoadBalancerPortCreate struct for LoadBalancerPortCreate +type LoadBalancerPortCreate struct { + // A name for the port + Name string `json:"name"` + // Listing port + Number int32 `json:"number"` + // A list of pool IDs assigned to the port + PoolIds []string `json:"pool_ids,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPortCreate LoadBalancerPortCreate + +// NewLoadBalancerPortCreate instantiates a new LoadBalancerPortCreate object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPortCreate(name string, number int32) *LoadBalancerPortCreate { + this := LoadBalancerPortCreate{} + this.Name = name + this.Number = number + return &this +} + +// NewLoadBalancerPortCreateWithDefaults instantiates a new LoadBalancerPortCreate object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPortCreateWithDefaults() *LoadBalancerPortCreate { + this := LoadBalancerPortCreate{} + return &this +} + +// GetName returns the Name field value +func (o *LoadBalancerPortCreate) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPortCreate) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *LoadBalancerPortCreate) SetName(v string) { + o.Name = v +} + +// GetNumber returns the Number field value +func (o *LoadBalancerPortCreate) GetNumber() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.Number +} + +// GetNumberOk returns a tuple with the Number field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerPortCreate) GetNumberOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.Number, true +} + +// SetNumber sets field value +func (o *LoadBalancerPortCreate) SetNumber(v int32) { + o.Number = v +} + +// GetPoolIds returns the PoolIds field value if set, zero value otherwise. +func (o *LoadBalancerPortCreate) GetPoolIds() []string { + if o == nil || IsNil(o.PoolIds) { + var ret []string + return ret + } + return o.PoolIds +} + +// GetPoolIdsOk returns a tuple with the PoolIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPortCreate) GetPoolIdsOk() ([]string, bool) { + if o == nil || IsNil(o.PoolIds) { + return nil, false + } + return o.PoolIds, true +} + +// HasPoolIds returns a boolean if a field has been set. +func (o *LoadBalancerPortCreate) HasPoolIds() bool { + if o != nil && !IsNil(o.PoolIds) { + return true + } + + return false +} + +// SetPoolIds gets a reference to the given []string and assigns it to the PoolIds field. +func (o *LoadBalancerPortCreate) SetPoolIds(v []string) { + o.PoolIds = v +} + +func (o LoadBalancerPortCreate) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPortCreate) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["name"] = o.Name + toSerialize["number"] = o.Number + if !IsNil(o.PoolIds) { + toSerialize["pool_ids"] = o.PoolIds + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPortCreate) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPortCreate := _LoadBalancerPortCreate{} + + err = json.Unmarshal(bytes, &varLoadBalancerPortCreate) + + if err != nil { + return err + } + + *o = LoadBalancerPortCreate(varLoadBalancerPortCreate) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "name") + delete(additionalProperties, "number") + delete(additionalProperties, "pool_ids") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPortCreate struct { + value *LoadBalancerPortCreate + isSet bool +} + +func (v NullableLoadBalancerPortCreate) Get() *LoadBalancerPortCreate { + return v.value +} + +func (v *NullableLoadBalancerPortCreate) Set(val *LoadBalancerPortCreate) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPortCreate) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPortCreate) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPortCreate(val *LoadBalancerPortCreate) *NullableLoadBalancerPortCreate { + return &NullableLoadBalancerPortCreate{value: val, isSet: true} +} + +func (v NullableLoadBalancerPortCreate) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPortCreate) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_port_update.go b/internal/lbaas/v1/model_load_balancer_port_update.go new file mode 100644 index 000000000..4df032064 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_port_update.go @@ -0,0 +1,268 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerPortUpdate type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerPortUpdate{} + +// LoadBalancerPortUpdate struct for LoadBalancerPortUpdate +type LoadBalancerPortUpdate struct { + // A name for the port + Name *string `json:"name,omitempty"` + // Listing port + Number *int32 `json:"number,omitempty"` + // Add the provided pool ids to the port + AddPoolIds []string `json:"add_pool_ids,omitempty"` + // Remove the provided pool ids to the port + RemovePoolIds []string `json:"remove_pool_ids,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerPortUpdate LoadBalancerPortUpdate + +// NewLoadBalancerPortUpdate instantiates a new LoadBalancerPortUpdate object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerPortUpdate() *LoadBalancerPortUpdate { + this := LoadBalancerPortUpdate{} + return &this +} + +// NewLoadBalancerPortUpdateWithDefaults instantiates a new LoadBalancerPortUpdate object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerPortUpdateWithDefaults() *LoadBalancerPortUpdate { + this := LoadBalancerPortUpdate{} + return &this +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *LoadBalancerPortUpdate) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPortUpdate) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *LoadBalancerPortUpdate) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *LoadBalancerPortUpdate) SetName(v string) { + o.Name = &v +} + +// GetNumber returns the Number field value if set, zero value otherwise. +func (o *LoadBalancerPortUpdate) GetNumber() int32 { + if o == nil || IsNil(o.Number) { + var ret int32 + return ret + } + return *o.Number +} + +// GetNumberOk returns a tuple with the Number field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPortUpdate) GetNumberOk() (*int32, bool) { + if o == nil || IsNil(o.Number) { + return nil, false + } + return o.Number, true +} + +// HasNumber returns a boolean if a field has been set. +func (o *LoadBalancerPortUpdate) HasNumber() bool { + if o != nil && !IsNil(o.Number) { + return true + } + + return false +} + +// SetNumber gets a reference to the given int32 and assigns it to the Number field. +func (o *LoadBalancerPortUpdate) SetNumber(v int32) { + o.Number = &v +} + +// GetAddPoolIds returns the AddPoolIds field value if set, zero value otherwise. +func (o *LoadBalancerPortUpdate) GetAddPoolIds() []string { + if o == nil || IsNil(o.AddPoolIds) { + var ret []string + return ret + } + return o.AddPoolIds +} + +// GetAddPoolIdsOk returns a tuple with the AddPoolIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPortUpdate) GetAddPoolIdsOk() ([]string, bool) { + if o == nil || IsNil(o.AddPoolIds) { + return nil, false + } + return o.AddPoolIds, true +} + +// HasAddPoolIds returns a boolean if a field has been set. +func (o *LoadBalancerPortUpdate) HasAddPoolIds() bool { + if o != nil && !IsNil(o.AddPoolIds) { + return true + } + + return false +} + +// SetAddPoolIds gets a reference to the given []string and assigns it to the AddPoolIds field. +func (o *LoadBalancerPortUpdate) SetAddPoolIds(v []string) { + o.AddPoolIds = v +} + +// GetRemovePoolIds returns the RemovePoolIds field value if set, zero value otherwise. +func (o *LoadBalancerPortUpdate) GetRemovePoolIds() []string { + if o == nil || IsNil(o.RemovePoolIds) { + var ret []string + return ret + } + return o.RemovePoolIds +} + +// GetRemovePoolIdsOk returns a tuple with the RemovePoolIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerPortUpdate) GetRemovePoolIdsOk() ([]string, bool) { + if o == nil || IsNil(o.RemovePoolIds) { + return nil, false + } + return o.RemovePoolIds, true +} + +// HasRemovePoolIds returns a boolean if a field has been set. +func (o *LoadBalancerPortUpdate) HasRemovePoolIds() bool { + if o != nil && !IsNil(o.RemovePoolIds) { + return true + } + + return false +} + +// SetRemovePoolIds gets a reference to the given []string and assigns it to the RemovePoolIds field. +func (o *LoadBalancerPortUpdate) SetRemovePoolIds(v []string) { + o.RemovePoolIds = v +} + +func (o LoadBalancerPortUpdate) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerPortUpdate) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.Number) { + toSerialize["number"] = o.Number + } + if !IsNil(o.AddPoolIds) { + toSerialize["add_pool_ids"] = o.AddPoolIds + } + if !IsNil(o.RemovePoolIds) { + toSerialize["remove_pool_ids"] = o.RemovePoolIds + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerPortUpdate) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerPortUpdate := _LoadBalancerPortUpdate{} + + err = json.Unmarshal(bytes, &varLoadBalancerPortUpdate) + + if err != nil { + return err + } + + *o = LoadBalancerPortUpdate(varLoadBalancerPortUpdate) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "name") + delete(additionalProperties, "number") + delete(additionalProperties, "add_pool_ids") + delete(additionalProperties, "remove_pool_ids") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerPortUpdate struct { + value *LoadBalancerPortUpdate + isSet bool +} + +func (v NullableLoadBalancerPortUpdate) Get() *LoadBalancerPortUpdate { + return v.value +} + +func (v *NullableLoadBalancerPortUpdate) Set(val *LoadBalancerPortUpdate) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerPortUpdate) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerPortUpdate) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerPortUpdate(val *LoadBalancerPortUpdate) *NullableLoadBalancerPortUpdate { + return &NullableLoadBalancerPortUpdate{value: val, isSet: true} +} + +func (v NullableLoadBalancerPortUpdate) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerPortUpdate) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_short.go b/internal/lbaas/v1/model_load_balancer_short.go new file mode 100644 index 000000000..d4173beb4 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_short.go @@ -0,0 +1,235 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "time" +) + +// checks if the LoadBalancerShort type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerShort{} + +// LoadBalancerShort struct for LoadBalancerShort +type LoadBalancerShort struct { + // ID of a load balancer + Id string `json:"id"` + // A name for the load balancer + Name string `json:"name"` + // Date and time of creation + CreatedAt time.Time `json:"created_at"` + // Date and time of last update + UpdatedAt time.Time `json:"updated_at"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerShort LoadBalancerShort + +// NewLoadBalancerShort instantiates a new LoadBalancerShort object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerShort(id string, name string, createdAt time.Time, updatedAt time.Time) *LoadBalancerShort { + this := LoadBalancerShort{} + this.Id = id + this.Name = name + this.CreatedAt = createdAt + this.UpdatedAt = updatedAt + return &this +} + +// NewLoadBalancerShortWithDefaults instantiates a new LoadBalancerShort object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerShortWithDefaults() *LoadBalancerShort { + this := LoadBalancerShort{} + return &this +} + +// GetId returns the Id field value +// If the value is explicit nil, the zero value for interface{} will be returned +func (o *LoadBalancerShort) GetId() string { + if o == nil { + var ret string + return ret + } + + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *LoadBalancerShort) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value +func (o *LoadBalancerShort) SetId(v string) { + o.Id = v +} + +// GetName returns the Name field value +func (o *LoadBalancerShort) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerShort) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *LoadBalancerShort) SetName(v string) { + o.Name = v +} + +// GetCreatedAt returns the CreatedAt field value +func (o *LoadBalancerShort) GetCreatedAt() time.Time { + if o == nil { + var ret time.Time + return ret + } + + return o.CreatedAt +} + +// GetCreatedAtOk returns a tuple with the CreatedAt field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerShort) GetCreatedAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return &o.CreatedAt, true +} + +// SetCreatedAt sets field value +func (o *LoadBalancerShort) SetCreatedAt(v time.Time) { + o.CreatedAt = v +} + +// GetUpdatedAt returns the UpdatedAt field value +func (o *LoadBalancerShort) GetUpdatedAt() time.Time { + if o == nil { + var ret time.Time + return ret + } + + return o.UpdatedAt +} + +// GetUpdatedAtOk returns a tuple with the UpdatedAt field value +// and a boolean to check if the value has been set. +func (o *LoadBalancerShort) GetUpdatedAtOk() (*time.Time, bool) { + if o == nil { + return nil, false + } + return &o.UpdatedAt, true +} + +// SetUpdatedAt sets field value +func (o *LoadBalancerShort) SetUpdatedAt(v time.Time) { + o.UpdatedAt = v +} + +func (o LoadBalancerShort) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerShort) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["id"] = o.Id + toSerialize["name"] = o.Name + toSerialize["created_at"] = o.CreatedAt + toSerialize["updated_at"] = o.UpdatedAt + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerShort) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerShort := _LoadBalancerShort{} + + err = json.Unmarshal(bytes, &varLoadBalancerShort) + + if err != nil { + return err + } + + *o = LoadBalancerShort(varLoadBalancerShort) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "id") + delete(additionalProperties, "name") + delete(additionalProperties, "created_at") + delete(additionalProperties, "updated_at") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerShort struct { + value *LoadBalancerShort + isSet bool +} + +func (v NullableLoadBalancerShort) Get() *LoadBalancerShort { + return v.value +} + +func (v *NullableLoadBalancerShort) Set(val *LoadBalancerShort) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerShort) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerShort) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerShort(val *LoadBalancerShort) *NullableLoadBalancerShort { + return &NullableLoadBalancerShort{value: val, isSet: true} +} + +func (v NullableLoadBalancerShort) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerShort) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_load_balancer_update.go b/internal/lbaas/v1/model_load_balancer_update.go new file mode 100644 index 000000000..22a42d522 --- /dev/null +++ b/internal/lbaas/v1/model_load_balancer_update.go @@ -0,0 +1,268 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the LoadBalancerUpdate type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &LoadBalancerUpdate{} + +// LoadBalancerUpdate struct for LoadBalancerUpdate +type LoadBalancerUpdate struct { + // Name of the load balancer + Name *string `json:"name,omitempty"` + // Add ports to load balancer + AddPortIds []string `json:"add_port_ids,omitempty"` + // Removed ports from load balancer + RemovePortIds []string `json:"remove_port_ids,omitempty"` + // Clear all ports from load balancer + ClearPorts *bool `json:"clear_ports,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _LoadBalancerUpdate LoadBalancerUpdate + +// NewLoadBalancerUpdate instantiates a new LoadBalancerUpdate object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewLoadBalancerUpdate() *LoadBalancerUpdate { + this := LoadBalancerUpdate{} + return &this +} + +// NewLoadBalancerUpdateWithDefaults instantiates a new LoadBalancerUpdate object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewLoadBalancerUpdateWithDefaults() *LoadBalancerUpdate { + this := LoadBalancerUpdate{} + return &this +} + +// GetName returns the Name field value if set, zero value otherwise. +func (o *LoadBalancerUpdate) GetName() string { + if o == nil || IsNil(o.Name) { + var ret string + return ret + } + return *o.Name +} + +// GetNameOk returns a tuple with the Name field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerUpdate) GetNameOk() (*string, bool) { + if o == nil || IsNil(o.Name) { + return nil, false + } + return o.Name, true +} + +// HasName returns a boolean if a field has been set. +func (o *LoadBalancerUpdate) HasName() bool { + if o != nil && !IsNil(o.Name) { + return true + } + + return false +} + +// SetName gets a reference to the given string and assigns it to the Name field. +func (o *LoadBalancerUpdate) SetName(v string) { + o.Name = &v +} + +// GetAddPortIds returns the AddPortIds field value if set, zero value otherwise. +func (o *LoadBalancerUpdate) GetAddPortIds() []string { + if o == nil || IsNil(o.AddPortIds) { + var ret []string + return ret + } + return o.AddPortIds +} + +// GetAddPortIdsOk returns a tuple with the AddPortIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerUpdate) GetAddPortIdsOk() ([]string, bool) { + if o == nil || IsNil(o.AddPortIds) { + return nil, false + } + return o.AddPortIds, true +} + +// HasAddPortIds returns a boolean if a field has been set. +func (o *LoadBalancerUpdate) HasAddPortIds() bool { + if o != nil && !IsNil(o.AddPortIds) { + return true + } + + return false +} + +// SetAddPortIds gets a reference to the given []string and assigns it to the AddPortIds field. +func (o *LoadBalancerUpdate) SetAddPortIds(v []string) { + o.AddPortIds = v +} + +// GetRemovePortIds returns the RemovePortIds field value if set, zero value otherwise. +func (o *LoadBalancerUpdate) GetRemovePortIds() []string { + if o == nil || IsNil(o.RemovePortIds) { + var ret []string + return ret + } + return o.RemovePortIds +} + +// GetRemovePortIdsOk returns a tuple with the RemovePortIds field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerUpdate) GetRemovePortIdsOk() ([]string, bool) { + if o == nil || IsNil(o.RemovePortIds) { + return nil, false + } + return o.RemovePortIds, true +} + +// HasRemovePortIds returns a boolean if a field has been set. +func (o *LoadBalancerUpdate) HasRemovePortIds() bool { + if o != nil && !IsNil(o.RemovePortIds) { + return true + } + + return false +} + +// SetRemovePortIds gets a reference to the given []string and assigns it to the RemovePortIds field. +func (o *LoadBalancerUpdate) SetRemovePortIds(v []string) { + o.RemovePortIds = v +} + +// GetClearPorts returns the ClearPorts field value if set, zero value otherwise. +func (o *LoadBalancerUpdate) GetClearPorts() bool { + if o == nil || IsNil(o.ClearPorts) { + var ret bool + return ret + } + return *o.ClearPorts +} + +// GetClearPortsOk returns a tuple with the ClearPorts field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *LoadBalancerUpdate) GetClearPortsOk() (*bool, bool) { + if o == nil || IsNil(o.ClearPorts) { + return nil, false + } + return o.ClearPorts, true +} + +// HasClearPorts returns a boolean if a field has been set. +func (o *LoadBalancerUpdate) HasClearPorts() bool { + if o != nil && !IsNil(o.ClearPorts) { + return true + } + + return false +} + +// SetClearPorts gets a reference to the given bool and assigns it to the ClearPorts field. +func (o *LoadBalancerUpdate) SetClearPorts(v bool) { + o.ClearPorts = &v +} + +func (o LoadBalancerUpdate) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o LoadBalancerUpdate) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Name) { + toSerialize["name"] = o.Name + } + if !IsNil(o.AddPortIds) { + toSerialize["add_port_ids"] = o.AddPortIds + } + if !IsNil(o.RemovePortIds) { + toSerialize["remove_port_ids"] = o.RemovePortIds + } + if !IsNil(o.ClearPorts) { + toSerialize["clear_ports"] = o.ClearPorts + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *LoadBalancerUpdate) UnmarshalJSON(bytes []byte) (err error) { + varLoadBalancerUpdate := _LoadBalancerUpdate{} + + err = json.Unmarshal(bytes, &varLoadBalancerUpdate) + + if err != nil { + return err + } + + *o = LoadBalancerUpdate(varLoadBalancerUpdate) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "name") + delete(additionalProperties, "add_port_ids") + delete(additionalProperties, "remove_port_ids") + delete(additionalProperties, "clear_ports") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableLoadBalancerUpdate struct { + value *LoadBalancerUpdate + isSet bool +} + +func (v NullableLoadBalancerUpdate) Get() *LoadBalancerUpdate { + return v.value +} + +func (v *NullableLoadBalancerUpdate) Set(val *LoadBalancerUpdate) { + v.value = val + v.isSet = true +} + +func (v NullableLoadBalancerUpdate) IsSet() bool { + return v.isSet +} + +func (v *NullableLoadBalancerUpdate) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableLoadBalancerUpdate(val *LoadBalancerUpdate) *NullableLoadBalancerUpdate { + return &NullableLoadBalancerUpdate{value: val, isSet: true} +} + +func (v NullableLoadBalancerUpdate) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableLoadBalancerUpdate) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_provider.go b/internal/lbaas/v1/model_provider.go new file mode 100644 index 000000000..4b7915b1e --- /dev/null +++ b/internal/lbaas/v1/model_provider.go @@ -0,0 +1,183 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the Provider type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Provider{} + +// Provider struct for Provider +type Provider struct { + // ID of the provider + Id *string `json:"id,omitempty"` + // A name for the provider + Name string `json:"name"` + AdditionalProperties map[string]interface{} +} + +type _Provider Provider + +// NewProvider instantiates a new Provider object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewProvider(name string) *Provider { + this := Provider{} + this.Name = name + return &this +} + +// NewProviderWithDefaults instantiates a new Provider object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewProviderWithDefaults() *Provider { + this := Provider{} + return &this +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *Provider) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Provider) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *Provider) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *Provider) SetId(v string) { + o.Id = &v +} + +// GetName returns the Name field value +func (o *Provider) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *Provider) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value +func (o *Provider) SetName(v string) { + o.Name = v +} + +func (o Provider) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Provider) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + toSerialize["name"] = o.Name + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *Provider) UnmarshalJSON(bytes []byte) (err error) { + varProvider := _Provider{} + + err = json.Unmarshal(bytes, &varProvider) + + if err != nil { + return err + } + + *o = Provider(varProvider) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "id") + delete(additionalProperties, "name") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableProvider struct { + value *Provider + isSet bool +} + +func (v NullableProvider) Get() *Provider { + return v.value +} + +func (v *NullableProvider) Set(val *Provider) { + v.value = val + v.isSet = true +} + +func (v NullableProvider) IsSet() bool { + return v.isSet +} + +func (v *NullableProvider) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableProvider(val *Provider) *NullableProvider { + return &NullableProvider{value: val, isSet: true} +} + +func (v NullableProvider) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableProvider) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/model_resource_created_response.go b/internal/lbaas/v1/model_resource_created_response.go new file mode 100644 index 000000000..30c3c89e0 --- /dev/null +++ b/internal/lbaas/v1/model_resource_created_response.go @@ -0,0 +1,268 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" +) + +// checks if the ResourceCreatedResponse type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ResourceCreatedResponse{} + +// ResourceCreatedResponse struct for ResourceCreatedResponse +type ResourceCreatedResponse struct { + // API Version + Version *string `json:"version,omitempty"` + // Response message + Message *string `json:"message,omitempty"` + // ID of resource + Id *string `json:"id,omitempty"` + // Status of response + Status *int32 `json:"status,omitempty"` + AdditionalProperties map[string]interface{} +} + +type _ResourceCreatedResponse ResourceCreatedResponse + +// NewResourceCreatedResponse instantiates a new ResourceCreatedResponse object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewResourceCreatedResponse() *ResourceCreatedResponse { + this := ResourceCreatedResponse{} + return &this +} + +// NewResourceCreatedResponseWithDefaults instantiates a new ResourceCreatedResponse object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewResourceCreatedResponseWithDefaults() *ResourceCreatedResponse { + this := ResourceCreatedResponse{} + return &this +} + +// GetVersion returns the Version field value if set, zero value otherwise. +func (o *ResourceCreatedResponse) GetVersion() string { + if o == nil || IsNil(o.Version) { + var ret string + return ret + } + return *o.Version +} + +// GetVersionOk returns a tuple with the Version field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ResourceCreatedResponse) GetVersionOk() (*string, bool) { + if o == nil || IsNil(o.Version) { + return nil, false + } + return o.Version, true +} + +// HasVersion returns a boolean if a field has been set. +func (o *ResourceCreatedResponse) HasVersion() bool { + if o != nil && !IsNil(o.Version) { + return true + } + + return false +} + +// SetVersion gets a reference to the given string and assigns it to the Version field. +func (o *ResourceCreatedResponse) SetVersion(v string) { + o.Version = &v +} + +// GetMessage returns the Message field value if set, zero value otherwise. +func (o *ResourceCreatedResponse) GetMessage() string { + if o == nil || IsNil(o.Message) { + var ret string + return ret + } + return *o.Message +} + +// GetMessageOk returns a tuple with the Message field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ResourceCreatedResponse) GetMessageOk() (*string, bool) { + if o == nil || IsNil(o.Message) { + return nil, false + } + return o.Message, true +} + +// HasMessage returns a boolean if a field has been set. +func (o *ResourceCreatedResponse) HasMessage() bool { + if o != nil && !IsNil(o.Message) { + return true + } + + return false +} + +// SetMessage gets a reference to the given string and assigns it to the Message field. +func (o *ResourceCreatedResponse) SetMessage(v string) { + o.Message = &v +} + +// GetId returns the Id field value if set, zero value otherwise. +func (o *ResourceCreatedResponse) GetId() string { + if o == nil || IsNil(o.Id) { + var ret string + return ret + } + return *o.Id +} + +// GetIdOk returns a tuple with the Id field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ResourceCreatedResponse) GetIdOk() (*string, bool) { + if o == nil || IsNil(o.Id) { + return nil, false + } + return o.Id, true +} + +// HasId returns a boolean if a field has been set. +func (o *ResourceCreatedResponse) HasId() bool { + if o != nil && !IsNil(o.Id) { + return true + } + + return false +} + +// SetId gets a reference to the given string and assigns it to the Id field. +func (o *ResourceCreatedResponse) SetId(v string) { + o.Id = &v +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *ResourceCreatedResponse) GetStatus() int32 { + if o == nil || IsNil(o.Status) { + var ret int32 + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ResourceCreatedResponse) GetStatusOk() (*int32, bool) { + if o == nil || IsNil(o.Status) { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *ResourceCreatedResponse) HasStatus() bool { + if o != nil && !IsNil(o.Status) { + return true + } + + return false +} + +// SetStatus gets a reference to the given int32 and assigns it to the Status field. +func (o *ResourceCreatedResponse) SetStatus(v int32) { + o.Status = &v +} + +func (o ResourceCreatedResponse) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ResourceCreatedResponse) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Version) { + toSerialize["version"] = o.Version + } + if !IsNil(o.Message) { + toSerialize["message"] = o.Message + } + if !IsNil(o.Id) { + toSerialize["id"] = o.Id + } + if !IsNil(o.Status) { + toSerialize["status"] = o.Status + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + + return toSerialize, nil +} + +func (o *ResourceCreatedResponse) UnmarshalJSON(bytes []byte) (err error) { + varResourceCreatedResponse := _ResourceCreatedResponse{} + + err = json.Unmarshal(bytes, &varResourceCreatedResponse) + + if err != nil { + return err + } + + *o = ResourceCreatedResponse(varResourceCreatedResponse) + + additionalProperties := make(map[string]interface{}) + + if err = json.Unmarshal(bytes, &additionalProperties); err == nil { + delete(additionalProperties, "version") + delete(additionalProperties, "message") + delete(additionalProperties, "id") + delete(additionalProperties, "status") + o.AdditionalProperties = additionalProperties + } + + return err +} + +type NullableResourceCreatedResponse struct { + value *ResourceCreatedResponse + isSet bool +} + +func (v NullableResourceCreatedResponse) Get() *ResourceCreatedResponse { + return v.value +} + +func (v *NullableResourceCreatedResponse) Set(val *ResourceCreatedResponse) { + v.value = val + v.isSet = true +} + +func (v NullableResourceCreatedResponse) IsSet() bool { + return v.isSet +} + +func (v *NullableResourceCreatedResponse) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableResourceCreatedResponse(val *ResourceCreatedResponse) *NullableResourceCreatedResponse { + return &NullableResourceCreatedResponse{value: val, isSet: true} +} + +func (v NullableResourceCreatedResponse) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableResourceCreatedResponse) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/internal/lbaas/v1/response.go b/internal/lbaas/v1/response.go new file mode 100644 index 000000000..50a63f7cb --- /dev/null +++ b/internal/lbaas/v1/response.go @@ -0,0 +1,47 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "net/http" +) + +// APIResponse stores the API response returned by the server. +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the OpenAPI operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +// NewAPIResponse returns a new APIResponse object. +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +// NewAPIResponseWithError returns a new APIResponse object with the provided error message. +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/internal/lbaas/v1/utils.go b/internal/lbaas/v1/utils.go new file mode 100644 index 000000000..813461892 --- /dev/null +++ b/internal/lbaas/v1/utils.go @@ -0,0 +1,347 @@ +/* +Load Balancer Management API + +Load Balancer Management API is an API for managing load balancers. + +API version: 0.0.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package v1 + +import ( + "encoding/json" + "reflect" + "time" +) + +// PtrBool is a helper routine that returns a pointer to given boolean value. +func PtrBool(v bool) *bool { return &v } + +// PtrInt is a helper routine that returns a pointer to given integer value. +func PtrInt(v int) *int { return &v } + +// PtrInt32 is a helper routine that returns a pointer to given integer value. +func PtrInt32(v int32) *int32 { return &v } + +// PtrInt64 is a helper routine that returns a pointer to given integer value. +func PtrInt64(v int64) *int64 { return &v } + +// PtrFloat32 is a helper routine that returns a pointer to given float value. +func PtrFloat32(v float32) *float32 { return &v } + +// PtrFloat64 is a helper routine that returns a pointer to given float value. +func PtrFloat64(v float64) *float64 { return &v } + +// PtrString is a helper routine that returns a pointer to given string value. +func PtrString(v string) *string { return &v } + +// PtrTime is helper routine that returns a pointer to given Time value. +func PtrTime(v time.Time) *time.Time { return &v } + +type NullableBool struct { + value *bool + isSet bool +} + +func (v NullableBool) Get() *bool { + return v.value +} + +func (v *NullableBool) Set(val *bool) { + v.value = val + v.isSet = true +} + +func (v NullableBool) IsSet() bool { + return v.isSet +} + +func (v *NullableBool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBool(val *bool) *NullableBool { + return &NullableBool{value: val, isSet: true} +} + +func (v NullableBool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt struct { + value *int + isSet bool +} + +func (v NullableInt) Get() *int { + return v.value +} + +func (v *NullableInt) Set(val *int) { + v.value = val + v.isSet = true +} + +func (v NullableInt) IsSet() bool { + return v.isSet +} + +func (v *NullableInt) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt(val *int) *NullableInt { + return &NullableInt{value: val, isSet: true} +} + +func (v NullableInt) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt32 struct { + value *int32 + isSet bool +} + +func (v NullableInt32) Get() *int32 { + return v.value +} + +func (v *NullableInt32) Set(val *int32) { + v.value = val + v.isSet = true +} + +func (v NullableInt32) IsSet() bool { + return v.isSet +} + +func (v *NullableInt32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt32(val *int32) *NullableInt32 { + return &NullableInt32{value: val, isSet: true} +} + +func (v NullableInt32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt64 struct { + value *int64 + isSet bool +} + +func (v NullableInt64) Get() *int64 { + return v.value +} + +func (v *NullableInt64) Set(val *int64) { + v.value = val + v.isSet = true +} + +func (v NullableInt64) IsSet() bool { + return v.isSet +} + +func (v *NullableInt64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt64(val *int64) *NullableInt64 { + return &NullableInt64{value: val, isSet: true} +} + +func (v NullableInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat32 struct { + value *float32 + isSet bool +} + +func (v NullableFloat32) Get() *float32 { + return v.value +} + +func (v *NullableFloat32) Set(val *float32) { + v.value = val + v.isSet = true +} + +func (v NullableFloat32) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat32(val *float32) *NullableFloat32 { + return &NullableFloat32{value: val, isSet: true} +} + +func (v NullableFloat32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat64 struct { + value *float64 + isSet bool +} + +func (v NullableFloat64) Get() *float64 { + return v.value +} + +func (v *NullableFloat64) Set(val *float64) { + v.value = val + v.isSet = true +} + +func (v NullableFloat64) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat64(val *float64) *NullableFloat64 { + return &NullableFloat64{value: val, isSet: true} +} + +func (v NullableFloat64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableString struct { + value *string + isSet bool +} + +func (v NullableString) Get() *string { + return v.value +} + +func (v *NullableString) Set(val *string) { + v.value = val + v.isSet = true +} + +func (v NullableString) IsSet() bool { + return v.isSet +} + +func (v *NullableString) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableString(val *string) *NullableString { + return &NullableString{value: val, isSet: true} +} + +func (v NullableString) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableString) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableTime struct { + value *time.Time + isSet bool +} + +func (v NullableTime) Get() *time.Time { + return v.value +} + +func (v *NullableTime) Set(val *time.Time) { + v.value = val + v.isSet = true +} + +func (v NullableTime) IsSet() bool { + return v.isSet +} + +func (v *NullableTime) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTime(val *time.Time) *NullableTime { + return &NullableTime{value: val, isSet: true} +} + +func (v NullableTime) MarshalJSON() ([]byte, error) { + return v.value.MarshalJSON() +} + +func (v *NullableTime) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// IsNil checks if an input is nil +func IsNil(i interface{}) bool { + if i == nil { + return true + } + switch reflect.TypeOf(i).Kind() { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: + return reflect.ValueOf(i).IsNil() + case reflect.Array: + return reflect.ValueOf(i).IsZero() + } + return false +} + +type MappedNullable interface { + ToMap() (map[string]interface{}, error) +} diff --git a/pkg/cloud/packet/client.go b/pkg/cloud/packet/client.go index 150cc5b6a..8ba06eba4 100644 --- a/pkg/cloud/packet/client.go +++ b/pkg/cloud/packet/client.go @@ -104,6 +104,8 @@ type CreateDeviceRequest struct { ExtraTags []string MachineScope *scope.MachineScope ControlPlaneEndpoint string + CPEMLBConfig string + EMLBID string } // NewDevice creates a new device. @@ -145,6 +147,14 @@ func (p *Client) NewDevice(ctx context.Context, req CreateDeviceRequest) (*metal userDataValues["controlPlaneEndpoint"] = req.ControlPlaneEndpoint } + if req.CPEMLBConfig != "" { + userDataValues["cpemConfig"] = req.CPEMLBConfig + } + + if req.EMLBID != "" { + userDataValues["emlbID"] = req.EMLBID + } + tags = append(tags, infrav1.ControlPlaneTag) } else { tags = append(tags, infrav1.WorkerTag) diff --git a/templates/cluster-template-emlb.yaml b/templates/cluster-template-emlb.yaml new file mode 100644 index 000000000..6e6249ba7 --- /dev/null +++ b/templates/cluster-template-emlb.yaml @@ -0,0 +1,243 @@ +kind: KubeadmControlPlane +apiVersion: controlplane.cluster.x-k8s.io/v1beta1 +metadata: + name: "${CLUSTER_NAME}-control-plane" +spec: + version: ${KUBERNETES_VERSION} + replicas: ${CONTROL_PLANE_MACHINE_COUNT} + machineTemplate: + infrastructureRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: PacketMachineTemplate + name: "${CLUSTER_NAME}-control-plane" + kubeadmConfigSpec: + clusterConfiguration: + apiServer: + extraArgs: + cloud-provider: external + controllerManager: + extraArgs: + cloud-provider: external + initConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: "equinixmetal://{{ `{{ v1.instance_id }}` }}" + joinConfiguration: + nodeRegistration: + ignorePreflightErrors: + - DirAvailable--etc-kubernetes-manifests + kubeletExtraArgs: + cloud-provider: external + provider-id: "equinixmetal://{{ `{{ v1.instance_id }}` }}" + preKubeadmCommands: + - | + sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab + swapoff -a + mount -a + cat < /etc/modules-load.d/containerd.conf + overlay + br_netfilter + EOF + modprobe overlay + modprobe br_netfilter + cat < /etc/sysctl.d/99-kubernetes-cri.conf + net.bridge.bridge-nf-call-iptables = 1 + net.ipv4.ip_forward = 1 + net.bridge.bridge-nf-call-ip6tables = 1 + EOF + sysctl --system + export DEBIAN_FRONTEND=noninteractive + apt-get update -y + apt-get remove -y docker docker-engine containerd runc + apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release linux-generic jq + major_vers=$(lsb_release -r | awk '{ print $2 }' | cut -d. -f1) + if [ "$major_vers" -ge 20 ]; then + apt-get install -y kubetail + fi + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + MINOR_KUBERNETES_VERSION=$(echo {{ .kubernetesVersion }} | cut -d. -f1-2 ) + curl -fsSL https://pkgs.k8s.io/core:/stable:/$${MINOR_KUBERNETES_VERSION}/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + chmod a+r /etc/apt/keyrings/docker.gpg + chmod a+r /etc/apt/keyrings/kubernetes-archive-keyring.gpg + echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" > /etc/apt/sources.list.d/docker.list + echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/$${MINOR_KUBERNETES_VERSION}/deb/ /" > /etc/apt/sources.list.d/kubernetes.list + apt-get update -y + TRIMMED_KUBERNETES_VERSION=$(echo {{ .kubernetesVersion }} | sed 's/\./\\\\./g' | sed 's/^v//') + RESOLVED_KUBERNETES_VERSION=$(apt-cache madison kubelet | awk -v VERSION=$${TRIMMED_KUBERNETES_VERSION} '$3~ VERSION { print $3 }' | head -n1) + apt-get install -y containerd.io kubelet=$${RESOLVED_KUBERNETES_VERSION} kubeadm=$${RESOLVED_KUBERNETES_VERSION} kubectl=$${RESOLVED_KUBERNETES_VERSION} + containerd config default > /etc/containerd/config.toml + cat < /etc/crictl.yaml + runtime-endpoint: unix:///run/containerd/containerd.sock + image-endpoint: unix:///run/containerd/containerd.sock + EOF + sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml + sed -i "s,sandbox_image.*$,sandbox_image = \"$(kubeadm config images list | grep pause | sort -r | head -n1)\"," /etc/containerd/config.toml + systemctl restart containerd + ping -c 3 -q {{ .controlPlaneEndpoint }} && echo OK || ip addr add {{ .controlPlaneEndpoint }} dev lo + postKubeadmCommands: + - | + cat <> /etc/network/interfaces + auto lo:0 + iface lo:0 inet static + address {{ .controlPlaneEndpoint }} + netmask 255.255.255.255 + EOF + systemctl restart networking + mkdir -p $HOME/.kube + cp /etc/kubernetes/admin.conf $HOME/.kube/config + echo "source <(kubectl completion bash)" >> $HOME/.bashrc + echo "alias k=kubectl" >> $HOME/.bashrc + echo "complete -o default -F __start_kubectl k" >> $HOME/.bashrc + if [ -f "/run/kubeadm/kubeadm.yaml" ]; then + export KUBECONFIG=/etc/kubernetes/admin.conf + export CPEM_YAML=https://github.com/equinix/cloud-provider-equinix-metal/releases/download/${CPEM_VERSION:=v3.8.0}/deployment.yaml + export SECRET_DATA='cloud-sa.json=''{"apiKey": "{{ .apiKey }}","projectID": "${PROJECT_ID}","loadbalancer": "{{ .cpemConfig }}","loadBalancerID": "{{ .emlbID }}"}''' + kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}" || (sleep 1 && kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}") || (sleep 1 && kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}") + kubectl apply -f $${CPEM_YAML} || (sleep 1 && kubectl apply -f $${CPEM_YAML}) || (sleep 1 && kubectl apply -f $${CPEM_YAML}) + fi +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: PacketMachineTemplate +metadata: + name: "${CLUSTER_NAME}-control-plane" +spec: + template: + spec: + os: "${NODE_OS:=ubuntu_20_04}" + billingCycle: hourly + machineType: "${CONTROLPLANE_NODE_TYPE}" + sshKeys: + - "${SSH_KEY}" + tags: [] +--- +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + name: "${CLUSTER_NAME}" +spec: + clusterNetwork: + pods: + cidrBlocks: + - ${POD_CIDR:=192.168.0.0/16} + services: + cidrBlocks: + - ${SERVICE_CIDR:=172.26.0.0/16} + infrastructureRef: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: PacketCluster + name: "${CLUSTER_NAME}" + controlPlaneRef: + apiVersion: controlplane.cluster.x-k8s.io/v1beta1 + kind: KubeadmControlPlane + name: "${CLUSTER_NAME}-control-plane" +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: PacketCluster +metadata: + name: "${CLUSTER_NAME}" +spec: + projectID: "${PROJECT_ID}" + metro: "${METRO}" + vipManager: "EMLB" +--- +apiVersion: cluster.x-k8s.io/v1beta1 +kind: MachineDeployment +metadata: + name: ${CLUSTER_NAME}-worker-a + labels: + cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME} + pool: worker-a +spec: + replicas: ${WORKER_MACHINE_COUNT} + clusterName: ${CLUSTER_NAME} + selector: + matchLabels: + cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME} + pool: worker-a + template: + metadata: + labels: + cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME} + pool: worker-a + spec: + version: ${KUBERNETES_VERSION} + clusterName: ${CLUSTER_NAME} + bootstrap: + configRef: + name: ${CLUSTER_NAME}-worker-a + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 + kind: KubeadmConfigTemplate + infrastructureRef: + name: ${CLUSTER_NAME}-worker-a + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: PacketMachineTemplate +--- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: PacketMachineTemplate +metadata: + name: ${CLUSTER_NAME}-worker-a +spec: + template: + spec: + os: "${NODE_OS:=ubuntu_20_04}" + billingCycle: hourly + machineType: "${WORKER_NODE_TYPE}" + sshKeys: + - "${SSH_KEY}" + tags: [] +--- +kind: KubeadmConfigTemplate +apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 +metadata: + name: "${CLUSTER_NAME}-worker-a" +spec: + template: + spec: + joinConfiguration: + nodeRegistration: + kubeletExtraArgs: + cloud-provider: external + provider-id: "equinixmetal://{{ `{{ v1.instance_id }}` }}" + preKubeadmCommands: + - | + sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab + swapoff -a + mount -a + cat < /etc/modules-load.d/containerd.conf + overlay + br_netfilter + EOF + modprobe overlay + modprobe br_netfilter + cat < /etc/sysctl.d/99-kubernetes-cri.conf + net.bridge.bridge-nf-call-iptables = 1 + net.ipv4.ip_forward = 1 + net.bridge.bridge-nf-call-ip6tables = 1 + EOF + sysctl --system + export DEBIAN_FRONTEND=noninteractive + apt-get update -y + apt-get remove -y docker docker-engine containerd runc + apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release linux-generic jq + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + MINOR_KUBERNETES_VERSION=$(echo {{ .kubernetesVersion }} | cut -d. -f1-2 ) + curl -fsSL https://pkgs.k8s.io/core:/stable:/$${MINOR_KUBERNETES_VERSION}/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + chmod a+r /etc/apt/keyrings/docker.gpg + chmod a+r /etc/apt/keyrings/kubernetes-archive-keyring.gpg + echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" > /etc/apt/sources.list.d/docker.list + echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/$${MINOR_KUBERNETES_VERSION}/deb/ /" > /etc/apt/sources.list.d/kubernetes.list + apt-get update -y + TRIMMED_KUBERNETES_VERSION=$(echo {{ .kubernetesVersion }} | sed 's/\./\\\\./g' | sed 's/^v//') + RESOLVED_KUBERNETES_VERSION=$(apt-cache madison kubelet | awk -v VERSION=$${TRIMMED_KUBERNETES_VERSION} '$3~ VERSION { print $3 }' | head -n1) + apt-get install -y containerd.io kubelet=$${RESOLVED_KUBERNETES_VERSION} kubeadm=$${RESOLVED_KUBERNETES_VERSION} kubectl=$${RESOLVED_KUBERNETES_VERSION} + cat < /etc/crictl.yaml + runtime-endpoint: unix:///run/containerd/containerd.sock + image-endpoint: unix:///run/containerd/containerd.sock + EOF + containerd config default > /etc/containerd/config.toml + sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml + sed -i "s,sandbox_image.*$,sandbox_image = \"$(kubeadm config images list | grep pause | sort -r | head -n1)\"," /etc/containerd/config.toml + systemctl restart containerd diff --git a/test/e2e/config/packet-ci.yaml b/test/e2e/config/packet-ci.yaml index 1c68f7d08..68d9d8e84 100644 --- a/test/e2e/config/packet-ci.yaml +++ b/test/e2e/config/packet-ci.yaml @@ -79,6 +79,20 @@ providers: - sourcePath: "../data/v1beta1/cluster-template-node-drain.yaml" - sourcePath: "../data/v1beta1/cluster-template-md-remediation.yaml" - sourcePath: "../data/v1beta1/cluster-template-kcp-remediation.yaml" + - name: v1.7.99 # next; use manifest from source files + value: "../../../config/default" + replacements: + - old: "image: .*/cluster-api-provider-packet:.*" + new: "image: ${REGISTRY:=quay.io}/${IMAGE_NAME:=kubernetes-sigs/cluster-api-provider-packet}:${TAG:=e2e}" + contract: v1beta1 + files: + - sourcePath: "../../../metadata.yaml" + - sourcePath: "../data/v1beta1/cluster-template.yaml" + - sourcePath: "../data/v1beta1/cluster-template-kube-vip.yaml" + - sourcePath: "../data/v1beta1/cluster-template-kcp-scale-in.yaml" + - sourcePath: "../data/v1beta1/cluster-template-node-drain.yaml" + - sourcePath: "../data/v1beta1/cluster-template-md-remediation.yaml" + - sourcePath: "../data/v1beta1/cluster-template-kcp-remediation.yaml" variables: # Update to versions matching https://github.com/kubernetes-sigs/cluster-api/blob/v{VERSION}/test/e2e/config/docker.yaml diff --git a/test/e2e/data/shared/v1beta1/metadata.yaml b/test/e2e/data/shared/v1beta1/metadata.yaml index ca0310b8e..80294287a 100644 --- a/test/e2e/data/shared/v1beta1/metadata.yaml +++ b/test/e2e/data/shared/v1beta1/metadata.yaml @@ -2,6 +2,9 @@ apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3 kind: Metadata releaseSeries: + - major: 1 + minor: 7 + contract: v1beta1 - major: 1 minor: 6 contract: v1beta1 @@ -23,9 +26,3 @@ releaseSeries: - major: 1 minor: 0 contract: v1beta1 - - major: 0 - minor: 4 - contract: v1alpha4 - - major: 0 - minor: 3 - contract: v1alpha3 diff --git a/tilt-provider.json b/tilt-provider.json index 23ebc6526..f879eea4b 100644 --- a/tilt-provider.json +++ b/tilt-provider.json @@ -3,7 +3,7 @@ "config": { "image": "quay.io/equinix-oss/cluster-api-provider-packet", "live_reload_deps": [ - "main.go", "go.mod", "go.sum", "api", "controllers", "pkg" + "main.go", "go.mod", "go.sum", "api", "controllers", "pkg", "internal" ], "label": "packet", "manager_name": "cluster-api-provider-packet-controller-manager" From 8a27c63bad7b6b203e43d08bdb278754b995e10a Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:07:47 +0000 Subject: [PATCH 02/16] fix: don't tell cpem about the VIP load balancer Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- templates/cluster-template-emlb.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/cluster-template-emlb.yaml b/templates/cluster-template-emlb.yaml index 6e6249ba7..3337d63a4 100644 --- a/templates/cluster-template-emlb.yaml +++ b/templates/cluster-template-emlb.yaml @@ -93,7 +93,7 @@ spec: if [ -f "/run/kubeadm/kubeadm.yaml" ]; then export KUBECONFIG=/etc/kubernetes/admin.conf export CPEM_YAML=https://github.com/equinix/cloud-provider-equinix-metal/releases/download/${CPEM_VERSION:=v3.8.0}/deployment.yaml - export SECRET_DATA='cloud-sa.json=''{"apiKey": "{{ .apiKey }}","projectID": "${PROJECT_ID}","loadbalancer": "{{ .cpemConfig }}","loadBalancerID": "{{ .emlbID }}"}''' + export SECRET_DATA='cloud-sa.json=''{"apiKey": "{{ .apiKey }}","projectID": "${PROJECT_ID}"}''' kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}" || (sleep 1 && kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}") || (sleep 1 && kubectl create secret generic -n kube-system metal-cloud-config --from-literal="$${SECRET_DATA}") kubectl apply -f $${CPEM_YAML} || (sleep 1 && kubectl apply -f $${CPEM_YAML}) || (sleep 1 && kubectl apply -f $${CPEM_YAML}) fi From 08b98796b563ffe2389a0ddaf28f2c136abdc904 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:10:25 +0000 Subject: [PATCH 03/16] fix: fix duplicate "origin" in origin naming. Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- internal/emlb/emlb.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/emlb/emlb.go b/internal/emlb/emlb.go index 27b57bd5e..210603c61 100644 --- a/internal/emlb/emlb.go +++ b/internal/emlb/emlb.go @@ -369,9 +369,9 @@ func (e *EMLB) createPool(ctx context.Context, name string) (*lbaas.ResourceCrea return e.client.ProjectsApi.CreatePool(ctx, e.projectID).LoadBalancerPoolCreate(createPoolRequest).Execute() } -func (e *EMLB) createOrigin(ctx context.Context, poolID, poolName string, target *Target) (*lbaas.ResourceCreatedResponse, *http.Response, error) { +func (e *EMLB) createOrigin(ctx context.Context, poolID, originName string, target *Target) (*lbaas.ResourceCreatedResponse, *http.Response, error) { createOriginRequest := lbaas.LoadBalancerPoolOriginCreate{ - Name: getResourceName(poolName, "origin"), + Name: originName, Target: target.IP, PortNumber: lbaas.Int32AsLoadBalancerPoolOriginPortNumber(&target.Port), Active: true, From 3e53a2260411245b2f0b16b0438f18e4c81aadaa Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:10:50 +0000 Subject: [PATCH 04/16] fix: only plumb ip address on localhost on the first machine Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- templates/cluster-template-emlb.yaml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/templates/cluster-template-emlb.yaml b/templates/cluster-template-emlb.yaml index 3337d63a4..c7de6c204 100644 --- a/templates/cluster-template-emlb.yaml +++ b/templates/cluster-template-emlb.yaml @@ -75,16 +75,11 @@ spec: sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml sed -i "s,sandbox_image.*$,sandbox_image = \"$(kubeadm config images list | grep pause | sort -r | head -n1)\"," /etc/containerd/config.toml systemctl restart containerd - ping -c 3 -q {{ .controlPlaneEndpoint }} && echo OK || ip addr add {{ .controlPlaneEndpoint }} dev lo + if [ -f "/run/kubeadm/kubeadm.yaml" ]; then + ip addr add {{ .controlPlaneEndpoint }} dev lo + fi postKubeadmCommands: - | - cat <> /etc/network/interfaces - auto lo:0 - iface lo:0 inet static - address {{ .controlPlaneEndpoint }} - netmask 255.255.255.255 - EOF - systemctl restart networking mkdir -p $HOME/.kube cp /etc/kubernetes/admin.conf $HOME/.kube/config echo "source <(kubectl completion bash)" >> $HOME/.bashrc From b827ce3a76670b2283294fb34b37701650b27a60 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Mon, 13 May 2024 21:19:55 +0000 Subject: [PATCH 05/16] chore: re-make go-mod following rebase Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 060e683b3..f8484c2b6 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 + golang.org/x/oauth2 v0.18.0 k8s.io/api v0.29.3 k8s.io/apimachinery v0.29.3 k8s.io/client-go v0.29.3 @@ -73,7 +74,6 @@ require ( golang.org/x/crypto v0.23.0 // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/net v0.23.0 // indirect - golang.org/x/oauth2 v0.18.0 // indirect golang.org/x/sync v0.6.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/term v0.20.0 // indirect From b9ca34e6a7beacfe42ebe2c0d66288e5bacb2ff3 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Mon, 13 May 2024 21:22:14 +0000 Subject: [PATCH 06/16] chore: fix packetcluster crd base following merge with 1.7 branch Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- ...cture.cluster.x-k8s.io_packetclusters.yaml | 260 +++++++++--------- 1 file changed, 128 insertions(+), 132 deletions(-) diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_packetclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_packetclusters.yaml index 48eb07123..96aec7f95 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_packetclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_packetclusters.yaml @@ -9,146 +9,142 @@ spec: group: infrastructure.cluster.x-k8s.io names: categories: - - cluster-api + - cluster-api kind: PacketCluster listKind: PacketClusterList plural: packetclusters shortNames: - - pcl + - pcl singular: packetcluster scope: Namespaced versions: - - additionalPrinterColumns: - - description: Cluster to which this PacketCluster belongs - jsonPath: .metadata.labels.cluster\.x-k8s\.io/cluster-name - name: Cluster - type: string - - description: PacketCluster ready status - jsonPath: .status.ready - name: Ready - type: string - name: v1beta1 - schema: - openAPIV3Schema: - description: PacketCluster is the Schema for the packetclusters API. - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: PacketClusterSpec defines the desired state of PacketCluster. - properties: - controlPlaneEndpoint: - description: - ControlPlaneEndpoint represents the endpoint used to - communicate with the control plane. + - additionalPrinterColumns: + - description: Cluster to which this PacketCluster belongs + jsonPath: .metadata.labels.cluster\.x-k8s\.io/cluster-name + name: Cluster + type: string + - description: PacketCluster ready status + jsonPath: .status.ready + name: Ready + type: string + name: v1beta1 + schema: + openAPIV3Schema: + description: PacketCluster is the Schema for the packetclusters API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: PacketClusterSpec defines the desired state of PacketCluster. + properties: + controlPlaneEndpoint: + description: ControlPlaneEndpoint represents the endpoint used to + communicate with the control plane. + properties: + host: + description: The hostname on which the API server is serving. + type: string + port: + description: The port on which the API server is serving. + format: int32 + type: integer + required: + - host + - port + type: object + facility: + description: Facility represents the Packet facility for this cluster + type: string + metro: + description: Metro represents the Packet metro for this cluster + type: string + projectID: + description: ProjectID represents the Packet Project where this cluster + will be placed into + type: string + vipManager: + default: CPEM + description: |- + VIPManager represents whether this cluster uses CPEM or kube-vip or Equinix Metal Load Balancer to + manage its vip for the api server IP + enum: + - CPEM + - KUBE_VIP + - EMLB + type: string + required: + - projectID + - vipManager + type: object + status: + description: PacketClusterStatus defines the observed state of PacketCluster. + properties: + conditions: + description: Conditions defines current service state of the PacketCluster. + items: + description: Condition defines an observation of a Cluster API resource + operational state. properties: - host: - description: The hostname on which the API server is serving. + lastTransitionTime: + description: |- + Last time the condition transitioned from one status to another. + This should be when the underlying condition changed. If that is not known, then using the time when + the API field changed is acceptable. + format: date-time + type: string + message: + description: |- + A human readable message indicating details about the transition. + This field may be empty. + type: string + reason: + description: |- + The reason for the condition's last transition in CamelCase. + The specific API may choose whether or not this field is considered a guaranteed API. + This field may not be empty. + type: string + severity: + description: |- + Severity provides an explicit classification of Reason code, so the users or machines can immediately + understand the current situation and act accordingly. + The Severity field MUST be set only when Status=False. + type: string + status: + description: Status of the condition, one of True, False, Unknown. + type: string + type: + description: |- + Type of condition in CamelCase or in foo.example.com/CamelCase. + Many .condition.type values are consistent across resources like Available, but because arbitrary conditions + can be useful (see .node.status.conditions), the ability to deconflict is important. type: string - port: - description: The port on which the API server is serving. - format: int32 - type: integer required: - - host - - port + - lastTransitionTime + - status + - type type: object - facility: - description: Facility represents the Packet facility for this cluster - type: string - metro: - description: Metro represents the Packet metro for this cluster - type: string - projectID: - description: - ProjectID represents the Packet Project where this cluster - will be placed into - type: string - vipManager: - default: CPEM - description: - VIPManager represents whether this cluster uses CPEM - or kube-vip or Equinix Metal Load Balancer to manage its vip for - the api server IP - enum: - - CPEM - - KUBE_VIP - - EMLB - type: string - required: - - projectID - - vipManager - type: object - status: - description: PacketClusterStatus defines the observed state of PacketCluster. - properties: - conditions: - description: Conditions defines current service state of the PacketCluster. - items: - description: - Condition defines an observation of a Cluster API resource - operational state. - properties: - lastTransitionTime: - description: |- - Last time the condition transitioned from one status to another. - This should be when the underlying condition changed. If that is not known, then using the time when - the API field changed is acceptable. - format: date-time - type: string - message: - description: |- - A human readable message indicating details about the transition. - This field may be empty. - type: string - reason: - description: |- - The reason for the condition's last transition in CamelCase. - The specific API may choose whether or not this field is considered a guaranteed API. - This field may not be empty. - type: string - severity: - description: |- - Severity provides an explicit classification of Reason code, so the users or machines can immediately - understand the current situation and act accordingly. - The Severity field MUST be set only when Status=False. - type: string - status: - description: Status of the condition, one of True, False, Unknown. - type: string - type: - description: |- - Type of condition in CamelCase or in foo.example.com/CamelCase. - Many .condition.type values are consistent across resources like Available, but because arbitrary conditions - can be useful (see .node.status.conditions), the ability to deconflict is important. - type: string - required: - - lastTransitionTime - - status - - type - type: object - type: array - ready: - description: Ready denotes that the cluster (infrastructure) is ready. - type: boolean - type: object - type: object - served: true - storage: true - subresources: - status: {} + type: array + ready: + description: Ready denotes that the cluster (infrastructure) is ready. + type: boolean + type: object + type: object + served: true + storage: true + subresources: + status: {} From 68c379384918ace0dec506195d82c993fa7d36f2 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Tue, 14 May 2024 22:10:44 +0000 Subject: [PATCH 07/16] chore: add boilerplate Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- internal/emlb/emlb.go | 16 ++++++++++++++++ internal/emlb/emlb_test.go | 16 ++++++++++++++++ internal/emlb/token_exchanger.go | 16 ++++++++++++++++ internal/lbaas/v1/api_load_balancers.go | 16 ++++++++++++++++ internal/lbaas/v1/api_origins.go | 16 ++++++++++++++++ internal/lbaas/v1/api_pools.go | 16 ++++++++++++++++ internal/lbaas/v1/api_ports.go | 16 ++++++++++++++++ internal/lbaas/v1/api_projects.go | 16 ++++++++++++++++ internal/lbaas/v1/client.go | 16 ++++++++++++++++ internal/lbaas/v1/configuration.go | 16 ++++++++++++++++ internal/lbaas/v1/model_load_balancer.go | 16 ++++++++++++++++ .../lbaas/v1/model_load_balancer_collection.go | 16 ++++++++++++++++ internal/lbaas/v1/model_load_balancer_create.go | 16 ++++++++++++++++ .../lbaas/v1/model_load_balancer_location.go | 16 ++++++++++++++++ internal/lbaas/v1/model_load_balancer_pool.go | 16 ++++++++++++++++ .../v1/model_load_balancer_pool_collection.go | 16 ++++++++++++++++ .../lbaas/v1/model_load_balancer_pool_create.go | 16 ++++++++++++++++ .../model_load_balancer_pool_create_protocol.go | 16 ++++++++++++++++ .../lbaas/v1/model_load_balancer_pool_origin.go | 16 ++++++++++++++++ ...model_load_balancer_pool_origin_collection.go | 16 ++++++++++++++++ .../v1/model_load_balancer_pool_origin_create.go | 16 ++++++++++++++++ ...odel_load_balancer_pool_origin_port_number.go | 16 ++++++++++++++++ .../v1/model_load_balancer_pool_origin_update.go | 16 ++++++++++++++++ .../v1/model_load_balancer_pool_protocol.go | 16 ++++++++++++++++ .../lbaas/v1/model_load_balancer_pool_short.go | 16 ++++++++++++++++ .../lbaas/v1/model_load_balancer_pool_update.go | 16 ++++++++++++++++ internal/lbaas/v1/model_load_balancer_port.go | 16 ++++++++++++++++ .../v1/model_load_balancer_port_collection.go | 16 ++++++++++++++++ .../lbaas/v1/model_load_balancer_port_create.go | 16 ++++++++++++++++ .../lbaas/v1/model_load_balancer_port_update.go | 16 ++++++++++++++++ internal/lbaas/v1/model_load_balancer_short.go | 16 ++++++++++++++++ internal/lbaas/v1/model_load_balancer_update.go | 16 ++++++++++++++++ internal/lbaas/v1/model_provider.go | 16 ++++++++++++++++ .../lbaas/v1/model_resource_created_response.go | 16 ++++++++++++++++ internal/lbaas/v1/response.go | 16 ++++++++++++++++ internal/lbaas/v1/utils.go | 16 ++++++++++++++++ 36 files changed, 576 insertions(+) diff --git a/internal/emlb/emlb.go b/internal/emlb/emlb.go index 210603c61..38ab963f6 100644 --- a/internal/emlb/emlb.go +++ b/internal/emlb/emlb.go @@ -1,3 +1,19 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Package emlb manages authentication to the Equinix Metal Load Balancer service. package emlb diff --git a/internal/emlb/emlb_test.go b/internal/emlb/emlb_test.go index 09e3cc95d..bba799ae2 100644 --- a/internal/emlb/emlb_test.go +++ b/internal/emlb/emlb_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Package emlb manages authentication to the Equinix Metal Load Balancer service. package emlb diff --git a/internal/emlb/token_exchanger.go b/internal/emlb/token_exchanger.go index 04223896b..a94e8e8f5 100644 --- a/internal/emlb/token_exchanger.go +++ b/internal/emlb/token_exchanger.go @@ -1,3 +1,19 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package emlb import ( diff --git a/internal/lbaas/v1/api_load_balancers.go b/internal/lbaas/v1/api_load_balancers.go index f4805d5fc..6a5afa3da 100644 --- a/internal/lbaas/v1/api_load_balancers.go +++ b/internal/lbaas/v1/api_load_balancers.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/api_origins.go b/internal/lbaas/v1/api_origins.go index a2a82c646..d31898948 100644 --- a/internal/lbaas/v1/api_origins.go +++ b/internal/lbaas/v1/api_origins.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/api_pools.go b/internal/lbaas/v1/api_pools.go index bfd5908e1..7901481c9 100644 --- a/internal/lbaas/v1/api_pools.go +++ b/internal/lbaas/v1/api_pools.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/api_ports.go b/internal/lbaas/v1/api_ports.go index 58b7d927e..7e6b0d2ea 100644 --- a/internal/lbaas/v1/api_ports.go +++ b/internal/lbaas/v1/api_ports.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/api_projects.go b/internal/lbaas/v1/api_projects.go index 5808f96f2..669d28bc4 100644 --- a/internal/lbaas/v1/api_projects.go +++ b/internal/lbaas/v1/api_projects.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/client.go b/internal/lbaas/v1/client.go index 2dddafb6d..e00956017 100644 --- a/internal/lbaas/v1/client.go +++ b/internal/lbaas/v1/client.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/configuration.go b/internal/lbaas/v1/configuration.go index cc055b006..dc8b8fcf1 100644 --- a/internal/lbaas/v1/configuration.go +++ b/internal/lbaas/v1/configuration.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer.go b/internal/lbaas/v1/model_load_balancer.go index 793d399d8..c47deaedc 100644 --- a/internal/lbaas/v1/model_load_balancer.go +++ b/internal/lbaas/v1/model_load_balancer.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_collection.go b/internal/lbaas/v1/model_load_balancer_collection.go index 4159c5f83..661984c85 100644 --- a/internal/lbaas/v1/model_load_balancer_collection.go +++ b/internal/lbaas/v1/model_load_balancer_collection.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_create.go b/internal/lbaas/v1/model_load_balancer_create.go index 23f3564d7..44edf43e6 100644 --- a/internal/lbaas/v1/model_load_balancer_create.go +++ b/internal/lbaas/v1/model_load_balancer_create.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_location.go b/internal/lbaas/v1/model_load_balancer_location.go index f266f8401..9ceceb290 100644 --- a/internal/lbaas/v1/model_load_balancer_location.go +++ b/internal/lbaas/v1/model_load_balancer_location.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool.go b/internal/lbaas/v1/model_load_balancer_pool.go index 3e828ef70..5b2a05e4e 100644 --- a/internal/lbaas/v1/model_load_balancer_pool.go +++ b/internal/lbaas/v1/model_load_balancer_pool.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_collection.go b/internal/lbaas/v1/model_load_balancer_pool_collection.go index 5b9eee7ee..e15422339 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_collection.go +++ b/internal/lbaas/v1/model_load_balancer_pool_collection.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_create.go b/internal/lbaas/v1/model_load_balancer_pool_create.go index 966e95c49..2c0bf88c9 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_create.go +++ b/internal/lbaas/v1/model_load_balancer_pool_create.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_create_protocol.go b/internal/lbaas/v1/model_load_balancer_pool_create_protocol.go index bf24e1b46..05dabc9e5 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_create_protocol.go +++ b/internal/lbaas/v1/model_load_balancer_pool_create_protocol.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_origin.go b/internal/lbaas/v1/model_load_balancer_pool_origin.go index 63e8e5355..55f1f0ec5 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_origin.go +++ b/internal/lbaas/v1/model_load_balancer_pool_origin.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_origin_collection.go b/internal/lbaas/v1/model_load_balancer_pool_origin_collection.go index 5bc937fd2..c4263c90b 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_origin_collection.go +++ b/internal/lbaas/v1/model_load_balancer_pool_origin_collection.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_origin_create.go b/internal/lbaas/v1/model_load_balancer_pool_origin_create.go index 5923b0c1f..ce4e36b55 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_origin_create.go +++ b/internal/lbaas/v1/model_load_balancer_pool_origin_create.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_origin_port_number.go b/internal/lbaas/v1/model_load_balancer_pool_origin_port_number.go index 10acd5c03..980acaadd 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_origin_port_number.go +++ b/internal/lbaas/v1/model_load_balancer_pool_origin_port_number.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_origin_update.go b/internal/lbaas/v1/model_load_balancer_pool_origin_update.go index 0aa26d89e..add3627cd 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_origin_update.go +++ b/internal/lbaas/v1/model_load_balancer_pool_origin_update.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_protocol.go b/internal/lbaas/v1/model_load_balancer_pool_protocol.go index b06edb0f7..755177aaa 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_protocol.go +++ b/internal/lbaas/v1/model_load_balancer_pool_protocol.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_short.go b/internal/lbaas/v1/model_load_balancer_pool_short.go index 41db6348a..a81c03e6f 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_short.go +++ b/internal/lbaas/v1/model_load_balancer_pool_short.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_pool_update.go b/internal/lbaas/v1/model_load_balancer_pool_update.go index eaac0b31d..fc8106230 100644 --- a/internal/lbaas/v1/model_load_balancer_pool_update.go +++ b/internal/lbaas/v1/model_load_balancer_pool_update.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_port.go b/internal/lbaas/v1/model_load_balancer_port.go index 78336830a..caa0d5645 100644 --- a/internal/lbaas/v1/model_load_balancer_port.go +++ b/internal/lbaas/v1/model_load_balancer_port.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_port_collection.go b/internal/lbaas/v1/model_load_balancer_port_collection.go index f47a22479..99c0e77de 100644 --- a/internal/lbaas/v1/model_load_balancer_port_collection.go +++ b/internal/lbaas/v1/model_load_balancer_port_collection.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_port_create.go b/internal/lbaas/v1/model_load_balancer_port_create.go index 8bc6202bb..2231b74e8 100644 --- a/internal/lbaas/v1/model_load_balancer_port_create.go +++ b/internal/lbaas/v1/model_load_balancer_port_create.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_port_update.go b/internal/lbaas/v1/model_load_balancer_port_update.go index 4df032064..997d23e46 100644 --- a/internal/lbaas/v1/model_load_balancer_port_update.go +++ b/internal/lbaas/v1/model_load_balancer_port_update.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_short.go b/internal/lbaas/v1/model_load_balancer_short.go index d4173beb4..1f6666888 100644 --- a/internal/lbaas/v1/model_load_balancer_short.go +++ b/internal/lbaas/v1/model_load_balancer_short.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_load_balancer_update.go b/internal/lbaas/v1/model_load_balancer_update.go index 22a42d522..933eb0072 100644 --- a/internal/lbaas/v1/model_load_balancer_update.go +++ b/internal/lbaas/v1/model_load_balancer_update.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_provider.go b/internal/lbaas/v1/model_provider.go index 4b7915b1e..d2e2dff1f 100644 --- a/internal/lbaas/v1/model_provider.go +++ b/internal/lbaas/v1/model_provider.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/model_resource_created_response.go b/internal/lbaas/v1/model_resource_created_response.go index 30c3c89e0..2060ed501 100644 --- a/internal/lbaas/v1/model_resource_created_response.go +++ b/internal/lbaas/v1/model_resource_created_response.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/response.go b/internal/lbaas/v1/response.go index 50a63f7cb..d5d6b5f59 100644 --- a/internal/lbaas/v1/response.go +++ b/internal/lbaas/v1/response.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API diff --git a/internal/lbaas/v1/utils.go b/internal/lbaas/v1/utils.go index 813461892..79265724f 100644 --- a/internal/lbaas/v1/utils.go +++ b/internal/lbaas/v1/utils.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + /* Load Balancer Management API From 36203e27a23fac9f51c99c0680fb5d4f618c509e Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Mon, 20 May 2024 16:08:23 -0500 Subject: [PATCH 08/16] chore: fix linting issues Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- api/v1beta1/packetcluster_webhook.go | 2 +- api/v1beta1/packetmachine_webhook.go | 2 +- cmd/ci-clean/main.go | 2 +- controllers/packetcluster_controller.go | 4 ++-- controllers/packetmachine_controller.go | 4 ++-- internal/emlb/emlb.go | 2 ++ 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/v1beta1/packetcluster_webhook.go b/api/v1beta1/packetcluster_webhook.go index ff28413e8..575e37942 100644 --- a/api/v1beta1/packetcluster_webhook.go +++ b/api/v1beta1/packetcluster_webhook.go @@ -94,7 +94,7 @@ func (c *PacketCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warning } // Must have only one of Metro or Facility - if len(c.Spec.Facility) > 0 && len(c.Spec.Metro) > 0 { + if c.Spec.Facility != "" && c.Spec.Metro != "" { allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "Facility"), c.Spec.Facility, "Metro and Facility are mutually exclusive, Metro is recommended"), diff --git a/api/v1beta1/packetmachine_webhook.go b/api/v1beta1/packetmachine_webhook.go index f19aec35f..2cf30a766 100644 --- a/api/v1beta1/packetmachine_webhook.go +++ b/api/v1beta1/packetmachine_webhook.go @@ -53,7 +53,7 @@ func (m *PacketMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, var allErrs field.ErrorList // Must have only one of Metro or Facility specified - if len(m.Spec.Facility) > 0 && len(m.Spec.Metro) > 0 { + if m.Spec.Facility != "" && m.Spec.Metro != "" { allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "Facility"), m.Spec.Facility, "Metro and Facility field are mutually exclusive"), diff --git a/cmd/ci-clean/main.go b/cmd/ci-clean/main.go index 1be5e3a62..6f97929b3 100644 --- a/cmd/ci-clean/main.go +++ b/cmd/ci-clean/main.go @@ -43,7 +43,7 @@ func main() { rootCmd := &cobra.Command{ //nolint:exhaustivestruct Use: "ci-clean", Short: "Clean up any stray resources in CI", - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { metalAuthToken := os.Getenv(authTokenEnvVar) if metalAuthToken == "" { return fmt.Errorf("%s: %w", authTokenEnvVar, errMissingRequiredEnvVar) diff --git a/controllers/packetcluster_controller.go b/controllers/packetcluster_controller.go index d615fe8d7..ce0781372 100644 --- a/controllers/packetcluster_controller.go +++ b/controllers/packetcluster_controller.go @@ -116,7 +116,7 @@ func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterSc packetCluster := clusterScope.PacketCluster switch { - case packetCluster.Spec.VIPManager == "EMLB": + case packetCluster.Spec.VIPManager == emlb.EMLBVIPID: if !packetCluster.Spec.ControlPlaneEndpoint.IsValid() { // Create new EMLB object lb := emlb.NewEMLB(r.PacketClient.GetConfig().DefaultHeader["X-Auth-Token"], packetCluster.Spec.ProjectID, packetCluster.Spec.Metro) @@ -134,7 +134,7 @@ func (r *PacketClusterReconciler) reconcileNormal(ctx context.Context, clusterSc } } - if packetCluster.Spec.VIPManager != "EMLB" { + if packetCluster.Spec.VIPManager != emlb.EMLBVIPID { ipReserv, err := r.PacketClient.GetIPByClusterIdentifier(ctx, clusterScope.Namespace(), clusterScope.Name(), packetCluster.Spec.ProjectID) switch { case errors.Is(err, packet.ErrControlPlanEndpointNotFound): diff --git a/controllers/packetmachine_controller.go b/controllers/packetmachine_controller.go index 3f49b4960..01eab431c 100644 --- a/controllers/packetmachine_controller.go +++ b/controllers/packetmachine_controller.go @@ -367,7 +367,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s addrs = append(addrs, a) } controlPlaneEndpointAddress = controlPlaneEndpoint.GetAddress() - case machineScope.PacketCluster.Spec.VIPManager == "EMLB": + case machineScope.PacketCluster.Spec.VIPManager == emlb.EMLBVIPID: controlPlaneEndpointAddress = machineScope.Cluster.Spec.ControlPlaneEndpoint.Host cpemLBConfig = "emlb:///" + machineScope.PacketCluster.Spec.Metro emlbID = machineScope.PacketCluster.Annotations["equinix.com/loadbalancerID"] @@ -440,7 +440,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s return ctrl.Result{RequeueAfter: time.Second * 20}, nil } } - case machineScope.PacketCluster.Spec.VIPManager == "EMLB": + case machineScope.PacketCluster.Spec.VIPManager == emlb.EMLBVIPID: if machineScope.IsControlPlane() { // Create new EMLB object lb := emlb.NewEMLB(r.PacketClient.GetConfig().DefaultHeader["X-Auth-Token"], machineScope.PacketCluster.Spec.ProjectID, machineScope.PacketCluster.Spec.Metro) diff --git a/internal/emlb/emlb.go b/internal/emlb/emlb.go index 38ab963f6..e9520fe16 100644 --- a/internal/emlb/emlb.go +++ b/internal/emlb/emlb.go @@ -49,6 +49,8 @@ const ( loadBalancerPoolIDAnnotation = "equinix.com/loadbalancerpoolID" // loadBalancerPoolOriginIDAnnotation is the anotation key representing the origin ID of a PacketMachine. loadBalancerOriginIDAnnotation = "equinix.com/loadbalanceroriginID" + // EMLBVIPID is the stringused to refer to the EMLB load balancer and VIP Manager type. + EMLBVIPID = "EMLB" ) var lbMetros = map[string]string{ From f440057b0fcb0217052c1e5600992f6c25d0c3e5 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Mon, 20 May 2024 16:59:52 -0500 Subject: [PATCH 09/16] test: add additional tests Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- internal/emlb/emlb_test.go | 97 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/internal/emlb/emlb_test.go b/internal/emlb/emlb_test.go index bba799ae2..a9b426d25 100644 --- a/internal/emlb/emlb_test.go +++ b/internal/emlb/emlb_test.go @@ -18,12 +18,109 @@ limitations under the License. package emlb import ( + "os" "reflect" "testing" corev1 "k8s.io/api/core/v1" ) +func Test_getResourceName(t *testing.T) { + loadBalancerName := "my-loadbalancer" + resourceType := "pool" + want := "my-loadbalancer-pool" + + got := getResourceName(loadBalancerName, resourceType) + + if got != want { + t.Errorf("getResourceName() = %v, want %v", got, want) + } +} + +func Test_checkDebugEnabled(t *testing.T) { + // Set the PACKNGO_DEBUG environment variable to enable debug mode + if err := os.Setenv("PACKNGO_DEBUG", "true"); err != nil { + t.Errorf("Error testing checkDebugEnabled: %v", err) + } + + // Call the checkDebugEnabled function + debugEnabled := checkDebugEnabled() + + // Check if debugEnabled is true + if !debugEnabled { + t.Errorf("checkDebugEnabled() = %v, want %v", debugEnabled, true) + } + + // Unset the PACKNGO_DEBUG environment variable + os.Unsetenv("PACKNGO_DEBUG") + + // Call the checkDebugEnabled function again + debugEnabled = checkDebugEnabled() + + // Check if debugEnabled is false + if debugEnabled { + t.Errorf("checkDebugEnabled() = %v, want %v", debugEnabled, false) + } +} + +func Test_convertToTarget(t *testing.T) { + type args struct { + devaddr corev1.NodeAddress + } + tests := []struct { + name string + args args + want *Target + }{ + { + name: "Internal IP", + args: args{ + corev1.NodeAddress{ + Type: "InternalIP", + Address: "10.2.1.5", + }, + }, + want: &Target{ + IP: "10.2.1.5", + Port: loadBalancerVIPPort, + }, + }, + { + name: "External IP", + args: args{ + corev1.NodeAddress{ + Type: "ExternalIP", + Address: "1.2.3.4", + }, + }, + want: &Target{ + IP: "1.2.3.4", + Port: loadBalancerVIPPort, + }, + }, + { + name: "Empty IP", + args: args{ + corev1.NodeAddress{ + Type: "ExternalIP", + Address: "", + }, + }, + want: &Target{ + IP: "", + Port: loadBalancerVIPPort, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := convertToTarget(tt.args.devaddr); !reflect.DeepEqual(got, tt.want) { + t.Errorf("convertToTarget() = %v, want %v", got, tt.want) + } + }) + } +} + func Test_getExternalIPv4Target(t *testing.T) { type args struct { deviceAddr []corev1.NodeAddress From 911648e83bb6456ba6913a0748883601c31f7be4 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Thu, 23 May 2024 16:19:38 -0500 Subject: [PATCH 10/16] test: test newemlb function Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- internal/emlb/emlb_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/emlb/emlb_test.go b/internal/emlb/emlb_test.go index a9b426d25..f68a1612e 100644 --- a/internal/emlb/emlb_test.go +++ b/internal/emlb/emlb_test.go @@ -178,3 +178,23 @@ func Test_getExternalIPv4Target(t *testing.T) { }) } } +func TestNewEMLB(t *testing.T) { + metalAPIKey := "metal-api-key" //nolint:gosec + projectID := "project-id" + metro := "am" + + emlb := NewEMLB(metalAPIKey, projectID, metro) + + if emlb.client == nil { + t.Error("NewEMLB() client is nil") + } + if emlb.tokenExchanger == nil { + t.Error("NewEMLB() tokenExchanger is nil") + } + if emlb.projectID != projectID { + t.Errorf("NewEMLB() projectID = %s, want %s", emlb.projectID, projectID) + } + if emlb.metro != metro { + t.Errorf("NewEMLB() metro = %s, want %s", emlb.metro, metro) + } +} From ae9a1f37db2fa6ab0c20d3e20e53bd62efa308f8 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Thu, 23 May 2024 17:35:28 -0500 Subject: [PATCH 11/16] test: make token exchange settable so it can be tested, add test Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- internal/emlb/emlb.go | 7 +++- internal/emlb/token-exchanger_test.go | 57 +++++++++++++++++++++++++++ internal/emlb/token_exchanger.go | 8 ++-- 3 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 internal/emlb/token-exchanger_test.go diff --git a/internal/emlb/emlb.go b/internal/emlb/emlb.go index e9520fe16..a8c99b9d5 100644 --- a/internal/emlb/emlb.go +++ b/internal/emlb/emlb.go @@ -51,6 +51,8 @@ const ( loadBalancerOriginIDAnnotation = "equinix.com/loadbalanceroriginID" // EMLBVIPID is the stringused to refer to the EMLB load balancer and VIP Manager type. EMLBVIPID = "EMLB" + // loadbalancerTokenExchangeURL is the default URL to use for Token Exchange to talk to the Equinix Metal Load Balancer API + loadbalancerTokenExchnageURL = "https://iam.metalctrl.io/api-keys/exchange" //nolint:gosec ) var lbMetros = map[string]string{ @@ -87,8 +89,9 @@ func NewEMLB(metalAPIKey, projectID, metro string) *EMLB { manager.client = lbaas.NewAPIClient(emlbConfig) manager.tokenExchanger = &TokenExchanger{ - metalAPIKey: metalAPIKey, - client: manager.client.GetConfig().HTTPClient, + metalAPIKey: metalAPIKey, + tokenExchangeURL: loadbalancerTokenExchnageURL, + client: manager.client.GetConfig().HTTPClient, } manager.projectID = projectID manager.metro = metro diff --git a/internal/emlb/token-exchanger_test.go b/internal/emlb/token-exchanger_test.go new file mode 100644 index 000000000..749e301c0 --- /dev/null +++ b/internal/emlb/token-exchanger_test.go @@ -0,0 +1,57 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package emlb + +import ( + "net/http" + "net/http/httptest" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestTokenExchanger_Token(t *testing.T) { + // Create a mock server to handle the token exchange request + mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // Return a sample token response + response := `{"access_token": "sample_token", "expires_in": 3600}` + w.WriteHeader(http.StatusOK) + w.Write([]byte(response)) + })) + defer mockServer.Close() + + // Create a TokenExchanger instance with the mock server URL + exchanger := &TokenExchanger{ + metalAPIKey: "sample_api_key", + tokenExchangeURL: mockServer.URL, + client: mockServer.Client(), + } + + // Call the Token method + token, err := exchanger.Token() + + // Assert that no error occurred + assert.NoError(t, err) + + // Assert that the token is not nil + assert.NotNil(t, token) + + // Assert the token values + assert.Equal(t, "sample_token", token.AccessToken) + assert.Equal(t, time.Now().Add(time.Hour).Round(time.Second), token.Expiry.Round(time.Second)) +} diff --git a/internal/emlb/token_exchanger.go b/internal/emlb/token_exchanger.go index a94e8e8f5..1509abc8d 100644 --- a/internal/emlb/token_exchanger.go +++ b/internal/emlb/token_exchanger.go @@ -28,14 +28,14 @@ import ( // TokenExchanger is an client for authenticating to the Load Balancer API. type TokenExchanger struct { - metalAPIKey string - client *http.Client + metalAPIKey string + tokenExchangeURL string + client *http.Client } // Token creates a Token object to authenticate with the Load Balancer API. func (m *TokenExchanger) Token() (*oauth2.Token, error) { - tokenExchangeURL := "https://iam.metalctrl.io/api-keys/exchange" //nolint:gosec - tokenExchangeRequest, err := http.NewRequest(http.MethodPost, tokenExchangeURL, http.NoBody) //nolint:noctx // we can't find a way to get the ctx into here yet and just using context.Background adds no value that we can tell + tokenExchangeRequest, err := http.NewRequest(http.MethodPost, m.tokenExchangeURL, http.NoBody) //nolint:noctx // we can't find a way to get the ctx into here yet and just using context.Background adds no value that we can tell if err != nil { return nil, err } From 0737d5bd5c82503628477ce2ce8ecfbf929a0056 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Fri, 24 May 2024 16:06:56 -0500 Subject: [PATCH 12/16] refactor: change token exchanger to unmarshal expires_in better Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- internal/emlb/token_exchanger.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/internal/emlb/token_exchanger.go b/internal/emlb/token_exchanger.go index 1509abc8d..0ab1bd5d4 100644 --- a/internal/emlb/token_exchanger.go +++ b/internal/emlb/token_exchanger.go @@ -33,6 +33,12 @@ type TokenExchanger struct { client *http.Client } +// TokenResponse adds ExpiresIn to the OauthResponse struct. +type TokenResponse struct { + oauth2.Token + ExpiresIn int64 `json:"expires_in,omitempty"` +} + // Token creates a Token object to authenticate with the Load Balancer API. func (m *TokenExchanger) Token() (*oauth2.Token, error) { tokenExchangeRequest, err := http.NewRequest(http.MethodPost, m.tokenExchangeURL, http.NoBody) //nolint:noctx // we can't find a way to get the ctx into here yet and just using context.Background adds no value that we can tell @@ -55,20 +61,17 @@ func (m *TokenExchanger) Token() (*oauth2.Token, error) { return nil, fmt.Errorf("token exchange request failed with status %v, body %v", resp.StatusCode, string(body)) } - token := oauth2.Token{} - err = json.Unmarshal(body, &token) + var tokenResp TokenResponse + err = json.Unmarshal(body, &tokenResp) if err != nil { - fmt.Println(len(body)) - fmt.Println(token) - fmt.Println(err) return nil, err } - expiresIn := token.Extra("expires_in") - if expiresIn != nil { - expiresInSeconds := expiresIn.(int) - token.Expiry = time.Now().Add(time.Second * time.Duration(expiresInSeconds)) + fmt.Println(tokenResp.ExpiresIn) + + if tokenResp.Expiry.IsZero() && tokenResp.ExpiresIn != 0 { + tokenResp.Expiry = time.Now().Add(time.Second * time.Duration(tokenResp.ExpiresIn)) } - return &token, nil + return &tokenResp.Token, nil } From 5712aff5fbe6d0327955fc7add49f18176c2c494 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Fri, 24 May 2024 16:07:14 -0500 Subject: [PATCH 13/16] test: add tests for token-exchanger, now functional Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- internal/emlb/token-exchanger_test.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/emlb/token-exchanger_test.go b/internal/emlb/token-exchanger_test.go index 749e301c0..02950f706 100644 --- a/internal/emlb/token-exchanger_test.go +++ b/internal/emlb/token-exchanger_test.go @@ -27,11 +27,18 @@ import ( func TestTokenExchanger_Token(t *testing.T) { // Create a mock server to handle the token exchange request - mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // Return a sample token response - response := `{"access_token": "sample_token", "expires_in": 3600}` - w.WriteHeader(http.StatusOK) - w.Write([]byte(response)) + mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + // Set content type + w.Header().Set("Content-Type", "application/json") + // Write out oauth2 json response + _, err := w.Write([]byte(`{ + "access_token": "sample_token", + "token_type": "Bearer", + "expires_in": 3600 + }`)) + if err != nil { + t.Fatalf("failed to write json response, err = %v", err) + } })) defer mockServer.Close() From 34e472bf41f440f762cf3344d628102c4dcc584d Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Fri, 24 May 2024 16:07:29 -0500 Subject: [PATCH 14/16] chore: fix comment lint Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- internal/emlb/emlb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/emlb/emlb.go b/internal/emlb/emlb.go index a8c99b9d5..7280ff6ef 100644 --- a/internal/emlb/emlb.go +++ b/internal/emlb/emlb.go @@ -51,7 +51,7 @@ const ( loadBalancerOriginIDAnnotation = "equinix.com/loadbalanceroriginID" // EMLBVIPID is the stringused to refer to the EMLB load balancer and VIP Manager type. EMLBVIPID = "EMLB" - // loadbalancerTokenExchangeURL is the default URL to use for Token Exchange to talk to the Equinix Metal Load Balancer API + // loadbalancerTokenExchangeURL is the default URL to use for Token Exchange to talk to the Equinix Metal Load Balancer API. loadbalancerTokenExchnageURL = "https://iam.metalctrl.io/api-keys/exchange" //nolint:gosec ) From ad4b492204c10da026da951a45e447a67f50a611 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Fri, 24 May 2024 17:01:49 -0500 Subject: [PATCH 15/16] test: use gomega for asserts instead of testify to avoid extra dependency Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- go.mod | 2 ++ internal/emlb/emlb_test.go | 55 ++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index f8484c2b6..bedb964ff 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 + github.com/stretchr/testify v1.9.0 golang.org/x/oauth2 v0.18.0 k8s.io/api v0.29.3 k8s.io/apimachinery v0.29.3 @@ -58,6 +59,7 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.18.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.45.0 // indirect diff --git a/internal/emlb/emlb_test.go b/internal/emlb/emlb_test.go index f68a1612e..251fe1271 100644 --- a/internal/emlb/emlb_test.go +++ b/internal/emlb/emlb_test.go @@ -19,25 +19,27 @@ package emlb import ( "os" - "reflect" "testing" + . "github.com/onsi/gomega" + corev1 "k8s.io/api/core/v1" ) func Test_getResourceName(t *testing.T) { + g := NewWithT(t) loadBalancerName := "my-loadbalancer" resourceType := "pool" want := "my-loadbalancer-pool" got := getResourceName(loadBalancerName, resourceType) - if got != want { - t.Errorf("getResourceName() = %v, want %v", got, want) - } + // assert name is correct + g.Expect(got).To(Equal(want)) } func Test_checkDebugEnabled(t *testing.T) { + g := NewWithT(t) // Set the PACKNGO_DEBUG environment variable to enable debug mode if err := os.Setenv("PACKNGO_DEBUG", "true"); err != nil { t.Errorf("Error testing checkDebugEnabled: %v", err) @@ -47,9 +49,7 @@ func Test_checkDebugEnabled(t *testing.T) { debugEnabled := checkDebugEnabled() // Check if debugEnabled is true - if !debugEnabled { - t.Errorf("checkDebugEnabled() = %v, want %v", debugEnabled, true) - } + g.Expect(debugEnabled).To(BeTrue()) // Unset the PACKNGO_DEBUG environment variable os.Unsetenv("PACKNGO_DEBUG") @@ -58,9 +58,7 @@ func Test_checkDebugEnabled(t *testing.T) { debugEnabled = checkDebugEnabled() // Check if debugEnabled is false - if debugEnabled { - t.Errorf("checkDebugEnabled() = %v, want %v", debugEnabled, false) - } + g.Expect(debugEnabled).To(BeFalse()) } func Test_convertToTarget(t *testing.T) { @@ -114,9 +112,9 @@ func Test_convertToTarget(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := convertToTarget(tt.args.devaddr); !reflect.DeepEqual(got, tt.want) { - t.Errorf("convertToTarget() = %v, want %v", got, tt.want) - } + g := NewWithT(t) + got := convertToTarget(tt.args.devaddr) + g.Expect(got).To(Equal(tt.want)) }) } } @@ -167,34 +165,33 @@ func Test_getExternalIPv4Target(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + g := NewWithT(t) got, err := getExternalIPv4Target(tt.args.deviceAddr) if (err != nil) != tt.wantErr { - t.Errorf("getExternalIPv4Target() error = %v, wantErr %v", err, tt.wantErr) + g.Expect(err).To(Equal(tt.wantErr)) return } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("getExternalIPv4Target() = %v, want %v", got, tt.want) - } + g.Expect(got).To(Equal(tt.want)) }) } } func TestNewEMLB(t *testing.T) { + g := NewWithT(t) metalAPIKey := "metal-api-key" //nolint:gosec projectID := "project-id" metro := "am" emlb := NewEMLB(metalAPIKey, projectID, metro) - if emlb.client == nil { - t.Error("NewEMLB() client is nil") - } - if emlb.tokenExchanger == nil { - t.Error("NewEMLB() tokenExchanger is nil") - } - if emlb.projectID != projectID { - t.Errorf("NewEMLB() projectID = %s, want %s", emlb.projectID, projectID) - } - if emlb.metro != metro { - t.Errorf("NewEMLB() metro = %s, want %s", emlb.metro, metro) - } + // assert client is not nil + g.Expect(emlb.client).To(Not(BeNil())) + + // assert tokenExchanger is not nil + g.Expect(emlb.tokenExchanger).To(Not(BeNil())) + + // assert project ID is correct + g.Expect(emlb.projectID).To(Equal(projectID)) + + // assert metro is correct + g.Expect(emlb.metro).To(Equal(metro)) } From 4ca3b7663aedcd76016a4c8e273368bd75af217c Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Fri, 24 May 2024 17:09:42 -0500 Subject: [PATCH 16/16] test: clean up wanterr logic to be more readable as an assert Signed-off-by: Chris Privitere <23177737+cprivitere@users.noreply.github.com> --- internal/emlb/emlb_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/emlb/emlb_test.go b/internal/emlb/emlb_test.go index 251fe1271..9f1ec5b8e 100644 --- a/internal/emlb/emlb_test.go +++ b/internal/emlb/emlb_test.go @@ -167,11 +167,12 @@ func Test_getExternalIPv4Target(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) got, err := getExternalIPv4Target(tt.args.deviceAddr) - if (err != nil) != tt.wantErr { - g.Expect(err).To(Equal(tt.wantErr)) - return + if tt.wantErr { + g.Expect(err).To(HaveOccurred()) + } else { + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(got).To(Equal(tt.want)) } - g.Expect(got).To(Equal(tt.want)) }) } }