mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
154 lines
4.7 KiB
Go
154 lines
4.7 KiB
Go
// Copyright 2019 Yunion
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package guestdrivers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"yunion.io/x/jsonutils"
|
|
"yunion.io/x/pkg/utils"
|
|
|
|
api "yunion.io/x/onecloud/pkg/apis/compute"
|
|
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
|
"yunion.io/x/onecloud/pkg/cloudprovider"
|
|
"yunion.io/x/onecloud/pkg/compute/models"
|
|
"yunion.io/x/onecloud/pkg/httperrors"
|
|
"yunion.io/x/onecloud/pkg/mcclient"
|
|
"yunion.io/x/onecloud/pkg/util/billing"
|
|
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
|
)
|
|
|
|
type SAzureGuestDriver struct {
|
|
SManagedVirtualizedGuestDriver
|
|
}
|
|
|
|
func init() {
|
|
driver := SAzureGuestDriver{}
|
|
models.RegisterGuestDriver(&driver)
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetHypervisor() string {
|
|
return api.HYPERVISOR_AZURE
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetProvider() string {
|
|
return api.CLOUD_PROVIDER_AZURE
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetComputeQuotaKeys(scope rbacutils.TRbacScope, ownerId mcclient.IIdentityProvider, brand string) models.SComputeResourceKeys {
|
|
keys := models.SComputeResourceKeys{}
|
|
keys.SBaseQuotaKeys = quotas.OwnerIdQuotaKeys(scope, ownerId)
|
|
keys.CloudEnv = api.CLOUD_ENV_PUBLIC_CLOUD
|
|
keys.Provider = api.CLOUD_PROVIDER_AZURE
|
|
// ignore brand
|
|
return keys
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetDefaultSysDiskBackend() string {
|
|
return api.STORAGE_STANDARD_LRS
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetMinimalSysDiskSizeGb() int {
|
|
return 30
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetStorageTypes() []string {
|
|
return []string{
|
|
api.STORAGE_STANDARD_LRS,
|
|
api.STORAGE_STANDARDSSD_LRS,
|
|
api.STORAGE_PREMIUM_LRS,
|
|
}
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) ChooseHostStorage(host *models.SHost, backend string, storageIds []string) *models.SStorage {
|
|
return self.chooseHostStorage(self, host, backend, storageIds)
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetMaxSecurityGroupCount() int {
|
|
return 1
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetDetachDiskStatus() ([]string, error) {
|
|
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
|
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
|
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetChangeConfigStatus() ([]string, error) {
|
|
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetDeployStatus() ([]string, error) {
|
|
return []string{api.VM_RUNNING}, nil
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) IsNeedRestartForResetLoginInfo() bool {
|
|
return false
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
|
|
//https://docs.microsoft.com/en-us/rest/api/compute/disks/update
|
|
//Resizes are only allowed if the disk is not attached to a running VM, and can only increase the disk's size
|
|
if !utils.IsInStringArray(guest.Status, []string{api.VM_READY}) {
|
|
return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, input *api.ServerCreateInput) (*api.ServerCreateInput, error) {
|
|
input, err := self.SManagedVirtualizedGuestDriver.ValidateCreateData(ctx, userCred, input)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(input.Networks) > 2 {
|
|
return nil, httperrors.NewInputParameterError("cannot support more than 1 nic")
|
|
}
|
|
return input, nil
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
|
if data.Contains("name") {
|
|
return nil, httperrors.NewInputParameterError("cannot support change azure instance name")
|
|
}
|
|
return data, nil
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetGuestInitialStateAfterCreate() string {
|
|
return api.VM_RUNNING
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetGuestInitialStateAfterRebuild() string {
|
|
return api.VM_READY
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string {
|
|
return api.VM_AZURE_DEFAULT_LOGIN_USER
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle) bool {
|
|
return false
|
|
}
|
|
|
|
func (self *SAzureGuestDriver) NeedStopForChangeSpec(guest *models.SGuest, cpuChanged, memChanged bool) bool {
|
|
return false
|
|
}
|