instancenic.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 bingocloud
  15. import "yunion.io/x/cloudmux/pkg/cloudprovider"
  16. type SInstanceNic struct {
  17. Association string `json:"association"`
  18. Attachment struct {
  19. AttachTime string `json:"attachTime"`
  20. AttachmentId string `json:"attachmentId"`
  21. DeleteOnTermination string `json:"deleteOnTermination"`
  22. DeviceIndex string `json:"deviceIndex"`
  23. InstanceId string `json:"instanceId"`
  24. InstanceOwnerId string `json:"instanceOwnerId"`
  25. Status string `json:"status"`
  26. } `json:"attachment"`
  27. AvailabilityZone string `json:"availabilityZone"`
  28. Description string `json:"description"`
  29. FirstPacketLimit string `json:"firstPacketLimit"`
  30. MACAddress string `json:"macAddress"`
  31. Model string `json:"model"`
  32. NetworkInterfaceId string `json:"networkInterfaceId"`
  33. NoMatchPort string `json:"noMatchPort"`
  34. OwnerId string `json:"ownerId"`
  35. PrivateDNSName string `json:"privateDnsName"`
  36. PrivateIPAddress string `json:"privateIpAddress"`
  37. PrivateIPAddressesSet []struct {
  38. Association string `json:"association"`
  39. Primary string `json:"primary"`
  40. PrivateDNSName string `json:"privateDnsName"`
  41. PrivateIPAddress string `json:"privateIpAddress"`
  42. } `json:"privateIpAddressesSet"`
  43. RequesterManaged string `json:"requesterManaged"`
  44. SourceDestCheck string `json:"sourceDestCheck"`
  45. Status string `json:"status"`
  46. SubnetId string `json:"subnetId"`
  47. VpcId string `json:"vpcId"`
  48. }
  49. func (self *SInstanceNic) GetId() string {
  50. return self.NetworkInterfaceId
  51. }
  52. func (self *SInstanceNic) GetIP() string {
  53. return self.PrivateIPAddress
  54. }
  55. func (self *SInstanceNic) GetIP6() string {
  56. return ""
  57. }
  58. func (self *SInstanceNic) GetMAC() string {
  59. return self.MACAddress
  60. }
  61. func (self *SInstanceNic) InClassicNetwork() bool {
  62. return false
  63. }
  64. func (self *SInstanceNic) GetDriver() string {
  65. return self.Model
  66. }
  67. func (self *SInstanceNic) GetINetworkId() string {
  68. return self.SubnetId
  69. }
  70. func (self *SInstanceNic) GetSubAddress() ([]string, error) {
  71. var ret []string
  72. for _, ip := range self.PrivateIPAddressesSet {
  73. if ip.PrivateIPAddress != self.PrivateIPAddress {
  74. ret = append(ret, ip.PrivateIPAddress)
  75. }
  76. }
  77. return ret, nil
  78. }
  79. func (self *SInstanceNic) AssignNAddress(count int) ([]string, error) {
  80. return nil, cloudprovider.ErrNotImplemented
  81. }
  82. func (self *SInstanceNic) AssignAddress(ipAddrs []string) error {
  83. return cloudprovider.ErrNotImplemented
  84. }
  85. func (self *SInstanceNic) UnassignAddress(ipAddrs []string) error {
  86. return cloudprovider.ErrNotImplemented
  87. }
  88. func (self *SRegion) GetInstanceNics(insId string) ([]SInstanceNic, error) {
  89. params := map[string]string{}
  90. if len(insId) > 0 {
  91. params["InstanceId"] = insId
  92. }
  93. resp, err := self.invoke("DescribeNetworkInterfaces", params)
  94. if err != nil {
  95. return nil, err
  96. }
  97. ret := struct {
  98. NetworkInterfaceSet []SInstanceNic
  99. }{}
  100. _ = resp.Unmarshal(&ret)
  101. return ret.NetworkInterfaceSet, nil
  102. }