-
Notifications
You must be signed in to change notification settings - Fork 11
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
db3e93b
commit c1eee59
Showing
9 changed files
with
208 additions
and
129 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 snatrules | ||
|
||
import ( | ||
"github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
type CreateOpts struct { | ||
// Specifies the NAT gateway ID. | ||
NatGatewayID string `json:"nat_gateway_id" required:"true"` | ||
// Specifies the network ID used by the SNAT rule. This parameter and cidr are alternative. | ||
NetworkID string `json:"network_id,omitempty"` | ||
// Specifies the EIP ID. Use commas (,) to separate multiple IDs. | ||
// The maximum length of the ID is 4,096 bytes. | ||
// Constraints: The number of EIP IDs cannot exceed 20. | ||
FloatingIPID string `json:"floating_ip_id" required:"true"` | ||
// Specifies CIDR, which can be in the format of a network segment or a host IP address. | ||
// This parameter and network_id are alternative. | ||
// If source_type is set to 0, cidr must be a subset of the VPC subnet. | ||
// If source_type is set to 1, cidr must be a CIDR block of your on-premises network connected to the VPC through Direct Connect or Cloud Connect. | ||
Cidr string `json:"cidr,omitempty"` | ||
// 0: Either network_id or cidr can be specified in a VPC. | ||
// 1: Only cidr can be specified over a Direct Connect connection. | ||
// If no value is entered, the default value 0 (VPC) is used. | ||
SourceType int `json:"source_type,omitempty"` | ||
// Provides supplementary information about the SNAT rule. | ||
Description string `json:"description,omitempty"` | ||
} | ||
|
||
func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*SnatRule, error) { | ||
b, err := build.RequestBody(opts, "snat_rule") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// POST /v2.0/snat_rules | ||
raw, err := client.Post(client.ServiceURL("snat_rules"), b, | ||
nil, &golangsdk.RequestOpts{ | ||
OkCodes: []int{201}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res SnatRule | ||
err = extract.IntoStructPtr(raw.Body, &res, "snat_rule") | ||
return &res, err | ||
} | ||
|
||
type SnatRule struct { | ||
// Specifies the SNAT rule ID. | ||
ID string `json:"id"` | ||
// Specifies the NAT gateway ID. | ||
NatGatewayID string `json:"nat_gateway_id"` | ||
// Specifies the network ID used by the SNAT rule. | ||
NetworkID string `json:"network_id"` | ||
// Specifies the project ID. | ||
TenantID string `json:"tenant_id"` | ||
// Specifies the EIP ID. Use commas (,) to separate multiple IDs. | ||
FloatingIPID string `json:"floating_ip_id"` | ||
// Specifies the EIP. Use commas (,) to separate multiple EIPs. | ||
FloatingIPAddress string `json:"floating_ip_address"` | ||
// Specifies the status of the SNAT rule. | ||
Status string `json:"status"` | ||
// Specifies the unfrozen or frozen state. | ||
// Specifies whether the SNAT rule is enabled or disabled. | ||
// The state can be: | ||
// true: The SNAT rule is enabled. | ||
// false: The SNAT rule is disabled. | ||
AdminStateUp bool `json:"admin_state_up"` | ||
// Specifies a subset of the VPC subnet CIDR block or a CIDR block of Direct Connect connection. | ||
Cidr string `json:"cidr"` | ||
// 0: Either network_id or cidr can be specified in a VPC. | ||
// 1: Only cidr can be specified over a Direct Connect connection. | ||
// If no value is entered, the default value 0 (VPC) is used. | ||
SourceType interface{} `json:"source_type"` | ||
// Specifies when the SNAT rule is created (UTC time). | ||
// Its value rounds to 6 decimal places for seconds. | ||
// The format is yyyy-mm-dd hh:mm:ss. | ||
CreatedAt string `json:"created_at"` | ||
} |
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,13 @@ | ||
package snatrules | ||
|
||
import ( | ||
"github.com/opentelekomcloud/gophertelekomcloud" | ||
) | ||
|
||
func Delete(client *golangsdk.ServiceClient, id string) (err error) { | ||
// DELETE /v2.0/snat_rules/{snat_rule_id} | ||
_, err = client.Delete(client.ServiceURL("snat_rules", id), &golangsdk.RequestOpts{ | ||
OkCodes: []int{204}, | ||
}) | ||
return | ||
} |
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,17 @@ | ||
package snatrules | ||
|
||
import ( | ||
"github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
func Get(client *golangsdk.ServiceClient, id string) (*SnatRule, error) { | ||
// GET /v2.0/snat_rules/{snat_rule_id} | ||
raw, err := client.Get(client.ServiceURL("snat_rules", id), nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res SnatRule | ||
return &res, extract.IntoStructPtr(raw.Body, &res, "snat_rule") | ||
} |
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,58 @@ | ||
package snatrules | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
func List(client *golangsdk.ServiceClient, opts ListOpts) ([]SnatRule, error) { | ||
url, err := golangsdk.NewURLBuilder().WithEndpoints("snat_rules").WithQueryParams(&opts).Build() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// GET /v2.0/snat_rules | ||
raw, err := client.Get(client.ServiceURL(url.String()), nil, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res []SnatRule | ||
err = extract.IntoSlicePtr(raw.Body, &res, "snat_rules") | ||
return res, err | ||
} | ||
|
||
type ListOpts struct { | ||
// Specifies the SNAT rule ID. | ||
Id string `q:"id,omitempty"` | ||
// Specifies the number of records returned on each page. | ||
Limit int `q:"limit,omitempty"` | ||
// Specifies the project ID. | ||
ProjectId string `q:"tenant_id,omitempty"` | ||
// Specifies the NAT gateway ID. | ||
NatGatewayId string `q:"nat_gateway_id,omitempty"` | ||
// Specifies the network ID used by the SNAT rule. | ||
NetworkId string `q:"network_id,omitempty"` | ||
// Specifies a subset of the VPC subnet CIDR block or a CIDR block of Direct Connect connection. | ||
Cidr string `q:"cidr,omitempty"` | ||
// 0: Either network_id or cidr can be specified in a VPC. | ||
// 1: Only cidr can be specified over a Direct Connect connection. | ||
// If no value is entered, the default value 0 (VPC) is used. | ||
SourceType string `q:"source_type,omitempty"` | ||
// Specifies the EIP ID. | ||
FloatingIpId string `q:"floating_ip_id,omitempty"` | ||
// Specifies the EIP address. | ||
FloatingIpAddress string `q:"floating_ip_address,omitempty"` | ||
// Provides supplementary information about the SNAT rule. | ||
Description string `q:"description,omitempty"` | ||
// Specifies the status of the SNAT rule. | ||
Status string `q:"status,omitempty"` | ||
// Specifies whether the SNAT rule is enabled or disabled. | ||
// The value can be: | ||
// true: The SNAT rule is enabled. | ||
// false: The SNAT rule is disabled. | ||
AdminStateUp bool `q:"admin_state_up,omitempty"` | ||
// Specifies when the SNAT rule was created (UTC time). | ||
// Its value rounds to 6 decimal places for seconds. The format is yyyy-mm-dd hh:mm:ss. | ||
CreatedAt bool `q:"created_at,omitempty"` | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.