yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/cloudpods/instancenic.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 cloudpods 16 17 import ( 18 "fmt" 19 20 "yunion.io/x/jsonutils" 21 22 api "yunion.io/x/onecloud/pkg/apis/compute" 23 modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute" 24 25 "yunion.io/x/cloudmux/pkg/cloudprovider" 26 "yunion.io/x/cloudmux/pkg/multicloud" 27 ) 28 29 type SInstanceNic struct { 30 multicloud.SResourceBase 31 ins *SInstance 32 33 api.GuestnetworkDetails 34 } 35 36 func (self *SInstanceNic) GetId() string { 37 return fmt.Sprintf("%d", self.RowId) 38 } 39 40 func (self *SInstanceNic) GetIP() string { 41 return self.IpAddr 42 } 43 44 func (self *SInstanceNic) GetDriver() string { 45 return self.Driver 46 } 47 48 func (self *SInstanceNic) InClassicNetwork() bool { 49 return false 50 } 51 52 func (self *SInstanceNic) GetMAC() string { 53 return self.MacAddr 54 } 55 56 func (self *SInstanceNic) GetSubAddress() ([]string, error) { 57 return []string{}, nil 58 } 59 60 func (self *SInstanceNic) AssignNAddress(count int) ([]string, error) { 61 return nil, cloudprovider.ErrNotImplemented 62 } 63 64 func (self *SInstanceNic) AssignAddress(ipAddrs []string) error { 65 return cloudprovider.ErrNotImplemented 66 } 67 68 func (self *SInstanceNic) UnassignAddress(IpAddrs []string) error { 69 return cloudprovider.ErrNotImplemented 70 } 71 72 func (self *SInstanceNic) GetINetworkId() string { 73 return self.NetworkId 74 } 75 76 func (self *SInstance) GetINics() ([]cloudprovider.ICloudNic, error) { 77 nics, err := self.host.zone.region.GetGuestnetworks(self.Id) 78 if err != nil { 79 return nil, err 80 } 81 ret := []cloudprovider.ICloudNic{} 82 for i := range nics { 83 nics[i].ins = self 84 ret = append(ret, &nics[i]) 85 } 86 return ret, nil 87 } 88 89 func (self *SRegion) GetGuestnetworks(serverId string) ([]SInstanceNic, error) { 90 ret := []SInstanceNic{} 91 params := map[string]interface{}{ 92 "scope": "system", 93 } 94 if len(serverId) > 0 { 95 params["server_id"] = serverId 96 } 97 resp, err := modules.Servernetworks.List(self.cli.s, jsonutils.Marshal(params)) 98 if err != nil { 99 return nil, err 100 } 101 return ret, jsonutils.Update(&ret, resp.Data) 102 }