fix(region): support cnware (#23389)

This commit is contained in:
屈轩
2025-09-26 14:45:37 +08:00
committed by GitHub
parent c9ece3e7de
commit e67f8392a7
26 changed files with 575 additions and 12 deletions
+3
View File
@@ -62,6 +62,7 @@ func init() {
cmd.CreateWithKeyword("create-qingcloud", &options.SQingCloudCloudAccountCreateOptions{})
cmd.CreateWithKeyword("create-oracle", &options.SOracleCloudAccountCreateOptions{})
cmd.CreateWithKeyword("create-cephfs", &options.SCephFSCloudAccountCreateOptions{})
cmd.CreateWithKeyword("create-cnware", &options.SCNwareCloudAccountCreateOptions{})
cmd.UpdateWithKeyword("update-vmware", &options.SVMwareCloudAccountUpdateOptions{})
cmd.UpdateWithKeyword("update-aliyun", &options.SAliyunCloudAccountUpdateOptions{})
@@ -88,6 +89,7 @@ func init() {
cmd.UpdateWithKeyword("update-baidu", &options.SBaiduCloudAccountUpdateOptions{})
cmd.UpdateWithKeyword("update-cucloud", &options.SCucloudCloudAccountUpdateOptions{})
cmd.UpdateWithKeyword("update-qingcloud", &options.SQingCloudCloudAccountUpdateOptions{})
cmd.UpdateWithKeyword("update-cnware", &options.SCNwareCloudAccountUpdateOptions{})
cmd.Perform("update-credential", &options.CloudaccountUpdateCredentialOptions{})
@@ -117,6 +119,7 @@ func init() {
cmd.PerformWithKeyword("update-credential-baidu", "update-credential", &options.SBaiduCloudAccountUpdateCredentialOptions{})
cmd.PerformWithKeyword("update-credential-cucloud", "update-credential", &options.SCucloudCloudAccountUpdateCredentialOptions{})
cmd.PerformWithKeyword("update-credential-qingcloud", "update-credential", &options.SQingCloudCloudAccountUpdateCredentialOptions{})
cmd.PerformWithKeyword("update-credential-cnware", "update-credential", &options.SCNwareCloudAccountUpdateCredentialOptions{})
cmd.PerformWithKeyword("test-connectivity-google", "test-connectivity", &options.SGoogleCloudAccountUpdateCredentialOptions{})
cmd.PerformWithKeyword("test-connectivity-vmware", "test-connectivity", &options.SVMwareCloudAccountUpdateCredentialOptions{})
+3 -3
View File
@@ -31,9 +31,9 @@ import (
)
type GeneralUsageOptions struct {
HostType []string `help:"Host types" choices:"hypervisor|baremetal|esxi|xen|kubelet|hyperv|aliyun|azure|aws|huawei|qcloud|openstack|ucloud|zstack|google|ctyun"`
Provider []string `help:"Provider" choices:"OneCloud|VMware|Aliyun|Azure|Aws|Qcloud|Huawei|OpenStack|Ucloud|VolcEngine|ZStack|Google|Ctyun"`
Brand []string `help:"Brands" choices:"OneCloud|VMware|Aliyun|Azure|Aws|Qcloud|Huawei|OpenStack|Ucloud|VolcEngine|ZStack|Google|Ctyun"`
HostType []string `help:"Host types" choices:"hypervisor|baremetal|esxi|xen|kubelet|hyperv|aliyun|azure|aws|huawei|qcloud|openstack|ucloud|zstack|google|ctyun|cnware"`
Provider []string `help:"Provider" choices:"OneCloud|VMware|Aliyun|Azure|Aws|Qcloud|Huawei|OpenStack|Ucloud|VolcEngine|ZStack|Google|Ctyun|CNWare"`
Brand []string `help:"Brands" choices:"OneCloud|VMware|Aliyun|Azure|Aws|Qcloud|Huawei|OpenStack|Ucloud|VolcEngine|ZStack|Google|Ctyun|CNWare"`
Project string `help:"show usage of specified project"`
ProjectDomain string `help:"show usage of specified domain"`
+1
View File
@@ -105,6 +105,7 @@ func init() {
"oraclecloud",
"sangfor",
"cephfs",
"cnware",
}
features = append(features, storageFeatures...)
+1 -1
View File
@@ -95,7 +95,7 @@ require (
k8s.io/cri-api v0.22.17
k8s.io/klog/v2 v2.20.0
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926020321-3e215c9cf597
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926060637-3dea34e8fa4e
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
+2 -2
View File
@@ -1411,8 +1411,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926020321-3e215c9cf597 h1:mcpY90is1NOvZJ0GuGvYau9KqFehXWbiVJag3k6VZaI=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926020321-3e215c9cf597/go.mod h1:R5iP/4nGCluuekoa30B5hM/49IfPpGHXwFK3yT7m6Vw=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926060637-3dea34e8fa4e h1:ZiXgmtdPInE7vSgYqU1/PeFikCKQahLew1EueuEoWog=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926060637-3dea34e8fa4e/go.mod h1:R5iP/4nGCluuekoa30B5hM/49IfPpGHXwFK3yT7m6Vw=
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 h1:msG4SiDSVU7CrXH06WuHlNEZXIooTcmNbfrIGHuIHBU=
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
+6 -1
View File
@@ -76,6 +76,7 @@ const (
CLOUD_PROVIDER_UIS = compute.CLOUD_PROVIDER_UIS
CLOUD_PROVIDER_CAS = compute.CLOUD_PROVIDER_CAS
CLOUD_PROVIDER_CLOUDFLARE = compute.CLOUD_PROVIDER_CLOUDFLARE
CLOUD_PROVIDER_CNWARE = compute.CLOUD_PROVIDER_CNWARE
CLOUD_PROVIDER_GENERICS3 = compute.CLOUD_PROVIDER_GENERICS3
CLOUD_PROVIDER_CEPH = compute.CLOUD_PROVIDER_CEPH
@@ -125,7 +126,7 @@ var (
CLOUD_PROVIDER_HCSO, CLOUD_PROVIDER_HCS, CLOUD_PROVIDER_HCSOP,
CLOUD_PROVIDER_INCLOUD_SPHERE, CLOUD_PROVIDER_PROXMOX, CLOUD_PROVIDER_REMOTEFILE,
CLOUD_PROVIDER_H3C, CLOUD_PROVIDER_SANGFOR, CLOUD_PROVIDER_ZSTACK, CLOUD_PROVIDER_UIS,
CLOUD_PROVIDER_ZETTAKIT, CLOUD_PROVIDER_CAS,
CLOUD_PROVIDER_ZETTAKIT, CLOUD_PROVIDER_CAS, CLOUD_PROVIDER_CNWARE,
}
PUBLIC_CLOUD_PROVIDERS = []string{
CLOUD_PROVIDER_ALIYUN,
@@ -184,6 +185,7 @@ var (
CLOUD_PROVIDER_UIS,
CLOUD_PROVIDER_CAS,
CLOUD_PROVIDER_CLOUDFLARE,
CLOUD_PROVIDER_CNWARE,
}
CLOUD_PROVIDER_HOST_TYPE_MAP = map[string][]string{
@@ -294,6 +296,9 @@ var (
CLOUD_PROVIDER_CAS: {
HOST_TYPE_CAS,
},
CLOUD_PROVIDER_CNWARE: {
HOST_TYPE_CNWARE,
},
}
)
+2
View File
@@ -223,6 +223,7 @@ const (
HYPERVISOR_ZETTAKIT = compute.HYPERVISOR_ZETTAKIT
HYPERVISOR_UIS = compute.HYPERVISOR_UIS
HYPERVISOR_CAS = compute.HYPERVISOR_CAS
HYPERVISOR_CNWARE = compute.HYPERVISOR_CNWARE
// HYPERVISOR_DEFAULT = HYPERVISOR_KVM
HYPERVISOR_DEFAULT = HYPERVISOR_KVM
@@ -305,6 +306,7 @@ var HYPERVISORS = []string{
HYPERVISOR_SANGFOR,
HYPERVISOR_ZETTAKIT,
HYPERVISOR_UIS,
HYPERVISOR_CNWARE,
}
const (
+2
View File
@@ -60,6 +60,7 @@ const (
HOST_TYPE_ZETTAKIT = compute.HOST_TYPE_ZETTAKIT
HOST_TYPE_UIS = compute.HOST_TYPE_UIS
HOST_TYPE_CAS = compute.HOST_TYPE_CAS
HOST_TYPE_CNWARE = compute.HOST_TYPE_CNWARE
HOST_TYPE_DEFAULT = HOST_TYPE_HYPERVISOR
@@ -165,6 +166,7 @@ var HOST_TYPES = []string{
HOST_TYPE_SANGFOR,
HOST_TYPE_ZETTAKIT,
HOST_TYPE_UIS,
HOST_TYPE_CNWARE,
}
var ALL_NIC_TYPES = []compute.TNicType{NIC_TYPE_IPMI, NIC_TYPE_ADMIN, NIC_TYPE_NORMAL}
+8
View File
@@ -143,6 +143,14 @@ const (
// zettakit
STORAGE_ZETTAKIT_NORMAL = compute.STORAGE_ZETTAKIT_NORMAL
// cnware storage type
STORAGE_CNWARE_FCSAN = compute.STORAGE_CNWARE_FC_SAN
STORAGE_CNWARE_IPSAN = compute.STORAGE_CNWARE_IP_SAN
STORAGE_CNWARE_NAS = compute.STORAGE_CNWARE_NAS
STORAGE_CNWARE_CEPH = compute.STORAGE_CNWARE_CEPH
STORAGE_CNWARE_LOCAL = compute.STORAGE_CNWARE_LOCAL
STORAGE_CNWARE_NVME = compute.STORAGE_CNWARE_NVME
)
const (
+1
View File
@@ -40,4 +40,5 @@ const (
VOLC_ENGINE = "volcengine"
BAIDU = "baidu"
SANGFOR = "sangfor"
CNWARE = "cnware"
)
+35
View File
@@ -0,0 +1,35 @@
// 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 providerdriver
import (
api "yunion.io/x/onecloud/pkg/apis/compute"
)
type CNwareCollect struct {
SCollectByResourceIdDriver
}
func (self *CNwareCollect) GetProvider() string {
return api.CLOUD_PROVIDER_CNWARE
}
func (self *CNwareCollect) IsSupportMetrics() bool {
return true
}
func init() {
Register(&CNwareCollect{})
}
+341
View File
@@ -0,0 +1,341 @@
// 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"
"sort"
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/rbacscope"
"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/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/compute/options"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
)
type SCNwareGuestDriver struct {
SManagedVirtualizedGuestDriver
}
func init() {
driver := SCNwareGuestDriver{}
models.RegisterGuestDriver(&driver)
}
func (self *SCNwareGuestDriver) DoScheduleCPUFilter() bool { return true }
func (self *SCNwareGuestDriver) DoScheduleMemoryFilter() bool { return true }
func (self *SCNwareGuestDriver) DoScheduleSKUFilter() bool { return false }
func (self *SCNwareGuestDriver) DoScheduleStorageFilter() bool { return true }
func (self *SCNwareGuestDriver) GetHypervisor() string {
return api.HYPERVISOR_CNWARE
}
func (self *SCNwareGuestDriver) GetProvider() string {
return api.CLOUD_PROVIDER_CNWARE
}
func (self *SCNwareGuestDriver) GetComputeQuotaKeys(scope rbacscope.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_CNWARE
keys.Brand = brand
keys.Hypervisor = api.HYPERVISOR_CNWARE
return keys
}
func (self *SCNwareGuestDriver) GetDefaultSysDiskBackend() string {
return api.STORAGE_CNWARE_LOCAL
}
func (self *SCNwareGuestDriver) GetMinimalSysDiskSizeGb() int {
return 10
}
func (self *SCNwareGuestDriver) GetStorageTypes() []string {
return []string{
api.STORAGE_CNWARE_FCSAN,
api.STORAGE_CNWARE_IPSAN,
api.STORAGE_CNWARE_NAS,
api.STORAGE_CNWARE_CEPH,
api.STORAGE_CNWARE_LOCAL,
api.STORAGE_CNWARE_NVME,
}
}
func (self *SCNwareGuestDriver) GetMaxSecurityGroupCount() int {
return 0
}
func (self *SCNwareGuestDriver) ChooseHostStorage(host *models.SHost, guest *models.SGuest, diskConfig *api.DiskConfig, storageIds []string) (*models.SStorage, error) {
switch {
case !options.Options.LockStorageFromCachedimage:
return self.SVirtualizedGuestDriver.ChooseHostStorage(host, guest, diskConfig, storageIds)
case len(diskConfig.ImageId) > 0:
var (
image *cloudprovider.SImage
err error
)
obj, err := models.CachedimageManager.FetchById(diskConfig.ImageId)
if err != nil {
return nil, errors.Wrapf(err, "unable to fetch cachedimage %s", diskConfig.ImageId)
}
cachedimage := obj.(*models.SCachedimage)
if len(cachedimage.ExternalId) > 0 || cloudprovider.TImageType(cachedimage.ImageType) != cloudprovider.ImageTypeSystem {
return self.SVirtualizedGuestDriver.ChooseHostStorage(host, guest, diskConfig, storageIds)
}
storages, err := cachedimage.GetStorages()
if err != nil {
return nil, errors.Wrapf(err, "unable to GetStorages of cachedimage %s", diskConfig.ImageId)
}
if len(storages) == 0 {
log.Warningf("there no storage associated with cachedimage %q", image.Id)
return self.SVirtualizedGuestDriver.ChooseHostStorage(host, guest, diskConfig, storageIds)
}
if len(storages) > 1 {
log.Warningf("there are multiple storageCache associated with caheimage %q", image.Id)
}
wantStorageIds := make([]string, len(storages))
for i := range wantStorageIds {
wantStorageIds[i] = storages[i].GetId()
}
for i := range wantStorageIds {
if utils.IsInStringArray(wantStorageIds[i], storageIds) {
log.Infof("use storage %q in where cachedimage %q", wantStorageIds[i], image.Id)
return &storages[i], nil
}
}
return self.SVirtualizedGuestDriver.ChooseHostStorage(host, guest, diskConfig, storageIds)
default:
ispId := guest.GetMetadata(context.Background(), "__base_instance_snapshot_id", nil)
if len(ispId) == 0 {
return self.SVirtualizedGuestDriver.ChooseHostStorage(host, guest, diskConfig, storageIds)
}
obj, err := models.InstanceSnapshotManager.FetchById(ispId)
if err != nil {
return nil, errors.Wrapf(err, "unable to fetch InstanceSnapshot %q", ispId)
}
isp := obj.(*models.SInstanceSnapshot)
ispGuest, err := isp.GetGuest()
if err != nil {
return nil, errors.Wrapf(err, "unable to fetch Guest of InstanceSnapshot %q", ispId)
}
storages, err := ispGuest.GetStorages()
if err != nil {
return nil, errors.Wrapf(err, "GetStorages")
}
if len(storages) == 0 {
return self.SVirtualizedGuestDriver.ChooseHostStorage(host, guest, diskConfig, storageIds)
}
if utils.IsInStringArray(storages[0].GetId(), storageIds) {
return &storages[0], nil
}
return self.SVirtualizedGuestDriver.ChooseHostStorage(host, guest, diskConfig, storageIds)
}
}
func (self *SCNwareGuestDriver) GetDetachDiskStatus() ([]string, error) {
return []string{api.VM_READY, api.VM_RUNNING}, nil
}
func (self *SCNwareGuestDriver) GetAttachDiskStatus() ([]string, error) {
return []string{api.VM_READY, api.VM_RUNNING}, nil
}
func (self *SCNwareGuestDriver) GetRebuildRootStatus() ([]string, error) {
return []string{api.VM_READY}, nil
}
func (self *SCNwareGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
return []string{api.VM_READY}, nil
}
func (self *SCNwareGuestDriver) GetDeployStatus() ([]string, error) {
return []string{api.VM_RUNNING}, nil
}
func (self *SCNwareGuestDriver) IsNeedRestartForResetLoginInfo() bool {
return false
}
func (self *SCNwareGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
if !utils.IsInStringArray(guest.Status, []string{api.VM_READY, api.VM_RUNNING}) {
return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
}
return nil
}
func (self *SCNwareGuestDriver) ValidateCreateEip(ctx context.Context, userCred mcclient.TokenCredential, input api.ServerCreateEipInput) error {
return httperrors.NewInputParameterError("%s not support create eip, it only support bind eip", self.GetHypervisor())
}
func (self *SCNwareGuestDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, data *api.ServerCreateInput) (*api.ServerCreateInput, error) {
if data.CpuSockets > data.VcpuCount {
return nil, httperrors.NewInputParameterError("The number of cpu sockets cannot be greater than the number of cpus")
}
// check disk config
if len(data.Disks) == 0 {
return data, nil
}
rootDisk := data.Disks[0]
if len(rootDisk.ImageId) == 0 {
return data, nil
}
image, err := models.CachedimageManager.GetImageInfo(ctx, userCred, rootDisk.ImageId, false)
if err != nil {
return nil, errors.Wrapf(err, "unable to GetImageInfo of image %q", rootDisk.ImageId)
}
if len(image.SubImages) <= 1 {
return data, nil
}
sort.Slice(image.SubImages, func(i, j int) bool {
return image.SubImages[i].Index < image.SubImages[j].Index
})
newDataDisks := make([]*api.DiskConfig, 0, len(image.SubImages)+len(data.Disks)-1)
for i, subImage := range image.SubImages {
nDataDisk := *rootDisk
nDataDisk.SizeMb = subImage.MinDiskMB
nDataDisk.Format = "vmdk"
nDataDisk.Index = i
if i > 0 {
nDataDisk.ImageId = ""
}
newDataDisks = append(newDataDisks, &nDataDisk)
}
for i := 1; i < len(data.Disks); i++ {
data.Disks[i].Index += len(image.SubImages) - 1
newDataDisks = append(newDataDisks, data.Disks[i])
}
data.Disks = newDataDisks
return data, nil
}
func (self *SCNwareGuestDriver) GetGuestInitialStateAfterCreate() string {
return api.VM_RUNNING
}
func (self *SCNwareGuestDriver) GetGuestInitialStateAfterRebuild() string {
return api.VM_READY
}
func (self *SCNwareGuestDriver) IsNeedInjectPasswordByCloudInit() bool {
return true
}
func (self *SCNwareGuestDriver) GetUserDataType() string {
return cloudprovider.CLOUD_SHELL
}
func (self *SCNwareGuestDriver) IsWindowsUserDataTypeNeedEncode() bool {
return true
}
func (self *SCNwareGuestDriver) 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,
},
},
}
}
func (self *SCNwareGuestDriver) AllowReconfigGuest() bool {
return true
}
func (self *SCNwareGuestDriver) IsSupportEip() bool {
return false
}
func (self *SCNwareGuestDriver) RequestSyncSecgroupsOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
return nil // do nothing, not support securitygroup
}
func (self *SCNwareGuestDriver) DoGuestCreateDisksTask(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
return nil
}
func (self *SCNwareGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
return []string{api.VM_READY}, nil
}
func (self *SCNwareGuestDriver) ValidateGuestChangeConfigInput(ctx context.Context, guest *models.SGuest, input api.ServerChangeConfigInput) (*api.ServerChangeConfigSettings, error) {
confs, err := self.SBaseGuestDriver.ValidateGuestChangeConfigInput(ctx, guest, input)
if err != nil {
return nil, errors.Wrap(err, "SBaseGuestDriver.ValidateGuestChangeConfigInput")
}
sku, err := models.ServerSkuManager.FetchSkuByNameAndProvider(input.Sku, "OneCloud", true)
if err != nil {
return nil, errors.Wrap(err, "FetchSkuByNameAndProvider")
}
confs.InstanceTypeFamily = ""
confs.InstanceType = ""
confs.VcpuCount = sku.CpuCoreCount
confs.VmemSize = sku.MemorySizeMB
confs.CpuSockets = 1
log.Infof("ValidateGuestChangeConfigInput: %+v", confs)
if input.CpuSockets != nil && *input.CpuSockets > 0 {
confs.CpuSockets = *input.CpuSockets
}
defaultStorageId := ""
if root, _ := guest.GetSystemDisk(); root != nil {
defaultStorageId = root.StorageId
}
storages, err := guest.GetStorages()
if err != nil {
return nil, errors.Wrapf(err, "GetStorages")
}
storageMap := map[string]string{}
for _, storage := range storages {
storageMap[storage.StorageType] = storage.Id
if len(defaultStorageId) == 0 {
defaultStorageId = storage.Id
}
}
for i := range confs.Create {
confs.Create[i].Format = "vmdk"
if len(confs.Create[i].Storage) == 0 {
// 若不指定存储类型,默认和系统盘一致
if len(confs.Create[i].Backend) == 0 {
confs.Create[i].Storage = defaultStorageId
} else if storageId, ok := storageMap[confs.Create[i].Backend]; ok { // 否则和已有磁盘存储保持一致
confs.Create[i].Storage = storageId
}
}
}
return confs, nil
}
+58
View File
@@ -0,0 +1,58 @@
// 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"
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 SCNwareHostDriver struct {
SManagedVirtualizationHostDriver
}
func init() {
driver := SCNwareHostDriver{}
models.RegisterHostDriver(&driver)
}
func (self *SCNwareHostDriver) GetHostType() string {
return api.HOST_TYPE_CNWARE
}
func (self *SCNwareHostDriver) GetHypervisor() string {
return api.HYPERVISOR_CNWARE
}
func (self *SCNwareHostDriver) GetProvider() string {
return api.CLOUD_PROVIDER_CNWARE
}
func (self *SCNwareHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
return nil
}
func (self *SCNwareHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
for _, guest := range guests {
if guest.Status != api.VM_READY {
return nil, httperrors.NewBadRequestError("CNware reset disk operation requried guest status is ready")
}
}
return input, nil
}
+1
View File
@@ -5472,6 +5472,7 @@ func (manager *SGuestManager) StartHostGuestsMigrateTask(
var supportInstanceSnapshotHypervisors = []string{
api.HYPERVISOR_KVM,
api.HYPERVISOR_ESXI,
api.HYPERVISOR_CNWARE,
}
func (self *SGuest) validateCreateInstanceSnapshot(
+2
View File
@@ -164,6 +164,7 @@ var HypervisorBrandMap = map[string]string{
computeapis.HYPERVISOR_ZSTACK: computeapis.CLOUD_PROVIDER_ZSTACK,
computeapis.HYPERVISOR_GOOGLE: computeapis.CLOUD_PROVIDER_GOOGLE,
computeapis.HYPERVISOR_CTYUN: computeapis.CLOUD_PROVIDER_CTYUN,
computeapis.HYPERVISOR_CNWARE: computeapis.CLOUD_PROVIDER_CNWARE,
}
var BrandHypervisorMap = map[string]string{
@@ -179,6 +180,7 @@ var BrandHypervisorMap = map[string]string{
computeapis.CLOUD_PROVIDER_ZSTACK: computeapis.HYPERVISOR_ZSTACK,
computeapis.CLOUD_PROVIDER_GOOGLE: computeapis.HYPERVISOR_GOOGLE,
computeapis.CLOUD_PROVIDER_CTYUN: computeapis.HYPERVISOR_CTYUN,
computeapis.CLOUD_PROVIDER_CNWARE: computeapis.HYPERVISOR_CNWARE,
}
func Hypervisor2Brand(hypervisor string) string {
+63
View File
@@ -0,0 +1,63 @@
// 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 regiondrivers
import (
"context"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/compute/models"
"yunion.io/x/onecloud/pkg/mcclient"
)
type SCNwareRegionDriver struct {
SManagedVirtualizationRegionDriver
}
func init() {
driver := SCNwareRegionDriver{}
models.RegisterRegionDriver(&driver)
}
func (self *SCNwareRegionDriver) GetProvider() string {
return api.CLOUD_PROVIDER_CNWARE
}
func (self *SCNwareRegionDriver) RequestCreateNetwork(ctx context.Context, userCred mcclient.TokenCredential, net *models.SNetwork, task taskman.ITask) error {
return net.SetStatus(ctx, userCred, api.NETWORK_STATUS_AVAILABLE, "")
}
func (self *SCNwareRegionDriver) RequestCreateInstanceSnapshot(ctx context.Context, guest *models.SGuest, isp *models.SInstanceSnapshot, task taskman.ITask, params *jsonutils.JSONDict) error {
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
ivm, err := guest.GetIVM(ctx)
if err != nil {
return nil, errors.Wrap(err, "unable to GetIVM")
}
_, err = ivm.CreateInstanceSnapshot(ctx, isp.GetName(), isp.Description)
if err != nil {
return nil, errors.Wrap(err, "unable to CreateInstanceSnapshot")
}
_, err = db.Update(isp, func() error {
isp.SetExternalId(isp.Name)
return nil
})
return nil, err
})
return nil
}
+1 -1
View File
@@ -245,7 +245,7 @@ type BaseListOptions struct {
Manager []string `help:"List objects belonging to the cloud provider" json:"manager,omitempty"`
Account string `help:"List objects belonging to the cloud account" json:"account,omitempty"`
Provider []string `help:"List objects from the provider" choices:"OneCloud|VMware|Aliyun|Apsara|Qcloud|Azure|Aws|Huawei|OpenStack|Ucloud|VolcEngine|ZStack|Google|Ctyun|Cloudpods|Nutanix|BingoCloud|IncloudSphere|JDcloud|Proxmox|Ceph|CephFS|Ecloud|HCSO|HCS|HCSOP|H3C|S3|RemoteFile|Ksyun|Baidu|QingCloud|OracleCloud|SangFor|ZettaKit|UIS" json:"provider,omitempty"`
Provider []string `help:"List objects from the provider" choices:"OneCloud|VMware|Aliyun|Apsara|Qcloud|Azure|Aws|Huawei|OpenStack|Ucloud|VolcEngine|ZStack|Google|Ctyun|Cloudpods|Nutanix|BingoCloud|IncloudSphere|JDcloud|Proxmox|Ceph|CephFS|Ecloud|HCSO|HCS|HCSOP|H3C|S3|RemoteFile|Ksyun|Baidu|QingCloud|OracleCloud|SangFor|ZettaKit|UIS|CNWare" json:"provider,omitempty"`
Brand []string `help:"List objects belonging to a special brand"`
CloudEnv string `help:"Cloud environment" choices:"public|private|onpremise|private_or_onpremise" json:"cloud_env,omitempty"`
PublicCloud *bool `help:"List objects belonging to public cloud" json:"public_cloud"`
@@ -1570,3 +1570,32 @@ func (opts *SCephFSCloudAccountCreateOptions) Params() (jsonutils.JSONObject, er
params.(*jsonutils.JSONDict).Add(jsonutils.NewString("CephFS"), "provider")
return params, nil
}
type SCNwareCloudAccountCreateOptions struct {
SCloudAccountCreateBaseOptions
SUserPasswordCredential
AuthURL string `help:"CNware auth_url" positional:"true" json:"auth_url"`
}
func (opts *SCNwareCloudAccountCreateOptions) Params() (jsonutils.JSONObject, error) {
params := jsonutils.Marshal(opts)
params.(*jsonutils.JSONDict).Add(jsonutils.NewString("CNware"), "provider")
return params, nil
}
type SCNwareCloudAccountUpdateCredentialOptions struct {
SCloudAccountIdOptions
SUserPasswordCredential
}
func (opts *SCNwareCloudAccountUpdateCredentialOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(opts), nil
}
type SCNwareCloudAccountUpdateOptions struct {
SCloudAccountUpdateBaseOptions
}
func (opts *SCNwareCloudAccountUpdateOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(opts), nil
}
+1 -1
View File
@@ -45,7 +45,7 @@ type ServerListOptions struct {
Gpu *bool `help:"Show gpu servers"`
Secgroup string `help:"Secgroup ID or Name"`
AdminSecgroup string `help:"AdminSecgroup ID or Name"`
Hypervisor string `help:"Show server of hypervisor" choices:"kvm|esxi|pod|baremetal|aliyun|azure|aws|huawei|ucloud|volcengine|zstack|openstack|google|ctyun|incloudsphere|nutanix|bingocloud|cloudpods|ecloud|jdcloud|remotefile|h3c|hcs|hcso|hcsop|proxmox|ksyun|baidu|cucloud|qingcloud|sangfor|zettakit|uis"`
Hypervisor string `help:"Show server of hypervisor" choices:"kvm|esxi|pod|baremetal|aliyun|azure|aws|huawei|ucloud|volcengine|zstack|openstack|google|ctyun|incloudsphere|nutanix|bingocloud|cloudpods|ecloud|jdcloud|remotefile|h3c|hcs|hcso|hcsop|proxmox|ksyun|baidu|cucloud|qingcloud|sangfor|zettakit|uis|cnware"`
Region string `help:"Show servers in cloudregion"`
WithEip *bool `help:"Show Servers with EIP"`
WithoutEip *bool `help:"Show Servers without EIP"`
+1 -1
View File
@@ -322,7 +322,7 @@ func handleServerRemoteConsole(ctx context.Context, w http.ResponseWriter, r *ht
session.VMRC, session.ZSTACK, session.CTYUN,
session.HUAWEI, session.HCS, session.APSARA,
session.JDCLOUD, session.CLOUDPODS, session.PROXMOX,
session.VOLCENGINE, session.BAIDU:
session.VOLCENGINE, session.BAIDU, session.CNWARE:
responsePublicCloudConsole(ctx, info, w)
case session.VNC:
handleDataSession(ctx, info, w, "no-vnc", url.Values{"password": {info.GetPassword()}}, true)
+2 -1
View File
@@ -52,6 +52,7 @@ const (
VOLCENGINE = api.VOLC_ENGINE
BAIDU = api.BAIDU
SANGFOR = api.SANGFOR
CNWARE = api.CNWARE
)
type RemoteConsoleInfo struct {
@@ -130,7 +131,7 @@ func (info *RemoteConsoleInfo) GetConnectParams() (string, error) {
return info.getQcloudURL()
case CLOUDPODS:
return info.getCloudpodsURL()
case OPENSTACK, VMRC, ZSTACK, CTYUN, HUAWEI, HCS, JDCLOUD, PROXMOX, SANGFOR, BAIDU:
case OPENSTACK, VMRC, ZSTACK, CTYUN, HUAWEI, HCS, JDCLOUD, PROXMOX, SANGFOR, BAIDU, CNWARE:
return info.Url, nil
case VOLCENGINE:
return info.getVolcEngineURL()
+1 -1
View File
@@ -1875,7 +1875,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926020321-3e215c9cf597
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926060637-3dea34e8fa4e
## explicit; go 1.24
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
+1
View File
@@ -50,6 +50,7 @@ const (
CLOUD_PROVIDER_ZETTAKIT = "ZettaKit"
CLOUD_PROVIDER_UIS = "UIS"
CLOUD_PROVIDER_CAS = "CAS"
CLOUD_PROVIDER_CNWARE = "CNware"
CLOUD_PROVIDER_GENERICS3 = "S3"
CLOUD_PROVIDER_CEPH = "Ceph"
+1
View File
@@ -83,6 +83,7 @@ const (
HYPERVISOR_ZETTAKIT = "zettakit"
HYPERVISOR_UIS = "uis"
HYPERVISOR_CAS = "cas"
HYPERVISOR_CNWARE = "cnware"
)
const (
+1
View File
@@ -52,6 +52,7 @@ const (
HOST_TYPE_ZETTAKIT = "zettakit"
HOST_TYPE_UIS = "uis"
HOST_TYPE_CAS = "cas"
HOST_TYPE_CNWARE = "cnware"
// # possible status
HOST_ONLINE = "online"
+8
View File
@@ -132,6 +132,14 @@ const (
STORAGE_BAIDU_ENHANCED_SSD_PL2 = "enhanced_ssd_pl2" // 增强型SSD_PL2
STORAGE_BAIDU_ENHANCED_SSD_PL3 = "enhanced_ssd_pl3" // 增强型SSD_PL2
// cnware storage type
STORAGE_CNWARE_FC_SAN = "fc-san"
STORAGE_CNWARE_IP_SAN = "ip-scan"
STORAGE_CNWARE_NAS = "nas"
STORAGE_CNWARE_CEPH = "ceph"
STORAGE_CNWARE_LOCAL = "local"
STORAGE_CNWARE_NVME = "nvme"
// ZettaKit
STORAGE_ZETTAKIT_NORMAL = "normal"
)