instancenic.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 baidu
  15. import "yunion.io/x/cloudmux/pkg/cloudprovider"
  16. type Ips struct {
  17. PrivateIP string
  18. Eip string
  19. Primary bool
  20. EipId string
  21. EipAllocationId string
  22. EipSize string
  23. EipStatus string
  24. EipGroupId string
  25. EipType string
  26. }
  27. type NicInfo struct {
  28. cloudprovider.DummyICloudNic
  29. EniId string
  30. EniUUId string
  31. Name string
  32. Type string
  33. SubnetId string
  34. SubnetType string
  35. Az string
  36. Description string
  37. DeviceId string
  38. Status string
  39. MacAddress string
  40. VpcId string
  41. CreatedTime string
  42. EniNum int
  43. EriNum int
  44. Ips []Ips
  45. SecurityGroups []string
  46. }
  47. func (nic *NicInfo) GetId() string {
  48. return nic.EniId
  49. }
  50. func (nic *NicInfo) GetIP() string {
  51. for _, ip := range nic.Ips {
  52. if ip.Primary {
  53. return ip.PrivateIP
  54. }
  55. }
  56. return ""
  57. }
  58. func (nic *NicInfo) InClassicNetwork() bool {
  59. return false
  60. }
  61. func (nic *NicInfo) GetIP6() string {
  62. return ""
  63. }
  64. func (nic *NicInfo) GetDriver() string {
  65. return "virtio"
  66. }
  67. func (nic *NicInfo) GetINetworkId() string {
  68. return nic.SubnetId
  69. }
  70. func (nic *NicInfo) GetMAC() string {
  71. return nic.MacAddress
  72. }
  73. func (nic *NicInfo) GetSubAddress() ([]string, error) {
  74. ret := []string{}
  75. for _, ip := range nic.Ips {
  76. if ip.Primary {
  77. continue
  78. }
  79. if len(ip.PrivateIP) > 0 {
  80. ret = append(ret, ip.PrivateIP)
  81. }
  82. }
  83. return ret, nil
  84. }