Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/m static routes #468

Merged
merged 7 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions client/v3/v3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ type Service interface {
UpdateFloatingIP(ctx context.Context, uuid string, body *FIPIntentInput) (*FloatingIPsIntentResponse, error)
ListFloatingIPs(ctx context.Context, getRequest *DSMetadata) (*FloatingIPsListIntentResponse, error)
ListAllFloatingIPs(ctx context.Context, filter string) (*FloatingIPsListIntentResponse, error)
GetStaticRoute(ctx context.Context, vpcUUID string) (*StaticRouteIntentResponse, error)
UpdateStaticRoute(ctx context.Context, uuid string, body *StaticRouteIntentInput) (*StaticRouteIntentResponse, error)
}

/*CreateVM Creates a VM
Expand Down Expand Up @@ -2565,11 +2567,12 @@ func (op Operations) CreatePBR(ctx context.Context, body *PbrIntentInput) (*PbrI
func (op Operations) GetPBR(ctx context.Context, uuid string) (*PbrIntentResponse, error) {
path := fmt.Sprintf("/routing_policies/%s", uuid)
req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
pbrIntentResponse := new(PbrIntentResponse)

if err != nil {
return nil, err
}

pbrIntentResponse := new(PbrIntentResponse)
return pbrIntentResponse, op.client.Do(ctx, req, pbrIntentResponse)
}

Expand Down Expand Up @@ -2623,7 +2626,6 @@ func (op Operations) ListAllPBR(ctx context.Context, filter string) (*PbrListInt
if err != nil {
return nil, err
}

totalEntities := utils.Int64Value(resp.Metadata.TotalMatches)
remaining := totalEntities
offset := utils.Int64Value(resp.Metadata.Offset)
Expand Down Expand Up @@ -2652,6 +2654,32 @@ func (op Operations) ListAllPBR(ctx context.Context, filter string) (*PbrListInt
return resp, nil
}

func (op Operations) GetStaticRoute(ctx context.Context, uuid string) (*StaticRouteIntentResponse, error) {
path := fmt.Sprintf("/vpcs/%s/route_tables", uuid)
req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)

if err != nil {
return nil, err
}

staticIntentResponse := new(StaticRouteIntentResponse)

return staticIntentResponse, op.client.Do(ctx, req, staticIntentResponse)
}

func (op Operations) UpdateStaticRoute(ctx context.Context, uuid string, body *StaticRouteIntentInput) (*StaticRouteIntentResponse, error) {
path := fmt.Sprintf("/vpcs/%s/route_tables", uuid)
req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)

if err != nil {
return nil, err
}

staticIntentResponse := new(StaticRouteIntentResponse)

return staticIntentResponse, op.client.Do(ctx, req, staticIntentResponse)
}

func (op Operations) CreateFloatingIPs(ctx context.Context, request *FIPIntentInput) (*FloatingIPsIntentResponse, error) {
req, err := op.client.NewRequest(ctx, http.MethodPost, "/floating_ips", request)

Expand Down
52 changes: 48 additions & 4 deletions client/v3/v3_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2730,6 +2730,46 @@ type PbrIntentInput struct {
Spec *PbrSpec `json:"spec" mapstructure:"spec"`
}

type PbrListIntentResponse struct {
APIVersion *string `json:"api_version"`
Metadata *ListMetadataOutput `json:"metadata"`
Entities []*PbrIntentResponse `json:"entities"`
}

type NextHop struct {
ExternalSubnetReference *Reference `json:"external_subnet_reference,omitempty"`
}

type StaticRoutesList struct {
NextHop *NextHop `json:"nexthop,omitempty"`
Destination *string `json:"destination,omitempty"`
Priority *int64 `json:"priority,omitempty"`
IsActive *bool `json:"is_active,omitempty"`
}

type StaticRouteResources struct {
StaticRoutesList []*StaticRoutesList `json:"static_routes_list,omitempty"`
}

type StaticRouteSpec struct {
Name *string `json:"name,omitempty"`
Resources *StaticRouteResources `json:"resources,omitempty"`
}

type StaticRouteDefStatus struct {
State *string `json:"state,omitempty"`
Resources *StaticRouteResources `json:"resources,omitempty"`
ExecutionContext *ExecutionContext `json:"execution_context,omitempty"`
}

type StaticRouteIntentInput struct {
APIVersion *string `json:"api_version,omitempty" mapstructure:"api_version,omitempty"`

Metadata *Metadata `json:"metadata" mapstructure:"metadata"`

Spec *StaticRouteSpec `json:"spec" mapstructure:"spec"`
}

type PbrDefStatus struct {
State *string `json:"state,omitempty" mapstructure:"state,omitempty"`
ExecutionContext *ExecutionContext `json:"execution_context,omitempty" mapstructure:"execution_context,omitempty"`
Expand All @@ -2746,10 +2786,14 @@ type PbrIntentResponse struct {
Status *PbrDefStatus `json:"status"`
}

type PbrListIntentResponse struct {
APIVersion *string `json:"api_version"`
Metadata *ListMetadataOutput `json:"metadata"`
Entities []*PbrIntentResponse `json:"entities"`
type StaticRouteIntentResponse struct {
APIVersion *string `json:"api_version,omitempty" mapstructure:"api_version,omitempty"`

Metadata *Metadata `json:"metadata" mapstructure:"metadata"`

Spec *StaticRouteSpec `json:"spec" mapstructure:"spec"`

Status *StaticRouteDefStatus `json:"status"`
}

type FIPResource struct {
Expand Down
48 changes: 48 additions & 0 deletions examples/static_routes/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
terraform{
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "1.6.0"
}
}
}

#definig nutanix configuration
provider "nutanix"{
username = var.nutanix_username
password = var.nutanix_password
endpoint = var.nutanix_endpoint
port = 9440
insecure = true
}


#create one static route for vpc with external subnet
resource "nutanix_static_routes" "scn" {
vpc_uuid = "{{vpc_uuid}}"

static_routes_list{
# destination prefix format 10.x.x.x/x
destination= "10.x.x.x/x"
# required ext subnet uuid for next hop
external_subnet_reference_uuid = "{{ext_subnet_uuid}}"
}
}


#create multiple static routes for vpc with external subnet
resource "nutanix_static_routes" "scn" {
vpc_uuid = "{{vpc_uuid}}"

static_routes_list{
# destination prefix format 10.x.x.x/x
destination= "10.x.x.x/x"
# required ext subnet uuid for next hop
external_subnet_reference_uuid = "{{ext_subnet_uuid}}"
}

static_routes_list{
destination= "10.x.x.x/x"
external_subnet_reference_uuid = "{{ext_subnet_uuid}}"
}
}
5 changes: 5 additions & 0 deletions examples/static_routes/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define values to the variables to be used in terraform file
nutanix_username = "admin"
nutanix_password = "password"
nutanix_endpoint = "10.xx.xx.xx"
nutanix_port = 9440
13 changes: 13 additions & 0 deletions examples/static_routes/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#define the type of variables to be used in terraform file
variable "nutanix_username" {
type = string
}
variable "nutanix_password" {
type = string
}
variable "nutanix_endpoint" {
type = string
}
variable "nutanix_port" {
type = string
}
Loading