Skip to content

Commit

Permalink
add basic advanced networking stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
simonfuhrer committed Mar 9, 2022
1 parent 9b9f48d commit 443c34d
Show file tree
Hide file tree
Showing 10 changed files with 811 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.15,1.16]
go-version: [1.16,1.17]
steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v1
Expand Down
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type Client struct {
Snapshot SnapshotClient
AvailabilityZone AvailabilityZoneClient
VMRecoveryPoint VMRecoveryPointClient
VPC VpcClient
FlotatingIP FloatingIPClient
RoutingPolicy RoutingPolicyClient
}

// Credentials needed username and password
Expand Down Expand Up @@ -145,6 +148,9 @@ func NewClient(options ...ClientOption) *Client {
client.Snapshot = SnapshotClient{client: client}
client.AvailabilityZone = AvailabilityZoneClient{client: client}
client.VMRecoveryPoint = VMRecoveryPointClient{client: client}
client.VPC = VpcClient{client: client}
client.FlotatingIP = FloatingIPClient{client: client}
client.RoutingPolicy = RoutingPolicyClient{client: client}
return client
}

Expand Down
82 changes: 82 additions & 0 deletions floating_ip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package nutanix

import (
"context"
"fmt"
"net/http"

"github.com/tecbiz-ch/nutanix-go-sdk/pkg/utils"
"github.com/tecbiz-ch/nutanix-go-sdk/schema"
)

const (
floatingIPBasePath = "/floating_ips"
floatingIPListPath = floatingIPBasePath + "/list"
floatingIPSinglePath = floatingIPBasePath + "/%s"
)

// FloatingIPClient is a client for the vpc API.
type FloatingIPClient struct {
client *Client
}

// Get retrieves an FlotatingIp by its UUID if the input can be parsed as an uuid, otherwise it
// retrieves a FlotatingIp by its name
func (c *FloatingIPClient) Get(ctx context.Context, idOrName string) (*schema.FloatingIPIntent, error) {
if utils.IsValidUUID(idOrName) {
return c.GetByUUID(ctx, idOrName)
}
return c.GetByName(ctx, idOrName)
}

// GetByUUID retrieves an FlotatingIp by its UUID
func (c *FloatingIPClient) GetByUUID(ctx context.Context, uuid string) (*schema.FloatingIPIntent, error) {
response := new(schema.FloatingIPIntent)
err := c.client.requestHelper(ctx, fmt.Sprintf(floatingIPSinglePath, uuid), http.MethodGet, nil, response)
return response, err
}

// GetByName retrieves an FlotatingIp by its name
func (c *FloatingIPClient) GetByName(ctx context.Context, name string) (*schema.FloatingIPIntent, error) {
list, err := c.List(ctx, &schema.DSMetadata{Filter: fmt.Sprintf("floating_ip==%s", name)})
if err != nil {
return nil, err
}
if len(list.Entities) == 0 {
return nil, fmt.Errorf("floating_ip not found: %s", name)
}
return list.Entities[0], err
}

// List returns a list of FlotatingIp's
func (c *FloatingIPClient) List(ctx context.Context, opts *schema.DSMetadata) (*schema.FloatingIPListIntent, error) {
response := new(schema.FloatingIPListIntent)
err := c.client.requestHelper(ctx, floatingIPListPath, http.MethodPost, opts, response)
return response, err

}

// All returns all FlotatingIp's
func (c *FloatingIPClient) All(ctx context.Context) (*schema.FloatingIPListIntent, error) {
return c.List(ctx, &schema.DSMetadata{Length: utils.Int64Ptr(itemsPerPage), Offset: utils.Int64Ptr(0)})
}

// Create creates a FlotatingIp
func (c *FloatingIPClient) Create(ctx context.Context, createRequest *schema.FloatingIPIntent) (*schema.FloatingIPIntent, error) {
response := new(schema.FloatingIPIntent)
err := c.client.requestHelper(ctx, floatingIPBasePath, http.MethodPost, createRequest, response)
return response, err
}

// Update a FlotatingIp
func (c *FloatingIPClient) Update(ctx context.Context, fip *schema.FloatingIPIntent) (*schema.FloatingIPIntent, error) {
fip.Status = nil
response := new(schema.FloatingIPIntent)
err := c.client.requestHelper(ctx, fmt.Sprintf(floatingIPSinglePath, fip.Metadata.UUID), http.MethodPut, fip, response)
return response, err
}

// Delete deletes a FlotatingIp
func (c *FloatingIPClient) Delete(ctx context.Context, uuid string) error {
return c.client.requestHelper(ctx, fmt.Sprintf(floatingIPSinglePath, uuid), http.MethodDelete, nil, nil)
}
61 changes: 61 additions & 0 deletions routing_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package nutanix

import (
"context"
"fmt"
"net/http"

"github.com/tecbiz-ch/nutanix-go-sdk/pkg/utils"
"github.com/tecbiz-ch/nutanix-go-sdk/schema"
)

const (
routingPolicyBasePath = "/routing_policies"
routingPolicyListPath = routingPolicyBasePath + "/list"
routingPolicySinglePath = routingPolicyBasePath + "/%s"
)

