1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
package ecs
import (
"testing"
"github.com/denverdino/aliyungo/common"
)
func TestAllocatePublicIpAddress(t *testing.T) {
client := NewTestClient()
instance, err := client.DescribeInstanceAttribute(TestInstanceId)
if err != nil {
t.Fatalf("Failed to describe instance %s: %v", TestInstanceId, err)
}
t.Logf("Instance: %++v %v", instance, err)
ipAddr, err := client.AllocatePublicIpAddress(TestInstanceId)
if err != nil {
t.Fatalf("Failed to allocate public IP address for instance %s: %v", TestInstanceId, err)
}
t.Logf("Public IP address of instance %s: %s", TestInstanceId, ipAddr)
}
func testEipAddress(t *testing.T, client *Client, regionId common.Region, instanceId string) error {
args := AllocateEipAddressArgs{
RegionId: regionId,
Bandwidth: 5,
InternetChargeType: common.PayByTraffic,
ClientToken: client.GenerateClientToken(),
}
ipAddr, allocationId, err := client.AllocateEipAddress(&args)
if err != nil {
t.Errorf("Failed to allocate EIP address: %v", err)
return err
}
t.Logf("EIP address: %s, AllocationId: %s", ipAddr, allocationId)
err = client.WaitForEip(regionId, allocationId, EipStatusAvailable, 0)
if err != nil {
t.Errorf("Failed to wait EIP %s: %v", allocationId, err)
}
err = client.AssociateEipAddress(allocationId, instanceId)
if err != nil {
t.Errorf("Failed to associate EIP address: %v", err)
}
err = client.WaitForEip(regionId, allocationId, EipStatusInUse, 0)
if err != nil {
t.Errorf("Failed to wait EIP %s: %v", allocationId, err)
}
err = client.UnassociateEipAddress(allocationId, instanceId)
if err != nil {
t.Errorf("Failed to unassociate EIP address: %v", err)
}
err = client.WaitForEip(regionId, allocationId, EipStatusAvailable, 0)
if err != nil {
t.Errorf("Failed to wait EIP %s: %v", allocationId, err)
}
err = client.ReleaseEipAddress(allocationId)
if err != nil {
t.Errorf("Failed to release EIP address: %v", err)
}
return err
}
func TestClient_AllocateEipAddress(t *testing.T) {
client := NewVPCClientWithSecurityToken(TestAccessKeyId, TestAccessKeySecret, "", TestRegionID)
client.SetDebug(true)
args := &AllocateEipAddressArgs{
RegionId: TestRegionID,
Bandwidth: 5,
InternetChargeType: common.PayByTraffic,
ISP: "BGP_FinanceCloud",
ClientToken: client.GenerateClientToken(),
}
eip, aid, err := client.AllocateEipAddress(args)
if err != nil {
t.Fatalf("Error %++v", err)
} else {
t.Logf("eip=%s,aid=%s", eip, aid)
}
}
func TestClient_DescribeEipAddresses(t *testing.T) {
client := NewVpcTestClientForDebug()
args := &DescribeEipAddressesArgs{
RegionId: TestRegionID,
AssociatedInstanceType: AssociatedInstanceTypeNat,
AssociatedInstanceId: TestInstanceId,
}
eips, _, err := client.DescribeEipAddresses(args)
if err != nil {
t.Fatalf("Error %++v", err)
} else {
for index, item := range eips {
t.Logf("eips[%d]=%++v", index, item)
}
}
}
|