host.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 ecloud
  15. import (
  16. "fmt"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/errors"
  19. api "yunion.io/x/cloudmux/pkg/apis/compute"
  20. "yunion.io/x/cloudmux/pkg/cloudprovider"
  21. "yunion.io/x/cloudmux/pkg/multicloud"
  22. )
  23. type SHost struct {
  24. multicloud.SHostBase
  25. zone *SZone
  26. }
  27. func (h *SHost) GetId() string {
  28. return fmt.Sprintf("%s-%s", h.zone.region.client.cpcfg.Id, h.zone.GetId())
  29. }
  30. func (h *SHost) GetName() string {
  31. return fmt.Sprintf("%s-%s", h.zone.region.client.cpcfg.Name, h.zone.GetId())
  32. }
  33. func (h *SHost) GetGlobalId() string {
  34. return h.GetId()
  35. }
  36. func (h *SHost) GetStatus() string {
  37. return api.HOST_STATUS_RUNNING
  38. }
  39. func (h *SHost) Refresh() error {
  40. return nil
  41. }
  42. func (h *SHost) IsEmulated() bool {
  43. return true
  44. }
  45. func (h *SHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
  46. vms, err := h.zone.region.GetInstances(h.zone.ZoneId, "")
  47. if err != nil {
  48. return nil, errors.Wrap(err, "SHost.GetVMs")
  49. }
  50. ivms := make([]cloudprovider.ICloudVM, len(vms))
  51. for i := range vms {
  52. vms[i].host = h
  53. ivms[i] = &vms[i]
  54. }
  55. return ivms, nil
  56. }
  57. func (h *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
  58. vm, err := h.zone.region.GetInstance(id)
  59. if err != nil {
  60. return nil, err
  61. }
  62. vm.host = h
  63. return vm, nil
  64. }
  65. func (h *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
  66. return h.zone.GetIStorages()
  67. }
  68. func (h *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
  69. return h.zone.GetIStorageById(id)
  70. }
  71. func (h *SHost) GetEnabled() bool {
  72. return true
  73. }
  74. func (h *SHost) GetHostStatus() string {
  75. return api.HOST_ONLINE
  76. }
  77. func (h *SHost) GetAccessIp() string {
  78. return ""
  79. }
  80. func (h *SHost) GetAccessMac() string {
  81. return ""
  82. }
  83. func (h *SHost) GetSysInfo() jsonutils.JSONObject {
  84. info := jsonutils.NewDict()
  85. info.Add(jsonutils.NewString(api.CLOUD_PROVIDER_ECLOUD), "manufacture")
  86. return info
  87. }
  88. func (h *SHost) GetSN() string {
  89. return ""
  90. }
  91. func (h *SHost) GetCpuCount() int {
  92. return 0
  93. }
  94. func (h *SHost) GetNodeCount() int8 {
  95. return 0
  96. }
  97. func (h *SHost) GetCpuDesc() string {
  98. return ""
  99. }
  100. func (h *SHost) GetCpuMhz() int {
  101. return 0
  102. }
  103. func (h *SHost) GetMemSizeMB() int {
  104. return 0
  105. }
  106. func (h *SHost) GetStorageSizeMB() int64 {
  107. return 0
  108. }
  109. func (h *SHost) GetStorageType() string {
  110. return api.DISK_TYPE_HYBRID
  111. }
  112. func (h *SHost) GetHostType() string {
  113. return api.HOST_TYPE_ECLOUD
  114. }
  115. func (h *SHost) GetIsMaintenance() bool {
  116. return false
  117. }
  118. func (h *SHost) GetVersion() string {
  119. return CLOUD_API_VERSION
  120. }
  121. func (h *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
  122. return nil, cloudprovider.ErrNotImplemented
  123. }
  124. func (h *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
  125. wires, err := h.zone.GetIWires()
  126. if err != nil {
  127. return nil, errors.Wrap(err, "GetIWires")
  128. }
  129. return cloudprovider.GetHostNetifs(h, wires), nil
  130. }
  131. func (h *SRegion) GetVMs() ([]SInstance, error) {
  132. return nil, cloudprovider.ErrNotImplemented
  133. }
  134. func (h *SRegion) GetVMById(vmId string) (*SInstance, error) {
  135. return nil, cloudprovider.ErrNotImplemented
  136. }