yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/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 google
    16  
    17  import (
    18  	"yunion.io/x/pkg/util/netutils"
    19  
    20  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    21  )
    22  
    23  type SNetworkInterface struct {
    24  	instance *SInstance
    25  
    26  	Network       string
    27  	Subnetwork    string
    28  	NetworkIP     string
    29  	Name          string
    30  	AccessConfigs []AccessConfig
    31  	Fingerprint   string
    32  	Kind          string
    33  
    34  	cloudprovider.DummyICloudNic
    35  }
    36  
    37  func (nic *SNetworkInterface) GetId() string {
    38  	return ""
    39  }
    40  
    41  func (nic *SNetworkInterface) GetIP() string {
    42  	return nic.NetworkIP
    43  }
    44  
    45  func (nic *SNetworkInterface) GetMAC() string {
    46  	ip, _ := netutils.NewIPV4Addr(nic.NetworkIP)
    47  	return ip.ToMac("42:01:")
    48  }
    49  
    50  func (nic *SNetworkInterface) GetDriver() string {
    51  	return "virtio"
    52  }
    53  
    54  func (nic *SNetworkInterface) InClassicNetwork() bool {
    55  	return false
    56  }
    57  
    58  func (nic *SNetworkInterface) GetINetworkId() string {
    59  	vpc := &SVpc{region: nic.instance.host.zone.region}
    60  	err := nic.instance.host.zone.region.GetBySelfId(nic.Subnetwork, vpc)
    61  	if err != nil {
    62  		return ""
    63  	}
    64  	return vpc.Id
    65  }