| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package volcengine
- import (
- "fmt"
- api "yunion.io/x/cloudmux/pkg/apis/compute"
- "yunion.io/x/cloudmux/pkg/cloudprovider"
- "yunion.io/x/cloudmux/pkg/multicloud"
- "yunion.io/x/jsonutils"
- "yunion.io/x/pkg/errors"
- )
- type SHost struct {
- multicloud.SHostBase
- zone *SZone
- }
- func (host *SHost) GetIWires() ([]cloudprovider.ICloudWire, error) {
- return host.zone.GetIWires()
- }
- func (host *SHost) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
- return host.zone.GetIStorages()
- }
- func (host *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) {
- return host.zone.GetIStorageById(id)
- }
- func (host *SHost) GetId() string {
- return fmt.Sprintf("%s-%s", host.zone.region.client.cpcfg.Id, host.zone.GetId())
- }
- func (host *SHost) GetName() string {
- return fmt.Sprintf("%s-%s", host.zone.region.client.cpcfg.Name, host.zone.GetId())
- }
- func (host *SHost) GetGlobalId() string {
- return fmt.Sprintf("%s-%s", host.zone.region.client.cpcfg.Id, host.zone.GetId())
- }
- func (host *SHost) IsEmulated() bool {
- return true
- }
- func (host *SHost) GetStatus() string {
- return api.HOST_STATUS_RUNNING
- }
- func (host *SHost) Refresh() error {
- return nil
- }
- func (host *SHost) GetHostStatus() string {
- return api.HOST_ONLINE
- }
- func (host *SHost) GetEnabled() bool {
- return true
- }
- func (host *SHost) GetAccessIp() string {
- return ""
- }
- func (host *SHost) GetAccessMac() string {
- return ""
- }
- func (host *SHost) GetSysInfo() jsonutils.JSONObject {
- info := jsonutils.NewDict()
- info.Add(jsonutils.NewString(CLOUD_PROVIDER_VOLCENGINE), "manufacture")
- return info
- }
- func (host *SHost) GetSN() string {
- return ""
- }
- func (host *SHost) GetCpuCount() int {
- return 0
- }
- func (host *SHost) GetNodeCount() int8 {
- return 0
- }
- func (host *SHost) GetCpuDesc() string {
- return ""
- }
- func (host *SHost) GetCpuMhz() int {
- return 0
- }
- func (host *SHost) GetMemSizeMB() int {
- return 0
- }
- func (host *SHost) GetStorageSizeMB() int64 {
- return 0
- }
- func (host *SHost) GetStorageType() string {
- return api.DISK_TYPE_HYBRID
- }
- func (host *SHost) GetHostType() string {
- return api.HOST_TYPE_VOLCENGINE
- }
- func (host *SHost) GetIHostNics() ([]cloudprovider.ICloudHostNetInterface, error) {
- wires, err := host.zone.GetIWires()
- if err != nil {
- return nil, errors.Wrap(err, "GetIWires")
- }
- return cloudprovider.GetHostNetifs(host, wires), nil
- }
- func (host *SHost) GetIsMaintenance() bool {
- return false
- }
- func (host *SHost) GetVersion() string {
- return VOLCENGINE_API_VERSION
- }
- func (host *SHost) GetIVMs() ([]cloudprovider.ICloudVM, error) {
- vms, err := host.zone.region.GetInstances(host.zone.ZoneId, nil)
- if err != nil {
- return nil, err
- }
- ivms := make([]cloudprovider.ICloudVM, len(vms))
- for i := 0; i < len(vms); i += 1 {
- vms[i].host = host
- ivms[i] = &vms[i]
- }
- return ivms, nil
- }
- func (host *SHost) GetIVMById(id string) (cloudprovider.ICloudVM, error) {
- vm, err := host.zone.region.GetInstance(id)
- if err != nil {
- return nil, err
- }
- vm.host = host
- return vm, nil
- }
- func (host *SHost) GetInstanceById(instanceId string) (*SInstance, error) {
- inst, err := host.zone.region.GetInstance(instanceId)
- if err != nil {
- return nil, err
- }
- inst.host = host
- return inst, nil
- }
- func (host *SHost) CreateVM(opts *cloudprovider.SManagedVMCreateConfig) (cloudprovider.ICloudVM, error) {
- vmId, err := host._createVM(opts)
- if err != nil {
- return nil, err
- }
- vm, err := host.GetInstanceById(vmId)
- if err != nil {
- return nil, errors.Wrapf(err, "GetInstanceById")
- }
- return vm, nil
- }
- func (host *SHost) _createVM(opts *cloudprovider.SManagedVMCreateConfig) (string, error) {
- var err error
- if len(opts.PublicKey) > 0 {
- opts.KeypairName, err = host.zone.region.syncKeypair(opts.PublicKey)
- if err != nil {
- return "", err
- }
- }
- if len(opts.InstanceType) == 0 {
- return "", fmt.Errorf("instance type must be specified")
- }
- vmId, err := host.zone.region.CreateInstance(host.zone.ZoneId, opts)
- if err != nil {
- return "", errors.Wrapf(err, "Failed to create %s", opts.InstanceType)
- }
- return vmId, nil
- }
|