yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/remotefile/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 remotefile
    16  
    17  import "yunion.io/x/cloudmux/pkg/cloudprovider"
    18  
    19  type SWire struct {
    20  	SResourceBase
    21  
    22  	region *SRegion
    23  
    24  	WireId    string
    25  	VpcId     string
    26  	ZoneId    string
    27  	Bandwidth int
    28  }
    29  
    30  func (self *SWire) GetIVpc() cloudprovider.ICloudVpc {
    31  	vpcs, err := self.region.client.GetVpcs()
    32  	if err != nil {
    33  		return nil
    34  	}
    35  	for i := range vpcs {
    36  		if vpcs[i].GetId() == self.VpcId {
    37  			vpcs[i].region = self.region
    38  			return &vpcs[i]
    39  		}
    40  	}
    41  	return nil
    42  }
    43  
    44  func (self *SWire) GetIZone() cloudprovider.ICloudZone {
    45  	zones, err := self.region.client.GetZones()
    46  	if err != nil {
    47  		return nil
    48  	}
    49  	for i := range zones {
    50  		if zones[i].GetId() == self.ZoneId {
    51  			zones[i].region = self.region
    52  			return &zones[i]
    53  		}
    54  	}
    55  	return nil
    56  }
    57  
    58  func (self *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) {
    59  	networks, err := self.region.client.GetNetworks()
    60  	if err != nil {
    61  		return nil, err
    62  	}
    63  	ret := []cloudprovider.ICloudNetwork{}
    64  	for i := range networks {
    65  		if networks[i].WireId != self.GetId() {
    66  			continue
    67  		}
    68  		networks[i].wire = self
    69  		ret = append(ret, &networks[i])
    70  	}
    71  	return ret, nil
    72  }
    73  
    74  func (self *SWire) GetBandwidth() int {
    75  	return self.Bandwidth
    76  }
    77  
    78  func (self *SWire) GetINetworkById(id string) (cloudprovider.ICloudNetwork, error) {
    79  	networks, err := self.GetINetworks()
    80  	if err != nil {
    81  		return nil, err
    82  	}
    83  	for i := range networks {
    84  		if networks[i].GetGlobalId() == id {
    85  			return networks[i], nil
    86  		}
    87  	}
    88  	return nil, cloudprovider.ErrNotFound
    89  }
    90  
    91  func (self *SWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) {
    92  	return nil, cloudprovider.ErrNotSupported
    93  }