hostnic.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 esxi
  15. import (
  16. "yunion.io/x/pkg/tristate"
  17. "yunion.io/x/cloudmux/pkg/apis/compute"
  18. "yunion.io/x/cloudmux/pkg/cloudprovider"
  19. )
  20. type sHostNicInfo struct {
  21. Dev string
  22. Driver string
  23. Mac string
  24. Index int8
  25. LinkUp bool
  26. IpAddr string
  27. IpAddr6 string
  28. Mtu int32
  29. NicType compute.TNicType
  30. VlanId int
  31. IpAddrPrefixLen int8
  32. IpAddr6PrefixLen int8
  33. host *SHost
  34. network IVMNetwork
  35. }
  36. func (nic *sHostNicInfo) GetDevice() string {
  37. return nic.Dev
  38. }
  39. func (nic *sHostNicInfo) GetDriver() string {
  40. return nic.Driver
  41. }
  42. func (nic *sHostNicInfo) GetMac() string {
  43. if len(nic.Mac) > 0 {
  44. return nic.Mac
  45. }
  46. if nic.network != nil {
  47. return cloudprovider.HashIdsMac(nic.host.GetGlobalId(), nic.network.GetId())
  48. }
  49. panic("sHostNicInfo: empty mac and network?")
  50. }
  51. func (nic *sHostNicInfo) GetVlanId() int {
  52. if nic.VlanId > 0 {
  53. return nic.VlanId
  54. }
  55. return 1
  56. }
  57. func (nic *sHostNicInfo) GetIndex() int8 {
  58. return nic.Index
  59. }
  60. func (nic *sHostNicInfo) IsLinkUp() tristate.TriState {
  61. if nic.LinkUp {
  62. return tristate.True
  63. }
  64. return tristate.False
  65. }
  66. func (nic *sHostNicInfo) GetIpAddr() string {
  67. return nic.IpAddr
  68. }
  69. func (nic *sHostNicInfo) GetIpAddrPrefixLen() int8 {
  70. return nic.IpAddrPrefixLen
  71. }
  72. func (nic *sHostNicInfo) GetIpAddr6() string {
  73. return nic.IpAddr6
  74. }
  75. func (nic *sHostNicInfo) GetIpAddr6PrefixLen() int8 {
  76. return nic.IpAddr6PrefixLen
  77. }
  78. func (nic *sHostNicInfo) GetMtu() int32 {
  79. return nic.Mtu
  80. }
  81. func (nic *sHostNicInfo) GetNicType() string {
  82. return string(nic.NicType)
  83. }
  84. func (nic *sHostNicInfo) GetBridge() string {
  85. if nic.network != nil {
  86. return nic.network.GetId()
  87. }
  88. return ""
  89. }
  90. func (nic *sHostNicInfo) GetIWire() cloudprovider.ICloudWire {
  91. if nic.network != nil {
  92. return &sWire{
  93. network: nic.network,
  94. client: nic.host.manager,
  95. }
  96. }
  97. return nil
  98. }