github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/alicloud/service_alicloud_vpc.go (about) 1 package alicloud 2 3 import ( 4 "github.com/denverdino/aliyungo/common" 5 "github.com/denverdino/aliyungo/ecs" 6 "strings" 7 ) 8 9 func (client *AliyunClient) DescribeEipAddress(allocationId string) (*ecs.EipAddressSetType, error) { 10 11 args := ecs.DescribeEipAddressesArgs{ 12 RegionId: client.Region, 13 AllocationId: allocationId, 14 } 15 16 eips, _, err := client.ecsconn.DescribeEipAddresses(&args) 17 if err != nil { 18 return nil, err 19 } 20 if len(eips) == 0 { 21 return nil, common.GetClientErrorFromString("Not found") 22 } 23 24 return &eips[0], nil 25 } 26 27 func (client *AliyunClient) DescribeNatGateway(natGatewayId string) (*NatGatewaySetType, error) { 28 29 args := &DescribeNatGatewaysArgs{ 30 RegionId: client.Region, 31 NatGatewayId: natGatewayId, 32 } 33 34 natGateways, _, err := DescribeNatGateways(client.ecsconn, args) 35 if err != nil { 36 return nil, err 37 } 38 39 if len(natGateways) == 0 { 40 return nil, common.GetClientErrorFromString("Not found") 41 } 42 43 return &natGateways[0], nil 44 } 45 46 func (client *AliyunClient) DescribeVpc(vpcId string) (*ecs.VpcSetType, error) { 47 args := ecs.DescribeVpcsArgs{ 48 RegionId: client.Region, 49 VpcId: vpcId, 50 } 51 52 vpcs, _, err := client.ecsconn.DescribeVpcs(&args) 53 if err != nil { 54 if notFoundError(err) { 55 return nil, nil 56 } 57 return nil, err 58 } 59 60 if len(vpcs) == 0 { 61 return nil, nil 62 } 63 64 return &vpcs[0], nil 65 } 66 67 // describe vswitch by param filters 68 func (client *AliyunClient) QueryVswitches(args *ecs.DescribeVSwitchesArgs) (vswitches []ecs.VSwitchSetType, err error) { 69 vsws, _, err := client.ecsconn.DescribeVSwitches(args) 70 if err != nil { 71 if notFoundError(err) { 72 return nil, nil 73 } 74 return nil, err 75 } 76 77 return vsws, nil 78 } 79 80 func (client *AliyunClient) QueryVswitchById(vpcId, vswitchId string) (vsw *ecs.VSwitchSetType, err error) { 81 args := &ecs.DescribeVSwitchesArgs{ 82 VpcId: vpcId, 83 VSwitchId: vswitchId, 84 } 85 vsws, err := client.QueryVswitches(args) 86 if err != nil { 87 return nil, err 88 } 89 90 if len(vsws) == 0 { 91 return nil, nil 92 } 93 94 return &vsws[0], nil 95 } 96 97 func (client *AliyunClient) QueryRouteTables(args *ecs.DescribeRouteTablesArgs) (routeTables []ecs.RouteTableSetType, err error) { 98 rts, _, err := client.ecsconn.DescribeRouteTables(args) 99 if err != nil { 100 return nil, err 101 } 102 103 return rts, nil 104 } 105 106 func (client *AliyunClient) QueryRouteTableById(routeTableId string) (rt *ecs.RouteTableSetType, err error) { 107 args := &ecs.DescribeRouteTablesArgs{ 108 RouteTableId: routeTableId, 109 } 110 rts, err := client.QueryRouteTables(args) 111 if err != nil { 112 return nil, err 113 } 114 115 if len(rts) == 0 { 116 return nil, &common.Error{ErrorResponse: common.ErrorResponse{Message: Notfound}} 117 } 118 119 return &rts[0], nil 120 } 121 122 func (client *AliyunClient) QueryRouteEntry(routeTableId, cidrBlock, nextHopType, nextHopId string) (rn *ecs.RouteEntrySetType, err error) { 123 rt, errs := client.QueryRouteTableById(routeTableId) 124 if errs != nil { 125 return nil, errs 126 } 127 128 for _, e := range rt.RouteEntrys.RouteEntry { 129 if strings.ToLower(string(e.DestinationCidrBlock)) == cidrBlock { 130 return &e, nil 131 } 132 } 133 return nil, nil 134 }