host.go 3.5 KB

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