yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/wire.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 google 16 17 import ( 18 "fmt" 19 "time" 20 21 "yunion.io/x/pkg/errors" 22 23 api "yunion.io/x/cloudmux/pkg/apis/compute" 24 "yunion.io/x/cloudmux/pkg/cloudprovider" 25 "yunion.io/x/cloudmux/pkg/multicloud" 26 ) 27 28 type SWire struct { 29 multicloud.SResourceBase 30 GoogleTags 31 vpc *SVpc 32 } 33 34 func (wire *SWire) GetId() string { 35 return wire.vpc.GetGlobalId() 36 } 37 38 func (wire *SWire) GetGlobalId() string { 39 return fmt.Sprintf("%s-%s", wire.GetId(), wire.vpc.region.Name) 40 } 41 42 func (wire *SWire) GetName() string { 43 return wire.vpc.GetName() 44 } 45 46 func (wire *SWire) GetCreatedAt() time.Time { 47 return time.Time{} 48 } 49 50 func (wire *SWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) { 51 return nil, cloudprovider.ErrNotSupported 52 } 53 54 func (wire *SWire) GetIVpc() cloudprovider.ICloudVpc { 55 return wire.vpc 56 } 57 58 func (wire *SWire) GetIZone() cloudprovider.ICloudZone { 59 return nil 60 } 61 62 func (self *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) { 63 network := SNetwork{wire: self} 64 return []cloudprovider.ICloudNetwork{&network}, nil 65 } 66 67 func (self *SWire) GetINetworkById(id string) (cloudprovider.ICloudNetwork, error) { 68 networks, err := self.GetINetworks() 69 if err != nil { 70 return nil, errors.Wrapf(err, "GetINetwork") 71 } 72 for i := range networks { 73 if networks[i].GetGlobalId() == id { 74 return networks[i], nil 75 } 76 } 77 return nil, errors.Wrapf(cloudprovider.ErrNotFound, id) 78 } 79 80 func (wire *SWire) GetBandwidth() int { 81 return 0 82 } 83 84 func (wire *SWire) GetStatus() string { 85 return api.WIRE_STATUS_AVAILABLE 86 } 87 88 func (wire *SWire) IsEmulated() bool { 89 return true 90 } 91 92 func (wire *SWire) Refresh() error { 93 return nil 94 }