huawei client update

This commit is contained in:
tb365
2021-08-10 16:28:31 +08:00
parent b35e9d7a9a
commit 2996dfcd7a
251 changed files with 25357 additions and 391 deletions
+157
View File
@@ -0,0 +1,157 @@
// 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 (
"fmt"
"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/mcclient"
"yunion.io/x/onecloud/pkg/util/billing"
"yunion.io/x/onecloud/pkg/util/rbacutils"
)
type SHuaweiCloudStackGuestDriver struct {
SManagedVirtualizedGuestDriver
}
func init() {
driver := SHuaweiCloudStackGuestDriver{}
models.RegisterGuestDriver(&driver)
}
func (self *SHuaweiCloudStackGuestDriver) GetHypervisor() string {
return api.HYPERVISOR_HUAWEI_CLOUD_STACK
}
func (self *SHuaweiCloudStackGuestDriver) GetProvider() string {
return api.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK
}
func (self *SHuaweiCloudStackGuestDriver) GetComputeQuotaKeys(scope rbacutils.TRbacScope, ownerId mcclient.IIdentityProvider, brand string) models.SComputeResourceKeys {
keys := models.SComputeResourceKeys{}
keys.SBaseProjectQuotaKeys = quotas.OwnerIdProjectQuotaKeys(scope, ownerId)
keys.CloudEnv = api.CLOUD_ENV_PRIVATE_CLOUD
keys.Provider = api.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK
keys.Brand = api.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK
keys.Hypervisor = api.HYPERVISOR_HUAWEI_CLOUD_STACK
return keys
}
func (self *SHuaweiCloudStackGuestDriver) GetDefaultSysDiskBackend() string {
return api.STORAGE_HUAWEI_SAS
}
func (self *SHuaweiCloudStackGuestDriver) GetMinimalSysDiskSizeGb() int {
return 40
}
func (self *SHuaweiCloudStackGuestDriver) GetStorageTypes() []string {
return []string{api.STORAGE_HUAWEI_SATA, api.STORAGE_HUAWEI_SAS, api.STORAGE_HUAWEI_SSD}
}
func (self *SHuaweiCloudStackGuestDriver) ChooseHostStorage(host *models.SHost, guest *models.SGuest, diskConfig *api.DiskConfig, storageIds []string) (*models.SStorage, error) {
return self.chooseHostStorage(self, host, diskConfig.Backend, storageIds), nil
}
func (self *SHuaweiCloudStackGuestDriver) GetDetachDiskStatus() ([]string, error) {
return []string{api.VM_READY, api.VM_RUNNING}, nil
}
func (self *SHuaweiCloudStackGuestDriver) GetAttachDiskStatus() ([]string, error) {
return []string{api.VM_READY, api.VM_RUNNING}, nil
}
func (self *SHuaweiCloudStackGuestDriver) GetRebuildRootStatus() ([]string, error) {
return []string{api.VM_READY, api.VM_RUNNING}, nil
}
func (self *SHuaweiCloudStackGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
return []string{api.VM_READY}, nil
}
func (self *SHuaweiCloudStackGuestDriver) GetDeployStatus() ([]string, error) {
return []string{api.VM_READY, api.VM_RUNNING}, nil
}
func (self *SHuaweiCloudStackGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY}) {
return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
}
if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_HUAWEI_SATA, api.STORAGE_HUAWEI_SAS, api.STORAGE_HUAWEI_SSD}) {
return fmt.Errorf("Cannot resize disk with unsupported volumes type %s", storage.StorageType)
}
return nil
}
func (self *SHuaweiCloudStackGuestDriver) GetGuestInitialStateAfterCreate() string {
return api.VM_RUNNING
}
func (self *SHuaweiCloudStackGuestDriver) GetGuestInitialStateAfterRebuild() string {
return api.VM_RUNNING
}
func (self *SHuaweiCloudStackGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapability {
return cloudprovider.SInstanceCapability{
Hypervisor: self.GetHypervisor(),
Provider: self.GetProvider(),
DefaultAccount: cloudprovider.SDefaultAccount{
Linux: cloudprovider.SOsDefaultAccount{
DefaultAccount: api.VM_DEFAULT_LINUX_LOGIN_USER,
},
Windows: cloudprovider.SOsDefaultAccount{
DefaultAccount: api.VM_DEFAULT_WINDOWS_LOGIN_USER,
},
},
Storages: cloudprovider.Storage{
DataDisk: []cloudprovider.StorageInfo{
cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SSD, MaxSizeGb: 32768, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SATA, MaxSizeGb: 32768, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SAS, MaxSizeGb: 32768, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_GPSSD, MaxSizeGb: 32768, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
},
SysDisk: []cloudprovider.StorageInfo{
cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SSD, MaxSizeGb: 1024, MinSizeGb: 40, StepSizeGb: 1, Resizable: false},
cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SATA, MaxSizeGb: 1024, MinSizeGb: 40, StepSizeGb: 1, Resizable: false},
cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SAS, MaxSizeGb: 1024, MinSizeGb: 40, StepSizeGb: 1, Resizable: false},
cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_GPSSD, MaxSizeGb: 1024, MinSizeGb: 40, StepSizeGb: 1, Resizable: false},
},
},
}
}
func (self *SHuaweiCloudStackGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle) bool {
months := bc.GetMonths()
if (months >= 1 && months <= 9) || (months == 12) || (months == 24) || (months == 36) {
return true
}
return false
}
func (self *SHuaweiCloudStackGuestDriver) IsNeedInjectPasswordByCloudInit(desc *cloudprovider.SManagedVMCreateConfig) bool {
return true
}
func (self *SHuaweiCloudStackGuestDriver) IsSupportSetAutoRenew() bool {
return true
}
+73
View File
@@ -0,0 +1,73 @@
// 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 hostdrivers
import (
"context"
"fmt"
"yunion.io/x/jsonutils"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
)
type SHuaweiCloudStackHostDriver struct {
SManagedVirtualizationHostDriver
}
func init() {
driver := SHuaweiCloudStackHostDriver{}
models.RegisterHostDriver(&driver)
}
func (self *SHuaweiCloudStackHostDriver) GetHostType() string {
return api.HOST_TYPE_HUAWEI_CLOUD_STACK
}
func (self *SHuaweiCloudStackHostDriver) GetHypervisor() string {
return api.HYPERVISOR_HUAWEI_CLOUD_STACK
}
// 系统盘必须至少40G
func (self *SHuaweiCloudStackHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
switch storage.StorageType {
case api.STORAGE_HUAWEI_SSD, api.STORAGE_HUAWEI_SATA, api.STORAGE_HUAWEI_SAS:
if sizeGb < 10 || sizeGb > 32768 {
return fmt.Errorf("The %s disk size must be in the range of 10G ~ 32768GB", storage.StorageType)
}
default:
return fmt.Errorf("Not support create %s disk", storage.StorageType)
}
return nil
}
func (self *SHuaweiCloudStackHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
if len(guests) >= 1 {
if disk.DiskType == api.DISK_TYPE_SYS {
for _, g := range guests {
if g.Status != api.VM_READY {
return nil, httperrors.NewBadRequestError("Server %s must in status ready", g.GetName())
}
}
} else {
return nil, httperrors.NewBadRequestError("Disk must be detached")
}
}
return data, nil
}
+1 -1
View File
@@ -54,7 +54,7 @@ func (self *SManagedVirtualizationHostDriver) CheckAndSetCacheImage(ctx context.
}
providerName := storageCache.GetProviderName()
if utils.IsInStringArray(providerName, []string{api.CLOUD_PROVIDER_HUAWEI, api.CLOUD_PROVIDER_UCLOUD}) {
if utils.IsInStringArray(providerName, []string{api.CLOUD_PROVIDER_HUAWEI, api.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK, api.CLOUD_PROVIDER_UCLOUD}) {
image.OsVersion, _ = params.GetString("os_full_version")
}
+26 -8
View File
@@ -436,13 +436,25 @@ func (manager *SCloudaccountManager) validateCreateData(
input.Zone = obj.GetId()
}
var endpointOptions jsonutils.JSONObject
endpoints := cloudprovider.SApsaraEndpoints{}
if input.SCloudaccountCredential.SApsaraEndpoints != nil {
endpoints = *input.SCloudaccountCredential.SApsaraEndpoints
endpointOptions = jsonutils.Marshal(input.SCloudaccountCredential.SApsaraEndpoints)
}
hcsoEndpoints := cloudprovider.SHuaweiCloudStackEndpoints{}
if input.SCloudaccountCredential.SHuaweiCloudStackEndpoints != nil {
hcsoEndpoints = *input.SCloudaccountCredential.SHuaweiCloudStackEndpoints
endpointOptions = jsonutils.Marshal(input.SCloudaccountCredential.SHuaweiCloudStackEndpoints)
}
if endpointOptions != nil {
if input.Options == nil {
input.Options = jsonutils.NewDict()
}
endpoints = *input.SCloudaccountCredential.SApsaraEndpoints
input.Options.Update(jsonutils.Marshal(input.SCloudaccountCredential.SApsaraEndpoints))
input.Options.Update(endpointOptions)
}
input.SCloudaccount, err = providerDriver.ValidateCreateCloudaccountData(ctx, userCred, input.SCloudaccountCredential)
@@ -499,7 +511,8 @@ func (manager *SCloudaccountManager) validateCreateData(
Secret: input.Secret,
ProxyFunc: proxyFunc,
SApsaraEndpoints: endpoints,
SApsaraEndpoints: endpoints,
SHuaweiCloudStackEndpoints: hcsoEndpoints,
})
if err != nil {
if err == cloudprovider.ErrNoSuchProvder {
@@ -903,8 +916,13 @@ func (self *SCloudaccount) getProviderInternal() (cloudprovider.ICloudProvider,
return nil, fmt.Errorf("Invalid password %s", err)
}
endpoints := cloudprovider.SApsaraEndpoints{}
if self.Provider == api.CLOUD_PROVIDER_APSARA && self.Options != nil {
self.Options.Unmarshal(&endpoints)
hcsoEndpoints := cloudprovider.SHuaweiCloudStackEndpoints{}
if self.Options != nil {
if self.Provider == api.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK {
self.Options.Unmarshal(&hcsoEndpoints)
} else if self.Provider == api.CLOUD_PROVIDER_APSARA {
self.Options.Unmarshal(&endpoints)
}
}
return cloudprovider.GetProvider(cloudprovider.ProviderConfig{
Id: self.Id,
@@ -914,9 +932,9 @@ func (self *SCloudaccount) getProviderInternal() (cloudprovider.ICloudProvider,
Account: self.Account,
Secret: secret,
SApsaraEndpoints: endpoints,
ProxyFunc: self.proxyFunc(),
SApsaraEndpoints: endpoints,
SHuaweiCloudStackEndpoints: hcsoEndpoints,
ProxyFunc: self.proxyFunc(),
})
}
+8 -2
View File
@@ -875,8 +875,13 @@ func (self *SCloudprovider) GetProvider() (cloudprovider.ICloudProvider, error)
account := self.GetCloudaccount()
endpoints := cloudprovider.SApsaraEndpoints{}
hscsoEndpoints := cloudprovider.SHuaweiCloudStackEndpoints{}
if account.Options != nil {
account.Options.Unmarshal(&endpoints)
if self.Provider == api.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK {
account.Options.Unmarshal(&hscsoEndpoints)
} else if self.Provider == api.CLOUD_PROVIDER_APSARA {
account.Options.Unmarshal(&endpoints)
}
}
return cloudprovider.GetProvider(cloudprovider.ProviderConfig{
@@ -888,7 +893,8 @@ func (self *SCloudprovider) GetProvider() (cloudprovider.ICloudProvider, error)
Secret: passwd,
ProxyFunc: account.proxyFunc(),
SApsaraEndpoints: endpoints,
SApsaraEndpoints: endpoints,
SHuaweiCloudStackEndpoints: hscsoEndpoints,
})
}
+1 -1
View File
@@ -615,7 +615,7 @@ func (self *SSecurityGroupCache) StartSecurityGroupCacheDeleteTask(ctx context.C
}
func (manager *SSecurityGroupCacheManager) InitializeData() error {
providerIds := CloudproviderManager.Query("id").In("provider", []string{api.CLOUD_PROVIDER_HUAWEI, api.CLOUD_PROVIDER_CTYUN, api.CLOUD_PROVIDER_QCLOUD}).SubQuery()
providerIds := CloudproviderManager.Query("id").In("provider", []string{api.CLOUD_PROVIDER_HUAWEI, api.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK, api.CLOUD_PROVIDER_CTYUN, api.CLOUD_PROVIDER_QCLOUD}).SubQuery()
deprecatedSecgroups := []SSecurityGroupCache{}
q := manager.Query().In("manager_id", providerIds).NotEquals("vpc_id", api.NORMAL_VPC_ID)
+19
View File
@@ -0,0 +1,19 @@
package regiondrivers
import (
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/compute/models"
)
type SHuaweiCloudStackRegionDriver struct {
SHuaWeiRegionDriver
}
func init() {
driver := SHuaweiCloudStackRegionDriver{}
models.RegisterRegionDriver(&driver)
}
func (self *SHuaweiCloudStackRegionDriver) GetProvider() string {
return api.CLOUD_PROVIDER_HUAWEI_CLOUD_STACK
}