// RoutingPolicyClient is a client for the vpc API.
type RoutingPolicyClient struct {
client *Client
}

// GetByUUID retrieves an FlotatingIp by its UUID
func (c *RoutingPolicyClient) GetByUUID(ctx context.Context, uuid string) (*schema.RoutingPolicyIntent, error) {
response := new(schema.RoutingPolicyIntent)
err := c.client.requestHelper(ctx, fmt.Sprintf(routingPolicySinglePath, uuid), http.MethodGet, nil, response)
return response, err
}

// List returns a list of FlotatingIp's
func (c *RoutingPolicyClient) List(ctx context.Context, opts *schema.DSMetadata) (*schema.RoutingPolicyListIntent, error) {
response := new(schema.RoutingPolicyListIntent)
err := c.client.requestHelper(ctx, routingPolicyListPath, http.MethodPost, opts, response)
return response, err

}

// All returns all FlotatingIp's
func (c *RoutingPolicyClient) All(ctx context.Context) (*schema.RoutingPolicyListIntent, error) {
return c.List(ctx, &schema.DSMetadata{Length: utils.Int64Ptr(itemsPerPage), Offset: utils.Int64Ptr(0)})
}

// Create creates a FlotatingIp
func (c *RoutingPolicyClient) Create(ctx context.Context, createRequest *schema.RoutingPolicyIntent) (*schema.RoutingPolicyIntent, error) {
response := new(schema.RoutingPolicyIntent)
err := c.client.requestHelper(ctx, routingPolicyBasePath, http.MethodPost, createRequest, response)
return response, err
}

// Update a FlotatingIp
func (c *RoutingPolicyClient) Update(ctx context.Context, r *schema.RoutingPolicyIntent) (*schema.RoutingPolicyIntent, error) {
r.Status = nil
response := new(schema.RoutingPolicyIntent)
err := c.client.requestHelper(ctx, fmt.Sprintf(routingPolicySinglePath, r.Metadata.UUID), http.MethodPut, r, response)
return response, err
}

// Delete deletes a FlotatingIp
func (c *RoutingPolicyClient) Delete(ctx context.Context, uuid string) error {
return c.client.requestHelper(ctx, fmt.Sprintf(routingPolicySinglePath, uuid), http.MethodDelete, nil, nil)
}
110 changes: 110 additions & 0 deletions schema/floating_ip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package schema

type FloatingIP struct {

// availability zone reference
AvailabilityZoneReference *Reference `json:"availability_zone_reference,omitempty"`

// A description for floating_ip.
// Max Length: 1000
Description string `json:"description,omitempty"`

// floating_ip Name.
// Max Length: 256
Name string `json:"name,omitempty"`

// resources
// Required: true
Resources *FloatingIPResources `json:"resources"`
}

// FloatingIPResourcesDefStatus Floating IP allocation status
//
// Floating IP allocation status.
//
// swagger:model floating_ip_resources_def_status
type FloatingIPResources struct {

// External subnet from which floating IP is selected.
ExternalSubnetReference *Reference `json:"external_subnet_reference,omitempty"`

// The Floating IP associated with the vnic.
// Pattern: ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
FloatingIP string `json:"floating_ip,omitempty"`

// Private IP with which the floating IP is associated.
// Pattern: ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
PrivateIP string `json:"private_ip,omitempty"`

// NIC with which the floating IP is associated.
VMNicReference *Reference `json:"vm_nic_reference,omitempty"`

// VPC in which the private IP exists.
VpcReference *Reference `json:"vpc_reference,omitempty"`
}

type FloatingIPIntent struct {

// api version
APIVersion string `json:"api_version,omitempty"`

// metadata
// Required: true
Metadata *Metadata `json:"metadata"`

// spec
Spec *FloatingIP `json:"spec,omitempty"`

// status
Status *FloatingIPDefStatus `json:"status,omitempty"`
}

// FloatingIPDefStatus floating_ip Intent Status with placement specified
//
// An intentful representation of a floating_ip status
//
// swagger:model floating_ip_def_status
type FloatingIPDefStatus struct {

// availability zone reference
AvailabilityZoneReference *Reference `json:"availability_zone_reference,omitempty"`

// cluster reference
ClusterReference *Reference `json:"cluster_reference,omitempty"`

// A description for floating_ip.
Description string `json:"description,omitempty"`

// Any error messages for the floating_ip, if in an error state.
MessageList []*MessageResource `json:"message_list"`

// floating_ip Name.
// Required: true
Name *string `json:"name"`

// resources
// Required: true
Resources *FloatingIPResources `json:"resources"`

// The state of the floating_ip.
State string `json:"state,omitempty"`
}

// FloatingIPListIntentResponse Entity Intent List Response
//
// Response object for intentful operation of floating_ips
//
// swagger:model floating_ip_list_intent_response
type FloatingIPListIntent struct {

// api version
// Required: true
APIVersion string `json:"api_version,omitempty"`

// entities
Entities []*FloatingIPIntent `json:"entities"`

// metadata
// Required: true
Metadata *ListMetadata `json:"metadata"`
}
Loading

0 comments on commit 443c34d

Please sign in to comment.