Skip to content

Commit

Permalink
eCloud loadbalancers (#105)
Browse files Browse the repository at this point in the history
* add loadbalancer CRUD

* add load balancer network CRUD

* add lb spec

* fix signatures

* add to interface

* fix tests

* remove networks

* fix response types
  • Loading branch information
0x4c6565 authored Feb 15, 2022
1 parent dc40274 commit 1ef2e04
Show file tree
Hide file tree
Showing 14 changed files with 1,556 additions and 19 deletions.
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
27 changes: 27 additions & 0 deletions pkg/service/ecloud/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,30 @@ type VPNProfileGroupNotFoundError struct {
func (e *VPNProfileGroupNotFoundError) Error() string {
return fmt.Sprintf("VPN profile group not found with ID [%s]", e.ID)
}

// LoadBalancerNotFoundError indicates a load balancer was not found
type LoadBalancerNotFoundError struct {
ID string
}

func (e *LoadBalancerNotFoundError) Error() string {
return fmt.Sprintf("Load balancer not found with ID [%s]", e.ID)
}

// LoadBalancerNetworkNotFoundError indicates a load balancer network was not found
type LoadBalancerNetworkNotFoundError struct {
ID string
}

func (e *LoadBalancerNetworkNotFoundError) Error() string {
return fmt.Sprintf("Load balancer network not found with ID [%s]", e.ID)
}

// LoadBalancerNetworkNotFoundError indicates a load balancer spec was not found
type LoadBalancerSpecNotFoundError struct {
ID string
}

func (e *LoadBalancerSpecNotFoundError) Error() string {
return fmt.Sprintf("Load balancer spec not found with ID [%s]", e.ID)
}
40 changes: 40 additions & 0 deletions pkg/service/ecloud/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,3 +1072,43 @@ type VPNSessionTunnelStatistics struct {
type VPNSessionPreSharedKey struct {
PSK string `json:"psk"`
}

// LoadBalancer represents an eCloud loadbalancer
// +genie:model_response
// +genie:model_paginated
type LoadBalancer struct {
ID string `json:"id"`
Name string `json:"name"`
AvailabilityZoneID string `json:"availability_zone_id"`
VPCID string `json:"vpc_id"`
LoadBalancerSpecID string `json:"load_balancer_spec_id"`
Sync ResourceSync `json:"sync"`
ConfigID int `json:"config_id"`
Nodes int `json:"nodes"`
CreatedAt connection.DateTime `json:"created_at"`
UpdatedAt connection.DateTime `json:"updated_at"`
}

// LoadBalancerNetwork represents an eCloud loadbalancer network
// +genie:model_response
// +genie:model_paginated
type LoadBalancerNetwork struct {
ID string `json:"id"`
Name string `json:"name"`
LoadBalancerID string `json:"load_balancer_id"`
NetworkID string `json:"network_id"`
Sync ResourceSync `json:"sync"`
CreatedAt connection.DateTime `json:"created_at"`
UpdatedAt connection.DateTime `json:"updated_at"`
}

// LoadBalancerSpec represents an eCloud loadbalancer specification
// +genie:model_response
// +genie:model_paginated
type LoadBalancerSpec struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt connection.DateTime `json:"created_at"`
UpdatedAt connection.DateTime `json:"updated_at"`
}
42 changes: 42 additions & 0 deletions pkg/service/ecloud/model_paginated_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,45 @@ func NewPaginatedVPNSession(getFunc connection.PaginatedGetFunc, parameters conn
PaginatedBase: connection.NewPaginatedBase(parameters, pagination, getFunc),
}
}

// PaginatedLoadBalancer represents a paginated collection of LoadBalancer
type PaginatedLoadBalancer struct {
*connection.PaginatedBase
Items []LoadBalancer
}

// NewPaginatedLoadBalancer returns a pointer to an initialized PaginatedLoadBalancer struct
func NewPaginatedLoadBalancer(getFunc connection.PaginatedGetFunc, parameters connection.APIRequestParameters, pagination connection.APIResponseMetadataPagination, items []LoadBalancer) *PaginatedLoadBalancer {
return &PaginatedLoadBalancer{
Items: items,
PaginatedBase: connection.NewPaginatedBase(parameters, pagination, getFunc),
}
}

// PaginatedLoadBalancerNetwork represents a paginated collection of LoadBalancerNetwork
type PaginatedLoadBalancerNetwork struct {
*connection.PaginatedBase
Items []LoadBalancerNetwork
}

// NewPaginatedLoadBalancerNetwork returns a pointer to an initialized PaginatedLoadBalancerNetwork struct
func NewPaginatedLoadBalancerNetwork(getFunc connection.PaginatedGetFunc, parameters connection.APIRequestParameters, pagination connection.APIResponseMetadataPagination, items []LoadBalancerNetwork) *PaginatedLoadBalancerNetwork {
return &PaginatedLoadBalancerNetwork{
Items: items,
PaginatedBase: connection.NewPaginatedBase(parameters, pagination, getFunc),
}
}

// PaginatedLoadBalancerSpec represents a paginated collection of LoadBalancerSpec
type PaginatedLoadBalancerSpec struct {
*connection.PaginatedBase
Items []LoadBalancerSpec
}

// NewPaginatedLoadBalancerSpec returns a pointer to an initialized PaginatedLoadBalancerSpec struct
func NewPaginatedLoadBalancerSpec(getFunc connection.PaginatedGetFunc, parameters connection.APIRequestParameters, pagination connection.APIResponseMetadataPagination, items []LoadBalancerSpec) *PaginatedLoadBalancerSpec {
return &PaginatedLoadBalancerSpec{
Items: items,
PaginatedBase: connection.NewPaginatedBase(parameters, pagination, getFunc),
}
}
36 changes: 36 additions & 0 deletions pkg/service/ecloud/model_response_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,39 @@ type GetVPNSessionPreSharedKeyResponseBody struct {
connection.APIResponseBody
Data VPNSessionPreSharedKey `json:"data"`
}

// GetLoadBalancerSliceResponseBody represents an API response body containing []LoadBalancer data
type GetLoadBalancerSliceResponseBody struct {
connection.APIResponseBody
Data []LoadBalancer `json:"data"`
}

// GetLoadBalancerResponseBody represents an API response body containing LoadBalancer data
type GetLoadBalancerResponseBody struct {
connection.APIResponseBody
Data LoadBalancer `json:"data"`
}

// GetLoadBalancerNetworkSliceResponseBody represents an API response body containing []LoadBalancerNetwork data
type GetLoadBalancerNetworkSliceResponseBody struct {
connection.APIResponseBody
Data []LoadBalancerNetwork `json:"data"`
}

// GetLoadBalancerNetworkResponseBody represents an API response body containing LoadBalancerNetwork data
type GetLoadBalancerNetworkResponseBody struct {
connection.APIResponseBody
Data LoadBalancerNetwork `json:"data"`
}

// GetLoadBalancerSpecSliceResponseBody represents an API response body containing []LoadBalancerSpec data
type GetLoadBalancerSpecSliceResponseBody struct {
connection.APIResponseBody
Data []LoadBalancerSpec `json:"data"`
}

// GetLoadBalancerSpecResponseBody represents an API response body containing LoadBalancerSpec data
type GetLoadBalancerSpecResponseBody struct {
connection.APIResponseBody
Data LoadBalancerSpec `json:"data"`
}
26 changes: 26 additions & 0 deletions pkg/service/ecloud/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,29 @@ type CreateVolumeGroupRequest struct {
type PatchVolumeGroupRequest struct {
Name string `json:"name,omitempty"`
}

// CreateLoadBalancerRequest represents a request to create a load balancer
type CreateLoadBalancerRequest struct {
Name string `json:"name,omitempty"`
AvailabilityZoneID string `json:"availability_zone_id"`
VPCID string `json:"vpc_id"`
LoadBalancerSpecID string `json:"load_balancer_spec_id"`
NetworkIDs []string `json:"network_ids"`
}

// CreateLoadBalancerRequest represents a request to patch a load balancer
type PatchLoadBalancerRequest struct {
Name string `json:"name,omitempty"`
}

// CreateLoadBalancerNetworkRequest represents a request to create a load balancer network
type CreateLoadBalancerNetworkRequest struct {
Name string `json:"name,omitempty"`
LoadBalancerID string `json:"load_balancer_id"`
NetworkID string `json:"network_id"`
}

// PatchLoadBalancerNetworkRequest represents a request to patch a load balancer network
type PatchLoadBalancerNetworkRequest struct {
Name string `json:"name,omitempty"`
}
23 changes: 23 additions & 0 deletions pkg/service/ecloud/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,29 @@ type ECloudService interface {
GetVPNProfileGroups(parameters connection.APIRequestParameters) ([]VPNProfileGroup, error)
GetVPNProfileGroupsPaginated(parameters connection.APIRequestParameters) (*PaginatedVPNProfileGroup, error)
GetVPNProfileGroup(groupID string) (VPNProfileGroup, error)

// Load Balancer
GetLoadBalancers(parameters connection.APIRequestParameters) ([]LoadBalancer, error)
GetLoadBalancersPaginated(parameters connection.APIRequestParameters) (*PaginatedLoadBalancer, error)
GetLoadBalancer(loadbalancerID string) (LoadBalancer, error)
CreateLoadBalancer(req CreateLoadBalancerRequest) (TaskReference, error)
PatchLoadBalancer(loadbalancerID string, req PatchLoadBalancerRequest) (TaskReference, error)
DeleteLoadBalancer(loadbalancerID string) (string, error)
GetLoadBalancerLoadBalancerNetworks(loadbalancerID string, parameters connection.APIRequestParameters) ([]LoadBalancerNetwork, error)
GetLoadBalancerLoadBalancerNetworksPaginated(loadbalancerID string, parameters connection.APIRequestParameters) (*PaginatedLoadBalancerNetwork, error)

// Load Balancer Network
GetLoadBalancerNetworks(parameters connection.APIRequestParameters) ([]LoadBalancerNetwork, error)
GetLoadBalancerNetworksPaginated(parameters connection.APIRequestParameters) (*PaginatedLoadBalancerNetwork, error)
GetLoadBalancerNetwork(lbNetworkID string) (LoadBalancerNetwork, error)
CreateLoadBalancerNetwork(req CreateLoadBalancerNetworkRequest) (TaskReference, error)
PatchLoadBalancerNetwork(lbNetworkID string, req PatchLoadBalancerNetworkRequest) (TaskReference, error)
DeleteLoadBalancerNetwork(lbNetworkID string) (string, error)

// Load Balancer Spec
GetLoadBalancerSpecs(parameters connection.APIRequestParameters) ([]LoadBalancerSpec, error)
GetLoadBalancerSpecsPaginated(parameters connection.APIRequestParameters) (*PaginatedLoadBalancerSpec, error)
GetLoadBalancerSpec(lbSpecID string) (LoadBalancerSpec, error)
}

// Service implements ECloudService for managing
Expand Down
Loading

0 comments on commit 1ef2e04

Please sign in to comment.