mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-05-06 21:52:54 +08:00
fix(region): add cas (#21889)
This commit is contained in:
2
go.mod
2
go.mod
@@ -93,7 +93,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.20241221173250-5f4ed89000f5
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241224075750-4d47750bdc09
|
||||
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256
|
||||
yunion.io/x/jsonutils v1.0.1-0.20240930100528-1671a2d0d22f
|
||||
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1376,8 +1376,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.20241221173250-5f4ed89000f5 h1:Nrrybroza4SiDpHUVlShsrSUhwg9R74AhK2W2jNno8w=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241221173250-5f4ed89000f5/go.mod h1:KQ/jWx7bZlmjCE711KEWuvHW/dzpdr/UTlBjjutkj0Y=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241224075750-4d47750bdc09 h1:j5zw172RWdBimE8Z3rAOjTHjmQkHqlx+DZcMwITgTQY=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241224075750-4d47750bdc09/go.mod h1:KQ/jWx7bZlmjCE711KEWuvHW/dzpdr/UTlBjjutkj0Y=
|
||||
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256 h1:kLKQ6zbgPDQflRwoHFAjxNChcbhXIFgsUVLkJwiXu/8=
|
||||
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -74,6 +74,7 @@ const (
|
||||
CLOUD_PROVIDER_SANGFOR = compute.CLOUD_PROVIDER_SANGFOR
|
||||
CLOUD_PROVIDER_ZETTAKIT = compute.CLOUD_PROVIDER_ZETTAKIT
|
||||
CLOUD_PROVIDER_UIS = compute.CLOUD_PROVIDER_UIS
|
||||
CLOUD_PROVIDER_CAS = compute.CLOUD_PROVIDER_CAS
|
||||
|
||||
CLOUD_PROVIDER_GENERICS3 = compute.CLOUD_PROVIDER_GENERICS3
|
||||
CLOUD_PROVIDER_CEPH = compute.CLOUD_PROVIDER_CEPH
|
||||
@@ -123,7 +124,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_ZETTAKIT, CLOUD_PROVIDER_CAS,
|
||||
}
|
||||
PUBLIC_CLOUD_PROVIDERS = []string{
|
||||
CLOUD_PROVIDER_ALIYUN,
|
||||
@@ -179,6 +180,7 @@ var (
|
||||
CLOUD_PROVIDER_SANGFOR,
|
||||
CLOUD_PROVIDER_ZETTAKIT,
|
||||
CLOUD_PROVIDER_UIS,
|
||||
CLOUD_PROVIDER_CAS,
|
||||
}
|
||||
|
||||
CLOUD_PROVIDER_HOST_TYPE_MAP = map[string][]string{
|
||||
@@ -286,6 +288,9 @@ var (
|
||||
CLOUD_PROVIDER_UIS: {
|
||||
HOST_TYPE_UIS,
|
||||
},
|
||||
CLOUD_PROVIDER_CAS: {
|
||||
HOST_TYPE_CAS,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -222,6 +222,7 @@ const (
|
||||
HYPERVISOR_SANGFOR = compute.HYPERVISOR_SANGFOR
|
||||
HYPERVISOR_ZETTAKIT = compute.HYPERVISOR_ZETTAKIT
|
||||
HYPERVISOR_UIS = compute.HYPERVISOR_UIS
|
||||
HYPERVISOR_CAS = compute.HYPERVISOR_CAS
|
||||
|
||||
// HYPERVISOR_DEFAULT = HYPERVISOR_KVM
|
||||
HYPERVISOR_DEFAULT = HYPERVISOR_KVM
|
||||
|
||||
@@ -59,6 +59,7 @@ const (
|
||||
HOST_TYPE_SANGFOR = compute.HOST_TYPE_SANGFOR
|
||||
HOST_TYPE_ZETTAKIT = compute.HOST_TYPE_ZETTAKIT
|
||||
HOST_TYPE_UIS = compute.HOST_TYPE_UIS
|
||||
HOST_TYPE_CAS = compute.HOST_TYPE_CAS
|
||||
|
||||
HOST_TYPE_DEFAULT = HOST_TYPE_HYPERVISOR
|
||||
|
||||
|
||||
35
pkg/cloudmon/providerdriver/cas.go
Normal file
35
pkg/cloudmon/providerdriver/cas.go
Normal 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 CasCollect struct {
|
||||
SCollectByResourceIdDriver
|
||||
}
|
||||
|
||||
func (self *CasCollect) GetProvider() string {
|
||||
return api.CLOUD_PROVIDER_CAS
|
||||
}
|
||||
|
||||
func (self *CasCollect) IsSupportMetrics() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(&CasCollect{})
|
||||
}
|
||||
228
pkg/compute/guestdrivers/cas.go
Normal file
228
pkg/compute/guestdrivers/cas.go
Normal file
@@ -0,0 +1,228 @@
|
||||
// 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"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/billing"
|
||||
"yunion.io/x/pkg/util/cloudinit"
|
||||
"yunion.io/x/pkg/util/rbacscope"
|
||||
"yunion.io/x/pkg/utils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"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/mcclient"
|
||||
)
|
||||
|
||||
type SCasGuestDriver struct {
|
||||
SManagedVirtualizedGuestDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SCasGuestDriver{}
|
||||
models.RegisterGuestDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_CAS
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetProvider() string {
|
||||
return api.CLOUD_PROVIDER_CAS
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) DoScheduleSKUFilter() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) DoScheduleStorageFilter() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) 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_CAS
|
||||
keys.Brand = api.CLOUD_PROVIDER_CAS
|
||||
keys.Hypervisor = api.HYPERVISOR_CAS
|
||||
return keys
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetDefaultSysDiskBackend() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetMinimalSysDiskSizeGb() int {
|
||||
return 20
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetStorageTypes() []string {
|
||||
storages, _ := models.StorageManager.GetStorageTypesByProvider(self.GetProvider())
|
||||
return storages
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) ChooseHostStorage(host *models.SHost, guest *models.SGuest, diskConfig *api.DiskConfig, storageIds []string) (*models.SStorage, error) {
|
||||
return chooseHostStorage(self, host, diskConfig.Backend, storageIds), nil
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetDetachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetRebuildRootStatus() ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetChangeConfigStatus(guest *models.SGuest) ([]string, error) {
|
||||
return []string{api.VM_READY}, nil
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetDeployStatus() ([]string, error) {
|
||||
return []string{api.VM_READY, api.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) 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)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, input *api.ServerCreateInput) (*api.ServerCreateInput, error) {
|
||||
if len(input.UserData) > 0 {
|
||||
_, err := cloudinit.ParseUserData(input.UserData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if len(input.Cdrom) > 0 {
|
||||
image, err := models.CachedimageManager.GetCachedimageById(ctx, userCred, input.Cdrom, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(image.ExternalId) > 0 {
|
||||
hosts, err := image.GetHosts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(input.PreferHost) == 0 && len(hosts) == 1 {
|
||||
input.PreferHost = hosts[0].Id
|
||||
}
|
||||
}
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetGuestInitialStateAfterCreate() string {
|
||||
return api.VM_READY
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetGuestInitialStateAfterRebuild() string {
|
||||
return api.VM_READY
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) 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 *SCasGuestDriver) RemoteDeployGuestSyncHost(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, host *models.SHost, iVM cloudprovider.ICloudVM) (cloudprovider.ICloudHost, error) {
|
||||
if hostId := iVM.GetIHostId(); len(hostId) > 0 {
|
||||
nh, err := db.FetchByExternalIdAndManagerId(models.HostManager, hostId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
return q.Equals("manager_id", host.ManagerId)
|
||||
})
|
||||
if err != nil {
|
||||
log.Debugf("failed to found new hostId(%s) for ivm %s(%s) error: %v", hostId, guest.Name, guest.Id, err)
|
||||
if errors.Cause(err) != sql.ErrNoRows {
|
||||
return nil, errors.Wrap(err, "FetchByExternalIdAndManagerId")
|
||||
}
|
||||
|
||||
// HYPERVISOR_CAS VM被部署到一台全新的宿主机
|
||||
zone, err := host.GetZone()
|
||||
if err != nil {
|
||||
log.Warningf("host %s GetZone: %s", host.GetId(), err)
|
||||
} else {
|
||||
_host, err := models.HostManager.NewFromCloudHost(ctx, userCred, iVM.GetIHost(), host.GetCloudprovider(), zone)
|
||||
if err != nil {
|
||||
log.Warningf("NewFromCloudHost %s: %s", iVM.GetIHostId(), err)
|
||||
} else {
|
||||
host = _host
|
||||
}
|
||||
}
|
||||
} else {
|
||||
host = nh.(*models.SHost)
|
||||
}
|
||||
}
|
||||
|
||||
if host.GetId() != guest.HostId {
|
||||
guest.OnScheduleToHost(ctx, userCred, host.GetId())
|
||||
}
|
||||
|
||||
return host.GetIHost(ctx)
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) IsNeedInjectPasswordByCloudInit() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) IsSupportSetAutoRenew() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) RequestSyncSecgroupsOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
|
||||
return nil // do nothing, not support securitygroup
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) GetMaxSecurityGroupCount() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) RequestGuestHotAddIso(ctx context.Context, guest *models.SGuest, path string, boot bool, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCasGuestDriver) IsSupportCdrom(guest *models.SGuest) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
208
pkg/compute/hostdrivers/cas.go
Normal file
208
pkg/compute/hostdrivers/cas.go
Normal file
@@ -0,0 +1,208 @@
|
||||
// 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"
|
||||
"io"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"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/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/image"
|
||||
)
|
||||
|
||||
type SCasHostDriver struct {
|
||||
SManagedVirtualizationHostDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SCasHostDriver{}
|
||||
models.RegisterHostDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SCasHostDriver) GetHostType() string {
|
||||
return api.HOST_TYPE_CAS
|
||||
}
|
||||
|
||||
func (self *SCasHostDriver) GetHypervisor() string {
|
||||
return api.HYPERVISOR_CAS
|
||||
}
|
||||
|
||||
func (self *SCasHostDriver) GetProvider() string {
|
||||
return api.CLOUD_PROVIDER_CAS
|
||||
}
|
||||
|
||||
func (self *SCasHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCasHostDriver) CheckAndSetCacheImage(ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, storageCache *models.SStoragecache, task taskman.ITask) error {
|
||||
input := api.CacheImageInput{}
|
||||
task.GetParams().Unmarshal(&input)
|
||||
opts := &cloudprovider.SImageCreateOption{}
|
||||
task.GetParams().Unmarshal(&opts)
|
||||
|
||||
if len(input.ImageId) == 0 {
|
||||
return fmt.Errorf("no image_id params")
|
||||
}
|
||||
|
||||
if input.Format != "iso" {
|
||||
return fmt.Errorf("invalid image format %s", input.Format)
|
||||
}
|
||||
|
||||
imageSize := int64(0)
|
||||
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
|
||||
lockman.LockRawObject(ctx, models.CachedimageManager.Keyword(), fmt.Sprintf("%s-%s", storageCache.Id, input.ImageId))
|
||||
defer lockman.ReleaseRawObject(ctx, models.CachedimageManager.Keyword(), fmt.Sprintf("%s-%s", storageCache.Id, input.ImageId))
|
||||
|
||||
log.Debugf("XXX Hold lockman key %p cachedimages %s-%s", ctx, storageCache.Id, input.ImageId)
|
||||
|
||||
image, err := models.CachedimageManager.GetCachedimageById(ctx, userCred, input.ImageId, false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CachedimageManager.FetchById(%s)", input.ImageId)
|
||||
}
|
||||
|
||||
if len(image.ExternalId) > 0 {
|
||||
storages, err := image.GetStorages()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
find := false
|
||||
for i := range storages {
|
||||
iStorage, _ := storages[i].GetIStorage(ctx)
|
||||
if gotypes.IsNil(iStorage) {
|
||||
continue
|
||||
}
|
||||
iCache := iStorage.GetIStoragecache()
|
||||
if gotypes.IsNil(iCache) {
|
||||
continue
|
||||
}
|
||||
iImage, err := iCache.GetIImageById(image.ExternalId)
|
||||
if err == nil {
|
||||
imageSize = iImage.GetSizeByte()
|
||||
find = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !find {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, image.ExternalId)
|
||||
}
|
||||
opts.ExternalId = image.ExternalId
|
||||
} else {
|
||||
var guest *models.SGuest
|
||||
if len(input.ServerId) > 0 {
|
||||
server, _ := models.GuestManager.FetchById(input.ServerId)
|
||||
if server != nil {
|
||||
guest = server.(*models.SGuest)
|
||||
}
|
||||
}
|
||||
|
||||
callback := func(progress float32) {
|
||||
guestInfo := ""
|
||||
if guest != nil {
|
||||
guest.SetProgress(progress)
|
||||
guestInfo = fmt.Sprintf(" for server %s ", guest.Name)
|
||||
}
|
||||
log.Infof("Upload image %s from storagecache %s%s status: %.2f%%", opts.ImageName, storageCache.Name, guestInfo, progress)
|
||||
}
|
||||
|
||||
storages, err := host.GetStorages()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetStorages")
|
||||
}
|
||||
|
||||
opts.ExternalId, err = func() (string, error) {
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
info, err := modules.Images.Get(s, input.ImageId, nil)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "Images.Get(%s)", input.ImageId)
|
||||
}
|
||||
opts.Description, _ = info.GetString("description")
|
||||
opts.Checksum, _ = info.GetString("checksum")
|
||||
minDiskMb, _ := info.Int("min_disk")
|
||||
opts.MinDiskMb = int(minDiskMb)
|
||||
minRamMb, _ := info.Int("min_ram")
|
||||
opts.MinRamMb = int(minRamMb)
|
||||
opts.TmpPath = options.Options.TempPath
|
||||
|
||||
opts.GetReader = func(imageId, format string) (io.Reader, int64, error) {
|
||||
_, reader, sizeByte, err := modules.Images.Download(s, imageId, format, false)
|
||||
return reader, sizeByte, err
|
||||
}
|
||||
|
||||
for i := range storages {
|
||||
cache := storages[i].GetStoragecache()
|
||||
iCache, _ := cache.GetIStorageCache(ctx)
|
||||
if gotypes.IsNil(iCache) {
|
||||
continue
|
||||
}
|
||||
|
||||
ret, err := iCache.UploadImage(ctx, opts, callback)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported {
|
||||
continue
|
||||
}
|
||||
return "", errors.Wrapf(err, "UploadImage")
|
||||
}
|
||||
|
||||
region, err := host.GetRegion()
|
||||
if err != nil {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
obj, err := models.CachedimageManager.FetchById(input.ImageId)
|
||||
if err != nil {
|
||||
return ret, errors.Wrapf(err, "CachedimageManager.FetchById")
|
||||
}
|
||||
cachedImage := obj.(*models.SCachedimage)
|
||||
db.Update(cachedImage, func() error {
|
||||
cachedImage.ExternalId = ret
|
||||
return nil
|
||||
})
|
||||
|
||||
cache.SyncCloudImages(ctx, userCred, iCache, region, true)
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("no valid storagecache for upload image")
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Infof("upload image %s id: %s", opts.ImageName, image.ExternalId)
|
||||
}
|
||||
|
||||
ret := jsonutils.NewDict()
|
||||
ret.Add(jsonutils.NewString(opts.ExternalId), "image_id")
|
||||
ret.Add(jsonutils.NewInt(imageSize), "size")
|
||||
return ret, nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
49
pkg/compute/regiondrivers/cas.go
Normal file
49
pkg/compute/regiondrivers/cas.go
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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 (
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
|
||||
type SCasRegionDriver struct {
|
||||
SManagedVirtualizationRegionDriver
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver := SCasRegionDriver{}
|
||||
models.RegisterRegionDriver(&driver)
|
||||
}
|
||||
|
||||
func (self *SCasRegionDriver) GetProvider() string {
|
||||
return api.CLOUD_PROVIDER_CAS
|
||||
}
|
||||
|
||||
func (self *SCasRegionDriver) IsSupportedElasticcacheSecgroup() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SCasRegionDriver) GetMaxElasticcacheSecurityGroupCount() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func (self *SCasRegionDriver) GetSecurityGroupFilter(vpc *models.SVpc) (func(q *sqlchemy.SQuery) *sqlchemy.SQuery, error) {
|
||||
return func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
return q.Equals("cloudregion_id", vpc.CloudregionId).Equals("manager_id", vpc.ManagerId)
|
||||
}, nil
|
||||
}
|
||||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@@ -1785,7 +1785,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.20241221173250-5f4ed89000f5
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20241224075750-4d47750bdc09
|
||||
## explicit; go 1.21
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
1
vendor/yunion.io/x/cloudmux/pkg/apis/compute/cloudaccount_const.go
generated
vendored
1
vendor/yunion.io/x/cloudmux/pkg/apis/compute/cloudaccount_const.go
generated
vendored
@@ -49,6 +49,7 @@ const (
|
||||
CLOUD_PROVIDER_SANGFOR = "SangFor"
|
||||
CLOUD_PROVIDER_ZETTAKIT = "ZettaKit"
|
||||
CLOUD_PROVIDER_UIS = "UIS"
|
||||
CLOUD_PROVIDER_CAS = "CAS"
|
||||
|
||||
CLOUD_PROVIDER_GENERICS3 = "S3"
|
||||
CLOUD_PROVIDER_CEPH = "Ceph"
|
||||
|
||||
1
vendor/yunion.io/x/cloudmux/pkg/apis/compute/guest_const.go
generated
vendored
1
vendor/yunion.io/x/cloudmux/pkg/apis/compute/guest_const.go
generated
vendored
@@ -82,6 +82,7 @@ const (
|
||||
HYPERVISOR_SANGFOR = "sangfor"
|
||||
HYPERVISOR_ZETTAKIT = "zettakit"
|
||||
HYPERVISOR_UIS = "uis"
|
||||
HYPERVISOR_CAS = "cas"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
1
vendor/yunion.io/x/cloudmux/pkg/apis/compute/host_const.go
generated
vendored
1
vendor/yunion.io/x/cloudmux/pkg/apis/compute/host_const.go
generated
vendored
@@ -51,6 +51,7 @@ const (
|
||||
HOST_TYPE_SANGFOR = "sangfor"
|
||||
HOST_TYPE_ZETTAKIT = "zettakit"
|
||||
HOST_TYPE_UIS = "uis"
|
||||
HOST_TYPE_CAS = "cas"
|
||||
|
||||
// # possible status
|
||||
HOST_ONLINE = "online"
|
||||
|
||||
Reference in New Issue
Block a user