instancenic.go 1.7 KB

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