instancenic.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 zstack
  15. import (
  16. "fmt"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/log"
  19. "yunion.io/x/cloudmux/pkg/cloudprovider"
  20. )
  21. type SInstanceNic struct {
  22. instance *SInstance
  23. UUID string `json:"uuid"`
  24. VMInstanceUUID string `json:"vmInstanceUuid"`
  25. L3NetworkUUID string `json:"l3NetworkUuid"`
  26. IP string `json:"ip"`
  27. Mac string `json:"mac"`
  28. HypervisorType string `json:"hypervisorType"`
  29. IPVersion int `json:"ipVersion"`
  30. UsedIps []string `json:"usedIps"`
  31. InternalName string `json:"internalName"`
  32. DeviceID int `json:"deviceId"`
  33. ZStackTime
  34. cloudprovider.DummyICloudNic
  35. }
  36. func (nic *SInstanceNic) GetId() string {
  37. return ""
  38. }
  39. func (nic *SInstanceNic) GetIP() string {
  40. return nic.IP
  41. }
  42. func (nic *SInstanceNic) GetMAC() string {
  43. return nic.Mac
  44. }
  45. func (nic *SInstanceNic) GetDriver() string {
  46. return "virtio"
  47. }
  48. func (nic *SInstanceNic) InClassicNetwork() bool {
  49. return false
  50. }
  51. func (nic *SInstanceNic) GetINetworkId() string {
  52. networks, err := nic.instance.host.zone.region.GetNetworks(nic.instance.host.zone.UUID, "", nic.L3NetworkUUID, "")
  53. if err != nil {
  54. log.Errorf("failed to found networks for nic %v error: %v", jsonutils.Marshal(nic).String(), err)
  55. return ""
  56. }
  57. for i := 0; i < len(networks); i++ {
  58. if networks[i].Contains(nic.IP) {
  59. return fmt.Sprintf("%s/%s", networks[i].L3NetworkUUID, networks[i].UUID)
  60. }
  61. }
  62. return ""
  63. }