yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/ecloud/host.go (about)

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