yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/natdtable.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package qcloud 16 17 import ( 18 "fmt" 19 "time" 20 21 api "yunion.io/x/cloudmux/pkg/apis/compute" 22 "yunion.io/x/cloudmux/pkg/cloudprovider" 23 "yunion.io/x/cloudmux/pkg/multicloud" 24 ) 25 26 type SDTable struct { 27 multicloud.SResourceBase 28 QcloudTags 29 nat *SNatGateway 30 31 Eip string 32 NatId string 33 Description string 34 UniqVpcId string 35 Proto string 36 Pport int 37 Eport int 38 Owner string 39 VpcId int 40 PipType int 41 Pip string 42 UniqNatId string 43 CreateTime time.Time 44 } 45 46 func (table *SDTable) GetName() string { 47 if len(table.Description) > 0 { 48 return table.Description 49 } 50 return fmt.Sprintf("%s/%s/%d", table.Eip, table.Proto, table.Eport) 51 } 52 53 func (table *SDTable) GetId() string { 54 return fmt.Sprintf("%s/%s/%d", table.NatId, table.Eip, table.Eport) 55 } 56 57 func (table *SDTable) GetGlobalId() string { 58 return table.GetId() 59 } 60 61 func (table *SDTable) GetStatus() string { 62 return api.NAT_STAUTS_AVAILABLE 63 } 64 65 func (table *SDTable) GetExternalIp() string { 66 return table.Eip 67 } 68 69 func (table *SDTable) GetExternalPort() int { 70 return table.Eport 71 } 72 73 func (table *SDTable) GetInternalIp() string { 74 return table.Pip 75 } 76 77 func (table *SDTable) GetInternalPort() int { 78 return table.Pport 79 } 80 81 func (table *SDTable) GetIpProtocol() string { 82 return table.Proto 83 } 84 85 func (table *SDTable) Delete() error { 86 return cloudprovider.ErrNotImplemented 87 } 88 89 func (region *SRegion) GetDTables(natId, vpcId string) ([]SDTable, error) { 90 param := map[string]string{} 91 param["vpcId"] = vpcId 92 param["natId"] = natId 93 94 body, err := region.vpc2017Request("GetDnaptRule", param) 95 if err != nil { 96 return nil, err 97 } 98 tables := []SDTable{} 99 err = body.Unmarshal(&tables, "data", "detail") 100 if err != nil { 101 return nil, err 102 } 103 return tables, nil 104 }