yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/zstack/vpc.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 zstack 16 17 import ( 18 "fmt" 19 20 api "yunion.io/x/cloudmux/pkg/apis/compute" 21 "yunion.io/x/cloudmux/pkg/cloudprovider" 22 "yunion.io/x/cloudmux/pkg/multicloud" 23 ) 24 25 type SVpc struct { 26 multicloud.SVpc 27 ZStackTags 28 29 region *SRegion 30 31 iwires []cloudprovider.ICloudWire 32 } 33 34 func (vpc *SVpc) GetId() string { 35 return fmt.Sprintf("%s/vpc", vpc.region.GetGlobalId()) 36 } 37 38 func (vpc *SVpc) GetName() string { 39 return fmt.Sprintf("%s-VPC", vpc.region.client.cpcfg.Name) 40 } 41 42 func (vpc *SVpc) GetGlobalId() string { 43 return vpc.GetId() 44 } 45 46 func (vpc *SVpc) IsEmulated() bool { 47 return true 48 } 49 50 func (vpc *SVpc) GetIsDefault() bool { 51 return true 52 } 53 54 func (vpc *SVpc) GetCidrBlock() string { 55 return "" 56 } 57 58 func (vpc *SVpc) GetStatus() string { 59 return api.VPC_STATUS_AVAILABLE 60 } 61 62 func (vpc *SVpc) Refresh() error { 63 return nil 64 } 65 66 func (vpc *SVpc) GetRegion() cloudprovider.ICloudRegion { 67 return vpc.region 68 } 69 70 func (vpc *SVpc) GetIWires() ([]cloudprovider.ICloudWire, error) { 71 if vpc.iwires == nil || len(vpc.iwires) == 0 { 72 vpc.iwires = []cloudprovider.ICloudWire{} 73 wires, err := vpc.region.GetWires("", "", "") 74 if err != nil { 75 return nil, err 76 } 77 for i := 0; i < len(wires); i++ { 78 wires[i].vpc = vpc 79 vpc.iwires = append(vpc.iwires, &wires[i]) 80 } 81 } 82 return vpc.iwires, nil 83 } 84 85 func (vpc *SVpc) GetIWireById(wireId string) (cloudprovider.ICloudWire, error) { 86 wire, err := vpc.region.GetWire(wireId) 87 if err != nil { 88 return nil, err 89 } 90 wire.vpc = vpc 91 return wire, nil 92 } 93 94 func (vpc *SVpc) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) { 95 secgroups, err := vpc.region.GetSecurityGroups("", "", "") 96 if err != nil { 97 return nil, err 98 } 99 isecgroups := []cloudprovider.ICloudSecurityGroup{} 100 for i := 0; i < len(secgroups); i++ { 101 isecgroups = append(isecgroups, &secgroups[i]) 102 } 103 return isecgroups, nil 104 } 105 106 func (vpc *SVpc) GetIRouteTables() ([]cloudprovider.ICloudRouteTable, error) { 107 return nil, cloudprovider.ErrNotSupported 108 } 109 110 func (self *SVpc) GetIRouteTableById(routeTableId string) (cloudprovider.ICloudRouteTable, error) { 111 return nil, cloudprovider.ErrNotSupported 112 } 113 114 func (vpc *SVpc) Delete() error { 115 return nil 116 }