-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
9b9f48d
commit 443c34d
Showing
10 changed files
with
811 additions
and
5 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,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) | ||
} |
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,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) | ||
} |
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,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"` | ||
} |
Oops, something went wrong.