| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- // Copyright 2019 Yunion
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package ctyun
- import (
- "yunion.io/x/pkg/errors"
- api "yunion.io/x/cloudmux/pkg/apis/compute"
- "yunion.io/x/cloudmux/pkg/cloudprovider"
- "yunion.io/x/cloudmux/pkg/multicloud"
- )
- type SWire struct {
- multicloud.SResourceBase
- CtyunTags
- vpc *SVpc
- }
- func (self *SWire) GetId() string {
- return self.vpc.GetId()
- }
- func (self *SWire) GetName() string {
- return self.vpc.GetName()
- }
- func (self *SWire) GetGlobalId() string {
- return self.vpc.GetGlobalId()
- }
- func (self *SWire) GetStatus() string {
- return api.WIRE_STATUS_AVAILABLE
- }
- func (self *SWire) IsEmulated() bool {
- return true
- }
- func (self *SWire) GetIVpc() cloudprovider.ICloudVpc {
- return self.vpc
- }
- func (self *SWire) GetIZone() cloudprovider.ICloudZone {
- return nil
- }
- func (self *SWire) GetINetworks() ([]cloudprovider.ICloudNetwork, error) {
- networks, err := self.vpc.region.GetNetwroks(self.vpc.VpcId)
- if err != nil {
- return nil, err
- }
- ret := []cloudprovider.ICloudNetwork{}
- for i := range networks {
- networks[i].wire = self
- ret = append(ret, &networks[i])
- }
- return ret, nil
- }
- func (self *SWire) GetBandwidth() int {
- return 10000
- }
- func (self *SWire) GetINetworkById(netid string) (cloudprovider.ICloudNetwork, error) {
- networks, err := self.GetINetworks()
- if err != nil {
- return nil, err
- }
- for i := 0; i < len(networks); i += 1 {
- if networks[i].GetGlobalId() == netid {
- return networks[i], nil
- }
- }
- return nil, cloudprovider.ErrNotFound
- }
- func (self *SWire) CreateINetwork(opts *cloudprovider.SNetworkCreateOptions) (cloudprovider.ICloudNetwork, error) {
- network, err := self.vpc.region.CreateNetwork(self.vpc.VpcId, opts)
- if err != nil {
- return nil, errors.Wrap(err, "CreateNetwork")
- }
- network.wire = self
- return network, nil
- }
|