diff --git a/cmd/climc/shell/compute/cloudaccounts.go b/cmd/climc/shell/compute/cloudaccounts.go index a9e0a0c1fa..3e288b3d9d 100644 --- a/cmd/climc/shell/compute/cloudaccounts.go +++ b/cmd/climc/shell/compute/cloudaccounts.go @@ -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{}) diff --git a/cmd/climc/shell/compute/usages.go b/cmd/climc/shell/compute/usages.go index b2f5913567..c7351832b6 100644 --- a/cmd/climc/shell/compute/usages.go +++ b/cmd/climc/shell/compute/usages.go @@ -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"` diff --git a/cmd/climc/shell/misc/feature.go b/cmd/climc/shell/misc/feature.go index f235614995..390de68c1a 100644 --- a/cmd/climc/shell/misc/feature.go +++ b/cmd/climc/shell/misc/feature.go @@ -105,6 +105,7 @@ func init() { "oraclecloud", "sangfor", "cephfs", + "cnware", } features = append(features, storageFeatures...) diff --git a/go.mod b/go.mod index 2aee937789..ba0ac2f91a 100644 --- a/go.mod +++ b/go.mod @@ -96,7 +96,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.20250926020310-3d004271191d + yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926060627-f3514bd9ae0e 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 diff --git a/go.sum b/go.sum index 8b37cca876..1715501da9 100644 --- a/go.sum +++ b/go.sum @@ -1426,8 +1426,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.20250926020310-3d004271191d h1:ZAYOZuFaAeGFz+LYE2FMXu4fwx/qqfuTww3eJRK/ZzY= -yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926020310-3d004271191d/go.mod h1:R5iP/4nGCluuekoa30B5hM/49IfPpGHXwFK3yT7m6Vw= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926060627-f3514bd9ae0e h1:i2PgAwxPsZROib7oSmrJ0ZshRZE+2V/hOtIIXPyNYf4= +yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926060627-f3514bd9ae0e/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= diff --git a/pkg/apis/compute/cloudaccount_const.go b/pkg/apis/compute/cloudaccount_const.go index 8dcbfb6859..dba82ee084 100644 --- a/pkg/apis/compute/cloudaccount_const.go +++ b/pkg/apis/compute/cloudaccount_const.go @@ -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, + }, } ) diff --git a/pkg/apis/compute/guest_const.go b/pkg/apis/compute/guest_const.go index d077c22bf4..81f4102848 100644 --- a/pkg/apis/compute/guest_const.go +++ b/pkg/apis/compute/guest_const.go @@ -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 ( diff --git a/pkg/apis/compute/host_const.go b/pkg/apis/compute/host_const.go index 61e59171ce..548ea148fb 100644 --- a/pkg/apis/compute/host_const.go +++ b/pkg/apis/compute/host_const.go @@ -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} diff --git a/pkg/apis/compute/storage_const.go b/pkg/apis/compute/storage_const.go index 64463307a5..fa2205b19e 100644 --- a/pkg/apis/compute/storage_const.go +++ b/pkg/apis/compute/storage_const.go @@ -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 ( diff --git a/pkg/apis/webconsole/consts.go b/pkg/apis/webconsole/consts.go index 49d311376f..4f9c7285b2 100644 --- a/pkg/apis/webconsole/consts.go +++ b/pkg/apis/webconsole/consts.go @@ -40,4 +40,5 @@ const ( VOLC_ENGINE = "volcengine" BAIDU = "baidu" SANGFOR = "sangfor" + CNWARE = "cnware" ) diff --git a/pkg/cloudmon/providerdriver/cnware.go b/pkg/cloudmon/providerdriver/cnware.go new file mode 100644 index 0000000000..462f5ae371 --- /dev/null +++ b/pkg/cloudmon/providerdriver/cnware.go @@ -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{}) +} diff --git a/pkg/compute/guestdrivers/cnware.go b/pkg/compute/guestdrivers/cnware.go new file mode 100644 index 0000000000..d61e80a025 --- /dev/null +++ b/pkg/compute/guestdrivers/cnware.go @@ -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 +} diff --git a/pkg/compute/hostdrivers/cnware.go b/pkg/compute/hostdrivers/cnware.go new file mode 100644 index 0000000000..abc068a8ba --- /dev/null +++ b/pkg/compute/hostdrivers/cnware.go @@ -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 +} diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index df55000b68..133b7b8ffb 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -5472,6 +5472,7 @@ func (manager *SGuestManager) StartHostGuestsMigrateTask( var supportInstanceSnapshotHypervisors = []string{ api.HYPERVISOR_KVM, api.HYPERVISOR_ESXI, + api.HYPERVISOR_CNWARE, } func (self *SGuest) validateCreateInstanceSnapshot( diff --git a/pkg/compute/models/guest_template.go b/pkg/compute/models/guest_template.go index f93ca64541..3c7cdec61b 100644 --- a/pkg/compute/models/guest_template.go +++ b/pkg/compute/models/guest_template.go @@ -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 { diff --git a/pkg/compute/regiondrivers/cnware.go b/pkg/compute/regiondrivers/cnware.go new file mode 100644 index 0000000000..b62e5378f5 --- /dev/null +++ b/pkg/compute/regiondrivers/cnware.go @@ -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 +} diff --git a/pkg/mcclient/options/base.go b/pkg/mcclient/options/base.go index ed5e739e86..578f581eaa 100644 --- a/pkg/mcclient/options/base.go +++ b/pkg/mcclient/options/base.go @@ -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"` diff --git a/pkg/mcclient/options/compute/cloudaccounts.go b/pkg/mcclient/options/compute/cloudaccounts.go index 833dea0595..c8ad8103fa 100644 --- a/pkg/mcclient/options/compute/cloudaccounts.go +++ b/pkg/mcclient/options/compute/cloudaccounts.go @@ -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 +} diff --git a/pkg/mcclient/options/compute/servers.go b/pkg/mcclient/options/compute/servers.go index 165fb47938..66735f4dee 100644 --- a/pkg/mcclient/options/compute/servers.go +++ b/pkg/mcclient/options/compute/servers.go @@ -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"` diff --git a/pkg/webconsole/service/handlers.go b/pkg/webconsole/service/handlers.go index 2a2350102d..d68c066247 100644 --- a/pkg/webconsole/service/handlers.go +++ b/pkg/webconsole/service/handlers.go @@ -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) diff --git a/pkg/webconsole/session/remote_console.go b/pkg/webconsole/session/remote_console.go index 2776fa3549..12974cd3b5 100644 --- a/pkg/webconsole/session/remote_console.go +++ b/pkg/webconsole/session/remote_console.go @@ -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() diff --git a/vendor/modules.txt b/vendor/modules.txt index 2c52668d01..f4916c4d09 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1900,7 +1900,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.20250926020310-3d004271191d +# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250926060627-f3514bd9ae0e ## explicit; go 1.24 yunion.io/x/cloudmux/pkg/apis yunion.io/x/cloudmux/pkg/apis/billing diff --git a/vendor/yunion.io/x/cloudmux/pkg/apis/compute/cloudaccount_const.go b/vendor/yunion.io/x/cloudmux/pkg/apis/compute/cloudaccount_const.go index 86b8cc142b..66d1f75835 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/apis/compute/cloudaccount_const.go +++ b/vendor/yunion.io/x/cloudmux/pkg/apis/compute/cloudaccount_const.go @@ -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" diff --git a/vendor/yunion.io/x/cloudmux/pkg/apis/compute/guest_const.go b/vendor/yunion.io/x/cloudmux/pkg/apis/compute/guest_const.go index e4adc68241..2a0ae715b7 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/apis/compute/guest_const.go +++ b/vendor/yunion.io/x/cloudmux/pkg/apis/compute/guest_const.go @@ -83,6 +83,7 @@ const ( HYPERVISOR_ZETTAKIT = "zettakit" HYPERVISOR_UIS = "uis" HYPERVISOR_CAS = "cas" + HYPERVISOR_CNWARE = "cnware" ) const ( diff --git a/vendor/yunion.io/x/cloudmux/pkg/apis/compute/host_const.go b/vendor/yunion.io/x/cloudmux/pkg/apis/compute/host_const.go index c0753d2fa0..a2094f9e42 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/apis/compute/host_const.go +++ b/vendor/yunion.io/x/cloudmux/pkg/apis/compute/host_const.go @@ -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" diff --git a/vendor/yunion.io/x/cloudmux/pkg/apis/compute/storage_const.go b/vendor/yunion.io/x/cloudmux/pkg/apis/compute/storage_const.go index 864886f462..8f156f806b 100644 --- a/vendor/yunion.io/x/cloudmux/pkg/apis/compute/storage_const.go +++ b/vendor/yunion.io/x/cloudmux/pkg/apis/compute/storage_const.go @@ -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" )