yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/classic_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 azure
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"yunion.io/x/jsonutils"
    21  	"yunion.io/x/log"
    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 SClassicHost struct {
    29  	multicloud.SHostBase
    30  	zone *SZone
    31  }
    32  
    33  func (self *SClassicHost) GetId() string {
    34  	return fmt.Sprintf("%s-%s-classic", self.zone.region.client.cpcfg.Id, self.zone.GetId())
    35  }
    36  
    37  func (self *SClassicHost) GetName() string {
    38  	return fmt.Sprintf("%s/%s-classic", self.zone.region.GetGlobalId(), self.zone.region.client.subscriptionId)
    39  }
    40  
    41  func (self *SClassicHost) GetGlobalId() string {
    42  	return fmt.Sprintf("%s/%s-classic", self.zone.region.GetGlobalId(), self.zone.region.client.subscriptionId)
    43  }
    44  
    45  func (self *SClassicHost) IsEmulated() bool {
    46  	return true
    47  }
    48  
    49  func (self *SClassicHost) GetStatus() string {
    50  	return api.HOST_STATUS_READY
    51  }
    52  
    53  func (self *SClassicHost) Refresh() error {
    54  	return nil
    55  }
    56  
    57  func (self *SClassicHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
    58  	return nil, cloudprovider.ErrNotImplemented
    59  }
    60  
    61  func (self *SClassicHost) GetAccessIp() string {
    62  	return ""
    63  }
    64  
    65  func (self *SClassicHost) GetAccessMac() string {
    66  	return ""
    67  }
    68  
    69  func (self *SClassicHost) GetCpuCount() int {
    70  	return 0
    71  }
    72  
    73  func (self *SClassicHost) GetCpuDesc() string {
    74  	return ""
    75  }
    76  
    77  func (self *SClassicHost) GetCpuMhz() int {
    78  	return 0
    79  }
    80  
    81  func (self *SClassicHost) GetMemSizeMB() int {
    82  	return 0
    83  }
    84  func (self *SClassicHost) GetEnabled() bool {
    85  	return true
    86  }
    87  
    88  func (self *SClassicHost) GetHostStatus() string {
    89  	return api.HOST_ONLINE
    90  }
    91  func (self *SClassicHost) GetNodeCount() int8 {
    92  	return 0
    93  }
    94  
    95  func (self *SClassicHost) GetHostType() string {
    96  	return api.HOST_TYPE_AZURE
    97  }
    98  
    99  func (self *SClassicHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
   100  	return self.zone.GetIStorageById(id)
   101  }
   102  
   103  func (self *SClassicHost) GetSysInfo() jsonutils.JSONObject {
   104  	info := jsonutils.NewDict()
   105  	info.Add(jsonutils.NewString(CLOUD_PROVIDER_AZURE), "manufacture")
   106  	return info
   107  }
   108  
   109  func (self *SClassicHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
   110  	return self.zone.GetIClassicStorages(), nil
   111  }
   112  
   113  func (self *SClassicHost) GetIVMById(instanceId string) (cloudprovider.ICloudVM, error) {
   114  	instance, err := self.zone.region.GetClassicInstance(instanceId)
   115  	if err != nil {
   116  		return nil, err
   117  	}
   118  	instance.host = self
   119  	return instance, nil
   120  }
   121  
   122  func (self *SClassicHost) GetStorageSizeMB() int {
   123  	return 0
   124  }
   125  
   126  func (self *SClassicHost) GetStorageType() string {
   127  	return api.DISK_TYPE_HYBRID
   128  }
   129  
   130  func (self *SClassicHost) GetSN() string {
   131  	return ""
   132  }
   133  
   134  func (self *SClassicHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
   135  	if vms, err := self.zone.region.GetClassicInstances(); err != nil {
   136  		return nil, err
   137  	} else {
   138  		ivms := make([]cloudprovider.ICloudVM, len(vms))
   139  		for i := 0; i < len(vms); i++ {
   140  			vms[i].host = self
   141  			ivms[i] = &vms[i]
   142  			log.Debugf("find vm %s for host %s", vms[i].GetName(), self.GetName())
   143  		}
   144  		return ivms, nil
   145  	}
   146  }
   147  
   148  func (self *SClassicHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
   149  	return self.zone.GetIClassicWires()
   150  }
   151  
   152  func (host *SClassicHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
   153  	return nil, cloudprovider.ErrNotSupported
   154  }
   155  
   156  func (host *SClassicHost) GetIsMaintenance() bool {
   157  	return false
   158  }
   159  
   160  func (host *SClassicHost) GetVersion() string {
   161  	return AZURE_API_VERSION
   162  }