-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mario Schäfer
committed
Nov 2, 2023
1 parent
00237d6
commit e22cc7e
Showing
12 changed files
with
544 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package v2 | ||
|
||
// commonRequestBody is used to optionally omit the `State` field on create and update | ||
// by embedding it to the request in the FilterAPIRequestBody hook | ||
type commonRequestBody struct { | ||
State string `json:"state,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"go.anx.io/go-anxcloud/pkg/apis/common/gs" | ||
"net/url" | ||
) | ||
|
||
// FilterAPIRequestBody adds the CommonRequestBody | ||
func (c *Cluster) FilterAPIRequestBody(ctx context.Context) (interface{}, error) { | ||
return gs.RequestBody(ctx, func() interface{} { | ||
return &struct { | ||
commonRequestBody | ||
Cluster | ||
}{ | ||
Cluster: *c, | ||
} | ||
}) | ||
} | ||
|
||
// EndpointURL returns the common URL for operations on the Cluster resource | ||
func (c *Cluster) EndpointURL(ctx context.Context) (*url.URL, error) { | ||
return gs.EndpointURL(ctx, c, "/api/LBaaSv2/v1/clusters.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package v2 | ||
|
||
import ( | ||
"go.anx.io/go-anxcloud/pkg/apis/common/gs" | ||
) | ||
|
||
type LoadBalancerImplementation string | ||
|
||
const ( | ||
LoadBalancerImplementationHAProxy LoadBalancerImplementation = "haproxy" | ||
) | ||
|
||
// anxcloud:object | ||
|
||
// Cluster holds the information of a load balancing cluster | ||
type Cluster struct { | ||
gs.GenericService | ||
gs.HasState | ||
|
||
Identifier string `json:"identifier,omitempty" anxcloud:"identifier"` | ||
Name string `json:"name,omitempty"` | ||
Implementation LoadBalancerImplementation `json:"implementation,omitempty"` | ||
FrontendPrefixes *gs.PartialResourceList `json:"frontend_prefixes,omitempty"` | ||
BackendPrefixes *gs.PartialResourceList `json:"backend_prefixes,omitempty"` | ||
Replicas *int `json:"replicas,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"go.anx.io/go-anxcloud/pkg/apis/common/gs" | ||
"net/url" | ||
) | ||
|
||
// FilterAPIRequestBody adds the CommonRequestBody | ||
func (n *Node) FilterAPIRequestBody(ctx context.Context) (interface{}, error) { | ||
return gs.RequestBody(ctx, func() interface{} { | ||
return &struct { | ||
commonRequestBody | ||
Node | ||
}{ | ||
Node: *n, | ||
} | ||
}) | ||
} | ||
|
||
// EndpointURL returns the common URL for operations on the Node resource | ||
func (n *Node) EndpointURL(ctx context.Context) (*url.URL, error) { | ||
return gs.EndpointURL(ctx, n, "/api/LBaaSv2/v1/nodes.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package v2 | ||
|
||
import ( | ||
"go.anx.io/go-anxcloud/pkg/apis/common" | ||
"go.anx.io/go-anxcloud/pkg/apis/common/gs" | ||
) | ||
|
||
// anxcloud:object | ||
|
||
// Node holds the information of a load balancing node within a Cluster | ||
type Node struct { | ||
gs.GenericService | ||
gs.HasState | ||
|
||
Identifier string `json:"identifier,omitempty" anxcloud:"identifier"` | ||
Name string `json:"name,omitempty"` | ||
VM *common.PartialResource `json:"vm,omitempty"` | ||
Cluster *common.PartialResource `json:"cluster,omitempty" anxcloud:"filterable"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"go.anx.io/go-anxcloud/pkg/apis/common/gs" | ||
"net/url" | ||
) | ||
|
||
// FilterAPIRequestBody adds the CommonRequestBody | ||
func (lb *LoadBalancer) FilterAPIRequestBody(ctx context.Context) (interface{}, error) { | ||
return gs.RequestBody(ctx, func() interface{} { | ||
return &struct { | ||
commonRequestBody | ||
LoadBalancer | ||
}{ | ||
LoadBalancer: *lb, | ||
} | ||
}) | ||
} | ||
|
||
// EndpointURL returns the common URL for operations on LoadBalancer resource | ||
func (lb *LoadBalancer) EndpointURL(ctx context.Context) (*url.URL, error) { | ||
return gs.EndpointURL(ctx, lb, "/api/LBaaSv2/v1/load_balancers.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package v2 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"go.anx.io/go-anxcloud/pkg/apis/common" | ||
"go.anx.io/go-anxcloud/pkg/apis/common/gs" | ||
) | ||
|
||
// anxcloud:object | ||
|
||
// LoadBalancer holds the information of a load balancing configuration within a Cluster | ||
type LoadBalancer struct { | ||
gs.GenericService | ||
gs.HasState | ||
|
||
Identifier string `json:"identifier,omitempty" anxcloud:"identifier"` | ||
Name string `json:"name,omitempty"` | ||
Generation int `json:"generation,omitempty"` | ||
Cluster *common.PartialResource `json:"cluster,omitempty" anxcloud:"filterable"` | ||
FrontendIPs *gs.PartialResourceList `json:"frontend_ips,omitempty"` | ||
SSLCertificates *gs.PartialResourceList `json:"ssl_certificates,omitempty"` | ||
// Definition onfigures the load balancer's frontends and backends. | ||
// This field is currently unstable and requires an update of go-anxcloud | ||
// in the near future. | ||
Definition *Definition `json:"definition,omitempty"` | ||
} | ||
|
||
type FrontendProtocol string | ||
|
||
const ( | ||
FrontendProtocolTCP FrontendProtocol = "TCP" | ||
) | ||
|
||
type BackendProtocol string | ||
|
||
const ( | ||
BackendProtocolTCP BackendProtocol = "TCP" | ||
BackendProtocolPROXY BackendProtocol = "PROXY" | ||
) | ||
|
||
type definition struct { | ||
Frontends []Frontend `json:"frontends,omitempty"` | ||
Backends []Backend `json:"backends,omitempty"` | ||
} | ||
|
||
type Definition definition | ||
|
||
func (d *Definition) MarshalJSON() ([]byte, error) { | ||
inner := definition(*d) | ||
|
||
data, err := json.Marshal(&inner) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return json.Marshal(string(data)) | ||
} | ||
|
||
func (d *Definition) UnmarshalJSON(data []byte) error { | ||
var innerString string | ||
if err := json.Unmarshal(data, &innerString); err != nil { | ||
return err | ||
} | ||
|
||
var inner definition | ||
if err := json.Unmarshal([]byte(innerString), &inner); err != nil { | ||
return err | ||
} | ||
|
||
*d = Definition(inner) | ||
|
||
return nil | ||
} | ||
|
||
// Define ports and protocols exposed to the public side of the Load Balancer | ||
type Frontend struct { | ||
// Name of the Frontend | ||
Name string `json:"name"` | ||
// Frontend service protocol | ||
Protocol FrontendProtocol `json:"protocol"` | ||
// Configure frontend - backend relation | ||
Backend FrontendBackend `json:"backend,omitempty"` | ||
// TCP specific frontend configuration | ||
TCP *FrontendTCP `json:"tcp,omitempty"` | ||
} | ||
|
||
// TCP specific frontend configuration | ||
type FrontendTCP struct { | ||
// Port for the frontend to listen to | ||
Port uint16 `json:"port,omitempty"` | ||
} | ||
|
||
// Configure frontend - backend relation | ||
type FrontendBackend struct { | ||
// Backend service protocol | ||
Protocol BackendProtocol `json:"protocol"` | ||
// TCP specific backend configuration | ||
TCP *FrontendBackendTCP `json:"tcp,omitempty"` | ||
} | ||
|
||
// TCP specific backend configuration | ||
type FrontendBackendTCP struct { | ||
Port uint16 `json:"port"` | ||
} | ||
|
||
// Define backend services and connect them to frontends | ||
type Backend struct { | ||
// Name of the Backend | ||
Name string `json:"name"` | ||
// IP addresses of the backend service | ||
IPs []string `json:"ips,omitempty"` | ||
// List of frontends connected to the backend | ||
Frontends []BackendFrontend `json:"frontends,omitempty"` | ||
} | ||
|
||
type BackendFrontend struct { | ||
// Name of the frontend to be connected to the backend | ||
Name string `json:"name"` | ||
} |
Oops, something went wrong.