mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
Merge pull request #11868 from ioito/automated-cherry-pick-of-#11867-upstream-release-3.7
Automated cherry pick of #11867: fix(region): return sql error
This commit is contained in:
@@ -292,7 +292,7 @@ func (self *SBaremetalGuestDriver) RequestGuestCreateAllDisks(ctx context.Contex
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
storage := diskCat.Root.GetStorage()
|
||||
storage, _ := diskCat.Root.GetStorage()
|
||||
if storage == nil {
|
||||
return fmt.Errorf("no valid storage")
|
||||
}
|
||||
@@ -308,12 +308,12 @@ func (self *SBaremetalGuestDriver) NeedRequestGuestHotAddIso(ctx context.Context
|
||||
}
|
||||
|
||||
func (self *SBaremetalGuestDriver) RequestGuestHotAddIso(ctx context.Context, guest *models.SGuest, path string, boot bool, task taskman.ITask) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
return host.StartInsertIsoTask(ctx, task.GetUserCred(), filepath.Base(path), boot, task.GetTaskId())
|
||||
}
|
||||
|
||||
func (self *SBaremetalGuestDriver) RequestGuestHotRemoveIso(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
return host.StartEjectIsoTask(ctx, task.GetUserCred(), task.GetTaskId())
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ func (self *SBaremetalGuestDriver) RequestStartOnHost(ctx context.Context, guest
|
||||
func (self *SBaremetalGuestDriver) RequestStopGuestForDelete(ctx context.Context, guest *models.SGuest,
|
||||
host *models.SHost, task taskman.ITask) error {
|
||||
if host == nil {
|
||||
host = guest.GetHost()
|
||||
host, _ = guest.GetHost()
|
||||
}
|
||||
guestStatus, _ := task.GetParams().GetString("guest_status")
|
||||
overridePendingDelete := jsonutils.QueryBoolean(task.GetParams(), "override_pending_delete", false)
|
||||
@@ -433,7 +433,7 @@ func (self *SBaremetalGuestDriver) GetJsonDescAtHost(ctx context.Context, userCr
|
||||
func (self *SBaremetalGuestDriver) GetGuestVncInfo(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, host *models.SHost) (*jsonutils.JSONDict, error) {
|
||||
data := jsonutils.NewDict()
|
||||
data.Add(jsonutils.NewString(host.Id), "host_id")
|
||||
zone := host.GetZone()
|
||||
zone, _ := host.GetZone()
|
||||
data.Add(jsonutils.NewString(zone.Name), "zone")
|
||||
return data, nil
|
||||
}
|
||||
@@ -562,7 +562,7 @@ func (self *SBaremetalGuestDriver) OnDeleteGuestFinalCleanup(ctx context.Context
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
baremetal := guest.GetHost()
|
||||
baremetal, _ := guest.GetHost()
|
||||
if baremetal != nil {
|
||||
return baremetal.UpdateDiskConfig(userCred, nil)
|
||||
}
|
||||
@@ -574,7 +574,7 @@ func (self *SBaremetalGuestDriver) IsSupportGuestClone() bool {
|
||||
}
|
||||
|
||||
func (self *SBaremetalGuestDriver) IsSupportCdrom(guest *models.SGuest) (bool, error) {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return false, errors.Wrap(httperrors.ErrNotFound, "no host")
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ func (self *SESXiGuestDriver) RequestDeployGuestOnHost(ctx context.Context, gues
|
||||
if diskCat.Root == nil {
|
||||
return fmt.Errorf("no root disk???")
|
||||
}
|
||||
storage := diskCat.Root.GetStorage()
|
||||
storage, _ := diskCat.Root.GetStorage()
|
||||
if storage == nil {
|
||||
return fmt.Errorf("root disk has no storage???")
|
||||
}
|
||||
@@ -438,7 +438,7 @@ func (self *SESXiGuestDriver) RequestDeployGuestOnHost(ctx context.Context, gues
|
||||
|
||||
func (self *SESXiGuestDriver) RqeuestSuspendOnHost(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, errors.Error("fail to get host of guest")
|
||||
}
|
||||
@@ -462,7 +462,7 @@ func (self *SESXiGuestDriver) RqeuestSuspendOnHost(ctx context.Context, guest *m
|
||||
|
||||
func (self *SESXiGuestDriver) RqeuestResumeOnHost(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, errors.Error("fail to get host of guest")
|
||||
}
|
||||
@@ -581,7 +581,7 @@ func (self *SESXiGuestDriver) RequestMigrate(ctx context.Context, guest *models.
|
||||
return nil, errors.Wrap(fmt.Errorf("empty hostExternalId"), "iVM.GetIHostId()")
|
||||
}
|
||||
iHost, err = db.FetchByExternalIdAndManagerId(models.HostManager, hostExternalId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
if host := guest.GetHost(); host != nil {
|
||||
if host, _ := guest.GetHost(); host != nil {
|
||||
return q.Equals("manager_id", host.ManagerId)
|
||||
}
|
||||
return q
|
||||
@@ -626,7 +626,7 @@ func (self *SESXiGuestDriver) RequestLiveMigrate(ctx context.Context, guest *mod
|
||||
return nil, errors.Wrap(fmt.Errorf("empty hostExternalId"), "iVM.GetIHostId()")
|
||||
}
|
||||
iHost, err = db.FetchByExternalIdAndManagerId(models.HostManager, hostExternalId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
if host := guest.GetHost(); host != nil {
|
||||
if host, _ := guest.GetHost(); host != nil {
|
||||
return q.Equals("manager_id", host.ManagerId)
|
||||
}
|
||||
return q
|
||||
|
||||
@@ -115,7 +115,7 @@ func (self *SKVMGuestDriver) DoGuestCreateDisksTask(ctx context.Context, guest *
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) RequestDiskSnapshot(ctx context.Context, guest *models.SGuest, task taskman.ITask, snapshotId, diskId string) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
url := fmt.Sprintf("%s/servers/%s/snapshot", host.ManagerUri, guest.Id)
|
||||
body := jsonutils.NewDict()
|
||||
body.Set("disk_id", jsonutils.NewString(diskId))
|
||||
@@ -126,7 +126,7 @@ func (self *SKVMGuestDriver) RequestDiskSnapshot(ctx context.Context, guest *mod
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) RequestDeleteSnapshot(ctx context.Context, guest *models.SGuest, task taskman.ITask, params *jsonutils.JSONDict) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
url := fmt.Sprintf("%s/servers/%s/delete-snapshot", host.ManagerUri, guest.Id)
|
||||
header := self.getTaskRequestHeader(task)
|
||||
_, _, err := httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "POST", url, header, params, false)
|
||||
@@ -134,7 +134,7 @@ func (self *SKVMGuestDriver) RequestDeleteSnapshot(ctx context.Context, guest *m
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) RequestReloadDiskSnapshot(ctx context.Context, guest *models.SGuest, task taskman.ITask, params *jsonutils.JSONDict) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
url := fmt.Sprintf("%s/servers/%s/reload-disk-snapshot", host.ManagerUri, guest.Id)
|
||||
header := self.getTaskRequestHeader(task)
|
||||
_, _, err := httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "POST", url, header, params, false)
|
||||
@@ -403,7 +403,7 @@ func (self *SKVMGuestDriver) RequestChangeVmConfig(ctx context.Context, guest *m
|
||||
if vmemSize > int64(guest.VmemSize) {
|
||||
body.Set("add_mem", jsonutils.NewInt(addMem))
|
||||
}
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
url := fmt.Sprintf("%s/servers/%s/hotplug-cpu-mem", host.ManagerUri, guest.Id)
|
||||
_, _, err := httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "POST", url, header, body, false)
|
||||
return err
|
||||
@@ -419,7 +419,7 @@ func (self *SKVMGuestDriver) RequestSoftReset(ctx context.Context, guest *models
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) RequestDetachDisk(ctx context.Context, guest *models.SGuest, disk *models.SDisk, task taskman.ITask) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
header := task.GetTaskRequestHeader()
|
||||
url := fmt.Sprintf("%s/servers/%s/status", host.ManagerUri, guest.Id)
|
||||
_, res, _ := httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "GET", url, header, nil, false)
|
||||
@@ -449,7 +449,7 @@ func (self *SKVMGuestDriver) RequestSaveImage(ctx context.Context, userCred mccl
|
||||
|
||||
func (self *SKVMGuestDriver) RequestOpenForward(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, req *guestdriver_types.OpenForwardRequest) (*guestdriver_types.OpenForwardResponse, error) {
|
||||
var (
|
||||
host = guest.GetHost()
|
||||
host, _ = guest.GetHost()
|
||||
url = fmt.Sprintf("%s/servers/%s/open-forward", host.ManagerUri, guest.Id)
|
||||
httpClient = httputils.GetDefaultClient()
|
||||
header = mcclient.GetTokenHeaders(userCred)
|
||||
@@ -481,7 +481,7 @@ func (self *SKVMGuestDriver) RequestOpenForward(ctx context.Context, userCred mc
|
||||
|
||||
func (self *SKVMGuestDriver) RequestCloseForward(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, req *guestdriver_types.CloseForwardRequest) (*guestdriver_types.CloseForwardResponse, error) {
|
||||
var (
|
||||
host = guest.GetHost()
|
||||
host, _ = guest.GetHost()
|
||||
url = fmt.Sprintf("%s/servers/%s/close-forward", host.ManagerUri, guest.Id)
|
||||
httpClient = httputils.GetDefaultClient()
|
||||
header = mcclient.GetTokenHeaders(userCred)
|
||||
@@ -511,7 +511,7 @@ func (self *SKVMGuestDriver) RequestCloseForward(ctx context.Context, userCred m
|
||||
|
||||
func (self *SKVMGuestDriver) RequestListForward(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, req *guestdriver_types.ListForwardRequest) (*guestdriver_types.ListForwardResponse, error) {
|
||||
var (
|
||||
host = guest.GetHost()
|
||||
host, _ = guest.GetHost()
|
||||
url = fmt.Sprintf("%s/servers/%s/list-forward", host.ManagerUri, guest.Id)
|
||||
httpClient = httputils.GetDefaultClient()
|
||||
header = mcclient.GetTokenHeaders(userCred)
|
||||
@@ -594,7 +594,7 @@ func (self *SKVMGuestDriver) RequestSyncConfigOnHost(ctx context.Context, guest
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) RqeuestSuspendOnHost(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
url := fmt.Sprintf("%s/servers/%s/suspend", host.ManagerUri, guest.Id)
|
||||
header := self.getTaskRequestHeader(task)
|
||||
_, _, err := httputils.JSONRequest(httputils.GetDefaultClient(), ctx, "POST", url, header, nil, false)
|
||||
@@ -629,7 +629,7 @@ func (self *SKVMGuestDriver) RequestRebuildRootDisk(ctx context.Context, guest *
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) RequestSyncToBackup(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
desc, err := guest.GetDriver().GetJsonDescAtHost(ctx, task.GetUserCred(), guest, host, nil)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetJsonDescAtHost")
|
||||
@@ -713,8 +713,9 @@ func (self *SKVMGuestDriver) CheckMigrate(guest *models.SGuest, userCred mcclien
|
||||
if input.IsRescueMode {
|
||||
guestDisks := guest.GetDisks()
|
||||
for _, guestDisk := range guestDisks {
|
||||
storage, _ := guestDisk.GetDisk().GetStorage()
|
||||
if utils.IsInStringArray(
|
||||
guestDisk.GetDisk().GetStorage().StorageType, api.STORAGE_LOCAL_TYPES) {
|
||||
storage.StorageType, api.STORAGE_LOCAL_TYPES) {
|
||||
return httperrors.NewBadRequestError("Rescue mode requires all disk store in shared storages")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func (self *SManagedVirtualizedGuestDriver) GetJsonDescAtHost(ctx context.Contex
|
||||
|
||||
for i := 0; i < len(disks); i += 1 {
|
||||
disk := disks[i].GetDisk()
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if i == 0 {
|
||||
config.SysDisk.Name = disk.Name
|
||||
config.SysDisk.StorageExternalId = storage.ExternalId
|
||||
@@ -150,11 +150,11 @@ func (self *SManagedVirtualizedGuestDriver) RequestSaveImage(ctx context.Context
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "wait image %s(%s) active current is: %s", image.GetName(), image.GetGlobalId(), image.GetStatus())
|
||||
}
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "find guest %s host", guest.Name)
|
||||
}
|
||||
region := host.GetRegion()
|
||||
region, _ := host.GetRegion()
|
||||
iRegion, err := host.GetIRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "host.GetIRegion")
|
||||
@@ -188,7 +188,7 @@ func (self *SManagedVirtualizedGuestDriver) RequestGuestCreateAllDisks(ctx conte
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
storage := diskCat.Root.GetStorage()
|
||||
storage, _ := diskCat.Root.GetStorage()
|
||||
if storage == nil {
|
||||
return fmt.Errorf("no valid storage")
|
||||
}
|
||||
@@ -435,7 +435,7 @@ func (self *SManagedVirtualizedGuestDriver) RequestDeployGuestOnHost(ctx context
|
||||
|
||||
switch action {
|
||||
case "create":
|
||||
region := host.GetRegion()
|
||||
region, _ := host.GetRegion()
|
||||
if len(desc.InstanceType) == 0 && region != nil && utils.IsInStringArray(guest.Hypervisor, api.PUBLIC_CLOUD_HYPERVISORS) {
|
||||
sku, err := models.ServerSkuManager.GetMatchedSku(region.GetId(), int64(desc.Cpu), int64(desc.MemoryMB))
|
||||
if err != nil {
|
||||
@@ -710,7 +710,7 @@ func (self *SManagedVirtualizedGuestDriver) RequestUndeployGuestOnHost(ctx conte
|
||||
|
||||
for _, guestdisk := range guest.GetDisks() {
|
||||
disk := guestdisk.GetDisk()
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if disk != nil && disk.AutoDelete && !utils.IsInStringArray(storage.StorageType, api.STORAGE_LOCAL_TYPES) {
|
||||
idisk, err := disk.GetIDisk()
|
||||
if err != nil {
|
||||
@@ -817,7 +817,7 @@ func (self *SManagedVirtualizedGuestDriver) DoGuestCreateDisksTask(ctx context.C
|
||||
}
|
||||
|
||||
func (self *SManagedVirtualizedGuestDriver) RequestChangeVmConfig(ctx context.Context, guest *models.SGuest, task taskman.ITask, instanceType string, vcpuCount, vmemSize int64) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
ihost, err := host.GetIHost()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -829,7 +829,8 @@ func (self *SManagedVirtualizedGuestDriver) RequestChangeVmConfig(ctx context.Co
|
||||
}
|
||||
|
||||
if len(instanceType) == 0 {
|
||||
sku, err := models.ServerSkuManager.GetMatchedSku(host.GetRegion().GetId(), vcpuCount, vmemSize)
|
||||
region, _ := host.GetRegion()
|
||||
sku, err := models.ServerSkuManager.GetMatchedSku(region.GetId(), vcpuCount, vmemSize)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ManagedVirtualizedGuestDriver.RequestChangeVmConfig.GetMatchedSku")
|
||||
}
|
||||
@@ -941,7 +942,7 @@ func (self *SManagedVirtualizedGuestDriver) OnGuestDeployTaskDataReceived(ctx co
|
||||
|
||||
if len(diskInfo[i].StorageExternalId) > 0 {
|
||||
storage, err := db.FetchByExternalIdAndManagerId(models.StorageManager, diskInfo[i].StorageExternalId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host != nil {
|
||||
return q.Equals("manager_id", host.ManagerId)
|
||||
}
|
||||
@@ -1020,7 +1021,7 @@ func (self *SManagedVirtualizedGuestDriver) RequestSyncSecgroupsOnHost(ctx conte
|
||||
return errors.Wrap(err, "guest.GetVpc")
|
||||
}
|
||||
|
||||
region := host.GetRegion()
|
||||
region, _ := host.GetRegion()
|
||||
|
||||
vpcId, err := region.GetDriver().GetSecurityGroupVpcId(ctx, task.GetUserCred(), region, host, vpc, false)
|
||||
if err != nil {
|
||||
@@ -1236,7 +1237,8 @@ func (self *SManagedVirtualizedGuestDriver) RequestRemoteUpdate(ctx context.Cont
|
||||
}
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
|
||||
err = cloudprovider.SetTags(ctx, iVM, guest.GetHost().ManagerId, tags, replaceTags)
|
||||
host, _ := guest.GetHost()
|
||||
err = cloudprovider.SetTags(ctx, iVM, host.ManagerId, tags, replaceTags)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == cloudprovider.ErrNotSupported || errors.Cause(err) == cloudprovider.ErrNotImplemented {
|
||||
return nil
|
||||
|
||||
@@ -219,7 +219,7 @@ func (self *SOpenStackGuestDriver) RemoteDeployGuestForRebuildRoot(ctx context.C
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "guest.GetSystemDisk(")
|
||||
}
|
||||
storage := sysDisk.GetStorage()
|
||||
storage, _ := sysDisk.GetStorage()
|
||||
if storage.StorageType == api.STORAGE_OPENSTACK_NOVA { //不通过镜像创建磁盘的机器
|
||||
conf := cloudprovider.SManagedVMRebuildRootConfig{
|
||||
Account: desc.Account,
|
||||
@@ -400,7 +400,7 @@ func (self *SOpenStackGuestDriver) RequestMigrate(ctx context.Context, guest *mo
|
||||
return nil, errors.Wrap(fmt.Errorf("empty hostExternalId"), "iVM.GetIHostId()")
|
||||
}
|
||||
iHost, err := db.FetchByExternalIdAndManagerId(models.HostManager, hostExternalId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
if host := guest.GetHost(); host != nil {
|
||||
if host, _ := guest.GetHost(); host != nil {
|
||||
return q.Equals("manager_id", host.ManagerId)
|
||||
}
|
||||
return q
|
||||
@@ -445,7 +445,7 @@ func (self *SOpenStackGuestDriver) RequestLiveMigrate(ctx context.Context, guest
|
||||
return nil, errors.Wrap(fmt.Errorf("empty hostExternalId"), "iVM.GetIHostId()")
|
||||
}
|
||||
iHost, err := db.FetchByExternalIdAndManagerId(models.HostManager, hostExternalId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
if host := guest.GetHost(); host != nil {
|
||||
if host, _ := guest.GetHost(); host != nil {
|
||||
return q.Equals("manager_id", host.ManagerId)
|
||||
}
|
||||
return q
|
||||
|
||||
@@ -177,7 +177,7 @@ func (self *SQcloudGuestDriver) ValidateChangeConfig(ctx context.Context, userCr
|
||||
if err != nil {
|
||||
return httperrors.NewResourceNotFoundError("failed to found system disk error: %v", err)
|
||||
}
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage == nil {
|
||||
return httperrors.NewResourceNotFoundError("failed to found storage for disk %s(%s)", disk.Name, disk.Id)
|
||||
}
|
||||
@@ -218,7 +218,7 @@ func (self *SQcloudGuestDriver) ValidateChangeConfig(ctx context.Context, userCr
|
||||
}
|
||||
|
||||
func (self *SQcloudGuestDriver) ValidateDetachDisk(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, disk *models.SDisk) error {
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage == nil {
|
||||
return httperrors.NewResourceNotFoundError("failed to found storage for disk %s(%s)", disk.Name, disk.Id)
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ func (self *SVirtualizedGuestDriver) StartGuestSyncstatusTask(guest *models.SGue
|
||||
func (self *SVirtualizedGuestDriver) RequestStopGuestForDelete(ctx context.Context, guest *models.SGuest,
|
||||
host *models.SHost, task taskman.ITask) error {
|
||||
if host == nil {
|
||||
host = guest.GetHost()
|
||||
host, _ = guest.GetHost()
|
||||
}
|
||||
if host != nil && host.GetEnabled() && host.HostStatus == api.HOST_ONLINE {
|
||||
return guest.StartGuestStopTask(ctx, task.GetUserCred(), true, false, task.GetTaskId())
|
||||
|
||||
@@ -70,8 +70,9 @@ func (self *SESXiHostDriver) CheckAndSetCacheImage(ctx context.Context, host *mo
|
||||
// else, use it
|
||||
hostCacheImage := models.StoragecachedimageManager.GetStoragecachedimage(storageCache.GetId(), cacheImage.GetId())
|
||||
if hostCacheImage == nil {
|
||||
zone, _ := host.GetZone()
|
||||
srcHostCacheImage, err = cacheImage.ChooseSourceStoragecacheInRange(api.HOST_TYPE_ESXI, []string{host.Id},
|
||||
[]interface{}{host.GetZone(), host.GetCloudprovider()})
|
||||
[]interface{}{zone, host.GetCloudprovider()})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -314,7 +315,7 @@ func (self *SESXiHostDriver) RequestSaveUploadImageOnHost(ctx context.Context, h
|
||||
// return fmt.Errorf("cannot find host with id %s", agentId)
|
||||
// }
|
||||
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
|
||||
type specStruct struct {
|
||||
ImagePath string
|
||||
|
||||
@@ -188,7 +188,8 @@ func (self *SKVMHostDriver) CheckAndSetCacheImage(ctx context.Context, host *mod
|
||||
return errors.Wrapf(err, "Fetch cached image by image_id %s", imageId)
|
||||
}
|
||||
cacheImage := obj.(*models.SCachedimage)
|
||||
rangeObjs := []interface{}{host.GetZone()}
|
||||
zone, _ := host.GetZone()
|
||||
rangeObjs := []interface{}{zone}
|
||||
if srcHost != nil {
|
||||
rangeObjs = append(rangeObjs, srcHost)
|
||||
}
|
||||
@@ -357,7 +358,8 @@ func (self *SKVMHostDriver) RequestPrepareSaveDiskOnHost(ctx context.Context, ho
|
||||
func (self *SKVMHostDriver) RequestSaveUploadImageOnHost(ctx context.Context, host *models.SHost, disk *models.SDisk, imageId string, task taskman.ITask, data jsonutils.JSONObject) error {
|
||||
body := jsonutils.NewDict()
|
||||
backup, _ := data.GetString("backup")
|
||||
content := map[string]string{"image_path": backup, "image_id": imageId, "storagecached_id": disk.GetStorage().StoragecacheId}
|
||||
storage, _ := disk.GetStorage()
|
||||
content := map[string]string{"image_path": backup, "image_id": imageId, "storagecached_id": storage.StoragecacheId}
|
||||
if data.Contains("format") {
|
||||
content["format"], _ = data.GetString("format")
|
||||
}
|
||||
|
||||
@@ -59,7 +59,8 @@ func getBmAgentUrl(ctx context.Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
zoneId := n.GetWire().ZoneId
|
||||
wire, _ := n.GetWire()
|
||||
zoneId := wire.ZoneId
|
||||
bmAgent := models.BaremetalagentManager.GetAgent(compute.AgentTypeBaremetal, zoneId)
|
||||
if bmAgent == nil {
|
||||
httperrors.InternalServerError(ctx, w, "Baremetal agent not found")
|
||||
|
||||
@@ -250,7 +250,7 @@ func getDomainManagerProviderSubq(domainId string) *sqlchemy.SSubQuery {
|
||||
|
||||
func getDBInstanceInfo(region *SCloudregion, zone *SZone) map[string]map[string]map[string][]string {
|
||||
if zone != nil {
|
||||
region = zone.GetRegion()
|
||||
region, _ = zone.GetRegion()
|
||||
}
|
||||
if region == nil {
|
||||
return nil
|
||||
@@ -708,7 +708,7 @@ func getAutoAllocNetworkCount(ownerId mcclient.IIdentityProvider, scope rbacutil
|
||||
|
||||
func getNetworkCountByFilter(ownerId mcclient.IIdentityProvider, scope rbacutils.TRbacScope, region *SCloudregion, zone *SZone, isAutoAlloc tristate.TriState, serverType string) (int, error) {
|
||||
if zone != nil && region == nil {
|
||||
region = zone.GetRegion()
|
||||
region, _ = zone.GetRegion()
|
||||
}
|
||||
|
||||
networks := NetworkManager.Query().SubQuery()
|
||||
|
||||
@@ -2517,7 +2517,7 @@ func (manager *SCloudaccountManager) queryCloudAccountByCapability(region *SClou
|
||||
q = q.IsFalse("enabled")
|
||||
}
|
||||
if zone != nil {
|
||||
region = zone.GetRegion()
|
||||
region, _ = zone.GetRegion()
|
||||
}
|
||||
if region != nil {
|
||||
providerregions := CloudproviderRegionManager.Query().SubQuery()
|
||||
|
||||
@@ -557,7 +557,7 @@ func (sr *SSyncRange) normalizeZoneIds() error {
|
||||
}
|
||||
}
|
||||
zone := obj.(*SZone)
|
||||
region := zone.GetRegion()
|
||||
region, _ := zone.GetRegion()
|
||||
if region == nil {
|
||||
continue
|
||||
}
|
||||
@@ -580,11 +580,11 @@ func (sr *SSyncRange) normalizeHostIds() error {
|
||||
}
|
||||
}
|
||||
host := obj.(*SHost)
|
||||
zone := host.GetZone()
|
||||
zone, _ := host.GetZone()
|
||||
if zone == nil {
|
||||
continue
|
||||
}
|
||||
region := zone.GetRegion()
|
||||
region, _ := zone.GetRegion()
|
||||
if region == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -592,7 +592,7 @@ func syncStorageCaches(ctx context.Context, userCred mcclient.TokenCredential, p
|
||||
cachePair.local = localCache
|
||||
cachePair.remote = remoteCache
|
||||
cachePair.isNew = isNew
|
||||
cachePair.region = localStorage.GetRegion()
|
||||
cachePair.region, _ = localStorage.GetRegion()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1343,7 +1343,7 @@ func getZoneForPremiseCloudRegion(ctx context.Context, userCred mcclient.TokenCr
|
||||
log.Errorf(msg)
|
||||
continue
|
||||
}
|
||||
return wire.GetZone(), nil
|
||||
return wire.GetZone()
|
||||
}
|
||||
return nil, errors.Wrap(errors.ErrNotFound, "no suitable zone")
|
||||
}
|
||||
|
||||
@@ -332,7 +332,7 @@ func (man *SDBInstanceManager) ValidateCreateData(ctx context.Context, userCred
|
||||
return input, httperrors.NewInputParameterError("Ip %s not in network %s(%s) range", input.Address, network.Name, network.Id)
|
||||
}
|
||||
}
|
||||
vpc = network.GetVpc()
|
||||
vpc, _ = network.GetVpc()
|
||||
} else if len(input.VpcId) > 0 {
|
||||
_vpc, err := validators.ValidateModel(userCred, VpcManager, &input.VpcId)
|
||||
if err != nil {
|
||||
|
||||
@@ -52,37 +52,36 @@ func ValidateDiskResourceInput(userCred mcclient.TokenCredential, input api.Disk
|
||||
return diskObj.(*SDisk), input, nil
|
||||
}
|
||||
|
||||
func (self *SDiskResourceBase) GetDisk() *SDisk {
|
||||
obj, _ := DiskManager.FetchById(self.DiskId)
|
||||
if obj != nil {
|
||||
return obj.(*SDisk)
|
||||
func (self *SDiskResourceBase) GetDisk() (*SDisk, error) {
|
||||
obj, err := DiskManager.FetchById(self.DiskId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDisk(%s)", self.DiskId)
|
||||
}
|
||||
return nil
|
||||
return obj.(*SDisk), nil
|
||||
}
|
||||
|
||||
func (self *SDiskResourceBase) GetStorage() *SStorage {
|
||||
disk := self.GetDisk()
|
||||
if disk != nil {
|
||||
return disk.GetStorage()
|
||||
func (self *SDiskResourceBase) GetStorage() (*SStorage, error) {
|
||||
disk, err := self.GetDisk()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return disk.GetStorage()
|
||||
}
|
||||
|
||||
func (self *SDiskResourceBase) GetZone() *SZone {
|
||||
storage := self.GetStorage()
|
||||
if storage != nil {
|
||||
return storage.GetZone()
|
||||
func (self *SDiskResourceBase) GetZone() (*SZone, error) {
|
||||
storage, err := self.GetStorage()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return storage.GetZone()
|
||||
}
|
||||
|
||||
func (self *SDiskResourceBase) GetRegion() *SCloudregion {
|
||||
storage := self.GetStorage()
|
||||
if storage == nil {
|
||||
return nil
|
||||
func (self *SDiskResourceBase) GetRegion() (*SCloudregion, error) {
|
||||
storage, err := self.GetStorage()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetStorage")
|
||||
}
|
||||
region := storage.GetRegion()
|
||||
return region
|
||||
return storage.GetRegion()
|
||||
}
|
||||
|
||||
func (self *SDiskResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) api.DiskResourceInfo {
|
||||
@@ -250,7 +249,7 @@ func (manager *SDiskResourceBaseManager) GetExportKeys() []string {
|
||||
}
|
||||
|
||||
func (self *SDiskResourceBase) GetChangeOwnerCandidateDomainIds() []string {
|
||||
disk := self.GetDisk()
|
||||
disk, _ := self.GetDisk()
|
||||
if disk != nil {
|
||||
return disk.GetChangeOwnerCandidateDomainIds()
|
||||
}
|
||||
|
||||
+47
-46
@@ -389,7 +389,7 @@ func (self *SDisk) ValidateUpdateData(ctx context.Context, userCred mcclient.Tok
|
||||
}
|
||||
}
|
||||
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return input, httperrors.NewNotFoundError("failed to find storage for disk %s", self.Name)
|
||||
}
|
||||
@@ -423,7 +423,7 @@ func diskCreateInput2ComputeQuotaKeys(input api.DiskCreateInput, ownerId mcclien
|
||||
if len(input.PreferHost) > 0 {
|
||||
hostObj, _ := HostManager.FetchById(input.PreferHost)
|
||||
host := hostObj.(*SHost)
|
||||
zone := host.GetZone()
|
||||
zone, _ := host.GetZone()
|
||||
keys.ZoneId = zone.Id
|
||||
keys.RegionId = zone.CloudregionId
|
||||
} else if len(input.PreferZone) > 0 {
|
||||
@@ -434,7 +434,7 @@ func diskCreateInput2ComputeQuotaKeys(input api.DiskCreateInput, ownerId mcclien
|
||||
} else if len(input.PreferWire) > 0 {
|
||||
wireObj, _ := WireManager.FetchById(input.PreferWire)
|
||||
wire := wireObj.(*SWire)
|
||||
zone := wire.GetZone()
|
||||
zone, _ := wire.GetZone()
|
||||
keys.ZoneId = zone.Id
|
||||
keys.RegionId = zone.CloudregionId
|
||||
} else if len(input.PreferRegion) > 0 {
|
||||
@@ -482,10 +482,11 @@ func (manager *SDiskManager) ValidateCreateData(ctx context.Context, userCred mc
|
||||
}
|
||||
input.Storage = storage.Id
|
||||
|
||||
zone, _ := storage.getZone()
|
||||
quotaKey = fetchComputeQuotaKeys(
|
||||
rbacutils.ScopeProject,
|
||||
ownerId,
|
||||
storage.getZone(),
|
||||
zone,
|
||||
provider,
|
||||
input.Hypervisor,
|
||||
)
|
||||
@@ -621,10 +622,11 @@ func getDiskResourceRequirements(ctx context.Context, userCred mcclient.TokenCre
|
||||
if len(input.Storage) > 0 {
|
||||
storageObj, _ := StorageManager.FetchById(input.Storage)
|
||||
storage := storageObj.(*SStorage)
|
||||
zone, _ := storage.getZone()
|
||||
quotaKey = fetchComputeQuotaKeys(
|
||||
rbacutils.ScopeProject,
|
||||
ownerId,
|
||||
storage.getZone(),
|
||||
zone,
|
||||
storage.GetCloudprovider(),
|
||||
input.Hypervisor,
|
||||
)
|
||||
@@ -795,7 +797,7 @@ func (self *SDisk) PerformDiskReset(ctx context.Context, userCred mcclient.Token
|
||||
if !utils.IsInStringArray(self.Status, []string{api.DISK_READY}) {
|
||||
return nil, httperrors.NewInputParameterError("Cannot reset disk in status %s", self.Status)
|
||||
}
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return nil, httperrors.NewNotFoundError("failed to find storage for disk %s", self.Name)
|
||||
}
|
||||
@@ -883,7 +885,7 @@ func (disk *SDisk) PerformResize(ctx context.Context, userCred mcclient.TokenCre
|
||||
}
|
||||
|
||||
func (disk *SDisk) getHypervisor() string {
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage != nil {
|
||||
host := storage.GetMasterHost()
|
||||
if host != nil {
|
||||
@@ -895,7 +897,7 @@ func (disk *SDisk) getHypervisor() string {
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetQuotaKeys() (quotas.IQuotaKeys, error) {
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage == nil {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "no valid storage")
|
||||
}
|
||||
@@ -903,7 +905,7 @@ func (disk *SDisk) GetQuotaKeys() (quotas.IQuotaKeys, error) {
|
||||
if provider == nil && len(storage.ManagerId) > 0 {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "no valid manager")
|
||||
}
|
||||
zone := storage.getZone()
|
||||
zone, _ := storage.getZone()
|
||||
if zone == nil {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "no valid zone")
|
||||
}
|
||||
@@ -927,7 +929,7 @@ func (disk *SDisk) doResize(ctx context.Context, userCred mcclient.TokenCredenti
|
||||
return nil
|
||||
}
|
||||
addDisk := sizeMb - disk.DiskSize
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage == nil {
|
||||
return httperrors.NewInternalServerError("disk has no valid storage")
|
||||
}
|
||||
@@ -963,7 +965,7 @@ func (disk *SDisk) doResize(ctx context.Context, userCred mcclient.TokenCredenti
|
||||
}
|
||||
|
||||
func (self *SDisk) GetIStorage() (cloudprovider.ICloudStorage, error) {
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("fail to find storage for disk %s", self.GetName())
|
||||
}
|
||||
@@ -983,15 +985,16 @@ func (self *SDisk) GetIDisk() (cloudprovider.ICloudDisk, error) {
|
||||
return iStorage.GetIDiskById(self.GetExternalId())
|
||||
}
|
||||
|
||||
func (self *SDisk) GetZone() *SZone {
|
||||
if storage := self.GetStorage(); storage != nil {
|
||||
return storage.getZone()
|
||||
func (self *SDisk) GetZone() (*SZone, error) {
|
||||
storage, err := self.GetStorage()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return storage.getZone()
|
||||
}
|
||||
|
||||
func (self *SDisk) PrepareSaveImage(ctx context.Context, userCred mcclient.TokenCredential, input api.ServerSaveImageInput) (string, error) {
|
||||
zone := self.GetZone()
|
||||
zone, _ := self.GetZone()
|
||||
if zone == nil {
|
||||
return "", httperrors.NewResourceNotFoundError("No zone for this disk")
|
||||
}
|
||||
@@ -1106,7 +1109,7 @@ func (self *SDisk) ValidatePurgeCondition(ctx context.Context) error {
|
||||
|
||||
func (self *SDisk) validateDeleteCondition(ctx context.Context, isPurge bool) error {
|
||||
if !isPurge {
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
// storage is empty, a dirty data, allow delete
|
||||
return nil
|
||||
@@ -1167,7 +1170,7 @@ func (self *SDisk) GetTemplateId() string {
|
||||
}
|
||||
|
||||
func (self *SDisk) IsLocal() bool {
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage != nil {
|
||||
return storage.IsLocal()
|
||||
}
|
||||
@@ -1175,23 +1178,23 @@ func (self *SDisk) IsLocal() bool {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetCloudproviderId() string {
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage != nil {
|
||||
return storage.GetCloudproviderId()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SDisk) GetStorage() *SStorage {
|
||||
store, _ := StorageManager.FetchById(self.StorageId)
|
||||
if store != nil {
|
||||
return store.(*SStorage)
|
||||
func (self *SDisk) GetStorage() (*SStorage, error) {
|
||||
store, err := StorageManager.FetchById(self.StorageId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetStorage(%s)", self.StorageId)
|
||||
}
|
||||
return nil
|
||||
return store.(*SStorage), nil
|
||||
}
|
||||
|
||||
func (self *SDisk) GetRegionDriver() (IRegionDriver, error) {
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return nil, fmt.Errorf("failed to found storage for disk %s(%s)", self.Name, self.Id)
|
||||
}
|
||||
@@ -1210,7 +1213,7 @@ func (self *SDisk) GetBackupStorage() *SStorage {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetCloudprovider() *SCloudprovider {
|
||||
if storage := self.GetStorage(); storage != nil {
|
||||
if storage, _ := self.GetStorage(); storage != nil {
|
||||
return storage.GetCloudprovider()
|
||||
}
|
||||
return nil
|
||||
@@ -1230,7 +1233,7 @@ func (self *SDisk) GetPathAtHost(host *SHost) string {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetFetchUrl() string {
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return ""
|
||||
}
|
||||
@@ -1391,7 +1394,7 @@ func (self *SDisk) syncDiskStorage(ctx context.Context, userCred mcclient.TokenC
|
||||
}
|
||||
|
||||
func (self *SDisk) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return nil, fmt.Errorf("failed to get storage for disk %s(%s)", self.Name, self.Id)
|
||||
}
|
||||
@@ -1404,11 +1407,9 @@ func (self *SDisk) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
if provider.GetFactory().IsOnPremise() {
|
||||
return provider.GetOnPremiseIRegion()
|
||||
}
|
||||
region := storage.GetRegion()
|
||||
if region == nil {
|
||||
msg := "fail to find region of storage???"
|
||||
log.Errorf(msg)
|
||||
return nil, fmt.Errorf(msg)
|
||||
region, err := storage.GetRegion()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return provider.GetIRegionById(region.ExternalId)
|
||||
}
|
||||
@@ -1425,7 +1426,7 @@ func (self *SDisk) syncRemoveCloudDisk(ctx context.Context, userCred mcclient.To
|
||||
if err == nil {
|
||||
if storageId := iDisk.GetIStorageId(); len(storageId) > 0 {
|
||||
storage, err := db.FetchByExternalIdAndManagerId(StorageManager, storageId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
if s := self.GetStorage(); s != nil {
|
||||
if s, _ := self.GetStorage(); s != nil {
|
||||
return q.Equals("manager_id", s.ManagerId)
|
||||
}
|
||||
return q
|
||||
@@ -1515,7 +1516,7 @@ func (self *SDisk) syncWithCloudDisk(ctx context.Context, userCred mcclient.Toke
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Get snapshot policies of ICloudDisk %s.", extDisk.GetId())
|
||||
}
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return fmt.Errorf("no valid storage")
|
||||
}
|
||||
@@ -1828,7 +1829,7 @@ func (self *SDisk) ToDiskInfo() DiskInfo {
|
||||
Size: int64(self.DiskSize),
|
||||
DiskType: self.DiskType,
|
||||
}
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return ret
|
||||
}
|
||||
@@ -1848,7 +1849,7 @@ func (self *SDisk) ToDiskConfig() *api.DiskConfig {
|
||||
SizeMb: self.DiskSize,
|
||||
DiskType: self.DiskType,
|
||||
}
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return ret
|
||||
}
|
||||
@@ -1924,7 +1925,7 @@ func (self *SDisk) CustomizeDelete(ctx context.Context, userCred mcclient.TokenC
|
||||
if cnt > 0 {
|
||||
return httperrors.NewForbiddenError("not allow to delete. Virtual disk must not have snapshots")
|
||||
}
|
||||
} else if storage := self.GetStorage(); storage != nil && storage.StorageType == api.STORAGE_RBD {
|
||||
} else if storage, _ := self.GetStorage(); storage != nil && storage.StorageType == api.STORAGE_RBD {
|
||||
scnt, err := self.GetSnapshotCount()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1988,7 +1989,7 @@ func (self *SDisk) getMoreDetails(ctx context.Context, userCred mcclient.TokenCr
|
||||
policy.Name = sps[i].Name
|
||||
out.Snapshotpolicies = append(out.Snapshotpolicies, policy)
|
||||
}
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage != nil {
|
||||
manualSnapshotCount, _ := self.GetManualSnapshotCount()
|
||||
if utils.IsInStringArray(storage.StorageType, append(api.SHARED_FILE_STORAGE, api.STORAGE_LOCAL)) {
|
||||
@@ -2101,7 +2102,7 @@ func (self *SDisk) SwitchToBackup(userCred mcclient.TokenCredential) error {
|
||||
}
|
||||
|
||||
func (self *SDisk) ClearHostSchedCache() error {
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return fmt.Errorf("no valid storage")
|
||||
}
|
||||
@@ -2121,7 +2122,7 @@ func (self *SDisk) ClearHostSchedCache() error {
|
||||
func (self *SDisk) GetShortDesc(ctx context.Context) *jsonutils.JSONDict {
|
||||
desc := self.SVirtualResourceBase.GetShortDesc(ctx)
|
||||
desc.Add(jsonutils.NewInt(int64(self.DiskSize)), "size")
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage != nil {
|
||||
desc.Add(jsonutils.NewString(storage.StorageType), "storage_type")
|
||||
desc.Add(jsonutils.NewString(storage.MediumType), "medium_type")
|
||||
@@ -2267,7 +2268,7 @@ func (disk *SDisk) validateDiskAutoCreateSnapshot() error {
|
||||
if len(guests) == 0 {
|
||||
return fmt.Errorf("Disks %s not attach guest, can't create snapshot", disk.GetName())
|
||||
}
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage == nil {
|
||||
return fmt.Errorf("no valid storage")
|
||||
}
|
||||
@@ -2427,7 +2428,7 @@ func (self *SDisk) CancelExpireTime(ctx context.Context, userCred mcclient.Token
|
||||
}
|
||||
|
||||
func (self *SDisk) IsDetachable() bool {
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return true
|
||||
}
|
||||
@@ -2452,7 +2453,7 @@ func (self *SDisk) GetDynamicConditionInput() *jsonutils.JSONDict {
|
||||
}
|
||||
|
||||
func (self *SDisk) IsNeedWaitSnapshotsDeleted() (bool, error) {
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
return false, fmt.Errorf("no valid storage")
|
||||
}
|
||||
@@ -2577,12 +2578,12 @@ func (self *SDisk) syncSnapshots(ctx context.Context, userCred mcclient.TokenCre
|
||||
}
|
||||
provider := self.GetCloudprovider()
|
||||
syncOwnerId := provider.GetOwnerId()
|
||||
storage := self.GetStorage()
|
||||
storage, _ := self.GetStorage()
|
||||
if storage == nil {
|
||||
syncResult.Error(fmt.Errorf("no valid storage"))
|
||||
return
|
||||
}
|
||||
region := storage.GetRegion()
|
||||
region, _ := storage.GetRegion()
|
||||
|
||||
extSnapshots, err := extDisk.GetISnapshots()
|
||||
if err != nil {
|
||||
|
||||
@@ -158,7 +158,8 @@ func (self *SElasticcacheAccount) GetRegion() *SCloudregion {
|
||||
return nil
|
||||
}
|
||||
|
||||
return iec.(*SElasticcache).GetRegion()
|
||||
region, _ := iec.(*SElasticcache).GetRegion()
|
||||
return region
|
||||
}
|
||||
|
||||
func (self *SElasticcacheAccount) GetOwnerId() mcclient.IIdentityProvider {
|
||||
@@ -227,7 +228,7 @@ func (manager *SElasticcacheAccountManager) ValidateCreateData(ctx context.Conte
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting elastic cache instance failed")
|
||||
}
|
||||
region = ec.(*SElasticcache).GetRegion()
|
||||
region, _ = ec.(*SElasticcache).GetRegion()
|
||||
} else {
|
||||
return nil, httperrors.NewMissingParameterError("elasticcache_id")
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ func (manager *SElasticcacheAclManager) ValidateCreateData(ctx context.Context,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting elastic cache instance failed")
|
||||
}
|
||||
region = ec.(*SElasticcache).GetRegion()
|
||||
region, _ = ec.(*SElasticcache).GetRegion()
|
||||
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("getting elastic cache region failed")
|
||||
@@ -258,7 +258,8 @@ func (self *SElasticcacheAcl) GetRegion() *SCloudregion {
|
||||
return nil
|
||||
}
|
||||
|
||||
return ieb.(*SElasticcache).GetRegion()
|
||||
region, _ := ieb.(*SElasticcache).GetRegion()
|
||||
return region
|
||||
}
|
||||
|
||||
func (self *SElasticcacheAcl) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool {
|
||||
|
||||
@@ -242,7 +242,7 @@ func (manager *SElasticcacheBackupManager) ValidateCreateData(ctx context.Contex
|
||||
return nil, httperrors.NewMissingParameterError("elasticcache")
|
||||
}
|
||||
|
||||
region = ec.GetRegion()
|
||||
region, _ = ec.GetRegion()
|
||||
driver := region.GetDriver()
|
||||
if err := driver.AllowCreateElasticcacheBackup(ctx, userCred, ownerId, ec); err != nil {
|
||||
return nil, err
|
||||
@@ -328,7 +328,8 @@ func (self *SElasticcacheBackup) GetRegion() *SCloudregion {
|
||||
return nil
|
||||
}
|
||||
|
||||
return ieb.(*SElasticcache).GetRegion()
|
||||
region, _ := ieb.(*SElasticcache).GetRegion()
|
||||
return region
|
||||
}
|
||||
|
||||
func (self *SElasticcacheBackup) ValidateDeleteCondition(ctx context.Context) error {
|
||||
|
||||
@@ -192,9 +192,9 @@ func elasticcacheSubResourceFetchOwner(q *sqlchemy.SQuery, userCred mcclient.IId
|
||||
}
|
||||
|
||||
func (self *SElasticcache) getCloudProviderInfo() SCloudProviderInfo {
|
||||
region := self.GetRegion()
|
||||
region, _ := self.GetRegion()
|
||||
provider := self.GetCloudprovider()
|
||||
zone := self.GetZone()
|
||||
zone, _ := self.GetZone()
|
||||
return MakeCloudProviderInfo(region, zone, provider)
|
||||
}
|
||||
|
||||
@@ -782,8 +782,8 @@ func (manager *SElasticcacheManager) validateCreateData(ctx context.Context, use
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting network failed")
|
||||
}
|
||||
region = network.(*SNetwork).GetRegion()
|
||||
vpc := network.(*SNetwork).GetVpc()
|
||||
region, _ = network.(*SNetwork).GetRegion()
|
||||
vpc, _ := network.(*SNetwork).GetVpc()
|
||||
provider = vpc.GetCloudprovider()
|
||||
}
|
||||
|
||||
@@ -926,7 +926,7 @@ func (self *SElasticcache) GetCreateAliyunElasticcacheParams(data *jsonutils.JSO
|
||||
input.EngineVersion = self.EngineVersion
|
||||
input.PrivateIpAddress = self.PrivateIpAddr
|
||||
|
||||
zone := self.GetZone()
|
||||
zone, _ := self.GetZone()
|
||||
if zone != nil {
|
||||
izone, err := iregion.GetIZoneById(zone.ExternalId)
|
||||
if err != nil {
|
||||
@@ -1018,7 +1018,7 @@ func (self *SElasticcache) GetCreateHuaweiElasticcacheParams(data *jsonutils.JSO
|
||||
input.EngineVersion = self.EngineVersion
|
||||
input.PrivateIpAddress = self.PrivateIpAddr
|
||||
|
||||
zone := self.GetZone()
|
||||
zone, _ := self.GetZone()
|
||||
if zone != nil {
|
||||
izone, err := iregion.GetIZoneById(zone.ExternalId)
|
||||
if err != nil {
|
||||
@@ -1071,7 +1071,8 @@ func (self *SElasticcache) GetCreateHuaweiElasticcacheParams(data *jsonutils.JSO
|
||||
|
||||
// fill security group here
|
||||
if len(self.SecurityGroupId) > 0 {
|
||||
sgCache, err := SecurityGroupCacheManager.GetSecgroupCache(context.Background(), nil, self.SecurityGroupId, self.VpcId, self.GetRegion().Id, self.GetCloudprovider().Id, "")
|
||||
region, _ := self.GetRegion()
|
||||
sgCache, err := SecurityGroupCacheManager.GetSecgroupCache(context.Background(), nil, self.SecurityGroupId, self.VpcId, region.Id, self.GetCloudprovider().Id, "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "elasticcache.GetCreateHuaweiElasticcacheParams.SecurityGroup")
|
||||
}
|
||||
@@ -1106,7 +1107,7 @@ func (self *SElasticcache) GetCreateQCloudElasticcacheParams(data *jsonutils.JSO
|
||||
input.Password = password
|
||||
}
|
||||
|
||||
zone := self.GetZone()
|
||||
zone, _ := self.GetZone()
|
||||
if zone != nil {
|
||||
zones := []SZone{*zone}
|
||||
// slave zones
|
||||
@@ -1238,7 +1239,7 @@ func (self *SElasticcache) ValidatorChangeSpecData(ctx context.Context, userCred
|
||||
return nil, httperrors.NewInputParameterError("provider mismatch: %s instance can't use %s sku", self.GetProviderName(), sku.Provider)
|
||||
}
|
||||
|
||||
region := self.GetRegion()
|
||||
region, _ := self.GetRegion()
|
||||
if sku.CloudregionId != region.Id {
|
||||
return nil, httperrors.NewInputParameterError("region mismatch: instance region %s, sku region %s", region.Id, sku.CloudregionId)
|
||||
}
|
||||
@@ -1287,7 +1288,7 @@ func (self *SElasticcache) AllowPerformUpdateAuthMode(ctx context.Context, userC
|
||||
}
|
||||
|
||||
func (self *SElasticcache) ValidatorUpdateAuthModeData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
region := self.GetRegion()
|
||||
region, _ := self.GetRegion()
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("fail to found region for elastic cache")
|
||||
}
|
||||
@@ -1735,10 +1736,11 @@ func (man *SElasticcacheManager) TotalCount(
|
||||
}
|
||||
|
||||
func (cache *SElasticcache) GetQuotaKeys() quotas.IQuotaKeys {
|
||||
region, _ := cache.GetRegion()
|
||||
return fetchRegionalQuotaKeys(
|
||||
rbacutils.ScopeProject,
|
||||
cache.GetOwnerId(),
|
||||
cache.GetRegion(),
|
||||
region,
|
||||
cache.GetCloudprovider(),
|
||||
)
|
||||
}
|
||||
@@ -1971,7 +1973,7 @@ func (self *SElasticcache) OnMetadataUpdated(ctx context.Context, userCred mccli
|
||||
}
|
||||
|
||||
func (self *SElasticcache) getSecgroupsBySecgroupExternalIds(externalIds []string) ([]SSecurityGroup, error) {
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, errors.Wrap(errors.ErrNotFound, "GetVpc")
|
||||
}
|
||||
@@ -1994,7 +1996,7 @@ func (self *SElasticcache) validateSecgroupInput(secgroups []string) error {
|
||||
return httperrors.NewInputParameterError("Cannot add security groups in status %s", self.Status)
|
||||
}
|
||||
|
||||
region := self.GetRegion()
|
||||
region, _ := self.GetRegion()
|
||||
if region == nil {
|
||||
return httperrors.NewNotFoundError("region")
|
||||
}
|
||||
@@ -2300,7 +2302,7 @@ func (self *SElasticcache) PerformSetAutoRenew(ctx context.Context, userCred mcc
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
region := self.GetRegion()
|
||||
region, _ := self.GetRegion()
|
||||
if region == nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("elastic cache no related region found")
|
||||
}
|
||||
@@ -2350,7 +2352,7 @@ func (self *SElasticcache) PerformRenew(ctx context.Context, userCred mcclient.T
|
||||
return nil, httperrors.NewInputParameterError("invalid duration %s: %s", durationStr, err)
|
||||
}
|
||||
|
||||
region := self.GetRegion()
|
||||
region, _ := self.GetRegion()
|
||||
if region == nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("elastic cache no related region found")
|
||||
}
|
||||
|
||||
@@ -205,7 +205,8 @@ func (self *SElasticcacheParameter) GetRegion() *SCloudregion {
|
||||
return nil
|
||||
}
|
||||
|
||||
return ieb.(*SElasticcache).GetRegion()
|
||||
region, _ := ieb.(*SElasticcache).GetRegion()
|
||||
return region
|
||||
}
|
||||
|
||||
func (self *SElasticcacheParameter) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
|
||||
@@ -69,7 +69,8 @@ func (self *SElasticcacheResourceBase) GetVpc() *SVpc {
|
||||
log.Errorf("GetElasticcache fail %s", err)
|
||||
return nil
|
||||
}
|
||||
return cache.GetVpc()
|
||||
vpc, _ := cache.GetVpc()
|
||||
return vpc
|
||||
}
|
||||
|
||||
func (self *SElasticcacheResourceBase) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
|
||||
@@ -153,7 +153,7 @@ func (manager *SElasticipManager) ListItemFilter(
|
||||
}
|
||||
guest := serverObj.(*SGuest)
|
||||
if guest.Hypervisor == api.HYPERVISOR_KVM || utils.IsInStringArray(guest.Hypervisor, api.PRIVATE_CLOUD_HYPERVISORS) {
|
||||
zone := guest.getZone()
|
||||
zone, _ := guest.getZone()
|
||||
networks := NetworkManager.Query().SubQuery()
|
||||
wires := WireManager.Query().SubQuery()
|
||||
|
||||
@@ -163,10 +163,11 @@ func (manager *SElasticipManager) ListItemFilter(
|
||||
gns := GuestnetworkManager.Query("network_id").Equals("guest_id", guest.Id).SubQuery()
|
||||
q = q.Filter(sqlchemy.NotIn(q.Field("network_id"), gns))
|
||||
} else {
|
||||
region := guest.getRegion()
|
||||
region, _ := guest.getRegion()
|
||||
q = q.Equals("cloudregion_id", region.Id)
|
||||
}
|
||||
managerId := guest.GetHost().ManagerId
|
||||
host, _ := guest.GetHost()
|
||||
managerId := host.ManagerId
|
||||
if managerId != "" {
|
||||
q = q.Equals("manager_id", managerId)
|
||||
} else {
|
||||
@@ -286,13 +287,10 @@ func (self *SElasticip) GetNetwork() (*SNetwork, error) {
|
||||
return network.(*SNetwork), nil
|
||||
}
|
||||
|
||||
func (self *SElasticip) GetZone() *SZone {
|
||||
if len(self.NetworkId) == 0 {
|
||||
return nil
|
||||
}
|
||||
func (self *SElasticip) GetZone() (*SZone, error) {
|
||||
network, err := self.GetNetwork()
|
||||
if err != nil {
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
return network.GetZone()
|
||||
}
|
||||
@@ -1024,7 +1022,7 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient.
|
||||
}
|
||||
}
|
||||
}
|
||||
serverRegion := server.getRegion()
|
||||
serverRegion, _ := server.getRegion()
|
||||
if serverRegion == nil {
|
||||
return input, httperrors.NewInputParameterError("server region is not found???")
|
||||
}
|
||||
@@ -1037,15 +1035,15 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient.
|
||||
if serverRegion.Id != eipRegion.Id {
|
||||
return input, httperrors.NewInputParameterError("eip and server are not in the same region")
|
||||
}
|
||||
eipZone := self.GetZone()
|
||||
eipZone, _ := self.GetZone()
|
||||
if eipZone != nil {
|
||||
serverZone := server.getZone()
|
||||
serverZone, _ := server.getZone()
|
||||
if serverZone.Id != eipZone.Id {
|
||||
return input, httperrors.NewInputParameterError("eip and server are not in the same zone")
|
||||
}
|
||||
}
|
||||
|
||||
srvHost := server.GetHost()
|
||||
srvHost, _ := server.GetHost()
|
||||
if srvHost == nil {
|
||||
return input, httperrors.NewInputParameterError("server host is not found???")
|
||||
}
|
||||
@@ -1242,9 +1240,9 @@ func (manager *SElasticipManager) NewEipForVMOnHost(ctx context.Context, userCre
|
||||
)
|
||||
|
||||
if host != nil {
|
||||
region = host.GetRegion()
|
||||
region, _ = host.GetRegion()
|
||||
} else if nat != nil {
|
||||
region = nat.GetRegion()
|
||||
region, _ = nat.GetRegion()
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalid host or nat")
|
||||
}
|
||||
|
||||
@@ -137,8 +137,9 @@ func (man *SFileSystemManager) ValidateCreateData(ctx context.Context, userCred
|
||||
return input, err
|
||||
}
|
||||
network := net.(*SNetwork)
|
||||
input.ManagerId = network.GetVpc().ManagerId
|
||||
if zone := network.GetZone(); zone != nil {
|
||||
vpc, _ := network.GetVpc()
|
||||
input.ManagerId = vpc.ManagerId
|
||||
if zone, _ := network.GetZone(); zone != nil {
|
||||
input.ZoneId = zone.Id
|
||||
input.CloudregionId = zone.CloudregionId
|
||||
}
|
||||
@@ -151,7 +152,7 @@ func (man *SFileSystemManager) ValidateCreateData(ctx context.Context, userCred
|
||||
return input, err
|
||||
}
|
||||
zone := _zone.(*SZone)
|
||||
region := zone.GetRegion()
|
||||
region, _ := zone.GetRegion()
|
||||
input.CloudregionId = region.Id
|
||||
|
||||
if len(input.ManagerId) == 0 {
|
||||
|
||||
@@ -65,7 +65,7 @@ func rangeObjFilter(q *sqlchemy.SQuery, rangeObj db.IStandaloneModel, regionFiel
|
||||
} else if zoneField != nil {
|
||||
q = q.Filter(sqlchemy.Equals(zoneField, wire.ZoneId))
|
||||
} else if regionField != nil {
|
||||
vpc := wire.GetVpc()
|
||||
vpc, _ := wire.GetVpc()
|
||||
q = q.Filter(sqlchemy.Equals(regionField, vpc.CloudregionId))
|
||||
}
|
||||
case "host":
|
||||
@@ -79,7 +79,7 @@ func rangeObjFilter(q *sqlchemy.SQuery, rangeObj db.IStandaloneModel, regionFiel
|
||||
} else if zoneField != nil {
|
||||
q = q.Filter(sqlchemy.Equals(zoneField, host.ZoneId))
|
||||
} else if regionField != nil {
|
||||
zone := host.GetZone()
|
||||
zone, _ := host.GetZone()
|
||||
q = q.Filter(sqlchemy.Equals(regionField, zone.CloudregionId))
|
||||
}
|
||||
case "storage":
|
||||
@@ -93,7 +93,7 @@ func rangeObjFilter(q *sqlchemy.SQuery, rangeObj db.IStandaloneModel, regionFiel
|
||||
} else if zoneField != nil {
|
||||
q = q.Filter(sqlchemy.Equals(zoneField, storage.ZoneId))
|
||||
} else if regionField != nil {
|
||||
zone := storage.GetZone()
|
||||
zone, _ := storage.GetZone()
|
||||
q = q.Filter(sqlchemy.Equals(regionField, zone.CloudregionId))
|
||||
}
|
||||
case "cloudprovider":
|
||||
|
||||
@@ -73,7 +73,7 @@ func (self *SGuest) AllowGetDetailsVnc(ctx context.Context, userCred mcclient.To
|
||||
|
||||
func (self *SGuest) GetDetailsVnc(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_BLOCK_STREAM}) {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return nil, httperrors.NewInternalServerError("Host missing")
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (self *SGuest) PreCheckPerformAction(
|
||||
return err
|
||||
}
|
||||
if self.Hypervisor == api.HYPERVISOR_KVM {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host != nil && (host.HostStatus == api.HOST_OFFLINE || !host.Enabled.Bool()) &&
|
||||
utils.IsInStringArray(action,
|
||||
[]string{
|
||||
@@ -171,7 +171,7 @@ func (self *SGuest) AllowGetDetailsDesc(ctx context.Context, userCred mcclient.T
|
||||
}
|
||||
|
||||
func (self *SGuest) GetDetailsDesc(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return nil, httperrors.NewInvalidStatusError("No host for server")
|
||||
}
|
||||
@@ -201,7 +201,7 @@ func (self *SGuest) PerformSaveImage(ctx context.Context, userCred mcclient.Toke
|
||||
input.OsArch = self.OsArch
|
||||
if apis.IsARM(self.OsArch) {
|
||||
if osArch := self.GetMetadata("os_arch", nil); len(osArch) == 0 {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
input.OsArch = host.CpuArchitecture
|
||||
}
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func (self *SGuest) PerformSaveGuestImage(ctx context.Context, userCred mcclient
|
||||
if apis.IsARM(self.OsArch) {
|
||||
var osArch string
|
||||
if osArch = self.GetMetadata("os_arch", nil); len(osArch) == 0 {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
osArch = host.CpuArchitecture
|
||||
}
|
||||
properties.Add(jsonutils.NewString(osArch), "os_arch")
|
||||
@@ -458,7 +458,7 @@ func (self *SGuest) GetSchedMigrateParams(
|
||||
if input.LiveMigrate {
|
||||
schedDesc.LiveMigrate = input.LiveMigrate
|
||||
if self.GetMetadata("__cpu_mode", userCred) != api.CPU_MODE_QEMU {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
schedDesc.CpuDesc = host.CpuDesc
|
||||
schedDesc.CpuMicrocode = host.CpuMicrocode
|
||||
schedDesc.CpuMode = api.CPU_MODE_HOST
|
||||
@@ -748,9 +748,9 @@ func (self *SGuest) AllowPerformAttachdisk(ctx context.Context, userCred mcclien
|
||||
}
|
||||
|
||||
func (self *SGuest) ValidateAttachDisk(ctx context.Context, disk *SDisk) error {
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
host, _ := self.GetHost()
|
||||
if provider := storage.GetCloudprovider(); provider != nil {
|
||||
host := self.GetHost()
|
||||
if provider.Id != host.ManagerId {
|
||||
return httperrors.NewInputParameterError("Disk %s and guest not belong to the same account", disk.Name)
|
||||
}
|
||||
@@ -769,7 +769,7 @@ func (self *SGuest) ValidateAttachDisk(ctx context.Context, disk *SDisk) error {
|
||||
}
|
||||
}
|
||||
|
||||
if len(disk.GetPathAtHost(self.GetHost())) == 0 {
|
||||
if len(disk.GetPathAtHost(host)) == 0 {
|
||||
return httperrors.NewInputParameterError("Disk %s not belong the guest's host", disk.Name)
|
||||
}
|
||||
if disk.Status != api.DISK_READY {
|
||||
@@ -895,7 +895,7 @@ func (self *SGuest) PerformStart(ctx context.Context, userCred mcclient.TokenCre
|
||||
data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_START_FAILED, api.VM_SAVE_DISK_FAILED, api.VM_SUSPEND}) {
|
||||
if !self.guestDisksStorageTypeIsShared() {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
guestsMem, err := host.GetNotReadyGuestsMemorySize()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -995,7 +995,7 @@ func (self *SGuest) NotifyServerEvent(
|
||||
|
||||
kwargs.Add(jsonutils.NewString(self.Name), "name")
|
||||
kwargs.Add(jsonutils.NewString(self.Hypervisor), "hypervisor")
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host != nil {
|
||||
brand := host.GetBrand()
|
||||
if brand == api.CLOUD_PROVIDER_ONECLOUD {
|
||||
@@ -1515,7 +1515,7 @@ func (self *SGuest) PerformPurge(ctx context.Context, userCred mcclient.TokenCre
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host != nil && host.GetEnabled() {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot purge server on enabled host")
|
||||
}
|
||||
@@ -1756,7 +1756,7 @@ func (self *SGuest) PerformCreatedisk(ctx context.Context, userCred mcclient.Tok
|
||||
}
|
||||
diskSize += diskInfo.SizeMb
|
||||
}
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
logclient.AddActionLogWithContext(ctx, self, logclient.ACT_CREATE, "No valid host", userCred, false)
|
||||
return nil, httperrors.NewBadRequestError("No valid host")
|
||||
@@ -1910,7 +1910,7 @@ func (self *SGuest) PerformDetachIsolatedDevice(ctx context.Context, userCred mc
|
||||
}
|
||||
} else {
|
||||
devs := self.GetIsolatedDevices()
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
lockman.LockObject(ctx, host)
|
||||
defer lockman.ReleaseObject(ctx, host)
|
||||
for i := 0; i < len(devs); i++ {
|
||||
@@ -1935,7 +1935,7 @@ func (self *SGuest) startDetachIsolateDevice(ctx context.Context, userCred mccli
|
||||
return httperrors.NewBadRequestError(msgFmt, device)
|
||||
}
|
||||
dev := iDev.(*SIsolatedDevice)
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
lockman.LockObject(ctx, host)
|
||||
defer lockman.ReleaseObject(ctx, host)
|
||||
err = self.detachIsolateDevice(ctx, userCred, dev)
|
||||
@@ -2000,7 +2000,7 @@ func (self *SGuest) PerformAttachIsolatedDevice(ctx context.Context, userCred mc
|
||||
}
|
||||
|
||||
func (self *SGuest) startAttachIsolatedDevices(ctx context.Context, userCred mcclient.TokenCredential, gpuModel string, count int) error {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
lockman.LockObject(ctx, host)
|
||||
defer lockman.ReleaseObject(ctx, host)
|
||||
devs, err := IsolatedDeviceManager.GetDevsOnHost(host.Id, gpuModel, count)
|
||||
@@ -2029,7 +2029,7 @@ func (self *SGuest) startAttachIsolatedDevice(ctx context.Context, userCred mccl
|
||||
return httperrors.NewBadRequestError(msgFmt, device)
|
||||
}
|
||||
dev := iDev.(*SIsolatedDevice)
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
lockman.LockObject(ctx, host)
|
||||
defer lockman.ReleaseObject(ctx, host)
|
||||
err = self.attachIsolatedDevice(ctx, userCred, dev)
|
||||
@@ -2156,7 +2156,8 @@ func (self *SGuest) getReuseAddr(gn *SGuestnetwork) string {
|
||||
if self.GetHypervisor() != api.HYPERVISOR_BAREMETAL {
|
||||
return ""
|
||||
}
|
||||
hostNics := self.GetHost().GetNics()
|
||||
host, _ := self.GetHost()
|
||||
hostNics := host.GetNics()
|
||||
for _, hn := range hostNics {
|
||||
if hn.GetMac().String() == gn.MacAddr {
|
||||
return hn.IpAddr
|
||||
@@ -2206,7 +2207,7 @@ func (self *SGuest) PerformChangeIpaddr(ctx context.Context, userCred mcclient.T
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
|
||||
ngn, err := func() ([]SGuestnetwork, error) {
|
||||
lockman.LockRawObject(ctx, GuestnetworkManager.KeywordPlural(), "")
|
||||
@@ -2379,7 +2380,7 @@ func (self *SGuest) PerformAttachnetwork(ctx context.Context, userCred mcclient.
|
||||
if err != nil {
|
||||
return nil, httperrors.NewOutOfQuotaError("%v", err)
|
||||
}
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
defer host.ClearSchedDescCache()
|
||||
for i := 0; i < count; i++ {
|
||||
_, err = self.attach2NetworkDesc(ctx, userCred, host, input.Nets[i], pendingUsage, nil)
|
||||
@@ -2512,7 +2513,7 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot change config in %s", self.Status)
|
||||
}
|
||||
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return nil, httperrors.NewInvalidStatusError("No valid host")
|
||||
}
|
||||
@@ -2633,7 +2634,7 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
|
||||
arr := jsonutils.NewArray(jsonutils.NewString(disks[diskIdx].DiskId), jsonutils.NewInt(int64(diskConf.SizeMb)))
|
||||
resizeDisks.Add(arr)
|
||||
addDisk += diskConf.SizeMb - oldSize
|
||||
storage := disks[diskIdx].GetDisk().GetStorage()
|
||||
storage, _ := disks[diskIdx].GetDisk().GetStorage()
|
||||
schedInputDisks = append(schedInputDisks, &api.DiskConfig{
|
||||
SizeMb: addDisk,
|
||||
Index: diskConf.Index,
|
||||
@@ -3010,7 +3011,7 @@ func (self *SGuest) IsLegalKey(key string) bool {
|
||||
}
|
||||
|
||||
func (self *SGuest) SendMonitorCommand(ctx context.Context, userCred mcclient.TokenCredential, cmd string) (jsonutils.JSONObject, error) {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
url := fmt.Sprintf("%s/servers/%s/monitor", host.ManagerUri, self.Id)
|
||||
header := http.Header{}
|
||||
header.Add("X-Auth-Token", userCred.GetTokenString())
|
||||
@@ -3061,7 +3062,7 @@ func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.T
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(errors.Wrapf(err, "eip.GetRegion"))
|
||||
}
|
||||
instRegion := self.getRegion()
|
||||
instRegion, _ := self.getRegion()
|
||||
|
||||
if eip.Mode == api.EIP_MODE_INSTANCE_PUBLICIP {
|
||||
return nil, httperrors.NewUnsupportOperationError("fixed eip cannot be associated")
|
||||
@@ -3088,15 +3089,15 @@ func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.T
|
||||
}
|
||||
}
|
||||
|
||||
eipZone := eip.GetZone()
|
||||
eipZone, _ := eip.GetZone()
|
||||
if eipZone != nil {
|
||||
insZone := self.getZone()
|
||||
insZone, _ := self.getZone()
|
||||
if eipZone.Id != insZone.Id {
|
||||
return nil, httperrors.NewInputParameterError("cannot associate eip and instance in different zone")
|
||||
}
|
||||
}
|
||||
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return nil, httperrors.NewInputParameterError("server host is not found???")
|
||||
}
|
||||
@@ -3154,8 +3155,8 @@ func (self *SGuest) AllowPerformCreateEip(ctx context.Context, userCred mcclient
|
||||
|
||||
func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
var (
|
||||
host = self.GetHost()
|
||||
region = host.GetRegion()
|
||||
host, _ = self.GetHost()
|
||||
region, _ = host.GetRegion()
|
||||
regionDriver = region.GetDriver()
|
||||
|
||||
bw int64
|
||||
@@ -3560,7 +3561,8 @@ func (self *SGuest) AllowPerformCreateBackup(ctx context.Context, userCred mccli
|
||||
|
||||
func (self *SGuest) guestDisksStorageTypeIsLocal() bool {
|
||||
for _, gd := range self.GetDisks() {
|
||||
if gd.GetDisk().GetStorage().StorageType != api.STORAGE_LOCAL {
|
||||
storage, _ := gd.GetDisk().GetStorage()
|
||||
if storage.StorageType != api.STORAGE_LOCAL {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -3569,7 +3571,8 @@ func (self *SGuest) guestDisksStorageTypeIsLocal() bool {
|
||||
|
||||
func (self *SGuest) guestDisksStorageTypeIsShared() bool {
|
||||
for _, gd := range self.GetDisks() {
|
||||
if gd.GetDisk().GetStorage().StorageType == api.STORAGE_LOCAL {
|
||||
storage, _ := gd.GetDisk().GetStorage()
|
||||
if storage.StorageType == api.STORAGE_LOCAL {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -3837,7 +3840,7 @@ func (self *SGuest) GetStorages() []*SStorage {
|
||||
disks := self.GetDisks()
|
||||
storageMap := make(map[string]*SStorage)
|
||||
for i := range disks {
|
||||
storage := disks[i].GetStorage()
|
||||
storage, _ := disks[i].GetStorage()
|
||||
if _, ok := storageMap[storage.GetId()]; !ok {
|
||||
storageMap[storage.GetId()] = storage
|
||||
}
|
||||
@@ -4085,7 +4088,8 @@ func (self *SGuest) importNics(ctx context.Context, userCred mcclient.TokenCrede
|
||||
if err != nil {
|
||||
return httperrors.NewNotFoundError("Not found network by ip %s", nic.Ip)
|
||||
}
|
||||
_, err = self.attach2NetworkDesc(ctx, userCred, self.GetHost(), ToNetConfig(&nic, net), nil, nil)
|
||||
host, _ := self.GetHost()
|
||||
_, err = self.attach2NetworkDesc(ctx, userCred, host, ToNetConfig(&nic, net), nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -4116,8 +4120,9 @@ func (self *SGuest) importDisks(ctx context.Context, userCred mcclient.TokenCred
|
||||
if len(disks) == 0 {
|
||||
return httperrors.NewInputParameterError("Empty import disks")
|
||||
}
|
||||
host, _ := self.GetHost()
|
||||
for _, disk := range disks {
|
||||
disk, err := self.createDiskOnHost(ctx, userCred, self.GetHost(), ToDiskConfig(&disk), nil, true, true, nil, nil, true)
|
||||
disk, err := self.createDiskOnHost(ctx, userCred, host, ToDiskConfig(&disk), nil, true, true, nil, nil, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -4198,8 +4203,9 @@ func (self *SGuest) GetDetailsVirtInstall(
|
||||
vdiListenPort int64
|
||||
)
|
||||
|
||||
host, _ := self.GetHost()
|
||||
if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_BLOCK_STREAM}) {
|
||||
vncInfo, err := self.GetDriver().GetGuestVncInfo(ctx, userCred, self, self.GetHost())
|
||||
vncInfo, err := self.GetDriver().GetGuestVncInfo(ctx, userCred, self, host)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return nil, err
|
||||
@@ -4236,7 +4242,7 @@ func (self *SGuest) GenerateVirtInstallCommandLine(
|
||||
cmd += L(fmt.Sprintf("--ram %d", self.VmemSize))
|
||||
cmd += L(fmt.Sprintf("--vcpus %d", self.VcpuCount))
|
||||
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
|
||||
// disks
|
||||
guestDisks := self.GetDisks()
|
||||
@@ -4419,7 +4425,7 @@ func (self *SGuest) PerformSyncFixNics(ctx context.Context,
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return nil, httperrors.NewInternalServerError("host not found???")
|
||||
}
|
||||
@@ -4782,11 +4788,12 @@ func (self *SGuest) validateCreateInstanceSnapshot(
|
||||
|
||||
// construct Quota
|
||||
pendingUsage := &SRegionQuota{InstanceSnapshot: 1}
|
||||
provider := self.GetHost().GetProviderName()
|
||||
host, _ := self.GetHost()
|
||||
provider := host.GetProviderName()
|
||||
if utils.IsInStringArray(provider, ProviderHasSubSnapshot) {
|
||||
disks := self.GetDisks()
|
||||
for i := 0; i < len(disks); i++ {
|
||||
if storage := disks[i].GetDisk().GetStorage(); utils.IsInStringArray(storage.StorageType, api.FIEL_STORAGE) {
|
||||
if storage, _ := disks[i].GetDisk().GetStorage(); utils.IsInStringArray(storage.StorageType, api.FIEL_STORAGE) {
|
||||
count, err := SnapshotManager.GetDiskManualSnapshotCount(disks[i].DiskId)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInternalServerError("%v", err)
|
||||
@@ -5039,7 +5046,7 @@ func (self *SGuest) GetDetailsJnlp(ctx context.Context, userCred mcclient.TokenC
|
||||
if self.Hypervisor != api.HYPERVISOR_BAREMETAL {
|
||||
return nil, httperrors.NewInvalidStatusError("not a baremetal server")
|
||||
}
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return nil, httperrors.NewInvalidStatusError("no valid host")
|
||||
}
|
||||
|
||||
@@ -90,13 +90,13 @@ func (guest *SGuest) PerformMigrateNetwork(ctx context.Context, userCred mcclien
|
||||
}
|
||||
destNet := destModel.(*SNetwork)
|
||||
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "guest is not allocated!")
|
||||
}
|
||||
if destNet.isOneCloudVpcNetwork() {
|
||||
// vpc network should be in the same Zone
|
||||
destZone := destNet.GetZone()
|
||||
destZone, _ := destNet.GetZone()
|
||||
if destZone == nil || destZone.Id != host.ZoneId {
|
||||
return nil, errors.Wrap(httperrors.ErrBadRequest, "destination overlay network not in same zone as server")
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func (guest *SGuest) sshableTryEach(
|
||||
if network == nil {
|
||||
continue
|
||||
}
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ func (gtm *SGuestTemplateManager) validateData(
|
||||
return cinput, errors.Wrap(err, "NetworkManager.FetchById")
|
||||
}
|
||||
net := model.(*SNetwork)
|
||||
vpc := net.GetVpc()
|
||||
vpc, _ := net.GetVpc()
|
||||
if vpc != nil {
|
||||
cinput.VpcId = vpc.Id
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func (manager *SGuestdiskManager) FetchCustomizeColumns(
|
||||
rows[i].Status = disk.Status
|
||||
rows[i].DiskSize = disk.DiskSize
|
||||
rows[i].DiskType = disk.DiskType
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage != nil {
|
||||
rows[i].StorageType = storage.StorageType
|
||||
rows[i].MediumType = storage.MediumType
|
||||
@@ -198,7 +198,7 @@ func (self *SGuestdisk) GetJsonDescAtHost(host *SHost) jsonutils.JSONObject {
|
||||
templateId := disk.GetTemplateId()
|
||||
if len(templateId) > 0 {
|
||||
desc.Add(jsonutils.NewString(templateId), "template_id")
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
storagecacheimg := StoragecachedimageManager.GetStoragecachedimage(storage.StoragecacheId, templateId)
|
||||
if storagecacheimg != nil {
|
||||
desc.Add(jsonutils.NewString(storagecacheimg.Path), "image_path")
|
||||
@@ -278,7 +278,7 @@ func (self *SGuestdisk) GetDetailedInfo() api.GuestDiskInfo {
|
||||
}
|
||||
}
|
||||
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage == nil {
|
||||
return desc
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ func (manager *SGuestnetworkManager) newGuestNetwork(
|
||||
lockman.LockObject(ctx, network)
|
||||
defer lockman.ReleaseObject(ctx, network)
|
||||
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, fmt.Errorf("cannot find vpc of network %s(%s)", network.Id, network.Name)
|
||||
}
|
||||
@@ -535,7 +535,7 @@ func (self *SGuestnetwork) getJsonDescOneCloudVpc(network *SNetwork) *jsonutils.
|
||||
}
|
||||
}
|
||||
}
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
|
||||
vpcDesc := jsonutils.NewDict()
|
||||
vpcDesc.Set("id", jsonutils.NewString(vpc.Id))
|
||||
@@ -808,7 +808,7 @@ func (self *SGuestnetwork) getBandwidth() int {
|
||||
} else {
|
||||
net := self.GetNetwork()
|
||||
if net != nil {
|
||||
wire := net.GetWire()
|
||||
wire, _ := net.GetWire()
|
||||
if wire != nil {
|
||||
return wire.Bandwidth
|
||||
}
|
||||
@@ -822,7 +822,8 @@ func (self *SGuestnetwork) getMtu(net *SNetwork) int {
|
||||
}
|
||||
|
||||
func (self *SGuestnetwork) IsAllocated() bool {
|
||||
provider := self.GetGuest().getRegion().Provider
|
||||
region, _ := self.GetGuest().getRegion()
|
||||
provider := region.Provider
|
||||
if regutils.MatchMacAddr(self.MacAddr) && (self.Virtual || regutils.MatchIP4Addr(self.IpAddr) || (provider != api.CLOUD_PROVIDER_ONECLOUD && !options.Options.EnablePreAllocateIpAddr)) {
|
||||
return true
|
||||
}
|
||||
@@ -966,10 +967,11 @@ func (self *SGuestnetwork) ToNetworkConfig() *api.NetworkConfig {
|
||||
if net == nil {
|
||||
return nil
|
||||
}
|
||||
wire, _ := net.GetWire()
|
||||
ret := &api.NetworkConfig{
|
||||
Index: int(self.Index),
|
||||
Network: net.Id,
|
||||
Wire: net.GetWire().Id,
|
||||
Wire: wire.Id,
|
||||
Mac: self.MacAddr,
|
||||
Address: self.IpAddr,
|
||||
Driver: self.Driver,
|
||||
|
||||
@@ -52,37 +52,36 @@ func ValidateGuestResourceInput(userCred mcclient.TokenCredential, input api.Ser
|
||||
return srvObj.(*SGuest), input, nil
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetGuest() *SGuest {
|
||||
obj, _ := GuestManager.FetchById(self.GuestId)
|
||||
if obj != nil {
|
||||
return obj.(*SGuest)
|
||||
func (self *SGuestResourceBase) GetGuest() (*SGuest, error) {
|
||||
obj, err := GuestManager.FetchById(self.GuestId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return obj.(*SGuest), nil
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetHost() *SHost {
|
||||
guest := self.GetGuest()
|
||||
if guest != nil {
|
||||
return guest.GetHost()
|
||||
func (self *SGuestResourceBase) GetHost() (*SHost, error) {
|
||||
guest, err := self.GetGuest()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return guest.GetHost()
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetZone() *SZone {
|
||||
host := self.GetHost()
|
||||
if host != nil {
|
||||
return host.GetZone()
|
||||
func (self *SGuestResourceBase) GetZone() (*SZone, error) {
|
||||
host, err := self.GetHost()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return host.GetZone()
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetRegion() *SCloudregion {
|
||||
host := self.GetHost()
|
||||
if host == nil {
|
||||
return nil
|
||||
func (self *SGuestResourceBase) GetRegion() (*SCloudregion, error) {
|
||||
host, err := self.GetHost()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
region := host.GetRegion()
|
||||
return region
|
||||
return host.GetRegion()
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) api.GuestResourceInfo {
|
||||
@@ -249,7 +248,7 @@ func (manager *SGuestResourceBaseManager) GetExportKeys() []string {
|
||||
}
|
||||
|
||||
func (self *SGuestResourceBase) GetChangeOwnerCandidateDomainIds() []string {
|
||||
guest := self.GetGuest()
|
||||
guest, _ := self.GetGuest()
|
||||
if guest != nil {
|
||||
return guest.GetChangeOwnerCandidateDomainIds()
|
||||
}
|
||||
|
||||
@@ -688,7 +688,7 @@ func (guest *SGuest) ValidatePurgeCondition(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (guest *SGuest) ValidateDeleteCondition(ctx context.Context) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host != nil && guest.GetHypervisor() != api.HYPERVISOR_BAREMETAL {
|
||||
if !host.GetEnabled() {
|
||||
return httperrors.NewInputParameterError("Cannot delete server on disabled host")
|
||||
@@ -792,7 +792,7 @@ func (guest *SGuest) GetVpc() (*SVpc, error) {
|
||||
if network == nil {
|
||||
return nil, errors.Wrapf(err, "failed getting network for guest %s(%s)", guest.Name, guest.Id)
|
||||
}
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, errors.Wrapf(err, "failed getting vpc of guest network %s(%s)", network.Name, network.Id)
|
||||
}
|
||||
@@ -886,21 +886,22 @@ func (guest *SGuest) CustomizeCreate(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
|
||||
func (guest *SGuest) GetCloudproviderId() string {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host != nil {
|
||||
return host.GetCloudproviderId()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (guest *SGuest) GetHost() *SHost {
|
||||
func (guest *SGuest) GetHost() (*SHost, error) {
|
||||
if len(guest.HostId) > 0 && regutils.MatchUUID(guest.HostId) {
|
||||
host, _ := HostManager.FetchById(guest.HostId)
|
||||
if host != nil {
|
||||
return host.(*SHost)
|
||||
host, err := HostManager.FetchById(guest.HostId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return host.(*SHost), nil
|
||||
}
|
||||
return nil
|
||||
return nil, fmt.Errorf("empty host id")
|
||||
}
|
||||
|
||||
func (guest *SGuest) SetHostId(userCred mcclient.TokenCredential, hostId string) error {
|
||||
@@ -1051,7 +1052,7 @@ func serverCreateInput2ComputeQuotaKeys(input api.ServerCreateInput, ownerId mcc
|
||||
if len(input.PreferHost) > 0 {
|
||||
hostObj, _ := HostManager.FetchById(input.PreferHost)
|
||||
host := hostObj.(*SHost)
|
||||
zone := host.GetZone()
|
||||
zone, _ := host.GetZone()
|
||||
keys.ZoneId = zone.Id
|
||||
keys.RegionId = zone.CloudregionId
|
||||
} else if len(input.PreferZone) > 0 {
|
||||
@@ -1062,7 +1063,7 @@ func serverCreateInput2ComputeQuotaKeys(input api.ServerCreateInput, ownerId mcc
|
||||
} else if len(input.PreferWire) > 0 {
|
||||
wireObj, _ := WireManager.FetchById(input.PreferWire)
|
||||
wire := wireObj.(*SWire)
|
||||
zone := wire.GetZone()
|
||||
zone, _ := wire.GetZone()
|
||||
keys.ZoneId = zone.Id
|
||||
keys.RegionId = zone.CloudregionId
|
||||
} else if len(input.PreferRegion) > 0 {
|
||||
@@ -2273,20 +2274,20 @@ func (self *SGuest) getIPs() []string {
|
||||
return ips
|
||||
}
|
||||
|
||||
func (self *SGuest) getZone() *SZone {
|
||||
host := self.GetHost()
|
||||
if host != nil {
|
||||
return host.GetZone()
|
||||
func (self *SGuest) getZone() (*SZone, error) {
|
||||
host, err := self.GetHost()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return host.GetZone()
|
||||
}
|
||||
|
||||
func (self *SGuest) getRegion() *SCloudregion {
|
||||
zone := self.getZone()
|
||||
if zone != nil {
|
||||
return zone.GetRegion()
|
||||
func (self *SGuest) getRegion() (*SCloudregion, error) {
|
||||
zone, err := self.getZone()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return zone.GetRegion()
|
||||
}
|
||||
|
||||
func (self *SGuest) GetOS() string {
|
||||
@@ -2404,7 +2405,7 @@ var (
|
||||
)
|
||||
|
||||
func (self *SGuest) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return nil, fmt.Errorf("failed to get host by guest %s(%s)", self.Name, self.Id)
|
||||
}
|
||||
@@ -2446,7 +2447,7 @@ func (self *SGuest) syncRemoveCloudVM(ctx context.Context, userCred mcclient.Tok
|
||||
if err == nil { //漂移归位
|
||||
if hostId := iVM.GetIHostId(); len(hostId) > 0 {
|
||||
host, err := db.FetchByExternalIdAndManagerId(HostManager, hostId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host != nil {
|
||||
return q.Equals("manager_id", host.ManagerId)
|
||||
}
|
||||
@@ -2589,7 +2590,7 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token
|
||||
SyncCloudProject(userCred, self, syncOwnerId, extVM, host.ManagerId)
|
||||
|
||||
if provider.GetFactory().IsSupportPrepaidResources() && recycle {
|
||||
vhost := self.GetHost()
|
||||
vhost, _ := self.GetHost()
|
||||
err = vhost.syncWithCloudPrepaidVM(extVM, host)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -2706,7 +2707,7 @@ func (self *SGuest) detachNetworks(ctx context.Context, userCred mcclient.TokenC
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host != nil {
|
||||
host.ClearSchedDescCache() // ignore error
|
||||
}
|
||||
@@ -2958,13 +2959,13 @@ func getCloudNicNetwork(ctx context.Context, vnic cloudprovider.ICloudNic, host
|
||||
vnet := vnic.GetINetwork()
|
||||
if vnet == nil {
|
||||
if vnic.InClassicNetwork() {
|
||||
region := host.GetRegion()
|
||||
region, _ := host.GetRegion()
|
||||
cloudprovider := host.GetCloudprovider()
|
||||
vpc, err := VpcManager.GetOrCreateVpcForClassicNetwork(ctx, cloudprovider, region)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "NewVpcForClassicNetwork")
|
||||
}
|
||||
zone := host.GetZone()
|
||||
zone, _ := host.GetZone()
|
||||
wire, err := WireManager.GetOrCreateWireForClassicNetwork(ctx, vpc, zone)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "NewWireForClassicNetwork")
|
||||
@@ -4154,7 +4155,7 @@ func (self *SGuest) GetJsonDescAtHypervisor(ctx context.Context, host *SHost) *j
|
||||
desc.Add(jsonutils.NewString(kvmOptions), "kvm")
|
||||
}
|
||||
|
||||
zone := self.getZone()
|
||||
zone, _ := self.getZone()
|
||||
if zone != nil {
|
||||
desc.Add(jsonutils.NewString(zone.Id), "zone_id")
|
||||
desc.Add(jsonutils.NewString(zone.Name), "zone")
|
||||
@@ -4270,7 +4271,7 @@ func (self *SGuest) GetJsonDescAtBaremetal(ctx context.Context, host *SHost) *js
|
||||
desc.Add(jsonutils.NewString(rules), "admin_security_rules")
|
||||
}
|
||||
|
||||
zone := self.getZone()
|
||||
zone, _ := self.getZone()
|
||||
if zone != nil {
|
||||
desc.Add(jsonutils.NewString(zone.Id), "zone_id")
|
||||
desc.Add(jsonutils.NewString(zone.Name), "zone")
|
||||
@@ -4473,7 +4474,7 @@ func (self *SGuest) GetShortDesc(ctx context.Context) *jsonutils.JSONDict {
|
||||
|
||||
desc.Set("hypervisor", jsonutils.NewString(self.GetHypervisor()))
|
||||
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
|
||||
spec := self.GetSpec(false)
|
||||
if self.GetHypervisor() == api.HYPERVISOR_BAREMETAL {
|
||||
@@ -4726,7 +4727,7 @@ func (manager *SGuestManager) getExpiredPostpaidGuests() []SGuest {
|
||||
}
|
||||
|
||||
func (self *SGuest) doExternalSync(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return fmt.Errorf("no host???")
|
||||
}
|
||||
@@ -4958,11 +4959,12 @@ func (self *SGuest) SyncVMEip(ctx context.Context, userCred mcclient.TokenCreden
|
||||
}
|
||||
}
|
||||
|
||||
region, _ := self.getRegion()
|
||||
if eip == nil && extEip == nil {
|
||||
// do nothing
|
||||
} else if eip == nil && extEip != nil {
|
||||
// add
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, extEip, provider, self.getRegion(), syncOwnerId)
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, extEip, provider, region, syncOwnerId)
|
||||
if err != nil {
|
||||
result.AddError(errors.Wrapf(err, "getEipByExtEip"))
|
||||
} else {
|
||||
@@ -4991,7 +4993,7 @@ func (self *SGuest) SyncVMEip(ctx context.Context, userCred mcclient.TokenCreden
|
||||
result.DeleteError(err)
|
||||
} else {
|
||||
result.Delete()
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, extEip, provider, self.getRegion(), syncOwnerId)
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, extEip, provider, region, syncOwnerId)
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
} else {
|
||||
@@ -5018,7 +5020,7 @@ func (self *SGuest) SyncVMEip(ctx context.Context, userCred mcclient.TokenCreden
|
||||
}
|
||||
|
||||
func (self *SGuest) getSecgroupsBySecgroupExternalIds(externalIds []string) ([]SSecurityGroup, error) {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return nil, errors.Error("not found host for guest")
|
||||
}
|
||||
@@ -5056,7 +5058,7 @@ func (self *SGuest) GetIVM() (cloudprovider.ICloudVM, error) {
|
||||
log.Errorf(msg)
|
||||
return nil, fmt.Errorf(msg)
|
||||
}
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
msg := fmt.Sprintf("GetIVM: No valid host")
|
||||
log.Errorf(msg)
|
||||
@@ -5143,7 +5145,7 @@ func (self *SGuest) SetDisableDelete(userCred mcclient.TokenCredential, val bool
|
||||
func (self *SGuest) getDefaultStorageType() string {
|
||||
diskCat := self.CategorizeDisks()
|
||||
if diskCat.Root != nil {
|
||||
rootStorage := diskCat.Root.GetStorage()
|
||||
rootStorage, _ := diskCat.Root.GetStorage()
|
||||
if rootStorage != nil {
|
||||
return rootStorage.StorageType
|
||||
}
|
||||
@@ -5257,7 +5259,8 @@ func (self *SGuest) OnScheduleToHost(ctx context.Context, userCred mcclient.Toke
|
||||
notes.Add(jsonutils.NewString(hostId), "host_id")
|
||||
db.OpsLog.LogEvent(self, db.ACT_SCHEDULE, notes, userCred)
|
||||
|
||||
return self.GetHost().ClearSchedDescCache()
|
||||
host, _ := self.GetHost()
|
||||
return host.ClearSchedDescCache()
|
||||
}
|
||||
|
||||
func (guest *SGuest) AllowGetDetailsTasks(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {
|
||||
@@ -5402,7 +5405,7 @@ func (self *SGuest) toCreateInput() *api.ServerCreateInput {
|
||||
if keypair := self.getKeypair(); keypair != nil {
|
||||
r.KeypairId = keypair.Id
|
||||
}
|
||||
if host := self.GetHost(); host != nil {
|
||||
if host, _ := self.GetHost(); host != nil {
|
||||
r.ResourceType = host.ResourceType
|
||||
}
|
||||
if eip, _ := self.GetEipOrPublicIp(); eip != nil {
|
||||
@@ -5417,8 +5420,9 @@ func (self *SGuest) toCreateInput() *api.ServerCreateInput {
|
||||
}
|
||||
}
|
||||
}
|
||||
if zone := self.getZone(); zone != nil {
|
||||
r.PreferRegion = zone.GetRegion().GetId()
|
||||
if zone, _ := self.getZone(); zone != nil {
|
||||
region, _ := zone.GetRegion()
|
||||
r.PreferRegion = region.GetId()
|
||||
r.PreferZone = zone.GetId()
|
||||
}
|
||||
return r
|
||||
@@ -5443,7 +5447,7 @@ func (self *SGuest) ToDisksConfig() []*api.DiskConfig {
|
||||
diskConf.Driver = guestDisk.Driver
|
||||
diskConf.Cache = guestDisk.CacheMode
|
||||
diskConf.Mountpoint = guestDisk.Mountpoint
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
diskConf.Backend = storage.StorageType
|
||||
diskConf.Medium = storage.MediumType
|
||||
ret[idx] = diskConf
|
||||
@@ -5671,7 +5675,7 @@ func (self *SGuest) GetDiskIndex(diskId string) int8 {
|
||||
}
|
||||
|
||||
func (guest *SGuest) GetRegionalQuotaKeys() (quotas.IQuotaKeys, error) {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "no valid host")
|
||||
}
|
||||
@@ -5679,7 +5683,7 @@ func (guest *SGuest) GetRegionalQuotaKeys() (quotas.IQuotaKeys, error) {
|
||||
if provider == nil && len(host.ManagerId) > 0 {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "no valid manager")
|
||||
}
|
||||
region := host.GetRegion()
|
||||
region, _ := host.GetRegion()
|
||||
if region == nil {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "no valid region")
|
||||
}
|
||||
@@ -5687,7 +5691,7 @@ func (guest *SGuest) GetRegionalQuotaKeys() (quotas.IQuotaKeys, error) {
|
||||
}
|
||||
|
||||
func (guest *SGuest) GetQuotaKeys() (quotas.IQuotaKeys, error) {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "no valid host")
|
||||
}
|
||||
@@ -5695,7 +5699,7 @@ func (guest *SGuest) GetQuotaKeys() (quotas.IQuotaKeys, error) {
|
||||
if provider == nil && len(host.ManagerId) > 0 {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "no valid manager")
|
||||
}
|
||||
zone := host.GetZone()
|
||||
zone, _ := host.GetZone()
|
||||
if zone == nil {
|
||||
return nil, errors.Wrap(httperrors.ErrInvalidStatus, "no valid zone")
|
||||
}
|
||||
|
||||
@@ -108,9 +108,9 @@ func ValidateScheduleCreateData(ctx context.Context, userCred mcclient.TokenCred
|
||||
input.PreferHost = baremetal.Id
|
||||
input.DefaultStorageType = defaultStorage.StorageType
|
||||
|
||||
zone := baremetal.GetZone()
|
||||
zone, _ := baremetal.GetZone()
|
||||
input.PreferZone = zone.Id
|
||||
region := zone.GetRegion()
|
||||
region, _ := zone.GetRegion()
|
||||
input.PreferRegion = region.Id
|
||||
} else {
|
||||
if len(input.Schedtags) > 0 {
|
||||
@@ -132,9 +132,9 @@ func ValidateScheduleCreateData(ctx context.Context, userCred mcclient.TokenCred
|
||||
}
|
||||
wire := wireObj.(*SWire)
|
||||
input.PreferWire = wire.Id
|
||||
zone := wire.GetZone()
|
||||
zone, _ := wire.GetZone()
|
||||
input.PreferZone = zone.Id
|
||||
region := zone.GetRegion()
|
||||
region, _ := zone.GetRegion()
|
||||
input.PreferRegion = region.Id
|
||||
} else if input.PreferZone != "" {
|
||||
zoneStr := input.PreferZone
|
||||
@@ -148,7 +148,7 @@ func ValidateScheduleCreateData(ctx context.Context, userCred mcclient.TokenCred
|
||||
}
|
||||
zone := zoneObj.(*SZone)
|
||||
input.PreferZone = zone.Id
|
||||
region := zone.GetRegion()
|
||||
region, _ := zone.GetRegion()
|
||||
input.PreferRegion = region.Id
|
||||
} else if input.PreferRegion != "" {
|
||||
regionStr := input.PreferRegion
|
||||
|
||||
@@ -57,7 +57,7 @@ func (self *SGuest) CanPerformPrepaidRecycle() error {
|
||||
if self.ExpiredAt.Before(time.Now()) {
|
||||
return fmt.Errorf("prepaid expired")
|
||||
}
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return fmt.Errorf("no host")
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func (self *SGuest) doPrepaidRecycle(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
|
||||
func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
oHost := self.GetHost()
|
||||
oHost, _ := self.GetHost()
|
||||
|
||||
fakeHost := SHost{}
|
||||
fakeHost.SetModelManager(HostManager, &fakeHost)
|
||||
@@ -127,7 +127,7 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien
|
||||
totalSize := 0
|
||||
for i := 0; i < len(guestdisks); i += 1 {
|
||||
disk := guestdisks[i].GetDisk()
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
|
||||
totalSize += disk.DiskSize
|
||||
|
||||
@@ -149,7 +149,8 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien
|
||||
fakeHost.StorageSize = totalSize
|
||||
fakeHost.StorageInfo = jsonutils.Marshal(&storageInfo)
|
||||
|
||||
fakeHost.ZoneId = self.getZone().GetId()
|
||||
zone, _ := self.getZone()
|
||||
fakeHost.ZoneId = zone.GetId()
|
||||
fakeHost.IsBaremetal = false
|
||||
fakeHost.IsMaintenance = false
|
||||
fakeHost.ResourceType = api.HostResourceTypePrepaidRecycle
|
||||
@@ -213,7 +214,7 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien
|
||||
var externalId string
|
||||
for i := 0; i < len(guestdisks); i += 1 {
|
||||
disk := guestdisks[i].GetDisk()
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if disk.BillingType == billing_api.BILLING_TYPE_PREPAID {
|
||||
storageSize += int64(disk.DiskSize)
|
||||
if len(externalId) == 0 {
|
||||
@@ -229,7 +230,7 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien
|
||||
}
|
||||
}
|
||||
|
||||
sysStorage := guestdisks[0].GetDisk().GetStorage()
|
||||
sysStorage, _ := guestdisks[0].GetDisk().GetStorage()
|
||||
|
||||
fakeStorage := SStorage{}
|
||||
fakeStorage.SetModelManager(StorageManager, &fakeStorage)
|
||||
@@ -308,7 +309,7 @@ func (self *SGuest) PerformUndoPrepaidRecycle(ctx context.Context, userCred mccl
|
||||
return nil, httperrors.NewInvalidStatusError("cannot undo recycle in status %s", self.Status)
|
||||
}
|
||||
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
|
||||
if host == nil {
|
||||
return nil, httperrors.NewInvalidStatusError("no valid host")
|
||||
@@ -450,7 +451,7 @@ func doUndoPrepaidRecycleNoLock(ctx context.Context, userCred mcclient.TokenCred
|
||||
// check disk data integrity
|
||||
for i := 0; i < len(guestdisks); i += 1 {
|
||||
disk := guestdisks[i].GetDisk()
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage.StorageType == api.STORAGE_LOCAL {
|
||||
oHostStorage := oHost.GetHoststorageByExternalId(storage.ExternalId)
|
||||
if oHostStorage == nil {
|
||||
@@ -478,7 +479,7 @@ func doUndoPrepaidRecycleNoLock(ctx context.Context, userCred mcclient.TokenCred
|
||||
|
||||
for i := 0; i < len(guestdisks); i += 1 {
|
||||
disk := guestdisks[i].GetDisk()
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
|
||||
if storage.StorageType == api.STORAGE_LOCAL {
|
||||
oHostStorage := oHost.GetHoststorageByExternalId(storage.ExternalId)
|
||||
@@ -514,7 +515,7 @@ func doUndoPrepaidRecycleNoLock(ctx context.Context, userCred mcclient.TokenCred
|
||||
}
|
||||
|
||||
func (self *SGuest) IsPrepaidRecycle() bool {
|
||||
host := self.GetHost()
|
||||
host, _ := self.GetHost()
|
||||
if host == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
+28
-31
@@ -456,7 +456,8 @@ func (manager *SHostManager) ListItemFilter(
|
||||
wires := []string{}
|
||||
for i := 0; i < len(nets); i++ {
|
||||
net := nets[i].GetNetwork()
|
||||
if net.GetVpc().Id != api.DEFAULT_VPC_ID {
|
||||
vpc, _ := net.GetVpc()
|
||||
if vpc.Id != api.DEFAULT_VPC_ID {
|
||||
q = q.IsNotEmpty("ovn_version")
|
||||
} else {
|
||||
if !utils.IsInStringArray(net.WireId, wires) {
|
||||
@@ -558,23 +559,20 @@ func (self *SHost) IsArmHost() bool {
|
||||
return self.CpuArchitecture == apis.OS_ARCH_AARCH64
|
||||
}
|
||||
|
||||
func (self *SHost) GetZone() *SZone {
|
||||
if len(self.ZoneId) == 0 {
|
||||
return nil
|
||||
func (self *SHost) GetZone() (*SZone, error) {
|
||||
zone, err := ZoneManager.FetchById(self.ZoneId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
zone, _ := ZoneManager.FetchById(self.ZoneId)
|
||||
if zone != nil {
|
||||
return zone.(*SZone)
|
||||
}
|
||||
return nil
|
||||
return zone.(*SZone), nil
|
||||
}
|
||||
|
||||
func (self *SHost) GetRegion() *SCloudregion {
|
||||
zone := self.GetZone()
|
||||
if zone != nil {
|
||||
return zone.GetRegion()
|
||||
func (self *SHost) GetRegion() (*SCloudregion, error) {
|
||||
zone, err := self.GetZone()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return zone.GetRegion()
|
||||
}
|
||||
|
||||
func (self *SHost) GetCpuCount() int {
|
||||
@@ -1991,7 +1989,7 @@ func (manager *SHostManager) newFromCloudHost(ctx context.Context, userCred mccl
|
||||
log.Errorf(msg)
|
||||
return nil, fmt.Errorf(msg)
|
||||
}
|
||||
izone = wire.GetZone()
|
||||
izone, _ = wire.GetZone()
|
||||
}
|
||||
|
||||
newName, err := db.GenerateName(manager, userCred, extHost.GetName())
|
||||
@@ -2203,7 +2201,8 @@ func (self *SHost) newCloudHostStorage(ctx context.Context, userCred mcclient.To
|
||||
if err == sql.ErrNoRows {
|
||||
// no cloud storage found, this may happen for on-premise host
|
||||
// create the storage right now
|
||||
storageObj, err = StorageManager.newFromCloudStorage(ctx, userCred, extStorage, provider, self.GetZone())
|
||||
zone, _ := self.GetZone()
|
||||
storageObj, err = StorageManager.newFromCloudStorage(ctx, userCred, extStorage, provider, zone)
|
||||
if err != nil {
|
||||
log.Errorf("create by cloud storage fail %s", err)
|
||||
return nil, err
|
||||
@@ -2752,11 +2751,11 @@ func (self *SHost) GetIZone() (cloudprovider.ICloudZone, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("No cloudprovider for host: %s", err)
|
||||
}
|
||||
zone := self.GetZone()
|
||||
zone, _ := self.GetZone()
|
||||
if zone == nil {
|
||||
return nil, fmt.Errorf("no zone for host???")
|
||||
}
|
||||
region := zone.GetRegion()
|
||||
region, _ := zone.GetRegion()
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("No region for zone???")
|
||||
}
|
||||
@@ -2786,11 +2785,9 @@ func (self *SHost) GetIHostAndProvider() (cloudprovider.ICloudHost, cloudprovide
|
||||
if provider.GetFactory().IsOnPremise() {
|
||||
iregion, err = provider.GetOnPremiseIRegion()
|
||||
} else {
|
||||
region := self.GetRegion()
|
||||
if region == nil {
|
||||
msg := "fail to find region of host???"
|
||||
log.Errorf(msg)
|
||||
return nil, nil, fmt.Errorf(msg)
|
||||
region, err := self.GetRegion()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "GetRegion")
|
||||
}
|
||||
iregion, err = provider.GetIRegionById(region.ExternalId)
|
||||
}
|
||||
@@ -2810,7 +2807,7 @@ func (self *SHost) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("No cloudprovider for host %s: %s", self.Name, err)
|
||||
}
|
||||
region := self.GetRegion()
|
||||
region, _ := self.GetRegion()
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("failed to find host %s region info", self.Name)
|
||||
}
|
||||
@@ -3039,7 +3036,7 @@ func (self *SHost) GetDetailsVnc(ctx context.Context, userCred mcclient.TokenCre
|
||||
if utils.IsInStringArray(self.Status, []string{api.BAREMETAL_READY, api.BAREMETAL_RUNNING}) {
|
||||
retval := jsonutils.NewDict()
|
||||
retval.Set("host_id", jsonutils.NewString(self.Id))
|
||||
zone := self.GetZone()
|
||||
zone, _ := self.GetZone()
|
||||
retval.Set("zone", jsonutils.NewString(zone.GetName()))
|
||||
return retval, nil
|
||||
}
|
||||
@@ -3334,7 +3331,7 @@ func (manager *SHostManager) ValidateCreateData(
|
||||
return input, errors.Wrap(err, "net.reserveIpWithDuration")
|
||||
}
|
||||
}
|
||||
zoneObj := net.GetZone()
|
||||
zoneObj, _ := net.GetZone()
|
||||
if zoneObj == nil {
|
||||
return input, httperrors.NewInputParameterError("IPMI network has no zone???")
|
||||
}
|
||||
@@ -3401,7 +3398,7 @@ func (manager *SHostManager) ValidateCreateData(
|
||||
return input, httperrors.NewConflictError("Access ip %s has been used", accessIpAddr)
|
||||
}
|
||||
|
||||
zoneObj := accessNet.GetZone()
|
||||
zoneObj, _ := accessNet.GetZone()
|
||||
if zoneObj == nil {
|
||||
return input, httperrors.NewInputParameterError("Access network has no zone???")
|
||||
}
|
||||
@@ -3487,7 +3484,7 @@ func (self *SHost) ValidateUpdateData(ctx context.Context, userCred mcclient.Tok
|
||||
if net == nil {
|
||||
return input, httperrors.NewInputParameterError("%s is out of network IP ranges", ipmiIpAddr)
|
||||
}
|
||||
zoneObj := net.GetZone()
|
||||
zoneObj, _ := net.GetZone()
|
||||
if zoneObj == nil {
|
||||
return input, httperrors.NewInputParameterError("IPMI network has not zone???")
|
||||
}
|
||||
@@ -5285,9 +5282,9 @@ func (manager *SHostManager) GetHostByIp(hostIp string) (*SHost, error) {
|
||||
|
||||
func (self *SHost) getCloudProviderInfo() SCloudProviderInfo {
|
||||
var region *SCloudregion
|
||||
zone := self.GetZone()
|
||||
zone, _ := self.GetZone()
|
||||
if zone != nil {
|
||||
region = zone.GetRegion()
|
||||
region, _ = zone.GetRegion()
|
||||
}
|
||||
provider := self.GetCloudprovider()
|
||||
return MakeCloudProviderInfo(region, zone, provider)
|
||||
@@ -5866,7 +5863,7 @@ func GetHostQuotaKeysFromCreateInput(owner mcclient.IIdentityProvider, input api
|
||||
}
|
||||
|
||||
func (model *SHost) GetQuotaKeys() quotas.SDomainRegionalCloudResourceKeys {
|
||||
zone := model.GetZone()
|
||||
zone, _ := model.GetZone()
|
||||
manager := model.GetCloudprovider()
|
||||
ownerId := model.GetOwnerId()
|
||||
zoneKeys := fetchZonalQuotaKeys(rbacutils.ScopeDomain, ownerId, zone, manager)
|
||||
|
||||
@@ -245,7 +245,7 @@ func (self *SInstanceSnapshot) getMoreDetails(userCred mcclient.TokenCredential,
|
||||
if err != nil {
|
||||
log.Errorf("unable to GetSystemDisk of guest %q", guest.GetId())
|
||||
} else {
|
||||
s := disk.GetStorage()
|
||||
s, _ := disk.GetStorage()
|
||||
if s != nil {
|
||||
out.StorageType = s.StorageType
|
||||
}
|
||||
@@ -307,9 +307,9 @@ func (manager *SInstanceSnapshotManager) fillInstanceSnapshot(userCred mcclient.
|
||||
instanceSnapshot.GuestId = guest.Id
|
||||
guestSchedInput := guest.ToSchedDesc()
|
||||
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
instanceSnapshot.ManagerId = host.ManagerId
|
||||
zone := host.GetZone()
|
||||
zone, _ := host.GetZone()
|
||||
instanceSnapshot.CloudregionId = zone.CloudregionId
|
||||
|
||||
for i := 0; i < len(guestSchedInput.Disks); i++ {
|
||||
@@ -634,8 +634,8 @@ func (ism *SInstanceSnapshotManager) InitializeData() error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to GetGuest for isp %q", isp.GetId())
|
||||
} else {
|
||||
host := guest.GetHost()
|
||||
zone := host.GetZone()
|
||||
host, _ := guest.GetHost()
|
||||
zone, _ := host.GetZone()
|
||||
cloudregionId = zone.CloudregionId
|
||||
}
|
||||
_, err = db.Update(isp, func() error {
|
||||
|
||||
@@ -224,7 +224,7 @@ func (man *SLoadbalancerBackendGroupManager) ValidateCreateData(ctx context.Cont
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
guest := _guest.(*SGuest)
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, fmt.Errorf("error getting host of guest %s", guest.Name)
|
||||
}
|
||||
@@ -239,7 +239,7 @@ func (man *SLoadbalancerBackendGroupManager) ValidateCreateData(ctx context.Cont
|
||||
return nil, err
|
||||
}
|
||||
backends[i].Address = address
|
||||
backendRegion = host.GetRegion()
|
||||
backendRegion, _ = host.GetRegion()
|
||||
case api.LB_BACKEND_HOST:
|
||||
if !db.IsAdminAllowCreate(userCred, man) {
|
||||
return nil, httperrors.NewForbiddenError("only sysadmin can specify host as backend")
|
||||
@@ -256,7 +256,7 @@ func (man *SLoadbalancerBackendGroupManager) ValidateCreateData(ctx context.Cont
|
||||
backends[i].Name = host.Name
|
||||
backends[i].ExternalID = host.ExternalId
|
||||
backends[i].Address = host.AccessIp
|
||||
backendRegion = host.GetRegion()
|
||||
backendRegion, _ = host.GetRegion()
|
||||
default:
|
||||
return nil, httperrors.NewInputParameterError("unexpected backend type %s", backends[i].BackendType)
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ func (man *SLoadbalancerManager) ValidateCreateData(
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ValidateZoneResourceInput")
|
||||
}
|
||||
region = zone.GetRegion()
|
||||
region, _ = zone.GetRegion()
|
||||
} else if len(input.NetworkId) > 0 {
|
||||
if strings.IndexByte(input.NetworkId, ',') >= 0 {
|
||||
input.NetworkId = strings.Split(input.NetworkId, ",")[0]
|
||||
@@ -325,7 +325,7 @@ func (man *SLoadbalancerManager) ValidateCreateData(
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ValidateNetworkResourceInput")
|
||||
}
|
||||
region = network.GetRegion()
|
||||
region, _ = network.GetRegion()
|
||||
}
|
||||
|
||||
if region == nil {
|
||||
@@ -429,11 +429,13 @@ func (lb *SLoadbalancer) GetCloudproviderId() string {
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetZone() *SZone {
|
||||
return lb.SZoneResourceBase.GetZone()
|
||||
zone, _ := lb.SZoneResourceBase.GetZone()
|
||||
return zone
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetVpc() *SVpc {
|
||||
return lb.SVpcResourceBase.GetVpc()
|
||||
vpc, _ := lb.SVpcResourceBase.GetVpc()
|
||||
return vpc
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetNetworks() ([]SNetwork, error) {
|
||||
@@ -590,10 +592,10 @@ func (lb *SLoadbalancer) ValidateUpdateData(ctx context.Context, userCred mcclie
|
||||
}
|
||||
if clusterV.Model != nil {
|
||||
var (
|
||||
cluster = clusterV.Model.(*SLoadbalancerCluster)
|
||||
network = lb.GetNetwork()
|
||||
wire = network.GetWire()
|
||||
zone = wire.GetZone()
|
||||
cluster = clusterV.Model.(*SLoadbalancerCluster)
|
||||
network, _ = lb.GetNetwork()
|
||||
wire, _ = network.GetWire()
|
||||
zone, _ = wire.GetZone()
|
||||
)
|
||||
if cluster.ZoneId != zone.Id {
|
||||
return nil, httperrors.NewInputParameterError("cluster zone %s does not match network zone %s ",
|
||||
|
||||
@@ -132,7 +132,7 @@ func (manager *SMountTargetManager) ValidateCreateData(ctx context.Context, user
|
||||
return input, err
|
||||
}
|
||||
network := _network.(*SNetwork)
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return input, httperrors.NewGeneralError(fmt.Errorf("failed to found vpc for network %s", input.NetworkId))
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ func (man *SNatGatewayManager) ValidateCreateData(ctx context.Context, userCred
|
||||
return input, err
|
||||
}
|
||||
network := _network.(*SNetwork)
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return input, httperrors.NewGeneralError(errors.Errorf("failed to get network %s %s vpc", network.Name, network.Id))
|
||||
}
|
||||
@@ -648,7 +648,8 @@ func (self *SNatGateway) SyncNatGatewayEips(ctx context.Context, userCred mcclie
|
||||
}
|
||||
|
||||
for i := 0; i < len(added); i += 1 {
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, added[i], provider, self.GetRegion(), provider.GetOwnerId())
|
||||
region, _ := self.GetRegion()
|
||||
neip, err := ElasticipManager.getEipByExtEip(ctx, userCred, added[i], provider, region, provider.GetOwnerId())
|
||||
if err != nil {
|
||||
result.AddError(err)
|
||||
continue
|
||||
@@ -955,7 +956,8 @@ func (self *SNatGateway) PerformRenew(ctx context.Context, userCred mcclient.Tok
|
||||
return nil, httperrors.NewInputParameterError("invalid duration %s: %s", input.Duration, err)
|
||||
}
|
||||
|
||||
if !self.GetRegion().GetDriver().IsSupportedBillingCycle(bc, NatGatewayManager.KeywordPlural()) {
|
||||
region, _ := self.GetRegion()
|
||||
if !region.GetDriver().IsSupportedBillingCycle(bc, NatGatewayManager.KeywordPlural()) {
|
||||
return nil, httperrors.NewInputParameterError("unsupported duration %s", input.Duration)
|
||||
}
|
||||
|
||||
@@ -1001,7 +1003,7 @@ func (self *SNatGateway) PerformSetAutoRenew(ctx context.Context, userCred mccli
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
region := self.GetRegion()
|
||||
region, _ := self.GetRegion()
|
||||
if region == nil {
|
||||
return nil, httperrors.NewGeneralError(fmt.Errorf("filed to get nat %s region", self.Name))
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ func (man *SNatSEntryManager) ValidateCreateData(ctx context.Context, userCred m
|
||||
return nil, err
|
||||
}
|
||||
network := _network.(*SNetwork)
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, httperrors.NewGeneralError(errors.Wrapf(err, "network.GetVpc"))
|
||||
}
|
||||
|
||||
@@ -52,45 +52,44 @@ func ValidateNetworkResourceInput(userCred mcclient.TokenCredential, query api.N
|
||||
return netObj.(*SNetwork), query, nil
|
||||
}
|
||||
|
||||
func (self *SNetworkResourceBase) GetNetwork() *SNetwork {
|
||||
obj, _ := NetworkManager.FetchById(self.NetworkId)
|
||||
if obj != nil {
|
||||
return obj.(*SNetwork)
|
||||
func (self *SNetworkResourceBase) GetNetwork() (*SNetwork, error) {
|
||||
obj, err := NetworkManager.FetchById(self.NetworkId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetNetwork(%s)", self.NetworkId)
|
||||
}
|
||||
return nil
|
||||
return obj.(*SNetwork), nil
|
||||
}
|
||||
|
||||
func (self *SNetworkResourceBase) GetWire() *SWire {
|
||||
net := self.GetNetwork()
|
||||
if net != nil {
|
||||
return net.GetWire()
|
||||
func (self *SNetworkResourceBase) GetWire() (*SWire, error) {
|
||||
net, err := self.GetNetwork()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return net.GetWire()
|
||||
}
|
||||
|
||||
func (self *SNetworkResourceBase) GetZone() *SZone {
|
||||
wire := self.GetWire()
|
||||
if wire != nil {
|
||||
return wire.GetZone()
|
||||
func (self *SNetworkResourceBase) GetZone() (*SZone, error) {
|
||||
wire, err := self.GetWire()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return wire.GetZone()
|
||||
}
|
||||
|
||||
func (self *SNetworkResourceBase) GetVpc() *SVpc {
|
||||
wire := self.GetWire()
|
||||
if wire != nil {
|
||||
return wire.GetVpc()
|
||||
func (self *SNetworkResourceBase) GetVpc() (*SVpc, error) {
|
||||
wire, err := self.GetWire()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil
|
||||
return wire.GetVpc()
|
||||
}
|
||||
|
||||
func (self *SNetworkResourceBase) GetRegion() *SCloudregion {
|
||||
vpc := self.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil
|
||||
func (self *SNetworkResourceBase) GetRegion() (*SCloudregion, error) {
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
region, _ := vpc.GetRegion()
|
||||
return region
|
||||
return vpc.GetRegion()
|
||||
}
|
||||
|
||||
func (self *SNetworkResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.NetworkResourceInfo, error) {
|
||||
@@ -258,7 +257,7 @@ func (manager *SNetworkResourceBaseManager) GetExportKeys() []string {
|
||||
}
|
||||
|
||||
func (self *SNetworkResourceBase) GetChangeOwnerCandidateDomainIds() []string {
|
||||
network := self.GetNetwork()
|
||||
network, _ := self.GetNetwork()
|
||||
if network != nil {
|
||||
return network.GetChangeOwnerCandidateDomainIds()
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func (manager *SNetworkManager) AllowCreateItem(ctx context.Context, userCred mc
|
||||
func (self *SNetwork) getMtu() int {
|
||||
baseMtu := options.Options.DefaultMtu
|
||||
|
||||
wire := self.GetWire()
|
||||
wire, _ := self.GetWire()
|
||||
if wire != nil {
|
||||
baseMtu = wire.Mtu
|
||||
if IsOneCloudVpcResource(wire) {
|
||||
@@ -357,25 +357,25 @@ func (self *SNetwork) ValidateElbNetwork(ipAddr net.IP) (*SCloudregion, *SZone,
|
||||
}
|
||||
|
||||
// 验证网络可用
|
||||
wire := self.GetWire()
|
||||
wire, _ := self.GetWire()
|
||||
if wire == nil {
|
||||
return nil, nil, nil, nil, fmt.Errorf("getting wire failed")
|
||||
}
|
||||
|
||||
vpc := wire.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, nil, nil, nil, fmt.Errorf("getting vpc failed")
|
||||
vpc, err := wire.GetVpc()
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, errors.Wrapf(err, "GetVpc")
|
||||
}
|
||||
|
||||
var zone *SZone
|
||||
if len(wire.ZoneId) > 0 {
|
||||
zone = wire.GetZone()
|
||||
zone, _ = wire.GetZone()
|
||||
if zone == nil {
|
||||
return nil, nil, nil, nil, fmt.Errorf("getting zone failed")
|
||||
}
|
||||
}
|
||||
|
||||
region := wire.GetRegion()
|
||||
region, _ := wire.GetRegion()
|
||||
if region == nil {
|
||||
return nil, nil, nil, nil, fmt.Errorf("getting region failed")
|
||||
}
|
||||
@@ -444,7 +444,7 @@ func (self *SNetwork) GetNetworkInterfacesCount() (int, error) {
|
||||
|
||||
func (manager *SNetworkManager) GetOrCreateClassicNetwork(ctx context.Context, wire *SWire) (*SNetwork, error) {
|
||||
_network, err := db.FetchByExternalIdAndManagerId(manager, wire.Id, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
v := wire.GetVpc()
|
||||
v, _ := wire.GetVpc()
|
||||
if v != nil {
|
||||
wire := WireManager.Query().SubQuery()
|
||||
vpc := VpcManager.Query().SubQuery()
|
||||
@@ -820,7 +820,7 @@ func (self *SNetwork) syncRemoveCloudNetwork(ctx context.Context, userCred mccli
|
||||
}
|
||||
|
||||
func (self *SNetwork) SyncWithCloudNetwork(ctx context.Context, userCred mcclient.TokenCredential, extNet cloudprovider.ICloudNetwork, syncOwnerId mcclient.IIdentityProvider, provider *SCloudprovider) error {
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
diff, err := db.UpdateWithLock(ctx, self, func() error {
|
||||
extNet.Refresh()
|
||||
self.Status = extNet.GetStatus()
|
||||
@@ -889,7 +889,7 @@ func (manager *SNetworkManager) newFromCloudNetwork(ctx context.Context, userCre
|
||||
return nil, err
|
||||
}
|
||||
|
||||
vpc := wire.GetVpc()
|
||||
vpc, _ := wire.GetVpc()
|
||||
syncVirtualResourceMetadata(ctx, userCred, &net, extNet)
|
||||
SyncCloudProject(userCred, &net, syncOwnerId, extNet, vpc.ManagerId)
|
||||
|
||||
@@ -1414,7 +1414,7 @@ func (manager *SNetworkManager) validateEnsureWire(ctx context.Context, userCred
|
||||
return
|
||||
}
|
||||
w = wObj.(*SWire)
|
||||
v = w.GetVpc()
|
||||
v, _ = w.GetVpc()
|
||||
crObj, err := CloudregionManager.FetchById(v.CloudregionId)
|
||||
if err != nil {
|
||||
err = errors.Wrapf(err, "cloudregion %s", v.CloudregionId)
|
||||
@@ -1446,7 +1446,7 @@ func (manager *SNetworkManager) validateEnsureZoneVpc(ctx context.Context, userC
|
||||
|
||||
var wires []SWire
|
||||
// 华为云,ucloud wire zone_id 为空
|
||||
cr = z.GetRegion()
|
||||
cr, _ = z.GetRegion()
|
||||
if utils.IsInStringArray(cr.Provider, api.REGIONAL_NETWORK_PROVIDERS) {
|
||||
wires, err = WireManager.getWiresByVpcAndZone(v, nil)
|
||||
} else {
|
||||
@@ -1722,7 +1722,7 @@ func (self *SNetwork) validateUpdateData(ctx context.Context, userCred mcclient.
|
||||
}
|
||||
|
||||
netRange := netutils.NewIPV4AddrRange(startIp, endIp)
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
if !vpc.containsIPV4Range(netRange) {
|
||||
return input, httperrors.NewInputParameterError("Network not in range of VPC cidrblock %s", vpc.CidrBlock)
|
||||
}
|
||||
@@ -1836,7 +1836,7 @@ func isOverlapNetworks(nets []SNetwork, startIp netutils.IPV4Addr, endIp netutil
|
||||
}
|
||||
|
||||
func (self *SNetwork) IsManaged() bool {
|
||||
wire := self.GetWire()
|
||||
wire, _ := self.GetWire()
|
||||
if wire == nil {
|
||||
return false
|
||||
}
|
||||
@@ -1846,7 +1846,7 @@ func (self *SNetwork) IsManaged() bool {
|
||||
func (self *SNetwork) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
if !data.Contains("public_scope") {
|
||||
if self.ServerType == api.NETWORK_TYPE_GUEST && !self.IsManaged() {
|
||||
wire := self.GetWire()
|
||||
wire, _ := self.GetWire()
|
||||
if db.IsAdminAllowPerform(userCred, self, "public") && ownerId.GetProjectDomainId() == userCred.GetProjectDomainId() && wire != nil && wire.IsPublic && wire.PublicScope == string(rbacutils.ScopeSystem) {
|
||||
self.SetShare(rbacutils.ScopeSystem)
|
||||
} else if db.IsDomainAllowPerform(userCred, self, "public") && ownerId.GetProjectId() == userCred.GetProjectId() && consts.GetNonDefaultDomainProjects() {
|
||||
@@ -1865,7 +1865,7 @@ func (self *SNetwork) CustomizeCreate(ctx context.Context, userCred mcclient.Tok
|
||||
|
||||
func (self *SNetwork) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
self.SSharableVirtualResourceBase.PostCreate(ctx, userCred, ownerId, query, data)
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
if vpc != nil && vpc.IsManaged() {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "NetworkCreateTask", self, userCred, nil, "", "", nil)
|
||||
if err != nil {
|
||||
@@ -1953,11 +1953,9 @@ func (self *SNetwork) StartDeleteNetworkTask(ctx context.Context, userCred mccli
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetINetwork() (cloudprovider.ICloudNetwork, error) {
|
||||
wire := self.GetWire()
|
||||
if wire == nil {
|
||||
msg := "No wire for this network????"
|
||||
log.Errorf(msg)
|
||||
return nil, fmt.Errorf(msg)
|
||||
wire, err := self.GetWire()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetWire")
|
||||
}
|
||||
iwire, err := wire.GetIWire()
|
||||
if err != nil {
|
||||
@@ -2366,7 +2364,7 @@ func (self *SNetwork) PerformPurge(ctx context.Context, userCred mcclient.TokenC
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
if vpc != nil && len(vpc.ExternalId) > 0 {
|
||||
provider := vpc.GetCloudprovider()
|
||||
if provider != nil && provider.GetEnabled() {
|
||||
@@ -2765,7 +2763,7 @@ func (network *SNetwork) GetSchedtagJointManager() ISchedtagJointManager {
|
||||
}
|
||||
|
||||
func (network *SNetwork) ClearSchedDescCache() error {
|
||||
wire := network.GetWire()
|
||||
wire, _ := network.GetWire()
|
||||
if wire == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -2851,7 +2849,7 @@ func (net *SNetwork) AllowPerformSync(ctx context.Context, userCred mcclient.Tok
|
||||
// 同步接入云IP子网状态
|
||||
// 本地IDC不支持此操作
|
||||
func (net *SNetwork) PerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input *api.NetworkSyncInput) (jsonutils.JSONObject, error) {
|
||||
vpc := net.GetVpc()
|
||||
vpc, _ := net.GetVpc()
|
||||
if vpc != nil && vpc.IsManaged() {
|
||||
return nil, StartResourceSyncStatusTask(ctx, userCred, net, "NetworkSyncstatusTask", "")
|
||||
}
|
||||
@@ -2867,7 +2865,7 @@ func (net *SNetwork) PerformStatus(ctx context.Context, userCred mcclient.TokenC
|
||||
if len(input.Status) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("status")
|
||||
}
|
||||
vpc := net.GetVpc()
|
||||
vpc, _ := net.GetVpc()
|
||||
if vpc != nil && vpc.IsManaged() {
|
||||
return nil, httperrors.NewUnsupportOperationError("managed network cannot change status")
|
||||
}
|
||||
@@ -2879,9 +2877,9 @@ func (net *SNetwork) PerformStatus(ctx context.Context, userCred mcclient.TokenC
|
||||
|
||||
func (net *SNetwork) GetChangeOwnerCandidateDomainIds() []string {
|
||||
candidates := [][]string{}
|
||||
wire := net.GetWire()
|
||||
wire, _ := net.GetWire()
|
||||
if wire != nil {
|
||||
vpc := wire.GetVpc()
|
||||
vpc, _ := wire.GetVpc()
|
||||
if vpc != nil {
|
||||
candidates = append(candidates, vpc.GetChangeOwnerCandidateDomainIds())
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ func (self *SRouteTableAssociation) syncWithCloudAssociation(ctx context.Context
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "self.GetRouteTable()")
|
||||
}
|
||||
vpc := routeTable.GetVpc()
|
||||
vpc, _ := routeTable.GetVpc()
|
||||
subnet, err := vpc.GetNetworkByExtId(cloudAssociation.AssociatedResourceId)
|
||||
if err == nil {
|
||||
AssociatedResourceId = subnet.GetId()
|
||||
@@ -145,7 +145,7 @@ func (manager *SRouteTableAssociationManager) newAssociationFromCloud(
|
||||
association.RouteTableId = routeTable.GetId()
|
||||
association.ExternalId = cloudAssociation.GetGlobalId()
|
||||
if association.AssociationType == string(cloudprovider.RouteTableAssociaToSubnet) {
|
||||
vpc := routeTable.GetVpc()
|
||||
vpc, _ := routeTable.GetVpc()
|
||||
subnet, err := vpc.GetNetworkByExtId(association.ExtAssociatedResourceId)
|
||||
if err == nil {
|
||||
association.AssociatedResourceId = subnet.GetId()
|
||||
|
||||
@@ -143,7 +143,7 @@ func (manager *SRouteTableRouteSetManager) ValidateCreateData(
|
||||
input.ExtNextHopId = vpcPeer.GetExternalId()
|
||||
}
|
||||
|
||||
vpc := routeTable.GetVpc()
|
||||
vpc, _ := routeTable.GetVpc()
|
||||
account := vpc.GetCloudaccount()
|
||||
factory, err := account.GetProviderFactory()
|
||||
if err != nil {
|
||||
@@ -312,7 +312,7 @@ func (self *SRouteTableRouteSet) GetVpc() (*SVpc, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "self.GetRouteTable()")
|
||||
}
|
||||
return routeTable.GetVpc(), nil
|
||||
return routeTable.GetVpc()
|
||||
}
|
||||
|
||||
func (self *SRouteTableRouteSet) syncRemoveRouteSet(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
@@ -378,7 +378,7 @@ func (manager *SRouteTableRouteSetManager) newRouteSetFromCloud(ctx context.Cont
|
||||
routeSet.ExternalId = cloudRouteSet.GetGlobalId()
|
||||
routeSet.SetModelManager(manager, routeSet)
|
||||
if cloudRouteSet.GetNextHopType() == api.Next_HOP_TYPE_VPCPEERING {
|
||||
vpc := routeTable.GetVpc()
|
||||
vpc, _ := routeTable.GetVpc()
|
||||
vpcPeer, err := vpc.GetVpcPeeringConnectionByExtId(cloudRouteSet.GetNextHop())
|
||||
if err == nil {
|
||||
routeSet.NextHopId = vpcPeer.GetId()
|
||||
|
||||
@@ -164,7 +164,7 @@ func (sgm *SScalingGroupManager) ValidateCreateData(ctx context.Context, userCre
|
||||
|
||||
// check networks in vpc
|
||||
for i := range networks {
|
||||
vpc := networks[i].GetVpc()
|
||||
vpc, _ := networks[i].GetVpc()
|
||||
if vpc == nil {
|
||||
return input, fmt.Errorf("Get vpc of network '%s' failed", networks[i].Id)
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ func (self *SServerSkuManager) ValidateCreateData(ctx context.Context, userCred
|
||||
if input.CloudregionId != zone.CloudregionId {
|
||||
return input, httperrors.NewConflictError("zone %s not in cloudregion %s", zone.Name, input.CloudregionId)
|
||||
}
|
||||
region = zone.GetRegion()
|
||||
region, _ = zone.GetRegion()
|
||||
}
|
||||
|
||||
if input.CpuCoreCount < 1 || input.CpuCoreCount > 256 {
|
||||
@@ -798,7 +798,7 @@ func (manager *SServerSkuManager) ListItemFilter(
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
zone := _zone.(*SZone)
|
||||
region := zone.GetRegion()
|
||||
region, _ := zone.GetRegion()
|
||||
if region == nil {
|
||||
return nil, httperrors.NewResourceNotFoundError("failed to find cloudregion for zone %s(%s)", zone.Name, zone.Id)
|
||||
}
|
||||
|
||||
@@ -321,7 +321,8 @@ func (m *SSnapshotPolicyDiskManager) SyncByDisk(ctx context.Context, userCred mc
|
||||
}
|
||||
|
||||
//fetch snapshotPolicy Cache to find the snapshotpolicyID corresponding to extSnapshotpolicyID
|
||||
spCaches, err := SnapshotPolicyCacheManager.FetchAllByExtIds(extSnapshotpolicies, storage.GetRegion().GetId(),
|
||||
region, _ := storage.GetRegion()
|
||||
spCaches, err := SnapshotPolicyCacheManager.FetchAllByExtIds(extSnapshotpolicies, region.GetId(),
|
||||
storage.ManagerId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "fetachsnapshotpolicy caches failed")
|
||||
@@ -402,7 +403,8 @@ func (m *SSnapshotPolicyDiskManager) SyncAttachDiskExt(ctx context.Context, user
|
||||
extSnapshotpolicies []string, syncOwnerID mcclient.IIdentityProvider, disk *SDisk, storage *SStorage) error {
|
||||
|
||||
//fetch snapshotPolicy Cache to find the snapshotpolicyID corresponding to extSnapshotpolicyID
|
||||
spCaches, err := SnapshotPolicyCacheManager.FetchAllByExtIds(extSnapshotpolicies, storage.GetRegion().GetId(),
|
||||
region, _ := storage.GetRegion()
|
||||
spCaches, err := SnapshotPolicyCacheManager.FetchAllByExtIds(extSnapshotpolicies, region.GetId(),
|
||||
storage.ManagerId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "fetachsnapshotpolicy caches failed")
|
||||
@@ -491,7 +493,9 @@ func (self *SSnapshotPolicyDiskManager) ValidateCreateData(ctx context.Context,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = disk.GetStorage().GetRegion().GetDriver().ValidateCreateSnapshopolicyDiskData(ctx, userCred, disk, snapshotPolicy)
|
||||
storage, _ := disk.GetStorage()
|
||||
region, _ := storage.GetRegion()
|
||||
err = region.GetDriver().ValidateCreateSnapshopolicyDiskData(ctx, userCred, disk, snapshotPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -359,12 +359,12 @@ func (manager *SSnapshotManager) ValidateCreateData(
|
||||
input.Size = disk.DiskSize
|
||||
input.OsArch = disk.OsArch
|
||||
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if len(disk.ExternalId) == 0 {
|
||||
input.StorageId = disk.StorageId
|
||||
}
|
||||
input.ManagerId = storage.ManagerId
|
||||
region := storage.GetRegion()
|
||||
region, _ := storage.GetRegion()
|
||||
if region == nil {
|
||||
return input, httperrors.NewInputParameterError("failed to found region for disk's storage %s(%s)", storage.Name, storage.Id)
|
||||
}
|
||||
@@ -559,7 +559,7 @@ func (self *SSnapshotManager) CreateSnapshot(ctx context.Context, owner mcclient
|
||||
return nil, err
|
||||
}
|
||||
disk := iDisk.(*SDisk)
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
snapshot := &SSnapshot{}
|
||||
snapshot.SetModelManager(self, snapshot)
|
||||
snapshot.ProjectId = owner.GetProjectId()
|
||||
@@ -578,7 +578,7 @@ func (self *SSnapshotManager) CreateSnapshot(ctx context.Context, owner mcclient
|
||||
snapshot.Location = location
|
||||
snapshot.CreatedBy = createdBy
|
||||
snapshot.ManagerId = storage.ManagerId
|
||||
if cloudregion := storage.GetRegion(); cloudregion != nil {
|
||||
if cloudregion, _ := storage.GetRegion(); cloudregion != nil {
|
||||
snapshot.CloudregionId = cloudregion.GetId()
|
||||
}
|
||||
snapshot.Name = name
|
||||
|
||||
@@ -147,7 +147,7 @@ func (self *SStoragecache) GetRegion() (*SCloudregion, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
region := host.GetRegion()
|
||||
region, _ := host.GetRegion()
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("failed to get region for host %s(%s)", host.Name, host.Id)
|
||||
}
|
||||
|
||||
@@ -574,18 +574,22 @@ func (self *SStorage) GetZoneId() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SStorage) getZone() *SZone {
|
||||
func (self *SStorage) getZone() (*SZone, error) {
|
||||
zoneId := self.GetZoneId()
|
||||
if len(zoneId) > 0 {
|
||||
return ZoneManager.FetchZoneById(zoneId)
|
||||
zone, err := ZoneManager.FetchById(zoneId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetZone(%s)", zoneId)
|
||||
}
|
||||
return zone.(*SZone), nil
|
||||
}
|
||||
return nil
|
||||
return nil, fmt.Errorf("empty zoneId for storage %s(%s)", self.Name, self.Id)
|
||||
}
|
||||
|
||||
func (self *SStorage) GetRegion() *SCloudregion {
|
||||
zone := self.getZone()
|
||||
if zone == nil {
|
||||
return nil
|
||||
func (self *SStorage) GetRegion() (*SCloudregion, error) {
|
||||
zone, err := self.getZone()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return zone.GetRegion()
|
||||
}
|
||||
@@ -1295,7 +1299,7 @@ func (self *SStorage) GetIStorage() (cloudprovider.ICloudStorage, error) {
|
||||
if provider.GetFactory().IsOnPremise() {
|
||||
iRegion, err = provider.GetOnPremiseIRegion()
|
||||
} else {
|
||||
region := self.GetRegion()
|
||||
region, _ := self.GetRegion()
|
||||
if region == nil {
|
||||
msg := "cannot find region for storage???"
|
||||
log.Errorf(msg)
|
||||
@@ -1546,9 +1550,9 @@ func (self *SStorage) ClearSchedDescCache() error {
|
||||
|
||||
func (self *SStorage) getCloudProviderInfo() SCloudProviderInfo {
|
||||
var region *SCloudregion
|
||||
zone := self.getZone()
|
||||
zone, _ := self.getZone()
|
||||
if zone != nil {
|
||||
region = zone.GetRegion()
|
||||
region, _ = zone.GetRegion()
|
||||
}
|
||||
provider := self.GetCloudprovider()
|
||||
return MakeCloudProviderInfo(region, zone, provider)
|
||||
|
||||
@@ -33,8 +33,8 @@ import (
|
||||
)
|
||||
|
||||
type IVpcResource interface {
|
||||
GetVpc() *SVpc
|
||||
GetRegion() *SCloudregion
|
||||
GetVpc() (*SVpc, error)
|
||||
GetRegion() (*SCloudregion, error)
|
||||
}
|
||||
|
||||
type SVpcResourceBase struct {
|
||||
@@ -46,42 +46,41 @@ type SVpcResourceBaseManager struct {
|
||||
SManagedResourceBaseManager
|
||||
}
|
||||
|
||||
func (self *SVpcResourceBase) GetVpc() *SVpc {
|
||||
obj, _ := VpcManager.FetchById(self.VpcId)
|
||||
if obj == nil {
|
||||
return nil
|
||||
func (self *SVpcResourceBase) GetVpc() (*SVpc, error) {
|
||||
obj, err := VpcManager.FetchById(self.VpcId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetVpc(%s)", self.VpcId)
|
||||
}
|
||||
return obj.(*SVpc)
|
||||
return obj.(*SVpc), nil
|
||||
}
|
||||
|
||||
func (self *SVpcResourceBase) GetRegion() *SCloudregion {
|
||||
vpc := self.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil
|
||||
func (self *SVpcResourceBase) GetRegion() (*SCloudregion, error) {
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
region, _ := vpc.GetRegion()
|
||||
return region
|
||||
return vpc.GetRegion()
|
||||
}
|
||||
|
||||
func (self *SVpcResourceBase) GetRegionId() string {
|
||||
region := self.GetRegion()
|
||||
if region != nil {
|
||||
return region.Id
|
||||
region, err := self.GetRegion()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
return region.Id
|
||||
}
|
||||
|
||||
func (self *SVpcResourceBase) GetIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
vpc := self.GetVpc()
|
||||
if vpc != nil {
|
||||
return vpc.GetIRegion()
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetVpc")
|
||||
}
|
||||
return nil, errors.Wrap(httperrors.ErrBadRequest, "not a valid vpc")
|
||||
return vpc.GetIRegion()
|
||||
}
|
||||
|
||||
func (self *SVpcResourceBase) GetCloudprovider() *SCloudprovider {
|
||||
vpc := self.GetVpc()
|
||||
if vpc == nil {
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return vpc.GetCloudprovider()
|
||||
@@ -96,7 +95,7 @@ func (self *SVpcResourceBase) GetCloudproviderId() string {
|
||||
}
|
||||
|
||||
func (self *SVpcResourceBase) GetProviderName() string {
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
if vpc == nil {
|
||||
return ""
|
||||
}
|
||||
@@ -298,7 +297,7 @@ func (manager *SVpcResourceBaseManager) GetExportKeys() []string {
|
||||
}
|
||||
|
||||
func (self *SVpcResourceBase) GetChangeOwnerCandidateDomainIds() []string {
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
if vpc != nil {
|
||||
return vpc.GetChangeOwnerCandidateDomainIds()
|
||||
}
|
||||
@@ -306,11 +305,11 @@ func (self *SVpcResourceBase) GetChangeOwnerCandidateDomainIds() []string {
|
||||
}
|
||||
|
||||
func IsOneCloudVpcResource(res IVpcResource) bool {
|
||||
vpc := res.GetVpc()
|
||||
vpc, _ := res.GetVpc()
|
||||
if vpc == nil {
|
||||
return false
|
||||
}
|
||||
region := res.GetRegion()
|
||||
region, _ := res.GetRegion()
|
||||
if region == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -55,45 +55,44 @@ func ValidateWireResourceInput(userCred mcclient.TokenCredential, input api.Wire
|
||||
return wireObj.(*SWire), input, nil
|
||||
}
|
||||
|
||||
func (self *SWireResourceBase) GetWire() *SWire {
|
||||
w, _ := WireManager.FetchById(self.WireId)
|
||||
if w != nil {
|
||||
return w.(*SWire)
|
||||
func (self *SWireResourceBase) GetWire() (*SWire, error) {
|
||||
w, err := WireManager.FetchById(self.WireId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetWire(%s)", self.WireId)
|
||||
}
|
||||
return nil
|
||||
return w.(*SWire), nil
|
||||
}
|
||||
|
||||
func (self *SWireResourceBase) GetCloudproviderId() string {
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
if vpc != nil {
|
||||
return vpc.ManagerId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SWireResourceBase) GetVpc() *SVpc {
|
||||
wire := self.GetWire()
|
||||
if wire != nil {
|
||||
return wire.GetVpc()
|
||||
func (self *SWireResourceBase) GetVpc() (*SVpc, error) {
|
||||
wire, err := self.GetWire()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetWire")
|
||||
}
|
||||
return nil
|
||||
return wire.GetVpc()
|
||||
}
|
||||
|
||||
func (self *SWireResourceBase) GetRegion() *SCloudregion {
|
||||
vpc := self.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil
|
||||
func (self *SWireResourceBase) GetRegion() (*SCloudregion, error) {
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetVpc")
|
||||
}
|
||||
region, _ := vpc.GetRegion()
|
||||
return region
|
||||
return vpc.GetRegion()
|
||||
}
|
||||
|
||||
func (self *SWireResourceBase) GetZone() *SZone {
|
||||
wire := self.GetWire()
|
||||
if wire != nil {
|
||||
return wire.GetZone()
|
||||
func (self *SWireResourceBase) GetZone() (*SZone, error) {
|
||||
wire, err := self.GetWire()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetWire")
|
||||
}
|
||||
return nil
|
||||
return wire.GetZone()
|
||||
}
|
||||
|
||||
func (self *SWireResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) api.WireResourceInfo {
|
||||
@@ -329,7 +328,7 @@ func (manager *SWireResourceBaseManager) GetExportKeys() []string {
|
||||
}
|
||||
|
||||
func (self *SWireResourceBase) GetChangeOwnerCandidateDomainIds() []string {
|
||||
wire := self.GetWire()
|
||||
wire, _ := self.GetWire()
|
||||
if wire != nil {
|
||||
return wire.GetChangeOwnerCandidateDomainIds()
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ func (self *SWire) syncRemoveCloudWire(ctx context.Context, userCred mcclient.To
|
||||
lockman.LockObject(ctx, self)
|
||||
defer lockman.ReleaseObject(ctx, self)
|
||||
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
cloudprovider := vpc.GetCloudprovider()
|
||||
if self.ExternalId == WireManager.getWireExternalIdForClassicNetwork(cloudprovider.Provider, self.VpcId, self.ZoneId) {
|
||||
return nil
|
||||
@@ -373,7 +373,7 @@ func (self *SWire) syncWithCloudWire(ctx context.Context, userCred mcclient.Toke
|
||||
self.IsEmulated = extWire.IsEmulated()
|
||||
self.Status = extWire.GetStatus()
|
||||
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
if vpc != nil {
|
||||
region, err := vpc.GetRegion()
|
||||
if err != nil {
|
||||
@@ -1067,10 +1067,9 @@ func (wire *SWire) clearHostSchedDescCache() error {
|
||||
}
|
||||
|
||||
func (self *SWire) GetIWire() (cloudprovider.ICloudWire, error) {
|
||||
vpc := self.GetVpc()
|
||||
if vpc == nil {
|
||||
log.Errorf("Cannot find VPC for wire???")
|
||||
return nil, fmt.Errorf("No VPC?????")
|
||||
vpc, err := self.GetVpc()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetVpc")
|
||||
}
|
||||
ivpc, err := vpc.GetIVpc()
|
||||
if err != nil {
|
||||
@@ -1093,7 +1092,7 @@ func (manager *SWireManager) GetOnPremiseWireOfIp(ipAddr string) (*SWire, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
wire := net.GetWire()
|
||||
wire, _ := net.GetWire()
|
||||
if wire != nil {
|
||||
return wire, nil
|
||||
} else {
|
||||
@@ -1426,7 +1425,7 @@ func (man *SWireManager) removeWiresByVpc(ctx context.Context, userCred mcclient
|
||||
}
|
||||
|
||||
func (self *SWire) IsManaged() bool {
|
||||
vpc := self.GetVpc()
|
||||
vpc, _ := self.GetVpc()
|
||||
if vpc == nil {
|
||||
return false
|
||||
}
|
||||
@@ -1435,7 +1434,7 @@ func (self *SWire) IsManaged() bool {
|
||||
|
||||
func (model *SWire) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
if !data.Contains("public_scope") {
|
||||
vpc := model.GetVpc()
|
||||
vpc, _ := model.GetVpc()
|
||||
if !model.IsManaged() && db.IsAdminAllowPerform(userCred, model, "public") && ownerId.GetProjectDomainId() == userCred.GetProjectDomainId() && vpc != nil && vpc.IsPublic && vpc.PublicScope == string(rbacutils.ScopeSystem) {
|
||||
model.SetShare(rbacutils.ScopeSystem)
|
||||
} else {
|
||||
@@ -1449,7 +1448,7 @@ func (model *SWire) CustomizeCreate(ctx context.Context, userCred mcclient.Token
|
||||
|
||||
func (wire *SWire) GetChangeOwnerCandidateDomainIds() []string {
|
||||
candidates := [][]string{}
|
||||
vpc := wire.GetVpc()
|
||||
vpc, _ := wire.GetVpc()
|
||||
if vpc != nil {
|
||||
candidates = append(candidates,
|
||||
vpc.GetChangeOwnerCandidateDomainIds(),
|
||||
|
||||
@@ -52,8 +52,12 @@ func ValidateZoneResourceInput(userCred mcclient.TokenCredential, query api.Zone
|
||||
return zoneObj.(*SZone), query, nil
|
||||
}
|
||||
|
||||
func (self *SZoneResourceBase) GetZone() *SZone {
|
||||
return ZoneManager.FetchZoneById(self.ZoneId)
|
||||
func (self *SZoneResourceBase) GetZone() (*SZone, error) {
|
||||
zone, err := ZoneManager.FetchById(self.ZoneId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetZone(%s)", self.ZoneId)
|
||||
}
|
||||
return zone.(*SZone), nil
|
||||
}
|
||||
|
||||
func (self *SZoneResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) api.ZoneResourceInfo {
|
||||
|
||||
@@ -165,7 +165,8 @@ func (manager *SZoneManager) FetchCustomizeColumns(
|
||||
}
|
||||
zone := objs[i].(*SZone)
|
||||
rows[i].ZoneGeneralUsage = zone.GeneralUsage()
|
||||
rows[i].CloudenvResourceInfo = zone.GetRegion().GetRegionCloudenvInfo()
|
||||
region, _ := zone.GetRegion()
|
||||
rows[i].CloudenvResourceInfo = region.GetRegionCloudenvInfo()
|
||||
}
|
||||
return rows
|
||||
}
|
||||
@@ -330,8 +331,12 @@ func (manager *SZoneManager) FetchZoneById(zoneId string) *SZone {
|
||||
return zoneObj.(*SZone)
|
||||
}
|
||||
|
||||
func (zone *SZone) GetRegion() *SCloudregion {
|
||||
return CloudregionManager.FetchRegionById(zone.GetCloudRegionId())
|
||||
func (zone *SZone) GetRegion() (*SCloudregion, error) {
|
||||
region, err := CloudregionManager.FetchById(zone.GetCloudRegionId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return region.(*SCloudregion), nil
|
||||
}
|
||||
|
||||
func (manager *SZoneManager) InitializeData() error {
|
||||
@@ -687,7 +692,7 @@ func (self *SZone) GetDetailsDiskCapability(ctx context.Context, userCred mcclie
|
||||
}
|
||||
|
||||
func (self *SZone) isManaged() bool {
|
||||
region := self.GetRegion()
|
||||
region, _ := self.GetRegion()
|
||||
if region != nil && len(region.ExternalId) == 0 {
|
||||
return false
|
||||
} else {
|
||||
|
||||
@@ -105,7 +105,7 @@ func (self *SAliyunRegionDriver) validateCreateLBCommonData(ownerId mcclient.IId
|
||||
}
|
||||
}
|
||||
|
||||
region := zoneV.Model.(*models.SZone).GetRegion()
|
||||
region, _ := zoneV.Model.(*models.SZone).GetRegion()
|
||||
if region == nil {
|
||||
return nil, nil, fmt.Errorf("getting region failed")
|
||||
}
|
||||
@@ -293,7 +293,7 @@ func (self *SAliyunRegionDriver) ValidateCreateLoadbalancerBackendData(ctx conte
|
||||
}
|
||||
|
||||
guest := backend.(*models.SGuest)
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, fmt.Errorf("error getting host of guest %s", guest.GetId())
|
||||
}
|
||||
@@ -301,7 +301,7 @@ func (self *SAliyunRegionDriver) ValidateCreateLoadbalancerBackendData(ctx conte
|
||||
return nil, fmt.Errorf("error loadbalancer of backend group %s", backendGroup.GetId())
|
||||
}
|
||||
|
||||
hostRegion := host.GetRegion()
|
||||
hostRegion, _ := host.GetRegion()
|
||||
lbRegion := lb.GetRegion()
|
||||
if hostRegion.Id != lbRegion.Id {
|
||||
return nil, httperrors.NewInputParameterError("region of host %q (%s) != region of loadbalancer %q (%s))",
|
||||
@@ -884,11 +884,11 @@ func (self *SAliyunRegionDriver) ValidateCreateDBInstanceData(ctx context.Contex
|
||||
}
|
||||
|
||||
if network != nil {
|
||||
wire := network.GetWire()
|
||||
wire, _ := network.GetWire()
|
||||
if wire == nil {
|
||||
return input, httperrors.NewGeneralError(fmt.Errorf("failed to found wire for network %s(%s)", network.Name, network.Id))
|
||||
}
|
||||
zone := wire.GetZone()
|
||||
zone, _ := wire.GetZone()
|
||||
if zone == nil {
|
||||
return input, httperrors.NewGeneralError(fmt.Errorf("failed to found zone for wire %s(%s)", wire.Name, wire.Id))
|
||||
}
|
||||
@@ -952,7 +952,7 @@ func (self *SAliyunRegionDriver) ValidateCreateDBInstanceData(ctx context.Contex
|
||||
}
|
||||
case api.DBINSTANCE_TYPE_SQLSERVER:
|
||||
if input.Category == api.ALIYUN_DBINSTANCE_CATEGORY_ALWAYSON {
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
count, err := vpc.GetNetworkCount()
|
||||
if err != nil {
|
||||
return input, httperrors.NewGeneralError(err)
|
||||
@@ -1127,7 +1127,7 @@ func (self *SAliyunRegionDriver) ValidateCreateElasticcacheData(ctx context.Cont
|
||||
data.Set("billing_cycle", jsonutils.NewString(cycle.String()))
|
||||
}
|
||||
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, httperrors.NewNotFoundError("network %s related vpc not found", network.GetId())
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ func (self *SHuaWeiRegionDriver) ValidateCreateLoadbalancerData(ctx context.Cont
|
||||
data.Set("eip_id", jsonutils.NewString(eip.ExternalId))
|
||||
}
|
||||
|
||||
region := zoneV.Model.(*models.SZone).GetRegion()
|
||||
region, _ := zoneV.Model.(*models.SZone).GetRegion()
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("getting region failed")
|
||||
}
|
||||
@@ -2334,7 +2334,7 @@ func ValidateElasticcacheSku(zoneId string, chargeType string, sku *models.SElas
|
||||
}
|
||||
|
||||
if network != nil {
|
||||
if zone := network.GetZone(); zone != nil && zone.Id != sku.ZoneId {
|
||||
if zone, _ := network.GetZone(); zone != nil && zone.Id != sku.ZoneId {
|
||||
return httperrors.NewResourceNotFoundError("elastic cache sku zone (%s) and subnet zone (%s) mismatch", sku.ZoneId, zone.Id)
|
||||
}
|
||||
}
|
||||
@@ -2451,7 +2451,7 @@ func (self *SHuaWeiRegionDriver) ValidateCreateElasticcacheData(ctx context.Cont
|
||||
data.Set("billing_cycle", jsonutils.NewString(cycle.String()))
|
||||
}
|
||||
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, httperrors.NewNotFoundError("network %s related vpc not found", network.GetId())
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func (self *SKVMRegionDriver) ValidateCreateLoadbalancerBackendData(ctx context.
|
||||
guest := backend.(*models.SGuest)
|
||||
{
|
||||
// guest zone must match that of loadbalancer's
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, httperrors.NewInputParameterError("error getting host of guest %s", guest.GetId())
|
||||
}
|
||||
@@ -240,8 +240,8 @@ func (self *SKVMRegionDriver) ValidateCreateLoadbalancerBackendData(ctx context.
|
||||
return nil, httperrors.NewInputParameterError("error loadbalancer of backend group %s", backendGroup.GetId())
|
||||
}
|
||||
var (
|
||||
lbRegion = lb.GetRegion()
|
||||
hostRegion = host.GetRegion()
|
||||
lbRegion = lb.GetRegion()
|
||||
hostRegion, _ = host.GetRegion()
|
||||
)
|
||||
if lbRegion.Id != hostRegion.Id {
|
||||
return nil, httperrors.NewInputParameterError("region of host %q (%s) != region of loadbalancer %q (%s)",
|
||||
@@ -956,7 +956,7 @@ func (self *SKVMRegionDriver) ValidateCreateEipData(ctx context.Context, userCre
|
||||
}
|
||||
input.NetworkId = network.Id
|
||||
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return httperrors.NewInputParameterError("failed to found vpc for network %s(%s)", network.Name, network.Id)
|
||||
}
|
||||
@@ -1105,7 +1105,7 @@ func (self *SKVMRegionDriver) RequestCreateInstanceSnapshot(ctx context.Context,
|
||||
}
|
||||
|
||||
func (self *SKVMRegionDriver) SnapshotIsOutOfChain(disk *models.SDisk) bool {
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
return models.GetStorageDriver(storage.StorageType).SnapshotIsOutOfChain(disk)
|
||||
}
|
||||
|
||||
@@ -1127,7 +1127,7 @@ func (self *SKVMRegionDriver) OnDiskReset(ctx context.Context, userCred mcclient
|
||||
return err
|
||||
}
|
||||
}
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
return models.GetStorageDriver(storage.StorageType).OnDiskReset(ctx, userCred, disk, snapshot, data)
|
||||
}
|
||||
|
||||
@@ -1190,7 +1190,7 @@ func (self *SKVMRegionDriver) OnSnapshotDelete(ctx context.Context, snapshot *mo
|
||||
|
||||
func (self *SKVMRegionDriver) RequestSyncDiskStatus(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
host := storage.GetMasterHost()
|
||||
header := task.GetTaskRequestHeader()
|
||||
url := fmt.Sprintf("%s/disks/%s/%s/status", host.ManagerUri, storage.Id, disk.Id)
|
||||
|
||||
@@ -84,14 +84,14 @@ func (self *SManagedVirtualizationRegionDriver) ValidateCreateLoadbalancerBacken
|
||||
return nil, httperrors.NewUnsupportOperationError("internal error: unexpected backend type %s", backendType)
|
||||
}
|
||||
guest := backend.(*models.SGuest)
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
return nil, fmt.Errorf("error getting host of guest %s", guest.GetId())
|
||||
}
|
||||
if lb == nil {
|
||||
return nil, fmt.Errorf("error loadbalancer of backend group %s", backendGroup.GetId())
|
||||
}
|
||||
hostRegion := host.GetRegion()
|
||||
hostRegion, _ := host.GetRegion()
|
||||
lbRegion := lb.GetRegion()
|
||||
if hostRegion.Id != lbRegion.Id {
|
||||
return nil, httperrors.NewInputParameterError("region of host %q (%s) != region of loadbalancer %q (%s))",
|
||||
@@ -1302,8 +1302,10 @@ func (self *SManagedVirtualizationRegionDriver) RequestApplySnapshotPolicy(ctx c
|
||||
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
|
||||
regionId := disk.GetStorage().GetRegion().GetId()
|
||||
providerId := disk.GetStorage().ManagerId
|
||||
storage, _ := disk.GetStorage()
|
||||
region, _ := storage.GetRegion()
|
||||
regionId := region.GetId()
|
||||
providerId := storage.ManagerId
|
||||
spcache, err := models.SnapshotPolicyCacheManager.Register(ctx, userCred, sp.GetId(), regionId, providerId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "registersnapshotpolicy cache failed")
|
||||
@@ -1330,8 +1332,10 @@ func (self *SManagedVirtualizationRegionDriver) RequestCancelSnapshotPolicy(ctx
|
||||
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
|
||||
regionId := disk.GetStorage().GetRegion().GetId()
|
||||
providerId := disk.GetStorage().ManagerId
|
||||
storage, _ := disk.GetStorage()
|
||||
region, _ := storage.GetRegion()
|
||||
regionId := region.GetId()
|
||||
providerId := storage.ManagerId
|
||||
spcache, err := models.SnapshotPolicyCacheManager.FetchSnapshotPolicyCache(sp.GetId(), regionId, providerId)
|
||||
|
||||
if err != nil {
|
||||
@@ -2937,7 +2941,7 @@ func (self *SManagedVirtualizationRegionDriver) RequestRemoteUpdateElasticcache(
|
||||
}
|
||||
tagsUpdateInfo := cloudprovider.TagsUpdateInfo{OldTags: oldTags, NewTags: tags}
|
||||
mangerId := ""
|
||||
if vpc := elasticcache.GetVpc(); vpc != nil {
|
||||
if vpc, _ := elasticcache.GetVpc(); vpc != nil {
|
||||
mangerId = vpc.ManagerId
|
||||
}
|
||||
err = cloudprovider.SetTags(ctx, iElasticcache, mangerId, tags, replaceTags)
|
||||
|
||||
@@ -129,7 +129,7 @@ func (self *SOpenStackRegionDriver) ValidateCreateLoadbalancerData(ctx context.C
|
||||
}
|
||||
|
||||
// region := zoneV.Model.(*models.SZone).GetRegion()
|
||||
region := networkV.Model.(*models.SNetwork).GetRegion()
|
||||
region, _ := networkV.Model.(*models.SNetwork).GetRegion()
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("getting region failed")
|
||||
}
|
||||
@@ -267,7 +267,7 @@ func (self *SOpenStackRegionDriver) ValidateCreateEipData(ctx context.Context, u
|
||||
network := _network.(*models.SNetwork)
|
||||
input.NetworkId = network.Id
|
||||
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return httperrors.NewInputParameterError("failed to found vpc for network %s(%s)", network.Name, network.Id)
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func (self *SQcloudRegionDriver) ValidateCreateLoadbalancerData(ctx context.Cont
|
||||
}
|
||||
}
|
||||
|
||||
region := zoneV.Model.(*models.SZone).GetRegion()
|
||||
region, _ := zoneV.Model.(*models.SZone).GetRegion()
|
||||
if region == nil {
|
||||
return nil, fmt.Errorf("getting region failed")
|
||||
}
|
||||
@@ -1294,8 +1294,10 @@ func (self *SQcloudRegionDriver) RequestPreSnapshotPolicyApply(ctx context.Conte
|
||||
if sp == nil {
|
||||
return data, nil
|
||||
}
|
||||
storage, _ := disk.GetStorage()
|
||||
region, _ := storage.GetRegion()
|
||||
spcache, err := models.SnapshotPolicyCacheManager.FetchSnapshotPolicyCache(sp.GetId(),
|
||||
disk.GetStorage().GetRegion().GetId(), disk.GetStorage().ManagerId)
|
||||
region.GetId(), storage.ManagerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1569,7 +1571,7 @@ func (self *SQcloudRegionDriver) ValidateCreateElasticcacheData(ctx context.Cont
|
||||
data.Set("billing_cycle", jsonutils.NewString(cycle.String()))
|
||||
}
|
||||
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return nil, httperrors.NewNotFoundError("network %s related vpc not found", network.GetId())
|
||||
}
|
||||
@@ -1695,8 +1697,9 @@ func (self *SQcloudRegionDriver) RequestSyncSecgroupsForElasticcache(ctx context
|
||||
return nil, fmt.Errorf("failed to sync project %s for create %s elastic cache %s error: %v", ec.ProjectId, provider.Provider, ec.Name, err)
|
||||
}
|
||||
|
||||
vpc := ec.GetVpc()
|
||||
vpcId, err := self.GetSecurityGroupVpcId(ctx, userCred, ec.GetRegion(), nil, vpc, false)
|
||||
vpc, _ := ec.GetVpc()
|
||||
region, _ := vpc.GetRegion()
|
||||
vpcId, err := self.GetSecurityGroupVpcId(ctx, userCred, region, nil, vpc, false)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetSecurityGroupVpcId")
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func (self *SZStackRegionDriver) ValidateCreateEipData(ctx context.Context, user
|
||||
network := _network.(*models.SNetwork)
|
||||
input.NetworkId = network.Id
|
||||
|
||||
vpc := network.GetVpc()
|
||||
vpc, _ := network.GetVpc()
|
||||
if vpc == nil {
|
||||
return httperrors.NewInputParameterError("failed to found vpc for network %s(%s)", network.Name, network.Id)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ type BaremetalServerResetTask struct {
|
||||
|
||||
func (self *BaremetalServerResetTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
|
||||
guest := obj.(*models.SGuest)
|
||||
baremetal := guest.GetHost()
|
||||
baremetal, _ := guest.GetHost()
|
||||
if baremetal == nil {
|
||||
self.SetStageFailed(ctx, jsonutils.NewString("Baremetal is not found"))
|
||||
return
|
||||
|
||||
@@ -39,7 +39,7 @@ func (self *BaremetalServerStartTask) OnInit(ctx context.Context, obj db.IStanda
|
||||
guest := obj.(*models.SGuest)
|
||||
guest.SetStatus(self.UserCred, api.VM_START_START, "")
|
||||
db.OpsLog.LogEvent(guest, db.ACT_STARTING, "", self.UserCred)
|
||||
baremetal := guest.GetHost()
|
||||
baremetal, _ := guest.GetHost()
|
||||
if baremetal == nil {
|
||||
self.OnStartCompleteFailed(ctx, guest, jsonutils.NewString("Baremetal is None"))
|
||||
return
|
||||
@@ -59,7 +59,7 @@ func (self *BaremetalServerStartTask) OnInit(ctx context.Context, obj db.IStanda
|
||||
|
||||
func (self *BaremetalServerStartTask) OnStartComplete(ctx context.Context, guest *models.SGuest, body jsonutils.JSONObject) {
|
||||
guest.SetStatus(self.UserCred, api.VM_RUNNING, "")
|
||||
baremetal := guest.GetHost()
|
||||
baremetal, _ := guest.GetHost()
|
||||
baremetal.SetStatus(self.UserCred, api.BAREMETAL_RUNNING, "")
|
||||
db.OpsLog.LogEvent(guest, db.ACT_START, guest.GetShortDesc(ctx), self.UserCred)
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func (self *BaremetalServerStartTask) OnStartComplete(ctx context.Context, guest
|
||||
func (self *BaremetalServerStartTask) OnStartCompleteFailed(ctx context.Context, guest *models.SGuest, body jsonutils.JSONObject) {
|
||||
guest.SetStatus(self.UserCred, api.VM_START_FAILED, body.String())
|
||||
db.OpsLog.LogEvent(guest, db.ACT_START_FAIL, body, self.UserCred)
|
||||
baremetal := guest.GetHost()
|
||||
baremetal, _ := guest.GetHost()
|
||||
baremetal.SetStatus(self.UserCred, api.BAREMETAL_START_FAIL, body.String())
|
||||
self.SetStageFailed(ctx, body)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func (self *BaremetalServerStopTask) OnInit(ctx context.Context, obj db.IStandal
|
||||
guest := obj.(*models.SGuest)
|
||||
db.OpsLog.LogEvent(guest, db.ACT_STOPPING, "", self.UserCred)
|
||||
guest.SetStatus(self.UserCred, api.VM_START_STOP, "")
|
||||
baremetal := guest.GetHost()
|
||||
baremetal, _ := guest.GetHost()
|
||||
if baremetal != nil {
|
||||
self.OnStopGuestFail(ctx, guest, "Baremetal is None")
|
||||
return
|
||||
@@ -68,7 +68,7 @@ func (self *BaremetalServerStopTask) OnGuestStopTaskComplete(ctx context.Context
|
||||
guest.SetStatus(self.UserCred, api.VM_READY, "")
|
||||
db.OpsLog.LogEvent(guest, db.ACT_STOP, "", self.UserCred)
|
||||
}
|
||||
baremetal := guest.GetHost()
|
||||
baremetal, _ := guest.GetHost()
|
||||
baremetal.SetStatus(self.UserCred, api.BAREMETAL_READY, "")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
if guest.Status == api.VM_READY {
|
||||
@@ -81,7 +81,7 @@ func (self *BaremetalServerStopTask) OnGuestStopTaskComplete(ctx context.Context
|
||||
func (self *BaremetalServerStopTask) OnGuestStopTaskCompleteFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
guest.SetStatus(self.UserCred, db.ACT_STOP_FAIL, data.String())
|
||||
db.OpsLog.LogEvent(guest, db.ACT_STOP_FAIL, data, self.UserCred)
|
||||
baremetal := guest.GetHost()
|
||||
baremetal, _ := guest.GetHost()
|
||||
baremetal.SetStatus(self.UserCred, api.BAREMETAL_READY, data.String())
|
||||
self.SetStageFailed(ctx, data)
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func init() {
|
||||
|
||||
func (self *BaremetalServerSyncStatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
guest := obj.(*models.SGuest)
|
||||
baremetal := guest.GetHost()
|
||||
baremetal, _ := guest.GetHost()
|
||||
if baremetal == nil {
|
||||
guest.SetStatus(self.UserCred, api.VM_INIT, "BaremetalServerSyncStatusTask")
|
||||
self.SetStageComplete(ctx, nil)
|
||||
@@ -57,7 +57,7 @@ func (self *BaremetalServerSyncStatusTask) OnInit(ctx context.Context, obj db.IS
|
||||
func (self *BaremetalServerSyncStatusTask) OnGuestStatusTaskComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
|
||||
var status string
|
||||
var hostStatus string
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if data.Contains("status") {
|
||||
statusStr, _ := data.GetString("status")
|
||||
switch statusStr {
|
||||
|
||||
@@ -47,7 +47,7 @@ func (self *SDiskBaseTask) finalReleasePendingUsage(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (self *SDiskBaseTask) CleanHostSchedCache(disk *models.SDisk) {
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ type DiskCreateTask struct {
|
||||
func (self *DiskCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
disk := obj.(*models.SDisk)
|
||||
|
||||
storagecache := disk.GetStorage().GetStoragecache()
|
||||
storage, _ := disk.GetStorage()
|
||||
storagecache := storage.GetStoragecache()
|
||||
imageId := disk.GetTemplateId()
|
||||
if len(imageId) > 0 {
|
||||
self.SetStage("OnStorageCacheImageComplete", nil)
|
||||
@@ -52,7 +53,7 @@ func (self *DiskCreateTask) OnStorageCacheImageComplete(ctx context.Context, dis
|
||||
if rebuild {
|
||||
db.OpsLog.LogEvent(disk, db.ACT_DELOCATE, disk.GetShortDesc(ctx), self.GetUserCred())
|
||||
}
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
host := storage.GetMasterHost()
|
||||
db.OpsLog.LogEvent(disk, db.ACT_ALLOCATING, disk.GetShortDesc(ctx), self.GetUserCred())
|
||||
disk.SetStatus(self.GetUserCred(), api.DISK_STARTALLOC, fmt.Sprintf("Disk start alloc use host %s(%s)", host.Name, host.Id))
|
||||
|
||||
@@ -100,7 +100,7 @@ func (self *DiskDeleteTask) startDeleteDisk(ctx context.Context, disk *models.SD
|
||||
host *models.SHost
|
||||
)
|
||||
|
||||
storage = disk.GetStorage()
|
||||
storage, _ = disk.GetStorage()
|
||||
if storage == nil { // dirty data
|
||||
self.OnGuestDiskDeleteComplete(ctx, disk, nil)
|
||||
return
|
||||
|
||||
@@ -102,7 +102,7 @@ func (self *DiskResetTask) OnStartGuest(ctx context.Context, disk *models.SDisk,
|
||||
|
||||
func (self *DiskResetTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
disk := obj.(*models.SDisk)
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage == nil {
|
||||
self.TaskFailed(ctx, disk, fmt.Errorf("Disk storage not found"))
|
||||
return
|
||||
@@ -166,7 +166,7 @@ func (self *DiskCleanUpSnapshotsTask) StartCleanUpSnapshots(ctx context.Context,
|
||||
var host *models.SHost
|
||||
guests := disk.GetGuests()
|
||||
if len(guests) == 1 {
|
||||
host = guests[0].GetHost()
|
||||
host, _ = guests[0].GetHost()
|
||||
} else {
|
||||
self.SetStageFailed(ctx, jsonutils.NewString("Disk can't get guest"))
|
||||
return
|
||||
|
||||
@@ -49,10 +49,10 @@ func (self *DiskResizeTask) OnInit(ctx context.Context, obj db.IStandaloneModel,
|
||||
disk := obj.(*models.SDisk)
|
||||
|
||||
var host *models.SHost
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
guest := disk.GetGuest()
|
||||
if guest != nil {
|
||||
host = guest.GetHost()
|
||||
host, _ = guest.GetHost()
|
||||
} else {
|
||||
host = storage.GetMasterHost()
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ func init() {
|
||||
|
||||
func (self *DiskSaveTask) GetMasterHost(disk *models.SDisk) *models.SHost {
|
||||
if guests := disk.GetGuests(); len(guests) == 1 {
|
||||
if host := guests[0].GetHost(); host == nil {
|
||||
if storage := disk.GetStorage(); storage != nil {
|
||||
if host, _ := guests[0].GetHost(); host == nil {
|
||||
if storage, _ := disk.GetStorage(); storage != nil {
|
||||
return storage.GetMasterHost()
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -46,12 +46,12 @@ func (self *DiskSyncstatusTask) taskFailed(ctx context.Context, disk *models.SDi
|
||||
func (self *DiskSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
disk := obj.(*models.SDisk)
|
||||
|
||||
storage := disk.GetStorage()
|
||||
storage, _ := disk.GetStorage()
|
||||
if storage == nil {
|
||||
self.taskFailed(ctx, disk, fmt.Errorf("failed to found storage for disk %s", disk.Name))
|
||||
return
|
||||
}
|
||||
region := storage.GetRegion()
|
||||
region, _ := storage.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFailed(ctx, disk, fmt.Errorf("failed to found cloudregion for disk storage %s(%s)", disk.Name, disk.Id))
|
||||
return
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheAllocatePublicConnectionTask) taskFail(ctx context.Conte
|
||||
|
||||
func (self *ElasticcacheAllocatePublicConnectionTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
elasticcache := obj.(*models.SElasticcache)
|
||||
region := elasticcache.GetRegion()
|
||||
region, _ := elasticcache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, elasticcache, jsonutils.NewString(fmt.Sprintf("failed to find region for elastic cache %s", elasticcache.GetName())))
|
||||
return
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheChangeSpecTask) taskFail(ctx context.Context, ec *models
|
||||
|
||||
func (self *ElasticcacheChangeSpecTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
elasticcache := obj.(*models.SElasticcache)
|
||||
region := elasticcache.GetRegion()
|
||||
region, _ := elasticcache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, elasticcache, jsonutils.NewString(fmt.Sprintf("failed to find region for elastic cache %s", elasticcache.GetName())))
|
||||
return
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheCreateTask) taskFail(ctx context.Context, elasticcache *
|
||||
|
||||
func (self *ElasticcacheCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
elasticcache := obj.(*models.SElasticcache)
|
||||
region := elasticcache.GetRegion()
|
||||
region, _ := elasticcache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, elasticcache, jsonutils.NewString(fmt.Sprintf("failed to find region for elastic cache %s", elasticcache.GetName())))
|
||||
return
|
||||
@@ -80,7 +80,7 @@ func (self *ElasticcacheCreateTask) OnInit(ctx context.Context, obj db.IStandalo
|
||||
}
|
||||
|
||||
func (self *ElasticcacheCreateTask) OnSyncSecurityGroupComplete(ctx context.Context, elasticcache *models.SElasticcache, data jsonutils.JSONObject) {
|
||||
region := elasticcache.GetRegion()
|
||||
region, _ := elasticcache.GetRegion()
|
||||
self.SetStage("OnElasticcacheCreateComplete", nil)
|
||||
if err := region.GetDriver().RequestCreateElasticcache(ctx, self.GetUserCred(), elasticcache, self, data.(*jsonutils.JSONDict)); err != nil {
|
||||
self.taskFail(ctx, elasticcache, jsonutils.NewString(err.Error()))
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheDeleteTask) taskFail(ctx context.Context, elasticcache *
|
||||
|
||||
func (self *ElasticcacheDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
ec := obj.(*models.SElasticcache)
|
||||
region := ec.GetRegion()
|
||||
region, _ := ec.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, ec, jsonutils.NewString(fmt.Sprintf("failed to find region for elastic cache %s", ec.GetName())))
|
||||
return
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheFlushInstanceTask) taskFail(ctx context.Context, elastic
|
||||
|
||||
func (self *ElasticcacheFlushInstanceTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
elasticcache := obj.(*models.SElasticcache)
|
||||
region := elasticcache.GetRegion()
|
||||
region, _ := elasticcache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, elasticcache, jsonutils.NewString(fmt.Sprintf("failed to find region for elastic cache %s", elasticcache.GetName())))
|
||||
return
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheReleasePublicConnectionTask) taskFail(ctx context.Contex
|
||||
|
||||
func (self *ElasticcacheReleasePublicConnectionTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
elasticcache := obj.(*models.SElasticcache)
|
||||
region := elasticcache.GetRegion()
|
||||
region, _ := elasticcache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, elasticcache, jsonutils.NewString(fmt.Sprintf("failed to find region for elastic cache %s", elasticcache.GetName())))
|
||||
return
|
||||
|
||||
@@ -41,7 +41,7 @@ func (self *ElasticcacheRemoteUpdateTask) taskFail(ctx context.Context, elasticc
|
||||
|
||||
func (self *ElasticcacheRemoteUpdateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
ec := obj.(*models.SElasticcache)
|
||||
region := ec.GetRegion()
|
||||
region, _ := ec.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, ec, jsonutils.NewString(fmt.Sprintf("failed to find region for elastic cache %s", ec.GetName())))
|
||||
return
|
||||
|
||||
@@ -29,7 +29,8 @@ func (self *ElasticcacheRenewTask) OnInit(ctx context.Context, obj db.IStandalon
|
||||
durationStr, _ := self.GetParams().GetString("duration")
|
||||
bc, _ := billing.ParseBillingCycle(durationStr)
|
||||
|
||||
exp, err := instance.GetRegion().GetDriver().RequestRenewElasticcache(ctx, self.UserCred, instance, bc)
|
||||
region, _ := instance.GetRegion()
|
||||
exp, err := region.GetDriver().RequestRenewElasticcache(ctx, self.UserCred, instance, bc)
|
||||
if err != nil {
|
||||
db.OpsLog.LogEvent(instance, db.ACT_REW_FAIL, err, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, instance, logclient.ACT_RENEW, err, self.UserCred, false)
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheRestartTask) taskFail(ctx context.Context, elasticcache
|
||||
|
||||
func (self *ElasticcacheRestartTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
ec := obj.(*models.SElasticcache)
|
||||
region := ec.GetRegion()
|
||||
region, _ := ec.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, ec, jsonutils.NewString(fmt.Sprintf("failed to find region for elastic cache %s", ec.GetName())))
|
||||
return
|
||||
|
||||
@@ -24,7 +24,8 @@ func (self *ElasticcacheSetAutoRenewTask) OnInit(ctx context.Context, obj db.ISt
|
||||
ec := obj.(*models.SElasticcache)
|
||||
|
||||
autoRenew, _ := self.GetParams().Bool("auto_renew")
|
||||
err := ec.GetRegion().GetDriver().RequestElasticcacheSetAutoRenew(ctx, self.UserCred, ec, autoRenew, self)
|
||||
region, _ := ec.GetRegion()
|
||||
err := region.GetDriver().RequestElasticcacheSetAutoRenew(ctx, self.UserCred, ec, autoRenew, self)
|
||||
if err != nil {
|
||||
db.OpsLog.LogEvent(ec, db.ACT_SET_AUTO_RENEW_FAIL, err, self.UserCred)
|
||||
logclient.AddActionLogWithStartable(self, ec, logclient.ACT_SET_AUTO_RENEW, err, self.UserCred, false)
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheSetMaintainTimeTask) taskFail(ctx context.Context, elast
|
||||
|
||||
func (self *ElasticcacheSetMaintainTimeTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
elasticcache := obj.(*models.SElasticcache)
|
||||
region := elasticcache.GetRegion()
|
||||
region, _ := elasticcache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, elasticcache, jsonutils.NewString(fmt.Sprintf("failed to find region for elastic cache %s", elasticcache.GetName())))
|
||||
return
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheSyncTask) taskFail(ctx context.Context, elasticcache *mo
|
||||
|
||||
func (self *ElasticcacheSyncTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
ec := obj.(*models.SElasticcache)
|
||||
region := ec.GetRegion()
|
||||
region, _ := ec.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, ec, jsonutils.NewString(fmt.Sprintf("failed to find region for elastic cache %s", ec.GetName())))
|
||||
return
|
||||
|
||||
@@ -45,7 +45,7 @@ func (self *ElasticcacheSyncsecgroupsTask) taskFailed(ctx context.Context, cache
|
||||
func (self *ElasticcacheSyncsecgroupsTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
cache := obj.(*models.SElasticcache)
|
||||
|
||||
region := cache.GetRegion()
|
||||
region, _ := cache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFailed(ctx, cache, jsonutils.NewString(fmt.Sprintf("failed to found cloudregion for elasticcache %s(%s)", cache.Name, cache.Id)))
|
||||
return
|
||||
|
||||
@@ -45,7 +45,7 @@ func (self *ElasticcacheSyncstatusTask) taskFailed(ctx context.Context, cache *m
|
||||
func (self *ElasticcacheSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
cache := obj.(*models.SElasticcache)
|
||||
|
||||
region := cache.GetRegion()
|
||||
region, _ := cache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFailed(ctx, cache, jsonutils.NewString(fmt.Sprintf("failed to found cloudregion for elasticcache %s(%s)", cache.Name, cache.Id)))
|
||||
return
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheUpdateAuthModeTask) taskFail(ctx context.Context, elasti
|
||||
|
||||
func (self *ElasticcacheUpdateAuthModeTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
elasticcache := obj.(*models.SElasticcache)
|
||||
region := elasticcache.GetRegion()
|
||||
region, _ := elasticcache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, elasticcache, jsonutils.Marshal(fmt.Sprintf("failed to find region for elastic cache %s", elasticcache.GetName())))
|
||||
return
|
||||
|
||||
@@ -46,7 +46,7 @@ func (self *ElasticcacheUpdateBackupPolicyTask) taskFail(ctx context.Context, el
|
||||
|
||||
func (self *ElasticcacheUpdateBackupPolicyTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
elasticcache := obj.(*models.SElasticcache)
|
||||
region := elasticcache.GetRegion()
|
||||
region, _ := elasticcache.GetRegion()
|
||||
if region == nil {
|
||||
self.taskFail(ctx, elasticcache, jsonutils.Marshal(fmt.Sprintf("failed to find region for elastic cache %s", elasticcache.GetName())))
|
||||
return
|
||||
|
||||
@@ -54,6 +54,8 @@ func (self *FileSystemCreateTask) OnInit(ctx context.Context, obj db.IStandalone
|
||||
return
|
||||
}
|
||||
|
||||
zone, _ := fs.GetZone()
|
||||
|
||||
opts := &cloudprovider.FileSystemCraeteOptions{
|
||||
Name: fs.Name,
|
||||
Desc: fs.Description,
|
||||
@@ -61,7 +63,7 @@ func (self *FileSystemCreateTask) OnInit(ctx context.Context, obj db.IStandalone
|
||||
StorageType: fs.StorageType,
|
||||
Protocol: fs.Protocol,
|
||||
FileSystemType: fs.FileSystemType,
|
||||
ZoneId: strings.TrimPrefix(fs.GetZone().ExternalId, iRegion.GetGlobalId()+"/"),
|
||||
ZoneId: strings.TrimPrefix(zone.ExternalId, iRegion.GetGlobalId()+"/"),
|
||||
}
|
||||
|
||||
netId := jsonutils.GetAnyString(self.GetParams(), []string{"network_id"})
|
||||
@@ -73,7 +75,8 @@ func (self *FileSystemCreateTask) OnInit(ctx context.Context, obj db.IStandalone
|
||||
}
|
||||
network := net.(*models.SNetwork)
|
||||
opts.NetworkId = network.ExternalId
|
||||
opts.VpcId = network.GetVpc().ExternalId
|
||||
vpc, _ := network.GetVpc()
|
||||
opts.VpcId = vpc.ExternalId
|
||||
}
|
||||
|
||||
log.Infof("nas create params: %s", jsonutils.Marshal(opts).String())
|
||||
|
||||
@@ -43,7 +43,7 @@ type GuestSwitchToBackupTask struct {
|
||||
*/
|
||||
func (self *GuestSwitchToBackupTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
guest := obj.(*models.SGuest)
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
self.Params.Set("is_force", jsonutils.JSONTrue)
|
||||
self.SetStage("OnEnsureMasterGuestStoped", nil)
|
||||
err := guest.GetDriver().RequestStopOnHost(ctx, guest, host, self)
|
||||
|
||||
@@ -132,7 +132,7 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest
|
||||
}
|
||||
}
|
||||
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
|
||||
quotaCpuMem := models.SQuota{Count: 1, Cpu: int(guest.VcpuCount), Memory: guest.VmemSize}
|
||||
keys, err := guest.GetQuotaKeys()
|
||||
|
||||
@@ -39,7 +39,7 @@ func (self *GuestBlockIoThrottleTask) OnInit(ctx context.Context, obj db.IStanda
|
||||
guest := obj.(*models.SGuest)
|
||||
url := fmt.Sprintf("/servers/%s/io-throttle", guest.Id)
|
||||
headers := self.GetTaskRequestHeader()
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
self.SetStage("OnIoThrottle", nil)
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
|
||||
@@ -176,7 +176,8 @@ func (self *GuestChangeConfigTask) DoCreateDisksTask(ctx context.Context, guest
|
||||
self.OnCreateDisksComplete(ctx, guest, nil)
|
||||
return
|
||||
}
|
||||
err = guest.CreateDisksOnHost(ctx, self.UserCred, guest.GetHost(), disks, nil, false, false, nil, nil, false)
|
||||
host, _ := guest.GetHost()
|
||||
err = guest.CreateDisksOnHost(ctx, self.UserCred, host, disks, nil, false, false, nil, nil, false)
|
||||
if err != nil {
|
||||
self.markStageFailed(ctx, guest, jsonutils.NewString(err.Error()))
|
||||
return
|
||||
|
||||
@@ -78,7 +78,7 @@ func (self *GuestConvertEsxiToKvmTask) taskFailed(ctx context.Context, guest *mo
|
||||
|
||||
func (self *GuestConvertEsxiToKvmTask) GenerateEsxiAcceessInfo(guest *models.SGuest) (*jsonutils.JSONDict, error) {
|
||||
ret := jsonutils.NewDict()
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
accessInfo, err := host.GetCloudaccount().GetVCenterAccessInfo("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -113,7 +113,7 @@ func (self *GuestConvertEsxiToKvmTask) SaveScheduleResult(ctx context.Context, o
|
||||
self.taskFailed(ctx, guest, jsonutils.NewString(fmt.Sprintf("guest set metadata %s", err)))
|
||||
return
|
||||
}
|
||||
host := targetGuest.GetHost()
|
||||
host, _ := targetGuest.GetHost()
|
||||
|
||||
//pendingUsage := models.SQuota{}
|
||||
input := guest.ToCreateInput(self.UserCred)
|
||||
@@ -136,7 +136,7 @@ func (self *GuestConvertEsxiToKvmTask) SaveScheduleResult(ctx context.Context, o
|
||||
func (self *GuestConvertEsxiToKvmTask) RequestHostCreateGuestFromEsxi(
|
||||
ctx context.Context, guest *models.SGuest, esxiAccessInfo *jsonutils.JSONDict,
|
||||
) error {
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("desc", guest.GetJsonDescAtHypervisor(ctx, host))
|
||||
params.Set("esxi_access_info", esxiAccessInfo)
|
||||
|
||||
@@ -252,7 +252,7 @@ type ESXiGuestCreateDiskTask struct {
|
||||
|
||||
func (self *ESXiGuestCreateDiskTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
guest := obj.(*models.SGuest)
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if host == nil {
|
||||
self.SetStageFailed(ctx, jsonutils.NewString("no valid host"))
|
||||
return
|
||||
@@ -317,7 +317,8 @@ func (self *ESXiGuestCreateDiskTask) OnInit(ctx context.Context, obj db.IStandal
|
||||
}
|
||||
|
||||
disk.SetStatus(self.UserCred, api.DISK_READY, "create disk success")
|
||||
disk.GetStorage().ClearSchedDescCache()
|
||||
storage, _ := disk.GetStorage()
|
||||
storage.ClearSchedDescCache()
|
||||
db.OpsLog.LogEvent(disk, db.ACT_ALLOCATE, disk.GetShortDesc(ctx), self.UserCred)
|
||||
db.OpsLog.LogAttachEvent(ctx, guest, disk, self.UserCred, disk.GetShortDesc(ctx))
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func init() {
|
||||
|
||||
func (self *GuestDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
|
||||
guest := obj.(*models.SGuest)
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if guest.Hypervisor == api.HYPERVISOR_BAREMETAL && host != nil && host.HostType != api.HOST_TYPE_BAREMETAL {
|
||||
// if a fake server for converted hypervisor, then just skip stop
|
||||
self.OnGuestStopComplete(ctx, guest, data)
|
||||
@@ -285,7 +285,7 @@ func (self *GuestDeleteTask) OnGuestDetachDisksCompleteFailed(ctx context.Contex
|
||||
|
||||
func (self *GuestDeleteTask) DoDeleteGuest(ctx context.Context, guest *models.SGuest) {
|
||||
models.IsolatedDeviceManager.ReleaseDevicesOfGuest(ctx, guest, self.UserCred)
|
||||
host := guest.GetHost()
|
||||
host, _ := guest.GetHost()
|
||||
if guest.IsPrepaidRecycle() {
|
||||
err := host.BorrowIpAddrsFromGuest(ctx, self.UserCred, guest)
|
||||
if err != nil {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user