-
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
d9d1196
commit aa90dd7
Showing
9 changed files
with
492 additions
and
77 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
121 changes: 121 additions & 0 deletions
121
acceptance/openstack/dcaas/v3/virtual_interface_test.go
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,121 @@ | ||
package v3 | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" | ||
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" | ||
direct_connect "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v2/direct-connect" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v3/virtual-gateway" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/dcaas/v3/virtual-interface" | ||
"github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v1/vpcs" | ||
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" | ||
) | ||
|
||
func TestVirtualInterfaceListing(t *testing.T) { | ||
client, err := clients.NewDCaaSV3Client() | ||
th.AssertNoErr(t, err) | ||
|
||
// List virtual interfaces | ||
opts := virtual_interface.ListOpts{} | ||
viList, err := virtual_interface.List(client, opts) | ||
th.AssertNoErr(t, err) | ||
|
||
for _, vi := range viList { | ||
tools.PrintResource(t, vi) | ||
} | ||
} | ||
|
||
func TestVirtualInterfaceLifecycle(t *testing.T) { | ||
if os.Getenv("RUN_DCAAS_VIRTUAL_INTERFACE") == "" { | ||
t.Skip("DIRECT_CONNECT_ID necessary for this test or run it only in test_terraform") | ||
} | ||
vpcID := os.Getenv("OS_VPC_ID") | ||
if vpcID == "" { | ||
t.Skip("OS_VPC_ID necessary for this test") | ||
} | ||
clientV2, err := clients.NewDCaaSV2Client() | ||
th.AssertNoErr(t, err) | ||
clientV3, err := clients.NewDCaaSV3Client() | ||
th.AssertNoErr(t, err) | ||
|
||
name := strings.ToLower(tools.RandomString("acc-direct-connect", 5)) | ||
createOpts := direct_connect.CreateOpts{ | ||
Name: name, | ||
PortType: "1G", | ||
Bandwidth: 100, | ||
Location: "Biere", | ||
Provider: "OTC", | ||
} | ||
|
||
dc, err := direct_connect.Create(clientV2, createOpts) | ||
th.AssertNoErr(t, err) | ||
|
||
clientNet, err := clients.NewNetworkV1Client() | ||
th.AssertNoErr(t, err) | ||
vpc, err := vpcs.Get(clientNet, vpcID).Extract() | ||
th.AssertNoErr(t, err) | ||
|
||
// Create a virtual gateway | ||
nameVgw := strings.ToLower(tools.RandomString("acc-virtual-gateway-v3-", 5)) | ||
vgOpts := virtual_gateway.CreateOpts{ | ||
Name: nameVgw, | ||
VpcId: vpcID, | ||
Description: "acc-virtual-gateway-v3", | ||
LocalEpGroup: []string{vpc.CIDR}, | ||
Tags: []tags.ResourceTag{ | ||
{ | ||
Key: "TestKey", | ||
Value: "TestValue", | ||
}, | ||
}, | ||
} | ||
|
||
vg, err := virtual_gateway.Create(clientV3, vgOpts) | ||
th.AssertNoErr(t, err) | ||
|
||
t.Cleanup(func() { | ||
err = virtual_gateway.Delete(clientV3, vg.ID) | ||
th.AssertNoErr(t, err) | ||
}) | ||
|
||
// Create a virtual interface | ||
nameVi := tools.RandomString("acc-virtual-interface-", 5) | ||
viOpts := virtual_interface.CreateOpts{ | ||
Name: nameVi, | ||
DirectConnectID: dc.ID, | ||
VgwId: vg.ID, | ||
Type: "private", | ||
ServiceType: "vpc", | ||
VLAN: 100, | ||
Bandwidth: 5, | ||
LocalGatewayV4IP: "16.16.16.1/30", | ||
RemoteGatewayV4IP: "16.16.16.2/30", | ||
RouteMode: "static", | ||
RemoteEpGroup: []string{vpc.CIDR}, | ||
} | ||
|
||
created, err := virtual_interface.Create(clientV3, viOpts) | ||
th.AssertNoErr(t, err) | ||
|
||
vi, err := virtual_interface.Get(clientV3, created.ID) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, vi.RemoteEpGroup[0], vpc.CIDR) | ||
|
||
updated, err := virtual_interface.Update(clientV3, created.ID, virtual_interface.UpdateOpts{ | ||
Name: name + "-updated", | ||
Description: pointerto.String("New description"), | ||
}) | ||
th.AssertNoErr(t, err) | ||
th.AssertEquals(t, name+"-updated", updated.Name) | ||
|
||
// Cleanup | ||
t.Cleanup(func() { | ||
err = virtual_interface.Delete(clientV3, created.ID) | ||
th.AssertNoErr(t, err) | ||
}) | ||
} |
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,49 @@ | ||
package virtual_interface | ||
|
||
import ( | ||
golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
) | ||
|
||
type CreatePeerOpts struct { | ||
// Specifies the name of the virtual interface peer. | ||
Name string `json:"name" required:"true"` | ||
// Provides supplementary information about the virtual interface peer. | ||
Description string `json:"description,omitempty"` | ||
// Specifies the gateway address of the virtual interface peer used on the cloud. | ||
LocalGatewayIP string `json:"local_gateway_ip" required:"true"` | ||
// Specifies the IPv4 interface address of the gateway on the on-premises network. | ||
// This parameter is mandatory if address_family is set to an IPv4 address. | ||
RemoteGatewayIP string `json:"remote_gateway_ip" required:"true"` | ||
// Specifies the address family of the virtual interface. | ||
// The value can be IPv4 or IPv6. | ||
AddressFamily string `json:"address_family" required:"true"` | ||
// Specifies the routing mode. The value can be static or bgp. | ||
RouteMode string `json:"route_mode" required:"true"` | ||
// Specifies the ASN of the BGP peer on the customer side. | ||
BGPASN int `json:"bgp_asn,omitempty"` | ||
// Specifies the MD5 password of the BGP peer. | ||
BGPMD5 string `json:"bgp_md5,omitempty"` | ||
// Specifies the remote subnet list, which records the CIDR blocks used in the on-premises data center. | ||
RemoteEpGroup []string `json:"remote_ep_group,omitempty"` | ||
// Specifies the ID of the virtual interface corresponding to the virtual interface peer. | ||
VifId string `json:"vif_id" required:"true"` | ||
} | ||
|
||
func CreatePeer(c *golangsdk.ServiceClient, opts CreatePeerOpts) (*VifPeer, error) { | ||
b, err := build.RequestBody(opts, "vif_peer") | ||
if err != nil { | ||
return nil, err | ||
} | ||
raw, err := c.Post(c.ServiceURL("dcaas", "vif-peers"), b, nil, &golangsdk.RequestOpts{ | ||
OkCodes: []int{201}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var res VifPeer | ||
err = extract.IntoStructPtr(raw.Body, &res, "vif_peer") | ||
return &res, err | ||
} |
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,10 @@ | ||
package virtual_interface | ||
|
||
import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
|
||
func DeletePeer(c *golangsdk.ServiceClient, id string) (err error) { | ||
_, err = c.Delete(c.ServiceURL("dcaas", "vif-peers", id), &golangsdk.RequestOpts{ | ||
OkCodes: []int{200, 201, 204}, | ||
}) | ||
return | ||
} |
Oops, something went wrong.