diff --git a/pkg/apis/billing/billing_const.go b/pkg/apis/billing/billing_const.go new file mode 100644 index 0000000000..7d9c563f7d --- /dev/null +++ b/pkg/apis/billing/billing_const.go @@ -0,0 +1,6 @@ +package billing + +const ( + BILLING_TYPE_POSTPAID = "postpaid" + BILLING_TYPE_PREPAID = "prepaid" +) diff --git a/pkg/apis/billing/doc.go b/pkg/apis/billing/doc.go new file mode 100644 index 0000000000..6ff84376cb --- /dev/null +++ b/pkg/apis/billing/doc.go @@ -0,0 +1 @@ +package billing // import "yunion.io/x/onecloud/pkg/apis/billing" diff --git a/pkg/apis/compute/agent_const.go b/pkg/apis/compute/agent_const.go new file mode 100644 index 0000000000..3fbeb75840 --- /dev/null +++ b/pkg/apis/compute/agent_const.go @@ -0,0 +1,15 @@ +package compute + +const ( + BAREMETAL_AGENT_ENABLED = "enabled" + BAREMETAL_AGENT_DISABLED = "disabled" + BAREMETAL_AGENT_OFFLINE = "offline" +) + +type TAgentType string + +const ( + AgentTypeBaremetal = TAgentType("baremetal") + AgentTypeEsxi = TAgentType("esxiagent") + AgentTypeDefault = AgentTypeBaremetal +) diff --git a/pkg/apis/compute/cachedimages_const.go b/pkg/apis/compute/cachedimages_const.go new file mode 100644 index 0000000000..447866a382 --- /dev/null +++ b/pkg/apis/compute/cachedimages_const.go @@ -0,0 +1,17 @@ +package compute + +const ( + CACHED_IMAGE_STATUS_INIT = "init" + CACHED_IMAGE_STATUS_SAVING = "saving" + CACHED_IMAGE_STATUS_CACHING = "caching" + CACHED_IMAGE_STATUS_READY = "ready" + CACHED_IMAGE_STATUS_DELETING = "deleting" + CACHED_IMAGE_STATUS_CACHE_FAILED = "cache_fail" + + DOWNLOAD_SESSION_LENGTH = 3600 * 3 // 3 hour +) + +const ( + CACHED_IMAGE_REFRESH_SECONDS = 900 // 15 minutes + CACHED_IMAGE_REFERENCE_SESSION_EXPIRE_SECONDS = 86400 // 1 day +) diff --git a/pkg/apis/compute/cloudregions_const.go b/pkg/apis/compute/cloudregions_const.go new file mode 100644 index 0000000000..8fb526de7e --- /dev/null +++ b/pkg/apis/compute/cloudregions_const.go @@ -0,0 +1,8 @@ +package compute + +const ( + CLOUD_REGION_STATUS_INSERVER = "inservice" + CLOUD_REGION_STATUS_OUTOFSERVICE = "outofservice" + + DEFAULT_REGION_ID = "default" +) diff --git a/pkg/apis/compute/elasticips_const.go b/pkg/apis/compute/elasticips_const.go new file mode 100644 index 0000000000..cbc546ab5e --- /dev/null +++ b/pkg/apis/compute/elasticips_const.go @@ -0,0 +1,25 @@ +package compute + +const ( + EIP_MODE_INSTANCE_PUBLICIP = "public_ip" + EIP_MODE_STANDALONE_EIP = "elastic_ip" + + EIP_ASSOCIATE_TYPE_SERVER = "server" + + EIP_STATUS_READY = "ready" + EIP_STATUS_UNKNOWN = "unknown" + EIP_STATUS_ALLOCATE = "allocate" + EIP_STATUS_ALLOCATE_FAIL = "allocate_fail" + EIP_STATUS_DEALLOCATE = "deallocate" + EIP_STATUS_DEALLOCATE_FAIL = "deallocate_fail" + EIP_STATUS_ASSOCIATE = "associate" + EIP_STATUS_ASSOCIATE_FAIL = "associate_fail" + EIP_STATUS_DISSOCIATE = "dissociate" + EIP_STATUS_DISSOCIATE_FAIL = "dissociate_fail" + + EIP_STATUS_CHANGE_BANDWIDTH = "change_bandwidth" + + EIP_CHARGE_TYPE_BY_TRAFFIC = "traffic" + EIP_CHARGE_TYPE_BY_BANDWIDTH = "bandwidth" + EIP_CHARGE_TYPE_DEFAULT = EIP_CHARGE_TYPE_BY_TRAFFIC +) diff --git a/pkg/apis/compute/guest_const.go b/pkg/apis/compute/guest_const.go index 5b55a24d8d..89cb1b8165 100644 --- a/pkg/apis/compute/guest_const.go +++ b/pkg/apis/compute/guest_const.go @@ -184,3 +184,10 @@ var HOSTTYPE_HYPERVISOR = map[string]string{ HOST_TYPE_OPENSTACK: HYPERVISOR_OPENSTACK, HOST_TYPE_UCLOUD: HYPERVISOR_UCLOUD, } + +const ( + VM_AWS_DEFAULT_LOGIN_USER = "ec2user" + + VM_METADATA_APP_TAGS = "app_tags" + VM_METADATA_CREATE_PARAMS = "create_params" +) diff --git a/pkg/apis/compute/sku_const.go b/pkg/apis/compute/sku_const.go new file mode 100644 index 0000000000..5d1e3e9d8f --- /dev/null +++ b/pkg/apis/compute/sku_const.go @@ -0,0 +1,28 @@ +package compute + +const ( + SkuCategoryGeneralPurpose = "general_purpose" // 通用型 + SkuCategoryBurstable = "burstable" // 突发性能型 + SkuCategoryComputeOptimized = "compute_optimized" // 计算优化型 + SkuCategoryMemoryOptimized = "memory_optimized" // 内存优化型 + SkuCategoryStorageIOOptimized = "storage_optimized" // 存储IO优化型 + SkuCategoryHardwareAccelerated = "hardware_accelerated" // 硬件加速型 + SkuCategoryHighStorage = "high_storage" // 高存储型 + SkuCategoryHighMemory = "high_memory" // 高内存型 +) + +const ( + SkuStatusAvailable = "available" + SkuStatusSoldout = "soldout" +) + +var InstanceFamilies = map[string]string{ + SkuCategoryGeneralPurpose: "g1", + SkuCategoryBurstable: "t1", + SkuCategoryComputeOptimized: "c1", + SkuCategoryMemoryOptimized: "r1", + SkuCategoryStorageIOOptimized: "i1", + SkuCategoryHardwareAccelerated: "", + SkuCategoryHighStorage: "hc1", + SkuCategoryHighMemory: "hr1", +} diff --git a/pkg/apis/compute/snapshot_const.go b/pkg/apis/compute/snapshot_const.go new file mode 100644 index 0000000000..e15ae434fb --- /dev/null +++ b/pkg/apis/compute/snapshot_const.go @@ -0,0 +1,14 @@ +package compute + +const ( + // create by + SNAPSHOT_MANUAL = "manual" + SNAPSHOT_AUTO = "auto" + + SNAPSHOT_CREATING = "creating" + SNAPSHOT_ROLLBACKING = "rollbacking" + SNAPSHOT_FAILED = "create_failed" + SNAPSHOT_READY = "ready" + SNAPSHOT_DELETING = "deleting" + SNAPSHOT_UNKNOWN = "unknown" +) diff --git a/pkg/apis/compute/vpcs_const.go b/pkg/apis/compute/vpcs_const.go new file mode 100644 index 0000000000..6b5b5ca3ec --- /dev/null +++ b/pkg/apis/compute/vpcs_const.go @@ -0,0 +1,17 @@ +package compute + +const ( + VPC_STATUS_PENDING = "pending" + VPC_STATUS_AVAILABLE = "available" + VPC_STATUS_FAILED = "failed" + VPC_STATUS_START_DELETE = "start_delete" + VPC_STATUS_DELETING = "deleting" + VPC_STATUS_DELETE_FAILED = "delete_failed" + VPC_STATUS_DELETED = "deleted" + VPC_STATUS_UNKNOWN = "unknown" + + MAX_VPC_PER_REGION = 3 + + DEFAULT_VPC_ID = "default" + NORMAL_VPC_ID = "normal" // 没有关联VPC的安全组,统一使用normal +) diff --git a/pkg/apis/compute/zones_const.go b/pkg/apis/compute/zones_const.go new file mode 100644 index 0000000000..ec7be4cf10 --- /dev/null +++ b/pkg/apis/compute/zones_const.go @@ -0,0 +1,9 @@ +package compute + +const ( + ZONE_INIT = "init" + ZONE_ENABLE = "enable" + ZONE_DISABLE = "disable" + ZONE_SOLDOUT = "soldout" + // ZONE_LACK = "lack" +) diff --git a/pkg/compute/guestdrivers/aliyun.go b/pkg/compute/guestdrivers/aliyun.go index dd17d87d44..79178480aa 100644 --- a/pkg/compute/guestdrivers/aliyun.go +++ b/pkg/compute/guestdrivers/aliyun.go @@ -39,11 +39,11 @@ func init() { } func (self *SAliyunGuestDriver) GetHypervisor() string { - return models.HYPERVISOR_ALIYUN + return api.HYPERVISOR_ALIYUN } func (self *SAliyunGuestDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_CLOUD_EFFICIENCY + return api.STORAGE_CLOUD_EFFICIENCY } func (self *SAliyunGuestDriver) GetMinimalSysDiskSizeGb() int { @@ -52,11 +52,11 @@ func (self *SAliyunGuestDriver) GetMinimalSysDiskSizeGb() int { func (self *SAliyunGuestDriver) GetStorageTypes() []string { return []string{ - models.STORAGE_CLOUD_EFFICIENCY, - models.STORAGE_CLOUD_SSD, - models.STORAGE_CLOUD_ESSD, - models.STORAGE_PUBLIC_CLOUD, - models.STORAGE_EPHEMERAL_SSD, + api.STORAGE_CLOUD_EFFICIENCY, + api.STORAGE_CLOUD_SSD, + api.STORAGE_CLOUD_ESSD, + api.STORAGE_PUBLIC_CLOUD, + api.STORAGE_EPHEMERAL_SSD, } } @@ -78,33 +78,33 @@ func (self *SAliyunGuestDriver) ChooseHostStorage(host *models.SHost, backend st } func (self *SAliyunGuestDriver) GetDetachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAliyunGuestDriver) GetAttachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAliyunGuestDriver) GetRebuildRootStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAliyunGuestDriver) GetChangeConfigStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAliyunGuestDriver) GetDeployStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAliyunGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error { - if !utils.IsInStringArray(guest.Status, []string{models.VM_READY, models.VM_RUNNING}) { + if !utils.IsInStringArray(guest.Status, []string{api.VM_READY, api.VM_RUNNING}) { return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status) } - if disk.DiskType == models.DISK_TYPE_SYS { + if disk.DiskType == api.DISK_TYPE_SYS { return fmt.Errorf("Cannot resize system disk") } - if !utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_PUBLIC_CLOUD, models.STORAGE_CLOUD_SSD, models.STORAGE_CLOUD_EFFICIENCY}) { + if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_PUBLIC_CLOUD, api.STORAGE_CLOUD_SSD, api.STORAGE_CLOUD_EFFICIENCY}) { return fmt.Errorf("Cannot resize %s disk", storage.StorageType) } return nil @@ -127,15 +127,15 @@ func (self *SAliyunGuestDriver) ValidateCreateData(ctx context.Context, userCred return nil, httperrors.NewInputParameterError("The system disk size must be in the range of 20GB ~ 500Gb") } switch disk.Backend { - case models.STORAGE_CLOUD_EFFICIENCY, models.STORAGE_CLOUD_SSD, models.STORAGE_CLOUD_ESSD: + case api.STORAGE_CLOUD_EFFICIENCY, api.STORAGE_CLOUD_SSD, api.STORAGE_CLOUD_ESSD: if disk.SizeMb < 20*1024 || disk.SizeMb > 32768*1024 { return nil, httperrors.NewInputParameterError("The %s disk size must be in the range of 20GB ~ 32768GB", disk.Backend) } - case models.STORAGE_PUBLIC_CLOUD: + case api.STORAGE_PUBLIC_CLOUD: if disk.SizeMb < 5*1024 || disk.SizeMb > 2000*1024 { return nil, httperrors.NewInputParameterError("The %s disk size must be in the range of 5GB ~ 2000GB", disk.Backend) } - case models.STORAGE_EPHEMERAL_SSD: + case api.STORAGE_EPHEMERAL_SSD: if disk.SizeMb < 5*1024 || disk.SizeMb > 800*1024 { return nil, httperrors.NewInputParameterError("The %s disk size must be in the range of 5GB ~ 800GB", disk.Backend) } @@ -145,11 +145,11 @@ func (self *SAliyunGuestDriver) ValidateCreateData(ctx context.Context, userCred } func (self *SAliyunGuestDriver) GetGuestInitialStateAfterCreate() string { - return models.VM_READY + return api.VM_READY } func (self *SAliyunGuestDriver) GetGuestInitialStateAfterRebuild() string { - return models.VM_READY + return api.VM_READY } func (self *SAliyunGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string { diff --git a/pkg/compute/guestdrivers/aws.go b/pkg/compute/guestdrivers/aws.go index a7a64e430d..159a84c5ad 100644 --- a/pkg/compute/guestdrivers/aws.go +++ b/pkg/compute/guestdrivers/aws.go @@ -69,15 +69,15 @@ func fetchAwsUserName(desc cloudprovider.SManagedVMCreateConfig) string { func (self *SAwsGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string { // return fetchAwsUserName(desc) - return models.VM_AWS_DEFAULT_LOGIN_USER + return api.VM_AWS_DEFAULT_LOGIN_USER } func (self *SAwsGuestDriver) GetHypervisor() string { - return models.HYPERVISOR_AWS + return api.HYPERVISOR_AWS } func (self *SAwsGuestDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_GP2_SSD + return api.STORAGE_GP2_SSD } func (self *SAwsGuestDriver) GetMinimalSysDiskSizeGb() int { @@ -86,11 +86,11 @@ func (self *SAwsGuestDriver) GetMinimalSysDiskSizeGb() int { func (self *SAwsGuestDriver) GetStorageTypes() []string { return []string{ - models.STORAGE_GP2_SSD, - models.STORAGE_IO1_SSD, - models.STORAGE_ST1_HDD, - models.STORAGE_SC1_HDD, - models.STORAGE_STANDARD_HDD, + api.STORAGE_GP2_SSD, + api.STORAGE_IO1_SSD, + api.STORAGE_ST1_HDD, + api.STORAGE_SC1_HDD, + api.STORAGE_STANDARD_HDD, } } @@ -113,23 +113,23 @@ func (self *SAwsGuestDriver) ChooseHostStorage(host *models.SHost, backend strin } func (self *SAwsGuestDriver) GetDetachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAwsGuestDriver) GetAttachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAwsGuestDriver) GetRebuildRootStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAwsGuestDriver) GetChangeConfigStatus() ([]string, error) { - return []string{models.VM_READY}, nil + return []string{api.VM_READY}, nil } func (self *SAwsGuestDriver) GetDeployStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAwsGuestDriver) RequestDetachDisk(ctx context.Context, guest *models.SGuest, task taskman.ITask) error { @@ -142,24 +142,24 @@ func (self *SAwsGuestDriver) ValidateCreateData(ctx context.Context, userCred mc func (self *SAwsGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error { // https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/stop-start.html - if !utils.IsInStringArray(guest.Status, []string{models.VM_RUNNING, models.VM_READY}) { + if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY}) { return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status) } - if disk.DiskType == models.DISK_TYPE_SYS && !utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_IO1_SSD, models.STORAGE_STANDARD_HDD, models.STORAGE_GP2_SSD}) { + if disk.DiskType == api.DISK_TYPE_SYS && !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_IO1_SSD, api.STORAGE_STANDARD_HDD, api.STORAGE_GP2_SSD}) { return fmt.Errorf("Cannot resize system disk with unsupported volumes type %s", storage.StorageType) } - if !utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_GP2_SSD, models.STORAGE_IO1_SSD, models.STORAGE_ST1_HDD, models.STORAGE_SC1_HDD, models.STORAGE_STANDARD_HDD}) { + if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_GP2_SSD, api.STORAGE_IO1_SSD, api.STORAGE_ST1_HDD, api.STORAGE_SC1_HDD, api.STORAGE_STANDARD_HDD}) { return fmt.Errorf("Cannot resize %s disk", storage.StorageType) } return nil } func (self *SAwsGuestDriver) GetGuestInitialStateAfterCreate() string { - return models.VM_RUNNING + return api.VM_RUNNING } func (self *SAwsGuestDriver) GetGuestInitialStateAfterRebuild() string { - return models.VM_READY + return api.VM_READY } /*func (self *SAwsGuestDriver) RequestDeployGuestOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error { diff --git a/pkg/compute/guestdrivers/azure.go b/pkg/compute/guestdrivers/azure.go index 97cad489a0..1a6e5c91b7 100644 --- a/pkg/compute/guestdrivers/azure.go +++ b/pkg/compute/guestdrivers/azure.go @@ -45,11 +45,11 @@ func init() { } func (self *SAzureGuestDriver) GetHypervisor() string { - return models.HYPERVISOR_AZURE + return api.HYPERVISOR_AZURE } func (self *SAzureGuestDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_STANDARD_LRS + return api.STORAGE_STANDARD_LRS } func (self *SAzureGuestDriver) GetMinimalSysDiskSizeGb() int { @@ -58,9 +58,9 @@ func (self *SAzureGuestDriver) GetMinimalSysDiskSizeGb() int { func (self *SAzureGuestDriver) GetStorageTypes() []string { return []string{ - models.STORAGE_STANDARD_LRS, - models.STORAGE_STANDARDSSD_LRS, - models.STORAGE_PREMIUM_LRS, + api.STORAGE_STANDARD_LRS, + api.STORAGE_STANDARDSSD_LRS, + api.STORAGE_PREMIUM_LRS, } } @@ -86,23 +86,23 @@ func (self *SAzureGuestDriver) GetMaxSecurityGroupCount() int { } func (self *SAzureGuestDriver) GetDetachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAzureGuestDriver) GetAttachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAzureGuestDriver) GetRebuildRootStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAzureGuestDriver) GetChangeConfigStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SAzureGuestDriver) GetDeployStatus() ([]string, error) { - return []string{models.VM_RUNNING}, nil + return []string{api.VM_RUNNING}, nil } func (self *SAzureGuestDriver) IsNeedRestartForResetLoginInfo() bool { @@ -112,7 +112,7 @@ func (self *SAzureGuestDriver) IsNeedRestartForResetLoginInfo() bool { func (self *SAzureGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error { //https://docs.microsoft.com/en-us/rest/api/compute/disks/update //Resizes are only allowed if the disk is not attached to a running VM, and can only increase the disk's size - if !utils.IsInStringArray(guest.Status, []string{models.VM_READY}) { + if !utils.IsInStringArray(guest.Status, []string{api.VM_READY}) { return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status) } return nil @@ -149,11 +149,11 @@ func (self *SAzureGuestDriver) ValidateUpdateData(ctx context.Context, userCred } func (self *SAzureGuestDriver) GetGuestInitialStateAfterCreate() string { - return models.VM_RUNNING + return api.VM_RUNNING } func (self *SAzureGuestDriver) GetGuestInitialStateAfterRebuild() string { - return models.VM_READY + return api.VM_READY } func (self *SAzureGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string { diff --git a/pkg/compute/guestdrivers/baremetals.go b/pkg/compute/guestdrivers/baremetals.go index 47ad6a4d02..c859faa8f4 100644 --- a/pkg/compute/guestdrivers/baremetals.go +++ b/pkg/compute/guestdrivers/baremetals.go @@ -46,11 +46,11 @@ func init() { } func (self *SBaremetalGuestDriver) GetHypervisor() string { - return models.HYPERVISOR_BAREMETAL + return api.HYPERVISOR_BAREMETAL } func (self *SBaremetalGuestDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_LOCAL + return api.STORAGE_LOCAL } func (self *SBaremetalGuestDriver) GetMinimalSysDiskSizeGb() int { @@ -93,7 +93,7 @@ func (self *SBaremetalGuestDriver) PrepareDiskRaidConfig(userCred mcclient.Token } func (self *SBaremetalGuestDriver) GetRebuildRootStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_ADMIN}, nil + return []string{api.VM_READY, api.VM_ADMIN}, nil } func (self *SBaremetalGuestDriver) GetChangeConfigStatus() ([]string, error) { @@ -101,7 +101,7 @@ func (self *SBaremetalGuestDriver) GetChangeConfigStatus() ([]string, error) { } func (self *SBaremetalGuestDriver) GetDeployStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_ADMIN}, nil + return []string{api.VM_READY, api.VM_ADMIN}, nil } func (self *SBaremetalGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error { @@ -136,7 +136,7 @@ func (self *SBaremetalGuestDriver) GetNamedNetworkConfiguration(guest *models.SG } func (self *SBaremetalGuestDriver) GetRandomNetworkTypes() []string { - return []string{models.NETWORK_TYPE_BAREMETAL, models.NETWORK_TYPE_GUEST} + return []string{api.NETWORK_TYPE_BAREMETAL, api.NETWORK_TYPE_GUEST} } func (self *SBaremetalGuestDriver) Attach2RandomNetwork(guest *models.SGuest, ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, netConfig *api.NetworkConfig, pendingUsage quotas.IQuota) ([]models.SGuestnetwork, error) { @@ -209,7 +209,7 @@ func (self *SBaremetalGuestDriver) Attach2RandomNetwork(guest *models.SGuest, ct func (self *SBaremetalGuestDriver) GetStorageTypes() []string { return []string{ - models.STORAGE_BAREMETAL, + api.STORAGE_BAREMETAL, } } @@ -249,7 +249,7 @@ func (self *SBaremetalGuestDriver) RequestStopGuestForDelete(ctx context.Context overridePendingDelete := jsonutils.QueryBoolean(task.GetParams(), "override_pending_delete", false) purge := jsonutils.QueryBoolean(task.GetParams(), "purge", false) if host != nil && host.Enabled && - (guestStatus == models.VM_RUNNING || strings.Index(guestStatus, "stop") >= 0) && + (guestStatus == api.VM_RUNNING || strings.Index(guestStatus, "stop") >= 0) && options.Options.EnablePendingDelete && !guest.PendingDeleted && !overridePendingDelete && @@ -339,10 +339,10 @@ func (self *SBaremetalGuestDriver) ValidateCreateData(ctx context.Context, userC } func (self *SBaremetalGuestDriver) ValidateCreateDataOnHost(ctx context.Context, userCred mcclient.TokenCredential, bmName string, host *models.SHost, input *api.ServerCreateInput) (*api.ServerCreateInput, error) { - if host.HostType != models.HOST_TYPE_BAREMETAL || !host.IsBaremetal { + if host.HostType != api.HOST_TYPE_BAREMETAL || !host.IsBaremetal { return nil, httperrors.NewInputParameterError("Host %s is not a baremetal", bmName) } - if !utils.IsInStringArray(host.Status, []string{models.BAREMETAL_READY, models.BAREMETAL_RUNNING, models.BAREMETAL_START_CONVERT}) { + if !utils.IsInStringArray(host.Status, []string{api.BAREMETAL_READY, api.BAREMETAL_RUNNING, api.BAREMETAL_START_CONVERT}) { return nil, httperrors.NewInvalidStatusError("Baremetal %s is not ready", bmName) } if host.GetBaremetalServer() != nil { @@ -390,13 +390,13 @@ func (self *SBaremetalGuestDriver) OnGuestDeployTaskDataReceived(ctx context.Con } disk := iDisk.(*models.SDisk) diskSize, _ := disks[i].Int("size") - notes := fmt.Sprintf("%s=>%s", disk.Status, models.DISK_READY) + notes := fmt.Sprintf("%s=>%s", disk.Status, api.DISK_READY) _, err := db.Update(disk, func() error { if disk.DiskSize < int(diskSize) { disk.DiskSize = int(diskSize) } disk.DiskFormat = "raw" - disk.Status = models.DISK_READY + disk.Status = api.DISK_READY return nil }) if err != nil { diff --git a/pkg/compute/guestdrivers/base.go b/pkg/compute/guestdrivers/base.go index d96f262a89..92e2680c7d 100644 --- a/pkg/compute/guestdrivers/base.go +++ b/pkg/compute/guestdrivers/base.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -235,11 +236,11 @@ func (self *SBaseGuestDriver) RemoteDeployGuestForRebuildRoot(ctx context.Contex } func (self *SBaseGuestDriver) GetGuestInitialStateAfterCreate() string { - return models.VM_READY + return api.VM_READY } func (self *SBaseGuestDriver) GetGuestInitialStateAfterRebuild() string { - return models.VM_READY + return api.VM_READY } func (self *SBaseGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string { diff --git a/pkg/compute/guestdrivers/container.go b/pkg/compute/guestdrivers/container.go index addfc8ad34..b0ea336b58 100644 --- a/pkg/compute/guestdrivers/container.go +++ b/pkg/compute/guestdrivers/container.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/compute/options" @@ -47,11 +48,11 @@ func (self *SContainerDriver) newUnsupportOperationError(option string) error { } func (self *SContainerDriver) GetHypervisor() string { - return models.HYPERVISOR_CONTAINER + return api.HYPERVISOR_CONTAINER } func (self *SContainerDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_LOCAL + return api.STORAGE_LOCAL } func (self *SContainerDriver) GetMinimalSysDiskSizeGb() int { @@ -131,7 +132,7 @@ func (self *SContainerDriver) RequestUndeployGuestOnHost(ctx context.Context, gu } func (self *SContainerDriver) OnGuestDeployTaskComplete(ctx context.Context, guest *models.SGuest, task taskman.ITask) error { - guest.SetStatus(task.GetUserCred(), models.VM_RUNNING, "on deploy complete") + guest.SetStatus(task.GetUserCred(), api.VM_RUNNING, "on deploy complete") task.SetStageComplete(ctx, nil) return nil } @@ -182,7 +183,7 @@ func (self *SContainerDriver) RequestRebuildRootDisk(ctx context.Context, guest } func (self *SContainerDriver) GetRandomNetworkTypes() []string { - return []string{models.NETWORK_TYPE_CONTAINER, models.NETWORK_TYPE_GUEST} + return []string{api.NETWORK_TYPE_CONTAINER, api.NETWORK_TYPE_GUEST} } func (self *SContainerDriver) StartGuestRestartTask(guest *models.SGuest, ctx context.Context, userCred mcclient.TokenCredential, isForce bool, parentTaskId string) error { diff --git a/pkg/compute/guestdrivers/esxi.go b/pkg/compute/guestdrivers/esxi.go index fb2e034695..16eb7d492a 100644 --- a/pkg/compute/guestdrivers/esxi.go +++ b/pkg/compute/guestdrivers/esxi.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/compute/options" @@ -41,11 +42,11 @@ func init() { } func (self *SESXiGuestDriver) GetHypervisor() string { - return models.HYPERVISOR_ESXI + return api.HYPERVISOR_ESXI } func (self *SESXiGuestDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_LOCAL + return api.STORAGE_LOCAL } func (self *SESXiGuestDriver) GetMinimalSysDiskSizeGb() int { @@ -63,15 +64,15 @@ func (self *SESXiGuestDriver) GetMaxSecurityGroupCount() int { } func (self *SESXiGuestDriver) GetDetachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SESXiGuestDriver) GetAttachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SESXiGuestDriver) GetChangeConfigStatus() ([]string, error) { - return []string{models.VM_READY}, nil + return []string{api.VM_READY}, nil } func (self *SESXiGuestDriver) CanKeepDetachDisk() bool { @@ -93,18 +94,18 @@ func (self *SESXiGuestDriver) RequestGuestHotAddIso(ctx context.Context, guest * } func (self *SESXiGuestDriver) GetRebuildRootStatus() ([]string, error) { - return []string{models.VM_READY}, nil + return []string{api.VM_READY}, nil } func (self *SESXiGuestDriver) GetDeployStatus() ([]string, error) { - return []string{models.VM_READY}, nil + return []string{api.VM_READY}, nil } func (self *SESXiGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error { - if !utils.IsInStringArray(guest.Status, []string{models.VM_READY}) { + if !utils.IsInStringArray(guest.Status, []string{api.VM_READY}) { return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status) } - if disk.DiskType == models.DISK_TYPE_SYS { + if disk.DiskType == api.DISK_TYPE_SYS { return fmt.Errorf("Cannot resize system disk") } /*if !utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_PUBLIC_CLOUD, models.STORAGE_CLOUD_SSD, models.STORAGE_CLOUD_EFFICIENCY}) { diff --git a/pkg/compute/guestdrivers/huawei.go b/pkg/compute/guestdrivers/huawei.go index 3163f6c9bc..f6e79ef0be 100644 --- a/pkg/compute/guestdrivers/huawei.go +++ b/pkg/compute/guestdrivers/huawei.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/compute/models" @@ -36,11 +37,11 @@ func init() { } func (self *SHuaweiGuestDriver) GetHypervisor() string { - return models.HYPERVISOR_HUAWEI + return api.HYPERVISOR_HUAWEI } func (self *SHuaweiGuestDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_HUAWEI_SATA + return api.STORAGE_HUAWEI_SATA } func (self *SHuaweiGuestDriver) GetMinimalSysDiskSizeGb() int { @@ -48,7 +49,7 @@ func (self *SHuaweiGuestDriver) GetMinimalSysDiskSizeGb() int { } func (self *SHuaweiGuestDriver) GetStorageTypes() []string { - return []string{models.STORAGE_HUAWEI_SATA, models.STORAGE_HUAWEI_SAS, models.STORAGE_HUAWEI_SSD} + return []string{api.STORAGE_HUAWEI_SATA, api.STORAGE_HUAWEI_SAS, api.STORAGE_HUAWEI_SSD} } func (self *SHuaweiGuestDriver) ChooseHostStorage(host *models.SHost, backend string) *models.SStorage { @@ -70,23 +71,23 @@ func (self *SHuaweiGuestDriver) ChooseHostStorage(host *models.SHost, backend st } func (self *SHuaweiGuestDriver) GetDetachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SHuaweiGuestDriver) GetAttachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SHuaweiGuestDriver) GetRebuildRootStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SHuaweiGuestDriver) GetChangeConfigStatus() ([]string, error) { - return []string{models.VM_READY}, nil + return []string{api.VM_READY}, nil } func (self *SHuaweiGuestDriver) GetDeployStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SHuaweiGuestDriver) RequestDetachDisk(ctx context.Context, guest *models.SGuest, task taskman.ITask) error { @@ -94,10 +95,10 @@ func (self *SHuaweiGuestDriver) RequestDetachDisk(ctx context.Context, guest *mo } func (self *SHuaweiGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error { - if !utils.IsInStringArray(guest.Status, []string{models.VM_RUNNING, models.VM_READY}) { + if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY}) { return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status) } - if !utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_HUAWEI_SATA, models.STORAGE_HUAWEI_SAS, models.STORAGE_HUAWEI_SSD}) { + if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_HUAWEI_SATA, api.STORAGE_HUAWEI_SAS, api.STORAGE_HUAWEI_SSD}) { return fmt.Errorf("Cannot resize disk with unsupported volumes type %s", storage.StorageType) } @@ -105,11 +106,11 @@ func (self *SHuaweiGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *m } func (self *SHuaweiGuestDriver) GetGuestInitialStateAfterCreate() string { - return models.VM_RUNNING + return api.VM_RUNNING } func (self *SHuaweiGuestDriver) GetGuestInitialStateAfterRebuild() string { - return models.VM_RUNNING + return api.VM_RUNNING } func (self *SHuaweiGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string { diff --git a/pkg/compute/guestdrivers/kvm.go b/pkg/compute/guestdrivers/kvm.go index fee57dd67b..a6c6653b61 100644 --- a/pkg/compute/guestdrivers/kvm.go +++ b/pkg/compute/guestdrivers/kvm.go @@ -45,11 +45,11 @@ func init() { } func (self *SKVMGuestDriver) GetHypervisor() string { - return models.HYPERVISOR_KVM + return api.HYPERVISOR_KVM } func (self *SKVMGuestDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_LOCAL + return api.STORAGE_LOCAL } func (self *SKVMGuestDriver) GetMinimalSysDiskSizeGb() int { @@ -315,27 +315,27 @@ func (self *SKVMGuestDriver) RequestAttachDisk(ctx context.Context, guest *model } func (self *SKVMGuestDriver) GetDetachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SKVMGuestDriver) GetAttachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SKVMGuestDriver) GetRebuildRootStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SKVMGuestDriver) GetChangeConfigStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SKVMGuestDriver) GetDeployStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_ADMIN}, nil + return []string{api.VM_READY, api.VM_ADMIN}, nil } func (self *SKVMGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error { - if !utils.IsInStringArray(guest.Status, []string{models.VM_READY, models.VM_RUNNING}) { + if !utils.IsInStringArray(guest.Status, []string{api.VM_READY, api.VM_RUNNING}) { return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status) } return nil diff --git a/pkg/compute/guestdrivers/managedvirtual.go b/pkg/compute/guestdrivers/managedvirtual.go index f8577a53cf..443f1d207f 100644 --- a/pkg/compute/guestdrivers/managedvirtual.go +++ b/pkg/compute/guestdrivers/managedvirtual.go @@ -24,6 +24,7 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/compare" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" @@ -91,7 +92,7 @@ func (self *SManagedVirtualizedGuestDriver) GetJsonDescAtHost(ctx context.Contex } } - if guest.BillingType == models.BILLING_TYPE_PREPAID { + if guest.BillingType == billing_api.BILLING_TYPE_PREPAID { bc, err := billing.ParseBillingCycle(guest.BillingCycle) if err != nil { log.Errorf("fail to parse billing cycle %s: %s", guest.BillingCycle, err) @@ -156,7 +157,7 @@ func (self *SManagedVirtualizedGuestDriver) RequestStartOnHost(ctx context.Conte } result := jsonutils.NewDict() - if ivm.GetStatus() != models.VM_RUNNING { + if ivm.GetStatus() != api.VM_RUNNING { if err := ivm.StartVM(ctx); err != nil { return nil, e } else { @@ -213,11 +214,11 @@ func (self *SManagedVirtualizedGuestDriver) RequestDeployGuestOnHost(ctx context } func (self *SManagedVirtualizedGuestDriver) GetGuestInitialStateAfterCreate() string { - return models.VM_READY + return api.VM_READY } func (self *SManagedVirtualizedGuestDriver) GetGuestInitialStateAfterRebuild() string { - return models.VM_READY + return api.VM_READY } func (self *SManagedVirtualizedGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string { @@ -466,17 +467,17 @@ func (self *SManagedVirtualizedGuestDriver) RequestSyncstatusOnHost(ctx context. status := ivm.GetStatus() switch status { - case models.VM_RUNNING: + case api.VM_RUNNING: status = cloudprovider.CloudVMStatusRunning - case models.VM_READY: + case api.VM_READY: status = cloudprovider.CloudVMStatusStopped - case models.VM_STARTING: + case api.VM_STARTING: status = cloudprovider.CloudVMStatusStopped - case models.VM_STOPPING: + case api.VM_STOPPING: status = cloudprovider.CloudVMStatusRunning - case models.VM_CHANGE_FLAVOR: + case api.VM_CHANGE_FLAVOR: status = cloudprovider.CloudVMStatusChangeFlavor - case models.VM_DEPLOYING: + case api.VM_DEPLOYING: status = cloudprovider.CloudVMStatusDeploying default: status = cloudprovider.CloudVMStatusOther @@ -608,7 +609,7 @@ func (self *SManagedVirtualizedGuestDriver) OnGuestDeployTaskDataReceived(ctx co disk.DiskSize = diskInfo[i].Size disk.ExternalId = diskInfo[i].Uuid disk.DiskType = diskInfo[i].DiskType - disk.Status = models.DISK_READY + disk.Status = api.DISK_READY disk.FsFormat = diskInfo[i].FsFromat if diskInfo[i].AutoDelete { diff --git a/pkg/compute/guestdrivers/openstack.go b/pkg/compute/guestdrivers/openstack.go index 16c598c178..b6f8824e68 100644 --- a/pkg/compute/guestdrivers/openstack.go +++ b/pkg/compute/guestdrivers/openstack.go @@ -42,7 +42,7 @@ func init() { } func (self *SOpenStackGuestDriver) GetHypervisor() string { - return models.HYPERVISOR_OPENSTACK + return api.HYPERVISOR_OPENSTACK } func (self *SOpenStackGuestDriver) IsSupportEip() bool { @@ -50,7 +50,7 @@ func (self *SOpenStackGuestDriver) IsSupportEip() bool { } func (self *SOpenStackGuestDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_OPENSTACK_ISCSI + return api.STORAGE_OPENSTACK_ISCSI } func (self *SOpenStackGuestDriver) GetMinimalSysDiskSizeGb() int { @@ -58,7 +58,7 @@ func (self *SOpenStackGuestDriver) GetMinimalSysDiskSizeGb() int { } func (self *SOpenStackGuestDriver) GetStorageTypes() []string { - return []string{models.STORAGE_OPENSTACK_ISCSI} + return []string{api.STORAGE_OPENSTACK_ISCSI} } func (self *SOpenStackGuestDriver) ChooseHostStorage(host *models.SHost, backend string) *models.SStorage { @@ -79,19 +79,19 @@ func (self *SOpenStackGuestDriver) ChooseHostStorage(host *models.SHost, backend } func (self *SOpenStackGuestDriver) GetDetachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SOpenStackGuestDriver) GetAttachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SOpenStackGuestDriver) GetRebuildRootStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING, models.VM_REBUILD_ROOT_FAIL}, nil + return []string{api.VM_READY, api.VM_RUNNING, api.VM_REBUILD_ROOT_FAIL}, nil } func (self *SOpenStackGuestDriver) GetChangeConfigStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SOpenStackGuestDriver) IsNeedRestartForResetLoginInfo() bool { @@ -99,7 +99,7 @@ func (self *SOpenStackGuestDriver) IsNeedRestartForResetLoginInfo() bool { } func (self *SOpenStackGuestDriver) GetDeployStatus() ([]string, error) { - return []string{models.VM_RUNNING}, nil + return []string{api.VM_RUNNING}, nil } func (self *SOpenStackGuestDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, input *api.ServerCreateInput) (*api.ServerCreateInput, error) { @@ -115,11 +115,11 @@ func (self *SOpenStackGuestDriver) ValidateCreateData(ctx context.Context, userC } func (self *SOpenStackGuestDriver) GetGuestInitialStateAfterCreate() string { - return models.VM_RUNNING + return api.VM_RUNNING } func (self *SOpenStackGuestDriver) GetGuestInitialStateAfterRebuild() string { - return models.VM_READY + return api.VM_READY } /*func (self *SOpenStackGuestDriver) RequestDeployGuestOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error { diff --git a/pkg/compute/guestdrivers/qcloud.go b/pkg/compute/guestdrivers/qcloud.go index 0d1442441a..d5a0f54dae 100644 --- a/pkg/compute/guestdrivers/qcloud.go +++ b/pkg/compute/guestdrivers/qcloud.go @@ -42,11 +42,11 @@ func init() { } func (self *SQcloudGuestDriver) GetHypervisor() string { - return models.HYPERVISOR_QCLOUD + return api.HYPERVISOR_QCLOUD } func (self *SQcloudGuestDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_CLOUD_PREMIUM + return api.STORAGE_CLOUD_PREMIUM } func (self *SQcloudGuestDriver) GetMinimalSysDiskSizeGb() int { @@ -55,11 +55,11 @@ func (self *SQcloudGuestDriver) GetMinimalSysDiskSizeGb() int { func (self *SQcloudGuestDriver) GetStorageTypes() []string { return []string{ - models.STORAGE_CLOUD_BASIC, - models.STORAGE_CLOUD_PREMIUM, - models.STORAGE_CLOUD_SSD, - models.STORAGE_LOCAL_BASIC, - models.STORAGE_LOCAL_SSD, + api.STORAGE_CLOUD_BASIC, + api.STORAGE_CLOUD_PREMIUM, + api.STORAGE_CLOUD_SSD, + api.STORAGE_LOCAL_BASIC, + api.STORAGE_LOCAL_SSD, } } @@ -81,34 +81,34 @@ func (self *SQcloudGuestDriver) ChooseHostStorage(host *models.SHost, backend st } func (self *SQcloudGuestDriver) GetDetachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SQcloudGuestDriver) GetAttachDiskStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SQcloudGuestDriver) GetRebuildRootStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SQcloudGuestDriver) GetChangeConfigStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SQcloudGuestDriver) GetDeployStatus() ([]string, error) { - return []string{models.VM_READY, models.VM_RUNNING}, nil + return []string{api.VM_READY, api.VM_RUNNING}, nil } func (self *SQcloudGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error { //https://cloud.tencent.com/document/product/362/5747 - if !utils.IsInStringArray(guest.Status, []string{models.VM_READY, models.VM_RUNNING}) { + if !utils.IsInStringArray(guest.Status, []string{api.VM_READY, api.VM_RUNNING}) { return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status) } - if disk.DiskType == models.DISK_TYPE_SYS { + if disk.DiskType == api.DISK_TYPE_SYS { return fmt.Errorf("Cannot resize system disk") } - if utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_LOCAL_BASIC, models.STORAGE_LOCAL_SSD}) { + if utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_LOCAL_BASIC, api.STORAGE_LOCAL_SSD}) { return fmt.Errorf("Cannot resize %s disk", storage.StorageType) } return nil @@ -129,11 +129,11 @@ func (self *SQcloudGuestDriver) ValidateCreateData(ctx context.Context, userCred sysDisk := input.Disks[0] switch sysDisk.Backend { - case models.STORAGE_CLOUD_BASIC, models.STORAGE_CLOUD_SSD: + case api.STORAGE_CLOUD_BASIC, api.STORAGE_CLOUD_SSD: if sysDisk.SizeMb > 500*1024 { return nil, fmt.Errorf("The %s system disk size must be less than 500GB", sysDisk.Backend) } - case models.STORAGE_CLOUD_PREMIUM: + case api.STORAGE_CLOUD_PREMIUM: if sysDisk.SizeMb > 1024*1024 { return nil, fmt.Errorf("The %s system disk size must be less than 1024GB", sysDisk.Backend) } @@ -142,15 +142,15 @@ func (self *SQcloudGuestDriver) ValidateCreateData(ctx context.Context, userCred for i := 1; i < len(input.Disks); i++ { disk := input.Disks[i] switch disk.Backend { - case models.STORAGE_CLOUD_BASIC: + case api.STORAGE_CLOUD_BASIC: if disk.SizeMb < 10*1024 || disk.SizeMb > 16000*1024 { return nil, httperrors.NewInputParameterError("The %s disk size must be in the range of 10GB ~ 16000GB", disk.Backend) } - case models.STORAGE_CLOUD_PREMIUM: + case api.STORAGE_CLOUD_PREMIUM: if disk.SizeMb < 50*1024 || disk.SizeMb > 16000*1024 { return nil, httperrors.NewInputParameterError("The %s disk size must be in the range of 50GB ~ 16000GB", disk.Backend) } - case models.STORAGE_CLOUD_SSD: + case api.STORAGE_CLOUD_SSD: if disk.SizeMb < 100*1024 || disk.SizeMb > 16000*1024 { return nil, httperrors.NewInputParameterError("The %s disk size must be in the range of 100GB ~ 16000GB", disk.Backend) } @@ -160,11 +160,11 @@ func (self *SQcloudGuestDriver) ValidateCreateData(ctx context.Context, userCred } func (self *SQcloudGuestDriver) GetGuestInitialStateAfterCreate() string { - return models.VM_RUNNING + return api.VM_RUNNING } func (self *SQcloudGuestDriver) GetGuestInitialStateAfterRebuild() string { - return models.VM_RUNNING + return api.VM_RUNNING } func (self *SQcloudGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManagedVMCreateConfig) string { diff --git a/pkg/compute/guestdrivers/ucloud.go b/pkg/compute/guestdrivers/ucloud.go index 150b7c04ff..7cabf667e7 100644 --- a/pkg/compute/guestdrivers/ucloud.go +++ b/pkg/compute/guestdrivers/ucloud.go @@ -14,18 +14,21 @@ package guestdrivers -import "yunion.io/x/onecloud/pkg/compute/models" +import ( + api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/compute/models" +) type SUCloudGuestDriver struct { SManagedVirtualizedGuestDriver } func (self *SUCloudGuestDriver) GetHypervisor() string { - return models.HYPERVISOR_UCLOUD + return api.HYPERVISOR_UCLOUD } func (self *SUCloudGuestDriver) GetDefaultSysDiskBackend() string { - return models.STORAGE_UCLOUD_CLOUD_SSD + return api.STORAGE_UCLOUD_CLOUD_SSD } func (self *SUCloudGuestDriver) GetMinimalSysDiskSizeGb() int { diff --git a/pkg/compute/guestdrivers/utils.go b/pkg/compute/guestdrivers/utils.go index ddafd112e8..5289e86d23 100644 --- a/pkg/compute/guestdrivers/utils.go +++ b/pkg/compute/guestdrivers/utils.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SDiskInfo struct { @@ -113,7 +113,7 @@ func fetchIVMinfo(desc cloudprovider.SManagedVMCreateConfig, iVM cloudprovider.I } data.Add(metadataDict, "metadata") - if iVM.GetBillingType() == models.BILLING_TYPE_PREPAID { + if iVM.GetBillingType() == billing_api.BILLING_TYPE_PREPAID { data.Add(jsonutils.NewTimeString(iVM.GetExpiredAt()), "expired_at") } diff --git a/pkg/compute/guestdrivers/virtualization.go b/pkg/compute/guestdrivers/virtualization.go index 35276a571a..ea9e22d47f 100644 --- a/pkg/compute/guestdrivers/virtualization.go +++ b/pkg/compute/guestdrivers/virtualization.go @@ -67,7 +67,7 @@ func (self *SVirtualizedGuestDriver) GetNamedNetworkConfiguration(guest *models. } func (self *SVirtualizedGuestDriver) GetRandomNetworkTypes() []string { - return []string{models.NETWORK_TYPE_GUEST} + return []string{api.NETWORK_TYPE_GUEST} } func (self *SVirtualizedGuestDriver) Attach2RandomNetwork(guest *models.SGuest, ctx context.Context, userCred mcclient.TokenCredential, host *models.SHost, netConfig *api.NetworkConfig, pendingUsage quotas.IQuota) ([]models.SGuestnetwork, error) { @@ -192,7 +192,7 @@ func (self *SVirtualizedGuestDriver) RequestStopGuestForDelete(ctx context.Conte if host == nil { host = guest.GetHost() } - if host != nil && host.Enabled && host.HostStatus == models.HOST_ONLINE { + if host != nil && host.Enabled && host.HostStatus == api.HOST_ONLINE { return guest.StartGuestStopTask(ctx, task.GetUserCred(), true, task.GetTaskId()) } if host != nil && !jsonutils.QueryBoolean(task.GetParams(), "purge", false) { @@ -207,7 +207,7 @@ func (self *SVirtualizedGuestDriver) ValidateCreateData(ctx context.Context, use } func (self *SVirtualizedGuestDriver) ValidateCreateDataOnHost(ctx context.Context, userCred mcclient.TokenCredential, bmName string, host *models.SHost, input *api.ServerCreateInput) (*api.ServerCreateInput, error) { - if host.HostStatus != models.HOST_ONLINE { + if host.HostStatus != api.HOST_ONLINE { return nil, httperrors.NewInvalidStatusError("Host %s is not online", bmName) } input.PreferHost = host.Id diff --git a/pkg/compute/hostdrivers/aliyun.go b/pkg/compute/hostdrivers/aliyun.go index 6237f3897b..a1f6214b89 100644 --- a/pkg/compute/hostdrivers/aliyun.go +++ b/pkg/compute/hostdrivers/aliyun.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/httperrors" ) @@ -34,7 +35,7 @@ func init() { } func (self *SAliyunHostDriver) GetHostType() string { - return models.HOST_TYPE_ALIYUN + return api.HOST_TYPE_ALIYUN } func (self *SAliyunHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error { @@ -42,11 +43,11 @@ func (self *SAliyunHostDriver) ValidateAttachStorage(host *models.SHost, storage } func (self *SAliyunHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error { - if utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_CLOUD_EFFICIENCY, models.STORAGE_CLOUD_SSD, models.STORAGE_CLOUD_ESSD}) { + if utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_CLOUD_EFFICIENCY, api.STORAGE_CLOUD_SSD, api.STORAGE_CLOUD_ESSD}) { if sizeGb < 20 || sizeGb > 32768 { return fmt.Errorf("The %s disk size must be in the range of 20G ~ 32768GB", storage.StorageType) } - } else if storage.StorageType == models.STORAGE_PUBLIC_CLOUD { + } else if storage.StorageType == api.STORAGE_PUBLIC_CLOUD { if sizeGb < 5 || sizeGb > 2000 { return fmt.Errorf("The %s disk size must be in the range of 5G ~ 2000GB", storage.StorageType) } diff --git a/pkg/compute/hostdrivers/aws.go b/pkg/compute/hostdrivers/aws.go index aec36c4b86..897e2a4115 100644 --- a/pkg/compute/hostdrivers/aws.go +++ b/pkg/compute/hostdrivers/aws.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/httperrors" ) @@ -34,7 +35,7 @@ func init() { } func (self *SAwsHostDriver) GetHostType() string { - return models.HOST_TYPE_AWS + return api.HOST_TYPE_AWS } func (self *SAwsHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error { @@ -42,19 +43,19 @@ func (self *SAwsHostDriver) ValidateAttachStorage(host *models.SHost, storage *m } func (self *SAwsHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error { - if storage.StorageType == models.STORAGE_GP2_SSD { + if storage.StorageType == api.STORAGE_GP2_SSD { if sizeGb < 1 || sizeGb > 16384 { return fmt.Errorf("The %s disk size must be in the range of 1G ~ 16384GB", storage.StorageType) } - } else if storage.StorageType == models.STORAGE_IO1_SSD { + } else if storage.StorageType == api.STORAGE_IO1_SSD { if sizeGb < 4 || sizeGb > 16384 { return fmt.Errorf("The %s disk size must be in the range of 4G ~ 16384GB", storage.StorageType) } - } else if utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_ST1_HDD, models.STORAGE_SC1_HDD}) { + } else if utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_ST1_HDD, api.STORAGE_SC1_HDD}) { if sizeGb < 500 || sizeGb > 16384 { return fmt.Errorf("The %s disk size must be in the range of 500G ~ 16384GB", storage.StorageType) } - } else if storage.StorageType == models.STORAGE_STANDARD_HDD { + } else if storage.StorageType == api.STORAGE_STANDARD_HDD { if sizeGb < 1 || sizeGb > 1024 { return fmt.Errorf("The %s disk size must be in the range of 1G ~ 1024GB", storage.StorageType) } diff --git a/pkg/compute/hostdrivers/azure.go b/pkg/compute/hostdrivers/azure.go index d5b58ea86d..12e22c43dc 100644 --- a/pkg/compute/hostdrivers/azure.go +++ b/pkg/compute/hostdrivers/azure.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/httperrors" @@ -37,7 +38,7 @@ func init() { } func (self *SAzureHostDriver) GetHostType() string { - return models.HOST_TYPE_AZURE + return api.HOST_TYPE_AZURE } func (self *SAzureHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error { @@ -52,7 +53,7 @@ func (self *SAzureHostDriver) ValidateUpdateDisk(ctx context.Context, userCred m } func (self *SAzureHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error { - if utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_STANDARD_LRS, models.STORAGE_STANDARDSSD_LRS, models.STORAGE_PREMIUM_LRS}) { + if utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_STANDARD_LRS, api.STORAGE_STANDARDSSD_LRS, api.STORAGE_PREMIUM_LRS}) { if sizeGb < 1 || sizeGb > 4095 { return fmt.Errorf("The %s disk size must be in the range of 1G ~ 4095GB", storage.StorageType) } diff --git a/pkg/compute/hostdrivers/baremetal.go b/pkg/compute/hostdrivers/baremetal.go index 785e47d44e..0ca33716c3 100644 --- a/pkg/compute/hostdrivers/baremetal.go +++ b/pkg/compute/hostdrivers/baremetal.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/httperrors" @@ -35,7 +36,7 @@ func init() { } func (self *SBaremetalHostDriver) GetHostType() string { - return models.HOST_TYPE_BAREMETAL + return api.HOST_TYPE_BAREMETAL } func (self *SBaremetalHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error { diff --git a/pkg/compute/hostdrivers/base.go b/pkg/compute/hostdrivers/base.go index c6a1117a2d..bde4003e95 100644 --- a/pkg/compute/hostdrivers/base.go +++ b/pkg/compute/hostdrivers/base.go @@ -93,7 +93,7 @@ func (self *SBaseHostDriver) FinishUnconvert(ctx context.Context, userCred mccli if bss != nil { bs := bss.GetStorage() if bs != nil { - bs.SetStatus(userCred, models.STORAGE_ONLINE, "") + bs.SetStatus(userCred, api.STORAGE_ONLINE, "") } else { log.Errorf("ERROR: baremetal storage is None???") } @@ -111,8 +111,8 @@ func (self *SBaseHostDriver) FinishUnconvert(ctx context.Context, userCred mccli db.Update(host, func() error { host.AccessIp = adminNic.IpAddr host.Enabled = true - host.HostType = models.HOST_TYPE_BAREMETAL - host.HostStatus = models.HOST_OFFLINE + host.HostType = api.HOST_TYPE_BAREMETAL + host.HostStatus = api.HOST_OFFLINE host.ManagerUri = "" host.Version = "" host.MemReserved = 0 @@ -143,13 +143,13 @@ func (self *SBaseHostDriver) FinishConvert(userCred mcclient.TokenCredential, ho }) } bs := host.GetBaremetalstorage().GetStorage() - bs.SetStatus(userCred, models.STORAGE_OFFLINE, "") + bs.SetStatus(userCred, api.STORAGE_OFFLINE, "") db.Update(host, func() error { host.CpuReserved = 0 host.MemReserved = 0 host.AccessIp = guest.GetRealIPs()[0] host.Enabled = false - host.HostStatus = models.HOST_OFFLINE + host.HostStatus = api.HOST_OFFLINE host.HostType = hostType host.IsBaremetal = true return nil diff --git a/pkg/compute/hostdrivers/esxi.go b/pkg/compute/hostdrivers/esxi.go index 5d38b64714..f264a5bcd7 100644 --- a/pkg/compute/hostdrivers/esxi.go +++ b/pkg/compute/hostdrivers/esxi.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/httperrors" @@ -38,7 +39,7 @@ func init() { } func (self *SESXiHostDriver) GetHostType() string { - return models.HOST_TYPE_ESXI + return api.HOST_TYPE_ESXI } func (self *SESXiHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error { @@ -61,7 +62,7 @@ func (self *SESXiHostDriver) CheckAndSetCacheImage(ctx context.Context, host *mo return err } cacheImage := obj.(*models.SCachedimage) - srcHostCacheImage, err := cacheImage.ChooseSourceStoragecacheInRange(models.HOST_TYPE_ESXI, []string{host.Id}, + srcHostCacheImage, err := cacheImage.ChooseSourceStoragecacheInRange(api.HOST_TYPE_ESXI, []string{host.Id}, []interface{}{host.GetZone(), host.GetCloudprovider()}) if err != nil { return err diff --git a/pkg/compute/hostdrivers/huawei.go b/pkg/compute/hostdrivers/huawei.go index 81aea3cfbe..904e15fb1d 100644 --- a/pkg/compute/hostdrivers/huawei.go +++ b/pkg/compute/hostdrivers/huawei.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/httperrors" ) @@ -33,7 +34,7 @@ func init() { } func (self *SHuaweiHostDriver) GetHostType() string { - return models.HOST_TYPE_HUAWEI + return api.HOST_TYPE_HUAWEI } func (self *SHuaweiHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error { @@ -43,7 +44,7 @@ func (self *SHuaweiHostDriver) ValidateAttachStorage(host *models.SHost, storage // 系统盘必须至少40G func (self *SHuaweiHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error { switch storage.StorageType { - case models.STORAGE_HUAWEI_SSD, models.STORAGE_HUAWEI_SATA, models.STORAGE_HUAWEI_SAS: + case api.STORAGE_HUAWEI_SSD, api.STORAGE_HUAWEI_SATA, api.STORAGE_HUAWEI_SAS: if sizeGb < 10 || sizeGb > 32768 { return fmt.Errorf("The %s disk size must be in the range of 10G ~ 32768GB", storage.StorageType) } diff --git a/pkg/compute/hostdrivers/kvm.go b/pkg/compute/hostdrivers/kvm.go index 1cc6b624e3..774a97a63d 100644 --- a/pkg/compute/hostdrivers/kvm.go +++ b/pkg/compute/hostdrivers/kvm.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/baremetal" "yunion.io/x/onecloud/pkg/compute/models" @@ -42,21 +43,21 @@ func init() { } func (self *SKVMHostDriver) GetHostType() string { - return models.HOST_TYPE_HYPERVISOR + return api.HOST_TYPE_HYPERVISOR } func (self *SKVMHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error { - if !utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_LOCAL, models.STORAGE_RBD, models.STORAGE_NFS}) { + if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_LOCAL, api.STORAGE_RBD, api.STORAGE_NFS}) { return httperrors.NewUnsupportOperationError("Unsupport attach %s storage for %s host", storage.StorageType, host.HostType) } - if storage.StorageType == models.STORAGE_RBD { - if host.HostStatus != models.HOST_ONLINE { + if storage.StorageType == api.STORAGE_RBD { + if host.HostStatus != api.HOST_ONLINE { return httperrors.NewInvalidStatusError("Attach rbd storage require host status is online") } pool, _ := storage.StorageConf.GetString("pool") data.Set("mount_point", jsonutils.NewString(fmt.Sprintf("rbd:%s", pool))) - } else if storage.StorageType == models.STORAGE_NFS { - if host.HostStatus != models.HOST_ONLINE { + } else if storage.StorageType == api.STORAGE_NFS { + if host.HostStatus != api.HOST_ONLINE { return httperrors.NewInvalidStatusError("Attach nfs storage require host status is online") } } @@ -65,7 +66,7 @@ func (self *SKVMHostDriver) ValidateAttachStorage(host *models.SHost, storage *m func (self *SKVMHostDriver) RequestAttachStorage(ctx context.Context, hoststorage *models.SHoststorage, host *models.SHost, storage *models.SStorage, task taskman.ITask) error { taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) { - if utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_NFS, models.STORAGE_RBD}) { + if utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_NFS, api.STORAGE_RBD}) { log.Infof("Attach SharedStorage[%s] on host %s ...", storage.Name, host.Name) url := fmt.Sprintf("%s/storages/attach", host.ManagerUri) headers := mcclient.GetTokenHeaders(task.GetUserCred()) @@ -93,7 +94,7 @@ func (self *SKVMHostDriver) RequestAttachStorage(ctx context.Context, hoststorag func (self *SKVMHostDriver) RequestDetachStorage(ctx context.Context, host *models.SHost, storage *models.SStorage, task taskman.ITask) error { taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) { - if utils.IsInStringArray(storage.StorageType, []string{models.STORAGE_NFS, models.STORAGE_RBD}) && host.HostStatus == models.HOST_ONLINE { + if utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_NFS, api.STORAGE_RBD}) && host.HostStatus == api.HOST_ONLINE { log.Infof("Detach SharedStorage[%s] on host %s ...", storage.Name, host.Name) url := fmt.Sprintf("%s/storages/detach", host.ManagerUri) headers := mcclient.GetTokenHeaders(task.GetUserCred()) @@ -126,7 +127,7 @@ func (self *SKVMHostDriver) CheckAndSetCacheImage(ctx context.Context, host *mod return err } cacheImage := obj.(*models.SCachedimage) - srcHostCacheImage, err := cacheImage.ChooseSourceStoragecacheInRange(models.HOST_TYPE_HYPERVISOR, []string{host.Id}, []interface{}{host.GetZone()}) + srcHostCacheImage, err := cacheImage.ChooseSourceStoragecacheInRange(api.HOST_TYPE_HYPERVISOR, []string{host.Id}, []interface{}{host.GetZone()}) if err != nil { return err } @@ -447,7 +448,7 @@ func (self *SKVMHostDriver) PrepareUnconvert(host *models.SHost) error { } for i := 0; i < len(hoststorages); i++ { storage := hoststorages[i].GetStorage() - if storage.IsLocal() && storage.StorageType != models.STORAGE_BAREMETAL && storage.GetDiskCount() > 0 { + if storage.IsLocal() && storage.StorageType != api.STORAGE_BAREMETAL && storage.GetDiskCount() > 0 { return fmt.Errorf("Local host storage is not empty??? %s", storage.GetName()) } } @@ -460,7 +461,7 @@ func (self *SKVMHostDriver) FinishUnconvert(ctx context.Context, userCred mcclie if storage == nil { continue } - if storage.StorageType != models.STORAGE_BAREMETAL { + if storage.StorageType != api.STORAGE_BAREMETAL { hs.Delete(ctx, userCred) if storage.IsLocal() { storage.Delete(ctx, userCred) diff --git a/pkg/compute/hostdrivers/managedvirtual.go b/pkg/compute/hostdrivers/managedvirtual.go index ca80442b34..b03dbed0b6 100644 --- a/pkg/compute/hostdrivers/managedvirtual.go +++ b/pkg/compute/hostdrivers/managedvirtual.go @@ -172,13 +172,13 @@ func (self *SManagedVirtualizationHostDriver) RequestSaveUploadImageOnHost(ctx c osType, _ := params.GetString("properties", "os_type") scimg := models.StoragecachedimageManager.Register(ctx, task.GetUserCred(), iStoragecache.GetId(), imageId, "") - if scimg.Status != models.CACHED_IMAGE_STATUS_READY { - scimg.SetStatus(task.GetUserCred(), models.CACHED_IMAGE_STATUS_CACHING, "request_prepare_save_disk_on_host") + if scimg.Status != api.CACHED_IMAGE_STATUS_READY { + scimg.SetStatus(task.GetUserCred(), api.CACHED_IMAGE_STATUS_CACHING, "request_prepare_save_disk_on_host") } iImage, err := iStoragecache.CreateIImage(snapshot.GetId(), fmt.Sprintf("Image-%s", imageId), osType, "") if err != nil { log.Errorf("fail to create iImage: %v", err) - scimg.SetStatus(task.GetUserCred(), models.CACHED_IMAGE_STATUS_CACHE_FAILED, err.Error()) + scimg.SetStatus(task.GetUserCred(), api.CACHED_IMAGE_STATUS_CACHE_FAILED, err.Error()) return nil, err } scimg.SetExternalId(iImage.GetId()) @@ -189,7 +189,7 @@ func (self *SManagedVirtualizationHostDriver) RequestSaveUploadImageOnHost(ctx c } result, err := iStoragecache.DownloadImage(task.GetUserCred(), imageId, iImage.GetId(), options.Options.TempPath) if err != nil { - scimg.SetStatus(task.GetUserCred(), models.CACHED_IMAGE_STATUS_CACHE_FAILED, err.Error()) + scimg.SetStatus(task.GetUserCred(), api.CACHED_IMAGE_STATUS_CACHE_FAILED, err.Error()) return nil, err } if err := iImage.Delete(ctx); err != nil { @@ -198,7 +198,7 @@ func (self *SManagedVirtualizationHostDriver) RequestSaveUploadImageOnHost(ctx c if err := snapshot.Delete(); err != nil { log.Errorf("Delete snapshot %s failed: %v", snapshot.GetId(), err) } - scimg.SetStatus(task.GetUserCred(), models.CACHED_IMAGE_STATUS_READY, "") + scimg.SetStatus(task.GetUserCred(), api.CACHED_IMAGE_STATUS_READY, "") return result, nil }) return nil diff --git a/pkg/compute/hostdrivers/openstack.go b/pkg/compute/hostdrivers/openstack.go index ce46628bca..03183e1daf 100644 --- a/pkg/compute/hostdrivers/openstack.go +++ b/pkg/compute/hostdrivers/openstack.go @@ -17,6 +17,7 @@ package hostdrivers import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/httperrors" ) @@ -31,7 +32,7 @@ func init() { } func (self *SOpenStackHostDriver) GetHostType() string { - return models.HOST_TYPE_OPENSTACK + return api.HOST_TYPE_OPENSTACK } func (self *SOpenStackHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error { diff --git a/pkg/compute/hostdrivers/qcloud.go b/pkg/compute/hostdrivers/qcloud.go index aaa23b7b98..ae1418781f 100644 --- a/pkg/compute/hostdrivers/qcloud.go +++ b/pkg/compute/hostdrivers/qcloud.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/httperrors" @@ -35,7 +36,7 @@ func init() { } func (self *SQcloudHostDriver) GetHostType() string { - return models.HOST_TYPE_QCLOUD + return api.HOST_TYPE_QCLOUD } func (self *SQcloudHostDriver) ValidateAttachStorage(host *models.SHost, storage *models.SStorage, data *jsonutils.JSONDict) error { @@ -46,15 +47,15 @@ func (self *SQcloudHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb if sizeGb%10 != 0 { return fmt.Errorf("The disk size must be a multiple of 10Gb") } - if storage.StorageType == models.STORAGE_CLOUD_BASIC { + if storage.StorageType == api.STORAGE_CLOUD_BASIC { if sizeGb < 10 || sizeGb > 16000 { return fmt.Errorf("The %s disk size must be in the range of 10 ~ 16000GB", storage.StorageType) } - } else if storage.StorageType == models.STORAGE_CLOUD_PREMIUM { + } else if storage.StorageType == api.STORAGE_CLOUD_PREMIUM { if sizeGb < 50 || sizeGb > 16000 { return fmt.Errorf("The %s disk size must be in the range of 50 ~ 16000GB", storage.StorageType) } - } else if storage.StorageType == models.STORAGE_CLOUD_SSD { + } else if storage.StorageType == api.STORAGE_CLOUD_SSD { if sizeGb < 100 || sizeGb > 16000 { return fmt.Errorf("The %s disk size must be in the range of 100 ~ 16000GB", storage.StorageType) } diff --git a/pkg/compute/hostdrivers/ucloud.go b/pkg/compute/hostdrivers/ucloud.go index 9c7bf0d350..5622adfb02 100644 --- a/pkg/compute/hostdrivers/ucloud.go +++ b/pkg/compute/hostdrivers/ucloud.go @@ -14,7 +14,10 @@ package hostdrivers -import "yunion.io/x/onecloud/pkg/compute/models" +import ( + api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/compute/models" +) type SUCloudHostDriver struct { SManagedVirtualizationHostDriver @@ -26,5 +29,5 @@ func init() { } func (self *SUCloudHostDriver) GetHostType() string { - return models.HOST_TYPE_UCLOUD + return api.HOST_TYPE_UCLOUD } diff --git a/pkg/compute/models/baremetalagents.go b/pkg/compute/models/baremetalagents.go index ec5c236bd1..25251e749c 100644 --- a/pkg/compute/models/baremetalagents.go +++ b/pkg/compute/models/baremetalagents.go @@ -23,25 +23,12 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/regutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" ) -const ( - BAREMETAL_AGENT_ENABLED = "enabled" - BAREMETAL_AGENT_DISABLED = "disabled" - BAREMETAL_AGENT_OFFLINE = "offline" -) - -type TAgentType string - -const ( - AgentTypeBaremetal = TAgentType("baremetal") - AgentTypeEsxi = TAgentType("esxiagent") - AgentTypeDefault = AgentTypeBaremetal -) - type SBaremetalagentManager struct { db.SStandaloneResourceBaseManager } @@ -89,7 +76,7 @@ func (self *SBaremetalagent) AllowDeleteItem(ctx context.Context, userCred mccli } func (self *SBaremetalagent) ValidateDeleteCondition(ctx context.Context) error { - if self.Status == BAREMETAL_AGENT_ENABLED { + if self.Status == api.BAREMETAL_AGENT_ENABLED { return fmt.Errorf("Cannot delete in status %s", self.Status) } return self.SStandaloneResourceBase.ValidateDeleteCondition(ctx) @@ -121,9 +108,9 @@ func (self *SBaremetalagent) AllowPerformEnable(ctx context.Context, userCred mc } func (self *SBaremetalagent) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status != BAREMETAL_AGENT_ENABLED { + if self.Status != api.BAREMETAL_AGENT_ENABLED { db.Update(self, func() error { - self.Status = BAREMETAL_AGENT_ENABLED + self.Status = api.BAREMETAL_AGENT_ENABLED return nil }) db.OpsLog.LogEvent(self, db.ACT_ENABLE, "", userCred) @@ -136,9 +123,9 @@ func (self *SBaremetalagent) AllowPerformDisable(ctx context.Context, userCred m } func (self *SBaremetalagent) PerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status != BAREMETAL_AGENT_DISABLED { + if self.Status != api.BAREMETAL_AGENT_DISABLED { db.Update(self, func() error { - self.Status = BAREMETAL_AGENT_DISABLED + self.Status = api.BAREMETAL_AGENT_DISABLED return nil }) db.OpsLog.LogEvent(self, db.ACT_DISABLE, "", userCred) @@ -151,9 +138,9 @@ func (self *SBaremetalagent) AllowPerformOnline(ctx context.Context, userCred mc } func (self *SBaremetalagent) PerformOnline(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status == BAREMETAL_AGENT_OFFLINE { + if self.Status == api.BAREMETAL_AGENT_OFFLINE { db.Update(self, func() error { - self.Status = BAREMETAL_AGENT_ENABLED + self.Status = api.BAREMETAL_AGENT_ENABLED return nil }) db.OpsLog.LogEvent(self, db.ACT_ONLINE, "", userCred) @@ -166,9 +153,9 @@ func (self *SBaremetalagent) AllowPerformOffline(ctx context.Context, userCred m } func (self *SBaremetalagent) PerformOffline(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status == BAREMETAL_AGENT_ENABLED { + if self.Status == api.BAREMETAL_AGENT_ENABLED { db.Update(self, func() error { - self.Status = BAREMETAL_AGENT_OFFLINE + self.Status = api.BAREMETAL_AGENT_OFFLINE return nil }) db.OpsLog.LogEvent(self, db.ACT_OFFLINE, "", userCred) @@ -195,7 +182,7 @@ func (self *SBaremetalagent) GetExtraDetails(ctx context.Context, userCred mccli return extra, nil } -func (manager *SBaremetalagentManager) GetAgent(agentType TAgentType, zoneId string) *SBaremetalagent { +func (manager *SBaremetalagentManager) GetAgent(agentType api.TAgentType, zoneId string) *SBaremetalagent { q := manager.Query().Equals("agent_type", agentType).Equals("zone_id", zoneId).Asc("created_at") agents := make([]SBaremetalagent, 0) err := db.FetchModelObjects(manager, q, &agents) @@ -209,7 +196,7 @@ func (manager *SBaremetalagentManager) GetAgent(agentType TAgentType, zoneId str return nil } for i := range agents { - if agents[i].Status == BAREMETAL_AGENT_ENABLED { + if agents[i].Status == api.BAREMETAL_AGENT_ENABLED { return &agents[i] } } diff --git a/pkg/compute/models/billingresource.go b/pkg/compute/models/billingresource.go index b8d25a81be..3041d68c34 100644 --- a/pkg/compute/models/billingresource.go +++ b/pkg/compute/models/billingresource.go @@ -16,11 +16,8 @@ package models import ( "time" -) -const ( - BILLING_TYPE_POSTPAID = "postpaid" - BILLING_TYPE_PREPAID = "prepaid" + api "yunion.io/x/onecloud/pkg/apis/billing" ) type SBillingResourceBase struct { @@ -33,14 +30,14 @@ func (self *SBillingResourceBase) GetChargeType() string { if len(self.BillingType) > 0 { return self.BillingType } else { - return BILLING_TYPE_POSTPAID + return api.BILLING_TYPE_POSTPAID } } func (self *SBillingResourceBase) getBillingBaseInfo() SBillingBaseInfo { info := SBillingBaseInfo{} info.ChargeType = self.GetChargeType() - if self.GetChargeType() == BILLING_TYPE_PREPAID { + if self.GetChargeType() == api.BILLING_TYPE_PREPAID { info.ExpiredAt = self.ExpiredAt info.BillingCycle = self.BillingCycle } @@ -48,7 +45,7 @@ func (self *SBillingResourceBase) getBillingBaseInfo() SBillingBaseInfo { } func (self *SBillingResourceBase) IsValidPrePaid() bool { - if self.BillingType == BILLING_TYPE_PREPAID { + if self.BillingType == api.BILLING_TYPE_PREPAID { now := time.Now().UTC() if self.ExpiredAt.After(now) { return true diff --git a/pkg/compute/models/cachedimages.go b/pkg/compute/models/cachedimages.go index e60e60c470..941207bcc2 100644 --- a/pkg/compute/models/cachedimages.go +++ b/pkg/compute/models/cachedimages.go @@ -37,11 +37,6 @@ import ( "yunion.io/x/onecloud/pkg/mcclient/modules" ) -const ( - CACHED_IMAGE_REFRESH_SECONDS = 900 // 15 minutes - CACHED_IMAGE_REFERENCE_SESSION_EXPIRE_SECONDS = 86400 // 1 day -) - type SCachedimageManager struct { db.SStandaloneResourceBaseManager } @@ -105,7 +100,7 @@ func (self *SCachedimage) ValidateDeleteCondition(ctx context.Context) error { } func (self *SCachedimage) isReferenceSessionExpire() bool { - if !self.LastRef.IsZero() && time.Now().Sub(self.LastRef) < CACHED_IMAGE_REFERENCE_SESSION_EXPIRE_SECONDS*time.Second { + if !self.LastRef.IsZero() && time.Now().Sub(self.LastRef) < api.CACHED_IMAGE_REFERENCE_SESSION_EXPIRE_SECONDS*time.Second { return false } else { return true @@ -116,7 +111,7 @@ func (self *SCachedimage) isRefreshSessionExpire() bool { if len(self.ExternalId) > 0 { // external image info never expires return false } - if !self.LastRef.IsZero() && time.Now().Sub(self.LastRef) < CACHED_IMAGE_REFRESH_SECONDS*time.Second { + if !self.LastRef.IsZero() && time.Now().Sub(self.LastRef) < api.CACHED_IMAGE_REFRESH_SECONDS*time.Second { return false } else { return true @@ -355,13 +350,13 @@ func (self *SCachedimage) ChooseSourceStoragecacheInRange(hostType string, exclu Join(hostStorage, sqlchemy.Equals(hostStorage.Field("storage_id"), storage.Field("id"))). Join(host, sqlchemy.Equals(hostStorage.Field("host_id"), host.Field("id"))). Filter(sqlchemy.Equals(storageCachedImage.Field("cachedimage_id"), self.Id)). - Filter(sqlchemy.Equals(storageCachedImage.Field("status"), CACHED_IMAGE_STATUS_READY)). - Filter(sqlchemy.Equals(host.Field("status"), HOST_STATUS_RUNNING)). + Filter(sqlchemy.Equals(storageCachedImage.Field("status"), api.CACHED_IMAGE_STATUS_READY)). + Filter(sqlchemy.Equals(host.Field("status"), api.HOST_STATUS_RUNNING)). Filter(sqlchemy.IsTrue(host.Field("enabled"))). - Filter(sqlchemy.Equals(host.Field("host_status"), HOST_ONLINE)). + Filter(sqlchemy.Equals(host.Field("host_status"), api.HOST_ONLINE)). Filter(sqlchemy.IsTrue(storage.Field("enabled"))). - Filter(sqlchemy.In(storage.Field("status"), []string{STORAGE_ENABLED, STORAGE_ONLINE})). - Filter(sqlchemy.Equals(storage.Field("storage_type"), STORAGE_LOCAL)) + Filter(sqlchemy.In(storage.Field("status"), []string{api.STORAGE_ENABLED, api.STORAGE_ONLINE})). + Filter(sqlchemy.Equals(storage.Field("storage_type"), api.STORAGE_LOCAL)) if len(excludes) > 0 { q = q.Filter(sqlchemy.NotIn(host.Field("id"), excludes)) diff --git a/pkg/compute/models/capabilities.go b/pkg/compute/models/capabilities.go index 9dd4754297..cf87d8d409 100644 --- a/pkg/compute/models/capabilities.go +++ b/pkg/compute/models/capabilities.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -96,9 +97,9 @@ func getHypervisors(region *SCloudregion, zone *SZone) []string { var managerId string rows.Scan(&hostType, &managerId) if len(hostType) > 0 && IsProviderAccountEnabled(managerId) { - hypervisor := HOSTTYPE_HYPERVISOR[hostType] + hypervisor := api.HOSTTYPE_HYPERVISOR[hostType] if !utils.IsInStringArray(hypervisor, hypervisors) { - hypervisors = append(hypervisors, HOSTTYPE_HYPERVISOR[hostType]) + hypervisors = append(hypervisors, hypervisor) } } } @@ -157,17 +158,17 @@ func getStorageTypes(region *SCloudregion, zone *SZone, isSysDisk bool) []string if zone != nil { q = q.Filter(sqlchemy.Equals(storages.Field("zone_id"), zone.Id)) } - q = q.Filter(sqlchemy.Equals(hosts.Field("resource_type"), HostResourceTypeShared)) + q = q.Filter(sqlchemy.Equals(hosts.Field("resource_type"), api.HostResourceTypeShared)) q = q.Filter(sqlchemy.IsNotEmpty(storages.Field("storage_type"))) q = q.Filter(sqlchemy.IsNotNull(storages.Field("storage_type"))) q = q.Filter(sqlchemy.IsNotEmpty(storages.Field("medium_type"))) q = q.Filter(sqlchemy.IsNotNull(storages.Field("medium_type"))) - q = q.Filter(sqlchemy.In(storages.Field("status"), []string{STORAGE_ENABLED, STORAGE_ONLINE})) + q = q.Filter(sqlchemy.In(storages.Field("status"), []string{api.STORAGE_ENABLED, api.STORAGE_ONLINE})) q = q.Filter(sqlchemy.IsTrue(storages.Field("enabled"))) if isSysDisk { q = q.Filter(sqlchemy.IsTrue(storages.Field("is_sys_disk_store"))) } - q = q.Filter(sqlchemy.NotEquals(hosts.Field("host_type"), HOST_TYPE_BAREMETAL)) + q = q.Filter(sqlchemy.NotEquals(hosts.Field("host_type"), api.HOST_TYPE_BAREMETAL)) q = q.Distinct() rows, err := q.Rows() if err != nil { @@ -231,7 +232,7 @@ func getNetworkCount(region *SCloudregion, zone *SZone) int { q = q.Join(wires, sqlchemy.Equals(networks.Field("wire_id"), wires.Field("id"))) q = q.Filter(sqlchemy.Equals(wires.Field("zone_id"), zone.Id)) } - q = q.Filter(sqlchemy.Equals(networks.Field("status"), NETWORK_STATUS_AVAILABLE)) + q = q.Filter(sqlchemy.Equals(networks.Field("status"), api.NETWORK_STATUS_AVAILABLE)) return q.Count() } diff --git a/pkg/compute/models/cloudproviders.go b/pkg/compute/models/cloudproviders.go index 99fe57d638..467742ec76 100644 --- a/pkg/compute/models/cloudproviders.go +++ b/pkg/compute/models/cloudproviders.go @@ -885,7 +885,7 @@ func (provider *SCloudprovider) prepareCloudproviderRegions(ctx context.Context, return nil, err } if driver.GetFactory().IsOnPremise() { - cpr := CloudproviderRegionManager.FetchByIdsOrCreate(provider.Id, DEFAULT_REGION_ID) + cpr := CloudproviderRegionManager.FetchByIdsOrCreate(provider.Id, api.DEFAULT_REGION_ID) return []SCloudproviderregion{*cpr}, nil } iregions := driver.GetIRegions() diff --git a/pkg/compute/models/cloudregions.go b/pkg/compute/models/cloudregions.go index 7014c3e9ba..ea46baf6d7 100644 --- a/pkg/compute/models/cloudregions.go +++ b/pkg/compute/models/cloudregions.go @@ -35,13 +35,6 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" ) -const ( - CLOUD_REGION_STATUS_INSERVER = "inservice" - CLOUD_REGION_STATUS_OUTOFSERVICE = "outofservice" - - DEFAULT_REGION_ID = "default" -) - type SCloudregionManager struct { db.SEnabledStatusStandaloneResourceBaseManager } @@ -99,7 +92,7 @@ func (self *SCloudregion) ValidateDeleteCondition(ctx context.Context) error { if self.GetZoneCount() > 0 || self.GetVpcCount() > 0 { return httperrors.NewNotEmptyError("not empty cloud region") } - if self.Id == DEFAULT_REGION_ID { + if self.Id == api.DEFAULT_REGION_ID { return httperrors.NewProtectedResourceError("not allow to delete default cloud region") } return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx) @@ -107,7 +100,7 @@ func (self *SCloudregion) ValidateDeleteCondition(ctx context.Context) error { func (self *SCloudregion) GetZoneCount() int { zones := ZoneManager.Query() - if self.Id == DEFAULT_REGION_ID { + if self.Id == api.DEFAULT_REGION_ID { return zones.Filter(sqlchemy.OR(sqlchemy.IsNull(zones.Field("cloudregion_id")), sqlchemy.IsEmpty(zones.Field("cloudregion_id")), sqlchemy.Equals(zones.Field("cloudregion_id"), self.Id))).Count() @@ -118,7 +111,7 @@ func (self *SCloudregion) GetZoneCount() int { func (self *SCloudregion) GetGuestCount(increment bool) int { zoneTable := ZoneManager.Query("id") - if self.Id == DEFAULT_REGION_ID { + if self.Id == api.DEFAULT_REGION_ID { zoneTable = zoneTable.Filter(sqlchemy.OR(sqlchemy.IsNull(zoneTable.Field("cloudregion_id")), sqlchemy.IsEmpty(zoneTable.Field("cloudregion_id")), sqlchemy.Equals(zoneTable.Field("cloudregion_id"), self.Id))) @@ -137,7 +130,7 @@ func (self *SCloudregion) GetGuestCount(increment bool) int { func (self *SCloudregion) GetVpcCount() int { vpcs := VpcManager.Query() - if self.Id == DEFAULT_REGION_ID { + if self.Id == api.DEFAULT_REGION_ID { return vpcs.Filter(sqlchemy.OR(sqlchemy.IsNull(vpcs.Field("cloudregion_id")), sqlchemy.IsEmpty(vpcs.Field("cloudregion_id")), sqlchemy.Equals(vpcs.Field("cloudregion_id"), self.Id))).Count() @@ -284,7 +277,7 @@ func (self *SCloudregion) syncRemoveCloudRegion(ctx context.Context, userCred mc // err = self.Delete(ctx, userCred) // } - err := self.SetStatus(userCred, CLOUD_REGION_STATUS_OUTOFSERVICE, "Out of sync") + err := self.SetStatus(userCred, api.CLOUD_REGION_STATUS_OUTOFSERVICE, "Out of sync") if err == nil { _, err = self.PerformDisable(ctx, userCred, nil, nil) } @@ -385,15 +378,15 @@ func (manager *SCloudregionManager) FetchRegionById(id string) *SCloudregion { func (manager *SCloudregionManager) InitializeData() error { // check if default region exists - _, err := manager.FetchById(DEFAULT_REGION_ID) + _, err := manager.FetchById(api.DEFAULT_REGION_ID) if err != nil { if err == sql.ErrNoRows { defRegion := SCloudregion{} - defRegion.Id = DEFAULT_REGION_ID + defRegion.Id = api.DEFAULT_REGION_ID defRegion.Name = "Default" defRegion.Enabled = true defRegion.Description = "Default Region" - defRegion.Status = CLOUD_REGION_STATUS_INSERVER + defRegion.Status = api.CLOUD_REGION_STATUS_INSERVER err = manager.TableSpec().Insert(&defRegion) if err != nil { log.Errorf("Insert default region fails: %s", err) @@ -482,24 +475,24 @@ func (manager *SCloudregionManager) ListItemFilter(ctx context.Context, q *sqlch } sq = sq.Join(providers, sqlchemy.Equals(vpcs.Field("manager_id"), providers.Field("id"))) if usableNet { - sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), NETWORK_STATUS_AVAILABLE)) + sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), api.NETWORK_STATUS_AVAILABLE)) } sq = sq.Filter(sqlchemy.IsTrue(providers.Field("enabled"))) sq = sq.Filter(sqlchemy.In(providers.Field("status"), api.CLOUD_PROVIDER_VALID_STATUS)) sq = sq.Filter(sqlchemy.Equals(providers.Field("health_status"), api.CLOUD_PROVIDER_HEALTH_NORMAL)) if usableVpc { - sq = sq.Filter(sqlchemy.Equals(vpcs.Field("status"), VPC_STATUS_AVAILABLE)) + sq = sq.Filter(sqlchemy.Equals(vpcs.Field("status"), api.VPC_STATUS_AVAILABLE)) } sq2 := vpcs.Query(sqlchemy.DISTINCT("cloudregion_id", vpcs.Field("cloudregion_id"))) if usableNet { sq2 = sq2.Join(wires, sqlchemy.Equals(vpcs.Field("id"), wires.Field("vpc_id"))) sq2 = sq2.Join(networks, sqlchemy.Equals(wires.Field("id"), networks.Field("wire_id"))) - sq2 = sq2.Filter(sqlchemy.Equals(networks.Field("status"), NETWORK_STATUS_AVAILABLE)) + sq2 = sq2.Filter(sqlchemy.Equals(networks.Field("status"), api.NETWORK_STATUS_AVAILABLE)) } sq2 = sq2.Filter(sqlchemy.IsNullOrEmpty(vpcs.Field("manager_id"))) if usableVpc { - sq2 = sq2.Filter(sqlchemy.Equals(vpcs.Field("status"), VPC_STATUS_AVAILABLE)) + sq2 = sq2.Filter(sqlchemy.Equals(vpcs.Field("status"), api.VPC_STATUS_AVAILABLE)) } q = q.Filter(sqlchemy.OR( diff --git a/pkg/compute/models/disks.go b/pkg/compute/models/disks.go index 6cdfa7d64d..aec9034c51 100644 --- a/pkg/compute/models/disks.go +++ b/pkg/compute/models/disks.go @@ -31,6 +31,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/cmdline" "yunion.io/x/onecloud/pkg/cloudcommon/db" @@ -46,45 +47,6 @@ import ( "yunion.io/x/onecloud/pkg/util/billing" ) -const ( - DISK_INIT = api.DISK_INIT - DISK_REBUILD = api.DISK_REBUILD - DISK_ALLOC_FAILED = api.DISK_ALLOC_FAILED - DISK_STARTALLOC = api.DISK_STARTALLOC - DISK_BACKUP_STARTALLOC = api.DISK_BACKUP_STARTALLOC - DISK_BACKUP_ALLOC_FAILED = api.DISK_BACKUP_ALLOC_FAILED - DISK_ALLOCATING = api.DISK_ALLOCATING - DISK_READY = api.DISK_READY - DISK_RESET = api.DISK_RESET // 快照回滚 - DISK_RESET_FAILED = api.DISK_RESET_FAILED // 快照回滚失败 - DISK_DEALLOC = api.DISK_DEALLOC - DISK_DEALLOC_FAILED = api.DISK_DEALLOC_FAILED - DISK_UNKNOWN = api.DISK_UNKNOWN - DISK_DETACHING = api.DISK_DETACHING - DISK_ATTACHING = api.DISK_ATTACHING - DISK_CLONING = api.DISK_CLONING // 硬盘克隆 - - DISK_START_SAVE = api.DISK_START_SAVE - DISK_SAVING = api.DISK_SAVING - - DISK_START_RESIZE = api.DISK_START_RESIZE - DISK_RESIZING = api.DISK_RESIZING - - DISK_START_MIGRATE = api.DISK_START_MIGRATE - DISK_POST_MIGRATE = api.DISK_POST_MIGRATE - DISK_MIGRATING = api.DISK_MIGRATING - - DISK_START_SNAPSHOT = api.DISK_START_SNAPSHOT - DISK_SNAPSHOTING = api.DISK_SNAPSHOTING - - DISK_TYPE_SYS = api.DISK_TYPE_SYS - DISK_TYPE_SWAP = api.DISK_TYPE_SWAP - DISK_TYPE_DATA = api.DISK_TYPE_DATA - DISK_TYPE_VOLUME = api.DISK_TYPE_VOLUME - - DISK_BACKING_IMAGE = api.DISK_BACKING_IMAGE -) - type SDiskManager struct { db.SSharableVirtualResourceBaseManager } @@ -163,7 +125,7 @@ func (manager *SDiskManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu billingTypeStr, _ := queryDict.GetString("billing_type") if len(billingTypeStr) > 0 { - if billingTypeStr == BILLING_TYPE_POSTPAID { + if billingTypeStr == billing_api.BILLING_TYPE_POSTPAID { q = q.Filter( sqlchemy.OR( sqlchemy.IsNullOrEmpty(q.Field("billing_type")), @@ -192,7 +154,7 @@ func (manager *SDiskManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu } if jsonutils.QueryBoolean(query, "share", false) { - sq := storages.Query(storages.Field("id")).Filter(sqlchemy.NotIn(storages.Field("storage_type"), STORAGE_LOCAL_TYPES)) + sq := storages.Query(storages.Field("id")).Filter(sqlchemy.NotIn(storages.Field("storage_type"), api.STORAGE_LOCAL_TYPES)) q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq)) } @@ -232,7 +194,7 @@ func (manager *SDiskManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu }*/ if jsonutils.QueryBoolean(query, "local", false) { - sq := storages.Query(storages.Field("id")).Filter(sqlchemy.In(storages.Field("storage_type"), STORAGE_LOCAL_TYPES)) + sq := storages.Query(storages.Field("id")).Filter(sqlchemy.In(storages.Field("storage_type"), api.STORAGE_LOCAL_TYPES)) q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq)) } @@ -356,7 +318,7 @@ func (self *SDisk) GetRuningGuestCount() int { return guests.Query().Join(guestdisks, sqlchemy.AND( sqlchemy.Equals(guestdisks.Field("guest_id"), guests.Field("id")))). Filter(sqlchemy.Equals(guestdisks.Field("disk_id"), self.Id)). - Filter(sqlchemy.Equals(guests.Field("status"), VM_RUNNING)).Count() + Filter(sqlchemy.Equals(guests.Field("status"), api.VM_RUNNING)).Count() } func (self *SDisk) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) error { @@ -380,7 +342,7 @@ func (self *SDisk) ValidateUpdateData(ctx context.Context, userCred mcclient.Tok } if diskType, _ := data.GetString("disk_type"); diskType != "" { - if !utils.IsInStringArray(diskType, []string{DISK_TYPE_DATA, DISK_TYPE_VOLUME}) { + if !utils.IsInStringArray(diskType, []string{api.DISK_TYPE_DATA, api.DISK_TYPE_VOLUME}) { return nil, httperrors.NewInputParameterError("not support update disk_type %s", diskType) } } @@ -422,7 +384,7 @@ func (manager *SDiskManager) ValidateCreateData(ctx context.Context, userCred mc } input.Storage = storage.Id } else { - diskConfig.Backend = STORAGE_LOCAL + diskConfig.Backend = api.STORAGE_LOCAL serverInput, err := ValidateScheduleCreateData(ctx, userCred, input.ToServerCreateInput(), input.Hypervisor) if err != nil { return nil, err @@ -444,7 +406,7 @@ func (manager *SDiskManager) validateDiskOnStorage(diskConfig *api.DiskConfig, s if !storage.Enabled { return httperrors.NewInputParameterError("Cannot create disk with disabled storage[%s]", storage.Name) } - if !utils.IsInStringArray(storage.Status, []string{STORAGE_ENABLED, STORAGE_ONLINE}) { + if !utils.IsInStringArray(storage.Status, []string{api.STORAGE_ENABLED, api.STORAGE_ONLINE}) { return httperrors.NewInputParameterError("Cannot create disk with offline storage[%s]", storage.Name) } if storage.StorageType != diskConfig.Backend { @@ -497,7 +459,7 @@ func (disk *SDisk) SetStorageByHost(hostId string, diskConfig *api.DiskConfig) e return fmt.Errorf("Backend is empty") } var storage *SStorage - if utils.IsInStringArray(backend, STORAGE_LIMITED_TYPES) { + if utils.IsInStringArray(backend, api.STORAGE_LIMITED_TYPES) { storage = host.GetLeastUsedStorage(backend) } else { // unlimited pulic cloud storages @@ -617,7 +579,7 @@ func (self *SDisk) GetDetailsConvertSnapshot(ctx context.Context, userCred mccli return nil, httperrors.NewBadRequestError("Snapshot %s dose not have convert snapshot", deleteSnapshot.Id) } var FakeDelete bool - if deleteSnapshot.CreatedBy == MANUAL && !deleteSnapshot.FakeDeleted { + if deleteSnapshot.CreatedBy == api.SNAPSHOT_MANUAL && !deleteSnapshot.FakeDeleted { FakeDelete = true } ret := jsonutils.NewDict() @@ -676,7 +638,7 @@ func (self *SDisk) AllowPerformDiskReset(ctx context.Context, userCred mcclient. } func (self *SDisk) PerformDiskReset(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status != DISK_READY { + if self.Status != api.DISK_READY { return nil, httperrors.NewInvalidStatusError("Cannot reset disk in status %s", self.Status) } snapshotId, err := data.GetString("snapshot_id") @@ -687,7 +649,7 @@ func (self *SDisk) PerformDiskReset(ctx context.Context, userCred mcclient.Token if len(guests) > 1 { return nil, httperrors.NewBadRequestError("Disk attach muti guests") } else if len(guests) == 1 { - if guests[0].Status != VM_READY { + if guests[0].Status != api.VM_READY { return nil, httperrors.NewServerStatusError("Disk attached guest status must be ready") } } @@ -696,7 +658,7 @@ func (self *SDisk) PerformDiskReset(ctx context.Context, userCred mcclient.Token return nil, httperrors.NewNotFoundError("Snapshot %s not found", snapshotId) } snapshot := iSnapshot.(*SSnapshot) - if snapshot.Status != SNAPSHOT_READY { + if snapshot.Status != api.SNAPSHOT_READY { return nil, httperrors.NewBadRequestError("Cannot reset disk with snapshot in status %s", snapshot.Status) } autoStart := jsonutils.QueryBoolean(data, "auto_start", false) @@ -705,7 +667,7 @@ func (self *SDisk) PerformDiskReset(ctx context.Context, userCred mcclient.Token } func (self *SDisk) StartResetDisk(ctx context.Context, userCred mcclient.TokenCredential, snapshotId string, autoStart bool) error { - self.SetStatus(userCred, DISK_RESET, "") + self.SetStatus(userCred, api.DISK_RESET, "") params := jsonutils.NewDict() params.Set("snapshot_id", jsonutils.NewString(snapshotId)) params.Set("auto_start", jsonutils.NewBool(autoStart)) @@ -731,7 +693,7 @@ func (self *SDisk) PerformResize(ctx context.Context, userCred mcclient.TokenCre if err != nil { return nil, err } - if self.Status != DISK_READY { + if self.Status != api.DISK_READY { return nil, httperrors.NewResourceNotReadyError("Resize disk when disk is READY") } if sizeMb < self.DiskSize { @@ -832,7 +794,7 @@ func (self *SDisk) AllowPerformSave(ctx context.Context, userCred mcclient.Token } func (self *SDisk) PerformSave(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status != DISK_READY { + if self.Status != api.DISK_READY { return nil, httperrors.NewResourceNotReadyError("Save disk when disk is READY") } @@ -853,7 +815,7 @@ func (self *SDisk) PerformSave(ctx context.Context, userCred mcclient.TokenCrede } func (self *SDisk) StartDiskSaveTask(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, parentTaskId string) error { - self.SetStatus(userCred, DISK_START_SAVE, "") + self.SetStatus(userCred, api.DISK_START_SAVE, "") if task, err := taskman.TaskManager.NewTask(ctx, "DiskSaveTask", self, userCred, data, parentTaskId, "", nil); err != nil { log.Errorf("Start DiskSaveTask failed:%v", err) return err @@ -1055,7 +1017,7 @@ func (self *SDisk) syncRemoveCloudDisk(ctx context.Context, userCred mcclient.To err := self.ValidatePurgeCondition(ctx) if err != nil { - return self.SetStatus(userCred, DISK_UNKNOWN, "missing original disk after sync") + return self.SetStatus(userCred, api.DISK_UNKNOWN, "missing original disk after sync") } else { return self.RealDelete(ctx, userCred) } @@ -1082,7 +1044,7 @@ func (self *SDisk) syncWithCloudDisk(ctx context.Context, userCred mcclient.Toke // self.TemplateId = extDisk.GetTemplateId() no sync template ID self.DiskType = extDisk.GetDiskType() if index == 0 { - self.DiskType = DISK_TYPE_SYS + self.DiskType = api.DISK_TYPE_SYS } // self.FsFormat = extDisk.GetFsFormat() self.Nonpersistent = extDisk.GetIsNonPersistent() @@ -1122,7 +1084,7 @@ func (manager *SDiskManager) newFromCloudDisk(ctx context.Context, userCred mccl disk.AutoDelete = extDisk.GetIsAutoDelete() disk.DiskType = extDisk.GetDiskType() if index == 0 { - disk.DiskType = DISK_TYPE_SYS + disk.DiskType = api.DISK_TYPE_SYS } disk.Nonpersistent = extDisk.GetIsNonPersistent() @@ -1154,9 +1116,9 @@ func totalDiskSize(projectId string, active tristate.TriState, ready tristate.Tr q = q.Join(storages, sqlchemy.AND(sqlchemy.IsFalse(storages.Field("deleted")), sqlchemy.Equals(storages.Field("id"), disks.Field("storage_id")))) if active.IsTrue() { - q = q.Filter(sqlchemy.In(storages.Field("status"), []string{STORAGE_ENABLED, STORAGE_ONLINE})) + q = q.Filter(sqlchemy.In(storages.Field("status"), []string{api.STORAGE_ENABLED, api.STORAGE_ONLINE})) } else { - q = q.Filter(sqlchemy.NotIn(storages.Field("status"), []string{STORAGE_ENABLED, STORAGE_ONLINE})) + q = q.Filter(sqlchemy.NotIn(storages.Field("status"), []string{api.STORAGE_ENABLED, api.STORAGE_ONLINE})) } } if len(projectId) > 0 { @@ -1164,9 +1126,9 @@ func totalDiskSize(projectId string, active tristate.TriState, ready tristate.Tr } if !ready.IsNone() { if ready.IsTrue() { - q = q.Filter(sqlchemy.Equals(disks.Field("status"), DISK_READY)) + q = q.Filter(sqlchemy.Equals(disks.Field("status"), api.DISK_READY)) } else { - q = q.Filter(sqlchemy.NotEquals(disks.Field("status"), DISK_READY)) + q = q.Filter(sqlchemy.NotEquals(disks.Field("status"), api.DISK_READY)) } } if !includeSystem { @@ -1272,7 +1234,7 @@ func parseIsoInfo(ctx context.Context, userCred mcclient.TokenCredential, imageI func (self *SDisk) fetchDiskInfo(diskConfig *api.DiskConfig) { if len(diskConfig.ImageId) > 0 { self.TemplateId = diskConfig.ImageId - self.DiskType = DISK_TYPE_SYS + self.DiskType = api.DISK_TYPE_SYS } else if len(diskConfig.SnapshotId) > 0 { self.SnapshotId = diskConfig.SnapshotId self.DiskType = diskConfig.DiskType @@ -1281,13 +1243,13 @@ func (self *SDisk) fetchDiskInfo(diskConfig *api.DiskConfig) { self.FsFormat = diskConfig.Fs } if self.FsFormat == "swap" { - self.DiskType = DISK_TYPE_SWAP + self.DiskType = api.DISK_TYPE_SWAP self.Nonpersistent = true } else { if len(self.DiskType) == 0 { - diskType := DISK_TYPE_DATA - if diskConfig.DiskType == DISK_TYPE_VOLUME { - diskType = DISK_TYPE_VOLUME + diskType := api.DISK_TYPE_DATA + if diskConfig.DiskType == api.DISK_TYPE_VOLUME { + diskType = api.DISK_TYPE_VOLUME } self.DiskType = diskType } @@ -1499,7 +1461,7 @@ func (self *SDisk) GetAttachedGuests() []SGuest { } func (self *SDisk) SetDiskReady(ctx context.Context, userCred mcclient.TokenCredential, reason string) { - self.SetStatus(userCred, DISK_READY, reason) + self.SetStatus(userCred, api.DISK_READY, reason) guests := self.GetAttachedGuests() if guests != nil { for _, guest := range guests { @@ -1588,11 +1550,11 @@ func (self *SDisk) GetMountPoint() string { } func (self *SDisk) isReady() bool { - return self.Status == DISK_READY + return self.Status == api.DISK_READY } func (self *SDisk) isInit() bool { - return self.Status == DISK_INIT + return self.Status == api.DISK_INIT } func (self *SDisk) AllowPerformCancelDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { @@ -1658,13 +1620,13 @@ func (manager *SDiskManager) AutoDiskSnapshot(ctx context.Context, userCred mccl log.Errorf("Disk %s(%s) is attached to %d guest(s)", disk.Name, disk.Id, len(guests)) continue } - if !utils.IsInStringArray(guests[0].Status, []string{VM_RUNNING, VM_READY}) { + if !utils.IsInStringArray(guests[0].Status, []string{api.VM_RUNNING, api.VM_READY}) { log.Errorf("Guest(%s) in status(%s) cannot do snapshot action", guests[0].Id, guests[0].Status) continue } // name name := "Auto-" + guests[0].Name + time.Now().Format("2006-01-02#15:04:05") - snap, err := SnapshotManager.CreateSnapshot(ctx, userCred, AUTO, disk.Id, guests[0].Id, "", name) + snap, err := SnapshotManager.CreateSnapshot(ctx, userCred, api.SNAPSHOT_AUTO, disk.Id, guests[0].Id, "", name) if err != nil { log.Errorln(err) continue @@ -1685,8 +1647,8 @@ func (disk *SDisk) StratCreateBackupTask(ctx context.Context, userCred mcclient. func (self *SDisk) SaveRenewInfo(ctx context.Context, userCred mcclient.TokenCredential, bc *billing.SBillingCycle, expireAt *time.Time) error { _, err := db.Update(self, func() error { - if self.BillingType != BILLING_TYPE_PREPAID { - self.BillingType = BILLING_TYPE_PREPAID + if self.BillingType != billing_api.BILLING_TYPE_PREPAID { + self.BillingType = billing_api.BILLING_TYPE_PREPAID } if expireAt != nil && !expireAt.IsZero() { self.ExpiredAt = *expireAt @@ -1712,10 +1674,10 @@ func (self *SDisk) IsDetachable() bool { if storage.IsLocal() { return false } - if self.BillingType == BILLING_TYPE_PREPAID { + if self.BillingType == billing_api.BILLING_TYPE_PREPAID { return false } - if utils.IsInStringArray(self.DiskType, []string{DISK_TYPE_SYS, DISK_TYPE_SWAP}) { + if utils.IsInStringArray(self.DiskType, []string{api.DISK_TYPE_SYS, api.DISK_TYPE_SWAP}) { return false } if self.AutoDelete { diff --git a/pkg/compute/models/elasticips.go b/pkg/compute/models/elasticips.go index 713d688ec9..8da6fbbdcc 100644 --- a/pkg/compute/models/elasticips.go +++ b/pkg/compute/models/elasticips.go @@ -26,6 +26,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas" @@ -35,30 +36,6 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" ) -const ( - EIP_MODE_INSTANCE_PUBLICIP = "public_ip" - EIP_MODE_STANDALONE_EIP = "elastic_ip" - - EIP_ASSOCIATE_TYPE_SERVER = "server" - - EIP_STATUS_READY = "ready" - EIP_STATUS_UNKNOWN = "unknown" - EIP_STATUS_ALLOCATE = "allocate" - EIP_STATUS_ALLOCATE_FAIL = "allocate_fail" - EIP_STATUS_DEALLOCATE = "deallocate" - EIP_STATUS_DEALLOCATE_FAIL = "deallocate_fail" - EIP_STATUS_ASSOCIATE = "associate" - EIP_STATUS_ASSOCIATE_FAIL = "associate_fail" - EIP_STATUS_DISSOCIATE = "dissociate" - EIP_STATUS_DISSOCIATE_FAIL = "dissociate_fail" - - EIP_STATUS_CHANGE_BANDWIDTH = "change_bandwidth" - - EIP_CHARGE_TYPE_BY_TRAFFIC = "traffic" - EIP_CHARGE_TYPE_BY_BANDWIDTH = "bandwidth" - EIP_CHARGE_TYPE_DEFAULT = EIP_CHARGE_TYPE_BY_TRAFFIC -) - type SElasticipManager struct { db.SVirtualResourceBaseManager } @@ -161,7 +138,7 @@ func (manager *SElasticipManager) ListItemFilter(ctx context.Context, q *sqlchem if query.Contains("usable") { usable := jsonutils.QueryBoolean(query, "usable", false) if usable { - q = q.Equals("status", EIP_STATUS_READY) + q = q.Equals("status", api.EIP_STATUS_READY) q = q.Filter(sqlchemy.OR(sqlchemy.IsNull(q.Field("associate_id")), sqlchemy.IsEmpty(q.Field("associate_id")))) } } @@ -291,7 +268,7 @@ func (self *SElasticip) syncRemoveCloudEip(ctx context.Context, userCred mcclien err := self.ValidateDeleteCondition(ctx) if err != nil { - return self.SetStatus(userCred, EIP_STATUS_UNKNOWN, "sync to delete") + return self.SetStatus(userCred, api.EIP_STATUS_UNKNOWN, "sync to delete") } else { return self.RealDelete(ctx, userCred) } @@ -453,7 +430,7 @@ func (self *SElasticip) Dissociate(ctx context.Context, userCred mcclient.TokenC db.OpsLog.LogEvent(self, db.ACT_EIP_DETACH, vm.GetShortDesc(ctx), userCred) db.OpsLog.LogEvent(vm, db.ACT_EIP_DETACH, self.GetShortDesc(ctx), userCred) } - if self.Mode == EIP_MODE_INSTANCE_PUBLICIP { + if self.Mode == api.EIP_MODE_INSTANCE_PUBLICIP { self.Delete(ctx, userCred) } return nil @@ -527,10 +504,10 @@ func (manager *SElasticipManager) ValidateCreateData(ctx context.Context, userCr chargeType := jsonutils.GetAnyString(data, []string{"charge_type"}) if len(chargeType) == 0 { - chargeType = EIP_CHARGE_TYPE_DEFAULT + chargeType = api.EIP_CHARGE_TYPE_DEFAULT } - if !utils.IsInStringArray(chargeType, []string{EIP_CHARGE_TYPE_BY_BANDWIDTH, EIP_CHARGE_TYPE_BY_TRAFFIC}) { + if !utils.IsInStringArray(chargeType, []string{api.EIP_CHARGE_TYPE_BY_BANDWIDTH, api.EIP_CHARGE_TYPE_BY_TRAFFIC}) { return nil, httperrors.NewInputParameterError("charge type %s not supported", chargeType) } @@ -563,7 +540,7 @@ func (self *SElasticip) startEipAllocateTask(ctx context.Context, userCred mccli log.Errorf("newtask EipAllocateTask fail %s", err) return err } - self.SetStatus(userCred, EIP_STATUS_ALLOCATE, "start allocate") + self.SetStatus(userCred, api.EIP_STATUS_ALLOCATE, "start allocate") task.ScheduleRun(nil) return nil } @@ -594,7 +571,7 @@ func (self *SElasticip) StartEipDeallocateTask(ctx context.Context, userCred mcc log.Errorf("newTask EipDeallocateTask fail %s", err) return err } - self.SetStatus(userCred, EIP_STATUS_DEALLOCATE, "start to delete") + self.SetStatus(userCred, api.EIP_STATUS_DEALLOCATE, "start to delete") task.ScheduleRun(nil) return nil } @@ -608,11 +585,11 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient. return nil, httperrors.NewConflictError("eip has been associated with instance") } - if self.Status != EIP_STATUS_READY { + if self.Status != api.EIP_STATUS_READY { return nil, httperrors.NewInvalidStatusError("eip cannot associate in status %s", self.Status) } - if self.Mode == EIP_MODE_INSTANCE_PUBLICIP { + if self.Mode == api.EIP_MODE_INSTANCE_PUBLICIP { return nil, httperrors.NewUnsupportOperationError("fixed eip cannot be associated") } @@ -622,10 +599,10 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient. } instanceType := jsonutils.GetAnyString(data, []string{"instance_type"}) if len(instanceType) == 0 { - instanceType = EIP_ASSOCIATE_TYPE_SERVER + instanceType = api.EIP_ASSOCIATE_TYPE_SERVER } - if instanceType != EIP_ASSOCIATE_TYPE_SERVER { + if instanceType != api.EIP_ASSOCIATE_TYPE_SERVER { return nil, httperrors.NewInputParameterError("Unsupported %s", instanceType) } @@ -652,7 +629,7 @@ func (self *SElasticip) PerformAssociate(ctx context.Context, userCred mcclient. return nil, httperrors.NewInvalidStatusError("instance is already associated with eip") } - if ok, _ := utils.InStringArray(server.Status, []string{VM_READY, VM_RUNNING}); !ok { + if ok, _ := utils.InStringArray(server.Status, []string{api.VM_READY, api.VM_RUNNING}); !ok { return nil, httperrors.NewInvalidStatusError("cannot associate server in status %s", server.Status) } @@ -687,7 +664,7 @@ func (self *SElasticip) StartEipAssociateInstanceTask(ctx context.Context, userC params := jsonutils.NewDict() params.Add(jsonutils.NewString(server.ExternalId), "instance_external_id") params.Add(jsonutils.NewString(server.Id), "instance_id") - params.Add(jsonutils.NewString(EIP_ASSOCIATE_TYPE_SERVER), "instance_type") + params.Add(jsonutils.NewString(api.EIP_ASSOCIATE_TYPE_SERVER), "instance_type") return self.StartEipAssociateTask(ctx, userCred, params, parentTaskId) } @@ -698,7 +675,7 @@ func (self *SElasticip) StartEipAssociateTask(ctx context.Context, userCred mccl log.Errorf("create EipAssociateTask task fail %s", err) return err } - self.SetStatus(userCred, EIP_STATUS_ASSOCIATE, "start to associate") + self.SetStatus(userCred, api.EIP_STATUS_ASSOCIATE, "start to associate") task.ScheduleRun(nil) return nil } @@ -717,11 +694,11 @@ func (self *SElasticip) PerformDissociate(ctx context.Context, userCred mcclient return nil, self.Dissociate(ctx, userCred) } - if self.Status != EIP_STATUS_READY { + if self.Status != api.EIP_STATUS_READY { return nil, httperrors.NewInvalidStatusError("eip cannot dissociate in status %s", self.Status) } - if self.Mode == EIP_MODE_INSTANCE_PUBLICIP { + if self.Mode == api.EIP_MODE_INSTANCE_PUBLICIP { return nil, httperrors.NewUnsupportOperationError("fixed public eip cannot be dissociated") } @@ -741,7 +718,7 @@ func (self *SElasticip) StartEipDissociateTask(ctx context.Context, userCred mcc log.Errorf("create EipDissociateTask fail %s", err) return nil } - self.SetStatus(userCred, EIP_STATUS_DISSOCIATE, "start to dissociate") + self.SetStatus(userCred, api.EIP_STATUS_DISSOCIATE, "start to dissociate") task.ScheduleRun(nil) return nil } @@ -777,7 +754,7 @@ func (self *SElasticip) PerformSync(ctx context.Context, userCred mcclient.Token return nil, httperrors.NewInvalidStatusError("eip cannot syncstatus in status %s", self.Status) }*/ - if self.Mode == EIP_MODE_INSTANCE_PUBLICIP { + if self.Mode == api.EIP_MODE_INSTANCE_PUBLICIP { return nil, httperrors.NewUnsupportOperationError("fixed eip cannot sync status") } @@ -825,13 +802,13 @@ func (manager *SElasticipManager) AllocateEipAndAssociateVM(ctx context.Context, region := host.GetRegion() if len(chargeType) == 0 { - chargeType = EIP_CHARGE_TYPE_BY_TRAFFIC + chargeType = api.EIP_CHARGE_TYPE_BY_TRAFFIC } eip := SElasticip{} eip.SetModelManager(manager) - eip.Mode = EIP_MODE_STANDALONE_EIP + eip.Mode = api.EIP_MODE_STANDALONE_EIP // do not implicitly auto dellocate EIP, should be set by user explicitly // eip.AutoDellocate = tristate.True eip.Bandwidth = bw @@ -850,9 +827,9 @@ func (manager *SElasticipManager) AllocateEipAndAssociateVM(ctx context.Context, params := jsonutils.NewDict() params.Add(jsonutils.NewString(vm.ExternalId), "instance_external_id") params.Add(jsonutils.NewString(vm.Id), "instance_id") - params.Add(jsonutils.NewString(EIP_ASSOCIATE_TYPE_SERVER), "instance_type") + params.Add(jsonutils.NewString(api.EIP_ASSOCIATE_TYPE_SERVER), "instance_type") - vm.SetStatus(userCred, VM_ASSOCIATE_EIP, "allocate and associate EIP") + vm.SetStatus(userCred, api.VM_ASSOCIATE_EIP, "allocate and associate EIP") return eip.startEipAllocateTask(ctx, userCred, params, eipPendingUsage) } @@ -862,7 +839,7 @@ func (self *SElasticip) AllowPerformChangeBandwidth(ctx context.Context, userCre } func (self *SElasticip) PerformChangeBandwidth(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status != EIP_STATUS_READY { + if self.Status != api.EIP_STATUS_READY { return nil, httperrors.NewInvalidStatusError("cannot change bandwidth in status %s", self.Status) } @@ -889,7 +866,7 @@ func (self *SElasticip) PerformChangeBandwidth(ctx context.Context, userCred mcc func (self *SElasticip) StartEipChangeBandwidthTask(ctx context.Context, userCred mcclient.TokenCredential, bandwidth int64) error { - self.SetStatus(userCred, EIP_STATUS_CHANGE_BANDWIDTH, "change bandwidth") + self.SetStatus(userCred, api.EIP_STATUS_CHANGE_BANDWIDTH, "change bandwidth") params := jsonutils.NewDict() params.Add(jsonutils.NewInt(bandwidth), "bandwidth") @@ -912,7 +889,7 @@ func (self *SElasticip) DoChangeBandwidth(userCred mcclient.TokenCredential, ban return nil }) - self.SetStatus(userCred, EIP_STATUS_READY, "finish change bandwidth") + self.SetStatus(userCred, api.EIP_STATUS_READY, "finish change bandwidth") if err != nil { log.Errorf("DoChangeBandwidth update fail %s", err) @@ -985,11 +962,11 @@ func (manager *SElasticipManager) usageQ(q *sqlchemy.SQuery, rangeObj db.IStanda func (manager *SElasticipManager) TotalCount(projectId string, rangeObj db.IStandaloneModel, providers []string) EipUsage { usage := EipUsage{} - q1 := manager.Query().Equals("mode", EIP_MODE_INSTANCE_PUBLICIP) + q1 := manager.Query().Equals("mode", api.EIP_MODE_INSTANCE_PUBLICIP) q1 = manager.usageQ(q1, rangeObj, providers) - q2 := manager.Query().Equals("mode", EIP_MODE_STANDALONE_EIP) + q2 := manager.Query().Equals("mode", api.EIP_MODE_STANDALONE_EIP) q2 = manager.usageQ(q2, rangeObj, providers) - q3 := manager.Query().Equals("mode", EIP_MODE_STANDALONE_EIP).IsNotEmpty("associate_id") + q3 := manager.Query().Equals("mode", api.EIP_MODE_STANDALONE_EIP).IsNotEmpty("associate_id") q3 = manager.usageQ(q3, rangeObj, providers) if len(projectId) > 0 { q1 = q1.Equals("tenant_id", projectId) @@ -1022,7 +999,7 @@ func (self *SElasticip) PerformPurge(ctx context.Context, userCred mcclient.Toke } func (self *SElasticip) DoPendingDelete(ctx context.Context, userCred mcclient.TokenCredential) { - if self.Mode == EIP_MODE_INSTANCE_PUBLICIP { + if self.Mode == api.EIP_MODE_INSTANCE_PUBLICIP { self.SVirtualResourceBase.DoPendingDelete(ctx, userCred) return } diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 6d9083dd5e..6f099dc9b8 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -32,6 +32,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" api "yunion.io/x/onecloud/pkg/apis/compute" schedapi "yunion.io/x/onecloud/pkg/apis/scheduler" "yunion.io/x/onecloud/pkg/cloudcommon/cmdline" @@ -58,7 +59,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{VM_RUNNING, VM_BLOCK_STREAM}) { + if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_BLOCK_STREAM}) { host := self.GetHost() if host == nil { return nil, httperrors.NewInternalServerError("Host missing") @@ -83,7 +84,7 @@ func (self *SGuest) AllowPerformMonitor(ctx context.Context, func (self *SGuest) PerformMonitor(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_BLOCK_STREAM}) { + if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_BLOCK_STREAM}) { cmd, err := data.GetString("command") if err != nil { return nil, httperrors.NewMissingParameterError("command") @@ -111,7 +112,7 @@ func (self *SGuest) AllowPerformSaveImage(ctx context.Context, userCred mcclient } func (self *SGuest) PerformSaveImage(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !utils.IsInStringArray(self.Status, []string{VM_READY}) { + if !utils.IsInStringArray(self.Status, []string{api.VM_READY}) { return nil, httperrors.NewInputParameterError("Cannot save image in status %s", self.Status) } else if !data.Contains("name") { return nil, httperrors.NewInputParameterError("Image name is required") @@ -119,7 +120,7 @@ func (self *SGuest) PerformSaveImage(ctx context.Context, userCred mcclient.Toke return nil, httperrors.NewInputParameterError("No root image") } else { kwargs := data.(*jsonutils.JSONDict) - restart := (self.Status == VM_RUNNING) || jsonutils.QueryBoolean(data, "auto_start", false) + restart := (self.Status == api.VM_RUNNING) || jsonutils.QueryBoolean(data, "auto_start", false) properties := jsonutils.NewDict() if notes, err := data.GetString("notes"); err != nil && len(notes) > 0 { properties.Add(jsonutils.NewString(notes), "notes") @@ -154,7 +155,7 @@ func (self *SGuest) AllowPerformSync(ctx context.Context, userCred mcclient.Toke } func (self *SGuest) PerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !utils.IsInStringArray(self.Status, []string{VM_READY, VM_RUNNING}) { + if !utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_RUNNING}) { return nil, httperrors.NewResourceBusyError("Cannot sync in status %s", self.Status) } if err := self.StartSyncTask(ctx, userCred, false, ""); err != nil { @@ -199,21 +200,21 @@ func (self *SGuest) AllowPerformMigrate(ctx context.Context, userCred mcclient.T } func (self *SGuest) PerformMigrate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.GetHypervisor() != HYPERVISOR_KVM { + if self.GetHypervisor() != api.HYPERVISOR_KVM { return nil, httperrors.NewNotAcceptableError("Not allow for hypervisor %s", self.GetHypervisor()) } if len(self.BackupHostId) > 0 { return nil, httperrors.NewBadRequestError("Guest have backup, can't migrate") } isRescueMode := jsonutils.QueryBoolean(data, "rescue_mode", false) - if !isRescueMode && self.Status != VM_READY { + if !isRescueMode && self.Status != api.VM_READY { return nil, httperrors.NewServerStatusError("Cannot normal migrate guest in status %s, try rescue mode or server-live-migrate?", self.Status) } if isRescueMode { guestDisks := self.GetDisks() for _, guestDisk := range guestDisks { if utils.IsInStringArray( - guestDisk.GetDisk().GetStorage().StorageType, STORAGE_LOCAL_TYPES) { + guestDisk.GetDisk().GetStorage().StorageType, api.STORAGE_LOCAL_TYPES) { return nil, httperrors.NewBadRequestError("Rescue mode requires all disk store in shared storages") } } @@ -262,13 +263,13 @@ func (self *SGuest) AllowPerformLiveMigrate(ctx context.Context, userCred mcclie } func (self *SGuest) PerformLiveMigrate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.GetHypervisor() != HYPERVISOR_KVM { + if self.GetHypervisor() != api.HYPERVISOR_KVM { return nil, httperrors.NewNotAcceptableError("Not allow for hypervisor %s", self.GetHypervisor()) } if len(self.BackupHostId) > 0 { return nil, httperrors.NewBadRequestError("Guest have backup, can't migrate") } - if utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_SUSPEND}) { + if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_SUSPEND}) { cdrom := self.getCdrom(false) if cdrom != nil && len(cdrom.ImageId) > 0 { return nil, httperrors.NewBadRequestError("Cannot migrate with cdrom") @@ -300,7 +301,7 @@ func (self *SGuest) PerformLiveMigrate(ctx context.Context, userCred mcclient.To } func (self *SGuest) StartGuestLiveMigrateTask(ctx context.Context, userCred mcclient.TokenCredential, guestStatus, preferHostId, parentTaskId string) error { - self.SetStatus(userCred, VM_START_MIGRATE, "") + self.SetStatus(userCred, api.VM_START_MIGRATE, "") data := jsonutils.NewDict() if len(preferHostId) > 0 { data.Set("prefer_host_id", jsonutils.NewString(preferHostId)) @@ -328,7 +329,7 @@ func (self *SGuest) PerformClone(ctx context.Context, userCred mcclient.TokenCre return nil, httperrors.NewBadRequestError("Guest hypervisor %s does not support clone", self.Hypervisor) } - if !utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_READY}) { + if !utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_READY}) { return nil, httperrors.NewInvalidStatusError("Cannot clone VM in status %s", self.Status) } @@ -466,7 +467,7 @@ func (self *SGuest) PerformDeploy(ctx context.Context, userCred mcclient.TokenCr } if utils.IsInStringArray(self.Status, deployStatus) { - if (doRestart && self.Status == VM_RUNNING) || (self.Status != VM_RUNNING && (jsonutils.QueryBoolean(kwargs, "auto_start", false) || jsonutils.QueryBoolean(kwargs, "restart", false))) { + if (doRestart && self.Status == api.VM_RUNNING) || (self.Status != api.VM_RUNNING && (jsonutils.QueryBoolean(kwargs, "auto_start", false) || jsonutils.QueryBoolean(kwargs, "restart", false))) { kwargs.Set("restart", jsonutils.JSONTrue) } else { // 避免前端直接传restart参数, 越过校验 @@ -504,7 +505,7 @@ func (self *SGuest) ValidateAttachDisk(ctx context.Context, disk *SDisk) error { if len(disk.GetPathAtHost(self.GetHost())) == 0 { return httperrors.NewInputParameterError("Disk %s not belong the guest's host", disk.Name) } - if disk.Status != DISK_READY { + if disk.Status != api.DISK_READY { return httperrors.NewInputParameterError("Disk in %s not able to attach", disk.Status) } guestStatus, err := self.GetDriver().GetAttachDiskStatus() @@ -549,7 +550,7 @@ func (self *SGuest) StartSyncTask(ctx context.Context, userCred mcclient.TokenCr data := jsonutils.NewDict() if fwOnly { data.Add(jsonutils.JSONTrue, "fw_only") - } else if err := self.SetStatus(userCred, VM_SYNC_CONFIG, ""); err != nil { + } else if err := self.SetStatus(userCred, api.VM_SYNC_CONFIG, ""); err != nil { log.Errorln(err) return err } @@ -578,7 +579,7 @@ func (self *SGuest) AllowPerformSuspend(ctx context.Context, userCred mcclient.T } func (self *SGuest) PerformSuspend(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status == VM_RUNNING { + if self.Status == api.VM_RUNNING { err := self.StartSuspendTask(ctx, userCred, "") return nil, err } @@ -586,7 +587,7 @@ func (self *SGuest) PerformSuspend(ctx context.Context, userCred mcclient.TokenC } func (self *SGuest) StartSuspendTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error { - err := self.SetStatus(userCred, VM_SUSPEND, "do suspend") + err := self.SetStatus(userCred, api.VM_SUSPEND, "do suspend") if err != nil { return err } @@ -602,7 +603,7 @@ func (self *SGuest) AllowPerformStart(ctx context.Context, func (self *SGuest) PerformStart(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if utils.IsInStringArray(self.Status, []string{VM_READY, VM_START_FAILED, VM_SAVE_DISK_FAILED, VM_SUSPEND}) { + if utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_START_FAILED, api.VM_SAVE_DISK_FAILED, api.VM_SUSPEND}) { if self.isAllDisksReady() { var kwargs *jsonutils.JSONDict if data != nil { @@ -619,7 +620,7 @@ func (self *SGuest) PerformStart(ctx context.Context, userCred mcclient.TokenCre } func (self *SGuest) StartGuestDeployTask(ctx context.Context, userCred mcclient.TokenCredential, kwargs *jsonutils.JSONDict, action string, parentTaskId string) error { - self.SetStatus(userCred, VM_START_DEPLOY, "") + self.SetStatus(userCred, api.VM_START_DEPLOY, "") if kwargs == nil { kwargs = jsonutils.NewDict() } @@ -681,7 +682,7 @@ func (self *SGuest) NotifyAdminServerEvent(ctx context.Context, event string, pr func (self *SGuest) StartGuestStopTask(ctx context.Context, userCred mcclient.TokenCredential, isForce bool, parentTaskId string) error { if len(parentTaskId) == 0 { - self.SetStatus(userCred, VM_START_STOP, "") + self.SetStatus(userCred, api.VM_START_STOP, "") } params := jsonutils.NewDict() if isForce { @@ -734,7 +735,7 @@ func (self *SGuest) PerformInsertiso(ctx context.Context, userCred mcclient.Toke return nil, err } - if utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_READY}) { + if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_READY}) { err = self.StartInsertIsoTask(ctx, image.Id, self.HostId, userCred, "") return nil, err } else { @@ -747,14 +748,14 @@ func (self *SGuest) AllowPerformEjectiso(ctx context.Context, userCred mcclient. } func (self *SGuest) PerformEjectiso(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Hypervisor != HYPERVISOR_KVM { + if self.Hypervisor != api.HYPERVISOR_KVM { return nil, httperrors.NewNotAcceptableError("Not allow for hypervisor %s", self.Hypervisor) } cdrom := self.getCdrom(false) if cdrom == nil || len(cdrom.ImageId) == 0 { return nil, httperrors.NewBadRequestError("No ISO to eject") } - if utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_READY}) { + if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_READY}) { err := self.StartEjectisoTask(ctx, userCred, "") return nil, err } else { @@ -787,7 +788,7 @@ func (self *SGuest) StartInsertIsoTask(ctx context.Context, imageId string, host } func (self *SGuest) StartGueststartTask(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, parentTaskId string) error { - self.SetStatus(userCred, VM_START_START, "") + self.SetStatus(userCred, api.VM_START_START, "") task, err := taskman.TaskManager.NewTask(ctx, "GuestStartTask", self, userCred, data, parentTaskId, "", nil) if err != nil { return err @@ -818,7 +819,7 @@ func (self *SGuest) StartDeleteGuestTask(ctx context.Context, userCred mcclient. if overridePendingDelete { params.Add(jsonutils.JSONTrue, "override_pending_delete") } - self.SetStatus(userCred, VM_START_DELETE, "") + self.SetStatus(userCred, api.VM_START_DELETE, "") return self.GetDriver().StartDeleteGuestTask(ctx, userCred, self, params, parentTaskId) } @@ -827,7 +828,7 @@ func (self *SGuest) AllowPerformAddSecgroup(ctx context.Context, userCred mcclie } func (self *SGuest) PerformAddSecgroup(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !utils.IsInStringArray(self.Status, []string{VM_READY, VM_RUNNING, VM_SUSPEND}) { + if !utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_RUNNING, api.VM_SUSPEND}) { return nil, httperrors.NewInputParameterError("Cannot assign security rules in status %s", self.Status) } @@ -932,7 +933,7 @@ func (self *SGuest) revokeSecgroup(ctx context.Context, userCred mcclient.TokenC } func (self *SGuest) PerformRevokeSecgroup(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !utils.IsInStringArray(self.Status, []string{VM_READY, VM_RUNNING, VM_SUSPEND}) { + if !utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_RUNNING, api.VM_SUSPEND}) { return nil, httperrors.NewInputParameterError("Cannot revoke security rules in status %s", self.Status) } @@ -975,7 +976,7 @@ func (self *SGuest) PerformRevokeSecgroup(ctx context.Context, userCred mcclient } func (self *SGuest) PerformAssignSecgroup(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !utils.IsInStringArray(self.Status, []string{VM_READY, VM_RUNNING, VM_SUSPEND}) { + if !utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_RUNNING, api.VM_SUSPEND}) { return nil, httperrors.NewInputParameterError("Cannot assign security rules in status %s", self.Status) } secgrpV := validators.NewModelIdOrNameValidator("secgrp", "secgroup", userCred.GetProjectId()) @@ -1002,7 +1003,7 @@ func (self *SGuest) AllowPerformSetSecgroup(ctx context.Context, userCred mcclie } func (self *SGuest) PerformSetSecgroup(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !utils.IsInStringArray(self.Status, []string{VM_READY, VM_RUNNING, VM_SUSPEND}) { + if !utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_RUNNING, api.VM_SUSPEND}) { return nil, httperrors.NewInputParameterError("Cannot assign security rules in status %s", self.Status) } secgrpJsonArray := jsonutils.GetArrayOfPrefix(data, "secgrp") @@ -1117,7 +1118,7 @@ func (self *SGuest) PerformRebuildRoot(ctx context.Context, userCred mcclient.To autoStart := jsonutils.QueryBoolean(data, "auto_start", false) var needStop = false - if self.Status == VM_RUNNING { + if self.Status == api.VM_RUNNING { needStop = true } resetPasswd := jsonutils.QueryBoolean(data, "reset_password", true) @@ -1181,8 +1182,8 @@ func (self *SGuest) StartRebuildRootTask(ctx context.Context, userCred mcclient. } else { data.Set("all_disks", jsonutils.JSONFalse) } - self.SetStatus(userCred, VM_REBUILD_ROOT, "request start rebuild root") - if self.GetHypervisor() == HYPERVISOR_BAREMETAL { + self.SetStatus(userCred, api.VM_REBUILD_ROOT, "request start rebuild root") + if self.GetHypervisor() == api.HYPERVISOR_BAREMETAL { task, err := taskman.TaskManager.NewTask(ctx, "BaremetalServerRebuildRootTask", self, userCred, data, "", "", nil) if err != nil { return err @@ -1309,7 +1310,7 @@ func (self *SGuest) PerformDetachdisk(ctx context.Context, userCred mcclient.Tok disk := iDisk.(*SDisk) if disk != nil { if self.isAttach2Disk(disk) { - if disk.DiskType == DISK_TYPE_SYS { + if disk.DiskType == api.DISK_TYPE_SYS { return nil, httperrors.NewUnsupportOperationError("Cannot detach sys disk") } detachDiskStatus, err := self.GetDriver().GetDetachDiskStatus() @@ -1336,7 +1337,7 @@ func (self *SGuest) StartGuestDetachdiskTask(ctx context.Context, userCred mccli taskData := jsonutils.NewDict() taskData.Add(jsonutils.NewString(disk.Id), "disk_id") taskData.Add(jsonutils.NewBool(keepDisk), "keep_disk") - if utils.IsInStringArray(disk.Status, []string{DISK_INIT, DISK_ALLOC_FAILED}) { + if utils.IsInStringArray(disk.Status, []string{api.DISK_INIT, api.DISK_ALLOC_FAILED}) { //删除非正常状态下的disk taskData.Add(jsonutils.JSONFalse, "keep_disk") db.Update(disk, func() error { @@ -1344,7 +1345,7 @@ func (self *SGuest) StartGuestDetachdiskTask(ctx context.Context, userCred mccli return nil }) } - disk.SetStatus(userCred, DISK_DETACHING, "") + disk.SetStatus(userCred, api.DISK_DETACHING, "") return self.GetDriver().StartGuestDetachdiskTask(ctx, userCred, self, taskData, parentTaskId) } @@ -1353,10 +1354,10 @@ func (self *SGuest) AllowPerformDetachIsolatedDevice(ctx context.Context, userCr } func (self *SGuest) PerformDetachIsolatedDevice(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Hypervisor != HYPERVISOR_KVM { + if self.Hypervisor != api.HYPERVISOR_KVM { return nil, httperrors.NewNotAcceptableError("Not allow for hypervisor %s", self.Hypervisor) } - if self.Status != VM_READY { + if self.Status != api.VM_READY { msg := "Only allowed to attach isolated device when guest is ready" logclient.AddActionLogWithContext(ctx, self, logclient.ACT_GUEST_DETACH_ISOLATED_DEVICE, msg, userCred, false) return nil, httperrors.NewInvalidStatusError(msg) @@ -1403,10 +1404,10 @@ func (self *SGuest) AllowPerformAttachIsolatedDevice(ctx context.Context, userCr } func (self *SGuest) PerformAttachIsolatedDevice(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Hypervisor != HYPERVISOR_KVM { + if self.Hypervisor != api.HYPERVISOR_KVM { return nil, httperrors.NewNotAcceptableError("Not allow for hypervisor %s", self.Hypervisor) } - if self.Status != VM_READY { + if self.Status != api.VM_READY { msg := "Only allowed to attach isolated device when guest is ready" logclient.AddActionLogWithContext(ctx, self, logclient.ACT_GUEST_ATTACH_ISOLATED_DEVICE, msg, userCred, false) return nil, httperrors.NewInvalidStatusError(msg) @@ -1472,7 +1473,7 @@ func (self *SGuest) findGuestnetworkByInfo(ipStr string, macStr string, index in } func (self *SGuest) PerformChangeIpaddr(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status != VM_READY && self.Status != VM_RUNNING { + if self.Status != api.VM_READY && self.Status != api.VM_RUNNING { return nil, httperrors.NewInvalidStatusError("Cannot change network ip_addr in status %s", self.Status) } @@ -1513,7 +1514,7 @@ func (self *SGuest) PerformChangeIpaddr(ctx context.Context, userCred mcclient.T if len(conf.Mac) > 0 { if conf.Mac != gn.MacAddr { - if self.Status != VM_READY { + if self.Status != api.VM_READY { // change mac return nil, httperrors.NewInvalidStatusError("cannot change mac when guest is running") } @@ -1566,7 +1567,7 @@ func (self *SGuest) AllowPerformDetachnetwork(ctx context.Context, userCred mccl } func (self *SGuest) PerformDetachnetwork(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status != VM_READY { + if self.Status != api.VM_READY { return nil, httperrors.NewInvalidStatusError("Cannot detach network in status %s", self.Status) } reserve := jsonutils.QueryBoolean(data, "reserve", false) @@ -1619,7 +1620,7 @@ func (self *SGuest) AllowPerformAttachnetwork(ctx context.Context, userCred mccl } func (self *SGuest) PerformAttachnetwork(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status == VM_READY { + if self.Status == api.VM_READY { // owner_cred = self.get_owner_user_cred() >.< netDesc, err := data.Get("net_desc") if err != nil { @@ -1675,7 +1676,7 @@ func (self *SGuest) AllowPerformChangeBandwidth(ctx context.Context, userCred mc } func (self *SGuest) PerformChangeBandwidth(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !utils.IsInStringArray(self.Status, []string{VM_READY, VM_RUNNING}) { + if !utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_RUNNING}) { msg := fmt.Sprintf("Cannot change bandwidth in status %s", self.Status) return nil, httperrors.NewBadRequestError(msg) } @@ -1797,7 +1798,7 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T } } - if self.Status == VM_RUNNING && (cpuChanged || memChanged) && self.GetDriver().NeedStopForChangeSpec(self) { + if self.Status == api.VM_RUNNING && (cpuChanged || memChanged) && self.GetDriver().NeedStopForChangeSpec(self) { return nil, httperrors.NewInvalidStatusError("cannot change CPU/Memory spec in status %s", self.Status) } @@ -1885,10 +1886,10 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T if resizeDisks.Length() > 0 { confs.Add(resizeDisks, "resize") } - if self.Status != VM_RUNNING && jsonutils.QueryBoolean(data, "auto_start", false) { + if self.Status != api.VM_RUNNING && jsonutils.QueryBoolean(data, "auto_start", false) { confs.Add(jsonutils.NewBool(true), "auto_start") } - if self.Status == VM_RUNNING { + if self.Status == api.VM_RUNNING { confs.Set("guest_online", jsonutils.JSONTrue) } @@ -1956,7 +1957,7 @@ func (self *SGuest) confToSchedDesc(addCpu, addMem, addDisk int) *schedapi.Sched func (self *SGuest) StartChangeConfigTask(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict, parentTaskId string, pendingUsage quotas.IQuota) error { - self.SetStatus(userCred, VM_CHANGE_FLAVOR, "") + self.SetStatus(userCred, api.VM_CHANGE_FLAVOR, "") task, err := taskman.TaskManager.NewTask(ctx, "GuestChangeConfigTask", self, userCred, data, parentTaskId, "", pendingUsage) if err != nil { return err @@ -2037,7 +2038,7 @@ func (self *SGuest) AllowPerformReset(ctx context.Context, func (self *SGuest) PerformReset(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { isHard := jsonutils.QueryBoolean(data, "is_hard", false) - if self.Status == VM_RUNNING || self.Status == VM_STOP_FAILED { + if self.Status == api.VM_RUNNING || self.Status == api.VM_STOP_FAILED { self.GetDriver().StartGuestResetTask(self, ctx, userCred, isHard, "") return nil, nil } @@ -2052,7 +2053,7 @@ func (self *SGuest) PerformDiskSnapshot(ctx context.Context, userCred mcclient.T if len(self.BackupHostId) > 0 { return nil, httperrors.NewBadRequestError("Guest has backup, can't create snapshot") } - if !utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_READY}) { + if !utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_READY}) { return nil, httperrors.NewInvalidStatusError("Cannot do snapshot when VM in status %s", self.Status) } diskId, err := data.GetString("disk_id") @@ -2070,10 +2071,10 @@ func (self *SGuest) PerformDiskSnapshot(ctx context.Context, userCred mcclient.T if self.GetGuestDisk(diskId) == nil { return nil, httperrors.NewNotFoundError("Guest disk %s not found", diskId) } - if self.GetHypervisor() == HYPERVISOR_KVM { + if self.GetHypervisor() == api.HYPERVISOR_KVM { q := SnapshotManager.Query() cnt := q.Filter(sqlchemy.AND(sqlchemy.Equals(q.Field("disk_id"), diskId), - sqlchemy.Equals(q.Field("created_by"), MANUAL), + sqlchemy.Equals(q.Field("created_by"), api.SNAPSHOT_MANUAL), sqlchemy.Equals(q.Field("fake_deleted"), false))).Count() if cnt >= options.Options.DefaultMaxManualSnapshotCount { return nil, httperrors.NewBadRequestError("Disk %s snapshot full, cannot take any more", diskId) @@ -2083,7 +2084,7 @@ func (self *SGuest) PerformDiskSnapshot(ctx context.Context, userCred mcclient.T if err != nil { return nil, httperrors.NewOutOfQuotaError("Check set pending quota error %s", err) } - snapshot, err := SnapshotManager.CreateSnapshot(ctx, userCred, MANUAL, diskId, self.Id, "", name) + snapshot, err := SnapshotManager.CreateSnapshot(ctx, userCred, api.SNAPSHOT_MANUAL, diskId, self.Id, "", name) QuotaManager.CancelPendingUsage(ctx, userCred, self.ProjectId, nil, pendingUsage) if err != nil { return nil, err @@ -2091,7 +2092,7 @@ func (self *SGuest) PerformDiskSnapshot(ctx context.Context, userCred mcclient.T err = self.StartDiskSnapshot(ctx, userCred, diskId, snapshot.Id) return nil, err } else { - snapshot, err := SnapshotManager.CreateSnapshot(ctx, userCred, MANUAL, diskId, self.Id, "", name) + snapshot, err := SnapshotManager.CreateSnapshot(ctx, userCred, api.SNAPSHOT_MANUAL, diskId, self.Id, "", name) if err != nil { return nil, err } @@ -2106,13 +2107,13 @@ func (self *SGuest) AllowPerformSyncstatus(ctx context.Context, userCred mcclien } func (self *SGuest) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - self.SetStatus(userCred, VM_SYNCING_STATUS, "perform_syncstatus") + self.SetStatus(userCred, api.VM_SYNCING_STATUS, "perform_syncstatus") err := self.StartSyncstatus(ctx, userCred, "") return nil, err } func (self *SGuest) isNotRunningStatus(status string) bool { - if status == VM_READY || status == VM_SUSPEND { + if status == api.VM_READY || status == api.VM_SUSPEND { return true } return false @@ -2126,7 +2127,7 @@ func (self *SGuest) PerformStatus(ctx context.Context, userCred mcclient.TokenCr } if preStatus != self.Status && !self.isNotRunningStatus(preStatus) && self.isNotRunningStatus(self.Status) { db.OpsLog.LogEvent(self, db.ACT_STOP, "", userCred) - if self.Status == VM_READY && !self.DisableDelete.Bool() && self.ShutdownBehavior == SHUTDOWN_TERMINATE { + if self.Status == api.VM_READY && !self.DisableDelete.Bool() && self.ShutdownBehavior == api.SHUTDOWN_TERMINATE { err = self.StartAutoDeleteGuestTask(ctx, userCred, "") return nil, err } @@ -2135,7 +2136,7 @@ func (self *SGuest) PerformStatus(ctx context.Context, userCred mcclient.TokenCr } func (self *SGuest) StartDiskSnapshot(ctx context.Context, userCred mcclient.TokenCredential, diskId, snapshotId string) error { - self.SetStatus(userCred, VM_START_SNAPSHOT, "StartDiskSnapshot") + self.SetStatus(userCred, api.VM_START_SNAPSHOT, "StartDiskSnapshot") params := jsonutils.NewDict() params.Set("disk_id", jsonutils.NewString(diskId)) params.Set("snapshot_id", jsonutils.NewString(snapshotId)) @@ -2153,7 +2154,7 @@ func (self *SGuest) PerformStop(ctx context.Context, userCred mcclient.TokenCred data jsonutils.JSONObject) (jsonutils.JSONObject, error) { // XXX if is force, force stop guest var isForce = jsonutils.QueryBoolean(data, "is_force", false) - if isForce || utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_STOP_FAILED}) { + if isForce || utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_STOP_FAILED}) { return nil, self.StartGuestStopTask(ctx, userCred, isForce, "") } else { return nil, httperrors.NewInvalidStatusError("Cannot stop server in status %s", self.Status) @@ -2169,7 +2170,7 @@ func (self *SGuest) AllowPerformRestart(ctx context.Context, func (self *SGuest) PerformRestart(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { isForce := jsonutils.QueryBoolean(data, "is_force", false) - if utils.IsInStringArray(self.Status, []string{VM_RUNNING, VM_STOP_FAILED}) || (isForce && self.Status == VM_STOPPING) { + if utils.IsInStringArray(self.Status, []string{api.VM_RUNNING, api.VM_STOP_FAILED}) || (isForce && self.Status == api.VM_STOPPING) { return nil, self.GetDriver().StartGuestRestartTask(self, ctx, userCred, isForce, "") } else { return nil, httperrors.NewInvalidStatusError("Cannot do restart server in status %s", self.Status) @@ -2181,10 +2182,10 @@ func (self *SGuest) AllowPerformSendkeys(ctx context.Context, userCred mcclient. } func (self *SGuest) PerformSendkeys(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Hypervisor != HYPERVISOR_KVM { + if self.Hypervisor != api.HYPERVISOR_KVM { return nil, httperrors.NewNotAcceptableError("Not allow for hypervisor %s", self.Hypervisor) } - if self.Status != VM_RUNNING { + if self.Status != api.VM_RUNNING { return nil, httperrors.NewInvalidStatusError("Cannot send keys in status %s", self.Status) } keys, err := data.GetString("keys") @@ -2256,7 +2257,7 @@ func (self *SGuest) AllowPerformAssociateEip(ctx context.Context, userCred mccli } func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !utils.IsInStringArray(self.Status, []string{VM_READY, VM_RUNNING}) { + if !utils.IsInStringArray(self.Status, []string{api.VM_READY, api.VM_RUNNING}) { return nil, httperrors.NewInvalidStatusError("cannot associate eip in status %s", self.Status) } @@ -2285,7 +2286,7 @@ func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.T eipRegion := eip.GetRegion() instRegion := self.getRegion() - if eip.Mode == EIP_MODE_INSTANCE_PUBLICIP { + if eip.Mode == api.EIP_MODE_INSTANCE_PUBLICIP { return nil, httperrors.NewUnsupportOperationError("fixed eip cannot be associated") } @@ -2307,12 +2308,12 @@ func (self *SGuest) PerformAssociateEip(ctx context.Context, userCred mcclient.T return nil, httperrors.NewInputParameterError("cannot associate eip and instance in different provider") } - self.SetStatus(userCred, VM_ASSOCIATE_EIP, "associate eip") + self.SetStatus(userCred, api.VM_ASSOCIATE_EIP, "associate eip") params := jsonutils.NewDict() params.Add(jsonutils.NewString(self.ExternalId), "instance_external_id") params.Add(jsonutils.NewString(self.Id), "instance_id") - params.Add(jsonutils.NewString(EIP_ASSOCIATE_TYPE_SERVER), "instance_type") + params.Add(jsonutils.NewString(api.EIP_ASSOCIATE_TYPE_SERVER), "instance_type") err = eip.StartEipAssociateTask(ctx, userCred, params, "") @@ -2333,7 +2334,7 @@ func (self *SGuest) PerformDissociateEip(ctx context.Context, userCred mcclient. return nil, httperrors.NewInvalidStatusError("No eip to dissociate") } - self.SetStatus(userCred, VM_DISSOCIATE_EIP, "associate eip") + self.SetStatus(userCred, api.VM_DISSOCIATE_EIP, "associate eip") autoDelete := jsonutils.QueryBoolean(data, "auto_delete", false) @@ -2357,7 +2358,7 @@ func (self *SGuest) PerformCreateEip(ctx context.Context, userCred mcclient.Toke chargeType, _ := data.GetString("charge_type") if len(chargeType) == 0 { - chargeType = EIP_CHARGE_TYPE_DEFAULT + chargeType = api.EIP_CHARGE_TYPE_DEFAULT } if len(self.ExternalId) == 0 { @@ -2444,14 +2445,14 @@ func (self *SGuest) AllowPerformSwitchToBackup(ctx context.Context, userCred mcc } func (self *SGuest) PerformSwitchToBackup(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status == VM_BLOCK_STREAM { + if self.Status == api.VM_BLOCK_STREAM { return nil, httperrors.NewBadRequestError("Cannot swith to backup when guest in status %s", self.Status) } if len(self.BackupHostId) == 0 { return nil, httperrors.NewBadRequestError("Guest no backup host") } oldStatus := self.Status - self.SetStatus(userCred, VM_SWITCH_TO_BACKUP, "Switch to backup") + self.SetStatus(userCred, api.VM_SWITCH_TO_BACKUP, "Switch to backup") deleteBackup := jsonutils.QueryBoolean(data, "delete_backup", false) purgeBackup := jsonutils.QueryBoolean(data, "purge_backup", false) @@ -2556,10 +2557,10 @@ func (self *SGuest) PerformCreateBackup(ctx context.Context, userCred mcclient.T if len(self.BackupHostId) > 0 { return nil, httperrors.NewBadRequestError("Already have backup server") } - if self.getDefaultStorageType() != STORAGE_LOCAL { + if self.getDefaultStorageType() != api.STORAGE_LOCAL { return nil, httperrors.NewBadRequestError("Cannot create backup with shared storage") } - if self.Hypervisor != HYPERVISOR_KVM { + if self.Hypervisor != api.HYPERVISOR_KVM { return nil, httperrors.NewBadRequestError("Backup only support hypervisor kvm") } if len(self.GetIsolatedDevices()) > 0 { @@ -2600,16 +2601,16 @@ func (self *SGuest) PerformDeleteBackup(ctx context.Context, userCred mcclient.T if backupHost == nil { return nil, httperrors.NewNotFoundError("Guest backup host not found") } - if backupHost.Status == HOST_OFFLINE && !jsonutils.QueryBoolean(data, "purge", false) { + if backupHost.Status == api.HOST_OFFLINE && !jsonutils.QueryBoolean(data, "purge", false) { return nil, httperrors.NewBadRequestError("Backup host is offline") } taskData := jsonutils.NewDict() taskData.Set("purge", jsonutils.NewBool(jsonutils.QueryBoolean(data, "purge", false))) taskData.Set("host_id", jsonutils.NewString(self.BackupHostId)) - taskData.Set("failed_status", jsonutils.NewString(VM_BACKUP_DELETE_FAILED)) + taskData.Set("failed_status", jsonutils.NewString(api.VM_BACKUP_DELETE_FAILED)) - self.SetStatus(userCred, VM_DELETING_BACKUP, "delete backup server") + self.SetStatus(userCred, api.VM_DELETING_BACKUP, "delete backup server") if task, err := taskman.TaskManager.NewTask( ctx, "GuestDeleteOnHostTask", self, userCred, taskData, "", "", nil); err != nil { log.Errorln(err) @@ -2652,7 +2653,7 @@ func (self *SGuest) PerformMirrorJobFailed(ctx context.Context, userCred mcclien if len(self.BackupHostId) == 0 { return nil, nil } else { - return nil, self.SetStatus(userCred, VM_MIRROR_FAIL, "OnSyncToBackup") + return nil, self.SetStatus(userCred, api.VM_MIRROR_FAIL, "OnSyncToBackup") } } @@ -2726,7 +2727,7 @@ func (self *SGuest) PerformRenew(ctx context.Context, userCred mcclient.TokenCre } func (self *SGuest) startGuestRenewTask(ctx context.Context, userCred mcclient.TokenCredential, duration string, parentTaskId string) error { - self.SetStatus(userCred, VM_RENEWING, "") + self.SetStatus(userCred, api.VM_RENEWING, "") data := jsonutils.NewDict() data.Add(jsonutils.NewString(duration), "duration") task, err := taskman.TaskManager.NewTask(ctx, "GuestRenewTask", self, userCred, data, parentTaskId, "", nil) @@ -2746,7 +2747,7 @@ func (self *SGuest) SaveRenewInfo(ctx context.Context, userCred mcclient.TokenCr guestdisks := self.GetDisks() for i := 0; i < len(guestdisks); i += 1 { disk := guestdisks[i].GetDisk() - if disk.BillingType == BILLING_TYPE_PREPAID { + if disk.BillingType == billing_api.BILLING_TYPE_PREPAID { err = disk.SaveRenewInfo(ctx, userCred, bc, expireAt) if err != nil { return err @@ -2758,8 +2759,8 @@ func (self *SGuest) SaveRenewInfo(ctx context.Context, userCred mcclient.TokenCr func (self *SGuest) doSaveRenewInfo(ctx context.Context, userCred mcclient.TokenCredential, bc *billing.SBillingCycle, expireAt *time.Time) error { _, err := db.Update(self, func() error { - if self.BillingType != BILLING_TYPE_PREPAID { - self.BillingType = BILLING_TYPE_PREPAID + if self.BillingType != billing_api.BILLING_TYPE_PREPAID { + self.BillingType = billing_api.BILLING_TYPE_PREPAID } if expireAt != nil && !expireAt.IsZero() { self.ExpiredAt = *expireAt @@ -2928,7 +2929,7 @@ func (self *SGuest) importDisks(ctx context.Context, userCred mcclient.TokenCred if err != nil { return err } - disk.SetStatus(userCred, DISK_READY, "") + disk.SetStatus(userCred, api.DISK_READY, "") } return nil } diff --git a/pkg/compute/models/guestdisks.go b/pkg/compute/models/guestdisks.go index 46983f9fa2..a3c5f2eaab 100644 --- a/pkg/compute/models/guestdisks.go +++ b/pkg/compute/models/guestdisks.go @@ -173,14 +173,14 @@ func (self *SGuestdisk) GetJsonDescAtHost(host *SHost) jsonutils.JSONObject { } storage := disk.GetStorage() // XXX ??? - if host.HostType == HOST_TYPE_HYPERVISOR { + if host.HostType == api.HOST_TYPE_HYPERVISOR { desc.Add(jsonutils.NewString(disk.StorageId), "storage_id") localpath := disk.GetPathAtHost(host) if len(localpath) == 0 { desc.Add(jsonutils.JSONTrue, "migrating") target := host.GetLeastUsedStorage(storage.StorageType) desc.Add(jsonutils.NewString(target.Id), "target_storage_id") - disk.SetStatus(nil, DISK_START_MIGRATE, "migration") + disk.SetStatus(nil, api.DISK_START_MIGRATE, "migration") } else { desc.Add(jsonutils.NewString(localpath), "path") } diff --git a/pkg/compute/models/guestnetworks.go b/pkg/compute/models/guestnetworks.go index f79f8fd1ca..3ba67cad6c 100644 --- a/pkg/compute/models/guestnetworks.go +++ b/pkg/compute/models/guestnetworks.go @@ -275,14 +275,14 @@ func (self *SGuestnetwork) getJsonDescAtHost(host *SHost) jsonutils.JSONObject { var hostWire *SHostwire for i := 0; i < len(hostwires); i++ { if netInter, _ := NetInterfaceManager.FetchByMac(hostwires[i].MacAddr); netInter != nil { - if netInter.NicType == NIC_TYPE_ADMIN { + if netInter.NicType == api.NIC_TYPE_ADMIN { hostWire = &hostwires[i] break } } } if hostWire == nil { - log.Errorf("Host %s has no net interface on wire %s as guest network %s", host.Name, network.WireId, NIC_TYPE_ADMIN) + log.Errorf("Host %s has no net interface on wire %s as guest network %s", host.Name, network.WireId, api.NIC_TYPE_ADMIN) return nil } return self.getGeneralJsonDesc(host, network, hostWire) @@ -340,7 +340,7 @@ func (self *SGuestnetwork) getGeneralJsonDesc(host *SHost, network *SNetwork, ho } guest := self.getGuest() - if guest.GetHypervisor() != HYPERVISOR_KVM { + if guest.GetHypervisor() != api.HYPERVISOR_KVM { desc.Add(jsonutils.JSONTrue, "manual") } @@ -520,7 +520,7 @@ func (self *SGuestnetwork) IsExit() bool { } func (self *SGuestnetwork) getBandwidth() int { - if self.BwLimit > 0 && self.BwLimit <= MAX_BANDWIDTH { + if self.BwLimit > 0 && self.BwLimit <= api.MAX_BANDWIDTH { return self.BwLimit } else { net := self.GetNetwork() diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 57bf1aa66f..580d7d35ea 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -35,6 +35,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" api "yunion.io/x/onecloud/pkg/apis/compute" schedapi "yunion.io/x/onecloud/pkg/apis/scheduler" "yunion.io/x/onecloud/pkg/cloudcommon/cmdline" @@ -58,6 +59,7 @@ import ( "yunion.io/x/onecloud/pkg/util/stringutils2" ) +/* const ( VM_INIT = api.VM_INIT VM_UNKNOWN = api.VM_UNKNOWN @@ -189,6 +191,7 @@ var PUBLIC_CLOUD_HYPERVISORS = api.PUBLIC_CLOUD_HYPERVISORS var HYPERVISOR_HOSTTYPE = api.HYPERVISOR_HOSTTYPE var HOSTTYPE_HYPERVISOR = api.HOSTTYPE_HYPERVISOR +*/ type SGuestManager struct { db.SVirtualResourceBaseManager @@ -272,7 +275,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ billingTypeStr, _ := queryDict.GetString("billing_type") if len(billingTypeStr) > 0 { - if billingTypeStr == BILLING_TYPE_POSTPAID { + if billingTypeStr == billing_api.BILLING_TYPE_POSTPAID { q = q.Filter( sqlchemy.OR( sqlchemy.IsNullOrEmpty(q.Field("billing_type")), @@ -291,7 +294,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ } isBMstr, _ := queryDict.GetString("baremetal") if len(isBMstr) > 0 && utils.ToBool(isBMstr) { - queryDict.Add(jsonutils.NewString(HYPERVISOR_BAREMETAL), "hypervisor") + queryDict.Add(jsonutils.NewString(api.HYPERVISOR_BAREMETAL), "hypervisor") queryDict.Remove("baremetal") } hypervisor, _ := queryDict.GetString("hypervisor") @@ -304,7 +307,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ hosts := HostManager.Query().SubQuery() subq := hosts.Query(hosts.Field("id")) switch resourceTypeStr { - case HostResourceTypeShared: + case api.HostResourceTypeShared: subq = subq.Filter( sqlchemy.OR( sqlchemy.IsNullOrEmpty(hosts.Field("resource_type")), @@ -470,7 +473,7 @@ func (manager *SGuestManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQ withoutEip, _ := queryDict.GetString("without_eip") if len(withEip) > 0 || len(withoutEip) > 0 { eips := ElasticipManager.Query().SubQuery() - sq := eips.Query(eips.Field("associate_id")).Equals("associate_type", EIP_ASSOCIATE_TYPE_SERVER) + sq := eips.Query(eips.Field("associate_id")).Equals("associate_type", api.EIP_ASSOCIATE_TYPE_SERVER) sq = sq.IsNotNull("associate_id").IsNotEmpty("associate_id") if utils.ToBool(withEip) { @@ -541,19 +544,19 @@ func (manager *SGuestManager) ExtraSearchConditions(ctx context.Context, q *sqlc func (guest *SGuest) GetHypervisor() string { if len(guest.Hypervisor) == 0 { - return HYPERVISOR_DEFAULT + return api.HYPERVISOR_DEFAULT } else { return guest.Hypervisor } } func (guest *SGuest) GetHostType() string { - return HYPERVISOR_HOSTTYPE[guest.Hypervisor] + return api.HYPERVISOR_HOSTTYPE[guest.Hypervisor] } func (guest *SGuest) GetDriver() IGuestDriver { hypervisor := guest.GetHypervisor() - if !utils.IsInStringArray(hypervisor, HYPERVISORS) { + if !utils.IsInStringArray(hypervisor, api.HYPERVISORS) { log.Fatalf("Unsupported hypervisor %s", hypervisor) } return GetDriver(hypervisor) @@ -736,7 +739,7 @@ func ValidateCpuData(vcpuCount int, driver IGuestDriver) (int, error) { func ValidateMemCpuData(vmemSize, vcpuCount int, hypervisor string) (int, int, error) { if len(hypervisor) == 0 { - hypervisor = HYPERVISOR_DEFAULT + hypervisor = api.HYPERVISOR_DEFAULT } driver := GetDriver(hypervisor) @@ -774,10 +777,10 @@ func (self *SGuest) ValidateUpdateData(ctx context.Context, userCred mcclient.To } if vmemSize > 0 || vcpuCount > 0 { - if !utils.IsInStringArray(self.Status, []string{VM_READY}) && self.GetHypervisor() != HYPERVISOR_CONTAINER { + if !utils.IsInStringArray(self.Status, []string{api.VM_READY}) && self.GetHypervisor() != api.HYPERVISOR_CONTAINER { return nil, httperrors.NewInvalidStatusError("Cannot modify Memory and CPU in status %s", self.Status) } - if self.GetHypervisor() == HYPERVISOR_BAREMETAL { + if self.GetHypervisor() == api.HYPERVISOR_BAREMETAL { return nil, httperrors.NewInputParameterError("Cannot modify memory for baremetal") } } @@ -831,7 +834,7 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m // var rootStorageType string var osProf osprofile.SOSProfile hypervisor = input.Hypervisor - if hypervisor != HYPERVISOR_CONTAINER { + if hypervisor != api.HYPERVISOR_CONTAINER { if len(input.Disks) == 0 { return nil, httperrors.NewInputParameterError("No disk information provided") } @@ -840,7 +843,7 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m if err != nil { return nil, httperrors.NewInputParameterError("Invalid root image: %s", err) } - if len(diskConfig.SnapshotId) > 0 && diskConfig.DiskType != DISK_TYPE_SYS { + if len(diskConfig.SnapshotId) > 0 && diskConfig.DiskType != api.DISK_TYPE_SYS { return nil, httperrors.NewBadRequestError("Snapshot error: disk index 0 but disk type is %s", diskConfig.DiskType) } @@ -895,7 +898,7 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m } hypervisor = input.Hypervisor - if hypervisor != HYPERVISOR_CONTAINER { + if hypervisor != api.HYPERVISOR_CONTAINER { // support sku here var sku *SServerSku skuName := input.InstanceType @@ -966,8 +969,8 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m if err != nil { return nil, httperrors.NewInputParameterError("parse disk description error %s", err) } - if diskConfig.DiskType == DISK_TYPE_SYS { - return nil, httperrors.NewBadRequestError("Snapshot error: disk index %d > 0 but disk type is %s", i+1, DISK_TYPE_SYS) + if diskConfig.DiskType == api.DISK_TYPE_SYS { + return nil, httperrors.NewBadRequestError("Snapshot error: disk index %d > 0 but disk type is %s", i+1, api.DISK_TYPE_SYS) } if len(diskConfig.Backend) == 0 { diskConfig.Backend = rootDiskConfig.Backend @@ -987,7 +990,7 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m return nil, httperrors.NewForbiddenError("only admin can create prepaid resource") } - if resourceTypeStr == HostResourceTypePrepaidRecycle { + if resourceTypeStr == api.HostResourceTypePrepaidRecycle { return nil, httperrors.NewConflictError("cannot create prepaid server on prepaid resource type") } @@ -1000,7 +1003,7 @@ func (manager *SGuestManager) ValidateCreateData(ctx context.Context, userCred m return nil, httperrors.NewInputParameterError("unsupported duration %s", durationStr) } - input.BillingType = BILLING_TYPE_PREPAID + input.BillingType = billing_api.BILLING_TYPE_PREPAID input.BillingCycle = billingCycle.String() // expired_at will be set later by callback // data.Add(jsonutils.NewTimeString(billingCycle.EndAt(time.Time{})), "expired_at") @@ -1122,7 +1125,7 @@ func (manager *SGuestManager) validateEip(userCred mcclient.TokenCredential, inp } eip := eipObj.(*SElasticip) - if eip.Status != EIP_STATUS_READY { + if eip.Status != api.EIP_STATUS_READY { return httperrors.NewInvalidStatusError("eip %s status invalid %s", eipStr, eip.Status) } if eip.IsAssociated() { @@ -1255,7 +1258,7 @@ func (guest *SGuest) PostCreate(ctx context.Context, userCred mcclient.TokenCred } func (guest *SGuest) setApptags(ctx context.Context, appTags []string, userCred mcclient.TokenCredential) { - err := guest.SetMetadata(ctx, VM_METADATA_APP_TAGS, strings.Join(appTags, ","), userCred) + err := guest.SetMetadata(ctx, api.VM_METADATA_APP_TAGS, strings.Join(appTags, ","), userCred) if err != nil { log.Errorln(err) } @@ -1264,7 +1267,7 @@ func (guest *SGuest) setApptags(ctx context.Context, appTags []string, userCred func (guest *SGuest) SetCreateParams(ctx context.Context, userCred mcclient.TokenCredential, data jsonutils.JSONObject) { // delete deploy files info data.(*jsonutils.JSONDict).Remove("deploy_configs") - err := guest.SetMetadata(ctx, VM_METADATA_CREATE_PARAMS, data.String(), userCred) + err := guest.SetMetadata(ctx, api.VM_METADATA_CREATE_PARAMS, data.String(), userCred) if err != nil { log.Errorf("Server %s SetCreateParams: %v", guest.Name, err) } @@ -1272,9 +1275,9 @@ func (guest *SGuest) SetCreateParams(ctx context.Context, userCred mcclient.Toke func (guest *SGuest) GetCreateParams(userCred mcclient.TokenCredential) (*api.ServerCreateInput, error) { input := new(api.ServerCreateInput) - data := guest.GetMetadataJson(VM_METADATA_CREATE_PARAMS, userCred) + data := guest.GetMetadataJson(api.VM_METADATA_CREATE_PARAMS, userCred) if data == nil { - return nil, fmt.Errorf("Not found %s %s in metadata", guest.Name, VM_METADATA_CREATE_PARAMS) + return nil, fmt.Errorf("Not found %s %s in metadata", guest.Name, api.VM_METADATA_CREATE_PARAMS) } err := data.Unmarshal(input) return input, err @@ -1808,9 +1811,9 @@ func (self *SGuest) syncRemoveCloudVM(ctx context.Context, userCred mcclient.Tok lockman.LockObject(ctx, self) defer lockman.ReleaseObject(ctx, self) - if self.BillingType == BILLING_TYPE_PREPAID { + if self.BillingType == billing_api.BILLING_TYPE_PREPAID { diff, err := db.Update(self, func() error { - self.BillingType = BILLING_TYPE_POSTPAID + self.BillingType = billing_api.BILLING_TYPE_POSTPAID self.ExpiredAt = time.Time{} return nil }) @@ -1831,8 +1834,8 @@ func (self *SGuest) syncRemoveCloudVM(ctx context.Context, userCred mcclient.Tok }) } - if self.Status != VM_UNKNOWN { - self.SetStatus(userCred, VM_UNKNOWN, "Sync lost") + if self.Status != api.VM_UNKNOWN { + self.SetStatus(userCred, api.VM_UNKNOWN, "Sync lost") } return nil @@ -1871,7 +1874,7 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token self.InstanceType = instanceType } - if extVM.GetHypervisor() == HYPERVISOR_AWS { + if extVM.GetHypervisor() == api.HYPERVISOR_AWS { sku, err := ServerSkuManager.FetchSkuByNameAndHypervisor(instanceType, extVM.GetHypervisor(), false) if err == nil { self.VmemSize = sku.MemorySizeMB @@ -1961,7 +1964,7 @@ func (manager *SGuestManager) newCloudVM(ctx context.Context, userCred mcclient. guest.InstanceType = instanceType } - if extVM.GetHypervisor() == HYPERVISOR_AWS { + if extVM.GetHypervisor() == api.HYPERVISOR_AWS { sku, err := ServerSkuManager.FetchSkuByNameAndHypervisor(instanceType, extVM.GetHypervisor(), false) if err == nil { guest.VmemSize = sku.MemorySizeMB @@ -1982,7 +1985,7 @@ func (manager *SGuestManager) newCloudVM(ctx context.Context, userCred mcclient. db.OpsLog.LogEvent(&guest, db.ACT_CREATE, guest.GetShortDesc(ctx), userCred) - if guest.Status == VM_RUNNING { + if guest.Status == api.VM_RUNNING { db.OpsLog.LogEvent(&guest, db.ACT_START, guest.GetShortDesc(ctx), userCred) } @@ -2594,7 +2597,7 @@ func (self *SGuest) createDiskOnStorage(ctx context.Context, userCred mcclient.T diskName := fmt.Sprintf("vdisk_%s_%d", self.Name, time.Now().UnixNano()) - billingType := BILLING_TYPE_POSTPAID + billingType := billing_api.BILLING_TYPE_POSTPAID billingCycle := "" if inheritBilling { billingType = self.BillingType @@ -2602,7 +2605,7 @@ func (self *SGuest) createDiskOnStorage(ctx context.Context, userCred mcclient.T } autoDelete := false - if storage.IsLocal() || billingType == BILLING_TYPE_PREPAID || isWithServerCreate { + if storage.IsLocal() || billingType == billing_api.BILLING_TYPE_PREPAID || isWithServerCreate { autoDelete = true } disk, err := storage.createDisk(diskName, diskConfig, userCred, self.ProjectId, autoDelete, self.IsSystem, @@ -2919,13 +2922,13 @@ func (self *SGuest) GetDeployConfigOnHost(ctx context.Context, userCred mcclient onFinish := "shutdown" if jsonutils.QueryBoolean(params, "auto_start", false) || jsonutils.QueryBoolean(params, "restart", false) { onFinish = "none" - } else if utils.IsInStringArray(self.Status, []string{VM_ADMIN}) { + } else if utils.IsInStringArray(self.Status, []string{api.VM_ADMIN}) { onFinish = "none" } config.Add(jsonutils.NewString(onFinish), "on_finish") - if deployAction == "create" && !utils.IsInStringArray(self.Hypervisor, []string{HYPERVISOR_KVM, HYPERVISOR_BAREMETAL, HYPERVISOR_CONTAINER, HYPERVISOR_ESXI, HYPERVISOR_XEN}) { + if deployAction == "create" && !utils.IsInStringArray(self.Hypervisor, []string{api.HYPERVISOR_KVM, api.HYPERVISOR_BAREMETAL, api.HYPERVISOR_CONTAINER, api.HYPERVISOR_ESXI, api.HYPERVISOR_XEN}) { nets, err := self.GetNetworks("") if err != nil || len(nets) == 0 { return nil, fmt.Errorf("failed to find network for guest %s: %s", self.Name, err) @@ -2935,10 +2938,10 @@ func (self *SGuest) GetDeployConfigOnHost(ctx context.Context, userCred mcclient registerVpcId := vpc.ExternalId externalVpcId := vpc.ExternalId switch self.Hypervisor { - case HYPERVISOR_ALIYUN, HYPERVISOR_HUAWEI: + case api.HYPERVISOR_ALIYUN, api.HYPERVISOR_HUAWEI: break - case HYPERVISOR_AWS: - loginUser := cloudinit.NewUser(VM_AWS_DEFAULT_LOGIN_USER) + case api.HYPERVISOR_AWS: + loginUser := cloudinit.NewUser(api.VM_AWS_DEFAULT_LOGIN_USER) loginUser.SudoPolicy(cloudinit.USER_SUDO_NOPASSWD) if pub, _ := config.GetString("public_key"); len(pub) > 0 { loginUser.SshKey(pub) @@ -2963,9 +2966,9 @@ func (self *SGuest) GetDeployConfigOnHost(ctx context.Context, userCred mcclient userdata := cloudconfig.UserDataBase64() config.Add(jsonutils.NewString(userdata), "user_data") - case HYPERVISOR_QCLOUD, HYPERVISOR_OPENSTACK: + case api.HYPERVISOR_QCLOUD, api.HYPERVISOR_OPENSTACK: registerVpcId = "normal" - case HYPERVISOR_AZURE: + case api.HYPERVISOR_AZURE: registerVpcId, externalVpcId = "normal", "normal" if strings.HasSuffix(host.Name, "-classic") { registerVpcId, externalVpcId = "classic", "classic" @@ -2977,7 +2980,7 @@ func (self *SGuest) GetDeployConfigOnHost(ctx context.Context, userCred mcclient if err != nil { return nil, fmt.Errorf("failed to get iregion for host %s error: %v", host.Name, err) } - if self.Hypervisor == HYPERVISOR_QCLOUD { //腾讯云目前仅支持shell,否则绑定秘钥会冲突失效 + if self.Hypervisor == api.HYPERVISOR_QCLOUD { //腾讯云目前仅支持shell,否则绑定秘钥会冲突失效 config.Add(jsonutils.NewString(cloudprovider.CLOUD_SHELL), "user_data_type") } secgroupIds := jsonutils.NewArray() @@ -3321,7 +3324,7 @@ func (manager *SGuestManager) GetSpecShouldCheckStatus(query *jsonutils.JSONDict func (self *SGuest) GetSpec(checkStatus bool) *jsonutils.JSONDict { if checkStatus { - if utils.IsInStringArray(self.Status, []string{VM_SCHEDULE_FAILED}) { + if utils.IsInStringArray(self.Status, []string{api.VM_SCHEDULE_FAILED}) { return nil } } @@ -3489,7 +3492,7 @@ func (self *SGuest) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { host := self.GetHost() spec := self.GetSpec(false) - if self.GetHypervisor() == HYPERVISOR_BAREMETAL { + if self.GetHypervisor() == api.HYPERVISOR_BAREMETAL { if host != nil { hostSpec := host.GetSpec(false) hostSpecIdent := HostManager.GetSpecIdent(hostSpec) @@ -3577,7 +3580,7 @@ func (self *SGuest) isAllDisksReady() bool { } for i := 0; i < len(disks); i += 1 { disk := disks[i].GetDisk() - if !(disk.isReady() || disk.Status == DISK_START_MIGRATE) { + if !(disk.isReady() || disk.Status == api.DISK_START_MIGRATE) { ready = false break } @@ -3675,7 +3678,7 @@ func (manager *SGuestManager) getExpiredPrepaidGuests() []SGuest { deadline := time.Now().Add(time.Duration(options.Options.PrepaidExpireCheckSeconds*-1) * time.Second) q := manager.Query() - q = q.Equals("billing_type", BILLING_TYPE_PREPAID).LT("expired_at", deadline).Limit(options.Options.ExpiredPrepaidMaxCleanBatchSize) + q = q.Equals("billing_type", billing_api.BILLING_TYPE_PREPAID).LT("expired_at", deadline).Limit(options.Options.ExpiredPrepaidMaxCleanBatchSize) guests := make([]SGuest, 0) err := db.FetchModelObjects(GuestManager, q, &guests) @@ -3910,7 +3913,7 @@ func (self *SGuest) DeleteEip(ctx context.Context, userCred mcclient.TokenCreden if eip == nil { return nil } - if eip.Mode == EIP_MODE_INSTANCE_PUBLICIP { + if eip.Mode == api.EIP_MODE_INSTANCE_PUBLICIP { err = eip.RealDelete(ctx, userCred) if err != nil { log.Errorf("Delete eip on delete server fail %s", err) @@ -3951,11 +3954,11 @@ func (self *SGuest) getDefaultStorageType() string { return rootStorage.StorageType } } - return STORAGE_LOCAL + return api.STORAGE_LOCAL } func (self *SGuest) GetApptags() []string { - tagsStr := self.GetMetadata(VM_METADATA_APP_TAGS, nil) + tagsStr := self.GetMetadata(api.VM_METADATA_APP_TAGS, nil) if len(tagsStr) > 0 { return strings.Split(tagsStr, ",") } diff --git a/pkg/compute/models/helper.go b/pkg/compute/models/helper.go index a01082747a..a548d14c80 100644 --- a/pkg/compute/models/helper.go +++ b/pkg/compute/models/helper.go @@ -57,11 +57,11 @@ func ValidateScheduleCreateData(ctx context.Context, userCred mcclient.TokenCred var err error if input.Baremetal { - hypervisor = HYPERVISOR_BAREMETAL + hypervisor = api.HYPERVISOR_BAREMETAL } // base validate_create_data - if (input.PreferHost != "") && hypervisor != HYPERVISOR_CONTAINER { + if (input.PreferHost != "") && hypervisor != api.HYPERVISOR_CONTAINER { if !userCred.IsAdminAllow(consts.GetServiceType(), GuestManager.KeywordPlural(), policy.PolicyActionPerform, "assign-host") { return nil, httperrors.NewNotSufficientPrivilegeError("Only system admin can specify preferred host") @@ -80,16 +80,16 @@ func ValidateScheduleCreateData(ctx context.Context, userCred mcclient.TokenCred return nil, httperrors.NewInvalidStatusError("Baremetal %s not enabled", bmName) } - if len(hypervisor) > 0 && hypervisor != HOSTTYPE_HYPERVISOR[baremetal.HostType] { + if len(hypervisor) > 0 && hypervisor != api.HOSTTYPE_HYPERVISOR[baremetal.HostType] { return nil, httperrors.NewInputParameterError("cannot run hypervisor %s on specified host with type %s", hypervisor, baremetal.HostType) } if len(hypervisor) == 0 { - hypervisor = HOSTTYPE_HYPERVISOR[baremetal.HostType] + hypervisor = api.HOSTTYPE_HYPERVISOR[baremetal.HostType] } if len(hypervisor) == 0 { - hypervisor = HYPERVISOR_DEFAULT + hypervisor = api.HYPERVISOR_DEFAULT } _, err = GetDriver(hypervisor).ValidateCreateDataOnHost(ctx, userCred, bmName, baremetal, input) @@ -172,10 +172,10 @@ func ValidateScheduleCreateData(ctx context.Context, userCred mcclient.TokenCred // default hypervisor if len(hypervisor) == 0 { - hypervisor = HYPERVISOR_KVM + hypervisor = api.HYPERVISOR_KVM } - if !utils.IsInStringArray(hypervisor, HYPERVISORS) { + if !utils.IsInStringArray(hypervisor, api.HYPERVISORS) { return nil, httperrors.NewInputParameterError("Hypervisor %s not supported", hypervisor) } diff --git a/pkg/compute/models/host_recycle.go b/pkg/compute/models/host_recycle.go index 0c3ee627ab..b6cb5817c4 100644 --- a/pkg/compute/models/host_recycle.go +++ b/pkg/compute/models/host_recycle.go @@ -27,6 +27,7 @@ import ( "yunion.io/x/pkg/tristate" "yunion.io/x/sqlchemy" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" @@ -43,7 +44,7 @@ func (self *SHost) GetResourceType() string { if len(self.ResourceType) > 0 { return self.ResourceType } - return HostResourceTypeDefault + return api.HostResourceTypeDefault } func (self *SGuest) AllowPerformPrepaidRecycle(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { @@ -51,7 +52,7 @@ func (self *SGuest) AllowPerformPrepaidRecycle(ctx context.Context, userCred mcc } func (self *SGuest) CanPerformPrepaidRecycle() error { - if self.BillingType != BILLING_TYPE_PREPAID { + if self.BillingType != billing_api.BILLING_TYPE_PREPAID { return fmt.Errorf("recycle prepaid server only") } if self.ExpiredAt.Before(time.Now()) { @@ -68,7 +69,7 @@ func (self *SGuest) CanPerformPrepaidRecycle() error { } func (self *SGuest) PerformPrepaidRecycle(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !self.IsInStatus(VM_READY, VM_RUNNING) { + if !self.IsInStatus(api.VM_READY, api.VM_RUNNING) { return nil, httperrors.NewInvalidStatusError("cannot recycle in status %s", self.Status) } err := self.CanPerformPrepaidRecycle() @@ -137,7 +138,7 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien info.Index = int64(i) info.Slot = i info.Driver = baremetal.DISK_DRIVER_LINUX - info.Rotate = (storage.MediumType != DISK_TYPE_SSD) + info.Rotate = (storage.MediumType != api.DISK_TYPE_SSD) storageInfo = append(storageInfo, info) } @@ -149,7 +150,7 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien fakeHost.ZoneId = self.getZone().GetId() fakeHost.IsBaremetal = false fakeHost.IsMaintenance = false - fakeHost.ResourceType = HostResourceTypePrepaidRecycle + fakeHost.ResourceType = api.HostResourceTypePrepaidRecycle guestnics, err := self.GetNetworks("") if err != nil || len(guestnics) == 0 { @@ -160,12 +161,12 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien fakeHost.AccessIp = guestnics[0].IpAddr fakeHost.AccessMac = guestnics[0].MacAddr - fakeHost.BillingType = BILLING_TYPE_PREPAID + fakeHost.BillingType = billing_api.BILLING_TYPE_PREPAID fakeHost.BillingCycle = self.BillingCycle fakeHost.ExpiredAt = self.ExpiredAt - fakeHost.Status = HOST_STATUS_RUNNING - fakeHost.HostStatus = HOST_ONLINE + fakeHost.Status = api.HOST_STATUS_RUNNING + fakeHost.HostStatus = api.HOST_ONLINE fakeHost.Enabled = true fakeHost.HostType = oHost.HostType fakeHost.ExternalId = oHost.ExternalId @@ -183,7 +184,7 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien for i := 0; i < len(guestnics); i += 1 { var nicType string if i == 0 { - nicType = NIC_TYPE_ADMIN + nicType = api.NIC_TYPE_ADMIN } err = fakeHost.addNetif(ctx, userCred, guestnics[i].MacAddr, @@ -211,7 +212,7 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien for i := 0; i < len(guestdisks); i += 1 { disk := guestdisks[i].GetDisk() storage := disk.GetStorage() - if disk.BillingType == BILLING_TYPE_PREPAID { + if disk.BillingType == billing_api.BILLING_TYPE_PREPAID { storageSize += disk.DiskSize if len(externalId) == 0 { externalId = storage.ExternalId @@ -233,13 +234,13 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien fakeStorage.Name = fmt.Sprintf("%s-storage", self.Name) fakeStorage.Capacity = storageSize - fakeStorage.StorageType = STORAGE_LOCAL + fakeStorage.StorageType = api.STORAGE_LOCAL fakeStorage.MediumType = sysStorage.MediumType fakeStorage.Cmtbound = 1.0 fakeStorage.ZoneId = fakeHost.ZoneId fakeStorage.StoragecacheId = sysStorage.StoragecacheId fakeStorage.Enabled = true - fakeStorage.Status = STORAGE_ONLINE + fakeStorage.Status = api.STORAGE_ONLINE fakeStorage.Description = "fake storage for prepaid vm recycling" fakeStorage.IsEmulated = true fakeStorage.ManagerId = sysStorage.ManagerId @@ -261,7 +262,7 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien _, err = db.Update(self, func() error { // clear billing information - self.BillingType = BILLING_TYPE_POSTPAID + self.BillingType = billing_api.BILLING_TYPE_POSTPAID self.BillingCycle = "" self.ExpiredAt = time.Time{} // switch to fakeHost @@ -277,9 +278,9 @@ func (self *SGuest) doPrepaidRecycleNoLock(ctx context.Context, userCred mcclien for i := 0; i < len(guestdisks); i += 1 { disk := guestdisks[i].GetDisk() - if disk.BillingType == BILLING_TYPE_PREPAID { + if disk.BillingType == billing_api.BILLING_TYPE_PREPAID { _, err = db.Update(disk, func() error { - disk.BillingType = BILLING_TYPE_POSTPAID + disk.BillingType = billing_api.BILLING_TYPE_POSTPAID disk.BillingCycle = "" disk.ExpiredAt = time.Time{} disk.StorageId = fakeStorage.Id @@ -301,7 +302,7 @@ func (self *SGuest) AllowPerformUndoPrepaidRecycle(ctx context.Context, userCred } func (self *SGuest) PerformUndoPrepaidRecycle(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !self.IsInStatus(VM_READY, VM_RUNNING) { + if !self.IsInStatus(api.VM_READY, api.VM_RUNNING) { return nil, httperrors.NewInvalidStatusError("cannot undo recycle in status %s", self.Status) } @@ -315,7 +316,7 @@ func (self *SGuest) PerformUndoPrepaidRecycle(ctx context.Context, userCred mccl return nil, httperrors.NewInvalidStatusError("host should be disabled") } - if host.ResourceType != HostResourceTypePrepaidRecycle || host.BillingType != BILLING_TYPE_PREPAID { + if host.ResourceType != api.HostResourceTypePrepaidRecycle || host.BillingType != billing_api.BILLING_TYPE_PREPAID { return nil, httperrors.NewInvalidStatusError("host is not a prepaid recycle host") } @@ -340,7 +341,7 @@ func (self *SHost) PerformUndoPrepaidRecycle(ctx context.Context, userCred mccli return nil, httperrors.NewInvalidStatusError("host should be disabled") } - if self.ResourceType != HostResourceTypePrepaidRecycle || self.BillingType != BILLING_TYPE_PREPAID { + if self.ResourceType != api.HostResourceTypePrepaidRecycle || self.BillingType != billing_api.BILLING_TYPE_PREPAID { return nil, httperrors.NewInvalidStatusError("host is not a prepaid recycle host") } @@ -354,7 +355,7 @@ func (self *SHost) PerformUndoPrepaidRecycle(ctx context.Context, userCred mccli return nil, httperrors.NewInvalidStatusError("a recycle host shoud not allocate more than 1 guest") } - if !guests[0].IsInStatus(VM_READY, VM_RUNNING) { + if !guests[0].IsInStatus(api.VM_READY, api.VM_RUNNING) { return nil, httperrors.NewInvalidStatusError("cannot undo recycle in status %s", guests[0].Status) } @@ -409,7 +410,7 @@ func doUndoPrepaidRecycleNoLock(ctx context.Context, userCred mcclient.TokenCred q = q.Equals("host_type", host.HostType) q = q.Filter(sqlchemy.OR( sqlchemy.IsNullOrEmpty(q.Field("resource_type")), - sqlchemy.Equals(q.Field("resource_type"), HostResourceTypeShared), + sqlchemy.Equals(q.Field("resource_type"), api.HostResourceTypeShared), )) oHostCnt := q.Count() @@ -441,7 +442,7 @@ func doUndoPrepaidRecycleNoLock(ctx context.Context, userCred mcclient.TokenCred for i := 0; i < len(guestdisks); i += 1 { disk := guestdisks[i].GetDisk() storage := disk.GetStorage() - if storage.StorageType == STORAGE_LOCAL { + if storage.StorageType == api.STORAGE_LOCAL { oHostStorage := oHost.GetHoststorageByExternalId(storage.ExternalId) if oHostStorage == nil { msg := fmt.Sprintf("oHost.GetHoststorageByExternalId not found %s", storage.ExternalId) @@ -454,7 +455,7 @@ func doUndoPrepaidRecycleNoLock(ctx context.Context, userCred mcclient.TokenCred // check passed, do convert _, err = db.Update(server, func() error { // recover billing information - server.BillingType = BILLING_TYPE_PREPAID + server.BillingType = billing_api.BILLING_TYPE_PREPAID server.BillingCycle = host.BillingCycle server.ExpiredAt = host.ExpiredAt // switch to original Host @@ -470,7 +471,7 @@ func doUndoPrepaidRecycleNoLock(ctx context.Context, userCred mcclient.TokenCred disk := guestdisks[i].GetDisk() storage := disk.GetStorage() - if storage.StorageType == STORAGE_LOCAL { + if storage.StorageType == api.STORAGE_LOCAL { oHostStorage := oHost.GetHoststorageByExternalId(storage.ExternalId) if oHostStorage == nil { msg := fmt.Sprintf("oHost.GetHoststorageByExternalId not found %s", storage.ExternalId) @@ -479,7 +480,7 @@ func doUndoPrepaidRecycleNoLock(ctx context.Context, userCred mcclient.TokenCred } oStorage := oHostStorage.GetStorage() _, err = db.Update(disk, func() error { - disk.BillingType = BILLING_TYPE_PREPAID + disk.BillingType = billing_api.BILLING_TYPE_PREPAID disk.BillingCycle = host.BillingCycle disk.ExpiredAt = host.ExpiredAt disk.StorageId = oStorage.Id @@ -512,10 +513,10 @@ func (self *SGuest) IsPrepaidRecycle() bool { } func (host *SHost) IsPrepaidRecycle() bool { - if host.ResourceType != HostResourceTypePrepaidRecycle { + if host.ResourceType != api.HostResourceTypePrepaidRecycle { return false } - if host.BillingType != BILLING_TYPE_PREPAID { + if host.BillingType != billing_api.BILLING_TYPE_PREPAID { return false } return true @@ -605,12 +606,12 @@ func (host *SHost) SetGuestCreateNetworkAndDiskParams(ctx context.Context, userC return nil, err } diskConfig.SizeMb = idisks[i].GetDiskSizeMB() - diskConfig.Backend = STORAGE_LOCAL + diskConfig.Backend = api.STORAGE_LOCAL input.Disks[i] = diskConfig } else { conf := &api.DiskConfig{ SizeMb: idisks[i].GetDiskSizeMB(), - Backend: STORAGE_LOCAL, + Backend: api.STORAGE_LOCAL, } conf, err = parseDiskInfo(ctx, userCred, conf) if err != nil { @@ -634,7 +635,7 @@ func (host *SHost) RebuildRecycledGuest(ctx context.Context, userCred mcclient.T q = q.Equals("external_id", host.ExternalId) q = q.Filter(sqlchemy.OR( sqlchemy.IsNullOrEmpty(q.Field("resource_type")), - sqlchemy.Equals(q.Field("resource_type"), HostResourceTypeShared), + sqlchemy.Equals(q.Field("resource_type"), api.HostResourceTypeShared), )) err := q.First(&oHost) @@ -731,7 +732,7 @@ func (self *SHost) PerformRenewPrepaidRecycle(ctx context.Context, userCred mccl return nil, httperrors.NewInputParameterError("invalid duration %s: %s", durationStr, err) } - if !GetDriver(HOSTTYPE_HYPERVISOR[self.HostType]).IsSupportedBillingCycle(bc) { + if !GetDriver(api.HOSTTYPE_HYPERVISOR[self.HostType]).IsSupportedBillingCycle(bc) { return nil, httperrors.NewInputParameterError("unsupported duration %s", durationStr) } @@ -757,8 +758,8 @@ func (self *SHost) startPrepaidRecycleHostRenewTask(ctx context.Context, userCre func (self *SHost) DoSaveRenewInfo(ctx context.Context, userCred mcclient.TokenCredential, bc *billing.SBillingCycle, expireAt *time.Time) error { _, err := db.Update(self, func() error { - if self.BillingType != BILLING_TYPE_PREPAID { - self.BillingType = BILLING_TYPE_PREPAID + if self.BillingType != billing_api.BILLING_TYPE_PREPAID { + self.BillingType = billing_api.BILLING_TYPE_PREPAID } if expireAt != nil && !expireAt.IsZero() { self.ExpiredAt = *expireAt diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 366376d9be..93b328b1f3 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -35,6 +35,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/cloudcommon/db" @@ -51,6 +52,7 @@ import ( "yunion.io/x/onecloud/pkg/util/logclient" ) +/* const ( HOST_TYPE_BAREMETAL = api.HOST_TYPE_BAREMETAL HOST_TYPE_HYPERVISOR = api.HOST_TYPE_HYPERVISOR // KVM @@ -115,6 +117,8 @@ var HOST_TYPES = api.HOST_TYPES var NIC_TYPES = api.NIC_TYPES +*/ + type SHostManager struct { db.SEnabledStatusStandaloneResourceBaseManager } @@ -226,11 +230,11 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu queryDict.Remove("resource_type") switch resType { - case HostResourceTypeShared: + case api.HostResourceTypeShared: q = q.Filter( sqlchemy.OR( sqlchemy.IsNullOrEmpty(q.Field("resource_type")), - sqlchemy.Equals(q.Field("resource_type"), HostResourceTypeShared), + sqlchemy.Equals(q.Field("resource_type"), api.HostResourceTypeShared), ), ) default: @@ -368,14 +372,14 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu hostQ1 = hostQ1.Filter(sqlchemy.IsTrue(providers.Field("enabled"))) hostQ1 = hostQ1.Filter(sqlchemy.In(providers.Field("status"), api.CLOUD_PROVIDER_VALID_STATUS)) hostQ1 = hostQ1.Filter(sqlchemy.Equals(providers.Field("health_status"), api.CLOUD_PROVIDER_HEALTH_NORMAL)) - hostQ1 = hostQ1.Filter(sqlchemy.Equals(networks.Field("status"), NETWORK_STATUS_AVAILABLE)) + hostQ1 = hostQ1.Filter(sqlchemy.Equals(networks.Field("status"), api.NETWORK_STATUS_AVAILABLE)) hostQ1 = hostQ1.Filter(sqlchemy.IsTrue(hosts.Field("enabled"))) hostQ2 := hosts.Query(hosts.Field("id")) hostQ2 = hostQ2.Join(hostwires, sqlchemy.Equals(hosts.Field("id"), hostwires.Field("host_id"))) hostQ2 = hostQ2.Join(networks, sqlchemy.Equals(hostwires.Field("wire_id"), networks.Field("wire_id"))) hostQ2 = hostQ2.Filter(sqlchemy.IsNullOrEmpty(hosts.Field("manager_id"))) - hostQ2 = hostQ2.Filter(sqlchemy.Equals(networks.Field("status"), NETWORK_STATUS_AVAILABLE)) + hostQ2 = hostQ2.Filter(sqlchemy.Equals(networks.Field("status"), api.NETWORK_STATUS_AVAILABLE)) hostQ2 = hostQ2.Filter(sqlchemy.IsTrue(hosts.Field("enabled"))) q = q.Filter(sqlchemy.OR( @@ -397,9 +401,9 @@ func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu if query.Contains("baremetal") { isBaremetal := jsonutils.QueryBoolean(query, "baremetal", false) if isBaremetal { - q = q.Equals("host_type", HOST_TYPE_BAREMETAL) + q = q.Equals("host_type", api.HOST_TYPE_BAREMETAL) } else { - q = q.NotEquals("host_type", HOST_TYPE_BAREMETAL) + q = q.NotEquals("host_type", api.HOST_TYPE_BAREMETAL) } } @@ -492,7 +496,7 @@ func (self *SHost) ValidatePurgeCondition(ctx context.Context) error { } func (self *SHost) validateDeleteCondition(ctx context.Context, purge bool) error { - if !purge && self.IsBaremetal && self.HostType != HOST_TYPE_BAREMETAL { + if !purge && self.IsBaremetal && self.HostType != api.HOST_TYPE_BAREMETAL { return httperrors.NewInvalidStatusError("Host is a converted baremetal, should be unconverted before delete") } if self.Enabled { @@ -643,7 +647,7 @@ func (self *SHost) GetBaremetalstorage() *SHoststorage { q := hoststorages.Query() q = q.Join(storages, sqlchemy.AND(sqlchemy.Equals(storages.Field("id"), hoststorages.Field("storage_id")), sqlchemy.IsFalse(storages.Field("deleted")))) - q = q.Filter(sqlchemy.Equals(storages.Field("storage_type"), STORAGE_BAREMETAL)) + q = q.Filter(sqlchemy.Equals(storages.Field("storage_type"), api.STORAGE_BAREMETAL)) q = q.Filter(sqlchemy.Equals(hoststorages.Field("host_id"), self.Id)) if q.Count() == 1 { hs := SHoststorage{} @@ -701,10 +705,10 @@ func (self *SHost) PerformUpdateStorage( storage := SStorage{} storage.Name = fmt.Sprintf("storage%s", self.GetName()) storage.Capacity = int(capacity) - storage.StorageType = STORAGE_BAREMETAL + storage.StorageType = api.STORAGE_BAREMETAL storage.MediumType = self.StorageType storage.Cmtbound = 1.0 - storage.Status = STORAGE_ONLINE + storage.Status = api.STORAGE_ONLINE storage.ZoneId = zoneId err := StorageManager.TableSpec().Insert(&storage) if err != nil { @@ -774,9 +778,9 @@ func (self *SHost) _getAttachedStorages(isBaremetal tristate.TriState, enabled t q = q.IsFalse("enabled") } if isBaremetal.IsTrue() { - q = q.Equals("storage_type", STORAGE_BAREMETAL) + q = q.Equals("storage_type", api.STORAGE_BAREMETAL) } else if isBaremetal.IsFalse() { - q = q.NotEquals("storage_type", STORAGE_BAREMETAL) + q = q.NotEquals("storage_type", api.STORAGE_BAREMETAL) } if len(storageType) > 0 { q = q.Equals("storage_type", storageType) @@ -867,14 +871,14 @@ func (self *SHost) GetSpec(statusCheck bool) *jsonutils.JSONDict { if !self.Enabled { return nil } - if utils.IsInStringArray(self.Status, []string{BAREMETAL_INIT, BAREMETAL_PREPARE_FAIL, BAREMETAL_PREPARE}) || + if utils.IsInStringArray(self.Status, []string{api.BAREMETAL_INIT, api.BAREMETAL_PREPARE_FAIL, api.BAREMETAL_PREPARE}) || self.GetBaremetalServer() != nil { return nil } if self.MemSize == 0 || self.CpuCount == 0 { return nil } - if self.ResourceType == HostResourceTypePrepaidRecycle && self.GetGuestCount() > 0 { + if self.ResourceType == api.HostResourceTypePrepaidRecycle && self.GetGuestCount() > 0 { return nil } @@ -894,7 +898,7 @@ func (self *SHost) GetSpec(statusCheck bool) *jsonutils.JSONDict { nifs := self.GetNetInterfaces() var nicCount int64 for _, nif := range nifs { - if nif.NicType != NIC_TYPE_IPMI { + if nif.NicType != api.NIC_TYPE_IPMI { nicCount++ } } @@ -1062,8 +1066,8 @@ func _getLeastUsedStorage(storages []SStorage, backends []string) *SStorage { func getLeastUsedStorage(storages []SStorage, backend string) *SStorage { var backends []string - if backend == STORAGE_LOCAL { - backends = []string{STORAGE_NAS, STORAGE_LOCAL} + if backend == api.STORAGE_LOCAL { + backends = []string{api.STORAGE_NAS, api.STORAGE_LOCAL} } else if len(backend) > 0 { backends = []string{backend} } else { @@ -1195,7 +1199,7 @@ func (self *SHost) GetGuestCount() int { func (self *SHost) GetContainerCount(status []string) int { q := self.GetGuestsQuery() - q = q.Filter(sqlchemy.Equals(q.Field("hypervisor"), HYPERVISOR_CONTAINER)) + q = q.Filter(sqlchemy.Equals(q.Field("hypervisor"), api.HYPERVISOR_CONTAINER)) if len(status) > 0 { q = q.In("status", status) } @@ -1210,7 +1214,7 @@ func (self *SHost) GetNonsystemGuestCount() int { func (self *SHost) GetRunningGuestCount() int { q := self.GetGuestsQuery() - q = q.In("status", VM_RUNNING_STATUS) + q = q.In("status", api.VM_RUNNING_STATUS) return q.Count() } @@ -1262,7 +1266,7 @@ func (self *SHost) GetAdminNetInterface() *SNetInterface { netif := SNetInterface{} netif.SetModelManager(NetInterfaceManager) - q := NetInterfaceManager.Query().Equals("baremetal_id", self.Id).Equals("nic_type", NIC_TYPE_ADMIN) + q := NetInterfaceManager.Query().Equals("baremetal_id", self.Id).Equals("nic_type", api.NIC_TYPE_ADMIN) err := q.First(&netif) if err != nil { log.Errorf("GetAdminNetInterface fail %s", err) @@ -1289,7 +1293,7 @@ func (self *SHost) DeleteBaremetalnetwork(ctx context.Context, userCred mcclient } func (self *SHost) GetHostDriver() IHostDriver { - if !utils.IsInStringArray(self.HostType, HOST_TYPES) { + if !utils.IsInStringArray(self.HostType, api.HOST_TYPES) { log.Fatalf("Unsupported host type %s", self.HostType) } return GetHostDriver(self.HostType) @@ -1305,7 +1309,7 @@ func (manager *SHostManager) getHostsByZoneProvider(zone *SZone, provider *SClou q = q.Equals("manager_id", provider.Id) } // exclude prepaid_recycle fake hosts - q = q.NotEquals("resource_type", HostResourceTypePrepaidRecycle) + q = q.NotEquals("resource_type", api.HostResourceTypePrepaidRecycle) err := db.FetchModelObjects(manager, q, &hosts) if err != nil { @@ -1381,7 +1385,7 @@ func (self *SHost) syncRemoveCloudHost(ctx context.Context, userCred mcclient.To err := self.ValidatePurgeCondition(ctx) if err != nil { - err = self.SetStatus(userCred, HOST_OFFLINE, "sync to delete") + err = self.SetStatus(userCred, api.HOST_OFFLINE, "sync to delete") if err == nil { _, err = self.PerformDisable(ctx, userCred, nil, nil) } @@ -1822,7 +1826,7 @@ func (self *SHost) SyncHostVMs(ctx context.Context, userCred mcclient.TokenCrede } for i := 0; i < len(added); i += 1 { - if added[i].GetBillingType() == BILLING_TYPE_PREPAID { + if added[i].GetBillingType() == billing_api.BILLING_TYPE_PREPAID { vhost := HostManager.GetHostByRealExternalId(added[i].GetGlobalId()) if vhost != nil { // this recycle vm is not build yet, skip synchronize @@ -2134,7 +2138,7 @@ func (self *SHost) GetBaremetalServer() *SGuest { } guest := SGuest{} guest.SetModelManager(GuestManager) - q := GuestManager.Query().Equals("host_id", self.Id).Equals("hypervisor", HOST_TYPE_BAREMETAL) + q := GuestManager.Query().Equals("host_id", self.Id).Equals("hypervisor", api.HOST_TYPE_BAREMETAL) err := q.First(&guest) if err != nil { if err != sql.ErrNoRows { @@ -2197,7 +2201,7 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict if server != nil { extra.Add(jsonutils.NewString(server.Id), "server_id") extra.Add(jsonutils.NewString(server.Name), "server") - if self.HostType == HOST_TYPE_BAREMETAL { + if self.HostType == api.HOST_TYPE_BAREMETAL { extra.Add(jsonutils.NewString(strings.Join(server.GetRealIPs(), ",")), "server_ips") } } @@ -2218,7 +2222,7 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict extra = GetSchedtagsDetailsToResource(self, ctx, extra) var usage *SHostGuestResourceUsage if options.Options.IgnoreNonrunningGuests { - usage = self.getGuestsResource(VM_RUNNING) + usage = self.getGuestsResource(api.VM_RUNNING) } else { usage = self.getGuestsResource("") } @@ -2227,7 +2231,7 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict extra.Add(jsonutils.NewInt(int64(usage.GuestVmemSize)), "mem_commit") } containerCount := self.GetContainerCount(nil) - runningContainerCount := self.GetContainerCount(VM_RUNNING_STATUS) + runningContainerCount := self.GetContainerCount(api.VM_RUNNING_STATUS) extra.Add(jsonutils.NewInt(int64(self.GetGuestCount()-containerCount)), "guests") extra.Add(jsonutils.NewInt(int64(self.GetNonsystemGuestCount()-containerCount)), "nonsystem_guests") extra.Add(jsonutils.NewInt(int64(self.GetRunningGuestCount()-runningContainerCount)), "running_guests") @@ -2281,7 +2285,7 @@ func (self *SHost) AllowGetDetailsVnc(ctx context.Context, userCred mcclient.Tok } func (self *SHost) GetDetailsVnc(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if utils.IsInStringArray(self.Status, []string{BAREMETAL_READY, BAREMETAL_RUNNING}) { + 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() @@ -2349,7 +2353,7 @@ func (self *SHost) Request(ctx context.Context, userCred mcclient.TokenCredentia } func (self *SHost) GetLocalStoragecache() *SStoragecache { - localStorages := self.GetAttachedStorages(STORAGE_LOCAL) + localStorages := self.GetAttachedStorages(api.STORAGE_LOCAL) for i := 0; i < len(localStorages); i += 1 { sc := localStorages[i].GetStoragecache() if sc != nil { @@ -2446,7 +2450,7 @@ func (manager *SHostManager) ValidateCreateData(ctx context.Context, userCred mc memReserved, err := data.Int("mem_reserved") if err != nil { hostType, _ := data.GetString("host_type") - if hostType != HOST_TYPE_BAREMETAL { + if hostType != api.HOST_TYPE_BAREMETAL { memSize, _ := data.Int("mem_size") memReserved = memSize / 8 if memReserved > 4096 { @@ -2549,9 +2553,9 @@ func (self *SHost) UpdateDnsRecord(netif *SNetInterface, isAdd bool) { } func (self *SHost) GetNetifName(netif *SNetInterface) string { - if netif.NicType == NIC_TYPE_IPMI { + if netif.NicType == api.NIC_TYPE_IPMI { return self.GetName() - } else if netif.NicType == NIC_TYPE_ADMIN { + } else if netif.NicType == api.NIC_TYPE_ADMIN { return self.GetName() + "-admin" } return "" @@ -2599,18 +2603,18 @@ func (self *SHost) PerformStart(ctx context.Context, userCred mcclient.TokenCred if !self.IsBaremetal { return nil, httperrors.NewBadRequestError("Cannot start a non-baremetal host") } - if !utils.IsInStringArray(self.Status, []string{BAREMETAL_READY}) { + if !utils.IsInStringArray(self.Status, []string{api.BAREMETAL_READY}) { return nil, httperrors.NewInvalidStatusError("Cannot start baremetal with active guest") } guest := self.GetBaremetalServer() if guest != nil { - if self.HostType == HOST_TYPE_BAREMETAL && utils.ToBool(guest.GetMetadata("is_fake_baremetal_server", userCred)) { + if self.HostType == api.HOST_TYPE_BAREMETAL && utils.ToBool(guest.GetMetadata("is_fake_baremetal_server", userCred)) { return nil, self.InitializedGuestStart(ctx, userCred, guest) } // if !utils.IsInStringArray(guest.Status, []string{VM_ADMIN}) { // return nil, httperrors.NewBadRequestError("Cannot start baremetal with active guest") // } - self.SetStatus(userCred, BAREMETAL_START_MAINTAIN, "") + self.SetStatus(userCred, api.BAREMETAL_START_MAINTAIN, "") return guest.PerformStart(ctx, userCred, query, data) } params := jsonutils.NewDict() @@ -2631,20 +2635,20 @@ func (self *SHost) PerformStop(ctx context.Context, userCred mcclient.TokenCrede if !self.IsBaremetal { return nil, httperrors.NewBadRequestError("Cannot stop a non-baremetal host") } - if !utils.IsInStringArray(self.Status, []string{BAREMETAL_RUNNING}) { + if !utils.IsInStringArray(self.Status, []string{api.BAREMETAL_RUNNING}) { return nil, httperrors.NewInvalidStatusError("Cannot stop baremetal with non-active guest") } guest := self.GetBaremetalServer() if guest != nil { - if self.HostType != HOST_TYPE_BAREMETAL { - if !utils.IsInStringArray(guest.Status, []string{VM_ADMIN}) { + if self.HostType != api.HOST_TYPE_BAREMETAL { + if !utils.IsInStringArray(guest.Status, []string{api.VM_ADMIN}) { return nil, httperrors.NewBadRequestError("Cannot stop baremetal with active guest") } } else { if utils.ToBool(guest.GetMetadata("is_fake_baremetal_server", userCred)) { return nil, self.InitializedGuestStop(ctx, userCred, guest) } - self.SetStatus(userCred, BAREMETAL_START_MAINTAIN, "") + self.SetStatus(userCred, api.BAREMETAL_START_MAINTAIN, "") return guest.PerformStop(ctx, userCred, query, data) } } @@ -2678,21 +2682,21 @@ func (self *SHost) AllowPerformMaintenance(ctx context.Context, } func (self *SHost) PerformMaintenance(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !utils.IsInStringArray(self.Status, []string{BAREMETAL_READY, BAREMETAL_RUNNING}) { + if !utils.IsInStringArray(self.Status, []string{api.BAREMETAL_READY, api.BAREMETAL_RUNNING}) { return nil, httperrors.NewInvalidStatusError("Cannot do maintenance in status %s", self.Status) } guest := self.GetBaremetalServer() - if guest != nil && !utils.IsInStringArray(guest.Status, []string{VM_READY, VM_RUNNING, VM_ADMIN}) { + if guest != nil && !utils.IsInStringArray(guest.Status, []string{api.VM_READY, api.VM_RUNNING, api.VM_ADMIN}) { return nil, httperrors.NewInvalidStatusError("Cannot do maintenance while guest status %s", guest.Status) } params := jsonutils.NewDict() if guest != nil { - if guest.Status == VM_RUNNING { + if guest.Status == api.VM_RUNNING { params.Set("guest_running", jsonutils.NewBool(true)) } - guest.SetStatus(userCred, VM_ADMIN, "") + guest.SetStatus(userCred, api.VM_ADMIN, "") } - if self.Status == BAREMETAL_RUNNING && jsonutils.QueryBoolean(data, "force_reboot", false) { + if self.Status == api.BAREMETAL_RUNNING && jsonutils.QueryBoolean(data, "force_reboot", false) { params.Set("force_reboot", jsonutils.NewBool(true)) } action := "maintenance" @@ -2700,7 +2704,7 @@ func (self *SHost) PerformMaintenance(ctx context.Context, userCred mcclient.Tok action, _ = data.GetString("action") } params.Set("action", jsonutils.NewString(action)) - self.SetStatus(userCred, BAREMETAL_START_MAINTAIN, "") + self.SetStatus(userCred, api.BAREMETAL_START_MAINTAIN, "") task, err := taskman.TaskManager.NewTask(ctx, "BaremetalMaintenanceTask", self, userCred, params, "", "", nil) if err != nil { return nil, err @@ -2717,11 +2721,11 @@ func (self *SHost) AllowPerformUnmaintenance(ctx context.Context, } func (self *SHost) PerformUnmaintenance(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if !utils.IsInStringArray(self.Status, []string{BAREMETAL_RUNNING, BAREMETAL_READY}) { + if !utils.IsInStringArray(self.Status, []string{api.BAREMETAL_RUNNING, api.BAREMETAL_READY}) { return nil, httperrors.NewInvalidStatusError("Cannot do unmaintenance in status %s", self.Status) } guest := self.GetBaremetalServer() - if guest != nil && guest.Status != VM_ADMIN { + if guest != nil && guest.Status != api.VM_ADMIN { return nil, httperrors.NewInvalidStatusError("Wrong guest status %s", guest.Status) } action, _ := data.GetString("action") @@ -2737,7 +2741,7 @@ func (self *SHost) PerformUnmaintenance(ctx context.Context, userCred mcclient.T } func (self *SHost) StartBaremetalUnmaintenanceTask(ctx context.Context, userCred mcclient.TokenCredential, startGuest bool, action string) error { - self.SetStatus(userCred, BAREMETAL_START_MAINTAIN, "") + self.SetStatus(userCred, api.BAREMETAL_START_MAINTAIN, "") params := jsonutils.NewDict() params.Set("guest_running", jsonutils.NewBool(startGuest)) if len(action) == 0 { @@ -2773,9 +2777,9 @@ func (self *SHost) AllowPerformOffline(ctx context.Context, } func (self *SHost) PerformOffline(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.HostStatus != HOST_OFFLINE { + if self.HostStatus != api.HOST_OFFLINE { _, err := self.SaveUpdates(func() error { - self.HostStatus = HOST_OFFLINE + self.HostStatus = api.HOST_OFFLINE return nil }) if err != nil { @@ -2796,11 +2800,11 @@ func (self *SHost) AllowPerformOnline(ctx context.Context, } func (self *SHost) PerformOnline(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.HostStatus != HOST_ONLINE { + if self.HostStatus != api.HOST_ONLINE { _, err := self.SaveUpdates(func() error { self.LastPingAt = time.Now() - self.HostStatus = HOST_ONLINE - self.Status = BAREMETAL_RUNNING + self.HostStatus = api.HOST_ONLINE + self.Status = api.BAREMETAL_RUNNING return nil }) if err != nil { @@ -2832,7 +2836,7 @@ func (self *SHost) AllowPerformPing(ctx context.Context, } func (self *SHost) PerformPing(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.HostStatus != HOST_ONLINE { + if self.HostStatus != api.HOST_ONLINE { self.PerformOnline(ctx, userCred, query, data) } else { self.SaveUpdates(func() error { @@ -2867,12 +2871,12 @@ func (self *SHost) AllowPerformPrepare(ctx context.Context, } func (self *SHost) PerformPrepare(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if utils.IsInStringArray(self.Status, []string{BAREMETAL_READY, BAREMETAL_RUNNING, BAREMETAL_PREPARE_FAIL}) { + if utils.IsInStringArray(self.Status, []string{api.BAREMETAL_READY, api.BAREMETAL_RUNNING, api.BAREMETAL_PREPARE_FAIL}) { var onfinish string if self.GetBaremetalServer() != nil { - if self.Status == BAREMETAL_RUNNING { + if self.Status == api.BAREMETAL_RUNNING { onfinish = "restart" - } else if self.Status == BAREMETAL_READY { + } else if self.Status == api.BAREMETAL_READY { onfinish = "shotdown" } } @@ -2886,7 +2890,7 @@ func (self *SHost) StartPrepareTask(ctx context.Context, userCred mcclient.Token if len(onfinish) > 0 { data.Set("on_finish", jsonutils.NewString(onfinish)) } - self.SetStatus(userCred, BAREMETAL_PREPARE, "start prepare task") + self.SetStatus(userCred, api.BAREMETAL_PREPARE, "start prepare task") if task, err := taskman.TaskManager.NewTask(ctx, "BaremetalPrepareTask", self, userCred, data, parentTaskId, "", nil); err != nil { log.Errorln(err) return err @@ -3030,7 +3034,7 @@ func (self *SHost) addNetif(ctx context.Context, userCred mcclient.TokenCredenti if len(bridge) == 0 { bridge = fmt.Sprintf("br%s", sw.GetName()) } - var isMaster = netif.NicType == NIC_TYPE_ADMIN + var isMaster = netif.NicType == api.NIC_TYPE_ADMIN hw, err := HostwireManager.FetchByIdsAndMac(self.Id, sw.Id, mac) if err != nil { hw = &SHostwire{} @@ -3077,7 +3081,7 @@ func (self *SHost) PerformEnableNetif(ctx context.Context, userCred mcclient.Tok if netif == nil { return nil, httperrors.NewBadRequestError("Interface %s not exist", mac) } - if !utils.IsInStringArray(netif.NicType, NIC_TYPES) { + if !utils.IsInStringArray(netif.NicType, api.NIC_TYPES) { return nil, httperrors.NewBadRequestError("Only ADMIN and IPMI nic can be enable") } network, _ := data.GetString("network") @@ -3132,10 +3136,10 @@ func (self *SHost) EnableNetif(ctx context.Context, userCred mcclient.TokenCrede } } else { var netTypes []string - if len(netType) > 0 && netType != NETWORK_TYPE_BAREMETAL { - netTypes = []string{netType, NETWORK_TYPE_BAREMETAL} + if len(netType) > 0 && netType != api.NETWORK_TYPE_BAREMETAL { + netTypes = []string{netType, api.NETWORK_TYPE_BAREMETAL} } else { - netTypes = []string{NETWORK_TYPE_BAREMETAL} + netTypes = []string{api.NETWORK_TYPE_BAREMETAL} } net, err = wire.GetCandidatePrivateNetwork(userCred, false, netTypes) if err != nil { @@ -3272,7 +3276,7 @@ func (self *SHost) AllowPerformSyncstatus(ctx context.Context, } func (self *SHost) PerformSyncstatus(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - self.SetStatus(userCred, BAREMETAL_SYNCING_STATUS, "") + self.SetStatus(userCred, api.BAREMETAL_SYNCING_STATUS, "") return nil, self.StartSyncstatus(ctx, userCred, "") } @@ -3287,13 +3291,13 @@ func (self *SHost) PerformReset(ctx context.Context, userCred mcclient.TokenCred if !self.IsBaremetal { return nil, httperrors.NewBadRequestError("Cannot start a non-baremetal host") } - if self.Status != BAREMETAL_RUNNING { + if self.Status != api.BAREMETAL_RUNNING { return nil, httperrors.NewBadRequestError("Cannot reset baremetal in status %s", self.Status) } guest := self.GetBaremetalServer() if guest != nil { - if self.HostType == HOST_TYPE_BAREMETAL { - if guest.Status != VM_ADMIN { + if self.HostType == api.HOST_TYPE_BAREMETAL { + if guest.Status != api.VM_ADMIN { return nil, httperrors.NewBadRequestError("Cannot reset baremetal with active guest") } } else { @@ -3316,7 +3320,7 @@ func (self *SHost) AllowPerformRemoveAllNetifs(ctx context.Context, func (self *SHost) PerformRemoveAllNetifs(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { netifs := self.GetNetInterfaces() for i := 0; i < len(netifs); i++ { - if !utils.IsInStringArray(netifs[i].NicType, NIC_TYPES) { + if !utils.IsInStringArray(netifs[i].NicType, api.NIC_TYPES) { self.RemoveNetif(ctx, userCred, &netifs[i], false) } } @@ -3376,7 +3380,7 @@ func (self *SHost) AllowPerformCacheImage(ctx context.Context, } func (self *SHost) PerformCacheImage(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.HostStatus != HOST_ONLINE { + if self.HostStatus != api.HOST_ONLINE { return nil, httperrors.NewInvalidStatusError("Cannot perform cache image in status %s", self.Status) } imageId, _ := data.GetString("image") @@ -3420,13 +3424,13 @@ func (self *SHost) PerformConvertHypervisor(ctx context.Context, userCred mcclie if err != nil { return nil, httperrors.NewNotAcceptableError("host_type must be specified") } - if self.HostType != HOST_TYPE_BAREMETAL { + if self.HostType != api.HOST_TYPE_BAREMETAL { return nil, httperrors.NewNotAcceptableError("Must be a baremetal host") } if self.GetBaremetalServer() != nil { return nil, httperrors.NewNotAcceptableError("Baremetal host is aleady occupied") } - if !utils.IsInStringArray(self.Status, []string{BAREMETAL_READY, BAREMETAL_RUNNING}) { + if !utils.IsInStringArray(self.Status, []string{api.BAREMETAL_READY, api.BAREMETAL_RUNNING}) { return nil, httperrors.NewNotAcceptableError("Connot convert hypervisor in status %s", self.Status) } driver := GetHostDriver(hostType) @@ -3475,7 +3479,7 @@ func (self *SHost) PerformConvertHypervisor(ctx context.Context, userCred mcclie } task.ScheduleRun(nil) - self.SetStatus(userCred, BAREMETAL_START_CONVERT, "") + self.SetStatus(userCred, api.BAREMETAL_START_CONVERT, "") return nil, nil } @@ -3490,13 +3494,13 @@ func (self *SHost) PerformUndoConvert(ctx context.Context, userCred mcclient.Tok if !self.IsBaremetal { return nil, httperrors.NewNotAcceptableError("Not a baremetal") } - if self.HostType == HOST_TYPE_BAREMETAL { + if self.HostType == api.HOST_TYPE_BAREMETAL { return nil, httperrors.NewNotAcceptableError("Not being convert to hypervisor") } if self.Enabled { return nil, httperrors.NewNotAcceptableError("Host should be disabled") } - if !utils.IsInStringArray(self.Status, []string{BAREMETAL_READY, BAREMETAL_RUNNING}) { + if !utils.IsInStringArray(self.Status, []string{api.BAREMETAL_READY, api.BAREMETAL_RUNNING}) { return nil, httperrors.NewNotAcceptableError("Cannot unconvert in status %s", self.Status) } driver := self.GetDriverWithDefault() @@ -3512,7 +3516,7 @@ func (self *SHost) PerformUndoConvert(ctx context.Context, userCred mcclient.Tok return nil, httperrors.NewNotAcceptableError("Not an empty host") } else if len(guests) == 1 { guest := guests[0] - if guest.Hypervisor != HYPERVISOR_BAREMETAL { + if guest.Hypervisor != api.HYPERVISOR_BAREMETAL { return nil, httperrors.NewNotAcceptableError("Not an converted hypervisor") } err := guest.SetDisableDelete(userCred, false) @@ -3533,7 +3537,7 @@ func (self *SHost) PerformUndoConvert(ctx context.Context, userCred mcclient.Tok func (self *SHost) GetDriverWithDefault() IHostDriver { hostType := self.HostType if len(hostType) == 0 { - hostType = HOST_TYPE_DEFAULT + hostType = api.HOST_TYPE_DEFAULT } return GetHostDriver(hostType) } @@ -3711,22 +3715,22 @@ func (host *SHost) SyncHostExternalNics(ctx context.Context, userCred mcclient.T // } func (self *SHost) IsBaremetalAgentReady() bool { - return self.isAgentReady(AgentTypeBaremetal) + return self.isAgentReady(api.AgentTypeBaremetal) } func (self *SHost) BaremetalSyncRequest(ctx context.Context, method httputils.THttpMethod, url string, headers http.Header, body *jsonutils.JSONDict) (jsonutils.JSONObject, error) { - return self.doAgentRequest(AgentTypeBaremetal, ctx, method, url, headers, body) + return self.doAgentRequest(api.AgentTypeBaremetal, ctx, method, url, headers, body) } func (self *SHost) IsEsxiAgentReady() bool { - return self.isAgentReady(AgentTypeEsxi) + return self.isAgentReady(api.AgentTypeEsxi) } func (self *SHost) EsxiRequest(ctx context.Context, method httputils.THttpMethod, url string, headers http.Header, body *jsonutils.JSONDict) (jsonutils.JSONObject, error) { - return self.doAgentRequest(AgentTypeEsxi, ctx, method, url, headers, body) + return self.doAgentRequest(api.AgentTypeEsxi, ctx, method, url, headers, body) } -func (self *SHost) isAgentReady(agentType TAgentType) bool { +func (self *SHost) isAgentReady(agentType api.TAgentType) bool { agent := BaremetalagentManager.GetAgent(agentType, self.ZoneId) if agent == nil { log.Errorf("%s ready: false", agentType) @@ -3735,7 +3739,7 @@ func (self *SHost) isAgentReady(agentType TAgentType) bool { return true } -func (self *SHost) doAgentRequest(agentType TAgentType, ctx context.Context, method httputils.THttpMethod, url string, headers http.Header, body *jsonutils.JSONDict) (jsonutils.JSONObject, error) { +func (self *SHost) doAgentRequest(agentType api.TAgentType, ctx context.Context, method httputils.THttpMethod, url string, headers http.Header, body *jsonutils.JSONDict) (jsonutils.JSONObject, error) { agent := BaremetalagentManager.GetAgent(agentType, self.ZoneId) if agent == nil { return nil, fmt.Errorf("no valid %s", agentType) @@ -3785,15 +3789,15 @@ func (self *SHost) GetShortDesc(ctx context.Context) *jsonutils.JSONDict { func (self *SHost) MarkGuestUnknown(userCred mcclient.TokenCredential) { log.Errorln(self.GetGuests()) for _, guest := range self.GetGuests() { - guest.SetStatus(userCred, VM_UNKNOWN, "host offline") + guest.SetStatus(userCred, api.VM_UNKNOWN, "host offline") } } func (manager *SHostManager) PingDetectionTask(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) { deadline := time.Now().Add(-1 * time.Duration(options.Options.HostOfflineMaxSeconds) * time.Second) - q := manager.Query().Equals("host_status", HOST_ONLINE). - Equals("host_type", HOST_TYPE_HYPERVISOR) + q := manager.Query().Equals("host_status", api.HOST_ONLINE). + Equals("host_type", api.HOST_TYPE_HYPERVISOR) q = q.Filter(sqlchemy.OR(sqlchemy.IsNull(q.Field("last_ping_at")), sqlchemy.LT(q.Field("last_ping_at"), deadline))) @@ -3814,7 +3818,7 @@ func (manager *SHostManager) PingDetectionTask(ctx context.Context, userCred mcc } func (self *SHost) IsPrepaidRecycleResource() bool { - return self.ResourceType == HostResourceTypePrepaidRecycle + return self.ResourceType == api.HostResourceTypePrepaidRecycle } func (host *SHost) AllowPerformSetSchedtag(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { diff --git a/pkg/compute/models/hoststorages.go b/pkg/compute/models/hoststorages.go index 00a0add6ab..4fe95f05ab 100644 --- a/pkg/compute/models/hoststorages.go +++ b/pkg/compute/models/hoststorages.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/pkg/tristate" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -150,7 +151,7 @@ func (self *SHoststorage) StartHostStorageAttachTask(ctx context.Context, userCr } func (self *SHoststorage) StartHostStorageDetachTask(ctx context.Context, userCred mcclient.TokenCredential) error { - if host := self.GetHost(); host.HostStatus == HOST_ONLINE { + if host := self.GetHost(); host.HostStatus == api.HOST_ONLINE { params := jsonutils.NewDict() params.Set("storage_id", jsonutils.NewString(self.StorageId)) params.Set("mount_point", jsonutils.NewString(self.MountPoint)) @@ -170,10 +171,10 @@ func (self *SHoststorage) PostDelete(ctx context.Context, userCred mcclient.Toke func (self *SHoststorage) SyncStorageStatus(userCred mcclient.TokenCredential) { storage := self.GetStorage() - status := STORAGE_OFFLINE + status := api.STORAGE_OFFLINE for _, host := range storage.GetAttachedHosts() { - if host.HostStatus == HOST_ONLINE { - status = STORAGE_ONLINE + if host.HostStatus == api.HOST_ONLINE { + status = api.STORAGE_ONLINE } } if status != storage.Status { diff --git a/pkg/compute/models/isolated_devices.go b/pkg/compute/models/isolated_devices.go index 87357bf104..ea971df00d 100644 --- a/pkg/compute/models/isolated_devices.go +++ b/pkg/compute/models/isolated_devices.go @@ -449,7 +449,7 @@ func (self *SIsolatedDevice) GetSpec(statusCheck bool) *jsonutils.JSONDict { return nil } host := self.getHost() - if host.Status != BAREMETAL_RUNNING || !host.Enabled { + if host.Status != api.BAREMETAL_RUNNING || !host.Enabled { return nil } } diff --git a/pkg/compute/models/netinterfaces.go b/pkg/compute/models/netinterfaces.go index 0ed8b90985..837caa0651 100644 --- a/pkg/compute/models/netinterfaces.go +++ b/pkg/compute/models/netinterfaces.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/regutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -266,7 +267,7 @@ func (self *SNetInterface) GetCandidateNetworkForIp(userCred mcclient.TokenCrede } func (self *SNetInterface) IsUsableServernic() bool { - if self.NicType == NIC_TYPE_IPMI { + if self.NicType == api.NIC_TYPE_IPMI { return false } if len(self.WireId) == 0 { diff --git a/pkg/compute/models/networks.go b/pkg/compute/models/networks.go index 59e1d9a94b..23762ffe32 100644 --- a/pkg/compute/models/networks.go +++ b/pkg/compute/models/networks.go @@ -41,33 +41,6 @@ import ( "yunion.io/x/onecloud/pkg/util/logclient" ) -const ( - // # DEFAULT_BANDWIDTH = options.default_bandwidth - MAX_BANDWIDTH = api.MAX_BANDWIDTH - - NETWORK_TYPE_GUEST = api.NETWORK_TYPE_GUEST - NETWORK_TYPE_BAREMETAL = api.NETWORK_TYPE_BAREMETAL - NETWORK_TYPE_CONTAINER = api.NETWORK_TYPE_CONTAINER - NETWORK_TYPE_PXE = api.NETWORK_TYPE_PXE - NETWORK_TYPE_IPMI = api.NETWORK_TYPE_IPMI - - STATIC_ALLOC = api.STATIC_ALLOC - - MAX_NETWORK_NAME_LEN = api.MAX_NETWORK_NAME_LEN - - EXTRA_DNS_UPDATE_TARGETS = api.EXTRA_DNS_UPDATE_TARGETS - - NETWORK_STATUS_INIT = api.NETWORK_STATUS_INIT - NETWORK_STATUS_PENDING = api.NETWORK_STATUS_PENDING - NETWORK_STATUS_AVAILABLE = api.NETWORK_STATUS_AVAILABLE - NETWORK_STATUS_FAILED = api.NETWORK_STATUS_FAILED - NETWORK_STATUS_UNKNOWN = api.NETWORK_STATUS_UNKNOWN - NETWORK_STATUS_START_DELETE = api.NETWORK_STATUS_START_DELETE - NETWORK_STATUS_DELETING = api.NETWORK_STATUS_DELETING - NETWORK_STATUS_DELETED = api.NETWORK_STATUS_DELETED - NETWORK_STATUS_DELETE_FAILED = api.NETWORK_STATUS_DELETE_FAILED -) - var ( ALL_NETWORK_TYPES = api.ALL_NETWORK_TYPES ) @@ -433,7 +406,7 @@ type DNSUpdateKeySecret struct { func (self *SNetwork) getDnsUpdateTargets() map[string][]DNSUpdateKeySecret { targets := make(map[string][]DNSUpdateKeySecret) - targetsJson := self.GetMetadataJson(EXTRA_DNS_UPDATE_TARGETS, nil) + targetsJson := self.GetMetadataJson(api.EXTRA_DNS_UPDATE_TARGETS, nil) if targetsJson == nil { return nil } else { @@ -539,7 +512,7 @@ func (self *SNetwork) syncRemoveCloudNetwork(ctx context.Context, userCred mccli err := self.ValidateDeleteCondition(ctx) if err != nil { // cannot delete - err = self.SetStatus(userCred, NETWORK_STATUS_UNKNOWN, "Sync to remove") + err = self.SetStatus(userCred, api.NETWORK_STATUS_UNKNOWN, "Sync to remove") } else { err = self.RealDelete(ctx, userCred) @@ -669,8 +642,8 @@ func (manager *SNetworkManager) allNetworksQ(providers []string, rangeObj db.ISt q = q.Join(hosts, sqlchemy.Equals(hosts.Field("id"), hostwires.Field("host_id"))) q = q.Filter(sqlchemy.IsTrue(hosts.Field("enabled"))) q = q.Filter(sqlchemy.OR( - sqlchemy.Equals(hosts.Field("host_type"), HOST_TYPE_BAREMETAL), - sqlchemy.Equals(hosts.Field("host_status"), HOST_ONLINE))) + sqlchemy.Equals(hosts.Field("host_type"), api.HOST_TYPE_BAREMETAL), + sqlchemy.Equals(hosts.Field("host_status"), api.HOST_ONLINE))) return AttachUsageQuery(q, hosts, nil, nil, providers, rangeObj) } @@ -778,8 +751,8 @@ func isValidNetworkInfo(userCred mcclient.TokenCredential, netConfig *api.Networ return httperrors.NewInputParameterError("Address %s has been used", netConfig.Address) } } - if netConfig.BwLimit > MAX_BANDWIDTH { - return httperrors.NewInputParameterError("Bandwidth limit cannot exceed %dMbps", MAX_BANDWIDTH) + if netConfig.BwLimit > api.MAX_BANDWIDTH { + return httperrors.NewInputParameterError("Bandwidth limit cannot exceed %dMbps", api.MAX_BANDWIDTH) } if net.getFreeAddressCount() < 1 { return httperrors.NewInputParameterError("network %s(%s) has no free addresses", net.Name, net.Id) @@ -1120,7 +1093,7 @@ func (manager *SNetworkManager) ValidateCreateData(ctx context.Context, userCred return nil, httperrors.NewInputParameterError("no valid vpc ???") } - if vpc.Status != VPC_STATUS_AVAILABLE { + if vpc.Status != api.VPC_STATUS_AVAILABLE { return nil, httperrors.NewInvalidStatusError("VPC not ready") } @@ -1134,7 +1107,7 @@ func (manager *SNetworkManager) ValidateCreateData(ctx context.Context, userCred serverTypeStr, _ := data.GetString("server_type") if len(serverTypeStr) == 0 { - serverTypeStr = NETWORK_TYPE_GUEST + serverTypeStr = api.NETWORK_TYPE_GUEST } else if !utils.IsInStringArray(serverTypeStr, ALL_NETWORK_TYPES) { return nil, httperrors.NewInputParameterError("Invalid server_type: %s", serverTypeStr) } @@ -1261,7 +1234,7 @@ func isOverlapNetworks(nets []SNetwork, startIp netutils.IPV4Addr, endIp netutil } func (self *SNetwork) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) error { - if db.IsAdminAllowCreate(userCred, self.GetModelManager()) && ownerProjId == userCred.GetProjectId() && self.ServerType == NETWORK_TYPE_GUEST { + if db.IsAdminAllowCreate(userCred, self.GetModelManager()) && ownerProjId == userCred.GetProjectId() && self.ServerType == api.NETWORK_TYPE_GUEST { self.IsPublic = true } else { self.IsPublic = false @@ -1286,7 +1259,7 @@ func (self *SNetwork) PostCreate(ctx context.Context, userCred mcclient.TokenCre task.ScheduleRun(nil) } } else { - self.SetStatus(userCred, NETWORK_STATUS_AVAILABLE, "") + self.SetStatus(userCred, api.NETWORK_STATUS_AVAILABLE, "") } } @@ -1301,7 +1274,7 @@ func (self *SNetwork) GetPrefix() (netutils.IPV4Prefix, error) { func (self *SNetwork) Delete(ctx context.Context, userCred mcclient.TokenCredential) error { log.Infof("SNetwork delete do nothing") - self.SetStatus(userCred, NETWORK_STATUS_START_DELETE, "") + self.SetStatus(userCred, api.NETWORK_STATUS_START_DELETE, "") return nil } @@ -1315,7 +1288,7 @@ func (self *SNetwork) CustomizeDelete(ctx context.Context, userCred mcclient.Tok func (self *SNetwork) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error { db.OpsLog.LogEvent(self, db.ACT_DELOCATE, self.GetShortDesc(ctx), userCred) - self.SetStatus(userCred, NETWORK_STATUS_DELETED, "real delete") + self.SetStatus(userCred, api.NETWORK_STATUS_DELETED, "real delete") return self.SSharableVirtualResourceBase.Delete(ctx, userCred) } @@ -1464,9 +1437,9 @@ func (manager *SNetworkManager) InitializeData() error { return err } for _, n := range networks { - if len(n.ExternalId) == 0 && len(n.WireId) > 0 && n.Status == NETWORK_STATUS_INIT { + if len(n.ExternalId) == 0 && len(n.WireId) > 0 && n.Status == api.NETWORK_STATUS_INIT { db.Update(&n, func() error { - n.Status = NETWORK_STATUS_AVAILABLE + n.Status = api.NETWORK_STATUS_AVAILABLE return nil }) } diff --git a/pkg/compute/models/purge.go b/pkg/compute/models/purge.go index 9cbb490f13..96f0fa3f48 100644 --- a/pkg/compute/models/purge.go +++ b/pkg/compute/models/purge.go @@ -4,11 +4,12 @@ import ( "context" "yunion.io/x/log" + "yunion.io/x/pkg/tristate" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" "yunion.io/x/onecloud/pkg/mcclient" - "yunion.io/x/pkg/tristate" ) type IPurgeableManager interface { @@ -75,7 +76,7 @@ func (host *SHost) purge(ctx context.Context, userCred mcclient.TokenCredential) } // clean all disks on locally attached storages - storages := host._getAttachedStorages(tristate.None, tristate.None, STORAGE_LOCAL) + storages := host._getAttachedStorages(tristate.None, tristate.None, api.STORAGE_LOCAL) for i := range storages { err := storages[i].purgeDisks(ctx, userCred) if err != nil { diff --git a/pkg/compute/models/secgroups.go b/pkg/compute/models/secgroups.go index bf699cdd41..b257432ee1 100644 --- a/pkg/compute/models/secgroups.go +++ b/pkg/compute/models/secgroups.go @@ -27,6 +27,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" @@ -98,7 +99,7 @@ func (self *SSecurityGroup) GetGuestsQuery() *sqlchemy.SQuery { sqlchemy.Equals(guests.Field("admin_secgrp_id"), self.Id), sqlchemy.In(guests.Field("id"), GuestsecgroupManager.Query("guest_id").Equals("secgroup_id", self.Id).SubQuery()), ), - ).Filter(sqlchemy.NotIn(guests.Field("hypervisor"), []string{HYPERVISOR_CONTAINER, HYPERVISOR_BAREMETAL, HYPERVISOR_ESXI})) + ).Filter(sqlchemy.NotIn(guests.Field("hypervisor"), []string{api.HYPERVISOR_CONTAINER, api.HYPERVISOR_BAREMETAL, api.HYPERVISOR_ESXI})) } func (self *SSecurityGroup) GetGuestsCount() int { diff --git a/pkg/compute/models/skus.go b/pkg/compute/models/skus.go index 3a430e838b..e1a8b2b30a 100644 --- a/pkg/compute/models/skus.go +++ b/pkg/compute/models/skus.go @@ -38,33 +38,6 @@ import ( "yunion.io/x/onecloud/pkg/util/hashcache" ) -const ( - SkuCategoryGeneralPurpose = "general_purpose" // 通用型 - SkuCategoryBurstable = "burstable" // 突发性能型 - SkuCategoryComputeOptimized = "compute_optimized" // 计算优化型 - SkuCategoryMemoryOptimized = "memory_optimized" // 内存优化型 - SkuCategoryStorageIOOptimized = "storage_optimized" // 存储IO优化型 - SkuCategoryHardwareAccelerated = "hardware_accelerated" // 硬件加速型 - SkuCategoryHighStorage = "high_storage" // 高存储型 - SkuCategoryHighMemory = "high_memory" // 高内存型 -) - -const ( - SkuStatusAvailable = "available" - SkuStatusSoldout = "soldout" -) - -var InstanceFamilies = map[string]string{ - SkuCategoryGeneralPurpose: "g1", - SkuCategoryBurstable: "t1", - SkuCategoryComputeOptimized: "c1", - SkuCategoryMemoryOptimized: "r1", - SkuCategoryStorageIOOptimized: "i1", - SkuCategoryHardwareAccelerated: "", - SkuCategoryHighStorage: "hc1", - SkuCategoryHighMemory: "hr1", -} - var Cache *hashcache.Cache type SServerSkuManager struct { @@ -320,7 +293,7 @@ func (self *SServerSkuManager) ValidateCreateData(ctx context.Context, } data.Add(jsonutils.NewString(regionObj.GetId()), "cloudregion_id") } else { - data.Add(jsonutils.NewString(DEFAULT_REGION_ID), "cloudregion_id") + data.Add(jsonutils.NewString(api.DEFAULT_REGION_ID), "cloudregion_id") } zoneStr := jsonutils.GetAnyString(data, []string{"zone", "zone_id"}) if len(zoneStr) > 0 { @@ -350,7 +323,7 @@ func (self *SServerSkuManager) ValidateCreateData(ctx context.Context, } category, _ := data.GetString("instance_type_category") - family, exists := InstanceFamilies[category] + family, exists := api.InstanceFamilies[category] if !exists { return nil, httperrors.NewInputParameterError("instance_type_category %s is invalid", category) } @@ -637,18 +610,18 @@ func (self *SServerSku) ValidateUpdateData( // 可用资源状态 if postpaid, err := data.GetString("postpaid_status"); err != nil { - if postpaid == SkuStatusSoldout { - data.Set("postpaid_status", jsonutils.NewString(SkuStatusSoldout)) + if postpaid == api.SkuStatusSoldout { + data.Set("postpaid_status", jsonutils.NewString(api.SkuStatusSoldout)) } else { - data.Set("postpaid_status", jsonutils.NewString(SkuStatusAvailable)) + data.Set("postpaid_status", jsonutils.NewString(api.SkuStatusAvailable)) } } prepaid, _ := data.GetString("prepaid_status") - if prepaid == SkuStatusSoldout { - data.Set("prepaid_status", jsonutils.NewString(SkuStatusSoldout)) + if prepaid == api.SkuStatusSoldout { + data.Set("prepaid_status", jsonutils.NewString(api.SkuStatusSoldout)) } else { - data.Set("prepaid_status", jsonutils.NewString(SkuStatusAvailable)) + data.Set("prepaid_status", jsonutils.NewString(api.SkuStatusAvailable)) } // name 由服务器端生成 @@ -823,9 +796,9 @@ func (manager *SServerSkuManager) FetchSkuByNameAndHypervisor(name string, hyper q = q.Equals("name", name) if len(hypervisor) > 0 { switch hypervisor { - case HYPERVISOR_BAREMETAL, HYPERVISOR_CONTAINER: + case api.HYPERVISOR_BAREMETAL, api.HYPERVISOR_CONTAINER: return nil, httperrors.NewNotImplementedError("%s not supported", hypervisor) - case HYPERVISOR_KVM, HYPERVISOR_ESXI, HYPERVISOR_XEN, HOST_TYPE_HYPERV, HYPERVISOR_OPENSTACK: + case api.HYPERVISOR_KVM, api.HYPERVISOR_ESXI, api.HYPERVISOR_XEN, api.HYPERVISOR_HYPERV: q = q.Filter(sqlchemy.OR( sqlchemy.IsEmpty(q.Field("provider")), sqlchemy.IsNull(q.Field("provider")), @@ -1022,7 +995,7 @@ func (self *SServerSku) syncRemoveCloudSku(ctx context.Context, userCred mcclien if err == nil { err = self.Delete(ctx, userCred) } else { - err = self.setPrepaidPostpaidStatus(userCred, SkuStatusSoldout, SkuStatusSoldout) + err = self.setPrepaidPostpaidStatus(userCred, api.SkuStatusSoldout, api.SkuStatusSoldout) } return err } @@ -1079,8 +1052,8 @@ func (manager *SServerSkuManager) MarkAsSoldout(id string) error { } _, err = manager.TableSpec().Update(sku, func() error { - sku.PrepaidStatus = SkuStatusSoldout - sku.PostpaidStatus = SkuStatusSoldout + sku.PrepaidStatus = api.SkuStatusSoldout + sku.PostpaidStatus = api.SkuStatusSoldout return nil }) @@ -1114,8 +1087,8 @@ func (manager *SServerSkuManager) FetchAllAvailableSkuIdByZoneId(zoneId string) skus := make([]SServerSku, 0) q = q.Equals("zone_id", zoneId) q = q.Filter(sqlchemy.OR( - sqlchemy.Equals(q.Field("prepaid_status"), SkuStatusAvailable), - sqlchemy.Equals(q.Field("postpaid_status"), SkuStatusAvailable))) + sqlchemy.Equals(q.Field("prepaid_status"), api.SkuStatusAvailable), + sqlchemy.Equals(q.Field("postpaid_status"), api.SkuStatusAvailable))) err := q.All(&skus) if err != nil { diff --git a/pkg/compute/models/snapshots.go b/pkg/compute/models/snapshots.go index ca32bf0a5a..9ff86453e5 100644 --- a/pkg/compute/models/snapshots.go +++ b/pkg/compute/models/snapshots.go @@ -27,6 +27,7 @@ import ( "yunion.io/x/pkg/util/timeutils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" @@ -36,19 +37,6 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" ) -const ( - // create by - MANUAL = "manual" - AUTO = "auto" - - SNAPSHOT_CREATING = "creating" - SNAPSHOT_ROLLBACKING = "rollbacking" - SNAPSHOT_FAILED = "create_failed" - SNAPSHOT_READY = "ready" - SNAPSHOT_DELETING = "deleting" - SNAPSHOT_UNKNOWN = "unknown" -) - type SSnapshotManager struct { db.SVirtualResourceBaseManager } @@ -98,7 +86,7 @@ func ValidateSnapshotName(hypervisor, name, owner string) error { if len(name) < 2 || len(name) > 128 { return fmt.Errorf("Snapshot name length must within 2~128") } - if hypervisor == HYPERVISOR_ALIYUN { + if hypervisor == api.HYPERVISOR_ALIYUN { if strings.HasPrefix(name, "auto") || strings.HasPrefix(name, "http://") || strings.HasPrefix(name, "https://") { return fmt.Errorf("Snapshot name can't start with auto, http:// or https://") } @@ -131,7 +119,7 @@ func (manager *SSnapshotManager) ListItemFilter(ctx context.Context, q *sqlchemy if jsonutils.QueryBoolean(query, "local", false) { storages := StorageManager.Query().SubQuery() - sq := storages.Query(storages.Field("id")).Filter(sqlchemy.Equals(storages.Field("storage_type"), STORAGE_LOCAL)) + sq := storages.Query(storages.Field("id")).Filter(sqlchemy.Equals(storages.Field("storage_type"), api.STORAGE_LOCAL)) q = q.Filter(sqlchemy.In(q.Field("storage_id"), sq)) } @@ -341,7 +329,7 @@ func (self *SSnapshotManager) GetDiskFirstSnapshot(diskId string) *SSnapshot { dest := &SSnapshot{} q := self.Query().SubQuery() err := q.Query().Filter(sqlchemy.AND(sqlchemy.Equals(q.Field("disk_id"), diskId), - sqlchemy.In(q.Field("status"), []string{SNAPSHOT_READY, SNAPSHOT_DELETING}), + sqlchemy.In(q.Field("status"), []string{api.SNAPSHOT_READY, api.SNAPSHOT_DELETING}), sqlchemy.Equals(q.Field("out_of_chain"), false))).Asc("created_at").First(dest) if err != nil { log.Errorf("Get Disk First snapshot error: %s", err.Error()) @@ -378,7 +366,7 @@ func (self *SSnapshotManager) CreateSnapshot(ctx context.Context, userCred mccli snapshot.ManagerId = storage.ManagerId snapshot.CloudregionId = storage.getZone().GetRegion().GetId() snapshot.Name = name - snapshot.Status = SNAPSHOT_CREATING + snapshot.Status = api.SNAPSHOT_CREATING err = SnapshotManager.TableSpec().Insert(snapshot) if err != nil { return nil, err @@ -411,11 +399,11 @@ func (self *SSnapshot) ValidateDeleteCondition(ctx context.Context) error { } func (self *SSnapshot) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error { - if self.Status == SNAPSHOT_DELETING { + if self.Status == api.SNAPSHOT_DELETING { return fmt.Errorf("Cannot delete snapshot in status %s", self.Status) } if len(self.ExternalId) == 0 { - if self.CreatedBy == MANUAL { + if self.CreatedBy == api.SNAPSHOT_MANUAL { if !self.FakeDeleted { return self.FakeDelete() } @@ -457,7 +445,7 @@ func (self *SSnapshotManager) GetConvertSnapshot(deleteSnapshot *SSnapshot) (*SS dest := &SSnapshot{} q := self.Query().SubQuery() err := q.Query().Filter(sqlchemy.AND(sqlchemy.Equals(q.Field("disk_id"), deleteSnapshot.DiskId), - sqlchemy.In(q.Field("status"), []string{SNAPSHOT_READY, SNAPSHOT_DELETING}), + sqlchemy.In(q.Field("status"), []string{api.SNAPSHOT_READY, api.SNAPSHOT_DELETING}), sqlchemy.Equals(q.Field("out_of_chain"), false), sqlchemy.GT(q.Field("created_at"), deleteSnapshot.CreatedAt))). Asc("created_at").First(dest) @@ -485,7 +473,7 @@ func (self *SSnapshotManager) PerformDeleteDiskSnapshots(ctx context.Context, us return nil, httperrors.NewNotFoundError("Disk %s dose not have snapshot", diskId) } for i := 0; i < len(snapshots); i++ { - if snapshots[i].CreatedBy == MANUAL && snapshots[i].FakeDeleted == false { + if snapshots[i].CreatedBy == api.SNAPSHOT_MANUAL && snapshots[i].FakeDeleted == false { return nil, httperrors.NewBadRequestError("Can not delete disk snapshots, have manual snapshot") } } @@ -554,7 +542,7 @@ func (self *SSnapshot) syncRemoveCloudSnapshot(ctx context.Context, userCred mcc err := self.ValidateDeleteCondition(ctx) if err != nil { - err = self.SetStatus(userCred, SNAPSHOT_UNKNOWN, "sync to delete") + err = self.SetStatus(userCred, api.SNAPSHOT_UNKNOWN, "sync to delete") } else { err = self.RealDelete(ctx, userCred) } diff --git a/pkg/compute/models/storagecachedimages.go b/pkg/compute/models/storagecachedimages.go index 8e11a732ed..fc3208775b 100644 --- a/pkg/compute/models/storagecachedimages.go +++ b/pkg/compute/models/storagecachedimages.go @@ -28,6 +28,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -35,17 +36,6 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" ) -const ( - CACHED_IMAGE_STATUS_INIT = "init" - CACHED_IMAGE_STATUS_SAVING = "saving" - CACHED_IMAGE_STATUS_CACHING = "caching" - CACHED_IMAGE_STATUS_READY = "ready" - CACHED_IMAGE_STATUS_DELETING = "deleting" - CACHED_IMAGE_STATUS_CACHE_FAILED = "cache_fail" - - DOWNLOAD_SESSION_LENGTH = 3600 * 3 // 3 hour -) - type SStoragecachedimageManager struct { db.SJointResourceBaseManager } @@ -216,7 +206,7 @@ func (self *SStoragecachedimage) getDiskReferenceCount() int { sqlchemy.IsFalse(storages.Field("deleted")))) q = q.Filter(sqlchemy.Equals(storages.Field("storagecache_id"), self.StoragecacheId)) q = q.Filter(sqlchemy.Equals(disks.Field("template_id"), self.CachedimageId)) - q = q.Filter(sqlchemy.NOT(sqlchemy.In(disks.Field("status"), []string{DISK_ALLOC_FAILED, DISK_INIT}))) + q = q.Filter(sqlchemy.NOT(sqlchemy.In(disks.Field("status"), []string{api.DISK_ALLOC_FAILED, api.DISK_INIT}))) return q.Count() } @@ -263,7 +253,7 @@ func (self *SStoragecachedimage) isCachedImageInUse() error { } func (self *SStoragecachedimage) isDownloadSessionExpire() bool { - if !self.LastDownload.IsZero() && time.Now().Sub(self.LastDownload) < DOWNLOAD_SESSION_LENGTH { + if !self.LastDownload.IsZero() && time.Now().Sub(self.LastDownload) < api.DOWNLOAD_SESSION_LENGTH { return false } else { return true @@ -291,11 +281,11 @@ func (self *SStoragecachedimage) markDeleting(ctx context.Context, userCred mccl } if !isForce && !utils.IsInStringArray(self.Status, - []string{CACHED_IMAGE_STATUS_READY, CACHED_IMAGE_STATUS_DELETING, CACHED_IMAGE_STATUS_CACHE_FAILED}) { + []string{api.CACHED_IMAGE_STATUS_READY, api.CACHED_IMAGE_STATUS_DELETING, api.CACHED_IMAGE_STATUS_CACHE_FAILED}) { return httperrors.NewInvalidStatusError("Cannot uncache in status %s", self.Status) } _, err = db.Update(self, func() error { - self.Status = CACHED_IMAGE_STATUS_DELETING + self.Status = api.CACHED_IMAGE_STATUS_DELETING return nil }) return err @@ -316,7 +306,7 @@ func (manager *SStoragecachedimageManager) Register(ctx context.Context, userCre cachedimage.StoragecacheId = cacheId cachedimage.CachedimageId = imageId if len(status) == 0 { - status = CACHED_IMAGE_STATUS_INIT + status = api.CACHED_IMAGE_STATUS_INIT } cachedimage.Status = status diff --git a/pkg/compute/models/storagecaches.go b/pkg/compute/models/storagecaches.go index 1cb6f3589e..4220450817 100644 --- a/pkg/compute/models/storagecaches.go +++ b/pkg/compute/models/storagecaches.go @@ -26,6 +26,7 @@ import ( "yunion.io/x/pkg/util/compare" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" @@ -128,10 +129,10 @@ func (self *SStoragecache) getHostId() (string, error) { host := HostManager.Query().SubQuery() q := host.Query(host.Field("id")) err := q.Join(hoststorages, sqlchemy.AND(sqlchemy.Equals(hoststorages.Field("host_id"), host.Field("id")), - sqlchemy.Equals(host.Field("host_status"), HOST_ONLINE), + sqlchemy.Equals(host.Field("host_status"), api.HOST_ONLINE), sqlchemy.IsTrue(host.Field("enabled")))). Join(storages, sqlchemy.AND(sqlchemy.Equals(storages.Field("storagecache_id"), self.Id), - sqlchemy.In(storages.Field("status"), []string{STORAGE_ENABLED, STORAGE_ONLINE}), + sqlchemy.In(storages.Field("status"), []string{api.STORAGE_ENABLED, api.STORAGE_ONLINE}), sqlchemy.IsTrue(storages.Field("enabled")))). Filter(sqlchemy.Equals(hoststorages.Field("storage_id"), storages.Field("id"))).All(&hosts) if err != nil { @@ -439,7 +440,7 @@ func (self *SStoragecache) PerformUncacheImage(ctx context.Context, userCred mcc return nil, httperrors.NewResourceNotFoundError("storage not cache image") } - if scimg.Status == CACHED_IMAGE_STATUS_INIT || isForce { + if scimg.Status == api.CACHED_IMAGE_STATUS_INIT || isForce { err = scimg.Detach(ctx, userCred) return nil, err } diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index 52dded9c35..ba08b205ad 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -35,6 +35,7 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" ) +/* const ( STORAGE_LOCAL = api.STORAGE_LOCAL STORAGE_BAREMETAL = api.STORAGE_BAREMETAL @@ -106,6 +107,7 @@ var ( STORAGE_LIMITED_TYPES = api.STORAGE_LIMITED_TYPES ) +*/ type SStorageManager struct { db.SStandaloneResourceBaseManager @@ -192,10 +194,10 @@ func (manager *SStorageManager) ValidateCreateData(ctx context.Context, userCred storageType, _ := data.GetString("storage_type") mediumType, _ := data.GetString("medium_type") - if !utils.IsInStringArray(storageType, STORAGE_TYPES) { + if !utils.IsInStringArray(storageType, api.STORAGE_TYPES) { return nil, httperrors.NewInputParameterError("Invalid storage type %s", storageType) } - if !utils.IsInStringArray(mediumType, DISK_TYPES) { + if !utils.IsInStringArray(mediumType, api.DISK_TYPES) { return nil, httperrors.NewInputParameterError("Invalid medium type %s", mediumType) } zoneId, err := data.GetString("zone") @@ -305,8 +307,8 @@ func (self *SStorage) AllowPerformOnline(ctx context.Context, userCred mcclient. } func (self *SStorage) PerformOnline(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status != STORAGE_ONLINE { - err := self.SetStatus(userCred, STORAGE_ONLINE, "") + if self.Status != api.STORAGE_ONLINE { + err := self.SetStatus(userCred, api.STORAGE_ONLINE, "") if err != nil { return nil, err } @@ -320,8 +322,8 @@ func (self *SStorage) AllowPerformOffline(ctx context.Context, userCred mcclient } func (self *SStorage) PerformOffline(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) { - if self.Status != STORAGE_OFFLINE { - err := self.SetStatus(userCred, STORAGE_OFFLINE, "") + if self.Status != api.STORAGE_OFFLINE { + err := self.SetStatus(userCred, api.STORAGE_OFFLINE, "") if err != nil { return nil, err } @@ -354,11 +356,11 @@ func (self *SStorage) GetSnapshotCount() int { } func (self *SStorage) IsLocal() bool { - return self.StorageType == STORAGE_LOCAL || self.StorageType == STORAGE_BAREMETAL + return self.StorageType == api.STORAGE_LOCAL || self.StorageType == api.STORAGE_BAREMETAL } func (self *SStorage) GetStorageCachePath(mountPoint, imageCachePath string) string { - if self.StorageType == STORAGE_NFS { + if self.StorageType == api.STORAGE_NFS { return path.Join(mountPoint, imageCachePath) } else { return imageCachePath @@ -407,9 +409,9 @@ func (self *SStorage) GetUsedCapacity(isReady tristate.TriState) int { q := disks.Query(sqlchemy.SUM("sum", disks.Field("disk_size"))).Equals("storage_id", self.Id) switch isReady { case tristate.True: - q = q.Equals("status", DISK_READY) + q = q.Equals("status", api.DISK_READY) case tristate.False: - q = q.NotEquals("status", DISK_READY) + q = q.NotEquals("status", api.DISK_READY) } if q.Count() == 0 { return 0 @@ -440,7 +442,7 @@ func (self *SStorage) GetMasterHost() *SHost { sqlchemy.IsFalse(hoststorages.Field("deleted")))) q = q.Filter(sqlchemy.Equals(hoststorages.Field("storage_id"), self.Id)) q = q.IsTrue("enabled") - q = q.Equals("host_status", HOST_ONLINE).Asc("id") + q = q.Equals("host_status", api.HOST_ONLINE).Asc("id") host := SHost{} host.SetModelManager(HostManager) err := q.First(&host) @@ -526,7 +528,7 @@ func (self *SStorage) SyncStatusWithHosts() { online := 0 offline := 0 for _, h := range hosts { - if h.HostStatus == HOST_ONLINE { + if h.HostStatus == api.HOST_ONLINE { online += 1 } else { offline += 1 @@ -537,14 +539,14 @@ func (self *SStorage) SyncStatusWithHosts() { if !self.IsLocal() { status = self.Status if online == 0 { - status = STORAGE_OFFLINE + status = api.STORAGE_OFFLINE } } else if online > 0 { - status = STORAGE_ONLINE + status = api.STORAGE_ONLINE } else if offline > 0 { - status = STORAGE_OFFLINE + status = api.STORAGE_OFFLINE } else { - status = STORAGE_OFFLINE + status = api.STORAGE_OFFLINE } if status != self.Status { self.SetStatus(nil, status, "SyncStatusWithHosts") @@ -655,7 +657,7 @@ func (self *SStorage) syncRemoveCloudStorage(ctx context.Context, userCred mccli err := self.ValidateDeleteCondition(ctx) if err != nil { // cannot delete - err = self.SetStatus(userCred, STORAGE_OFFLINE, "sync to delete") + err = self.SetStatus(userCred, api.STORAGE_OFFLINE, "sync to delete") if err == nil { _, err = self.PerformDisable(ctx, userCred, nil, nil) } @@ -732,7 +734,7 @@ func (manager *SStorageManager) disksReadyQ() *sqlchemy.SSubQuery { q := disks.Query( disks.Field("storage_id"), sqlchemy.SUM("used_capacity", disks.Field("disk_size")), - ).Equals("status", DISK_READY).GroupBy(disks.Field("storage_id")).SubQuery() + ).Equals("status", api.DISK_READY).GroupBy(disks.Field("storage_id")).SubQuery() return q } @@ -749,7 +751,7 @@ func (manager *SStorageManager) diskIsAttachedQ(isAttached bool) *sqlchemy.SSubQ q := disks.Query( disks.Field("storage_id"), sqlchemy.SUM(sumKey, disks.Field("disk_size")), - ).Equals("status", DISK_READY).GroupBy(disks.Field("storage_id")) + ).Equals("status", api.DISK_READY).GroupBy(disks.Field("storage_id")) return q.SubQuery() } @@ -766,7 +768,7 @@ func (manager *SStorageManager) disksFailedQ() *sqlchemy.SSubQuery { q := disks.Query( disks.Field("storage_id"), sqlchemy.SUM("failed_capacity", disks.Field("disk_size")), - ).NotEquals("status", DISK_READY).GroupBy(disks.Field("storage_id")).SubQuery() + ).NotEquals("status", api.DISK_READY).GroupBy(disks.Field("storage_id")).SubQuery() return q } @@ -800,7 +802,7 @@ func (manager *SStorageManager) totalCapacityQ( q = q.Join(hostStorages, sqlchemy.Equals(hostStorages.Field("storage_id"), storages.Field("id"))) q = q.Join(hosts, sqlchemy.Equals(hosts.Field("id"), hostStorages.Field("host_id"))) q = q.Filter(sqlchemy.IsTrue(hosts.Field("enabled"))) - q = q.Filter(sqlchemy.Equals(hosts.Field("host_status"), HOST_ONLINE)) + q = q.Filter(sqlchemy.Equals(hosts.Field("host_status"), api.HOST_ONLINE)) q = AttachUsageQuery(q, hosts, hostTypes, resourceTypes, nil, rangeObj) } @@ -909,7 +911,7 @@ func (self *SStorage) GetAllAttachingHosts() []SHost { sqlchemy.IsFalse(hoststorages.Field("deleted")))) q = q.Filter(sqlchemy.Equals(hoststorages.Field("storage_id"), self.Id)) q = q.Filter(sqlchemy.IsTrue(hosts.Field("enabled"))) - q = q.Filter(sqlchemy.Equals(hosts.Field("host_status"), HOST_ONLINE)) + q = q.Filter(sqlchemy.Equals(hosts.Field("host_status"), api.HOST_ONLINE)) ret := make([]SHost, 0) err := q.All(&ret) @@ -1030,7 +1032,7 @@ func (manager *SStorageManager) InitializeData() error { return nil }) } - if len(s.StoragecacheId) == 0 && s.StorageType == STORAGE_RBD { + if len(s.StoragecacheId) == 0 && s.StorageType == api.STORAGE_RBD { storagecache := &SStoragecache{} storagecache.SetModelManager(StoragecacheManager) storagecache.Name = "rbd-" + s.Id @@ -1088,11 +1090,11 @@ func (manager *SStorageManager) ListItemFilter(ctx context.Context, q *sqlchemy. } if jsonutils.QueryBoolean(query, "share", false) { - q = q.Filter(sqlchemy.NotIn(q.Field("storage_type"), STORAGE_LOCAL_TYPES)) + q = q.Filter(sqlchemy.NotIn(q.Field("storage_type"), api.STORAGE_LOCAL_TYPES)) } if jsonutils.QueryBoolean(query, "local", false) { - q = q.Filter(sqlchemy.In(q.Field("storage_type"), STORAGE_LOCAL_TYPES)) + q = q.Filter(sqlchemy.In(q.Field("storage_type"), api.STORAGE_LOCAL_TYPES)) } if jsonutils.QueryBoolean(query, "usable", false) { @@ -1100,10 +1102,10 @@ func (manager *SStorageManager) ListItemFilter(ctx context.Context, q *sqlchemy. hostTable := HostManager.Query().SubQuery() sq := hostStorageTable.Query(hostStorageTable.Field("storage_id")).Join(hostTable, sqlchemy.Equals(hostTable.Field("id"), hostStorageTable.Field("host_id"))). - Filter(sqlchemy.Equals(hostTable.Field("host_status"), HOST_ONLINE)) + Filter(sqlchemy.Equals(hostTable.Field("host_status"), api.HOST_ONLINE)) q = q.Filter(sqlchemy.In(q.Field("id"), sq)). - Filter(sqlchemy.In(q.Field("status"), []string{STORAGE_ENABLED, STORAGE_ONLINE})). + Filter(sqlchemy.In(q.Field("status"), []string{api.STORAGE_ENABLED, api.STORAGE_ONLINE})). Filter(sqlchemy.IsTrue(q.Field("enabled"))) } diff --git a/pkg/compute/models/usage.go b/pkg/compute/models/usage.go index c14d7ed61f..fd2b0f45c8 100644 --- a/pkg/compute/models/usage.go +++ b/pkg/compute/models/usage.go @@ -18,6 +18,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" ) @@ -33,7 +34,7 @@ func AttachUsageQuery( q = q.Filter(sqlchemy.In(hosts.Field("host_type"), hostTypes)) } if len(resourceTypes) > 0 { - if utils.IsInStringArray(HostResourceTypeShared, resourceTypes) { + if utils.IsInStringArray(api.HostResourceTypeShared, resourceTypes) { q = q.Filter(sqlchemy.OR( sqlchemy.IsNullOrEmpty(hosts.Field("resource_type")), sqlchemy.In(hosts.Field("resource_type"), resourceTypes), diff --git a/pkg/compute/models/vpcs.go b/pkg/compute/models/vpcs.go index 8891fc8dae..01b6ab208d 100644 --- a/pkg/compute/models/vpcs.go +++ b/pkg/compute/models/vpcs.go @@ -25,6 +25,7 @@ import ( "yunion.io/x/pkg/util/netutils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" @@ -33,22 +34,6 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" ) -const ( - VPC_STATUS_PENDING = "pending" - VPC_STATUS_AVAILABLE = "available" - VPC_STATUS_FAILED = "failed" - VPC_STATUS_START_DELETE = "start_delete" - VPC_STATUS_DELETING = "deleting" - VPC_STATUS_DELETE_FAILED = "delete_failed" - VPC_STATUS_DELETED = "deleted" - VPC_STATUS_UNKNOWN = "unknown" - - MAX_VPC_PER_REGION = 3 - - DEFAULT_VPC_ID = "default" - NORMAL_VPC_ID = "normal" // 没有关联VPC的安全组,统一使用normal -) - type SVpcManager struct { db.SEnabledStatusStandaloneResourceBaseManager } @@ -103,7 +88,7 @@ func (self *SVpc) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCr func (self *SVpc) GetCloudRegionId() string { if len(self.CloudregionId) == 0 { - return DEFAULT_REGION_ID + return api.DEFAULT_REGION_ID } else { return self.CloudregionId } @@ -121,7 +106,7 @@ func (self *SVpc) ValidateDeleteCondition(ctx context.Context) error { if self.GetNetworkCount() > 0 { return httperrors.NewNotEmptyError("VPC not empty") } - if self.Id == DEFAULT_VPC_ID { + if self.Id == api.DEFAULT_VPC_ID { return httperrors.NewProtectedResourceError("not allow to delete default vpc") } return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx) @@ -129,7 +114,7 @@ func (self *SVpc) ValidateDeleteCondition(ctx context.Context) error { func (self *SVpc) getWireQuery() *sqlchemy.SQuery { wires := WireManager.Query() - if self.Id == DEFAULT_VPC_ID { + if self.Id == api.DEFAULT_VPC_ID { return wires.Filter(sqlchemy.OR(sqlchemy.IsNull(wires.Field("vpc_id")), sqlchemy.IsEmpty(wires.Field("vpc_id")), sqlchemy.Equals(wires.Field("vpc_id"), self.Id))) @@ -327,7 +312,7 @@ func (self *SVpc) syncRemoveCloudVpc(ctx context.Context, userCred mcclient.Toke self.markAllNetworksUnknown(userCred) _, err := self.PerformDisable(ctx, userCred, nil, nil) if err == nil { - err = self.SetStatus(userCred, VPC_STATUS_UNKNOWN, "sync to delete") + err = self.SetStatus(userCred, api.VPC_STATUS_UNKNOWN, "sync to delete") } } else { err = self.RealDelete(ctx, userCred) @@ -393,17 +378,17 @@ func (self *SVpc) markAllNetworksUnknown(userCred mcclient.TokenCredential) erro } func (manager *SVpcManager) InitializeData() error { - vpcObj, err := manager.FetchById(DEFAULT_VPC_ID) + vpcObj, err := manager.FetchById(api.DEFAULT_VPC_ID) if err != nil { if err == sql.ErrNoRows { defVpc := SVpc{} defVpc.SetModelManager(VpcManager) - defVpc.Id = DEFAULT_VPC_ID + defVpc.Id = api.DEFAULT_VPC_ID defVpc.Name = "Default" - defVpc.CloudregionId = DEFAULT_REGION_ID + defVpc.CloudregionId = api.DEFAULT_REGION_ID defVpc.Description = "Default VPC" - defVpc.Status = VPC_STATUS_AVAILABLE + defVpc.Status = api.VPC_STATUS_AVAILABLE defVpc.IsDefault = true err = manager.TableSpec().Insert(&defVpc) if err != nil { @@ -415,9 +400,9 @@ func (manager *SVpcManager) InitializeData() error { } } else { vpc := vpcObj.(*SVpc) - if vpc.Status != VPC_STATUS_AVAILABLE { + if vpc.Status != api.VPC_STATUS_AVAILABLE { _, err = db.Update(vpc, func() error { - vpc.Status = VPC_STATUS_AVAILABLE + vpc.Status = api.VPC_STATUS_AVAILABLE return nil }) return err @@ -513,7 +498,7 @@ func (self *SVpc) GetIVpc() (cloudprovider.ICloudVpc, error) { func (self *SVpc) Delete(ctx context.Context, userCred mcclient.TokenCredential) error { log.Infof("SVpc delete do nothing") - self.SetStatus(userCred, VPC_STATUS_START_DELETE, "") + self.SetStatus(userCred, api.VPC_STATUS_START_DELETE, "") return nil } @@ -527,7 +512,7 @@ func (self *SVpc) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCr func (self *SVpc) RealDelete(ctx context.Context, userCred mcclient.TokenCredential) error { db.OpsLog.LogEvent(self, db.ACT_DELOCATE, self.GetShortDesc(ctx), userCred) - self.SetStatus(userCred, VPC_STATUS_DELETED, "real delete") + self.SetStatus(userCred, api.VPC_STATUS_DELETED, "real delete") routes := self.GetRouteTables() for i := 0; i < len(routes); i++ { routes[i].RealDelete(ctx, userCred) diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index f563f067d4..e5e6964827 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -26,6 +26,7 @@ import ( "yunion.io/x/pkg/util/netutils" "yunion.io/x/sqlchemy" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" @@ -277,7 +278,7 @@ func (self *SWire) markNetworkUnknown(userCred mcclient.TokenCredential) error { return err } for i := 0; i < len(nets); i += 1 { - nets[i].SetStatus(userCred, NETWORK_STATUS_UNKNOWN, "wire sync to remove") + nets[i].SetStatus(userCred, api.NETWORK_STATUS_UNKNOWN, "wire sync to remove") } return nil } @@ -419,7 +420,7 @@ func (self *SWire) getNetworks() ([]SNetwork, error) { func (self *SWire) getGatewayNetworkQuery() *sqlchemy.SQuery { q := self.getNetworkQuery() q = q.IsNotNull("guest_gateway").IsNotEmpty("guest_gateway") - q = q.Equals("status", NETWORK_STATUS_AVAILABLE) + q = q.Equals("status", api.NETWORK_STATUS_AVAILABLE) return q } @@ -528,7 +529,7 @@ func chooseCandidateNetworksByNetworkType(nets []SNetwork, isExit bool, serverTy if isExit != net.IsExitNetwork() { continue } - if serverType == net.ServerType || (len(net.ServerType) == 0 && serverType == NETWORK_TYPE_GUEST) { + if serverType == net.ServerType || (len(net.ServerType) == 0 && serverType == api.NETWORK_TYPE_GUEST) { matchingNets = append(matchingNets, &net) } else { notMatchingNets = append(notMatchingNets, &net) @@ -559,7 +560,7 @@ func (manager *SWireManager) InitializeData() error { for _, w := range wires { if len(w.VpcId) == 0 { db.Update(&w, func() error { - w.VpcId = DEFAULT_VPC_ID + w.VpcId = api.DEFAULT_VPC_ID return nil }) } @@ -578,7 +579,7 @@ func (wire *SWire) getEnabledHosts() []SHost { sqlchemy.IsFalse(hostwireQuery.Field("deleted")))) q = q.Filter(sqlchemy.Equals(hostwireQuery.Field("wire_id"), wire.Id)) q = q.Filter(sqlchemy.IsTrue(hostQuery.Field("enabled"))) - q = q.Filter(sqlchemy.Equals(hostQuery.Field("host_status"), HOST_ONLINE)) + q = q.Filter(sqlchemy.Equals(hostQuery.Field("host_status"), api.HOST_ONLINE)) err := db.FetchModelObjects(HostManager, q, &hosts) if err != nil { diff --git a/pkg/compute/models/zones.go b/pkg/compute/models/zones.go index 36c48535be..8f7a078171 100644 --- a/pkg/compute/models/zones.go +++ b/pkg/compute/models/zones.go @@ -33,14 +33,6 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" ) -const ( - ZONE_INIT = "init" - ZONE_ENABLE = "enable" - ZONE_DISABLE = "disable" - ZONE_SOLDOUT = "soldout" - // ZONE_LACK = "lack" -) - type SZoneManager struct { db.SStatusStandaloneResourceBaseManager } @@ -330,7 +322,7 @@ func (self *SZone) syncRemoveCloudZone(ctx context.Context, userCred mcclient.To err := self.ValidateDeleteCondition(ctx) if err != nil { // cannot delete - err = self.SetStatus(userCred, ZONE_DISABLE, "sync to delete") + err = self.SetStatus(userCred, api.ZONE_DISABLE, "sync to delete") } else { err = self.Delete(ctx, userCred) } @@ -401,13 +393,13 @@ func (manager *SZoneManager) InitializeData() error { for _, z := range zones { if len(z.CloudregionId) == 0 { db.Update(&z, func() error { - z.CloudregionId = DEFAULT_REGION_ID + z.CloudregionId = api.DEFAULT_REGION_ID return nil }) } - if z.Status == ZONE_INIT || z.Status == ZONE_DISABLE { + if z.Status == api.ZONE_INIT || z.Status == api.ZONE_DISABLE { db.Update(&z, func() error { - z.Status = ZONE_ENABLE + z.Status = api.ZONE_ENABLE return nil }) } @@ -430,14 +422,14 @@ func (manager *SZoneManager) usableZoneQ1(providers, vpcs, wires, networks *sqlc // add filters if usableNet { - sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), NETWORK_STATUS_AVAILABLE)) + sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), api.NETWORK_STATUS_AVAILABLE)) } sq = sq.Filter(sqlchemy.IsNotEmpty(wires.Field("zone_id"))) sq = sq.Filter(sqlchemy.IsTrue(providers.Field("enabled"))) sq = sq.Filter(sqlchemy.In(providers.Field("status"), api.CLOUD_PROVIDER_VALID_STATUS)) sq = sq.Filter(sqlchemy.Equals(providers.Field("health_status"), api.CLOUD_PROVIDER_HEALTH_NORMAL)) if usableVpc { - sq = sq.Filter(sqlchemy.Equals(vpcs.Field("status"), VPC_STATUS_AVAILABLE)) + sq = sq.Filter(sqlchemy.Equals(vpcs.Field("status"), api.VPC_STATUS_AVAILABLE)) } return sq.SubQuery() @@ -457,12 +449,12 @@ func (manager *SZoneManager) usableZoneQ2(vpcs, wires, networks *sqlchemy.SSubQu // add filters if usableNet { - sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), NETWORK_STATUS_AVAILABLE)) + sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), api.NETWORK_STATUS_AVAILABLE)) } sq = sq.Filter(sqlchemy.IsNotEmpty(wires.Field("zone_id"))) sq = sq.Filter(sqlchemy.IsNullOrEmpty(vpcs.Field("manager_id"))) if usableVpc { - sq = sq.Filter(sqlchemy.Equals(vpcs.Field("status"), VPC_STATUS_AVAILABLE)) + sq = sq.Filter(sqlchemy.Equals(vpcs.Field("status"), api.VPC_STATUS_AVAILABLE)) } return sq.SubQuery() @@ -486,14 +478,14 @@ func (manager *SZoneManager) usableZoneQ3(providers, vpcs, wires, networks, zone // add filters if usableNet { - sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), NETWORK_STATUS_AVAILABLE)) + sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), api.NETWORK_STATUS_AVAILABLE)) } sq = sq.Filter(sqlchemy.IsNullOrEmpty(wires.Field("zone_id"))) sq = sq.Filter(sqlchemy.IsTrue(providers.Field("enabled"))) sq = sq.Filter(sqlchemy.In(providers.Field("status"), api.CLOUD_PROVIDER_VALID_STATUS)) sq = sq.Filter(sqlchemy.Equals(providers.Field("health_status"), api.CLOUD_PROVIDER_HEALTH_NORMAL)) if usableVpc { - sq = sq.Filter(sqlchemy.Equals(vpcs.Field("status"), VPC_STATUS_AVAILABLE)) + sq = sq.Filter(sqlchemy.Equals(vpcs.Field("status"), api.VPC_STATUS_AVAILABLE)) } return sq.SubQuery() @@ -516,12 +508,12 @@ func (manager *SZoneManager) usableZoneQ4(vpcs, wires, networks, zones *sqlchemy // add filters if usableNet { - sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), NETWORK_STATUS_AVAILABLE)) + sq = sq.Filter(sqlchemy.Equals(networks.Field("status"), api.NETWORK_STATUS_AVAILABLE)) } sq = sq.Filter(sqlchemy.IsNullOrEmpty(wires.Field("zone_id"))) sq = sq.Filter(sqlchemy.IsNullOrEmpty(vpcs.Field("manager_id"))) if usableVpc { - sq = sq.Filter(sqlchemy.Equals(vpcs.Field("status"), VPC_STATUS_AVAILABLE)) + sq = sq.Filter(sqlchemy.Equals(vpcs.Field("status"), api.VPC_STATUS_AVAILABLE)) } return sq.SubQuery() @@ -599,7 +591,7 @@ func (manager *SZoneManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQu sqlchemy.In(q.Field("id"), sq3), sqlchemy.In(q.Field("id"), sq4), )) - q = q.Equals("status", ZONE_ENABLE) + q = q.Equals("status", api.ZONE_ENABLE) } managerStr, _ := query.GetString("manager") @@ -707,6 +699,6 @@ func (manager *SZoneManager) ValidateCreateData(ctx context.Context, userCred mc regionId = "default" } data.Add(jsonutils.NewString(regionId), "cloudregion_id") - data.Set("status", jsonutils.NewString(ZONE_ENABLE)) + data.Set("status", jsonutils.NewString(api.ZONE_ENABLE)) return manager.SStatusStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerProjId, query, data) } diff --git a/pkg/compute/storagedrivers/local.go b/pkg/compute/storagedrivers/local.go index 7c255bd008..3fab7067f2 100644 --- a/pkg/compute/storagedrivers/local.go +++ b/pkg/compute/storagedrivers/local.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/mcclient" ) @@ -33,7 +34,7 @@ func init() { } func (self *SLocalStorageDriver) GetStorageType() string { - return models.STORAGE_LOCAL + return api.STORAGE_LOCAL } func (self *SLocalStorageDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { diff --git a/pkg/compute/storagedrivers/nfs.go b/pkg/compute/storagedrivers/nfs.go index c7e41206db..d9c7a3e9f4 100644 --- a/pkg/compute/storagedrivers/nfs.go +++ b/pkg/compute/storagedrivers/nfs.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/compute/options" @@ -38,7 +39,7 @@ func init() { } func (self *SNfsStorageDriver) GetStorageType() string { - return models.STORAGE_NFS + return api.STORAGE_NFS } func (self *SNfsStorageDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { @@ -67,7 +68,7 @@ func (self *SNfsStorageDriver) PostCreate(ctx context.Context, userCred mcclient } _, err := db.Update(storage, func() error { storage.StoragecacheId = sc.Id - storage.Status = models.STORAGE_ONLINE + storage.Status = api.STORAGE_ONLINE return nil }) if err != nil { diff --git a/pkg/compute/storagedrivers/rbd.go b/pkg/compute/storagedrivers/rbd.go index 48da31d4a1..34f1ba878f 100644 --- a/pkg/compute/storagedrivers/rbd.go +++ b/pkg/compute/storagedrivers/rbd.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/httperrors" @@ -38,7 +39,7 @@ func init() { } func (self *SRbdStorageDriver) GetStorageType() string { - return models.STORAGE_RBD + return api.STORAGE_RBD } func (self *SRbdStorageDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { @@ -61,7 +62,7 @@ func (self *SRbdStorageDriver) ValidateCreateData(ctx context.Context, userCred } storages := []models.SStorage{} - q := models.StorageManager.Query().Equals("storage_type", models.STORAGE_RBD) + q := models.StorageManager.Query().Equals("storage_type", api.STORAGE_RBD) if err := db.FetchModelObjects(models.StorageManager, q, &storages); err != nil { return nil, httperrors.NewGeneralError(err) } @@ -83,7 +84,7 @@ func (self *SRbdStorageDriver) ValidateCreateData(ctx context.Context, userCred func (self *SRbdStorageDriver) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, storage *models.SStorage, data jsonutils.JSONObject) { storages := []models.SStorage{} - q := models.StorageManager.Query().Equals("storage_type", models.STORAGE_RBD) + q := models.StorageManager.Query().Equals("storage_type", api.STORAGE_RBD) if err := db.FetchModelObjects(models.StorageManager, q, &storages); err != nil { log.Errorf("fetch storages error: %v", err) return diff --git a/pkg/compute/tasks/baremetal_convert_hypervisor_task.go b/pkg/compute/tasks/baremetal_convert_hypervisor_task.go index 707356c9ae..3c2d3342d5 100644 --- a/pkg/compute/tasks/baremetal_convert_hypervisor_task.go +++ b/pkg/compute/tasks/baremetal_convert_hypervisor_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/cmdline" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" @@ -50,7 +51,7 @@ func (self *BaremetalConvertHypervisorTask) getHypervisor() string { func (self *BaremetalConvertHypervisorTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { baremetal := obj.(*models.SHost) - baremetal.SetStatus(self.UserCred, models.BAREMETAL_CONVERTING, "") + baremetal.SetStatus(self.UserCred, api.BAREMETAL_CONVERTING, "") self.SetStage("on_guest_deploy_complete", nil) diff --git a/pkg/compute/tasks/baremetal_delete_task.go b/pkg/compute/tasks/baremetal_delete_task.go index e77ebf58bc..1411954f68 100644 --- a/pkg/compute/tasks/baremetal_delete_task.go +++ b/pkg/compute/tasks/baremetal_delete_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -37,7 +38,7 @@ func init() { func (self *BaremetalDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { baremetal := obj.(*models.SHost) - baremetal.SetStatus(self.UserCred, models.BAREMETAL_DELETE, "") + baremetal.SetStatus(self.UserCred, api.BAREMETAL_DELETE, "") if !baremetal.IsBaremetalAgentReady() { self.OnDeleteBaremetalComplete(ctx, baremetal, nil) return @@ -66,6 +67,6 @@ func (self *BaremetalDeleteTask) OnDeleteBaremetalCompleteFailed(ctx context.Con } func (self *BaremetalDeleteTask) OnFailure(ctx context.Context, baremetal *models.SHost, body jsonutils.JSONObject) { - baremetal.SetStatus(self.UserCred, models.BAREMETAL_DELETE_FAIL, "") + baremetal.SetStatus(self.UserCred, api.BAREMETAL_DELETE_FAIL, "") self.SetStageFailed(ctx, "") } diff --git a/pkg/compute/tasks/baremetal_maintenance_task.go b/pkg/compute/tasks/baremetal_maintenance_task.go index 55f8fc4909..5ba9a712b2 100644 --- a/pkg/compute/tasks/baremetal_maintenance_task.go +++ b/pkg/compute/tasks/baremetal_maintenance_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -43,7 +44,7 @@ func (self *BaremetalMaintenanceTask) OnInit(ctx context.Context, obj db.IStanda if err != nil { self.OnEnterMaintenantModeSuccFailed(ctx, baremetal, jsonutils.NewString(err.Error())) } - baremetal.SetStatus(self.UserCred, models.BAREMETAL_MAINTAINING, "") + baremetal.SetStatus(self.UserCred, api.BAREMETAL_MAINTAINING, "") } func (self *BaremetalMaintenanceTask) OnEnterMaintenantModeSucc(ctx context.Context, baremetal *models.SHost, body jsonutils.JSONObject) { diff --git a/pkg/compute/tasks/baremetal_prepare_task.go b/pkg/compute/tasks/baremetal_prepare_task.go index def062b1b3..0b40da0b77 100644 --- a/pkg/compute/tasks/baremetal_prepare_task.go +++ b/pkg/compute/tasks/baremetal_prepare_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -45,7 +46,7 @@ func (self *BaremetalPrepareTask) OnInit(ctx context.Context, obj db.IStandalone } func (self *BaremetalPrepareTask) OnFailure(ctx context.Context, baremetal *models.SHost, reason string) { - baremetal.SetStatus(self.UserCred, models.BAREMETAL_PREPARE_FAIL, reason) + baremetal.SetStatus(self.UserCred, api.BAREMETAL_PREPARE_FAIL, reason) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/baremetal_server_rebuild_root_task.go b/pkg/compute/tasks/baremetal_server_rebuild_root_task.go index 2c9505e431..5bcc0bae2e 100644 --- a/pkg/compute/tasks/baremetal_server_rebuild_root_task.go +++ b/pkg/compute/tasks/baremetal_server_rebuild_root_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -49,8 +50,8 @@ func (self *BaremetalServerRebuildRootTask) OnStopServerComplete(ctx context.Con } func (self *BaremetalServerRebuildRootTask) StartRebuildRootDisk(ctx context.Context, guest *models.SGuest) { - if guest.Status != models.VM_ADMIN { - guest.SetStatus(self.UserCred, models.VM_REBUILD_ROOT, "") + if guest.Status != api.VM_ADMIN { + guest.SetStatus(self.UserCred, api.VM_REBUILD_ROOT, "") } imageId, _ := self.Params.GetString("image_id") db.OpsLog.LogEvent(guest, db.ACT_REBUILDING_ROOT, imageId, self.UserCred) @@ -58,7 +59,7 @@ func (self *BaremetalServerRebuildRootTask) StartRebuildRootDisk(ctx context.Con oldStatus := gds.Root.Status _, err := db.Update(gds.Root, func() error { gds.Root.TemplateId = imageId - gds.Root.Status = models.DISK_REBUILD + gds.Root.Status = api.DISK_REBUILD return nil }) if err != nil { @@ -67,7 +68,7 @@ func (self *BaremetalServerRebuildRootTask) StartRebuildRootDisk(ctx context.Con return } else { db.OpsLog.LogEvent(gds.Root, db.ACT_UPDATE_STATUS, - fmt.Sprintf("%s=>%s", oldStatus, models.DISK_REBUILD), self.UserCred) + fmt.Sprintf("%s=>%s", oldStatus, api.DISK_REBUILD), self.UserCred) } self.SetStage("OnRebuildRootDiskComplete", nil) @@ -88,8 +89,8 @@ func (self *BaremetalServerRebuildRootTask) OnRebuildRootDiskComplete(ctx contex func (self *BaremetalServerRebuildRootTask) OnRebuildRootDiskCompleteFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { db.OpsLog.LogEvent(guest, db.ACT_REBUILD_ROOT_FAIL, data, self.UserCred) - if guest.Status != models.VM_ADMIN { - guest.SetStatus(self.UserCred, models.VM_REBUILD_ROOT_FAIL, "") + if guest.Status != api.VM_ADMIN { + guest.SetStatus(self.UserCred, api.VM_REBUILD_ROOT_FAIL, "") } } diff --git a/pkg/compute/tasks/baremetal_server_start_task.go b/pkg/compute/tasks/baremetal_server_start_task.go index 83e4bf0d24..b371ef5db4 100644 --- a/pkg/compute/tasks/baremetal_server_start_task.go +++ b/pkg/compute/tasks/baremetal_server_start_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -36,7 +37,7 @@ func init() { func (self *BaremetalServerStartTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_START_START, "") + guest.SetStatus(self.UserCred, api.VM_START_START, "") db.OpsLog.LogEvent(guest, db.ACT_STARTING, "", self.UserCred) baremetal := guest.GetHost() if baremetal == nil { @@ -57,17 +58,17 @@ 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, models.VM_RUNNING, "") + guest.SetStatus(self.UserCred, api.VM_RUNNING, "") baremetal := guest.GetHost() - baremetal.SetStatus(self.UserCred, models.BAREMETAL_RUNNING, "") + baremetal.SetStatus(self.UserCred, api.BAREMETAL_RUNNING, "") db.OpsLog.LogEvent(guest, db.ACT_START, guest.GetShortDesc(ctx), self.UserCred) } func (self *BaremetalServerStartTask) OnStartCompleteFailed(ctx context.Context, guest *models.SGuest, body jsonutils.JSONObject) { reason := body.String() - guest.SetStatus(self.UserCred, models.VM_START_FAILED, reason) + guest.SetStatus(self.UserCred, api.VM_START_FAILED, reason) db.OpsLog.LogEvent(guest, db.ACT_START_FAIL, reason, self.UserCred) baremetal := guest.GetHost() - baremetal.SetStatus(self.UserCred, models.BAREMETAL_START_FAIL, reason) + baremetal.SetStatus(self.UserCred, api.BAREMETAL_START_FAIL, reason) self.SetStageFailed(ctx, reason) } diff --git a/pkg/compute/tasks/baremetal_server_stop_task.go b/pkg/compute/tasks/baremetal_server_stop_task.go index 43ddf94aab..1ef1842970 100644 --- a/pkg/compute/tasks/baremetal_server_stop_task.go +++ b/pkg/compute/tasks/baremetal_server_stop_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -37,7 +38,7 @@ func init() { func (self *BaremetalServerStopTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { guest := obj.(*models.SGuest) db.OpsLog.LogEvent(guest, db.ACT_STOPPING, "", self.UserCred) - guest.SetStatus(self.UserCred, models.VM_START_STOP, "") + guest.SetStatus(self.UserCred, api.VM_START_STOP, "") baremetal := guest.GetHost() if baremetal != nil { self.OnStopGuestFail(ctx, guest, "Baremetal is None") @@ -63,15 +64,15 @@ func (self *BaremetalServerStopTask) OnInit(ctx context.Context, obj db.IStandal } func (self *BaremetalServerStopTask) OnGuestStopTaskComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { - if guest.Status == models.VM_STOPPING { - guest.SetStatus(self.UserCred, models.VM_READY, "") + if guest.Status == api.VM_STOPPING { + guest.SetStatus(self.UserCred, api.VM_READY, "") db.OpsLog.LogEvent(guest, db.ACT_STOP, "", self.UserCred) } baremetal := guest.GetHost() - baremetal.SetStatus(self.UserCred, models.BAREMETAL_READY, "") + baremetal.SetStatus(self.UserCred, api.BAREMETAL_READY, "") self.SetStageComplete(ctx, nil) - if guest.Status == models.VM_READY { - if !jsonutils.QueryBoolean(self.Params, "reset", false) && guest.DisableDelete.IsFalse() && guest.ShutdownBehavior == models.SHUTDOWN_TERMINATE { + if guest.Status == api.VM_READY { + if !jsonutils.QueryBoolean(self.Params, "reset", false) && guest.DisableDelete.IsFalse() && guest.ShutdownBehavior == api.SHUTDOWN_TERMINATE { guest.StartAutoDeleteGuestTask(ctx, self.UserCred, "") } } @@ -81,7 +82,7 @@ func (self *BaremetalServerStopTask) OnGuestStopTaskCompleteFailed(ctx context.C guest.SetStatus(self.UserCred, db.ACT_STOP_FAIL, data.String()) db.OpsLog.LogEvent(guest, db.ACT_STOP_FAIL, data.String(), self.UserCred) baremetal := guest.GetHost() - baremetal.SetStatus(self.UserCred, models.BAREMETAL_READY, "") + baremetal.SetStatus(self.UserCred, api.BAREMETAL_READY, "") self.SetStageFailed(ctx, data.String()) } diff --git a/pkg/compute/tasks/baremetal_server_sync_status_task.go b/pkg/compute/tasks/baremetal_server_sync_status_task.go index 9d83aed3bf..c1d6eda830 100644 --- a/pkg/compute/tasks/baremetal_server_sync_status_task.go +++ b/pkg/compute/tasks/baremetal_server_sync_status_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -38,7 +39,7 @@ func (self *BaremetalServerSyncStatusTask) OnInit(ctx context.Context, obj db.IS guest := obj.(*models.SGuest) baremetal := guest.GetHost() if baremetal == nil { - guest.SetStatus(self.UserCred, models.VM_INIT, "BaremetalServerSyncStatusTask") + guest.SetStatus(self.UserCred, api.VM_INIT, "BaremetalServerSyncStatusTask") self.SetStageComplete(ctx, nil) return } @@ -59,21 +60,21 @@ func (self *BaremetalServerSyncStatusTask) OnGuestStatusTaskComplete(ctx context statusStr, _ := data.GetString("status") switch statusStr { case "running": - status = models.VM_RUNNING - hostStatus = models.HOST_STATUS_RUNNING + status = api.VM_RUNNING + hostStatus = api.HOST_STATUS_RUNNING case "stopped", "ready": - status = models.VM_READY - hostStatus = models.HOST_STATUS_READY + status = api.VM_READY + hostStatus = api.HOST_STATUS_READY case "admin": - status = models.VM_ADMIN - hostStatus = models.HOST_STATUS_RUNNING + status = api.VM_ADMIN + hostStatus = api.HOST_STATUS_RUNNING default: - status = models.VM_INIT - hostStatus = models.HOST_STATUS_UNKNOWN + status = api.VM_INIT + hostStatus = api.HOST_STATUS_UNKNOWN } } else { - status = models.VM_UNKNOWN - hostStatus = models.HOST_STATUS_UNKNOWN + status = api.VM_UNKNOWN + hostStatus = api.HOST_STATUS_UNKNOWN } guest.SetStatus(self.UserCred, status, "BaremetalServerSyncStatusTask") host := guest.GetHost() @@ -84,13 +85,13 @@ func (self *BaremetalServerSyncStatusTask) OnGuestStatusTaskComplete(ctx context func (self *BaremetalServerSyncStatusTask) OnGuestStatusTaskCompleteFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { kwargs := jsonutils.NewDict() - kwargs.Set("status", jsonutils.NewString(models.VM_UNKNOWN)) + kwargs.Set("status", jsonutils.NewString(api.VM_UNKNOWN)) guest.PerformStatus(ctx, self.UserCred, nil, kwargs) } func (self *BaremetalServerSyncStatusTask) OnGetStatusFail(ctx context.Context, guest *models.SGuest) { kwargs := jsonutils.NewDict() - kwargs.Set("status", jsonutils.NewString(models.VM_UNKNOWN)) + kwargs.Set("status", jsonutils.NewString(api.VM_UNKNOWN)) guest.PerformStatus(ctx, self.UserCred, nil, kwargs) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/baremetal_sync_status_task.go b/pkg/compute/tasks/baremetal_sync_status_task.go index 86b6258129..bc8156f92a 100644 --- a/pkg/compute/tasks/baremetal_sync_status_task.go +++ b/pkg/compute/tasks/baremetal_sync_status_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -73,7 +74,7 @@ func (self *BaremetalSyncAllGuestsStatusTask) OnInit(ctx context.Context, obj db return nil }) bs := baremetal.GetBaremetalstorage().GetStorage() - bs.SetStatus(self.UserCred, models.STORAGE_OFFLINE, "") + bs.SetStatus(self.UserCred, api.STORAGE_OFFLINE, "") if first && baremetal.Name != guest.Name { db.Update(baremetal, func() error { if models.HostManager.IsNewNameUnique(guest.Name, self.UserCred, nil) { @@ -97,8 +98,8 @@ func (self *BaremetalSyncAllGuestsStatusTask) OnInit(ctx context.Context, obj db func (self *BaremetalSyncAllGuestsStatusTask) OnGuestSyncStatusComplete(ctx context.Context, baremetal *models.SHost, body jsonutils.JSONObject) { var guests = make([]models.SGuest, 0) for _, guest := range baremetal.GetGuests() { - if guest.Status == models.VM_UNKNOWN && guest.Hypervisor != models.HYPERVISOR_BAREMETAL { - guest.SetStatus(self.UserCred, models.VM_SYNCING_STATUS, "") + if guest.Status == api.VM_UNKNOWN && guest.Hypervisor != api.HYPERVISOR_BAREMETAL { + guest.SetStatus(self.UserCred, api.VM_SYNCING_STATUS, "") guests = append(guests, guest) } } diff --git a/pkg/compute/tasks/baremetal_unconvert_hypervisor_task.go b/pkg/compute/tasks/baremetal_unconvert_hypervisor_task.go index 45ce4b3d8f..c6be22f89a 100644 --- a/pkg/compute/tasks/baremetal_unconvert_hypervisor_task.go +++ b/pkg/compute/tasks/baremetal_unconvert_hypervisor_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -36,7 +37,7 @@ func init() { func (self *BaremetalUnconvertHypervisorTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { baremetal := obj.(*models.SHost) - baremetal.SetStatus(self.UserCred, models.BAREMETAL_CONVERTING, "") + baremetal.SetStatus(self.UserCred, api.BAREMETAL_CONVERTING, "") guests := baremetal.GetGuests() if len(guests) > 1 { self.SetStageFailed(ctx, "Host guest conut > 1") diff --git a/pkg/compute/tasks/disk_batch_create_task.go b/pkg/compute/tasks/disk_batch_create_task.go index 815f1c5213..7dbce2fb19 100644 --- a/pkg/compute/tasks/disk_batch_create_task.go +++ b/pkg/compute/tasks/disk_batch_create_task.go @@ -96,10 +96,10 @@ func (self *DiskBatchCreateTask) SaveScheduleResult(ctx context.Context, obj ISc onError := func(err error) { models.QuotaManager.CancelPendingUsage(ctx, self.UserCred, disk.ProjectId, &pendingUsage, "aStorage) - disk.SetStatus(self.UserCred, models.DISK_ALLOC_FAILED, err.Error()) + disk.SetStatus(self.UserCred, api.DISK_ALLOC_FAILED, err.Error()) self.SetStageFailed(ctx, err.Error()) db.OpsLog.LogEvent(disk, db.ACT_ALLOCATE_FAIL, err, self.UserCred) - notifyclient.NotifySystemError(disk.Id, disk.Name, models.DISK_ALLOC_FAILED, err.Error()) + notifyclient.NotifySystemError(disk.Id, disk.Name, api.DISK_ALLOC_FAILED, err.Error()) } diskConfig, err := self.GetFirstDisk() @@ -112,10 +112,10 @@ func (self *DiskBatchCreateTask) SaveScheduleResult(ctx context.Context, obj ISc err = disk.SetStorage(candidate.Disks[0].StorageId, diskConfig) if err != nil { models.QuotaManager.CancelPendingUsage(ctx, self.UserCred, disk.ProjectId, &pendingUsage, "aStorage) - disk.SetStatus(self.UserCred, models.DISK_ALLOC_FAILED, err.Error()) + disk.SetStatus(self.UserCred, api.DISK_ALLOC_FAILED, err.Error()) self.SetStageFailed(ctx, err.Error()) db.OpsLog.LogEvent(disk, db.ACT_ALLOCATE_FAIL, err, self.UserCred) - notifyclient.NotifySystemError(disk.Id, disk.Name, models.DISK_ALLOC_FAILED, err.Error()) + notifyclient.NotifySystemError(disk.Id, disk.Name, api.DISK_ALLOC_FAILED, err.Error()) return } diff --git a/pkg/compute/tasks/disk_create_task.go b/pkg/compute/tasks/disk_create_task.go index 76e7c9138e..acbb477609 100644 --- a/pkg/compute/tasks/disk_create_task.go +++ b/pkg/compute/tasks/disk_create_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -64,7 +65,7 @@ func (self *DiskCreateTask) OnStorageCacheImageComplete(ctx context.Context, dis storage := disk.GetStorage() host := storage.GetMasterHost() db.OpsLog.LogEvent(disk, db.ACT_ALLOCATING, disk.GetShortDesc(ctx), self.GetUserCred()) - disk.SetStatus(self.GetUserCred(), models.DISK_STARTALLOC, "") + disk.SetStatus(self.GetUserCred(), api.DISK_STARTALLOC, "") if len(disk.BackupStorageId) > 0 { self.SetStage("OnMasterStorageCreateDiskComplete", nil) } else { @@ -81,7 +82,7 @@ func (self *DiskCreateTask) OnMasterStorageCreateDiskComplete(ctx context.Contex storage := models.StorageManager.FetchStorageById(disk.BackupStorageId) host := storage.GetMasterHost() db.OpsLog.LogEvent(disk, db.ACT_BACKUP_ALLOCATING, disk.GetShortDesc(ctx), self.GetUserCred()) - disk.SetStatus(self.UserCred, models.DISK_BACKUP_STARTALLOC, "") + disk.SetStatus(self.UserCred, api.DISK_BACKUP_STARTALLOC, "") self.SetStage("OnDiskReady", nil) if err := disk.StartAllocate(ctx, host, storage, self.GetTaskId(), self.GetUserCred(), rebuild, snapshot, self); err != nil { self.OnBackupAllocateFailed(ctx, disk, jsonutils.NewString(fmt.Sprintf("Backup disk alloctate failed: %s", err.Error()))) @@ -89,12 +90,12 @@ func (self *DiskCreateTask) OnMasterStorageCreateDiskComplete(ctx context.Contex } func (self *DiskCreateTask) OnBackupAllocateFailed(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) { - disk.SetStatus(self.UserCred, models.DISK_BACKUP_ALLOC_FAILED, data.String()) + disk.SetStatus(self.UserCred, api.DISK_BACKUP_ALLOC_FAILED, data.String()) self.SetStageFailed(ctx, data.String()) } func (self *DiskCreateTask) OnStartAllocateFailed(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) { - disk.SetStatus(self.UserCred, models.DISK_ALLOC_FAILED, data.String()) + disk.SetStatus(self.UserCred, api.DISK_ALLOC_FAILED, data.String()) self.SetStageFailed(ctx, data.String()) } @@ -109,14 +110,14 @@ func (self *DiskCreateTask) OnDiskReady(ctx context.Context, disk *models.SDisk, log.Errorf("update disk info error: %v", err) } - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") self.CleanHostSchedCache(disk) db.OpsLog.LogEvent(disk, db.ACT_ALLOCATE, disk.GetShortDesc(ctx), self.UserCred) self.SetStageComplete(ctx, nil) } func (self *DiskCreateTask) OnDiskReadyFailed(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) { - disk.SetStatus(self.UserCred, models.DISK_ALLOC_FAILED, data.String()) + disk.SetStatus(self.UserCred, api.DISK_ALLOC_FAILED, data.String()) self.SetStageFailed(ctx, data.String()) } @@ -140,7 +141,7 @@ func (self *DiskCreateBackupTask) OnInit(ctx context.Context, obj db.IStandalone func (self *DiskCreateBackupTask) OnDiskReady(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) { bkStorage := models.StorageManager.FetchStorageById(disk.BackupStorageId) bkStorage.ClearSchedDescCache() - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") db.OpsLog.LogEvent(disk, db.ACT_BACKUP_ALLOCATE, disk.GetShortDesc(ctx), self.UserCred) self.SetStageComplete(ctx, nil) } diff --git a/pkg/compute/tasks/disk_delete_task.go b/pkg/compute/tasks/disk_delete_task.go index 230c3dd193..5712315bd4 100644 --- a/pkg/compute/tasks/disk_delete_task.go +++ b/pkg/compute/tasks/disk_delete_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -59,7 +60,7 @@ func (self *DiskDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, func (self *DiskDeleteTask) startDeleteDisk(ctx context.Context, disk *models.SDisk) { db.OpsLog.LogEvent(disk, db.ACT_DELOCATING, disk.GetShortDesc(ctx), self.UserCred) - if disk.Status == models.DISK_INIT { + if disk.Status == api.DISK_INIT { self.OnGuestDiskDeleteComplete(ctx, disk, nil) return } @@ -69,7 +70,7 @@ func (self *DiskDeleteTask) startDeleteDisk(ctx context.Context, disk *models.SD if (host == nil || !host.Enabled) && jsonutils.QueryBoolean(self.Params, "purge", false) { isPurge = true } - disk.SetStatus(self.UserCred, models.DISK_DEALLOC, "") + disk.SetStatus(self.UserCred, api.DISK_DEALLOC, "") if isPurge { self.OnGuestDiskDeleteComplete(ctx, disk, nil) } else { @@ -122,7 +123,7 @@ func (self *DiskDeleteTask) OnGuestDiskDeleteComplete(ctx context.Context, obj d } func (self *DiskDeleteTask) OnGuestDiskDeleteCompleteFailed(ctx context.Context, disk *models.SDisk, resion jsonutils.JSONObject) { - disk.SetStatus(self.GetUserCred(), models.DISK_DEALLOC_FAILED, resion.String()) + disk.SetStatus(self.GetUserCred(), api.DISK_DEALLOC_FAILED, resion.String()) self.SetStageFailed(ctx, resion.String()) db.OpsLog.LogEvent(disk, db.ACT_DELOCATE_FAIL, disk.GetShortDesc(ctx), self.GetUserCred()) } diff --git a/pkg/compute/tasks/disk_reset_task.go b/pkg/compute/tasks/disk_reset_task.go index a31527b561..678caefe5a 100644 --- a/pkg/compute/tasks/disk_reset_task.go +++ b/pkg/compute/tasks/disk_reset_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -54,13 +55,13 @@ func (self *DiskResetTask) OnInit(ctx context.Context, obj db.IStandaloneModel, disk := obj.(*models.SDisk) storage := disk.GetStorage() if storage == nil { - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") self.TaskFailed(ctx, disk, "Disk storage not found") return } host := storage.GetMasterHost() if host == nil { - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") self.TaskFailed(ctx, disk, "Storage master host not found") return } @@ -70,7 +71,7 @@ func (self *DiskResetTask) OnInit(ctx context.Context, obj db.IStandaloneModel, func (self *DiskResetTask) RequestResetDisk(ctx context.Context, disk *models.SDisk, host *models.SHost) { snapshotId, err := self.Params.GetString("snapshot_id") if err != nil { - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") self.TaskFailed(ctx, disk, fmt.Sprintf("Get snapshotId error %s", err.Error())) return } @@ -90,7 +91,7 @@ func (self *DiskResetTask) RequestResetDisk(ctx context.Context, disk *models.SD self.SetStage("OnRequestResetDisk", nil) err = host.GetHostDriver().RequestResetDisk(ctx, host, disk, params, self) if err != nil { - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") self.TaskFailed(ctx, disk, err.Error()) } } @@ -124,13 +125,13 @@ func (self *DiskResetTask) OnRequestResetDisk(ctx context.Context, disk *models. self.SetStage("OnStartGuest", nil) guest.StartGueststartTask(ctx, self.UserCred, nil, self.GetTaskId()) } else { - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") self.TaskCompleted(ctx, disk, nil) } } func (self *DiskResetTask) OnStartGuest(ctx context.Context, disk *models.SDisk, data jsonutils.JSONObject) { - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") self.TaskCompleted(ctx, disk, nil) } diff --git a/pkg/compute/tasks/disk_resize_task.go b/pkg/compute/tasks/disk_resize_task.go index e31c870c1e..fc201a2c24 100644 --- a/pkg/compute/tasks/disk_resize_task.go +++ b/pkg/compute/tasks/disk_resize_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -40,7 +41,7 @@ func (self *DiskResizeTask) SetDiskReady(ctx context.Context, disk *models.SDisk // 此函数主要避免虚机更改配置时,虚机可能出现中间状态 if self.HasParentTask() { // 若是子任务,磁盘关联的虚拟机状态由父任务恢复,仅恢复磁盘自身状态即可 - disk.SetStatus(userCred, models.DISK_READY, reason) + disk.SetStatus(userCred, api.DISK_READY, reason) } else { // 若不是子任务,由于扩容时设置了关联的虚机状态,虚机的状态也由自己恢复 disk.SetDiskReady(ctx, userCred, reason) @@ -64,7 +65,7 @@ func (self *DiskResizeTask) OnInit(ctx context.Context, obj db.IStandaloneModel, } reason := "Cannot find host for disk" - if host == nil || host.HostStatus != models.HOST_ONLINE { + if host == nil || host.HostStatus != api.HOST_ONLINE { self.SetDiskReady(ctx, disk, self.GetUserCred(), reason) self.SetStageFailed(ctx, reason) db.OpsLog.LogEvent(disk, db.ACT_RESIZE_FAIL, reason, self.GetUserCred()) @@ -72,9 +73,9 @@ func (self *DiskResizeTask) OnInit(ctx context.Context, obj db.IStandaloneModel, return } - disk.SetStatus(self.GetUserCred(), models.DISK_START_RESIZE, "") + disk.SetStatus(self.GetUserCred(), api.DISK_START_RESIZE, "") if masterGuest != nil { - masterGuest.SetStatus(self.GetUserCred(), models.VM_RESIZE_DISK, "") + masterGuest.SetStatus(self.GetUserCred(), api.VM_RESIZE_DISK, "") } self.StartResizeDisk(ctx, host, storage, disk, masterGuest) } @@ -92,7 +93,7 @@ func (self *DiskResizeTask) StartResizeDisk(ctx context.Context, host *models.SH } func (self *DiskResizeTask) OnStartResizeDiskSucc(ctx context.Context, disk *models.SDisk) { - disk.SetStatus(self.GetUserCred(), models.DISK_RESIZING, "") + disk.SetStatus(self.GetUserCred(), api.DISK_RESIZING, "") } func (self *DiskResizeTask) OnStartResizeDiskFailed(ctx context.Context, disk *models.SDisk, reason error) { @@ -117,7 +118,7 @@ func (self *DiskResizeTask) OnDiskResizeComplete(ctx context.Context, disk *mode } oldStatus := disk.Status _, err = db.Update(disk, func() error { - disk.Status = models.DISK_READY + disk.Status = api.DISK_READY disk.DiskSize = int(sizeMb) return nil }) @@ -166,7 +167,7 @@ func (self *DiskResizeTask) OnDiskResizeCompleteFailed(ctx context.Context, disk guestId, _ := self.Params.GetString("guest_id") if len(guestId) > 0 { masterGuest := models.GuestManager.FetchGuestById(guestId) - masterGuest.SetStatus(self.UserCred, models.VM_RESIZE_DISK_FAILED, data.String()) + masterGuest.SetStatus(self.UserCred, api.VM_RESIZE_DISK_FAILED, data.String()) } self.SetStageFailed(ctx, data.String()) } diff --git a/pkg/compute/tasks/disk_save_task.go b/pkg/compute/tasks/disk_save_task.go index 43f771d81b..adf1d8d1d2 100644 --- a/pkg/compute/tasks/disk_save_task.go +++ b/pkg/compute/tasks/disk_save_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -57,9 +58,9 @@ func (self *DiskSaveTask) OnInit(ctx context.Context, obj db.IStandaloneModel, d self.TaskFailed(ctx, resion) db.OpsLog.LogEvent(disk, db.ACT_SAVE_FAIL, resion, self.GetUserCred()) } else { - disk.SetStatus(self.GetUserCred(), models.DISK_START_SAVE, "") + disk.SetStatus(self.GetUserCred(), api.DISK_START_SAVE, "") for _, guest := range disk.GetGuests() { - guest.SetStatus(self.GetUserCred(), models.VM_SAVE_DISK, "") + guest.SetStatus(self.GetUserCred(), api.VM_SAVE_DISK, "") } self.StartBackupDisk(ctx, disk, host) } @@ -67,7 +68,7 @@ func (self *DiskSaveTask) OnInit(ctx context.Context, obj db.IStandaloneModel, d func (self *DiskSaveTask) StartBackupDisk(ctx context.Context, disk *models.SDisk, host *models.SHost) { self.SetStage("on_disk_backup_complete", nil) - disk.SetStatus(self.GetUserCred(), models.DISK_SAVING, "") + disk.SetStatus(self.GetUserCred(), api.DISK_SAVING, "") imageId, _ := self.GetParams().GetString("image_id") if err := host.GetHostDriver().RequestPrepareSaveDiskOnHost(ctx, host, disk, imageId, self); err != nil { log.Errorf("Backup failed: %v", err) diff --git a/pkg/compute/tasks/eip_allocate_task.go b/pkg/compute/tasks/eip_allocate_task.go index 791e8c26e9..d60740449e 100644 --- a/pkg/compute/tasks/eip_allocate_task.go +++ b/pkg/compute/tasks/eip_allocate_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -49,7 +50,7 @@ func (self *EipAllocateTask) setGuestAllocateEipFailed(resion string) { return } guest := instance.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_ASSOCIATE_EIP_FAILED, resion) + guest.SetStatus(self.UserCred, api.VM_ASSOCIATE_EIP_FAILED, resion) } } @@ -68,7 +69,7 @@ func (self *EipAllocateTask) OnInit(ctx context.Context, obj db.IStandaloneModel iregion, err := eip.GetIRegion() if err != nil { msg := fmt.Sprintf("fail to find iregion for eip %s", err) - eip.SetStatus(self.UserCred, models.EIP_STATUS_ALLOCATE_FAIL, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_ALLOCATE_FAIL, msg) self.onFailed(ctx, msg) return } @@ -76,7 +77,7 @@ func (self *EipAllocateTask) OnInit(ctx context.Context, obj db.IStandaloneModel extEip, err := iregion.CreateEIP(eip.Name, eip.Bandwidth, eip.ChargeType, eip.BgpType) if err != nil { msg := fmt.Sprintf("create eip fail %s", err) - eip.SetStatus(self.UserCred, models.EIP_STATUS_ALLOCATE_FAIL, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_ALLOCATE_FAIL, msg) self.onFailed(ctx, msg) return } @@ -85,7 +86,7 @@ func (self *EipAllocateTask) OnInit(ctx context.Context, obj db.IStandaloneModel if err != nil { msg := fmt.Sprintf("sync eip fail %s", err) - eip.SetStatus(self.UserCred, models.EIP_STATUS_ALLOCATE_FAIL, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_ALLOCATE_FAIL, msg) self.onFailed(ctx, msg) return } diff --git a/pkg/compute/tasks/eip_associate_task.go b/pkg/compute/tasks/eip_associate_task.go index ae505db5d3..7a678dd792 100644 --- a/pkg/compute/tasks/eip_associate_task.go +++ b/pkg/compute/tasks/eip_associate_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -34,10 +35,10 @@ func init() { } func (self *EipAssociateTask) TaskFail(ctx context.Context, eip *models.SElasticip, msg string, vm *models.SGuest) { - eip.SetStatus(self.UserCred, models.EIP_STATUS_READY, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_READY, msg) self.SetStageFailed(ctx, msg) if vm != nil { - vm.SetStatus(self.UserCred, models.VM_ASSOCIATE_EIP_FAILED, msg) + vm.SetStatus(self.UserCred, api.VM_ASSOCIATE_EIP_FAILED, msg) } } @@ -53,8 +54,8 @@ func (self *EipAssociateTask) OnInit(ctx context.Context, obj db.IStandaloneMode return } - if server.Status != models.VM_ASSOCIATE_EIP { - server.SetStatus(self.UserCred, models.VM_ASSOCIATE_EIP, "associate eip") + if server.Status != api.VM_ASSOCIATE_EIP { + server.SetStatus(self.UserCred, api.VM_ASSOCIATE_EIP, "associate eip") } extEip, err := eip.GetIEip() @@ -78,7 +79,7 @@ func (self *EipAssociateTask) OnInit(ctx context.Context, obj db.IStandaloneMode return } - eip.SetStatus(self.UserCred, models.EIP_STATUS_READY, "associate") + eip.SetStatus(self.UserCred, api.EIP_STATUS_READY, "associate") server.StartSyncstatus(ctx, self.UserCred, "") diff --git a/pkg/compute/tasks/eip_change_bandwidth_task.go b/pkg/compute/tasks/eip_change_bandwidth_task.go index 00538d3385..a202a67edd 100644 --- a/pkg/compute/tasks/eip_change_bandwidth_task.go +++ b/pkg/compute/tasks/eip_change_bandwidth_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -38,7 +39,7 @@ func (self *EipChangeBandwidthTask) OnInit(ctx context.Context, obj db.IStandalo extEip, err := eip.GetIEip() if err != nil { - eip.SetStatus(self.UserCred, models.EIP_STATUS_READY, "fail to change bandwidth") + eip.SetStatus(self.UserCred, api.EIP_STATUS_READY, "fail to change bandwidth") msg := fmt.Sprintf("fail to find iEip %s", err) self.SetStageFailed(ctx, msg) return @@ -46,7 +47,7 @@ func (self *EipChangeBandwidthTask) OnInit(ctx context.Context, obj db.IStandalo bandwidth, _ := self.Params.Int("bandwidth") if bandwidth <= 0 { - eip.SetStatus(self.UserCred, models.EIP_STATUS_READY, "fail to change bandwidth") + eip.SetStatus(self.UserCred, api.EIP_STATUS_READY, "fail to change bandwidth") msg := fmt.Sprintf("invalid bandwidth %d", bandwidth) self.SetStageFailed(ctx, msg) return @@ -55,7 +56,7 @@ func (self *EipChangeBandwidthTask) OnInit(ctx context.Context, obj db.IStandalo err = extEip.ChangeBandwidth(int(bandwidth)) if err != nil { - eip.SetStatus(self.UserCred, models.EIP_STATUS_READY, "fail to change bandwidth") + eip.SetStatus(self.UserCred, api.EIP_STATUS_READY, "fail to change bandwidth") msg := fmt.Sprintf("fail to find iEip %s", err) self.SetStageFailed(ctx, msg) return diff --git a/pkg/compute/tasks/eip_deallocate_task.go b/pkg/compute/tasks/eip_deallocate_task.go index 95b6fbf68f..44d4ada59e 100644 --- a/pkg/compute/tasks/eip_deallocate_task.go +++ b/pkg/compute/tasks/eip_deallocate_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -42,7 +43,7 @@ func (self *EipDeallocateTask) OnInit(ctx context.Context, obj db.IStandaloneMod if err != nil { if err != cloudprovider.ErrNotFound && err != cloudprovider.ErrInvalidProvider { msg := fmt.Sprintf("fail to find iEIP for eip %s", err) - eip.SetStatus(self.UserCred, models.EIP_STATUS_DEALLOCATE_FAIL, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_DEALLOCATE_FAIL, msg) self.SetStageFailed(ctx, msg) return } @@ -50,7 +51,7 @@ func (self *EipDeallocateTask) OnInit(ctx context.Context, obj db.IStandaloneMod err = expEip.Delete() if err != nil { msg := fmt.Sprintf("fail to delete iEIP %s", err) - eip.SetStatus(self.UserCred, models.EIP_STATUS_DEALLOCATE_FAIL, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_DEALLOCATE_FAIL, msg) self.SetStageFailed(ctx, msg) return } @@ -60,7 +61,7 @@ func (self *EipDeallocateTask) OnInit(ctx context.Context, obj db.IStandaloneMod err := eip.RealDelete(ctx, self.UserCred) if err != nil { msg := fmt.Sprintf("fail to delete EIP %s", err) - eip.SetStatus(self.UserCred, models.EIP_STATUS_DEALLOCATE_FAIL, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_DEALLOCATE_FAIL, msg) self.SetStageFailed(ctx, msg) return } diff --git a/pkg/compute/tasks/eip_dissociate_task.go b/pkg/compute/tasks/eip_dissociate_task.go index 9d8cabfe2f..1bcbaab788 100644 --- a/pkg/compute/tasks/eip_dissociate_task.go +++ b/pkg/compute/tasks/eip_dissociate_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -35,10 +36,10 @@ func init() { } func (self *EipDissociateTask) TaskFail(ctx context.Context, eip *models.SElasticip, msg string, vm *models.SGuest) { - eip.SetStatus(self.UserCred, models.EIP_STATUS_READY, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_READY, msg) self.SetStageFailed(ctx, msg) if vm != nil { - vm.SetStatus(self.UserCred, models.VM_DISSOCIATE_EIP_FAILED, msg) + vm.SetStatus(self.UserCred, api.VM_DISSOCIATE_EIP_FAILED, msg) } } @@ -48,8 +49,8 @@ func (self *EipDissociateTask) OnInit(ctx context.Context, obj db.IStandaloneMod server := eip.GetAssociateVM() if server != nil { - if server.Status != models.VM_DISSOCIATE_EIP { - server.SetStatus(self.UserCred, models.VM_DISSOCIATE_EIP, "dissociate eip") + if server.Status != api.VM_DISSOCIATE_EIP { + server.SetStatus(self.UserCred, api.VM_DISSOCIATE_EIP, "dissociate eip") } extEip, err := eip.GetIEip() @@ -75,7 +76,7 @@ func (self *EipDissociateTask) OnInit(ctx context.Context, obj db.IStandaloneMod return } - eip.SetStatus(self.UserCred, models.EIP_STATUS_READY, "dissociate") + eip.SetStatus(self.UserCred, api.EIP_STATUS_READY, "dissociate") server.StartSyncstatus(ctx, self.UserCred, "") } diff --git a/pkg/compute/tasks/eip_syncstatus_task.go b/pkg/compute/tasks/eip_syncstatus_task.go index 5da786dfca..7860571e7f 100644 --- a/pkg/compute/tasks/eip_syncstatus_task.go +++ b/pkg/compute/tasks/eip_syncstatus_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -39,7 +40,7 @@ func (self *EipSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneMod extEip, err := eip.GetIEip() if err != nil { msg := fmt.Sprintf("fail to find ieip for eip %s", err) - eip.SetStatus(self.UserCred, models.EIP_STATUS_UNKNOWN, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_UNKNOWN, msg) self.SetStageFailed(ctx, msg) return } @@ -47,7 +48,7 @@ func (self *EipSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneMod err = extEip.Refresh() if err != nil { msg := fmt.Sprintf("fail to refresh eip status %s", err) - eip.SetStatus(self.UserCred, models.EIP_STATUS_UNKNOWN, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_UNKNOWN, msg) self.SetStageFailed(ctx, msg) return } @@ -55,7 +56,7 @@ func (self *EipSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneMod err = eip.SyncWithCloudEip(ctx, self.UserCred, eip.GetCloudprovider(), extEip, "") if err != nil { msg := fmt.Sprintf("fail to sync eip status %s", err) - eip.SetStatus(self.UserCred, models.EIP_STATUS_UNKNOWN, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_UNKNOWN, msg) self.SetStageFailed(ctx, msg) return } @@ -63,7 +64,7 @@ func (self *EipSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneMod err = eip.SyncInstanceWithCloudEip(ctx, self.UserCred, extEip) if err != nil { msg := fmt.Sprintf("fail to sync eip status %s", err) - eip.SetStatus(self.UserCred, models.EIP_STATUS_UNKNOWN, msg) + eip.SetStatus(self.UserCred, api.EIP_STATUS_UNKNOWN, msg) self.SetStageFailed(ctx, msg) return } diff --git a/pkg/compute/tasks/guest_attach_disk_task.go b/pkg/compute/tasks/guest_attach_disk_task.go index ea6790473b..c6e32767ea 100644 --- a/pkg/compute/tasks/guest_attach_disk_task.go +++ b/pkg/compute/tasks/guest_attach_disk_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -58,7 +59,7 @@ func (self *GuestAttachDiskTask) OnInit(ctx context.Context, obj db.IStandaloneM self.OnTaskFail(ctx, guest, nil, err) return } - disk.SetStatus(self.UserCred, models.DISK_ATTACHING, "Disk attach") + disk.SetStatus(self.UserCred, api.DISK_ATTACHING, "Disk attach") self.SetStage("on_sync_config_complete", nil) guest.GetDriver().RequestAttachDisk(ctx, guest, self) } @@ -75,7 +76,7 @@ func (self *GuestAttachDiskTask) OnSyncConfigComplete(ctx context.Context, guest self.OnTaskFail(ctx, guest, nil, fmt.Errorf("Connot find disk %s", diskId)) return } - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") self.SetStageComplete(ctx, nil) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_ATTACH_DISK, nil, self.UserCred, true) } @@ -90,16 +91,16 @@ func (self *GuestAttachDiskTask) OnSyncConfigCompleteFailed(ctx context.Context, } disk := objDisk.(*models.SDisk) db.OpsLog.LogEvent(disk, db.ACT_ATTACH, resion.String(), self.UserCred) - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") guest.DetachDisk(ctx, disk, self.UserCred) self.OnTaskFail(ctx, guest, disk, fmt.Errorf(resion.String())) } func (self *GuestAttachDiskTask) OnTaskFail(ctx context.Context, guest *models.SGuest, disk *models.SDisk, err error) { if disk != nil { - disk.SetStatus(self.UserCred, models.DISK_READY, "") + disk.SetStatus(self.UserCred, api.DISK_READY, "") } - guest.SetStatus(self.UserCred, models.VM_ATTACH_DISK_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_ATTACH_DISK_FAILED, err.Error()) self.SetStageFailed(ctx, err.Error()) log.Errorf("Guest %s GuestAttachDiskTask failed %s", guest.Name, err.Error()) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_ATTACH_DISK, err.Error(), self.UserCred, false) diff --git a/pkg/compute/tasks/guest_backup_tasks.go b/pkg/compute/tasks/guest_backup_tasks.go index ee5ef3aaa0..c41372061e 100644 --- a/pkg/compute/tasks/guest_backup_tasks.go +++ b/pkg/compute/tasks/guest_backup_tasks.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" schedapi "yunion.io/x/onecloud/pkg/apis/scheduler" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" @@ -99,7 +100,7 @@ func (self *GuestSwitchToBackupTask) OnNewMasterStarted(ctx context.Context, gue } func (self *GuestSwitchToBackupTask) OnFail(ctx context.Context, guest *models.SGuest, reason string) { - guest.SetStatus(self.UserCred, models.VM_SWITCH_TO_BACKUP_FAILED, reason) + guest.SetStatus(self.UserCred, api.VM_SWITCH_TO_BACKUP_FAILED, reason) db.OpsLog.LogEvent(guest, db.ACT_SWITCH_FAILED, reason, self.UserCred) logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_SWITCH_TO_BACKUP, reason, self.UserCred, false) self.SetStageFailed(ctx, reason) @@ -107,7 +108,7 @@ func (self *GuestSwitchToBackupTask) OnFail(ctx context.Context, guest *models.S func (self *GuestSwitchToBackupTask) OnSwitched(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { oldStatus, _ := self.Params.GetString("old_status") - if utils.IsInStringArray(oldStatus, models.VM_RUNNING_STATUS) { + if utils.IsInStringArray(oldStatus, api.VM_RUNNING_STATUS) { self.SetStage("OnNewMasterStarted", nil) guest.StartGueststartTask(ctx, self.UserCred, nil, self.GetTaskId()) } else { @@ -163,7 +164,7 @@ func (self *GuestStartAndSyncToBackupTask) OnStartBackupGuest(ctx context.Contex guest.SetMetadata(ctx, "backup_nbd_server_uri", nbdServerUri, self.UserCred) db.OpsLog.LogEvent(guest, db.ACT_BACKUP_START, "", self.UserCred) - if utils.IsInStringArray(guest.Status, models.VM_RUNNING_STATUS) { + if utils.IsInStringArray(guest.Status, api.VM_RUNNING_STATUS) { self.SetStage("OnRequestSyncToBackup", nil) err := guest.GetDriver().RequestSyncToBackup(ctx, guest, self) if err != nil { @@ -180,7 +181,7 @@ func (self *GuestStartAndSyncToBackupTask) OnStartBackupGuestFailed(ctx context. } func (self *GuestStartAndSyncToBackupTask) OnRequestSyncToBackup(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { - guest.SetStatus(self.UserCred, models.VM_BLOCK_STREAM, "OnSyncToBackup") + guest.SetStatus(self.UserCred, api.VM_BLOCK_STREAM, "OnSyncToBackup") self.SetStageComplete(ctx, nil) } @@ -194,7 +195,7 @@ func (self *GuestCreateBackupTask) OnInit(ctx context.Context, obj db.IStandalon func (self *GuestCreateBackupTask) OnStartSchedule(obj IScheduleModel) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_BACKUP_CREATING, "") + guest.SetStatus(self.UserCred, api.VM_BACKUP_CREATING, "") db.OpsLog.LogEvent(guest, db.ACT_START_CREATE_BACKUP, "", self.UserCred) } @@ -231,7 +232,7 @@ func (self *GuestCreateBackupTask) SaveScheduleResult(ctx context.Context, obj I db.OpsLog.LogEvent(guest, db.ACT_CREATE_BACKUP, fmt.Sprintf("guest backup start create on host %s", targetHostId), self.UserCred) // backup disk only support disk backend local - storage := guest.GetDriver().ChooseHostStorage(targetHost, models.STORAGE_LOCAL) + storage := guest.GetDriver().ChooseHostStorage(targetHost, api.STORAGE_LOCAL) if storage == nil { self.TaskFailed(ctx, guest, "Get backup storage error") return @@ -289,7 +290,7 @@ func (self *GuestCreateBackupTask) OnCreateBackupFailed(ctx context.Context, gue func (self *GuestCreateBackupTask) OnCreateBackup(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { guestStatus, _ := self.Params.GetString("guest_status") guest.SetStatus(self.UserCred, guestStatus, "") - if utils.IsInStringArray(guestStatus, models.VM_RUNNING_STATUS) { + if utils.IsInStringArray(guestStatus, api.VM_RUNNING_STATUS) { self.OnGuestStart(ctx, guest, nil) } else { self.TaskCompleted(ctx, guest, "") @@ -315,7 +316,7 @@ func (self *GuestCreateBackupTask) TaskCompleted(ctx context.Context, guest *mod } func (self *GuestCreateBackupTask) TaskFailed(ctx context.Context, guest *models.SGuest, reason string) { - guest.SetStatus(self.UserCred, models.VM_BACKUP_CREATE_FAILED, reason) + guest.SetStatus(self.UserCred, api.VM_BACKUP_CREATE_FAILED, reason) db.OpsLog.LogEvent(guest, db.ACT_CREATE_BACKUP_FAILED, reason, self.UserCred) logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_CREATE_BACKUP, reason, self.UserCred, false) self.SetStageFailed(ctx, reason) diff --git a/pkg/compute/tasks/guest_batch_create_task.go b/pkg/compute/tasks/guest_batch_create_task.go index 53ef127f7b..7cf633716f 100644 --- a/pkg/compute/tasks/guest_batch_create_task.go +++ b/pkg/compute/tasks/guest_batch_create_task.go @@ -79,7 +79,7 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest input, err = host.SetGuestCreateNetworkAndDiskParams(ctx, self.UserCred, input) if err != nil { log.Errorf("host.SetGuestCreateNetworkAndDiskParams fail %s", err) - guest.SetStatus(self.UserCred, models.VM_CREATE_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_CREATE_FAILED, err.Error()) return err } params := input.JSON(input) @@ -88,7 +88,7 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest input, err = self.GetCreateInput() if err != nil { - guest.SetStatus(self.UserCred, models.VM_CREATE_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_CREATE_FAILED, err.Error()) return err } err = guest.CreateNetworksOnHost(ctx, self.UserCred, host, input.Networks, &pendingUsage) @@ -96,7 +96,7 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest if err != nil { log.Errorf("Network failed: %s", err) - guest.SetStatus(self.UserCred, models.VM_NETWORK_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_NETWORK_FAILED, err.Error()) return err } @@ -106,7 +106,7 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest if err != nil { log.Errorf("Disk create failed: %s", err) - guest.SetStatus(self.UserCred, models.VM_DISK_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_DISK_FAILED, err.Error()) return err } @@ -115,7 +115,7 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest if err != nil { log.Errorf("IsolatedDevices create failed: %s", err) - guest.SetStatus(self.UserCred, models.VM_DEVICE_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_DEVICE_FAILED, err.Error()) return err } @@ -125,7 +125,7 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest err := host.RebuildRecycledGuest(ctx, self.UserCred, guest) if err != nil { log.Errorf("start guest create task fail %s", err) - guest.SetStatus(self.UserCred, models.VM_CREATE_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_CREATE_FAILED, err.Error()) return err } @@ -138,7 +138,7 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest err = guest.StartRebuildRootTask(ctx, self.UserCred, "", false, autoStart, passwd, resetPassword, true) if err != nil { log.Errorf("start guest create task fail %s", err) - guest.SetStatus(self.UserCred, models.VM_CREATE_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_CREATE_FAILED, err.Error()) return err } return nil @@ -147,7 +147,7 @@ func (self *GuestBatchCreateTask) allocateGuestOnHost(ctx context.Context, guest err = guest.StartGuestCreateTask(ctx, self.UserCred, input, nil, self.GetId()) if err != nil { log.Errorf("start guest create task fail %s", err) - guest.SetStatus(self.UserCred, models.VM_CREATE_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_CREATE_FAILED, err.Error()) return err } return nil @@ -165,7 +165,7 @@ func (self *GuestBatchCreateTask) SaveScheduleResult(ctx context.Context, obj IS if err != nil { db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, err, self.UserCred) logclient.AddActionLogWithStartable(self, obj, logclient.ACT_ALLOCATE, err.Error(), self.GetUserCred(), false) - notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_CREATE_FAILED, err.Error()) + notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_CREATE_FAILED, err.Error()) self.SetStageFailed(ctx, err.Error()) } } diff --git a/pkg/compute/tasks/guest_change_config_task.go b/pkg/compute/tasks/guest_change_config_task.go index ad72fbc5d0..1dee670c2f 100644 --- a/pkg/compute/tasks/guest_change_config_task.go +++ b/pkg/compute/tasks/guest_change_config_task.go @@ -241,7 +241,7 @@ func (self *GuestChangeConfigTask) OnSyncConfigComplete(ctx context.Context, obj func (self *GuestChangeConfigTask) OnSyncStatusComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { guest := obj.(*models.SGuest) - if guest.Status == models.VM_READY && jsonutils.QueryBoolean(self.Params, "auto_start", false) { + if guest.Status == api.VM_READY && jsonutils.QueryBoolean(self.Params, "auto_start", false) { self.SetStage("on_guest_start_complete", nil) guest.StartGueststartTask(ctx, self.UserCred, nil, self.GetTaskId()) } else { @@ -260,7 +260,7 @@ func (self *GuestChangeConfigTask) OnGuestStartComplete(ctx context.Context, obj } func (self *GuestChangeConfigTask) markStageFailed(ctx context.Context, guest *models.SGuest, reason string) { - guest.SetStatus(self.UserCred, models.VM_CHANGE_FLAVOR_FAIL, reason) + guest.SetStatus(self.UserCred, api.VM_CHANGE_FLAVOR_FAIL, reason) db.OpsLog.LogEvent(guest, db.ACT_CHANGE_FLAVOR_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_CHANGE_FLAVOR, reason, self.UserCred, false) self.SetStageFailed(ctx, reason) diff --git a/pkg/compute/tasks/guest_create_disk_task.go b/pkg/compute/tasks/guest_create_disk_task.go index 5baaf2dfc9..958107919b 100644 --- a/pkg/compute/tasks/guest_create_disk_task.go +++ b/pkg/compute/tasks/guest_create_disk_task.go @@ -85,7 +85,7 @@ func (self *KVMGuestCreateDiskTask) OnKvmDiskPrepared(ctx context.Context, obj d return } disk := iDisk.(*models.SDisk) - if disk.Status == models.DISK_INIT { + if disk.Status == api.DISK_INIT { snapshotId := d.SnapshotId err = disk.StartDiskCreateTask(ctx, self.UserCred, false, snapshotId, self.GetTaskId()) if err != nil { @@ -111,14 +111,14 @@ func (self *KVMGuestCreateDiskTask) OnKvmDiskPrepared(ctx context.Context, obj d return } disk := iDisk.(*models.SDisk) - if disk.Status != models.DISK_READY { + if disk.Status != api.DISK_READY { diskReady = false break } } if diskReady { guest := obj.(*models.SGuest) - if guest.Status == models.VM_RUNNING { + if guest.Status == api.VM_RUNNING { self.SetStage("on_config_sync_complete", nil) err := guest.StartSyncTask(ctx, self.UserCred, false, self.GetTaskId()) if err != nil { @@ -168,7 +168,7 @@ func (self *ManagedGuestCreateDiskTask) OnManagedDiskPrepared(ctx context.Contex return } disk := iDisk.(*models.SDisk) - if disk.Status == models.DISK_INIT { + if disk.Status == api.DISK_INIT { snapshot := d.SnapshotId err = disk.StartDiskCreateTask(ctx, self.UserCred, false, snapshot, self.GetTaskId()) if err != nil { @@ -189,7 +189,7 @@ func (self *ManagedGuestCreateDiskTask) OnManagedDiskPrepared(ctx context.Contex return } disk := iDisk.(*models.SDisk) - if disk.Status != models.DISK_READY { + if disk.Status != api.DISK_READY { self.SetStageFailed(ctx, fmt.Sprintf("disk %s is not ready", disk.Id)) return } @@ -247,7 +247,7 @@ func (self *ESXiGuestCreateDiskTask) OnInit(ctx context.Context, obj db.IStandal self.SetStageFailed(ctx, fmt.Sprintf("Disk %s not found", diskId)) return } - if disk.Status != models.DISK_INIT { + if disk.Status != api.DISK_INIT { self.SetStageFailed(ctx, fmt.Sprintf("Disk %s already created??", diskId)) return } @@ -282,7 +282,7 @@ func (self *ESXiGuestCreateDiskTask) OnInit(ctx context.Context, obj db.IStandal return } - disk.SetStatus(self.UserCred, models.DISK_READY, "create disk success") + disk.SetStatus(self.UserCred, api.DISK_READY, "create disk success") disk.GetStorage().ClearSchedDescCache() db.OpsLog.LogEvent(disk, db.ACT_ALLOCATE, disk.GetShortDesc(ctx), self.UserCred) db.OpsLog.LogAttachEvent(ctx, guest, disk, self.UserCred, disk.GetShortDesc(ctx)) diff --git a/pkg/compute/tasks/guest_create_task.go b/pkg/compute/tasks/guest_create_task.go index 8777481d96..9a22ab481c 100644 --- a/pkg/compute/tasks/guest_create_task.go +++ b/pkg/compute/tasks/guest_create_task.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudcommon/notifyclient" @@ -40,7 +41,7 @@ func init() { func (self *GuestCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_CREATE_NETWORK, "") + guest.SetStatus(self.UserCred, api.VM_CREATE_NETWORK, "") self.SetStage("on_wait_guest_networks_ready", nil) self.OnWaitGuestNetworksReady(ctx, obj, nil) } @@ -57,17 +58,17 @@ func (self *GuestCreateTask) OnWaitGuestNetworksReady(ctx context.Context, obj d } func (self *GuestCreateTask) OnGuestNetworkReady(ctx context.Context, guest *models.SGuest) { - guest.SetStatus(self.UserCred, models.VM_CREATE_DISK, "") + guest.SetStatus(self.UserCred, api.VM_CREATE_DISK, "") self.SetStage("OnDiskPrepared", nil) guest.GetDriver().RequestGuestCreateAllDisks(ctx, guest, self) } func (self *GuestCreateTask) OnDiskPreparedFailed(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_DISK_FAILED, "allocation failed") + guest.SetStatus(self.UserCred, api.VM_DISK_FAILED, "allocation failed") db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, data, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_ALLOCATE, data, self.UserCred, false) - notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_DISK_FAILED, data.String()) + notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_DISK_FAILED, data.String()) self.SetStageFailed(ctx, data.String()) } @@ -87,16 +88,16 @@ func (self *GuestCreateTask) OnCdromPrepared(ctx context.Context, obj db.IStanda log.Infof("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") log.Infof("DEPLOY GUEST %s", guest.Name) log.Infof("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") - guest.SetStatus(self.UserCred, models.VM_DEPLOYING, "") + guest.SetStatus(self.UserCred, api.VM_DEPLOYING, "") self.StartDeployGuest(ctx, guest) } func (self *GuestCreateTask) OnCdromPreparedFailed(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_DISK_FAILED, "") + guest.SetStatus(self.UserCred, api.VM_DISK_FAILED, "") db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, data, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_ALLOCATE, data, self.UserCred, false) - notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_DISK_FAILED, fmt.Sprintf("cdrom_failed %s", data)) + notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_DISK_FAILED, fmt.Sprintf("cdrom_failed %s", data)) self.SetStageFailed(ctx, fmt.Sprintf("cdrom_failed %s", data)) } @@ -121,10 +122,10 @@ func (self *GuestCreateTask) notifyServerCreated(ctx context.Context, guest *mod func (self *GuestCreateTask) OnDeployGuestDescCompleteFailed(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_DEPLOY_FAILED, "deploy_failed") + guest.SetStatus(self.UserCred, api.VM_DEPLOY_FAILED, "deploy_failed") db.OpsLog.LogEvent(guest, db.ACT_ALLOCATE_FAIL, data, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_ALLOCATE, data, self.UserCred, false) - notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_DEPLOY_FAILED, data.String()) + notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_DEPLOY_FAILED, data.String()) self.SetStageFailed(ctx, data.String()) } diff --git a/pkg/compute/tasks/guest_delete_task.go b/pkg/compute/tasks/guest_delete_task.go index a8bffaeccd..8ee1cece9e 100644 --- a/pkg/compute/tasks/guest_delete_task.go +++ b/pkg/compute/tasks/guest_delete_task.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudcommon/notifyclient" @@ -42,7 +43,7 @@ func init() { func (self *GuestDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { guest := obj.(*models.SGuest) host := guest.GetHost() - if guest.Hypervisor == models.HYPERVISOR_BAREMETAL && host != nil && host.HostType != models.HOST_TYPE_BAREMETAL { + 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, obj, data) return @@ -80,7 +81,7 @@ func (self *GuestDeleteTask) OnGuestStopComplete(ctx context.Context, obj db.ISt guest := obj.(*models.SGuest) eip, _ := guest.GetEip() - if eip != nil && eip.Mode != models.EIP_MODE_INSTANCE_PUBLICIP { + if eip != nil && eip.Mode != api.EIP_MODE_INSTANCE_PUBLICIP { // detach floating EIP only if jsonutils.QueryBoolean(self.Params, "purge", false) { // purge locally @@ -157,8 +158,8 @@ func (self *GuestDeleteTask) OnSyncConfigComplete(ctx context.Context, obj db.IS log.Debugf("XXXXXXX Do guest pending delete... XXXXXXX") guestStatus, _ := self.Params.GetString("guest_status") if !utils.IsInStringArray(guestStatus, []string{ - models.VM_SCHEDULE_FAILED, models.VM_NETWORK_FAILED, models.VM_DISK_FAILED, - models.VM_CREATE_FAILED, models.VM_DEVICE_FAILED}) { + api.VM_SCHEDULE_FAILED, api.VM_NETWORK_FAILED, api.VM_DISK_FAILED, + api.VM_CREATE_FAILED, api.VM_DEVICE_FAILED}) { self.StartPendingDeleteGuest(ctx, guest) return } @@ -180,7 +181,7 @@ func (self *GuestDeleteTask) OnGuestDeleteFailed(ctx context.Context, obj db.ISt func (self *GuestDeleteTask) doStartDeleteGuest(ctx context.Context, obj db.IStandaloneModel) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_DELETING, "delete server after stop") + guest.SetStatus(self.UserCred, api.VM_DELETING, "delete server after stop") db.OpsLog.LogEvent(guest, db.ACT_DELOCATING, nil, self.UserCred) self.StartDeleteGuest(ctx, guest) } @@ -246,7 +247,7 @@ func (self *GuestDeleteTask) DoDeleteGuest(ctx context.Context, guest *models.SG } func (self *GuestDeleteTask) OnFailed(ctx context.Context, guest *models.SGuest, err jsonutils.JSONObject) { - guest.SetStatus(self.UserCred, models.VM_DELETE_FAIL, err.String()) + guest.SetStatus(self.UserCred, api.VM_DELETE_FAIL, err.String()) db.OpsLog.LogEvent(guest, db.ACT_DELOCATE_FAIL, err, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_DELOCATE, err, self.UserCred, false) self.SetStageFailed(ctx, err.String()) diff --git a/pkg/compute/tasks/guest_deploy_task.go b/pkg/compute/tasks/guest_deploy_task.go index b525e560f0..f25aeede05 100644 --- a/pkg/compute/tasks/guest_deploy_task.go +++ b/pkg/compute/tasks/guest_deploy_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -72,7 +73,7 @@ func (self *GuestDeployTask) DeployBackup(ctx context.Context, guest *models.SGu log.Errorf("request_deploy_guest_on_host %s", err) self.OnDeployGuestFail(ctx, guest, err) } else { - guest.SetStatus(self.UserCred, models.VM_DEPLOYING_BACKUP, "") + guest.SetStatus(self.UserCred, api.VM_DEPLOYING_BACKUP, "") } } @@ -82,7 +83,7 @@ func (self *GuestDeployTask) DeployOnHost(ctx context.Context, guest *models.SGu log.Errorf("request_deploy_guest_on_host %s", err) self.OnDeployGuestFail(ctx, guest, err) } else { - guest.SetStatus(self.UserCred, models.VM_DEPLOYING, "") + guest.SetStatus(self.UserCred, api.VM_DEPLOYING, "") } } @@ -93,7 +94,7 @@ func (self *GuestDeployTask) OnSlaveHostDeployComplete(ctx context.Context, gues } func (self *GuestDeployTask) OnSlaveHostDeployCompleteFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { - guest.SetStatus(self.UserCred, models.VM_DEPLOYING_BACKUP_FAILED, "") + guest.SetStatus(self.UserCred, api.VM_DEPLOYING_BACKUP_FAILED, "") self.SetStage("OnUndeployBackupGuest", nil) guest.StartUndeployGuestTask(ctx, self.UserCred, self.GetId(), guest.BackupHostId) } @@ -103,7 +104,7 @@ func (self *GuestDeployTask) OnUndeployBackupGuest(ctx context.Context, guest *m } func (self *GuestDeployTask) OnDeployGuestFail(ctx context.Context, guest *models.SGuest, err error) { - guest.SetStatus(self.UserCred, models.VM_DEPLOY_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_DEPLOY_FAILED, err.Error()) self.SetStageFailed(ctx, err.Error()) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_DEPLOY, err, self.UserCred, false) } @@ -152,7 +153,7 @@ func (self *GuestDeployTask) OnDeployGuestCompleteFailed(ctx context.Context, ob log.Errorf("unset guest %s keypair failed %v", guest.Name, err) } } - guest.SetStatus(self.UserCred, models.VM_DEPLOY_FAILED, data.String()) + guest.SetStatus(self.UserCred, api.VM_DEPLOY_FAILED, data.String()) self.SetStageFailed(ctx, data.String()) } diff --git a/pkg/compute/tasks/guest_detach_disk_task.go b/pkg/compute/tasks/guest_detach_disk_task.go index a9161239ab..d8e0c13416 100644 --- a/pkg/compute/tasks/guest_detach_disk_task.go +++ b/pkg/compute/tasks/guest_detach_disk_task.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -61,7 +62,7 @@ func (self *GuestDetachDiskTask) OnInit(ctx context.Context, obj db.IStandaloneM guest.DetachDisk(ctx, disk, self.UserCred) host := guest.GetHost() purge := false - if host != nil && host.Status == models.HOST_DISABLED && jsonutils.QueryBoolean(self.Params, "purge", false) { + if host != nil && host.Status == api.HOST_DISABLED && jsonutils.QueryBoolean(self.Params, "purge", false) { purge = true } detachStatus, err := guest.GetDriver().GetDetachDiskStatus() @@ -93,7 +94,7 @@ func (self *GuestDetachDiskTask) OnSyncConfigComplete(ctx context.Context, guest keepDisk := jsonutils.QueryBoolean(self.Params, "keep_disk", true) host := guest.GetHost() purge := false - if host != nil && host.Status == models.HOST_DISABLED && jsonutils.QueryBoolean(self.Params, "purge", false) { + if host != nil && host.Status == api.HOST_DISABLED && jsonutils.QueryBoolean(self.Params, "purge", false) { purge = true } if !keepDisk && disk.GetGuestDiskCount() == 0 && disk.AutoDelete { @@ -134,7 +135,7 @@ func (self *GuestDetachDiskTask) OnTaskFail(ctx context.Context, guest *models.S if disk != nil { disk.SetDiskReady(ctx, self.UserCred, "") } - guest.SetStatus(self.UserCred, models.VM_DETACH_DISK_FAILED, err.Error()) + guest.SetStatus(self.UserCred, api.VM_DETACH_DISK_FAILED, err.Error()) self.SetStageFailed(ctx, err.Error()) log.Errorf("Guest %s GuestDetachDiskTask failed %s", guest.Id, err.Error()) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_DETACH_DISK, err.Error(), self.UserCred, false) diff --git a/pkg/compute/tasks/guest_disk_snapshot_task.go b/pkg/compute/tasks/guest_disk_snapshot_task.go index 884a38f209..1b0b3aebf1 100644 --- a/pkg/compute/tasks/guest_disk_snapshot_task.go +++ b/pkg/compute/tasks/guest_disk_snapshot_task.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -56,7 +57,7 @@ func (self *GuestDiskSnapshotTask) DoDiskSnapshot(ctx context.Context, guest *mo return } self.SetStage("OnDiskSnapshotComplete", nil) - guest.SetStatus(self.UserCred, models.VM_SNAPSHOT, "") + guest.SetStatus(self.UserCred, api.VM_SNAPSHOT, "") err = guest.GetDriver().RequestDiskSnapshot(ctx, guest, self, snapshotId, diskId) if err != nil { self.TaskFailed(ctx, guest, err.Error()) @@ -69,7 +70,7 @@ func (self *GuestDiskSnapshotTask) OnDiskSnapshotComplete(ctx context.Context, g snapshotId, _ := self.Params.GetString("snapshot_id") iSnapshot, _ := models.SnapshotManager.FetchById(snapshotId) snapshot := iSnapshot.(*models.SSnapshot) - if guest.Hypervisor == models.HYPERVISOR_KVM { + if guest.Hypervisor == api.HYPERVISOR_KVM { location, err := res.GetString("location") if err != nil { log.Infof("OnDiskSnapshotComplete called with data no location") @@ -77,18 +78,18 @@ func (self *GuestDiskSnapshotTask) OnDiskSnapshotComplete(ctx context.Context, g } db.Update(snapshot, func() error { snapshot.Location = location - snapshot.Status = models.SNAPSHOT_READY + snapshot.Status = api.SNAPSHOT_READY return nil }) } else { extSnapshotId, _ := data.GetString("snapshot_id") db.Update(snapshot, func() error { snapshot.ExternalId = extSnapshotId - snapshot.Status = models.SNAPSHOT_READY + snapshot.Status = api.SNAPSHOT_READY return nil }) } - guest.SetStatus(self.UserCred, models.VM_SNAPSHOT_SUCC, "") + guest.SetStatus(self.UserCred, api.VM_SNAPSHOT_SUCC, "") self.TaskComplete(ctx, guest, nil) } @@ -123,11 +124,11 @@ func (self *GuestDiskSnapshotTask) TaskFailed(ctx context.Context, guest *models iSnapshot, _ := models.SnapshotManager.FetchById(snapshotId) snapshot := iSnapshot.(*models.SSnapshot) db.Update(snapshot, func() error { - snapshot.Status = models.SNAPSHOT_FAILED + snapshot.Status = api.SNAPSHOT_FAILED return nil }) self.SetStageFailed(ctx, reason) - guest.SetStatus(self.UserCred, models.VM_SNAPSHOT_FAILED, reason) + guest.SetStatus(self.UserCred, api.VM_SNAPSHOT_FAILED, reason) db.OpsLog.LogEvent(iSnapshot, db.ACT_SNAPSHOT_FAIL, reason, self.UserCred) logclient.AddActionLogWithStartable(self, iSnapshot, logclient.ACT_CREATE, reason, self.UserCred, false) } @@ -190,7 +191,7 @@ func (self *SnapshotDeleteTask) deleteExternalSnapshot(ctx context.Context, snap func (self *SnapshotDeleteTask) StartReloadDisk(ctx context.Context, snapshot *models.SSnapshot, guest *models.SGuest) { self.SetStage("OnReloadDiskSnapshot", nil) - guest.SetStatus(self.UserCred, models.VM_SNAPSHOT, "Start Reload Snapshot") + guest.SetStatus(self.UserCred, api.VM_SNAPSHOT, "Start Reload Snapshot") params := jsonutils.NewDict() params.Set("disk_id", jsonutils.NewString(snapshot.DiskId)) err := guest.GetDriver().RequestReloadDiskSnapshot(ctx, guest, self, params) @@ -200,7 +201,7 @@ func (self *SnapshotDeleteTask) StartReloadDisk(ctx context.Context, snapshot *m } func (self *SnapshotDeleteTask) StartDeleteSnapshot(ctx context.Context, snapshot *models.SSnapshot, guest *models.SGuest) { - snapshot.SetStatus(self.UserCred, models.SNAPSHOT_DELETING, "On SnapshotDeleteTask StartDeleteSnapshot") + snapshot.SetStatus(self.UserCred, api.SNAPSHOT_DELETING, "On SnapshotDeleteTask StartDeleteSnapshot") params := jsonutils.NewDict() convertSnapshot, err := models.SnapshotManager.GetConvertSnapshot(snapshot) if err != nil { @@ -216,14 +217,14 @@ func (self *SnapshotDeleteTask) StartDeleteSnapshot(ctx context.Context, snapsho if !snapshot.OutOfChain { params.Set("convert_snapshot", jsonutils.NewString(convertSnapshot.Id)) var FakeDelete = jsonutils.JSONFalse - if snapshot.CreatedBy == models.MANUAL && snapshot.FakeDeleted == false { + if snapshot.CreatedBy == api.SNAPSHOT_MANUAL && snapshot.FakeDeleted == false { FakeDelete = jsonutils.JSONTrue } params.Set("pending_delete", FakeDelete) } else { params.Set("auto_deleted", jsonutils.JSONTrue) } - guest.SetStatus(self.UserCred, models.VM_SNAPSHOT_DELETE, "Start Delete Snapshot") + guest.SetStatus(self.UserCred, api.VM_SNAPSHOT_DELETE, "Start Delete Snapshot") self.SetStage("OnDeleteSnapshot", nil) err = guest.GetDriver().RequestDeleteSnapshot(ctx, guest, self, params) @@ -247,14 +248,14 @@ func (self *SnapshotDeleteTask) OnDeleteSnapshot(ctx context.Context, snapshot * log.Infof("OnDeleteSnapshot with no deleted") return } - snapshot.SetStatus(self.UserCred, models.SNAPSHOT_READY, "OnDeleteSnapshot") + snapshot.SetStatus(self.UserCred, api.SNAPSHOT_READY, "OnDeleteSnapshot") if snapshot.OutOfChain { snapshot.RealDelete(ctx, self.UserCred) self.TaskComplete(ctx, snapshot, nil) } else { guest, _ := snapshot.GetGuest() var FakeDelete = false - if snapshot.CreatedBy == models.MANUAL && snapshot.FakeDeleted == false { + if snapshot.CreatedBy == api.SNAPSHOT_MANUAL && snapshot.FakeDeleted == false { FakeDelete = true } if FakeDelete { @@ -269,7 +270,7 @@ func (self *SnapshotDeleteTask) OnDeleteSnapshot(ctx context.Context, snapshot * guest.StartSyncstatus(ctx, self.UserCred, "") } } else { - snapshot.SetStatus(self.UserCred, models.SNAPSHOT_READY, "OnDeleteSnapshot") + snapshot.SetStatus(self.UserCred, api.SNAPSHOT_READY, "OnDeleteSnapshot") snapshot.RealDelete(ctx, self.UserCred) self.TaskComplete(ctx, snapshot, nil) } @@ -284,7 +285,7 @@ func (self *SnapshotDeleteTask) OnReloadDiskSnapshot(ctx context.Context, snapsh log.Infof("OnDeleteSnapshot with no reopen") return } - if snapshot.CreatedBy == models.AUTO { + if snapshot.CreatedBy == api.SNAPSHOT_AUTO { err := snapshot.RealDelete(ctx, self.UserCred) if err != nil { self.TaskFailed(ctx, snapshot, err.Error()) @@ -313,8 +314,8 @@ func (self *SnapshotDeleteTask) TaskComplete(ctx context.Context, snapshot *mode } func (self *SnapshotDeleteTask) TaskFailed(ctx context.Context, snapshot *models.SSnapshot, reason string) { - if snapshot.Status == models.SNAPSHOT_DELETING { - snapshot.SetStatus(self.UserCred, models.SNAPSHOT_READY, "On SnapshotDeleteTask TaskFailed") + if snapshot.Status == api.SNAPSHOT_DELETING { + snapshot.SetStatus(self.UserCred, api.SNAPSHOT_READY, "On SnapshotDeleteTask TaskFailed") } self.SetStageFailed(ctx, reason) guest, err := snapshot.GetGuest() diff --git a/pkg/compute/tasks/guest_eject_iso_task.go b/pkg/compute/tasks/guest_eject_iso_task.go index c48b8f2113..460283bd75 100644 --- a/pkg/compute/tasks/guest_eject_iso_task.go +++ b/pkg/compute/tasks/guest_eject_iso_task.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -38,7 +39,7 @@ func (self *GuestEjectISOTask) OnInit(ctx context.Context, obj db.IStandaloneMod func (self *GuestEjectISOTask) startEjectIso(ctx context.Context, obj db.IStandaloneModel) { guest := obj.(*models.SGuest) - if guest.EjectIso(self.UserCred) && guest.Status == models.VM_RUNNING { + if guest.EjectIso(self.UserCred) && guest.Status == api.VM_RUNNING { self.SetStage("OnConfigSyncComplete", nil) guest.StartSyncTask(ctx, self.UserCred, false, self.GetId()) } else { diff --git a/pkg/compute/tasks/guest_insert_iso_task.go b/pkg/compute/tasks/guest_insert_iso_task.go index abb06302ff..7c426011cd 100644 --- a/pkg/compute/tasks/guest_insert_iso_task.go +++ b/pkg/compute/tasks/guest_insert_iso_task.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -79,7 +80,7 @@ func (self *GuestInsertIsoTask) OnIsoPrepareComplete(ctx context.Context, obj db guest := obj.(*models.SGuest) if guest.InsertIsoSucc(imageId, path, int(size), name) { db.OpsLog.LogEvent(guest, db.ACT_ISO_ATTACH, guest.GetDetailsIso(self.UserCred), self.UserCred) - if guest.Status == models.VM_RUNNING { + if guest.Status == api.VM_RUNNING { self.SetStage("OnConfigSyncComplete", nil) guest.GetDriver().RequestGuestHotAddIso(ctx, guest, path, self) } else { diff --git a/pkg/compute/tasks/guest_live_migrate_task.go b/pkg/compute/tasks/guest_live_migrate_task.go index 4b4009a89b..c4a5022160 100644 --- a/pkg/compute/tasks/guest_live_migrate_task.go +++ b/pkg/compute/tasks/guest_live_migrate_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" schedapi "yunion.io/x/onecloud/pkg/apis/scheduler" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" @@ -60,7 +61,7 @@ func (self *GuestMigrateTask) GetSchedParams() (*schedapi.ScheduleInput, error) func (self *GuestMigrateTask) OnStartSchedule(obj IScheduleModel) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_MIGRATING, "") + guest.SetStatus(self.UserCred, api.VM_MIGRATING, "") db.OpsLog.LogEvent(guest, db.ACT_MIGRATING, "", self.UserCred) } @@ -90,7 +91,7 @@ func (self *GuestMigrateTask) SaveScheduleResult(ctx context.Context, obj ISched disks := guest.GetDisks() disk := disks[0].GetDisk() isLocalStorage := utils.IsInStringArray(disk.GetStorage().StorageType, - models.STORAGE_LOCAL_TYPES) + api.STORAGE_LOCAL_TYPES) if isLocalStorage { body.Set("is_local_storage", jsonutils.JSONTrue) } else { @@ -118,7 +119,7 @@ func (self *GuestMigrateTask) OnCachedImageComplete(ctx context.Context, guest * header := self.GetTaskRequestHeader() body := jsonutils.NewDict() guestStatus, _ := self.Params.GetString("guest_status") - if !jsonutils.QueryBoolean(self.Params, "is_rescue_mode", false) && (guestStatus == models.VM_RUNNING || guestStatus == models.VM_SUSPEND) { + if !jsonutils.QueryBoolean(self.Params, "is_rescue_mode", false) && (guestStatus == api.VM_RUNNING || guestStatus == api.VM_SUSPEND) { body.Set("live_migrate", jsonutils.JSONTrue) } @@ -155,7 +156,7 @@ func (self *GuestMigrateTask) OnSrcPrepareComplete(ctx context.Context, guest *m return } guestStatus, _ := self.Params.GetString("guest_status") - if !jsonutils.QueryBoolean(self.Params, "is_rescue_mode", false) && (guestStatus == models.VM_RUNNING || guestStatus == models.VM_SUSPEND) { + if !jsonutils.QueryBoolean(self.Params, "is_rescue_mode", false) && (guestStatus == api.VM_RUNNING || guestStatus == api.VM_SUSPEND) { body.Set("live_migrate", jsonutils.JSONTrue) } @@ -178,7 +179,7 @@ func (self *GuestMigrateTask) OnMigrateConfAndDiskCompleteFailed(ctx context.Con func (self *GuestMigrateTask) OnMigrateConfAndDiskComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { guestStatus, _ := self.Params.GetString("guest_status") - if !jsonutils.QueryBoolean(self.Params, "is_rescue_mode", false) && (guestStatus == models.VM_RUNNING || guestStatus == models.VM_SUSPEND) { + if !jsonutils.QueryBoolean(self.Params, "is_rescue_mode", false) && (guestStatus == api.VM_RUNNING || guestStatus == api.VM_SUSPEND) { // Live migrate self.SetStage("OnStartDestComplete", nil) } else { @@ -306,12 +307,12 @@ func (self *GuestMigrateTask) setGuest(ctx context.Context, guest *models.SGuest targetHostId, _ := self.Params.GetString("target_host_id") if jsonutils.QueryBoolean(self.Params, "is_local_storage", false) { targetHost := models.HostManager.FetchHostById(targetHostId) - targetStorage := targetHost.GetLeastUsedStorage(models.STORAGE_LOCAL) + targetStorage := targetHost.GetLeastUsedStorage(api.STORAGE_LOCAL) guestDisks := guest.GetDisks() for i := 0; i < len(guestDisks); i++ { disk := guestDisks[i].GetDisk() db.Update(disk, func() error { - disk.Status = models.DISK_READY + disk.Status = api.DISK_READY disk.StorageId = targetStorage.Id return nil }) @@ -398,9 +399,9 @@ func (self *GuestMigrateTask) TaskComplete(ctx context.Context, guest *models.SG } func (self *GuestMigrateTask) TaskFailed(ctx context.Context, guest *models.SGuest, reason string) { - guest.SetStatus(self.UserCred, models.VM_MIGRATE_FAILED, reason) + guest.SetStatus(self.UserCred, api.VM_MIGRATE_FAILED, reason) db.OpsLog.LogEvent(guest, db.ACT_MIGRATE_FAIL, reason, self.UserCred) logclient.AddActionLogWithContext(ctx, guest, logclient.ACT_MIGRATE, reason, self.UserCred, false) self.SetStageFailed(ctx, reason) - notifyclient.NotifySystemError(guest.Id, guest.Name, models.VM_MIGRATE_FAILED, reason) + notifyclient.NotifySystemError(guest.Id, guest.Name, api.VM_MIGRATE_FAILED, reason) } diff --git a/pkg/compute/tasks/guest_rebuild_root_task.go b/pkg/compute/tasks/guest_rebuild_root_task.go index 62cb64e9f2..293eab9740 100644 --- a/pkg/compute/tasks/guest_rebuild_root_task.go +++ b/pkg/compute/tasks/guest_rebuild_root_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/util/osprofile" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudcommon/notifyclient" @@ -65,7 +66,7 @@ func (self *GuestRebuildRootTask) StartRebuildRootDisk(ctx context.Context, gues oldStatus := gds.Root.Status _, err := db.Update(gds.Root, func() error { gds.Root.TemplateId = imageId - gds.Root.Status = models.DISK_REBUILD + gds.Root.Status = api.DISK_REBUILD return nil }) if err != nil { @@ -73,11 +74,11 @@ func (self *GuestRebuildRootTask) StartRebuildRootDisk(ctx context.Context, gues return } else { db.OpsLog.LogEvent(gds.Root, db.ACT_UPDATE_STATUS, - fmt.Sprintf("%s=>%s", oldStatus, models.DISK_REBUILD), self.UserCred) + fmt.Sprintf("%s=>%s", oldStatus, api.DISK_REBUILD), self.UserCred) } self.SetStage("OnRebuildRootDiskComplete", nil) - guest.SetStatus(self.UserCred, models.VM_REBUILD_ROOT, "") + guest.SetStatus(self.UserCred, api.VM_REBUILD_ROOT, "") // clear logininfo loginParams := make(map[string]interface{}) @@ -96,7 +97,7 @@ func (self *GuestRebuildRootTask) OnRebuildRootDiskComplete(ctx context.Context, for i := 1; i < len(guestdisks); i += 1 { disk := guestdisks[i].GetDisk() if disk != nil { - disk.SetStatus(self.UserCred, models.DISK_INIT, "rebuild data disks") + disk.SetStatus(self.UserCred, api.DISK_INIT, "rebuild data disks") } } self.SetStage("OnRebuildingDataDisksComplete", nil) @@ -110,11 +111,11 @@ func (self *GuestRebuildRootTask) OnRebuildingDataDisksComplete(ctx context.Cont diskReady := true guestdisks := guest.GetDisks() if len(guestdisks) > 0 { - guest.SetStatus(self.UserCred, models.VM_REBUILD_ROOT, "rebuild data disks") + guest.SetStatus(self.UserCred, api.VM_REBUILD_ROOT, "rebuild data disks") } for i := 1; i < len(guestdisks); i += 1 { disk := guestdisks[i].GetDisk() - if disk.Status == models.DISK_INIT { + if disk.Status == api.DISK_INIT { diskReady = false disk.StartDiskCreateTask(ctx, self.UserCred, true, "", self.GetTaskId()) } @@ -170,12 +171,12 @@ func (self *GuestRebuildRootTask) OnRebuildAllDisksComplete(ctx context.Context, func (self *GuestRebuildRootTask) OnRebuildRootDiskCompleteFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { db.OpsLog.LogEvent(guest, db.ACT_REBUILD_ROOT_FAIL, data, self.UserCred) - guest.SetStatus(self.UserCred, models.VM_REBUILD_ROOT_FAIL, "OnRebuildRootDiskCompleteFailed") + guest.SetStatus(self.UserCred, api.VM_REBUILD_ROOT_FAIL, "OnRebuildRootDiskCompleteFailed") self.markFailed(ctx, guest, data.String()) } func (self *GuestRebuildRootTask) OnSyncStatusComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { - if guest.Status == models.VM_READY && jsonutils.QueryBoolean(self.Params, "auto_start", false) { + if guest.Status == api.VM_READY && jsonutils.QueryBoolean(self.Params, "auto_start", false) { self.SetStage("OnGuestStartComplete", nil) guest.StartGueststartTask(ctx, self.UserCred, nil, self.GetTaskId()) } else { @@ -207,7 +208,7 @@ func (self *KVMGuestRebuildRootTask) OnRebuildRootDiskComplete(ctx context.Conte guest := obj.(*models.SGuest) self.SetStage("OnGuestDeployComplete", nil) - guest.SetStatus(self.UserCred, models.VM_DEPLOYING, "") + guest.SetStatus(self.UserCred, api.VM_DEPLOYING, "") // params := jsonutils.NewDict() // params.Set("reset_password", jsonutils.JSONTrue) guest.StartGuestDeployTask(ctx, self.UserCred, self.GetParams(), "deploy", self.GetTaskId()) @@ -244,7 +245,7 @@ func (self *ManagedGuestRebuildRootTask) OnHostCacheImageComplete(ctx context.Co guest := obj.(*models.SGuest) self.SetStage("OnGuestDeployComplete", nil) - guest.SetStatus(self.UserCred, models.VM_DEPLOYING, "rebuild deploy") + guest.SetStatus(self.UserCred, api.VM_DEPLOYING, "rebuild deploy") guest.StartGuestDeployTask(ctx, self.UserCred, self.Params, "rebuild", self.GetTaskId()) } diff --git a/pkg/compute/tasks/guest_renew_task.go b/pkg/compute/tasks/guest_renew_task.go index ea2d246fff..eadce8892f 100644 --- a/pkg/compute/tasks/guest_renew_task.go +++ b/pkg/compute/tasks/guest_renew_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -49,7 +50,7 @@ func (self *GuestRenewTask) OnInit(ctx context.Context, obj db.IStandaloneModel, log.Errorf(msg) db.OpsLog.LogEvent(guest, db.ACT_REW_FAIL, msg, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_RENEW, msg, self.UserCred, false) - guest.SetStatus(self.GetUserCred(), models.VM_RENEW_FAILED, msg) + guest.SetStatus(self.GetUserCred(), api.VM_RENEW_FAILED, msg) self.SetStageFailed(ctx, msg) return } diff --git a/pkg/compute/tasks/guest_reset_task.go b/pkg/compute/tasks/guest_reset_task.go index f1ead9f192..d15d253b0a 100644 --- a/pkg/compute/tasks/guest_reset_task.go +++ b/pkg/compute/tasks/guest_reset_task.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -54,7 +55,7 @@ func (self *GuestHardResetTask) OnInit(ctx context.Context, obj db.IStandaloneMo } func (self *GuestHardResetTask) StopServer(ctx context.Context, guest *models.SGuest) { - guest.SetStatus(self.UserCred, models.VM_STOPPING, "") + guest.SetStatus(self.UserCred, api.VM_STOPPING, "") self.SetStage("OnServerStopComplete", nil) guest.StartGuestStopTask(ctx, self.UserCred, false, self.GetTaskId()) // logclient.AddActionLogWith(guest, logclient.ACT_VM_RESTART, `{"is_force": true}`, self.UserCred, true) @@ -78,7 +79,7 @@ type GuestRestartTask struct { } func (self *GuestRestartTask) StopServer(ctx context.Context, guest *models.SGuest) { - guest.SetStatus(self.UserCred, models.VM_STOPPING, "") + guest.SetStatus(self.UserCred, api.VM_STOPPING, "") self.SetStage("OnServerStopComplete", nil) isForce := jsonutils.QueryBoolean(self.Params, "is_force", false) guest.StartGuestStopTask(ctx, self.UserCred, isForce, self.GetTaskId()) diff --git a/pkg/compute/tasks/guest_save_image_task.go b/pkg/compute/tasks/guest_save_image_task.go index 118d0f770c..b76dc81bde 100644 --- a/pkg/compute/tasks/guest_save_image_task.go +++ b/pkg/compute/tasks/guest_save_image_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -46,13 +47,13 @@ func (self *GuestSaveImageTask) OnInit(ctx context.Context, obj db.IStandaloneMo } func (self *GuestSaveImageTask) OnStopServerComplete(ctx context.Context, guest *models.SGuest, body jsonutils.JSONObject) { - if guest.Status != models.VM_READY { + if guest.Status != api.VM_READY { resion := fmt.Sprintf("Server %s not in ready status", guest.Name) log.Errorf(resion) self.SetStageFailed(ctx, resion) } else { self.SetStage("on_save_root_image_complete", nil) - guest.SetStatus(self.GetUserCred(), models.VM_START_SAVE_DISK, "") + guest.SetStatus(self.GetUserCred(), api.VM_START_SAVE_DISK, "") disks := guest.CategorizeDisks() if err := disks.Root.StartDiskSaveTask(ctx, self.GetUserCred(), self.GetParams(), self.GetTaskId()); err != nil { self.SetStageFailed(ctx, err.Error()) @@ -71,7 +72,7 @@ func (self *GuestSaveImageTask) OnSaveRootImageComplete(ctx context.Context, gue func (self *GuestSaveImageTask) OnSaveRootImageCompleteFailed(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { log.Errorf("Guest save root image failed: %s", data.PrettyString()) - guest.SetStatus(self.GetUserCred(), models.VM_SAVE_DISK_FAILED, data.PrettyString()) + guest.SetStatus(self.GetUserCred(), api.VM_SAVE_DISK_FAILED, data.PrettyString()) self.SetStageFailed(ctx, data.PrettyString()) } diff --git a/pkg/compute/tasks/guest_start_task.go b/pkg/compute/tasks/guest_start_task.go index 05e2fafb92..00f0e6402e 100644 --- a/pkg/compute/tasks/guest_start_task.go +++ b/pkg/compute/tasks/guest_start_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -81,7 +82,7 @@ func (self *GuestStartTask) startStart(ctx context.Context, guest *models.SGuest func (self *GuestStartTask) RequestStart(ctx context.Context, guest *models.SGuest) { self.SetStage("OnStartComplete", nil) host := guest.GetHost() - guest.SetStatus(self.UserCred, models.VM_STARTING, "") + guest.SetStatus(self.UserCred, api.VM_STARTING, "") result, err := guest.GetDriver().RequestStartOnHost(ctx, guest, host, self.UserCred, self) if err != nil { self.OnStartCompleteFailed(ctx, guest, jsonutils.NewString(err.Error())) @@ -97,7 +98,7 @@ func (self *GuestStartTask) RequestStart(ctx context.Context, guest *models.SGue func (self *GuestStartTask) RequestStartBacking(ctx context.Context, guest *models.SGuest) { self.SetStage("OnStartBackupGuestComplete", nil) host := models.HostManager.FetchHostById(guest.BackupHostId) - guest.SetStatus(self.UserCred, models.VM_BACKUP_STARTING, "") + guest.SetStatus(self.UserCred, api.VM_BACKUP_STARTING, "") result, err := guest.GetDriver().RequestStartOnHost(ctx, guest, host, self.UserCred, self) if err != nil { self.OnStartCompleteFailed(ctx, guest, jsonutils.NewString(err.Error())) @@ -143,7 +144,7 @@ func (self *GuestStartTask) OnGuestSyncstatusAfterStart(ctx context.Context, obj func (self *GuestStartTask) OnStartCompleteFailed(ctx context.Context, obj db.IStandaloneModel, err jsonutils.JSONObject) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_START_FAILED, err.String()) + guest.SetStatus(self.UserCred, api.VM_START_FAILED, err.String()) db.OpsLog.LogEvent(guest, db.ACT_START_FAIL, err, self.UserCred) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_START, err, self.UserCred, false) self.SetStageFailed(ctx, err.String()) diff --git a/pkg/compute/tasks/guest_stop_task.go b/pkg/compute/tasks/guest_stop_task.go index c8876e50ba..3720caa7e4 100644 --- a/pkg/compute/tasks/guest_stop_task.go +++ b/pkg/compute/tasks/guest_stop_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -51,7 +52,7 @@ func (self *GuestStopTask) stopGuest(ctx context.Context, guest *models.SGuest) return } if !self.isSubtask() { - guest.SetStatus(self.UserCred, models.VM_STOPPING, "") + guest.SetStatus(self.UserCred, api.VM_STOPPING, "") } self.SetStage("OnMasterStopTaskComplete", nil) err := guest.GetDriver().RequestStopOnHost(ctx, guest, host, self) @@ -82,19 +83,19 @@ func (self *GuestStopTask) OnMasterStopTaskCompleteFailed(ctx context.Context, o func (self *GuestStopTask) OnGuestStopTaskComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) { if !self.isSubtask() { - guest.SetStatus(self.UserCred, models.VM_READY, "") + guest.SetStatus(self.UserCred, api.VM_READY, "") } db.OpsLog.LogEvent(guest, db.ACT_STOP, guest.GetShortDesc(ctx), self.UserCred) models.HostManager.ClearSchedDescCache(guest.HostId) self.SetStageComplete(ctx, nil) - if guest.Status == models.VM_READY && guest.DisableDelete.IsFalse() && guest.ShutdownBehavior == models.SHUTDOWN_TERMINATE { + if guest.Status == api.VM_READY && guest.DisableDelete.IsFalse() && guest.ShutdownBehavior == api.SHUTDOWN_TERMINATE { guest.StartAutoDeleteGuestTask(ctx, self.UserCred, "") } logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_STOP, "", self.UserCred, true) } func (self *GuestStopTask) OnGuestStopTaskCompleteFailed(ctx context.Context, guest *models.SGuest, resion jsonutils.JSONObject) { - guest.SetStatus(self.UserCred, models.VM_STOP_FAILED, resion.String()) + guest.SetStatus(self.UserCred, api.VM_STOP_FAILED, resion.String()) db.OpsLog.LogEvent(guest, db.ACT_STOP_FAIL, resion.String(), self.UserCred) self.SetStageFailed(ctx, resion.String()) logclient.AddActionLogWithStartable(self, guest, logclient.ACT_VM_STOP, resion.String(), self.UserCred, false) diff --git a/pkg/compute/tasks/guest_suspend_task.go b/pkg/compute/tasks/guest_suspend_task.go index 4e42bce8a2..38a9ba2554 100644 --- a/pkg/compute/tasks/guest_suspend_task.go +++ b/pkg/compute/tasks/guest_suspend_task.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -35,7 +36,7 @@ func init() { func (self *GuestSuspendTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { guest := obj.(*models.SGuest) db.OpsLog.LogEvent(guest, db.ACT_STOPPING, "", self.UserCred) - guest.SetStatus(self.UserCred, models.VM_SUSPENDING, "GuestSusPendTask") + guest.SetStatus(self.UserCred, api.VM_SUSPENDING, "GuestSusPendTask") self.SetStage("on_suspend_complete", nil) err := guest.GetDriver().RqeuestSuspendOnHost(ctx, guest, self) if err != nil { @@ -45,18 +46,18 @@ func (self *GuestSuspendTask) OnInit(ctx context.Context, obj db.IStandaloneMode func (self *GuestSuspendTask) OnSuspendComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_SUSPEND, "") + guest.SetStatus(self.UserCred, api.VM_SUSPEND, "") db.OpsLog.LogEvent(guest, db.ACT_STOP, "", self.UserCred) self.SetStageComplete(ctx, nil) } func (self *GuestSuspendTask) OnSuspendCompleteFailed(ctx context.Context, obj db.IStandaloneModel, err jsonutils.JSONObject) { guest := obj.(*models.SGuest) - guest.SetStatus(self.UserCred, models.VM_RUNNING, "") + guest.SetStatus(self.UserCred, api.VM_RUNNING, "") db.OpsLog.LogEvent(guest, db.ACT_STOP_FAIL, err.String(), self.UserCred) self.SetStageFailed(ctx, err.String()) } func (self *GuestSuspendTask) OnSuspendGuestFail(guest *models.SGuest, reason string) { - guest.SetStatus(self.UserCred, models.VM_SUSPEND_FAILED, reason) + guest.SetStatus(self.UserCred, api.VM_SUSPEND_FAILED, reason) } diff --git a/pkg/compute/tasks/guest_sync_task.go b/pkg/compute/tasks/guest_sync_task.go index 0183a62c77..5eb2698551 100644 --- a/pkg/compute/tasks/guest_sync_task.go +++ b/pkg/compute/tasks/guest_sync_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -79,7 +80,7 @@ func (self *GuestSyncConfTask) OnDiskSyncCompleteFailed(ctx context.Context, obj func (self *GuestSyncConfTask) OnSyncCompleteFailed(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { guest := obj.(*models.SGuest) - guest.SetStatus(self.GetUserCred(), models.VM_SYNC_FAIL, data.String()) + guest.SetStatus(self.GetUserCred(), api.VM_SYNC_FAIL, data.String()) log.Errorf("Guest sync config failed: %v", data.String()) db.OpsLog.LogEvent(guest, db.ACT_SYNC_CONF_FAIL, data.String(), self.UserCred) self.SetStageFailed(ctx, data.String()) diff --git a/pkg/compute/tasks/guest_syncstatus_task.go b/pkg/compute/tasks/guest_syncstatus_task.go index 7f401c726e..6c8d644716 100644 --- a/pkg/compute/tasks/guest_syncstatus_task.go +++ b/pkg/compute/tasks/guest_syncstatus_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -37,9 +38,9 @@ func init() { func (self *GuestSyncstatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) { guest := obj.(*models.SGuest) host := guest.GetHost() - if host == nil || host.HostStatus == models.HOST_OFFLINE { + if host == nil || host.HostStatus == api.HOST_OFFLINE { log.Errorf("host is not reachable") - guest.SetStatus(self.UserCred, models.VM_UNKNOWN, "Host not responding") + guest.SetStatus(self.UserCred, api.VM_UNKNOWN, "Host not responding") self.SetStageComplete(ctx, nil) return } @@ -56,15 +57,15 @@ func (self *GuestSyncstatusTask) OnGetStatusSucc(ctx context.Context, guest *mod statusStr, _ := body.GetString("status") switch statusStr { case cloudprovider.CloudVMStatusRunning: - statusStr = models.VM_RUNNING + statusStr = api.VM_RUNNING case cloudprovider.CloudVMStatusSuspend: - statusStr = models.VM_SUSPEND + statusStr = api.VM_SUSPEND case cloudprovider.CloudVMStatusStopped: - statusStr = models.VM_READY - case models.VM_BLOCK_STREAM: + statusStr = api.VM_READY + case api.VM_BLOCK_STREAM: /// XXX ??? break default: - statusStr = models.VM_UNKNOWN + statusStr = api.VM_UNKNOWN } statusData := jsonutils.NewDict() statusData.Add(jsonutils.NewString(statusStr), "status") @@ -74,7 +75,7 @@ func (self *GuestSyncstatusTask) OnGetStatusSucc(ctx context.Context, guest *mod } func (self *GuestSyncstatusTask) OnGetStatusFail(ctx context.Context, guest *models.SGuest, err error) { - guest.SetStatus(self.UserCred, models.VM_UNKNOWN, err.Error()) + guest.SetStatus(self.UserCred, api.VM_UNKNOWN, err.Error()) self.SetStageComplete(ctx, nil) // logclient.AddActionLog(guest, logclient.ACT_VM_SYNC_STATUS, err, self.UserCred, false) } diff --git a/pkg/compute/tasks/host_import_libvirt_servers_task.go b/pkg/compute/tasks/host_import_libvirt_servers_task.go index f65e2f4659..5da422d0f2 100644 --- a/pkg/compute/tasks/host_import_libvirt_servers_task.go +++ b/pkg/compute/tasks/host_import_libvirt_servers_task.go @@ -9,6 +9,7 @@ import ( "yunion.io/x/pkg/util/stringutils" "yunion.io/x/onecloud/pkg/apis/compute" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -116,7 +117,7 @@ func (self *HostImportLibvirtServersTask) FillLibvirtGuestDesc( for i := 0; i < len(guestDesc.Disks); i++ { guestDesc.Disks[i].DiskId = stringutils.UUID4() if len(guestDesc.Disks[i].Backend) == 0 { - guestDesc.Disks[i].Backend = models.STORAGE_LOCAL + guestDesc.Disks[i].Backend = api.STORAGE_LOCAL } } } @@ -175,7 +176,7 @@ func (self *CreateImportedLibvirtGuestTask) OnInit( _, err := db.Update(disk, func() error { disk.AccessPath = accessPath.String() if guestDisks[i].Index == 0 { - disk.DiskType = models.DISK_TYPE_SYS + disk.DiskType = api.DISK_TYPE_SYS } return nil }) diff --git a/pkg/compute/tasks/network_create_task.go b/pkg/compute/tasks/network_create_task.go index 97e6fdc7c9..60948a208c 100644 --- a/pkg/compute/tasks/network_create_task.go +++ b/pkg/compute/tasks/network_create_task.go @@ -22,6 +22,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -38,7 +39,7 @@ func init() { func (self *NetworkCreateTask) taskFailed(ctx context.Context, network *models.SNetwork, event string, err error) { log.Errorf("network create task fail on %s: %s", event, err) - network.SetStatus(self.UserCred, models.NETWORK_STATUS_FAILED, err.Error()) + network.SetStatus(self.UserCred, api.NETWORK_STATUS_FAILED, err.Error()) db.OpsLog.LogEvent(network, db.ACT_ALLOCATE_FAIL, err.Error(), self.UserCred) self.SetStageFailed(ctx, err.Error()) } @@ -46,7 +47,7 @@ func (self *NetworkCreateTask) taskFailed(ctx context.Context, network *models.S func (self *NetworkCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { network := obj.(*models.SNetwork) - network.SetStatus(self.UserCred, models.NETWORK_STATUS_PENDING, "") + network.SetStatus(self.UserCred, api.NETWORK_STATUS_PENDING, "") wire := network.GetWire() if wire == nil { @@ -73,7 +74,7 @@ func (self *NetworkCreateTask) OnInit(ctx context.Context, obj db.IStandaloneMod } network.SetExternalId(self.UserCred, inet.GetGlobalId()) - err = cloudprovider.WaitStatus(inet, models.NETWORK_STATUS_AVAILABLE, 10*time.Second, 300*time.Second) + err = cloudprovider.WaitStatus(inet, api.NETWORK_STATUS_AVAILABLE, 10*time.Second, 300*time.Second) if err != nil { self.taskFailed(ctx, network, "waitstatu", err) return diff --git a/pkg/compute/tasks/network_delete_task.go b/pkg/compute/tasks/network_delete_task.go index 9eeb17dca2..97708a6e3d 100644 --- a/pkg/compute/tasks/network_delete_task.go +++ b/pkg/compute/tasks/network_delete_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -36,7 +37,7 @@ func init() { func (self *NetworkDeleteTask) taskFailed(ctx context.Context, network *models.SNetwork, err error) { log.Errorf("network delete task fail: %s", err) - network.SetStatus(self.UserCred, models.NETWORK_STATUS_DELETE_FAILED, err.Error()) + network.SetStatus(self.UserCred, api.NETWORK_STATUS_DELETE_FAILED, err.Error()) db.OpsLog.LogEvent(network, db.ACT_ALLOCATE_FAIL, err.Error(), self.UserCred) self.SetStageFailed(ctx, err.Error()) } @@ -44,7 +45,7 @@ func (self *NetworkDeleteTask) taskFailed(ctx context.Context, network *models.S func (self *NetworkDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { network := obj.(*models.SNetwork) - network.SetStatus(self.UserCred, models.NETWORK_STATUS_DELETING, "") + network.SetStatus(self.UserCred, api.NETWORK_STATUS_DELETING, "") db.OpsLog.LogEvent(network, db.ACT_DELOCATING, network.GetShortDesc(ctx), self.UserCred) inet, err := network.GetINetwork() diff --git a/pkg/compute/tasks/schedule.go b/pkg/compute/tasks/schedule.go index e058c43581..ccaabc5c26 100644 --- a/pkg/compute/tasks/schedule.go +++ b/pkg/compute/tasks/schedule.go @@ -37,11 +37,6 @@ import ( "yunion.io/x/onecloud/pkg/util/logclient" ) -const ( - SCHEDULE = models.VM_SCHEDULE - SCHEDULE_FAILED = models.VM_SCHEDULE_FAILED -) - type IScheduleModel interface { db.IStandaloneModel @@ -98,14 +93,14 @@ func (self *SSchedTask) GetFirstDisk() (*api.DiskConfig, error) { func (self *SSchedTask) OnStartSchedule(obj IScheduleModel) { db.OpsLog.LogEvent(obj, db.ACT_ALLOCATING, nil, self.GetUserCred()) - obj.SetStatus(self.GetUserCred(), SCHEDULE, "") + obj.SetStatus(self.GetUserCred(), api.VM_SCHEDULE, "") } func (self *SSchedTask) OnScheduleFailCallback(ctx context.Context, obj IScheduleModel, reason string) { - obj.SetStatus(self.GetUserCred(), SCHEDULE_FAILED, reason) + obj.SetStatus(self.GetUserCred(), api.VM_SCHEDULE_FAILED, reason) db.OpsLog.LogEvent(obj, db.ACT_ALLOCATE_FAIL, reason, self.GetUserCred()) logclient.AddActionLogWithStartable(self, obj, logclient.ACT_ALLOCATE, reason, self.GetUserCred(), false) - notifyclient.NotifySystemError(obj.GetId(), obj.GetName(), SCHEDULE_FAILED, reason) + notifyclient.NotifySystemError(obj.GetId(), obj.GetName(), api.VM_SCHEDULE_FAILED, reason) } func (self *SSchedTask) OnScheduleComplete(ctx context.Context, items []db.IStandaloneModel, data *jsonutils.JSONDict) { diff --git a/pkg/compute/tasks/storage_cache_image_task.go b/pkg/compute/tasks/storage_cache_image_task.go index 039e0224c6..bb9a9fdfbd 100644 --- a/pkg/compute/tasks/storage_cache_image_task.go +++ b/pkg/compute/tasks/storage_cache_image_task.go @@ -20,6 +20,7 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -55,8 +56,8 @@ func (self *StorageCacheImageTask) OnRelinquishLeastUsedCachedImageComplete(ctx storageCache := obj.(*models.SStoragecache) scimg := models.StoragecachedimageManager.Register(ctx, self.UserCred, storageCache.Id, imageId, "") - if scimg.Status != models.CACHED_IMAGE_STATUS_READY { - scimg.SetStatus(self.UserCred, models.CACHED_IMAGE_STATUS_CACHING, "storage_cache_image_task") + if scimg.Status != api.CACHED_IMAGE_STATUS_READY { + scimg.SetStatus(self.UserCred, api.CACHED_IMAGE_STATUS_CACHING, "storage_cache_image_task") } db.OpsLog.LogEvent(storageCache, db.ACT_CACHING_IMAGE, imageId, self.UserCred) @@ -87,7 +88,7 @@ func (self *StorageCacheImageTask) OnImageCacheCompleteFailed(ctx context.Contex } func (self *StorageCacheImageTask) OnCacheFailed(ctx context.Context, cache *models.SStoragecache, imageId string, scimg *models.SStoragecachedimage, err error, extImgId string) { - scimg.SetStatus(self.UserCred, models.CACHED_IMAGE_STATUS_CACHE_FAILED, err.Error()) + scimg.SetStatus(self.UserCred, api.CACHED_IMAGE_STATUS_CACHE_FAILED, err.Error()) if len(extImgId) > 0 && scimg.ExternalId != extImgId { scimg.SetExternalId(extImgId) } @@ -103,7 +104,7 @@ func (self *StorageCacheImageTask) OnCacheSucc(ctx context.Context, cache *model scimg := models.StoragecachedimageManager.Register(ctx, self.UserCred, cache.Id, imageId, "") extImgId, _ := data.GetString("image_id") - scimg.SetStatus(self.UserCred, models.CACHED_IMAGE_STATUS_READY, "cached") + scimg.SetStatus(self.UserCred, api.CACHED_IMAGE_STATUS_READY, "cached") if len(extImgId) > 0 && scimg.ExternalId != extImgId { scimg.SetExternalId(extImgId) } diff --git a/pkg/compute/tasks/vpc_create_task.go b/pkg/compute/tasks/vpc_create_task.go index 24634ef325..4d081ace86 100644 --- a/pkg/compute/tasks/vpc_create_task.go +++ b/pkg/compute/tasks/vpc_create_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -37,14 +38,14 @@ func init() { func (self *VpcCreateTask) TaskFailed(ctx context.Context, vpc *models.SVpc, err error) { log.Errorf("vpc create task fail: %s", err) - vpc.SetStatus(self.UserCred, models.VPC_STATUS_FAILED, err.Error()) + vpc.SetStatus(self.UserCred, api.VPC_STATUS_FAILED, err.Error()) db.OpsLog.LogEvent(vpc, db.ACT_ALLOCATE_FAIL, err.Error(), self.UserCred) self.SetStageFailed(ctx, err.Error()) } func (self *VpcCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { vpc := obj.(*models.SVpc) - vpc.SetStatus(self.UserCred, models.VPC_STATUS_PENDING, "") + vpc.SetStatus(self.UserCred, api.VPC_STATUS_PENDING, "") iregion, err := vpc.GetIRegion() if err != nil { @@ -58,7 +59,7 @@ func (self *VpcCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, } vpc.SetExternalId(self.UserCred, ivpc.GetGlobalId()) - err = cloudprovider.WaitStatus(ivpc, models.VPC_STATUS_AVAILABLE, 10*time.Second, 300*time.Second) + err = cloudprovider.WaitStatus(ivpc, api.VPC_STATUS_AVAILABLE, 10*time.Second, 300*time.Second) if err != nil { self.TaskFailed(ctx, vpc, err) return diff --git a/pkg/compute/tasks/vpc_delete_task.go b/pkg/compute/tasks/vpc_delete_task.go index 041ee50fb2..1b1c7f224a 100644 --- a/pkg/compute/tasks/vpc_delete_task.go +++ b/pkg/compute/tasks/vpc_delete_task.go @@ -21,6 +21,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -37,7 +38,7 @@ func init() { func (self *VpcDeleteTask) taskFailed(ctx context.Context, vpc *models.SVpc, err error) { log.Errorf("vpc delete task fail: %s", err) - vpc.SetStatus(self.UserCred, models.VPC_STATUS_DELETE_FAILED, err.Error()) + vpc.SetStatus(self.UserCred, api.VPC_STATUS_DELETE_FAILED, err.Error()) db.OpsLog.LogEvent(vpc, db.ACT_DELOCATE_FAIL, err.Error(), self.UserCred) self.SetStageFailed(ctx, err.Error()) } @@ -45,7 +46,7 @@ func (self *VpcDeleteTask) taskFailed(ctx context.Context, vpc *models.SVpc, err func (self *VpcDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) { vpc := obj.(*models.SVpc) - vpc.SetStatus(self.UserCred, models.VPC_STATUS_DELETING, "") + vpc.SetStatus(self.UserCred, api.VPC_STATUS_DELETING, "") db.OpsLog.LogEvent(vpc, db.ACT_DELOCATING, vpc.GetShortDesc(ctx), self.UserCred) region, err := vpc.GetIRegion() diff --git a/pkg/compute/usages/handler.go b/pkg/compute/usages/handler.go index ec83e9b949..ccf96e3d57 100644 --- a/pkg/compute/usages/handler.go +++ b/pkg/compute/usages/handler.go @@ -25,6 +25,7 @@ import ( "yunion.io/x/pkg/util/sets" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/appctx" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/cloudcommon/consts" @@ -207,7 +208,7 @@ func getAdminGeneralUsage(userCred mcclient.TokenCredential, rangeObj db.IStanda var pmemTotal float64 var pcpuTotal float64 - hostEnabledUsage := HostEnabledUsage("", userCred, rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers) + hostEnabledUsage := HostEnabledUsage("", userCred, rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers) pmemTotal = float64(hostEnabledUsage.Get("enabled_hosts.memory").(int64)) pcpuTotal = float64(hostEnabledUsage.Get("enabled_hosts.cpu").(int64)) if rangeObj != nil && rangeObj.Keyword() == "host" { @@ -220,7 +221,7 @@ func getAdminGeneralUsage(userCred mcclient.TokenCredential, rangeObj db.IStanda count.Add("cpu.virtual", host.GetVirtualCPUCount()) } - guestRunningUsage := GuestRunningUsage("all.running_servers", nil, rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers) + guestRunningUsage := GuestRunningUsage("all.running_servers", nil, rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers) runningMem := guestRunningUsage.Get("all.running_servers.memory").(int) runningCpu := guestRunningUsage.Get("all.running_servers.cpu").(int) @@ -240,43 +241,43 @@ func getAdminGeneralUsage(userCred mcclient.TokenCredential, rangeObj db.IStanda count.Add("all.memory_commit_rate.running", runningMemCmtRate) count.Add("all.cpu_commit_rate.running", runningCpuCmtRate) - storageUsage := StorageUsage("", rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers) + storageUsage := StorageUsage("", rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers) count.Include( - HostAllUsage("", userCred, rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers), - HostAllUsage("prepaid_pool", userCred, rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + HostAllUsage("", userCred, rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers), + HostAllUsage("prepaid_pool", userCred, rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), HostAllUsage("any_pool", userCred, rangeObj, hostTypes, nil, providers), hostEnabledUsage, - HostEnabledUsage("prepaid_pool", userCred, rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + HostEnabledUsage("prepaid_pool", userCred, rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), HostEnabledUsage("any_pool", userCred, rangeObj, hostTypes, nil, providers), BaremetalUsage(userCred, rangeObj, hostTypes, providers), storageUsage, - StorageUsage("prepaid_pool", rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + StorageUsage("prepaid_pool", rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), StorageUsage("any_pool", rangeObj, hostTypes, nil, providers), - GuestNormalUsage("all.servers", nil, rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers), - GuestNormalUsage("all.servers.prepaid_pool", nil, rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + GuestNormalUsage("all.servers", nil, rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers), + GuestNormalUsage("all.servers.prepaid_pool", nil, rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), GuestNormalUsage("all.servers.any_pool", nil, rangeObj, hostTypes, nil, providers), - GuestPendingDeleteUsage("all.pending_delete_servers", nil, rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers), - GuestPendingDeleteUsage("all.pending_delete_servers.prepaid_pool", nil, rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + GuestPendingDeleteUsage("all.pending_delete_servers", nil, rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers), + GuestPendingDeleteUsage("all.pending_delete_servers.prepaid_pool", nil, rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), GuestPendingDeleteUsage("all.pending_delete_servers.any_pool", nil, rangeObj, hostTypes, nil, providers), - GuestReadyUsage("all.ready_servers", nil, rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers), - GuestReadyUsage("all.ready_servers.prepaid_pool", nil, rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + GuestReadyUsage("all.ready_servers", nil, rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers), + GuestReadyUsage("all.ready_servers.prepaid_pool", nil, rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), GuestReadyUsage("all.ready_servers.any_pool", nil, rangeObj, hostTypes, nil, providers), guestRunningUsage, - GuestRunningUsage("all.running_servers.prepaid_pool", nil, rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + GuestRunningUsage("all.running_servers.prepaid_pool", nil, rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), GuestRunningUsage("all.running_servers.any_pool", nil, rangeObj, hostTypes, nil, providers), containerRunningUsage, - IsolatedDeviceUsage("", rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers), - IsolatedDeviceUsage("prepaid_pool", rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + IsolatedDeviceUsage("", rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers), + IsolatedDeviceUsage("prepaid_pool", rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), IsolatedDeviceUsage("any_pool", rangeObj, hostTypes, nil, providers), WireUsage(rangeObj, hostTypes, providers), @@ -290,7 +291,7 @@ func getAdminGeneralUsage(userCred mcclient.TokenCredential, rangeObj db.IStanda } func getCommonGeneralUsage(cred mcclient.TokenCredential, rangeObj db.IStandaloneModel, hostTypes []string, providers []string) (count Usage, err error) { - guestNormalUsage := GuestNormalUsage("servers", cred, rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers) + guestNormalUsage := GuestNormalUsage("servers", cred, rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers) containerUsage := containerUsage("containers", cred, rangeObj, hostTypes, nil, providers) @@ -299,19 +300,19 @@ func getCommonGeneralUsage(cred mcclient.TokenCredential, rangeObj db.IStandalon snapshotUsage := SnapshotUsage(cred.GetProjectId(), rangeObj, providers) count = guestNormalUsage.Include( - GuestNormalUsage("servers.prepaid_pool", cred, rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + GuestNormalUsage("servers.prepaid_pool", cred, rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), GuestNormalUsage("servers.any_pool", cred, rangeObj, hostTypes, nil, providers), - GuestRunningUsage("running_servers", cred, rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers), - GuestRunningUsage("running_servers.prepaid_pool", cred, rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + GuestRunningUsage("running_servers", cred, rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers), + GuestRunningUsage("running_servers.prepaid_pool", cred, rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), GuestRunningUsage("running_servers.any_pool", cred, rangeObj, hostTypes, nil, providers), - GuestPendingDeleteUsage("pending_delete_servers", cred, rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers), - GuestPendingDeleteUsage("pending_delete_servers.prepaid_pool", cred, rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + GuestPendingDeleteUsage("pending_delete_servers", cred, rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers), + GuestPendingDeleteUsage("pending_delete_servers.prepaid_pool", cred, rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), GuestPendingDeleteUsage("pending_delete_servers.any_pool", cred, rangeObj, hostTypes, nil, providers), - GuestReadyUsage("ready_servers", cred, rangeObj, hostTypes, []string{models.HostResourceTypeShared}, providers), - GuestReadyUsage("ready_servers.prepaid_pool", cred, rangeObj, hostTypes, []string{models.HostResourceTypePrepaidRecycle}, providers), + GuestReadyUsage("ready_servers", cred, rangeObj, hostTypes, []string{api.HostResourceTypeShared}, providers), + GuestReadyUsage("ready_servers.prepaid_pool", cred, rangeObj, hostTypes, []string{api.HostResourceTypePrepaidRecycle}, providers), GuestReadyUsage("ready_servers.any_pool", cred, rangeObj, hostTypes, nil, providers), containerUsage, @@ -504,11 +505,11 @@ func GuestPendingDeleteUsage(prefix string, cred mcclient.TokenCredential, range } func GuestRunningUsage(prefix string, cred mcclient.TokenCredential, rangeObj db.IStandaloneModel, hostTypes []string, resourceTypes []string, providers []string) Usage { - return guestUsage(prefix, cred, rangeObj, hostTypes, resourceTypes, providers, []string{models.VM_RUNNING}, false) + return guestUsage(prefix, cred, rangeObj, hostTypes, resourceTypes, providers, []string{api.VM_RUNNING}, false) } func GuestReadyUsage(prefix string, cred mcclient.TokenCredential, rangeObj db.IStandaloneModel, hostTypes []string, resourceTypes []string, providers []string) Usage { - return guestUsage(prefix, cred, rangeObj, hostTypes, resourceTypes, providers, []string{models.VM_READY}, false) + return guestUsage(prefix, cred, rangeObj, hostTypes, resourceTypes, providers, []string{api.VM_READY}, false) } func guestHypervisorsUsage( @@ -531,7 +532,7 @@ func guestHypervisorsUsage( count[fmt.Sprintf("%s.cpu", prefix)] = guest.TotalCpuCount count[fmt.Sprintf("%s.memory", prefix)] = guest.TotalMemSize - if len(hypervisors) == 1 && hypervisors[0] == models.HYPERVISOR_CONTAINER { + if len(hypervisors) == 1 && hypervisors[0] == api.HYPERVISOR_CONTAINER { return count } @@ -549,14 +550,14 @@ func guestHypervisorsUsage( func guestUsage(prefix string, userCred mcclient.TokenCredential, rangeObj db.IStandaloneModel, hostTypes []string, resourceTypes []string, providers []string, status []string, pendingDelete bool) Usage { - hypervisors := sets.NewString(models.HYPERVISORS...) - hypervisors.Delete(models.HYPERVISOR_CONTAINER) + hypervisors := sets.NewString(api.HYPERVISORS...) + hypervisors.Delete(api.HYPERVISOR_CONTAINER) return guestHypervisorsUsage(prefix, userCred, rangeObj, hostTypes, resourceTypes, providers, status, hypervisors.List(), pendingDelete) } func containerUsage(prefix string, userCred mcclient.TokenCredential, rangeObj db.IStandaloneModel, hostTypes []string, resourceTypes []string, providers []string) Usage { - hypervisors := []string{models.HYPERVISOR_CONTAINER} + hypervisors := []string{api.HYPERVISOR_CONTAINER} return guestHypervisorsUsage(prefix, userCred, rangeObj, hostTypes, resourceTypes, providers, nil, hypervisors, false) } diff --git a/pkg/scheduler/algorithm/predicates/resource_type_predicate.go b/pkg/scheduler/algorithm/predicates/resource_type_predicate.go index 041740be9a..2df9f86eef 100644 --- a/pkg/scheduler/algorithm/predicates/resource_type_predicate.go +++ b/pkg/scheduler/algorithm/predicates/resource_type_predicate.go @@ -15,7 +15,7 @@ package predicates import ( - "yunion.io/x/onecloud/pkg/compute/models" + computeapi "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/scheduler/core" ) @@ -49,7 +49,7 @@ func (p *ResourceTypePredicate) Execute(u *core.Unit, c core.Candidater) (bool, h.Exclude2("resource_type", hostResType, reqResType) } - if hostResType == models.HostResourceTypePrepaidRecycle { + if hostResType == computeapi.HostResourceTypePrepaidRecycle { if c.GetGuestCount() == 0 { h.SetCapacity(1) } else { diff --git a/pkg/scheduler/api/sched.go b/pkg/scheduler/api/sched.go index f0837d3457..cd8a82d823 100644 --- a/pkg/scheduler/api/sched.go +++ b/pkg/scheduler/api/sched.go @@ -24,7 +24,6 @@ import ( api "yunion.io/x/onecloud/pkg/apis/scheduler" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/cloudcommon/cmdline" - "yunion.io/x/onecloud/pkg/compute/models" o "yunion.io/x/onecloud/pkg/scheduler/options" ) @@ -72,7 +71,7 @@ func NewSchedInfo(input *api.ScheduleInput) *SchedInfo { } if data.ResourceType == "" { - data.ResourceType = models.HostResourceTypeShared + data.ResourceType = computeapi.HostResourceTypeShared } if len(data.BaremetalDiskConfigs) == 0 { @@ -115,7 +114,7 @@ func (data *SchedInfo) reviseData() { } func (d *SchedInfo) SkipDirtyMarkHost() bool { - isSharePublicCloudProvider := d.IsPublicCloudProvider() && (d.ResourceType == "" || d.ResourceType == models.HostResourceTypeShared) + isSharePublicCloudProvider := d.IsPublicCloudProvider() && (d.ResourceType == "" || d.ResourceType == computeapi.HostResourceTypeShared) skipByHypervisor := isSharePublicCloudProvider || d.IsContainer || d.Hypervisor == SchedTypeContainer skipByBackup := d.Backup return skipByHypervisor || skipByBackup diff --git a/pkg/scheduler/api/types.go b/pkg/scheduler/api/types.go index f12a958969..91648d65d8 100644 --- a/pkg/scheduler/api/types.go +++ b/pkg/scheduler/api/types.go @@ -19,6 +19,7 @@ import ( "yunion.io/x/pkg/util/sets" + computeapi "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/compute/models" ) @@ -61,7 +62,7 @@ var ( AggregateStrategyAvoid, ) - PublicCloudProviders = sets.NewString(models.PUBLIC_CLOUD_HYPERVISORS...) + PublicCloudProviders = sets.NewString(computeapi.PUBLIC_CLOUD_HYPERVISORS...) ValidGpuTypes = sets.NewString( GPU_HPC_TYPE, diff --git a/pkg/scheduler/cache/candidate/base.go b/pkg/scheduler/cache/candidate/base.go index 66379e4175..0e3cb6aea3 100644 --- a/pkg/scheduler/cache/candidate/base.go +++ b/pkg/scheduler/cache/candidate/base.go @@ -26,6 +26,7 @@ import ( "yunion.io/x/onecloud/pkg/scheduler/core" "yunion.io/x/onecloud/pkg/scheduler/db/models" + computeapi "yunion.io/x/onecloud/pkg/apis/compute" computedb "yunion.io/x/onecloud/pkg/cloudcommon/db" computemodels "yunion.io/x/onecloud/pkg/compute/models" ) @@ -84,7 +85,7 @@ func (b baseHostGetter) Storages() []*api.CandidateStorage { func reviseResourceType(resType string) string { if resType == "" { - return computemodels.HostResourceTypeDefault + return computeapi.HostResourceTypeDefault } return resType } diff --git a/pkg/scheduler/cache/candidate/common.go b/pkg/scheduler/cache/candidate/common.go index c5a1592048..9b264f1b15 100644 --- a/pkg/scheduler/cache/candidate/common.go +++ b/pkg/scheduler/cache/candidate/common.go @@ -19,28 +19,29 @@ import ( "yunion.io/x/pkg/util/sets" + computeapi "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/compute/models" ) var ( VMRunningStatus = sets.NewString( - models.VM_START_START, - models.VM_STARTING, - models.VM_RUNNING, - models.VM_STOP_FAILED, - models.VM_BLOCK_STREAM, - models.VM_UNKNOWN, - models.VM_BACKUP_STARTING, + computeapi.VM_START_START, + computeapi.VM_STARTING, + computeapi.VM_RUNNING, + computeapi.VM_STOP_FAILED, + computeapi.VM_BLOCK_STREAM, + computeapi.VM_UNKNOWN, + computeapi.VM_BACKUP_STARTING, ) VMCreatingStatus = sets.NewString( - models.VM_CREATE_NETWORK, - models.VM_CREATE_DISK, - models.VM_START_DEPLOY, - models.VM_DEPLOYING, - models.VM_BACKUP_CREATING, - models.VM_DEPLOYING_BACKUP, + computeapi.VM_CREATE_NETWORK, + computeapi.VM_CREATE_DISK, + computeapi.VM_START_DEPLOY, + computeapi.VM_DEPLOYING, + computeapi.VM_BACKUP_CREATING, + computeapi.VM_DEPLOYING_BACKUP, ) ) diff --git a/pkg/scheduler/cache/candidate/hosts.go b/pkg/scheduler/cache/candidate/hosts.go index 21f7233c26..bdf960df40 100644 --- a/pkg/scheduler/cache/candidate/hosts.go +++ b/pkg/scheduler/cache/candidate/hosts.go @@ -29,7 +29,7 @@ import ( "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" - api "yunion.io/x/onecloud/pkg/apis/compute" + computeapi "yunion.io/x/onecloud/pkg/apis/compute" computedb "yunion.io/x/onecloud/pkg/cloudcommon/db" computemodels "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/scheduler/core" @@ -149,7 +149,7 @@ func NewGuestReservedResourceUsedByBuilder(b *HostBuilder, host *computemodels.S for _, g := range gst { dSize := guestDiskSize(&g, true) disk += int64(dSize) - if o.GetOptions().IgnoreNonrunningGuests && !utils.IsInStringArray(g.Status, api.VM_RUNNING_STATUS) { + if o.GetOptions().IgnoreNonrunningGuests && !utils.IsInStringArray(g.Status, computeapi.VM_RUNNING_STATUS) { continue } cpu += int64(g.VcpuCount) @@ -596,7 +596,7 @@ func (b *HostBuilder) init(ids []string, dbCache DBGroupCacher, syncCache SyncGr func (b *HostBuilder) setHosts(ids []string, errMessageChannel chan error) { hosts := computemodels.HostManager.Query() - q := hosts.In("id", ids).NotEquals("host_type", computemodels.HOST_TYPE_BAREMETAL) + q := hosts.In("id", ids).NotEquals("host_type", computeapi.HOST_TYPE_BAREMETAL) hostObjs := make([]computemodels.SHost, 0) err := computedb.FetchModelObjects(computemodels.HostManager, q, &hostObjs) if err != nil { @@ -908,7 +908,7 @@ func (b *HostBuilder) Type() string { func (b *HostBuilder) AllIDs() ([]string, error) { q := computemodels.HostManager.Query("id") - q = q.Filter(sqlchemy.NotEquals(q.Field("host_type"), computemodels.HOST_TYPE_BAREMETAL)) + q = q.Filter(sqlchemy.NotEquals(q.Field("host_type"), computeapi.HOST_TYPE_BAREMETAL)) rs, err := q.Rows() if err != nil { return nil, err @@ -1233,7 +1233,7 @@ func (vm *VendorModel) IsMatch(target *VendorModel) bool { if target.Vendor != "" { if vm.Vendor == target.Vendor { vendorMatch = true - } else if api.ID_VENDOR_MAP[vm.Vendor] == target.Vendor { + } else if computeapi.ID_VENDOR_MAP[vm.Vendor] == target.Vendor { vendorMatch = true } } else { diff --git a/pkg/scheduler/data_manager/sku/sku.go b/pkg/scheduler/data_manager/sku/sku.go index 7c7cc1b1ea..e8e1466db3 100644 --- a/pkg/scheduler/data_manager/sku/sku.go +++ b/pkg/scheduler/data_manager/sku/sku.go @@ -24,6 +24,7 @@ import ( "yunion.io/x/pkg/util/wait" "yunion.io/x/sqlchemy" + computeapi "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/compute/models" ) @@ -126,8 +127,8 @@ func (m *SSkuManager) syncOnce() { q := models.ServerSkuManager.Query("id", "name", "zone_id") q = q.Filter( sqlchemy.OR( - sqlchemy.Equals(q.Field("prepaid_status"), models.SkuStatusAvailable), - sqlchemy.Equals(q.Field("postpaid_status"), models.SkuStatusAvailable))) + sqlchemy.Equals(q.Field("prepaid_status"), computeapi.SkuStatusAvailable), + sqlchemy.Equals(q.Field("postpaid_status"), computeapi.SkuStatusAvailable))) if err := q.All(&skus); err != nil { log.Errorf("SkuManager query all available skus error: %v", err) return diff --git a/pkg/scheduler/handler/handler.go b/pkg/scheduler/handler/handler.go index 4433b514f4..dc27ff0c51 100644 --- a/pkg/scheduler/handler/handler.go +++ b/pkg/scheduler/handler/handler.go @@ -25,6 +25,7 @@ import ( "yunion.io/x/log" + computeapi "yunion.io/x/onecloud/pkg/apis/compute" schedapi "yunion.io/x/onecloud/pkg/apis/scheduler" computemodels "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/scheduler/api" @@ -189,7 +190,7 @@ func doCandidateDetail(c *gin.Context, id string) { args := new(api.CandidateDetailArgs) args.ID = id - if host.HostType == computemodels.HOST_TYPE_BAREMETAL { + if host.HostType == computeapi.HOST_TYPE_BAREMETAL { args.Type = api.HostTypeBaremetal } else { args.Type = api.HostTypeHost diff --git a/pkg/util/aliyun/charge.go b/pkg/util/aliyun/charge.go index fadba5c4e6..0c80676207 100644 --- a/pkg/util/aliyun/charge.go +++ b/pkg/util/aliyun/charge.go @@ -17,17 +17,17 @@ package aliyun import ( "time" - "yunion.io/x/onecloud/pkg/compute/models" + api "yunion.io/x/onecloud/pkg/apis/billing" ) func convertChargeType(ct TChargeType) string { switch ct { case PrePaidInstanceChargeType: - return models.BILLING_TYPE_PREPAID + return api.BILLING_TYPE_PREPAID case PostPaidInstanceChargeType: - return models.BILLING_TYPE_POSTPAID + return api.BILLING_TYPE_POSTPAID default: - return models.BILLING_TYPE_PREPAID + return api.BILLING_TYPE_PREPAID } } diff --git a/pkg/util/aliyun/disk.go b/pkg/util/aliyun/disk.go index f05a047666..3bb72c9116 100644 --- a/pkg/util/aliyun/disk.go +++ b/pkg/util/aliyun/disk.go @@ -23,8 +23,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SMountInstances struct { @@ -77,7 +77,7 @@ func (self *SDisk) GetMetadata() *jsonutils.JSONDict { priceKey := fmt.Sprintf("%s::%s::%s", self.RegionId, self.Category, self.Type) data.Add(jsonutils.NewString(priceKey), "price_key") - data.Add(jsonutils.NewString(models.HYPERVISOR_ALIYUN), "hypervisor") + data.Add(jsonutils.NewString(api.HYPERVISOR_ALIYUN), "hypervisor") return data } @@ -179,9 +179,9 @@ func (self *SDisk) GetStatus() string { // In_use Available Attaching Detaching Creating ReIniting All switch self.Status { case "Creating", "ReIniting": - return models.DISK_ALLOCATING + return api.DISK_ALLOCATING default: - return models.DISK_READY + return api.DISK_READY } } @@ -218,11 +218,11 @@ func (self *SDisk) GetTemplateId() string { func (self *SDisk) GetDiskType() string { switch self.Type { case "system": - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS case "data": - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA default: - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } } @@ -320,7 +320,7 @@ func (self *SDisk) CreateISnapshot(ctx context.Context, name, desc string) (clou return nil, err } else { snapshot.region = self.storage.zone.region - if err := cloudprovider.WaitStatus(snapshot, models.SNAPSHOT_READY, 15*time.Second, 3600*time.Second); err != nil { + if err := cloudprovider.WaitStatus(snapshot, api.SNAPSHOT_READY, 15*time.Second, 3600*time.Second); err != nil { return nil, err } return snapshot, nil diff --git a/pkg/util/aliyun/eip.go b/pkg/util/aliyun/eip.go index 06f77e621c..3c7f6be98e 100644 --- a/pkg/util/aliyun/eip.go +++ b/pkg/util/aliyun/eip.go @@ -22,8 +22,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type TInternetChargeType string @@ -102,13 +102,13 @@ func (self *SEipAddress) GetGlobalId() string { func (self *SEipAddress) GetStatus() string { switch self.Status { case EIP_STATUS_AVAILABLE, EIP_STATUS_INUSE: - return models.EIP_STATUS_READY + return api.EIP_STATUS_READY case EIP_STATUS_ASSOCIATING: - return models.EIP_STATUS_ASSOCIATE + return api.EIP_STATUS_ASSOCIATE case EIP_STATUS_UNASSOCIATING: - return models.EIP_STATUS_DISSOCIATE + return api.EIP_STATUS_DISSOCIATE default: - return models.EIP_STATUS_UNKNOWN + return api.EIP_STATUS_UNKNOWN } } @@ -142,9 +142,9 @@ func (self *SEipAddress) GetIpAddr() string { func (self *SEipAddress) GetMode() string { if self.InstanceId == self.AllocationId { - return models.EIP_MODE_INSTANCE_PUBLICIP + return api.EIP_MODE_INSTANCE_PUBLICIP } else { - return models.EIP_MODE_STANDALONE_EIP + return api.EIP_MODE_STANDALONE_EIP } } @@ -185,11 +185,11 @@ func (self *SEipAddress) GetBandwidth() int { func (self *SEipAddress) GetInternetChargeType() string { switch self.InternetChargeType { case InternetChargeByTraffic: - return models.EIP_CHARGE_TYPE_BY_TRAFFIC + return api.EIP_CHARGE_TYPE_BY_TRAFFIC case InternetChargeByBandwidth: - return models.EIP_CHARGE_TYPE_BY_BANDWIDTH + return api.EIP_CHARGE_TYPE_BY_BANDWIDTH default: - return models.EIP_CHARGE_TYPE_BY_TRAFFIC + return api.EIP_CHARGE_TYPE_BY_TRAFFIC } } @@ -198,7 +198,7 @@ func (self *SEipAddress) Associate(instanceId string) error { if err != nil { return err } - err = cloudprovider.WaitStatus(self, models.EIP_STATUS_READY, 10*time.Second, 180*time.Second) + err = cloudprovider.WaitStatus(self, api.EIP_STATUS_READY, 10*time.Second, 180*time.Second) return err } @@ -207,7 +207,7 @@ func (self *SEipAddress) Dissociate() error { if err != nil { return err } - err = cloudprovider.WaitStatus(self, models.EIP_STATUS_READY, 10*time.Second, 180*time.Second) + err = cloudprovider.WaitStatus(self, api.EIP_STATUS_READY, 10*time.Second, 180*time.Second) return err } @@ -285,9 +285,9 @@ func (region *SRegion) AllocateEIP(bwMbps int, chargeType TInternetChargeType) ( func (region *SRegion) CreateEIP(name string, bwMbps int, chargeType string, bgpType string) (cloudprovider.ICloudEIP, error) { var ctype TInternetChargeType switch chargeType { - case models.EIP_CHARGE_TYPE_BY_TRAFFIC: + case api.EIP_CHARGE_TYPE_BY_TRAFFIC: ctype = InternetChargeByTraffic - case models.EIP_CHARGE_TYPE_BY_BANDWIDTH: + case api.EIP_CHARGE_TYPE_BY_BANDWIDTH: ctype = InternetChargeByBandwidth } eip, err := region.AllocateEIP(bwMbps, ctype) diff --git a/pkg/util/aliyun/host.go b/pkg/util/aliyun/host.go index ce998020f2..7998988d61 100644 --- a/pkg/util/aliyun/host.go +++ b/pkg/util/aliyun/host.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" ) @@ -102,7 +102,7 @@ func (self *SHost) IsEmulated() bool { } func (self *SHost) GetStatus() string { - return models.HOST_STATUS_RUNNING + return api.HOST_STATUS_RUNNING } func (self *SHost) Refresh() error { @@ -110,7 +110,7 @@ func (self *SHost) Refresh() error { } func (self *SHost) GetHostStatus() string { - return models.HOST_ONLINE + return api.HOST_ONLINE } func (self *SHost) GetEnabled() bool { @@ -160,11 +160,11 @@ func (self *SHost) GetStorageSizeMB() int { } func (self *SHost) GetStorageType() string { - return models.DISK_TYPE_HYBRID + return api.DISK_TYPE_HYBRID } func (self *SHost) GetHostType() string { - return models.HOST_TYPE_ALIYUN + return api.HOST_TYPE_ALIYUN } func (self *SHost) GetManagerId() string { diff --git a/pkg/util/aliyun/image.go b/pkg/util/aliyun/image.go index e0e4d90105..f1d3740d0d 100644 --- a/pkg/util/aliyun/image.go +++ b/pkg/util/aliyun/image.go @@ -26,8 +26,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type ImageStatusType string @@ -126,15 +126,15 @@ func (self *SImage) GetIStoragecache() cloudprovider.ICloudStoragecache { func (self *SImage) GetStatus() string { switch self.Status { case ImageStatusCreating: - return models.CACHED_IMAGE_STATUS_SAVING + return api.CACHED_IMAGE_STATUS_SAVING case ImageStatusAvailable: - return models.CACHED_IMAGE_STATUS_READY + return api.CACHED_IMAGE_STATUS_READY case ImageStatusUnAvailable: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED case ImageStatusCreateFailed: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED default: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED } } diff --git a/pkg/util/aliyun/instance.go b/pkg/util/aliyun/instance.go index 2621526c7f..7ff16d779c 100644 --- a/pkg/util/aliyun/instance.go +++ b/pkg/util/aliyun/instance.go @@ -26,8 +26,8 @@ import ( "yunion.io/x/pkg/util/seclib" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" ) @@ -291,17 +291,17 @@ func (a byAttachedTime) Len() int { return len(a) } func (a byAttachedTime) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a byAttachedTime) Less(i, j int) bool { switch a[i].GetDiskType() { - case models.DISK_TYPE_SYS: + case api.DISK_TYPE_SYS: return true - case models.DISK_TYPE_SWAP: + case api.DISK_TYPE_SWAP: switch a[j].GetDiskType() { - case models.DISK_TYPE_SYS: + case api.DISK_TYPE_SYS: return false - case models.DISK_TYPE_DATA: + case api.DISK_TYPE_DATA: return true } - case models.DISK_TYPE_DATA: - if a[j].GetDiskType() != models.DISK_TYPE_DATA { + case api.DISK_TYPE_DATA: + if a[j].GetDiskType() != api.DISK_TYPE_DATA { return false } } @@ -386,15 +386,15 @@ func (self *SInstance) GetStatus() string { //Stopped:已停止 switch self.Status { case InstanceStatusRunning: - return models.VM_RUNNING + return api.VM_RUNNING case InstanceStatusStarting: - return models.VM_STARTING + return api.VM_STARTING case InstanceStatusStopping: - return models.VM_STOPPING + return api.VM_STOPPING case InstanceStatusStopped: - return models.VM_READY + return api.VM_READY default: - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } @@ -428,7 +428,7 @@ func (self *SInstance) GetRemoteStatus() string { */ func (self *SInstance) GetHypervisor() string { - return models.HYPERVISOR_ALIYUN + return api.HYPERVISOR_ALIYUN } func (self *SInstance) StartVM(ctx context.Context) error { @@ -441,10 +441,10 @@ func (self *SInstance) StartVM(ctx context.Context) error { if err != nil { return err } - log.Debugf("status %s expect %s", self.GetStatus(), models.VM_RUNNING) - if self.GetStatus() == models.VM_RUNNING { + log.Debugf("status %s expect %s", self.GetStatus(), api.VM_RUNNING) + if self.GetStatus() == api.VM_RUNNING { return nil - } else if self.GetStatus() == models.VM_READY { + } else if self.GetStatus() == api.VM_READY { err := self.host.zone.region.StartVM(self.InstanceId) if err != nil { return err @@ -460,7 +460,7 @@ func (self *SInstance) StopVM(ctx context.Context, isForce bool) error { if err != nil { return err } - return cloudprovider.WaitStatus(self, models.VM_READY, 10*time.Second, 300*time.Second) // 5mintues + return cloudprovider.WaitStatus(self, api.VM_READY, 10*time.Second, 300*time.Second) // 5mintues } func (self *SInstance) GetVNCInfo() (jsonutils.JSONObject, error) { diff --git a/pkg/util/aliyun/region.go b/pkg/util/aliyun/region.go index a08441dc38..dfe5512f6d 100644 --- a/pkg/util/aliyun/region.go +++ b/pkg/util/aliyun/region.go @@ -30,7 +30,6 @@ import ( api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SRegion struct { @@ -195,7 +194,7 @@ func (self *SRegion) GetGeographicInfo() cloudprovider.SGeographicInfo { } func (self *SRegion) GetStatus() string { - return models.CLOUD_REGION_STATUS_INSERVER + return api.CLOUD_REGION_STATUS_INSERVER } func (self *SRegion) Refresh() error { diff --git a/pkg/util/aliyun/snapshot.go b/pkg/util/aliyun/snapshot.go index 94458dd1ea..b3aff76c84 100644 --- a/pkg/util/aliyun/snapshot.go +++ b/pkg/util/aliyun/snapshot.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SnapshotStatusType string @@ -58,11 +58,11 @@ func (self *SSnapshot) GetName() string { func (self *SSnapshot) GetStatus() string { if self.Status == SnapshotStatusAccomplished { - return models.SNAPSHOT_READY + return api.SNAPSHOT_READY } else if self.Status == SnapshotStatusProgress { - return models.SNAPSHOT_CREATING + return api.SNAPSHOT_CREATING } else { // if self.Status == SnapshotStatusFailed - return models.SNAPSHOT_FAILED + return api.SNAPSHOT_FAILED } } @@ -76,9 +76,9 @@ func (self *SSnapshot) GetDiskId() string { func (self *SSnapshot) GetDiskType() string { if self.SourceDiskType == SnapshotTypeSystem { - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS } else if self.SourceDiskType == SnapshotTypeData { - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } else { return "" } diff --git a/pkg/util/aliyun/storage.go b/pkg/util/aliyun/storage.go index 53f3401ebd..247afa2f95 100644 --- a/pkg/util/aliyun/storage.go +++ b/pkg/util/aliyun/storage.go @@ -22,8 +22,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SStorage struct { @@ -83,9 +83,9 @@ func (self *SStorage) GetStorageType() string { func (self *SStorage) GetMediumType() string { if strings.HasSuffix(self.storageType, "_ssd") { - return models.DISK_TYPE_SSD + return api.DISK_TYPE_SSD } else { - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } } @@ -103,7 +103,7 @@ func (self *SStorage) GetManagerId() string { } func (self *SStorage) GetStatus() string { - return models.STORAGE_ONLINE + return api.STORAGE_ONLINE } func (self *SStorage) Refresh() error { diff --git a/pkg/util/aliyun/vswitch.go b/pkg/util/aliyun/vswitch.go index fa71425cfa..d0934b31ca 100644 --- a/pkg/util/aliyun/vswitch.go +++ b/pkg/util/aliyun/vswitch.go @@ -24,8 +24,8 @@ import ( "yunion.io/x/pkg/util/netutils" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) // {"AvailableIpAddressCount":4091,"CidrBlock":"172.31.32.0/20","CreationTime":"2017-03-19T13:37:44Z","Description":"System created default virtual switch.","IsDefault":true,"Status":"Available","VSwitchId":"vsw-j6c3gig5ub4fmi2veyrus","VSwitchName":"","VpcId":"vpc-j6c86z3sh8ufhgsxwme0q","ZoneId":"cn-hongkong-b"} @@ -129,7 +129,7 @@ func (self *SVSwitch) GetGateway() string { } func (self *SVSwitch) GetServerType() string { - return models.NETWORK_TYPE_GUEST + return api.NETWORK_TYPE_GUEST } func (self *SVSwitch) GetIsPublic() bool { diff --git a/pkg/util/aliyun/zone.go b/pkg/util/aliyun/zone.go index d667e30bc7..acf402632d 100644 --- a/pkg/util/aliyun/zone.go +++ b/pkg/util/aliyun/zone.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type TChargeType string @@ -150,9 +150,9 @@ func (self *SZone) IsEmulated() bool { func (self *SZone) GetStatus() string { if len(self.AvailableResourceCreation.ResourceTypes) == 0 || !utils.IsInStringArray("Instance", self.AvailableResourceCreation.ResourceTypes) { - return models.ZONE_SOLDOUT + return api.ZONE_SOLDOUT } else { - return models.ZONE_ENABLE + return api.ZONE_ENABLE } } diff --git a/pkg/util/aws/disk.go b/pkg/util/aws/disk.go index 3c5122aa82..ddfd01ee68 100644 --- a/pkg/util/aws/disk.go +++ b/pkg/util/aws/disk.go @@ -26,8 +26,9 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SMountInstances struct { @@ -98,13 +99,13 @@ func (self *SDisk) GetStatus() string { // creating | available | in-use | deleting | deleted | error switch self.Status { case "creating": - return models.DISK_ALLOCATING + return api.DISK_ALLOCATING case "deleting": - return models.DISK_DEALLOC + return api.DISK_DEALLOC case "error": - return models.DISK_ALLOC_FAILED + return api.DISK_ALLOC_FAILED default: - return models.DISK_READY + return api.DISK_READY } } @@ -122,14 +123,14 @@ func (self *SDisk) IsEmulated() bool { func (self *SDisk) GetMetadata() *jsonutils.JSONDict { data := jsonutils.NewDict() - data.Add(jsonutils.NewString(models.HYPERVISOR_AWS), "hypervisor") + data.Add(jsonutils.NewString(api.HYPERVISOR_AWS), "hypervisor") return data } func (self *SDisk) GetBillingType() string { // todo: implement me - return models.BILLING_TYPE_PREPAID + return billing.BILLING_TYPE_POSTPAID } func (self *SDisk) GetExpiredAt() time.Time { @@ -196,7 +197,7 @@ func (self *SDisk) CreateISnapshot(ctx context.Context, name string, desc string return nil, err } else { snapshot.region = self.storage.zone.region - if err := cloudprovider.WaitStatus(snapshot, models.SNAPSHOT_READY, 15*time.Second, 3600*time.Second); err != nil { + if err := cloudprovider.WaitStatus(snapshot, api.SNAPSHOT_READY, 15*time.Second, 3600*time.Second); err != nil { return nil, err } return snapshot, nil @@ -321,12 +322,12 @@ func (self *SRegion) GetDisks(instanceId string, zoneId string, storageType stri } if disk.Device == instance.RootDeviceName { - disk.Type = models.DISK_TYPE_SYS + disk.Type = api.DISK_TYPE_SYS } else { - disk.Type = models.DISK_TYPE_DATA + disk.Type = api.DISK_TYPE_DATA } } else { - disk.Type = models.DISK_TYPE_DATA + disk.Type = api.DISK_TYPE_DATA } } @@ -335,11 +336,11 @@ func (self *SRegion) GetDisks(instanceId string, zoneId string, storageType stri // 系统盘必须放在第零个位置 sort.Slice(disks, func(i, j int) bool { - if disks[i].Type == models.DISK_TYPE_SYS { + if disks[i].Type == api.DISK_TYPE_SYS { return true } - if disks[j].Type != models.DISK_TYPE_SYS && disks[i].Device < disks[j].Device { + if disks[j].Type != api.DISK_TYPE_SYS && disks[i].Device < disks[j].Device { return true } diff --git a/pkg/util/aws/eip.go b/pkg/util/aws/eip.go index 675a6d7358..1d38a9146c 100644 --- a/pkg/util/aws/eip.go +++ b/pkg/util/aws/eip.go @@ -23,8 +23,9 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) const ( @@ -69,9 +70,9 @@ func (self *SEipAddress) GetStatus() string { switch self.Status { // todo: EIP_STATUS_INUSE 对应READY? case EIP_STATUS_AVAILABLE, EIP_STATUS_INUSE: - return models.EIP_STATUS_READY + return api.EIP_STATUS_READY default: - return models.EIP_STATUS_UNKNOWN + return api.EIP_STATUS_UNKNOWN } } @@ -104,9 +105,9 @@ func (self *SEipAddress) GetIpAddr() string { func (self *SEipAddress) GetMode() string { if self.InstanceId == self.AllocationId { - return models.EIP_MODE_INSTANCE_PUBLICIP + return api.EIP_MODE_INSTANCE_PUBLICIP } else { - return models.EIP_MODE_STANDALONE_EIP + return api.EIP_MODE_STANDALONE_EIP } } @@ -125,7 +126,7 @@ func (self *SEipAddress) GetBandwidth() int { func (self *SEipAddress) GetInternetChargeType() string { // todo : implement me - return models.EIP_CHARGE_TYPE_BY_TRAFFIC + return api.EIP_CHARGE_TYPE_BY_TRAFFIC } func (self *SEipAddress) GetManagerId() string { @@ -141,7 +142,7 @@ func (self *SEipAddress) Associate(instanceId string) error { if err != nil { return err } - err = cloudprovider.WaitStatus(self, models.EIP_STATUS_READY, 10*time.Second, 180*time.Second) + err = cloudprovider.WaitStatus(self, api.EIP_STATUS_READY, 10*time.Second, 180*time.Second) return err } @@ -150,7 +151,7 @@ func (self *SEipAddress) Dissociate() error { if err != nil { return err } - err = cloudprovider.WaitStatus(self, models.EIP_STATUS_READY, 10*time.Second, 180*time.Second) + err = cloudprovider.WaitStatus(self, api.EIP_STATUS_READY, 10*time.Second, 180*time.Second) return err } @@ -315,7 +316,7 @@ func (self *SRegion) UpdateEipBandwidth(eipId string, bw int) error { } func (self *SEipAddress) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing.BILLING_TYPE_POSTPAID } func (self *SEipAddress) GetExpiredAt() time.Time { diff --git a/pkg/util/aws/host.go b/pkg/util/aws/host.go index 1b4cbe640e..9618e29b0b 100644 --- a/pkg/util/aws/host.go +++ b/pkg/util/aws/host.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SHost struct { @@ -41,7 +41,7 @@ func (self *SHost) GetGlobalId() string { } func (self *SHost) GetStatus() string { - return models.HOST_STATUS_RUNNING + return api.HOST_STATUS_RUNNING } func (self *SHost) Refresh() error { @@ -108,7 +108,7 @@ func (self *SHost) GetEnabled() bool { } func (self *SHost) GetHostStatus() string { - return models.HOST_ONLINE + return api.HOST_ONLINE } func (self *SHost) GetAccessIp() string { @@ -154,11 +154,11 @@ func (self *SHost) GetStorageSizeMB() int { } func (self *SHost) GetStorageType() string { - return models.DISK_TYPE_HYBRID + return api.DISK_TYPE_HYBRID } func (self *SHost) GetHostType() string { - return models.HOST_TYPE_AWS + return api.HOST_TYPE_AWS } func (self *SHost) GetManagerId() string { diff --git a/pkg/util/aws/image.go b/pkg/util/aws/image.go index df816ad650..94abe056d1 100644 --- a/pkg/util/aws/image.go +++ b/pkg/util/aws/image.go @@ -25,8 +25,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/timeutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type ImageStatusType string @@ -118,13 +118,13 @@ func (self *SImage) GetGlobalId() string { func (self *SImage) GetStatus() string { switch self.Status { case ImageStatusCreating: - return models.CACHED_IMAGE_STATUS_CACHING + return api.CACHED_IMAGE_STATUS_CACHING case ImageStatusAvailable: - return models.CACHED_IMAGE_STATUS_READY + return api.CACHED_IMAGE_STATUS_READY case ImageStatusCreateFailed: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED default: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED } } diff --git a/pkg/util/aws/instance.go b/pkg/util/aws/instance.go index e9af9f5a49..4aac87bbb4 100644 --- a/pkg/util/aws/instance.go +++ b/pkg/util/aws/instance.go @@ -26,8 +26,9 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/osprofile" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" ) @@ -142,15 +143,15 @@ func (self *SInstance) GetGlobalId() string { func (self *SInstance) GetStatus() string { switch self.Status { case InstanceStatusRunning: - return models.VM_RUNNING + return api.VM_RUNNING case InstanceStatusPending: // todo: pending ? - return models.VM_STARTING + return api.VM_STARTING case InstanceStatusStopping: - return models.VM_STOPPING + return api.VM_STOPPING case InstanceStatusStopped: - return models.VM_READY + return api.VM_READY default: - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } @@ -210,7 +211,7 @@ func (self *SInstance) GetMetadata() *jsonutils.JSONDict { func (self *SInstance) GetBillingType() string { // todo: implement me - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (self *SInstance) GetExpiredAt() time.Time { @@ -318,7 +319,7 @@ func (self *SInstance) SetSecurityGroups(secgroupIds []string) error { } func (self *SInstance) GetHypervisor() string { - return models.HYPERVISOR_AWS + return api.HYPERVISOR_AWS } func (self *SInstance) StartVM(ctx context.Context) error { @@ -332,9 +333,9 @@ func (self *SInstance) StartVM(ctx context.Context) error { return err } - if self.GetStatus() == models.VM_RUNNING { + if self.GetStatus() == api.VM_RUNNING { return nil - } else if self.GetStatus() == models.VM_READY { + } else if self.GetStatus() == api.VM_READY { err := self.host.zone.region.StartVM(self.InstanceId) if err != nil { return err @@ -350,7 +351,7 @@ func (self *SInstance) StopVM(ctx context.Context, isForce bool) error { if err != nil { return err } - return cloudprovider.WaitStatus(self, models.VM_READY, 10*time.Second, 300*time.Second) // 5mintues + return cloudprovider.WaitStatus(self, api.VM_READY, 10*time.Second, 300*time.Second) // 5mintues } func (self *SInstance) DeleteVM(ctx context.Context) error { @@ -641,7 +642,7 @@ func (self *SRegion) CreateInstance(name string, imageId string, instanceType st // io1类型的卷需要指定IOPS参数。这里根据aws网站的建议值进行设置 // 卷每增加1G。IOPS增加50。最大不超过32000 - if disk.Category == models.STORAGE_IO1_SSD { + if disk.Category == api.STORAGE_IO1_SSD { iops := int64(disk.Size * 50) if iops < 32000 { ebs.SetIops(iops) @@ -831,7 +832,7 @@ func (self *SRegion) ReplaceSystemDisk(ctx context.Context, instanceId string, i var rootDisk *SDisk for _, disk := range disks { - if disk.Type == models.DISK_TYPE_SYS { + if disk.Type == api.DISK_TYPE_SYS { rootDisk = &disk break } diff --git a/pkg/util/aws/network.go b/pkg/util/aws/network.go index 4eb4a44ad6..027d089c9e 100644 --- a/pkg/util/aws/network.go +++ b/pkg/util/aws/network.go @@ -25,8 +25,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/netutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SNetwork struct { @@ -114,7 +114,7 @@ func (self *SNetwork) GetGateway() string { } func (self *SNetwork) GetServerType() string { - return models.NETWORK_TYPE_GUEST + return api.NETWORK_TYPE_GUEST } func (self *SNetwork) GetIsPublic() bool { diff --git a/pkg/util/aws/region.go b/pkg/util/aws/region.go index 0778fb4b94..4dae8f5ed1 100644 --- a/pkg/util/aws/region.go +++ b/pkg/util/aws/region.go @@ -27,8 +27,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) var RegionLocations = map[string]string{ @@ -213,7 +213,7 @@ func (self *SRegion) GetGlobalId() string { } func (self *SRegion) GetStatus() string { - return models.CLOUD_REGION_STATUS_INSERVER + return api.CLOUD_REGION_STATUS_INSERVER } func (self *SRegion) Refresh() error { diff --git a/pkg/util/aws/snapshot.go b/pkg/util/aws/snapshot.go index 3dfb71a897..3b8321f920 100644 --- a/pkg/util/aws/snapshot.go +++ b/pkg/util/aws/snapshot.go @@ -23,8 +23,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SnapshotStatusType string @@ -72,11 +72,11 @@ func (self *SSnapshot) GetGlobalId() string { func (self *SSnapshot) GetStatus() string { // todo: implement me if self.Status == SnapshotStatusAccomplished { - return models.SNAPSHOT_READY + return api.SNAPSHOT_READY } else if self.Status == SnapshotStatusProgress { - return models.SNAPSHOT_CREATING + return api.SNAPSHOT_CREATING } else { // if self.Status == SnapshotStatusFailed - return models.SNAPSHOT_FAILED + return api.SNAPSHOT_FAILED } } diff --git a/pkg/util/aws/storage.go b/pkg/util/aws/storage.go index a531a3b295..6857496488 100644 --- a/pkg/util/aws/storage.go +++ b/pkg/util/aws/storage.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SStorage struct { @@ -42,7 +42,7 @@ func (self *SStorage) GetGlobalId() string { } func (self *SStorage) GetStatus() string { - return models.STORAGE_ONLINE + return api.STORAGE_ONLINE } func (self *SStorage) Refresh() error { @@ -91,10 +91,10 @@ func (self *SStorage) GetStorageType() string { } func (self *SStorage) GetMediumType() string { - if self.storageType == models.STORAGE_GP2_SSD || self.storageType == models.STORAGE_IO1_SSD { - return models.DISK_TYPE_SSD + if self.storageType == api.STORAGE_GP2_SSD || self.storageType == api.STORAGE_IO1_SSD { + return api.DISK_TYPE_SSD } else { - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } } diff --git a/pkg/util/aws/zone.go b/pkg/util/aws/zone.go index 0bbbced661..ac61bd995a 100644 --- a/pkg/util/aws/zone.go +++ b/pkg/util/aws/zone.go @@ -20,16 +20,16 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) var StorageTypes = []string{ - models.STORAGE_GP2_SSD, - models.STORAGE_IO1_SSD, - models.STORAGE_ST1_HDD, - models.STORAGE_SC1_HDD, - models.STORAGE_STANDARD_HDD, + api.STORAGE_GP2_SSD, + api.STORAGE_IO1_SSD, + api.STORAGE_ST1_HDD, + api.STORAGE_SC1_HDD, + api.STORAGE_STANDARD_HDD, } type SZone struct { @@ -109,9 +109,9 @@ func (self *SZone) GetGlobalId() string { func (self *SZone) GetStatus() string { if self.State == "unavailable" { - return models.ZONE_SOLDOUT + return api.ZONE_SOLDOUT } else { - return models.ZONE_ENABLE + return api.ZONE_ENABLE } } diff --git a/pkg/util/azure/classic_disk.go b/pkg/util/azure/classic_disk.go index 7a117c670c..c95ffcdcc3 100644 --- a/pkg/util/azure/classic_disk.go +++ b/pkg/util/azure/classic_disk.go @@ -22,8 +22,9 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SClassicDisk struct { @@ -72,9 +73,9 @@ func (self *SRegion) GetStorageAccountDisksWithSnapshots(storageaccount SStorage for _, file := range files { if strings.HasSuffix(file.Name, ".vhd") { - diskType := models.DISK_TYPE_DATA + diskType := api.DISK_TYPE_DATA if _diskType, ok := file.Metadata["microsoftazurecompute_disktype"]; ok && _diskType == "OSDisk" { - diskType = models.DISK_TYPE_SYS + diskType = api.DISK_TYPE_SYS } diskName := file.Name if _diskName, ok := file.Metadata["microsoftazurecompute_diskname"]; ok { @@ -118,7 +119,7 @@ func (self *SRegion) GetClassicDisks() ([]SClassicDisk, error) { func (self *SClassicDisk) GetMetadata() *jsonutils.JSONDict { data := jsonutils.NewDict() - data.Add(jsonutils.NewString(models.HYPERVISOR_AZURE), "hypervisor") + data.Add(jsonutils.NewString(api.HYPERVISOR_AZURE), "hypervisor") return data } @@ -131,7 +132,7 @@ func (self *SClassicDisk) Delete(ctx context.Context) error { } func (self *SClassicDisk) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (self *SClassicDisk) GetFsFormat() string { @@ -211,7 +212,7 @@ func (self *SClassicDisk) GetName() string { } func (self *SClassicDisk) GetStatus() string { - return models.DISK_READY + return api.DISK_READY } func (self *SClassicDisk) IsEmulated() bool { diff --git a/pkg/util/azure/classic_eip.go b/pkg/util/azure/classic_eip.go index c7365c40f4..3a1839baea 100644 --- a/pkg/util/azure/classic_eip.go +++ b/pkg/util/azure/classic_eip.go @@ -21,8 +21,9 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type ClassicEipProperties struct { @@ -85,7 +86,7 @@ func (self *SClassicEipAddress) GetId() string { } func (self *SClassicEipAddress) GetInternetChargeType() string { - return models.EIP_CHARGE_TYPE_BY_TRAFFIC + return api.EIP_CHARGE_TYPE_BY_TRAFFIC } func (self *SClassicEipAddress) GetIpAddr() string { @@ -103,9 +104,9 @@ func (self *SClassicEipAddress) GetMetadata() *jsonutils.JSONDict { func (self *SClassicEipAddress) GetMode() string { // TODO if self.instanceId == self.ID { - return models.EIP_MODE_INSTANCE_PUBLICIP + return api.EIP_MODE_INSTANCE_PUBLICIP } - return models.EIP_MODE_STANDALONE_EIP + return api.EIP_MODE_STANDALONE_EIP } func (self *SClassicEipAddress) GetName() string { @@ -115,10 +116,10 @@ func (self *SClassicEipAddress) GetName() string { func (self *SClassicEipAddress) GetStatus() string { switch self.Properties.Status { case "Created", "": - return models.EIP_STATUS_READY + return api.EIP_STATUS_READY default: log.Errorf("Unknown eip status: %s", self.Properties.ProvisioningState) - return models.EIP_STATUS_UNKNOWN + return api.EIP_STATUS_UNKNOWN } } @@ -159,7 +160,7 @@ func (region *SRegion) GetClassicEips() ([]SClassicEipAddress, error) { } func (self *SClassicEipAddress) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (self *SClassicEipAddress) GetExpiredAt() time.Time { diff --git a/pkg/util/azure/classic_host.go b/pkg/util/azure/classic_host.go index d9c50d1306..cb61c0e3ba 100644 --- a/pkg/util/azure/classic_host.go +++ b/pkg/util/azure/classic_host.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SClassicHost struct { @@ -49,7 +49,7 @@ func (self *SClassicHost) IsEmulated() bool { } func (self *SClassicHost) GetStatus() string { - return models.HOST_STATUS_RUNNING + return api.HOST_STATUS_RUNNING } func (self *SClassicHost) Refresh() error { @@ -88,14 +88,14 @@ func (self *SClassicHost) GetEnabled() bool { } func (self *SClassicHost) GetHostStatus() string { - return models.HOST_ONLINE + return api.HOST_ONLINE } func (self *SClassicHost) GetNodeCount() int8 { return 0 } func (self *SClassicHost) GetHostType() string { - return models.HOST_TYPE_AZURE + return api.HOST_TYPE_AZURE } func (self *SClassicHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { @@ -154,7 +154,7 @@ func (self *SClassicHost) GetStorageSizeMB() int { } func (self *SClassicHost) GetStorageType() string { - return models.DISK_TYPE_HYBRID + return api.DISK_TYPE_HYBRID } func (self *SClassicHost) GetSN() string { diff --git a/pkg/util/azure/classic_instance.go b/pkg/util/azure/classic_instance.go index 09c3abe5fb..ae767fd9dd 100644 --- a/pkg/util/azure/classic_instance.go +++ b/pkg/util/azure/classic_instance.go @@ -24,8 +24,9 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/osprofile" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" ) @@ -158,7 +159,7 @@ func (self *SClassicInstance) GetMetadata() *jsonutils.JSONDict { } func (self *SClassicInstance) GetHypervisor() string { - return models.HYPERVISOR_AZURE + return api.HYPERVISOR_AZURE } func (self *SClassicInstance) IsEmulated() bool { @@ -273,21 +274,21 @@ func (self *SClassicInstance) GetStatus() string { err := self.Refresh() if err != nil { log.Errorf("failed to get status for classic instance %s", self.Name) - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } switch self.Properties.InstanceView.Status { case "StoppedDeallocated": - return models.VM_READY + return api.VM_READY case "ReadyRole": - return models.VM_RUNNING + return api.VM_RUNNING case "Stopped": - return models.VM_READY + return api.VM_READY case "RoleStateUnknown": - return models.VM_UNKNOWN + return api.VM_UNKNOWN default: log.Errorf("Unknow classic instance %s status %s", self.Name, self.Properties.InstanceView.Status) - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } @@ -449,7 +450,7 @@ func (self *SClassicInstance) StartVM(ctx context.Context) error { if err := self.host.zone.region.StartVM(self.ID); err != nil { return err } - return cloudprovider.WaitStatus(self, models.VM_RUNNING, 10*time.Second, 300*time.Second) + return cloudprovider.WaitStatus(self, api.VM_RUNNING, 10*time.Second, 300*time.Second) } func (self *SClassicInstance) StopVM(ctx context.Context, isForce bool) error { @@ -457,7 +458,7 @@ func (self *SClassicInstance) StopVM(ctx context.Context, isForce bool) error { if err != nil { return err } - return cloudprovider.WaitStatus(self, models.VM_READY, 10*time.Second, 300*time.Second) + return cloudprovider.WaitStatus(self, api.VM_READY, 10*time.Second, 300*time.Second) } func (self *SRegion) StopClassicVM(instanceId string, isForce bool) error { @@ -536,7 +537,7 @@ func (self *SClassicInstance) AssignSecurityGroup(secgroupId string) error { } func (self *SClassicInstance) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (self *SClassicInstance) GetExpiredAt() time.Time { diff --git a/pkg/util/azure/classic_network.go b/pkg/util/azure/classic_network.go index d48555afe5..8236d19f65 100644 --- a/pkg/util/azure/classic_network.go +++ b/pkg/util/azure/classic_network.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/util/netutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SClassicNetwork struct { @@ -106,7 +106,7 @@ func (self *SClassicNetwork) GetIsPublic() bool { } func (self *SClassicNetwork) GetServerType() string { - return models.NETWORK_TYPE_GUEST + return api.NETWORK_TYPE_GUEST } func (self *SClassicNetwork) Refresh() error { diff --git a/pkg/util/azure/classic_snapshot.go b/pkg/util/azure/classic_snapshot.go index fdfd25f5e8..2039f484ea 100644 --- a/pkg/util/azure/classic_snapshot.go +++ b/pkg/util/azure/classic_snapshot.go @@ -19,8 +19,8 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SClassicSnapshot struct { @@ -49,7 +49,7 @@ func (self *SClassicSnapshot) GetName() string { } func (self *SClassicSnapshot) GetStatus() string { - return models.SNAPSHOT_READY + return api.SNAPSHOT_READY } func (self *SClassicSnapshot) IsEmulated() bool { diff --git a/pkg/util/azure/classic_storage.go b/pkg/util/azure/classic_storage.go index 5b821e0318..cf2ef14b61 100644 --- a/pkg/util/azure/classic_storage.go +++ b/pkg/util/azure/classic_storage.go @@ -19,8 +19,8 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type ClassicStorageProperties struct { @@ -118,9 +118,9 @@ func (self *SClassicStorage) GetManagerId() string { func (self *SClassicStorage) GetMediumType() string { if strings.Contains(self.Properties.AccountType, "Premium") { - return models.DISK_TYPE_SSD + return api.DISK_TYPE_SSD } - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } func (self *SClassicStorage) GetStorageConf() jsonutils.JSONObject { @@ -129,7 +129,7 @@ func (self *SClassicStorage) GetStorageConf() jsonutils.JSONObject { } func (self *SClassicStorage) GetStatus() string { - return models.STORAGE_ONLINE + return api.STORAGE_ONLINE } func (self *SClassicStorage) GetStorageType() string { diff --git a/pkg/util/azure/disk.go b/pkg/util/azure/disk.go index f92f838594..84191613e0 100644 --- a/pkg/util/azure/disk.go +++ b/pkg/util/azure/disk.go @@ -23,8 +23,9 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type DiskSku struct { @@ -164,7 +165,7 @@ func (self *SRegion) GetDisks() ([]SDisk, error) { func (self *SDisk) GetMetadata() *jsonutils.JSONDict { data := jsonutils.NewDict() - data.Add(jsonutils.NewString(models.HYPERVISOR_AZURE), "hypervisor") + data.Add(jsonutils.NewString(api.HYPERVISOR_AZURE), "hypervisor") return data } @@ -173,15 +174,15 @@ func (self *SDisk) GetStatus() string { status := self.Properties.ProvisioningState switch status { case "Updating": - return models.DISK_ALLOCATING + return api.DISK_ALLOCATING case "Succeeded": - return models.DISK_READY + return api.DISK_READY default: log.Errorf("Unknow azure disk %s status: %s", self.ID, status) - return models.DISK_UNKNOWN + return api.DISK_UNKNOWN } } - return models.DISK_READY + return api.DISK_READY } func (self *SDisk) GetId() string { @@ -267,9 +268,9 @@ func (self *SDisk) GetTemplateId() string { func (self *SDisk) GetDiskType() string { if len(self.Properties.OsType) > 0 { - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS } - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } func (self *SDisk) CreateISnapshot(ctx context.Context, name, desc string) (cloudprovider.ICloudSnapshot, error) { @@ -301,7 +302,7 @@ func (self *SDisk) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) { } func (self *SDisk) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (self *SDisk) GetExpiredAt() time.Time { diff --git a/pkg/util/azure/eip.go b/pkg/util/azure/eip.go index 93c17951d7..24729c1d1c 100644 --- a/pkg/util/azure/eip.go +++ b/pkg/util/azure/eip.go @@ -22,8 +22,9 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type PublicIPAddressSku struct { @@ -73,7 +74,7 @@ func (region *SRegion) AllocateEIP(eipName string) (*SEipAddress, error) { if err != nil { return nil, err } - return &eip, cloudprovider.WaitStatus(&eip, models.EIP_STATUS_READY, 10*time.Second, 300*time.Second) + return &eip, cloudprovider.WaitStatus(&eip, api.EIP_STATUS_READY, 10*time.Second, 300*time.Second) } func (region *SRegion) CreateEIP(eipName string, bwMbps int, chargeType string, bgpType string) (cloudprovider.ICloudEIP, error) { @@ -190,7 +191,7 @@ func (self *SEipAddress) GetId() string { } func (self *SEipAddress) GetInternetChargeType() string { - return models.EIP_CHARGE_TYPE_BY_TRAFFIC + return api.EIP_CHARGE_TYPE_BY_TRAFFIC } func (self *SEipAddress) GetIpAddr() string { @@ -207,15 +208,15 @@ func (self *SEipAddress) GetMetadata() *jsonutils.JSONDict { func (self *SEipAddress) GetMode() string { if self.IsEmulated() { - return models.EIP_MODE_INSTANCE_PUBLICIP + return api.EIP_MODE_INSTANCE_PUBLICIP } if self.Properties.IPConfiguration != nil { nic, err := self.region.GetNetworkInterfaceDetail(self.Properties.IPConfiguration.ID) if err == nil && nic.Properties.VirtualMachine != nil && len(nic.Properties.VirtualMachine.ID) > 0 { - return models.EIP_MODE_INSTANCE_PUBLICIP + return api.EIP_MODE_INSTANCE_PUBLICIP } } - return models.EIP_MODE_STANDALONE_EIP + return api.EIP_MODE_STANDALONE_EIP } func (self *SEipAddress) GetName() string { @@ -225,12 +226,12 @@ func (self *SEipAddress) GetName() string { func (self *SEipAddress) GetStatus() string { switch self.Properties.ProvisioningState { case "Succeeded", "": - return models.EIP_STATUS_READY + return api.EIP_STATUS_READY case "Updating": - return models.EIP_STATUS_ALLOCATE + return api.EIP_STATUS_ALLOCATE default: log.Errorf("Unknown eip status: %s", self.Properties.ProvisioningState) - return models.EIP_STATUS_UNKNOWN + return api.EIP_STATUS_UNKNOWN } } @@ -250,7 +251,7 @@ func (self *SEipAddress) Refresh() error { } func (self *SEipAddress) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (self *SEipAddress) GetExpiredAt() time.Time { diff --git a/pkg/util/azure/host.go b/pkg/util/azure/host.go index 6a646f2836..a2dbfd7c83 100644 --- a/pkg/util/azure/host.go +++ b/pkg/util/azure/host.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/ansible" ) @@ -51,7 +51,7 @@ func (self *SHost) IsEmulated() bool { } func (self *SHost) GetStatus() string { - return models.HOST_STATUS_RUNNING + return api.HOST_STATUS_RUNNING } func (self *SHost) Refresh() error { @@ -240,14 +240,14 @@ func (self *SHost) GetEnabled() bool { } func (self *SHost) GetHostStatus() string { - return models.HOST_ONLINE + return api.HOST_ONLINE } func (self *SHost) GetNodeCount() int8 { return 0 } func (self *SHost) GetHostType() string { - return models.HOST_TYPE_AZURE + return api.HOST_TYPE_AZURE } func (self *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { @@ -278,7 +278,7 @@ func (self *SHost) GetStorageSizeMB() int { } func (self *SHost) GetStorageType() string { - return models.DISK_TYPE_HYBRID + return api.DISK_TYPE_HYBRID } func (self *SHost) GetSN() string { diff --git a/pkg/util/azure/image.go b/pkg/util/azure/image.go index 51818d44a4..9cc8030783 100644 --- a/pkg/util/azure/image.go +++ b/pkg/util/azure/image.go @@ -24,8 +24,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type ImageStatusType string @@ -126,12 +126,12 @@ func (self *SImage) GetGlobalId() string { func (self *SImage) GetStatus() string { switch self.Properties.ProvisioningState { case "created": - return models.CACHED_IMAGE_STATUS_CACHING + return api.CACHED_IMAGE_STATUS_CACHING case "Succeeded": - return models.CACHED_IMAGE_STATUS_READY + return api.CACHED_IMAGE_STATUS_READY default: log.Errorf("Unknow image status: %s", self.Properties.ProvisioningState) - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED } } diff --git a/pkg/util/azure/instance.go b/pkg/util/azure/instance.go index 7e9649fdfc..8ba16d310b 100644 --- a/pkg/util/azure/instance.go +++ b/pkg/util/azure/instance.go @@ -24,8 +24,9 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/osprofile" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" ) @@ -245,7 +246,7 @@ func (self *SInstance) GetMetadata() *jsonutils.JSONDict { } func (self *SInstance) GetHypervisor() string { - return models.HYPERVISOR_AZURE + return api.HYPERVISOR_AZURE } func (self *SInstance) IsEmulated() bool { @@ -446,7 +447,7 @@ func (self *SInstance) GetStatus() string { err := self.Refresh() if err != nil { log.Errorf("failed to get status for instance %s", self.Name) - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } for _, statuses := range self.Properties.InstanceView.Statuses { @@ -454,18 +455,18 @@ func (self *SInstance) GetStatus() string { if code[0] == "PowerState" { switch code[1] { case "stopped", "deallocated": - return models.VM_READY + return api.VM_READY case "running": - return models.VM_RUNNING + return api.VM_RUNNING case "stopping": - return models.VM_START_STOP + return api.VM_START_STOP case "starting": - return models.VM_STARTING + return api.VM_STARTING case "deleting": - return models.VM_DELETING + return api.VM_DELETING default: log.Errorf("Unknow instance status %s", code[1]) - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } } @@ -473,7 +474,7 @@ func (self *SInstance) GetStatus() string { log.Errorf("Find error code: [%s] message: %s", statuses.Code, statuses.Message) } } - return models.VM_UNKNOWN + return api.VM_UNKNOWN } func (self *SInstance) GetIHost() cloudprovider.ICloudHost { @@ -998,7 +999,7 @@ func (self *SInstance) StartVM(ctx context.Context) error { return err } self.host.zone.region.client.jsonRequest("PATCH", self.ID, jsonutils.Marshal(self).String()) - return cloudprovider.WaitStatus(self, models.VM_RUNNING, 10*time.Second, 300*time.Second) + return cloudprovider.WaitStatus(self, api.VM_RUNNING, 10*time.Second, 300*time.Second) } func (self *SInstance) StopVM(ctx context.Context, isForce bool) error { @@ -1007,7 +1008,7 @@ func (self *SInstance) StopVM(ctx context.Context, isForce bool) error { return err } self.host.zone.region.client.jsonRequest("PATCH", self.ID, jsonutils.Marshal(self).String()) - return cloudprovider.WaitStatus(self, models.VM_READY, 10*time.Second, 300*time.Second) + return cloudprovider.WaitStatus(self, api.VM_READY, 10*time.Second, 300*time.Second) } func (self *SRegion) StopVM(instanceId string, isForce bool) error { @@ -1045,7 +1046,7 @@ func (self *SInstance) SetSecurityGroups(secgroupIds []string) error { } func (self *SInstance) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (self *SInstance) GetExpiredAt() time.Time { diff --git a/pkg/util/azure/network.go b/pkg/util/azure/network.go index 129e343467..676f93b694 100644 --- a/pkg/util/azure/network.go +++ b/pkg/util/azure/network.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/util/netutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SNetwork struct { @@ -112,7 +112,7 @@ func (self *SNetwork) GetIsPublic() bool { } func (self *SNetwork) GetServerType() string { - return models.NETWORK_TYPE_GUEST + return api.NETWORK_TYPE_GUEST } func (self *SNetwork) Refresh() error { diff --git a/pkg/util/azure/region.go b/pkg/util/azure/region.go index 0ea8b39dfd..0ad52416bf 100644 --- a/pkg/util/azure/region.go +++ b/pkg/util/azure/region.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/secrules" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/seclib2" ) @@ -143,7 +143,7 @@ func (self *SRegion) GetGeographicInfo() cloudprovider.SGeographicInfo { } func (self *SRegion) GetStatus() string { - return models.CLOUD_REGION_STATUS_INSERVER + return api.CLOUD_REGION_STATUS_INSERVER } func (self *SRegion) CreateIVpc(name string, desc string, cidr string) (cloudprovider.ICloudVpc, error) { diff --git a/pkg/util/azure/snapshot.go b/pkg/util/azure/snapshot.go index 522cb10ebf..52b3fb238e 100644 --- a/pkg/util/azure/snapshot.go +++ b/pkg/util/azure/snapshot.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SnapshotSku struct { @@ -61,10 +61,10 @@ func (self *SSnapshot) GetName() string { func (self *SSnapshot) GetStatus() string { switch self.Properties.ProvisioningState { case "Succeeded": - return models.SNAPSHOT_READY + return api.SNAPSHOT_READY default: log.Errorf("Unknow azure snapshot %s status: %s", self.ID, self.Properties.ProvisioningState) - return models.SNAPSHOT_UNKNOWN + return api.SNAPSHOT_UNKNOWN } } diff --git a/pkg/util/azure/storage.go b/pkg/util/azure/storage.go index 57b5cbcb0e..7e4fe6ab02 100644 --- a/pkg/util/azure/storage.go +++ b/pkg/util/azure/storage.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type Capabilitie struct { @@ -152,9 +152,9 @@ func (self *SStorage) GetManagerId() string { func (self *SStorage) GetMediumType() string { if strings.HasPrefix(self.storageType, "premium") { - return models.DISK_TYPE_SSD + return api.DISK_TYPE_SSD } - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } func (self *SStorage) GetStorageConf() jsonutils.JSONObject { @@ -163,7 +163,7 @@ func (self *SStorage) GetStorageConf() jsonutils.JSONObject { } func (self *SStorage) GetStatus() string { - return models.STORAGE_ONLINE + return api.STORAGE_ONLINE } func (self *SStorage) GetStorageType() string { diff --git a/pkg/util/esxi/host.go b/pkg/util/esxi/host.go index 89495e5b2e..93557162bd 100644 --- a/pkg/util/esxi/host.go +++ b/pkg/util/esxi/host.go @@ -28,8 +28,8 @@ import ( "yunion.io/x/pkg/util/netutils" "yunion.io/x/pkg/util/regutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) var HOST_SYSTEM_PROPS = []string{"name", "parent", "summary", "config", "hardware", "vm", "datastore"} @@ -134,11 +134,11 @@ func (self *SHost) GetStatus() string { */ switch self.getHostSystem().Summary.Runtime.PowerState { case types.HostSystemPowerStatePoweredOn: - return models.HOST_STATUS_RUNNING + return api.HOST_STATUS_RUNNING case types.HostSystemPowerStatePoweredOff: - return models.HOST_STATUS_READY + return api.HOST_STATUS_READY default: - return models.HOST_STATUS_UNKNOWN + return api.HOST_STATUS_UNKNOWN } } @@ -248,9 +248,9 @@ func (self *SHost) GetHostStatus() string { */ switch self.getHostSystem().Summary.Runtime.ConnectionState { case types.HostSystemConnectionStateConnected: - return models.HOST_ONLINE + return api.HOST_ONLINE default: - return models.HOST_OFFLINE + return api.HOST_OFFLINE } } @@ -266,7 +266,7 @@ func findHostNicByMac(nicInfoList []SHostNicInfo, mac string) *SHostNicInfo { func (self *SHost) getAdminNic() *SHostNicInfo { nics := self.getNicInfo() for i := 0; i < len(nics); i += 1 { - if nics[i].NicType == models.NIC_TYPE_ADMIN { + if nics[i].NicType == api.NIC_TYPE_ADMIN { return &nics[i] } } @@ -306,7 +306,7 @@ func (self *SHost) fetchNicInfo() []SHostNicInfo { if pnic != nil { pnic.IpAddr = nic.Spec.Ip.IpAddress if nic.Spec.Portgroup == "Management Network" { - pnic.NicType = models.NIC_TYPE_ADMIN + pnic.NicType = api.NIC_TYPE_ADMIN } pnic.LinkUp = true } @@ -507,16 +507,16 @@ func (self *SHost) GetStorageType() string { } } if ssd == 0 && rotate > 0 { - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } else if ssd > 0 && rotate == 0 { - return models.DISK_TYPE_SSD + return api.DISK_TYPE_SSD } else { - return models.DISK_TYPE_HYBRID + return api.DISK_TYPE_HYBRID } } func (self *SHost) GetHostType() string { - return models.HOST_TYPE_ESXI + return api.HOST_TYPE_ESXI } func (self *SHost) GetManagerId() string { diff --git a/pkg/util/esxi/image.go b/pkg/util/esxi/image.go index 918cbd64f9..ec88e38622 100644 --- a/pkg/util/esxi/image.go +++ b/pkg/util/esxi/image.go @@ -24,8 +24,8 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SImage struct { @@ -68,14 +68,14 @@ func (self *SImage) GetStatus() string { ctx := context.Background() _, err := dm.QueryVirtualDiskInfo(ctx, self.getFullFilename(), self.getDatacenter(), true) if err != nil { - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED } - return models.CACHED_IMAGE_STATUS_READY + return api.CACHED_IMAGE_STATUS_READY } func (self *SImage) GetImageStatus() string { status := self.GetStatus() - if status == models.CACHED_IMAGE_STATUS_READY { + if status == api.CACHED_IMAGE_STATUS_READY { return cloudprovider.IMAGE_STATUS_ACTIVE } return cloudprovider.IMAGE_STATUS_DELETED diff --git a/pkg/util/esxi/storage.go b/pkg/util/esxi/storage.go index 7749b2deb6..6595340287 100644 --- a/pkg/util/esxi/storage.go +++ b/pkg/util/esxi/storage.go @@ -34,8 +34,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/vmdkutils" ) @@ -90,9 +90,9 @@ func (self *SDatastore) GetEnabled() bool { func (self *SDatastore) GetStatus() string { if self.getDatastore().Summary.Accessible { - return models.STORAGE_ONLINE + return api.STORAGE_ONLINE } else { - return models.STORAGE_OFFLINE + return api.STORAGE_OFFLINE } } @@ -297,12 +297,12 @@ func (self *SDatastore) GetStorageType() string { switch strings.ToLower(moStore.Summary.Type) { case "vmfs": if self.isLocalVMFS() { - return models.STORAGE_LOCAL + return api.STORAGE_LOCAL } else { - return models.STORAGE_NAS + return api.STORAGE_NAS } case "nfs", "nfs41", "cifs", "vsan": - return models.STORAGE_NAS + return api.STORAGE_NAS default: log.Fatalf("unsupported datastore type %s", moStore.Summary.Type) return "" @@ -313,9 +313,9 @@ func (self *SDatastore) GetMediumType() string { moStore := self.getDatastore() vmfsInfo, ok := moStore.Info.(*types.VmfsDatastoreInfo) if ok && vmfsInfo.Vmfs.Ssd != nil && *vmfsInfo.Vmfs.Ssd { - return models.DISK_TYPE_SSD + return api.DISK_TYPE_SSD } - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } func (self *SDatastore) GetStorageConf() jsonutils.JSONObject { diff --git a/pkg/util/esxi/vdisk.go b/pkg/util/esxi/vdisk.go index 46a66b9d6c..6b2f193579 100644 --- a/pkg/util/esxi/vdisk.go +++ b/pkg/util/esxi/vdisk.go @@ -26,8 +26,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SVirtualDisk struct { @@ -81,7 +81,7 @@ func (disk *SVirtualDisk) GetGlobalId() string { } func (disk *SVirtualDisk) GetStatus() string { - return models.DISK_READY + return api.DISK_READY } func (disk *SVirtualDisk) Refresh() error { @@ -147,9 +147,9 @@ func (disk *SVirtualDisk) GetTemplateId() string { func (disk *SVirtualDisk) GetDiskType() string { backing := disk.getBackingInfo() if backing.Parent != nil { - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS } - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } func (disk *SVirtualDisk) GetFsFormat() string { diff --git a/pkg/util/esxi/virtualmachine.go b/pkg/util/esxi/virtualmachine.go index a0aafa5899..c42dd836f9 100644 --- a/pkg/util/esxi/virtualmachine.go +++ b/pkg/util/esxi/virtualmachine.go @@ -31,8 +31,9 @@ import ( "yunion.io/x/pkg/util/reflectutils" "yunion.io/x/pkg/util/regutils" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" ) @@ -76,17 +77,17 @@ func (self *SVirtualMachine) GetStatus() string { vm := object.NewVirtualMachine(self.manager.client.Client, self.getVirtualMachine().Self) state, err := vm.PowerState(self.manager.context) if err != nil { - return models.VM_UNKNOWN + return api.VM_UNKNOWN } switch state { case types.VirtualMachinePowerStatePoweredOff: - return models.VM_READY + return api.VM_READY case types.VirtualMachinePowerStatePoweredOn: - return models.VM_RUNNING + return api.VM_RUNNING case types.VirtualMachinePowerStateSuspended: - return models.VM_SUSPEND + return api.VM_SUSPEND default: - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } @@ -302,7 +303,7 @@ func (self *SVirtualMachine) GetMachine() string { } func (self *SVirtualMachine) GetHypervisor() string { - return models.HYPERVISOR_ESXI + return api.HYPERVISOR_ESXI } func (self *SVirtualMachine) getVmObj() *object.VirtualMachine { @@ -311,7 +312,7 @@ func (self *SVirtualMachine) getVmObj() *object.VirtualMachine { // ideopotent start func (self *SVirtualMachine) StartVM(ctx context.Context) error { - if self.GetStatus() == models.VM_RUNNING { + if self.GetStatus() == api.VM_RUNNING { return nil } return self.startVM(ctx) @@ -358,7 +359,7 @@ func makeNicStartConnected(nic *SVirtualNIC) *types.VirtualDeviceConfigSpec { } func (self *SVirtualMachine) StopVM(ctx context.Context, isForce bool) error { - if self.GetStatus() == models.VM_READY { + if self.GetStatus() == api.VM_READY { return nil } if !isForce && self.isToolsOk() { @@ -557,7 +558,7 @@ func (self *SVirtualMachine) SetSecurityGroups(secgroupIds []string) error { } func (self *SVirtualMachine) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (self *SVirtualMachine) GetExpiredAt() time.Time { diff --git a/pkg/util/huawei/disk.go b/pkg/util/huawei/disk.go index 09597f5560..1cd0255b2b 100644 --- a/pkg/util/huawei/disk.go +++ b/pkg/util/huawei/disk.go @@ -22,8 +22,9 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) /* @@ -132,37 +133,37 @@ func (self *SDisk) GetStatus() string { // https://support.huaweicloud.com/api-evs/zh-cn_topic_0051803385.html switch self.Status { case "creating", "downloading": - return models.DISK_ALLOCATING + return api.DISK_ALLOCATING case "available", "in-use": - return models.DISK_READY + return api.DISK_READY case "error": - return models.DISK_ALLOC_FAILED + return api.DISK_ALLOC_FAILED case "attaching": - return models.DISK_ATTACHING + return api.DISK_ATTACHING case "detaching": - return models.DISK_DETACHING + return api.DISK_DETACHING case "restoring-backup": - return models.DISK_REBUILD + return api.DISK_REBUILD case "backing-up": - return models.DISK_BACKUP_STARTALLOC // ? + return api.DISK_BACKUP_STARTALLOC // ? case "error_restoring": - return models.DISK_BACKUP_ALLOC_FAILED + return api.DISK_BACKUP_ALLOC_FAILED case "uploading": - return models.DISK_SAVING //? + return api.DISK_SAVING //? case "extending": - return models.DISK_RESIZING + return api.DISK_RESIZING case "error_extending": - return models.DISK_ALLOC_FAILED // ? + return api.DISK_ALLOC_FAILED // ? case "deleting": - return models.DISK_DEALLOC //? + return api.DISK_DEALLOC //? case "error_deleting": - return models.DISK_DEALLOC_FAILED // ? + return api.DISK_DEALLOC_FAILED // ? case "rollbacking": - return models.DISK_REBUILD + return api.DISK_REBUILD case "error_rollbacking": - return models.DISK_UNKNOWN + return api.DISK_UNKNOWN default: - return models.DISK_UNKNOWN + return api.DISK_UNKNOWN } } @@ -181,7 +182,7 @@ func (self *SDisk) IsEmulated() bool { func (self *SDisk) GetMetadata() *jsonutils.JSONDict { // todo: add price key data := jsonutils.NewDict() - data.Add(jsonutils.NewString(models.HYPERVISOR_HUAWEI), "hypervisor") + data.Add(jsonutils.NewString(api.HYPERVISOR_HUAWEI), "hypervisor") return data } @@ -189,9 +190,9 @@ func (self *SDisk) GetMetadata() *jsonutils.JSONDict { func (self *SDisk) GetBillingType() string { // https://support.huaweicloud.com/api-evs/zh-cn_topic_0020235170.html if self.Metadata.Billing == "1" { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } else { - return models.BILLING_TYPE_PREPAID // ? + return billing_api.BILLING_TYPE_PREPAID // ? } } @@ -260,9 +261,9 @@ func (self *SDisk) GetTemplateId() string { // 启动盘 != 系统盘(必须是启动盘且挂载在root device上) func (self *SDisk) GetDiskType() string { if self.Bootable == "true" { - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS } else { - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } } @@ -311,7 +312,7 @@ func (self *SDisk) Delete(ctx context.Context) error { return nil } else if disk.Status != "deleting" { // 等待硬盘ready - cloudprovider.WaitStatus(self, models.DISK_READY, 5*time.Second, 60*time.Second) + cloudprovider.WaitStatus(self, api.DISK_READY, 5*time.Second, 60*time.Second) err := self.storage.zone.region.DeleteDisk(self.GetId()) if err != nil { return err @@ -329,7 +330,7 @@ func (self *SDisk) CreateISnapshot(ctx context.Context, name string, desc string return nil, err } else { snapshot.region = self.storage.zone.region - if err := cloudprovider.WaitStatus(snapshot, models.SNAPSHOT_READY, 15*time.Second, 3600*time.Second); err != nil { + if err := cloudprovider.WaitStatus(snapshot, api.SNAPSHOT_READY, 15*time.Second, 3600*time.Second); err != nil { return nil, err } return snapshot, nil @@ -360,7 +361,7 @@ func (self *SDisk) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) { } func (self *SDisk) Resize(ctx context.Context, newSizeMB int64) error { - err := cloudprovider.WaitStatus(self, models.DISK_READY, 5*time.Second, 60*time.Second) + err := cloudprovider.WaitStatus(self, api.DISK_READY, 5*time.Second, 60*time.Second) if err != nil { return err } @@ -371,7 +372,7 @@ func (self *SDisk) Resize(ctx context.Context, newSizeMB int64) error { return err } - return cloudprovider.WaitStatusWithDelay(self, models.DISK_READY, 15*time.Second, 5*time.Second, 60*time.Second) + return cloudprovider.WaitStatusWithDelay(self, api.DISK_READY, 15*time.Second, 5*time.Second, 60*time.Second) } func (self *SDisk) Detach() error { @@ -403,7 +404,7 @@ func (self *SDisk) Attach(device string) error { return err } - return cloudprovider.WaitStatus(self, models.DISK_READY, 5*time.Second, 60*time.Second) + return cloudprovider.WaitStatus(self, api.DISK_READY, 5*time.Second, 60*time.Second) } // 在线卸载磁盘 https://support.huaweicloud.com/usermanual-ecs/zh-cn_topic_0036046828.html @@ -422,7 +423,7 @@ func (self *SDisk) Reset(ctx context.Context, snapshotId string) (string, error) return diskId, err } - err = cloudprovider.WaitStatus(self, models.DISK_READY, 5*time.Second, 300*time.Second) + err = cloudprovider.WaitStatus(self, api.DISK_READY, 5*time.Second, 300*time.Second) if err != nil { return "", err } diff --git a/pkg/util/huawei/eip.go b/pkg/util/huawei/eip.go index f55266b093..4b8fb3b572 100644 --- a/pkg/util/huawei/eip.go +++ b/pkg/util/huawei/eip.go @@ -20,8 +20,9 @@ import ( "yunion.io/x/jsonutils" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type TInternetChargeType string @@ -113,17 +114,17 @@ func (self *SEipAddress) GetStatus() string { // https://support.huaweicloud.com/api-vpc/zh-cn_topic_0020090598.html switch self.Status { case "ACTIVE", "DOWN", "ELB": - return models.EIP_STATUS_READY + return api.EIP_STATUS_READY case "PENDING_CREATE", "NOTIFYING": - return models.EIP_STATUS_ALLOCATE + return api.EIP_STATUS_ALLOCATE case "BINDING": - return models.EIP_STATUS_ALLOCATE + return api.EIP_STATUS_ALLOCATE case "BIND_ERROR": - return models.EIP_STATUS_ALLOCATE_FAIL + return api.EIP_STATUS_ALLOCATE_FAIL case "PENDING_DELETE", "NOTIFY_DELETE": - return models.EIP_STATUS_DEALLOCATE + return api.EIP_STATUS_DEALLOCATE default: - return models.EIP_STATUS_UNKNOWN + return api.EIP_STATUS_UNKNOWN } } @@ -151,7 +152,7 @@ func (self *SEipAddress) GetIpAddr() string { } func (self *SEipAddress) GetMode() string { - return models.EIP_MODE_STANDALONE_EIP + return api.EIP_MODE_STANDALONE_EIP } func (self *SEipAddress) GetAssociationType() string { @@ -181,13 +182,13 @@ func (self *SEipAddress) GetInternetChargeType() string { // https://support.huaweicloud.com/api-vpc/zh-cn_topic_0020090603.html bandwidth, err := self.region.GetEipBandwidth(self.BandwidthID) if err != nil { - return models.EIP_CHARGE_TYPE_BY_TRAFFIC + return api.EIP_CHARGE_TYPE_BY_TRAFFIC } if bandwidth.ChargeMode != "traffic" { - return models.EIP_CHARGE_TYPE_BY_BANDWIDTH + return api.EIP_CHARGE_TYPE_BY_BANDWIDTH } else { - return models.EIP_CHARGE_TYPE_BY_TRAFFIC + return api.EIP_CHARGE_TYPE_BY_TRAFFIC } } @@ -197,9 +198,9 @@ func (self *SEipAddress) GetManagerId() string { func (self *SEipAddress) GetBillingType() string { if self.Profile == nil { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } else { - return models.BILLING_TYPE_PREPAID + return billing_api.BILLING_TYPE_PREPAID } } @@ -230,7 +231,7 @@ func (self *SEipAddress) Associate(instanceId string) error { return err } - err = cloudprovider.WaitStatus(self, models.EIP_STATUS_READY, 10*time.Second, 180*time.Second) + err = cloudprovider.WaitStatus(self, api.EIP_STATUS_READY, 10*time.Second, 180*time.Second) return err } @@ -244,7 +245,7 @@ func (self *SEipAddress) Dissociate() error { if err != nil { return err } - err = cloudprovider.WaitStatus(self, models.EIP_STATUS_READY, 10*time.Second, 180*time.Second) + err = cloudprovider.WaitStatus(self, api.EIP_STATUS_READY, 10*time.Second, 180*time.Second) return err } diff --git a/pkg/util/huawei/host.go b/pkg/util/huawei/host.go index 049173a0be..c705e4f3f2 100644 --- a/pkg/util/huawei/host.go +++ b/pkg/util/huawei/host.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" ) @@ -44,7 +44,7 @@ func (self *SHost) GetGlobalId() string { } func (self *SHost) GetStatus() string { - return models.HOST_STATUS_RUNNING + return api.HOST_STATUS_RUNNING } func (self *SHost) Refresh() error { @@ -103,7 +103,7 @@ func (self *SHost) GetEnabled() bool { } func (self *SHost) GetHostStatus() string { - return models.HOST_ONLINE + return api.HOST_ONLINE } func (self *SHost) GetAccessIp() string { @@ -149,11 +149,11 @@ func (self *SHost) GetStorageSizeMB() int { } func (self *SHost) GetStorageType() string { - return models.DISK_TYPE_HYBRID + return api.DISK_TYPE_HYBRID } func (self *SHost) GetHostType() string { - return models.HOST_TYPE_HUAWEI + return api.HOST_TYPE_HUAWEI } func (self *SHost) GetIsMaintenance() bool { diff --git a/pkg/util/huawei/image.go b/pkg/util/huawei/image.go index 02115de76f..f6d4d7243d 100644 --- a/pkg/util/huawei/image.go +++ b/pkg/util/huawei/image.go @@ -23,8 +23,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type TImageOwnerType string @@ -104,13 +104,13 @@ func (self *SImage) GetGlobalId() string { func (self *SImage) GetStatus() string { switch self.Status { case ImageStatusQueued: - return models.CACHED_IMAGE_STATUS_CACHING + return api.CACHED_IMAGE_STATUS_CACHING case ImageStatusActive: - return models.CACHED_IMAGE_STATUS_READY + return api.CACHED_IMAGE_STATUS_READY case ImageStatusKilled: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED default: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED } } diff --git a/pkg/util/huawei/instance.go b/pkg/util/huawei/instance.go index 650d49c1f5..c0e9fa2d57 100644 --- a/pkg/util/huawei/instance.go +++ b/pkg/util/huawei/instance.go @@ -27,8 +27,9 @@ import ( "yunion.io/x/pkg/util/osprofile" "yunion.io/x/pkg/utils" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" "yunion.io/x/onecloud/pkg/util/huawei/client/modules" ) @@ -173,7 +174,7 @@ func compareSet(currentSet []string, newSet []string) (add []string, remove []st // 启动盘 != 系统盘(必须是启动盘且挂载在root device上) func isBootDisk(server *SInstance, disk *SDisk) bool { - if disk.GetDiskType() != models.DISK_TYPE_SYS { + if disk.GetDiskType() != api.DISK_TYPE_SYS { return false } @@ -201,15 +202,15 @@ func (self *SInstance) GetGlobalId() string { func (self *SInstance) GetStatus() string { switch self.Status { case "ACTIVE": - return models.VM_RUNNING + return api.VM_RUNNING case "MIGRATING", "REBUILD", "BUILD", "RESIZE", "VERIFY_RESIZE": // todo: pending ? - return models.VM_STARTING + return api.VM_STARTING case "REBOOT", "HARD_REBOOT": - return models.VM_STOPPING + return api.VM_STOPPING case "SHUTOFF": - return models.VM_READY + return api.VM_READY default: - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } @@ -264,9 +265,9 @@ func (self *SInstance) GetBillingType() string { // https://support.huaweicloud.com/api-ecs/zh-cn_topic_0094148849.html // charging_mode “0”:按需计费 “1”:按包年包月计费 if self.Metadata.ChargingMode == "1" { - return models.BILLING_TYPE_PREPAID + return billing_api.BILLING_TYPE_PREPAID } else { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } } @@ -431,7 +432,7 @@ func (self *SInstance) SetSecurityGroups(secgroupIds []string) error { } func (self *SInstance) GetHypervisor() string { - return models.HYPERVISOR_HUAWEI + return api.HYPERVISOR_HUAWEI } func (self *SInstance) StartVM(ctx context.Context) error { @@ -449,9 +450,9 @@ func (self *SInstance) StartVM(ctx context.Context) error { return err } - if self.GetStatus() == models.VM_RUNNING { + if self.GetStatus() == api.VM_RUNNING { return nil - } else if self.GetStatus() == models.VM_READY { + } else if self.GetStatus() == api.VM_READY { err := self.host.zone.region.StartVM(self.GetId()) if err != nil { return err @@ -476,7 +477,7 @@ func (self *SInstance) StopVM(ctx context.Context, isForce bool) error { if err != nil { return err } - return cloudprovider.WaitStatus(self, models.VM_READY, 10*time.Second, 300*time.Second) // 5mintues + return cloudprovider.WaitStatus(self, api.VM_READY, 10*time.Second, 300*time.Second) // 5mintues } func (self *SInstance) DeleteVM(ctx context.Context) error { @@ -561,7 +562,7 @@ func (self *SInstance) ChangeConfig(ctx context.Context, ncpu int, vmem int) err return err } - return cloudprovider.WaitStatusWithDelay(self, models.VM_READY, 15*time.Second, 15*time.Second, 180*time.Second) + return cloudprovider.WaitStatusWithDelay(self, api.VM_READY, 15*time.Second, 15*time.Second, 180*time.Second) } func (self *SInstance) ChangeConfig2(ctx context.Context, instanceType string) error { @@ -570,7 +571,7 @@ func (self *SInstance) ChangeConfig2(ctx context.Context, instanceType string) e return err } - return cloudprovider.WaitStatusWithDelay(self, models.VM_READY, 15*time.Second, 15*time.Second, 180*time.Second) + return cloudprovider.WaitStatusWithDelay(self, api.VM_READY, 15*time.Second, 15*time.Second, 180*time.Second) } // todo:// 返回jsonobject感觉很诡异。不能直接知道内部细节 diff --git a/pkg/util/huawei/network.go b/pkg/util/huawei/network.go index e85f0424a2..71bce941f8 100644 --- a/pkg/util/huawei/network.go +++ b/pkg/util/huawei/network.go @@ -19,8 +19,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/netutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/huawei/client/modules" ) @@ -68,11 +68,11 @@ func (self *SNetwork) GetGlobalId() string { func (self *SNetwork) GetStatus() string { switch self.Status { case "ACTIVE", "UNKNOWN": - return models.NETWORK_STATUS_AVAILABLE // ? todo: // UNKNOWN + return api.NETWORK_STATUS_AVAILABLE // ? todo: // UNKNOWN case "ERROR": - return models.NETWORK_STATUS_UNKNOWN + return api.NETWORK_STATUS_UNKNOWN default: - return models.NETWORK_STATUS_UNKNOWN + return api.NETWORK_STATUS_UNKNOWN } } @@ -127,7 +127,7 @@ func (self *SNetwork) GetGateway() string { } func (self *SNetwork) GetServerType() string { - return models.NETWORK_TYPE_GUEST + return api.NETWORK_TYPE_GUEST } func (self *SNetwork) GetIsPublic() bool { diff --git a/pkg/util/huawei/region.go b/pkg/util/huawei/region.go index 6aa76e1a12..d088e1377d 100644 --- a/pkg/util/huawei/region.go +++ b/pkg/util/huawei/region.go @@ -24,8 +24,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/secrules" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/huawei/client" "yunion.io/x/onecloud/pkg/util/huawei/obs" ) @@ -182,7 +182,7 @@ func (self *SRegion) GetGlobalId() string { } func (self *SRegion) GetStatus() string { - return models.CLOUD_REGION_STATUS_INSERVER + return api.CLOUD_REGION_STATUS_INSERVER } func (self *SRegion) Refresh() error { @@ -382,9 +382,9 @@ func (self *SRegion) CreateIVpc(name string, desc string, cidr string) (cloudpro func (self *SRegion) CreateEIP(name string, bwMbps int, chargeType string, bgpType string) (cloudprovider.ICloudEIP, error) { var ctype TInternetChargeType switch chargeType { - case models.EIP_CHARGE_TYPE_BY_TRAFFIC: + case api.EIP_CHARGE_TYPE_BY_TRAFFIC: ctype = InternetChargeByTraffic - case models.EIP_CHARGE_TYPE_BY_BANDWIDTH: + case api.EIP_CHARGE_TYPE_BY_BANDWIDTH: ctype = InternetChargeByBandwidth } @@ -408,7 +408,7 @@ func (self *SRegion) CreateEIP(name string, bwMbps int, chargeType string, bgpTy return nil, err } - err = cloudprovider.WaitStatus(eip, models.EIP_STATUS_READY, 5*time.Second, 60*time.Second) + err = cloudprovider.WaitStatus(eip, api.EIP_STATUS_READY, 5*time.Second, 60*time.Second) return eip, err } diff --git a/pkg/util/huawei/snapshot.go b/pkg/util/huawei/snapshot.go index 0dba1e8b54..223b239163 100644 --- a/pkg/util/huawei/snapshot.go +++ b/pkg/util/huawei/snapshot.go @@ -19,7 +19,7 @@ import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/compute/models" + api "yunion.io/x/onecloud/pkg/apis/compute" ) /* @@ -77,17 +77,17 @@ func (self *SSnapshot) GetGlobalId() string { func (self *SSnapshot) GetStatus() string { switch SnapshotStatusType(self.Status) { case SnapshotStatusAvailable: - return models.SNAPSHOT_READY + return api.SNAPSHOT_READY case SnapshotStatusCreating: - return models.SNAPSHOT_CREATING + return api.SNAPSHOT_CREATING case SnapshotStatusDeleting: - return models.SNAPSHOT_DELETING + return api.SNAPSHOT_DELETING case SnapshotStatusErrorDeleting, SnapshotStatusError: - return models.SNAPSHOT_FAILED + return api.SNAPSHOT_FAILED case SnapshotStatusRollbacking: - return models.SNAPSHOT_ROLLBACKING + return api.SNAPSHOT_ROLLBACKING default: - return models.SNAPSHOT_UNKNOWN + return api.SNAPSHOT_UNKNOWN } } @@ -122,9 +122,9 @@ func (self *SSnapshot) GetDiskId() string { func (self *SSnapshot) GetDiskType() string { if self.Metadata.SystemEnableActive == "true" { - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS } else { - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } } diff --git a/pkg/util/huawei/storage.go b/pkg/util/huawei/storage.go index c846352612..1a5428b82b 100644 --- a/pkg/util/huawei/storage.go +++ b/pkg/util/huawei/storage.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SStorage struct { @@ -43,7 +43,7 @@ func (self *SStorage) GetGlobalId() string { } func (self *SStorage) GetStatus() string { - return models.STORAGE_ONLINE + return api.STORAGE_ONLINE } func (self *SStorage) Refresh() error { @@ -94,10 +94,10 @@ func (self *SStorage) GetStorageType() string { } func (self *SStorage) GetMediumType() string { - if self.storageType == models.STORAGE_HUAWEI_SSD { - return models.DISK_TYPE_SSD + if self.storageType == api.STORAGE_HUAWEI_SSD { + return api.DISK_TYPE_SSD } else { - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } } @@ -131,7 +131,7 @@ func (self *SStorage) CreateIDisk(name string, sizeGb int, desc string) (cloudpr } disk.storage = self - err = cloudprovider.WaitStatus(disk, models.DISK_READY, 5*time.Second, 120*time.Second) + err = cloudprovider.WaitStatus(disk, api.DISK_READY, 5*time.Second, 120*time.Second) if err != nil { return nil, err } diff --git a/pkg/util/huawei/storagecache.go b/pkg/util/huawei/storagecache.go index 1cc8886bfc..03a78ad245 100644 --- a/pkg/util/huawei/storagecache.go +++ b/pkg/util/huawei/storagecache.go @@ -24,8 +24,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/compute/options" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" @@ -290,8 +290,8 @@ func (self *SRegion) createIImage(snapshotId, imageName, imageDesc string) (stri return "", err } - if disk.GetDiskType() != models.DISK_TYPE_SYS { - return "", fmt.Errorf("disk type err, expected disk type %s", models.DISK_TYPE_SYS) + if disk.GetDiskType() != api.DISK_TYPE_SYS { + return "", fmt.Errorf("disk type err, expected disk type %s", api.DISK_TYPE_SYS) } if len(disk.Attachments) == 0 { diff --git a/pkg/util/huawei/vpc.go b/pkg/util/huawei/vpc.go index 308021d5d5..7c48e9326e 100644 --- a/pkg/util/huawei/vpc.go +++ b/pkg/util/huawei/vpc.go @@ -19,8 +19,8 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) // https://support.huaweicloud.com/api-vpc/zh-cn_topic_0020090625.html @@ -113,7 +113,7 @@ func (self *SVpc) GetGlobalId() string { } func (self *SVpc) GetStatus() string { - return models.VPC_STATUS_AVAILABLE + return api.VPC_STATUS_AVAILABLE } func (self *SVpc) Refresh() error { diff --git a/pkg/util/huawei/zone.go b/pkg/util/huawei/zone.go index da55374207..6741bb32cc 100644 --- a/pkg/util/huawei/zone.go +++ b/pkg/util/huawei/zone.go @@ -19,14 +19,14 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) var StorageTypes = []string{ - models.STORAGE_HUAWEI_SAS, - models.STORAGE_HUAWEI_SATA, - models.STORAGE_HUAWEI_SSD, + api.STORAGE_HUAWEI_SAS, + api.STORAGE_HUAWEI_SATA, + api.STORAGE_HUAWEI_SSD, } type ZoneState struct { diff --git a/pkg/util/openstack/disk.go b/pkg/util/openstack/disk.go index 0bf336d393..50f7f74e08 100644 --- a/pkg/util/openstack/disk.go +++ b/pkg/util/openstack/disk.go @@ -23,8 +23,9 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) const ( @@ -117,7 +118,7 @@ type SDisk struct { func (disk *SDisk) GetMetadata() *jsonutils.JSONDict { data := jsonutils.NewDict() - data.Add(jsonutils.NewString(models.HYPERVISOR_OPENSTACK), "hypervisor") + data.Add(jsonutils.NewString(api.HYPERVISOR_OPENSTACK), "hypervisor") return data } @@ -194,21 +195,21 @@ func (disk *SDisk) GetIStorage() (cloudprovider.ICloudStorage, error) { func (disk *SDisk) GetStatus() string { switch disk.Status { case DISK_STATUS_CREATING, DISK_STATUS_DOWNLOADING: - return models.DISK_ALLOCATING + return api.DISK_ALLOCATING case DISK_STATUS_ATTACHING: - return models.DISK_ATTACHING + return api.DISK_ATTACHING case DISK_STATUS_DETACHING: - return models.DISK_DETACHING + return api.DISK_DETACHING case DISK_STATUS_EXTENDING: - return models.DISK_RESIZING + return api.DISK_RESIZING case DISK_STATUS_RETYPING, DISK_STATUS_AVAILABLE, DISK_STATUS_RESERVED, DISK_STATUS_IN_USE, DISK_STATUS_MAINTENANCE, DISK_STATUS_AWAITING_TRANSFER, DISK_STATUS_BACKING_UP, DISK_STATUS_RESTORING_BACKUP, DISK_STATUS_UPLOADING: - return models.DISK_READY + return api.DISK_READY case DISK_STATUS_DELETING: - return models.DISK_DEALLOC + return api.DISK_DEALLOC case DISK_STATUS_ERROR: - return models.DISK_ALLOC_FAILED + return api.DISK_ALLOC_FAILED default: - return models.DISK_UNKNOWN + return api.DISK_UNKNOWN } } @@ -242,9 +243,9 @@ func (disk *SDisk) GetTemplateId() string { func (disk *SDisk) GetDiskType() string { if disk.Bootable { - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS } - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } func (disk *SDisk) GetFsFormat() string { @@ -295,18 +296,18 @@ func (region *SRegion) CreateDisk(imageRef string, category string, name string, if err != nil { return nil, err } - log.Debugf("disk status %s expect %s", disk.GetStatus(), models.DISK_READY) + log.Debugf("disk status %s expect %s", disk.GetStatus(), api.DISK_READY) status := disk.GetStatus() - if status == models.DISK_READY { + if status == api.DISK_READY { break } - if status == models.DISK_ALLOC_FAILED { + if status == api.DISK_ALLOC_FAILED { region.DeleteDisk(disk.GetGlobalId()) return nil, fmt.Errorf("allocate disk failed, status is error") } time.Sleep(time.Second * 10) } - if disk.GetStatus() != models.DISK_READY { + if disk.GetStatus() != api.DISK_READY { region.DeleteDisk(disk.GetGlobalId()) return nil, fmt.Errorf("timeout for waitting disk ready, current status: %s", disk.Status) } @@ -354,7 +355,7 @@ func (disk *SDisk) CreateISnapshot(ctx context.Context, name, desc string) (clou if err != nil { return nil, err } - return snapshot, cloudprovider.WaitStatus(snapshot, models.SNAPSHOT_READY, time.Second*5, time.Minute*5) + return snapshot, cloudprovider.WaitStatus(snapshot, api.SNAPSHOT_READY, time.Second*5, time.Minute*5) } func (disk *SDisk) GetISnapshot(snapshotId string) (cloudprovider.ICloudSnapshot, error) { @@ -370,7 +371,7 @@ func (disk *SDisk) Reset(ctx context.Context, snapshotId string) (string, error) } func (disk *SDisk) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (disk *SDisk) GetExpiredAt() time.Time { diff --git a/pkg/util/openstack/flavor.go b/pkg/util/openstack/flavor.go index 9dbd69eb53..681225e1be 100644 --- a/pkg/util/openstack/flavor.go +++ b/pkg/util/openstack/flavor.go @@ -19,7 +19,7 @@ import ( "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/compute/models" + api "yunion.io/x/onecloud/pkg/apis/compute" ) type SFlavor struct { @@ -152,11 +152,11 @@ func (flavor *SFlavor) GetInstanceTypeCategory() string { } func (flavor *SFlavor) GetPrepaidStatus() string { - return models.SkuStatusSoldout + return api.SkuStatusSoldout } func (flavor *SFlavor) GetPostpaidStatus() string { - return models.SkuStatusAvailable + return api.SkuStatusAvailable } func (flavor *SFlavor) GetCpuCoreCount() int { diff --git a/pkg/util/openstack/host.go b/pkg/util/openstack/host.go index 080af3a248..bccdb76342 100644 --- a/pkg/util/openstack/host.go +++ b/pkg/util/openstack/host.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) const ( @@ -330,19 +330,19 @@ func (host *SHost) GetStorageSizeMB() int { } func (host *SHost) GetStorageType() string { - return models.DISK_TYPE_HYBRID + return api.DISK_TYPE_HYBRID } func (host *SHost) GetHostType() string { - return models.HOST_TYPE_OPENSTACK + return api.HOST_TYPE_OPENSTACK } func (host *SHost) GetHostStatus() string { switch host.State { case "up", "": - return models.HOST_ONLINE + return api.HOST_ONLINE default: - return models.HOST_OFFLINE + return api.HOST_OFFLINE } } @@ -369,7 +369,7 @@ func (host *SHost) GetManagerId() string { } func (host *SHost) GetStatus() string { - return models.HOST_STATUS_RUNNING + return api.HOST_STATUS_RUNNING } func (host *SHost) IsEmulated() bool { diff --git a/pkg/util/openstack/image.go b/pkg/util/openstack/image.go index d4a8d77d94..1162cd045f 100644 --- a/pkg/util/openstack/image.go +++ b/pkg/util/openstack/image.go @@ -22,8 +22,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) const ( @@ -116,13 +116,13 @@ func (image *SImage) Delete(ctx context.Context) error { func (image *SImage) GetStatus() string { switch image.Status { case QUEUED, SAVING, UPLOADING, IMPORTING: - return models.CACHED_IMAGE_STATUS_CACHING + return api.CACHED_IMAGE_STATUS_CACHING case ACTIVE: - return models.CACHED_IMAGE_STATUS_READY + return api.CACHED_IMAGE_STATUS_READY case DELETED, DEACTIVATED, PENDING_DELETE, KILLED: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED default: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED } } diff --git a/pkg/util/openstack/instance.go b/pkg/util/openstack/instance.go index 23b885b3ea..e8227e9d4a 100644 --- a/pkg/util/openstack/instance.go +++ b/pkg/util/openstack/instance.go @@ -24,8 +24,9 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" ) @@ -313,25 +314,26 @@ func (instance *SInstance) GetMachine() string { func (instance *SInstance) GetStatus() string { switch instance.Status { case INSTANCE_STATUS_ACTIVE, INSTANCE_STATUS_RESCUE: - return models.VM_RUNNING + return api.VM_RUNNING case INSTANCE_STATUS_BUILD, INSTANCE_STATUS_PASSWORD: - return models.VM_DEPLOYING + return api.VM_DEPLOYING case INSTANCE_STATUS_DELETED: - return models.VM_DELETING + return api.VM_DELETING case INSTANCE_STATUS_HARD_REBOOT, INSTANCE_STATUS_REBOOT: - return models.VM_STARTING + return api.VM_STARTING case INSTANCE_STATUS_MIGRATING: - return models.VM_MIGRATING + return api.VM_MIGRATING case INSTANCE_STATUS_PAUSED, INSTANCE_STATUS_SUSPENDED: - return models.VM_SUSPEND + return api.VM_SUSPEND case INSTANCE_STATUS_RESIZE: - return models.VM_CHANGE_FLAVOR + return api.VM_CHANGE_FLAVOR case INSTANCE_STATUS_VERIFY_RESIZE: - return INSTANCE_STATUS_VERIFY_RESIZE + /// return INSTANCE_STATUS_VERIFY_RESIZE ??? use sync_status instead + return api.VM_SYNCING_STATUS case INSTANCE_STATUS_SHELVED, INSTANCE_STATUS_SHELVED_OFFLOADED, INSTANCE_STATUS_SHUTOFF, INSTANCE_STATUS_SOFT_DELETED: - return models.VM_READY + return api.VM_READY default: - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } @@ -357,21 +359,21 @@ func (instance *SInstance) UpdateVM(ctx context.Context, name string) error { } func (instance *SInstance) GetHypervisor() string { - return models.HYPERVISOR_OPENSTACK + return api.HYPERVISOR_OPENSTACK } func (instance *SInstance) StartVM(ctx context.Context) error { if err := instance.host.zone.region.StartVM(instance.ID); err != nil { return err } - return cloudprovider.WaitStatus(instance, models.VM_RUNNING, 10*time.Second, 8*time.Minute) + return cloudprovider.WaitStatus(instance, api.VM_RUNNING, 10*time.Second, 8*time.Minute) } func (instance *SInstance) StopVM(ctx context.Context, isForce bool) error { if err := instance.host.zone.region.StopVM(instance.ID, isForce); err != nil { return err } - return cloudprovider.WaitStatus(instance, models.VM_READY, 10*time.Second, 8*time.Minute) + return cloudprovider.WaitStatus(instance, api.VM_READY, 10*time.Second, 8*time.Minute) } func (region *SRegion) GetInstanceVNCUrl(instanceId string) (string, error) { @@ -500,8 +502,8 @@ func (region *SRegion) DeleteVM(instanceId string) error { } status := instance.GetStatus() log.Debugf("Instance status on delete is %s", status) - if status != models.VM_READY { - log.Warningf("DeleteVM: vm status is %s expect %s", status, models.VM_READY) + if status != api.VM_READY { + log.Warningf("DeleteVM: vm status is %s expect %s", status, api.VM_READY) } return region.doDeleteVM(instanceId) } @@ -669,7 +671,7 @@ func (instance *SInstance) GetIEIP() (cloudprovider.ICloudEIP, error) { } func (instance *SInstance) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (instance *SInstance) GetExpiredAt() time.Time { diff --git a/pkg/util/openstack/network.go b/pkg/util/openstack/network.go index 8f2e8cec58..e42c31e83c 100644 --- a/pkg/util/openstack/network.go +++ b/pkg/util/openstack/network.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/netutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type AllocationPool struct { @@ -81,7 +81,7 @@ func (network *SNetwork) IsEmulated() bool { } func (network *SNetwork) GetStatus() string { - return models.NETWORK_STATUS_AVAILABLE + return api.NETWORK_STATUS_AVAILABLE } func (network *SNetwork) Delete() error { @@ -129,7 +129,7 @@ func (network *SNetwork) GetIsPublic() bool { } func (network *SNetwork) GetServerType() string { - return models.NETWORK_TYPE_GUEST + return api.NETWORK_TYPE_GUEST } func (region *SRegion) GetNetwork(networkId string) (*SNetwork, error) { diff --git a/pkg/util/openstack/region.go b/pkg/util/openstack/region.go index 2aa93bb125..e15cb33438 100644 --- a/pkg/util/openstack/region.go +++ b/pkg/util/openstack/region.go @@ -22,8 +22,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/httputils" ) @@ -71,7 +71,7 @@ func (region *SRegion) GetGeographicInfo() cloudprovider.SGeographicInfo { } func (region *SRegion) GetStatus() string { - return models.CLOUD_REGION_STATUS_INSERVER + return api.CLOUD_REGION_STATUS_INSERVER } func (region *SRegion) Refresh() error { diff --git a/pkg/util/openstack/snapshot.go b/pkg/util/openstack/snapshot.go index 1194b1185c..33f200045f 100644 --- a/pkg/util/openstack/snapshot.go +++ b/pkg/util/openstack/snapshot.go @@ -17,8 +17,8 @@ package openstack import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) const ( @@ -68,15 +68,15 @@ func (region *SRegion) GetISnapshotById(snapshotId string) (cloudprovider.ICloud func (snapshot *SSnapshot) GetStatus() string { switch snapshot.Status { case SNAPSHOT_STATUS_CREATING: - return models.SNAPSHOT_CREATING + return api.SNAPSHOT_CREATING case SNAPSHOT_STATUS_AVAILABLE: - return models.SNAPSHOT_READY + return api.SNAPSHOT_READY case SNAPSHOT_STATUS_BACKING_UP: - return models.SNAPSHOT_ROLLBACKING + return api.SNAPSHOT_ROLLBACKING case SNAPSHOT_STATUS_DELETED, SNAPSHOT_STATUS_DELETING: - return models.SNAPSHOT_DELETING + return api.SNAPSHOT_DELETING default: - return models.SNAPSHOT_UNKNOWN + return api.SNAPSHOT_UNKNOWN } } @@ -150,11 +150,11 @@ func (snapshot *SSnapshot) GetDiskType() string { if len(snapshot.VolumeID) > 0 { if disk, err := snapshot.region.GetDisk(snapshot.VolumeID); err == nil { if disk.Bootable { - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS } } } - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } func (region *SRegion) DeleteSnapshot(snapshotId string) error { diff --git a/pkg/util/openstack/storage.go b/pkg/util/openstack/storage.go index a76388a2d7..1736e1bc7d 100644 --- a/pkg/util/openstack/storage.go +++ b/pkg/util/openstack/storage.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SExtraSpecs struct { @@ -79,9 +79,9 @@ func (storage *SStorage) GetStorageType() string { func (storage *SStorage) GetMediumType() string { if strings.Contains(storage.Name, "SSD") { - return models.DISK_TYPE_SSD + return api.DISK_TYPE_SSD } - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } func (storage *SStorage) GetCapacityMB() int { @@ -98,7 +98,7 @@ func (storage *SStorage) GetManagerId() string { } func (storage *SStorage) GetStatus() string { - return models.STORAGE_ONLINE + return api.STORAGE_ONLINE } func (storage *SStorage) Refresh() error { @@ -121,7 +121,7 @@ func (storage *SStorage) CreateIDisk(name string, sizeGb int, desc string) (clou return nil, err } disk.storage = storage - return disk, cloudprovider.WaitStatus(disk, models.DISK_READY, time.Second*5, time.Minute*5) + return disk, cloudprovider.WaitStatus(disk, api.DISK_READY, time.Second*5, time.Minute*5) } func (storage *SStorage) GetIDiskById(idStr string) (cloudprovider.ICloudDisk, error) { diff --git a/pkg/util/openstack/storagecache.go b/pkg/util/openstack/storagecache.go index 05306f0e7e..8e33b6634c 100644 --- a/pkg/util/openstack/storagecache.go +++ b/pkg/util/openstack/storagecache.go @@ -22,8 +22,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/image/options" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" @@ -160,7 +160,7 @@ func (cache *SStoragecache) uploadImage(ctx context.Context, userCred mcclient.T if err != nil { return "", err } - return image.ID, cloudprovider.WaitStatus(image, models.CACHED_IMAGE_STATUS_READY, 15*time.Second, 3600*time.Second) + return image.ID, cloudprovider.WaitStatus(image, api.CACHED_IMAGE_STATUS_READY, 15*time.Second, 3600*time.Second) } func (cache *SStoragecache) CreateIImage(snapshoutId, imageName, osType, imageDesc string) (cloudprovider.ICloudImage, error) { diff --git a/pkg/util/openstack/vpc.go b/pkg/util/openstack/vpc.go index b0e73c011d..9806a6766a 100644 --- a/pkg/util/openstack/vpc.go +++ b/pkg/util/openstack/vpc.go @@ -19,8 +19,8 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) const ( @@ -96,13 +96,13 @@ func (vpc *SVpc) GetCidrBlock() string { func (vpc *SVpc) GetStatus() string { switch vpc.Status { case VPC_STATUS_ACTIVE: - return models.VPC_STATUS_AVAILABLE + return api.VPC_STATUS_AVAILABLE case VPC_STATUS_BUILD, VPC_STATUS_DOWN: - return models.VPC_STATUS_PENDING + return api.VPC_STATUS_PENDING case VPC_STATUS_ERROR: - return models.VPC_STATUS_FAILED + return api.VPC_STATUS_FAILED default: - return models.VPC_STATUS_UNKNOWN + return api.VPC_STATUS_UNKNOWN } } diff --git a/pkg/util/openstack/zone.go b/pkg/util/openstack/zone.go index 7c52df2a41..d3c562fa7d 100644 --- a/pkg/util/openstack/zone.go +++ b/pkg/util/openstack/zone.go @@ -22,8 +22,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type ZoneState struct { @@ -74,7 +74,7 @@ func (zone *SZone) IsEmulated() bool { } func (zone *SZone) GetStatus() string { - return models.ZONE_ENABLE + return api.ZONE_ENABLE } func (zone *SZone) Refresh() error { diff --git a/pkg/util/qcloud/disk.go b/pkg/util/qcloud/disk.go index 24d8feb006..0b8ec709ca 100644 --- a/pkg/util/qcloud/disk.go +++ b/pkg/util/qcloud/disk.go @@ -26,8 +26,9 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type Placement struct { @@ -88,7 +89,7 @@ func (self *SDisk) GetMetadata() *jsonutils.JSONDict { // priceKey := fmt.Sprintf("%s::%s::%s", self.RegionId, self.Category, self.Type) // data.Add(jsonutils.NewString(priceKey), "price_key") - data.Add(jsonutils.NewString(models.HYPERVISOR_QCLOUD), "hypervisor") + data.Add(jsonutils.NewString(api.HYPERVISOR_QCLOUD), "hypervisor") return data } @@ -216,9 +217,9 @@ func (self *SDisk) GetIStorage() (cloudprovider.ICloudStorage, error) { func (self *SDisk) GetStatus() string { switch self.DiskState { case "ATTACHING", "DETACHING", "EXPANDING", "ROLLBACKING": - return models.DISK_ALLOCATING + return api.DISK_ALLOCATING default: - return models.DISK_READY + return api.DISK_READY } } @@ -242,7 +243,7 @@ func (self *SDisk) CreateISnapshot(ctx context.Context, name, desc string) (clou } if total == 1 { snapshot := &snapshots[0] - err := cloudprovider.WaitStatus(snapshot, models.SNAPSHOT_READY, 15*time.Second, 3600*time.Second) + err := cloudprovider.WaitStatus(snapshot, api.SNAPSHOT_READY, 15*time.Second, 3600*time.Second) if err != nil { return nil, err } @@ -254,11 +255,11 @@ func (self *SDisk) CreateISnapshot(ctx context.Context, name, desc string) (clou func (self *SDisk) GetDiskType() string { switch self.DiskUsage { case "SYSTEM_DISK": - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS case "DATA_DISK": - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA default: - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } } @@ -285,11 +286,11 @@ func (self *SDisk) GetMountpoint() string { func (self *SDisk) GetBillingType() string { switch self.DiskChargeType { case "PREPAID": - return models.BILLING_TYPE_PREPAID + return billing_api.BILLING_TYPE_PREPAID case "POSTPAID_BY_HOUR": - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID default: - return models.BILLING_TYPE_PREPAID + return billing_api.BILLING_TYPE_PREPAID } } diff --git a/pkg/util/qcloud/eip.go b/pkg/util/qcloud/eip.go index 574a32c10d..706fdfea6f 100644 --- a/pkg/util/qcloud/eip.go +++ b/pkg/util/qcloud/eip.go @@ -21,8 +21,9 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type TInternetChargeType string @@ -84,15 +85,15 @@ func (self *SEipAddress) GetGlobalId() string { func (self *SEipAddress) GetStatus() string { switch self.AddressStatus { case EIP_STATUS_CREATING: - return models.EIP_STATUS_ALLOCATE + return api.EIP_STATUS_ALLOCATE case EIP_STATUS_BINDING: - return models.EIP_STATUS_ASSOCIATE + return api.EIP_STATUS_ASSOCIATE case EIP_STATUS_BIND, EIP_STATUS_UNBINDING, EIP_STATUS_UNBIND, EIP_STATUS_OFFLINING, EIP_STATUS_BIND_ENI: - return models.EIP_STATUS_READY + return api.EIP_STATUS_READY case EIP_STATUS_CREATE_FAILED: - return models.EIP_STATUS_ALLOCATE_FAIL + return api.EIP_STATUS_ALLOCATE_FAIL default: - return models.EIP_STATUS_UNKNOWN + return api.EIP_STATUS_UNKNOWN } } @@ -126,9 +127,9 @@ func (self *SEipAddress) GetIpAddr() string { func (self *SEipAddress) GetMode() string { if self.InstanceId == self.AddressId { - return models.EIP_MODE_INSTANCE_PUBLICIP + return api.EIP_MODE_INSTANCE_PUBLICIP } - return models.EIP_MODE_STANDALONE_EIP + return api.EIP_MODE_STANDALONE_EIP } func (self *SEipAddress) GetAssociationType() string { @@ -165,7 +166,7 @@ func (self *SEipAddress) GetBandwidth() int { } func (self *SEipAddress) GetBillingType() string { - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } func (self *SEipAddress) GetExpiredAt() time.Time { @@ -177,13 +178,13 @@ func (self *SEipAddress) GetInternetChargeType() string { if instance, err := self.region.GetInstance(self.InstanceId); err == nil { switch instance.InternetAccessible.InternetChargeType { case InternetChargeTypeTrafficPostpaidByHour: - return models.EIP_CHARGE_TYPE_BY_TRAFFIC + return api.EIP_CHARGE_TYPE_BY_TRAFFIC default: - return models.EIP_CHARGE_TYPE_BY_BANDWIDTH + return api.EIP_CHARGE_TYPE_BY_BANDWIDTH } } } - return models.EIP_CHARGE_TYPE_BY_TRAFFIC + return api.EIP_CHARGE_TYPE_BY_TRAFFIC } func (self *SEipAddress) Associate(instanceId string) error { @@ -191,7 +192,7 @@ func (self *SEipAddress) Associate(instanceId string) error { if err != nil { return err } - return cloudprovider.WaitStatus(self, models.EIP_STATUS_READY, 10*time.Second, 180*time.Second) + return cloudprovider.WaitStatus(self, api.EIP_STATUS_READY, 10*time.Second, 180*time.Second) } func (self *SEipAddress) Dissociate() error { @@ -199,11 +200,11 @@ func (self *SEipAddress) Dissociate() error { if err != nil { return err } - return cloudprovider.WaitStatus(self, models.EIP_STATUS_READY, 10*time.Second, 180*time.Second) + return cloudprovider.WaitStatus(self, api.EIP_STATUS_READY, 10*time.Second, 180*time.Second) } func (self *SEipAddress) ChangeBandwidth(bw int) error { - if self.GetInternetChargeType() == models.EIP_CHARGE_TYPE_BY_TRAFFIC { + if self.GetInternetChargeType() == api.EIP_CHARGE_TYPE_BY_TRAFFIC { if len(self.InstanceId) > 0 { return self.region.UpdateInstanceBandwidth(self.InstanceId, bw) } @@ -286,7 +287,7 @@ func (region *SRegion) AllocateEIP(name string, bwMbps int, chargeType TInternet if err != nil { return nil, err } - return eip, cloudprovider.WaitStatus(eip, models.EIP_STATUS_READY, time.Second*5, time.Second*300) + return eip, cloudprovider.WaitStatus(eip, api.EIP_STATUS_READY, time.Second*5, time.Second*300) } return nil, cloudprovider.ErrNotFound } @@ -294,9 +295,9 @@ func (region *SRegion) AllocateEIP(name string, bwMbps int, chargeType TInternet func (region *SRegion) CreateEIP(name string, bwMbps int, chargeType string, bgpType string) (cloudprovider.ICloudEIP, error) { var ctype TInternetChargeType switch chargeType { - case models.EIP_CHARGE_TYPE_BY_TRAFFIC: + case api.EIP_CHARGE_TYPE_BY_TRAFFIC: ctype = InternetChargeByTraffic - case models.EIP_CHARGE_TYPE_BY_BANDWIDTH: + case api.EIP_CHARGE_TYPE_BY_BANDWIDTH: ctype = InternetChargeByBandwidth } return region.AllocateEIP(name, bwMbps, ctype) diff --git a/pkg/util/qcloud/host.go b/pkg/util/qcloud/host.go index 7b218baac5..e0c67f48f7 100644 --- a/pkg/util/qcloud/host.go +++ b/pkg/util/qcloud/host.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" ) @@ -223,19 +223,19 @@ func (self *SHost) GetEnabled() bool { } func (self *SHost) GetStatus() string { - return models.HOST_STATUS_RUNNING + return api.HOST_STATUS_RUNNING } func (self *SHost) GetHostStatus() string { - return models.HOST_ONLINE + return api.HOST_ONLINE } func (self *SHost) GetHostType() string { - return models.HOST_TYPE_QCLOUD + return api.HOST_TYPE_QCLOUD } func (self *SHost) GetStorageType() string { - return models.DISK_TYPE_HYBRID + return api.DISK_TYPE_HYBRID } func (self *SHost) GetIStorageById(id string) (cloudprovider.ICloudStorage, error) { diff --git a/pkg/util/qcloud/image.go b/pkg/util/qcloud/image.go index 1ace0b0b0b..d6f30b9c91 100644 --- a/pkg/util/qcloud/image.go +++ b/pkg/util/qcloud/image.go @@ -25,8 +25,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type ImageStatusType string @@ -109,6 +109,7 @@ func (self *SRegion) GetImages(status string, owner string, imageIds []string, n total, _ := body.Float("TotalCount") return images, int(total), nil } + func (self *SImage) GetMetadata() *jsonutils.JSONDict { return nil } @@ -136,11 +137,11 @@ func (self *SImage) Delete(ctx context.Context) error { func (self *SImage) GetStatus() string { switch self.ImageState { case ImageStatusCreating, ImageStatusSycing, ImageStatusImporting: - return models.CACHED_IMAGE_STATUS_CACHING + return api.CACHED_IMAGE_STATUS_CACHING case ImageStatusNormal, ImageStatusUsing: - return models.CACHED_IMAGE_STATUS_READY + return api.CACHED_IMAGE_STATUS_READY default: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED } } diff --git a/pkg/util/qcloud/instance.go b/pkg/util/qcloud/instance.go index a9aaacc2ba..8f7c637d69 100644 --- a/pkg/util/qcloud/instance.go +++ b/pkg/util/qcloud/instance.go @@ -24,8 +24,9 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/billing" ) @@ -335,23 +336,23 @@ func (self *SInstance) GetMachine() string { func (self *SInstance) GetStatus() string { switch self.InstanceState { case "PENDING": - return models.VM_DEPLOYING + return api.VM_DEPLOYING case "LAUNCH_FAILED": - return models.VM_DEPLOY_FAILED + return api.VM_DEPLOY_FAILED case "RUNNING": - return models.VM_RUNNING + return api.VM_RUNNING case "STOPPED": - return models.VM_READY + return api.VM_READY case "STARTING", "REBOOTING": - return models.VM_STARTING + return api.VM_STARTING case "STOPPING": - return models.VM_STOPPING + return api.VM_STOPPING case "SHUTDOWN": - return models.VM_DEALLOCATED + return api.VM_DEALLOCATED case "TERMINATING": - return models.VM_DELETING + return api.VM_DELETING default: - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } @@ -364,7 +365,7 @@ func (self *SInstance) Refresh() error { } func (self *SInstance) GetHypervisor() string { - return models.HYPERVISOR_QCLOUD + return api.HYPERVISOR_QCLOUD } func (self *SInstance) StartVM(ctx context.Context) error { @@ -377,11 +378,11 @@ func (self *SInstance) StartVM(ctx context.Context) error { if err != nil { return err } - log.Debugf("status %s expect %s", self.GetStatus(), models.VM_RUNNING) - if self.GetStatus() == models.VM_RUNNING { + log.Debugf("status %s expect %s", self.GetStatus(), api.VM_RUNNING) + if self.GetStatus() == api.VM_RUNNING { return nil } - if self.GetStatus() == models.VM_READY { + if self.GetStatus() == api.VM_READY { err := self.host.zone.region.StartVM(self.InstanceId) if err != nil { return err @@ -397,7 +398,7 @@ func (self *SInstance) StopVM(ctx context.Context, isForce bool) error { if err != nil { return err } - return cloudprovider.WaitStatus(self, models.VM_READY, 10*time.Second, 8*time.Minute) // 8 mintues, 腾讯云有时关机比较慢 + return cloudprovider.WaitStatus(self, api.VM_READY, 10*time.Second, 8*time.Minute) // 8 mintues, 腾讯云有时关机比较慢 } func (self *SInstance) GetVNCInfo() (jsonutils.JSONObject, error) { @@ -794,11 +795,11 @@ func (self *SInstance) GetIEIP() (cloudprovider.ICloudEIP, error) { func (self *SInstance) GetBillingType() string { switch self.InstanceChargeType { case PrePaidInstanceChargeType: - return models.BILLING_TYPE_PREPAID + return billing_api.BILLING_TYPE_PREPAID case PostPaidInstanceChargeType: - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID default: - return models.BILLING_TYPE_PREPAID + return billing_api.BILLING_TYPE_PREPAID } } diff --git a/pkg/util/qcloud/localdisk.go b/pkg/util/qcloud/localdisk.go index df825da852..301294417f 100644 --- a/pkg/util/qcloud/localdisk.go +++ b/pkg/util/qcloud/localdisk.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SLocalDisk struct { @@ -34,7 +34,7 @@ type SLocalDisk struct { func (self *SLocalDisk) GetMetadata() *jsonutils.JSONDict { data := jsonutils.NewDict() - data.Add(jsonutils.NewString(models.HYPERVISOR_QCLOUD), "hypervisor") + data.Add(jsonutils.NewString(api.HYPERVISOR_QCLOUD), "hypervisor") return data } @@ -89,11 +89,11 @@ func (self *SLocalDisk) GetExpiredAt() time.Time { func (self *SLocalDisk) GetDiskType() string { switch self.DiskUsage { case "SYSTEM_DISK": - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS case "DATA_DISK": - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA default: - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } } @@ -110,7 +110,7 @@ func (self *SLocalDisk) GetTemplateId() string { } func (self *SLocalDisk) GetStatus() string { - return models.DISK_READY + return api.DISK_READY } func (self *SLocalDisk) GetName() string { diff --git a/pkg/util/qcloud/localstorage.go b/pkg/util/qcloud/localstorage.go index e0e5360f78..055167920c 100644 --- a/pkg/util/qcloud/localstorage.go +++ b/pkg/util/qcloud/localstorage.go @@ -20,8 +20,8 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SLocalStorage struct { @@ -69,9 +69,9 @@ func (self *SLocalStorage) GetStorageType() string { func (self *SLocalStorage) GetMediumType() string { if strings.HasSuffix(self.storageType, "_BASIC") { - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } - return models.DISK_TYPE_SSD + return api.DISK_TYPE_SSD } func (self *SLocalStorage) GetCapacityMB() int { @@ -88,7 +88,7 @@ func (self *SLocalStorage) GetManagerId() string { } func (self *SLocalStorage) GetStatus() string { - return models.STORAGE_ONLINE + return api.STORAGE_ONLINE } func (self *SLocalStorage) Refresh() error { diff --git a/pkg/util/qcloud/network.go b/pkg/util/qcloud/network.go index e965ad91d4..8a4988cbb6 100644 --- a/pkg/util/qcloud/network.go +++ b/pkg/util/qcloud/network.go @@ -21,8 +21,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/util/netutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SNetwork struct { @@ -64,7 +64,7 @@ func (self *SNetwork) IsEmulated() bool { } func (self *SNetwork) GetStatus() string { - return models.NETWORK_STATUS_AVAILABLE + return api.NETWORK_STATUS_AVAILABLE } func (self *SNetwork) Delete() error { @@ -121,7 +121,7 @@ func (self *SNetwork) GetIsPublic() bool { } func (self *SNetwork) GetServerType() string { - return models.NETWORK_TYPE_GUEST + return api.NETWORK_TYPE_GUEST } func (self *SNetwork) Refresh() error { diff --git a/pkg/util/qcloud/region.go b/pkg/util/qcloud/region.go index b11c29ab3e..324199c26d 100644 --- a/pkg/util/qcloud/region.go +++ b/pkg/util/qcloud/region.go @@ -24,8 +24,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SRegion struct { @@ -596,9 +596,9 @@ func (self *SRegion) GetMetadata() *jsonutils.JSONDict { func (self *SRegion) GetStatus() string { if self.RegionState == "AVAILABLE" { - return models.CLOUD_REGION_STATUS_INSERVER + return api.CLOUD_REGION_STATUS_INSERVER } - return models.CLOUD_REGION_STATUS_OUTOFSERVICE + return api.CLOUD_REGION_STATUS_OUTOFSERVICE } func (self *SRegion) Refresh() error { diff --git a/pkg/util/qcloud/snapshot.go b/pkg/util/qcloud/snapshot.go index df7112eed6..aa64359d9e 100644 --- a/pkg/util/qcloud/snapshot.go +++ b/pkg/util/qcloud/snapshot.go @@ -22,8 +22,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SnapshotStatusType string @@ -74,13 +74,13 @@ func (self *SSnapshot) GetStatus() string { // COPYING_FROM_REMOTE:跨地域复制快照拷贝中。 switch self.SnapshotState { case "NORMAL", "COPYING_FROM_REMOTE": - return models.SNAPSHOT_READY + return api.SNAPSHOT_READY case "CREATING": - return models.SNAPSHOT_CREATING + return api.SNAPSHOT_CREATING case "ROLLBACKING": - return models.SNAPSHOT_ROLLBACKING + return api.SNAPSHOT_ROLLBACKING } - return models.SNAPSHOT_UNKNOWN + return api.SNAPSHOT_UNKNOWN } func (self *SSnapshot) IsEmulated() bool { @@ -207,11 +207,11 @@ func (self *SSnapshot) Delete() error { func (self *SSnapshot) GetDiskType() string { switch self.DiskUsage { case "SYSTEM_DISK": - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS case "DATA_DISK": - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } func (self *SRegion) DeleteSnapshot(snapshotId string) error { diff --git a/pkg/util/qcloud/storage.go b/pkg/util/qcloud/storage.go index e810e2f43d..df55046a3f 100644 --- a/pkg/util/qcloud/storage.go +++ b/pkg/util/qcloud/storage.go @@ -22,8 +22,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SStorage struct { @@ -82,9 +82,9 @@ func (self *SStorage) GetStorageType() string { func (self *SStorage) GetMediumType() string { if strings.HasSuffix(self.storageType, "_BASIC") { - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } - return models.DISK_TYPE_SSD + return api.DISK_TYPE_SSD } func (self *SStorage) GetCapacityMB() int { @@ -101,7 +101,7 @@ func (self *SStorage) GetManagerId() string { } func (self *SStorage) GetStatus() string { - return models.STORAGE_ONLINE + return api.STORAGE_ONLINE } func (self *SStorage) Refresh() error { diff --git a/pkg/util/qcloud/storagecache.go b/pkg/util/qcloud/storagecache.go index 58a0079cc1..cd9f0bd213 100644 --- a/pkg/util/qcloud/storagecache.go +++ b/pkg/util/qcloud/storagecache.go @@ -27,8 +27,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/compute/options" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/auth" @@ -237,7 +237,7 @@ func (self *SStoragecache) uploadImage(ctx context.Context, userCred mcclient.To log.Debugf("Import image %s", imageName) if image, err := self.region.ImportImage(imageName, osArch, osDist, osVersion, self.region.getCosUrl(bucketName, imageId)); err != nil { return "", err - } else if cloudprovider.WaitStatus(image, models.CACHED_IMAGE_STATUS_READY, 15*time.Second, 3600*time.Second); err != nil { + } else if cloudprovider.WaitStatus(image, api.CACHED_IMAGE_STATUS_READY, 15*time.Second, 3600*time.Second); err != nil { return "", err } else { return image.ImageId, nil diff --git a/pkg/util/qcloud/vpc.go b/pkg/util/qcloud/vpc.go index f2902432f4..9716b11375 100644 --- a/pkg/util/qcloud/vpc.go +++ b/pkg/util/qcloud/vpc.go @@ -19,8 +19,8 @@ import ( "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SVpc struct { @@ -73,7 +73,7 @@ func (self *SVpc) GetCidrBlock() string { } func (self *SVpc) GetStatus() string { - return models.VPC_STATUS_AVAILABLE + return api.VPC_STATUS_AVAILABLE } func (self *SVpc) Delete() error { diff --git a/pkg/util/qcloud/zone.go b/pkg/util/qcloud/zone.go index 292cbcacec..be473e0daa 100644 --- a/pkg/util/qcloud/zone.go +++ b/pkg/util/qcloud/zone.go @@ -23,8 +23,8 @@ import ( "yunion.io/x/log" "yunion.io/x/pkg/utils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type InstanceChargeType string @@ -80,9 +80,9 @@ func (self *SZone) Refresh() error { func (self *SZone) GetStatus() string { if self.ZoneState == "AVAILABLE" { - return models.ZONE_ENABLE + return api.ZONE_ENABLE } - return models.ZONE_SOLDOUT + return api.ZONE_SOLDOUT } func (self *SZone) GetIHostById(id string) (cloudprovider.ICloudHost, error) { diff --git a/pkg/util/ucloud/client.go b/pkg/util/ucloud/client.go index f3a0d37cf1..a88a5f3d8f 100644 --- a/pkg/util/ucloud/client.go +++ b/pkg/util/ucloud/client.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/util/httputils" ) diff --git a/pkg/util/ucloud/disk.go b/pkg/util/ucloud/disk.go index 0d42205635..47bf77b84d 100644 --- a/pkg/util/ucloud/disk.go +++ b/pkg/util/ucloud/disk.go @@ -22,9 +22,11 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/pkg/utils" + + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/cloudprovider" ) // https://docs.ucloud.cn/api/udisk-api/describe_udisk @@ -75,25 +77,25 @@ func (self *SDisk) GetGlobalId() string { func (self *SDisk) GetStatus() string { switch self.Status { case "Available": - return models.DISK_READY + return api.DISK_READY case "Attaching": - return models.DISK_ATTACHING + return api.DISK_ATTACHING case "InUse": - return models.DISK_READY + return api.DISK_READY case "Detaching": - return models.DISK_DETACHING + return api.DISK_DETACHING case "Initializating": - return models.DISK_ALLOCATING + return api.DISK_ALLOCATING case "Failed": - return models.DISK_ALLOC_FAILED + return api.DISK_ALLOC_FAILED case "Cloning": - return models.DISK_CLONING + return api.DISK_CLONING case "Restoring": - return models.DISK_RESET + return api.DISK_RESET case "RestoreFailed": - return models.DISK_RESET_FAILED + return api.DISK_RESET_FAILED default: - return models.DISK_UNKNOWN + return api.DISK_UNKNOWN } } @@ -112,7 +114,7 @@ func (self *SDisk) IsEmulated() bool { func (self *SDisk) GetMetadata() *jsonutils.JSONDict { // todo: add price key data := jsonutils.NewDict() - data.Add(jsonutils.NewString(models.HYPERVISOR_UCLOUD), "hypervisor") + data.Add(jsonutils.NewString(api.HYPERVISOR_UCLOUD), "hypervisor") return data } @@ -121,9 +123,9 @@ func (self *SDisk) GetMetadata() *jsonutils.JSONDict { func (self *SDisk) GetBillingType() string { switch self.ChargeType { case "Year", "Month": - return models.BILLING_TYPE_PREPAID + return billing_api.BILLING_TYPE_PREPAID default: - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } } @@ -166,10 +168,10 @@ func (self *SDisk) GetTemplateId() string { func (self *SDisk) GetDiskType() string { if strings.Contains(self.DiskType, "SystemDisk") { - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS } - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } func (self *SDisk) GetFsFormat() string { diff --git a/pkg/util/ucloud/eip.go b/pkg/util/ucloud/eip.go index e6d5c496c7..fe2e6921fe 100644 --- a/pkg/util/ucloud/eip.go +++ b/pkg/util/ucloud/eip.go @@ -17,10 +17,13 @@ package ucloud import ( "time" - "github.com/coredns/coredns/plugin/pkg/log" + "yunion.io/x/log" + "yunion.io/x/jsonutils" + + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) // https://docs.ucloud.cn/api/unet-api/describe_eip @@ -87,13 +90,13 @@ func (self *SEip) GetGlobalId() string { func (self *SEip) GetStatus() string { switch self.Status { case "used": - return models.EIP_STATUS_ASSOCIATE // ? + return api.EIP_STATUS_ASSOCIATE // ? case "free": - return models.EIP_STATUS_READY + return api.EIP_STATUS_READY case "freeze": - return models.EIP_STATUS_UNKNOWN + return api.EIP_STATUS_UNKNOWN default: - return models.EIP_STATUS_UNKNOWN + return api.EIP_STATUS_UNKNOWN } } @@ -120,9 +123,9 @@ func (self *SEip) GetMetadata() *jsonutils.JSONDict { func (self *SEip) GetBillingType() string { switch self.ChargeType { case "Year", "Month": - return models.BILLING_TYPE_PREPAID + return billing_api.BILLING_TYPE_PREPAID default: - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } } @@ -141,7 +144,7 @@ func (self *SEip) GetIpAddr() string { } func (self *SEip) GetMode() string { - return models.EIP_MODE_STANDALONE_EIP + return api.EIP_MODE_STANDALONE_EIP } func (self *SEip) GetAssociationType() string { @@ -167,11 +170,11 @@ func (self *SEip) GetBandwidth() int { func (self *SEip) GetInternetChargeType() string { switch self.PayMode { case "Bandwidth": - return models.EIP_CHARGE_TYPE_BY_BANDWIDTH + return api.EIP_CHARGE_TYPE_BY_BANDWIDTH case "Traffic": - return models.EIP_CHARGE_TYPE_BY_TRAFFIC + return api.EIP_CHARGE_TYPE_BY_TRAFFIC default: - return models.EIP_CHARGE_TYPE_BY_BANDWIDTH + return api.EIP_CHARGE_TYPE_BY_BANDWIDTH } } diff --git a/pkg/util/ucloud/host.go b/pkg/util/ucloud/host.go index b0f8469aa5..66e621c5ea 100644 --- a/pkg/util/ucloud/host.go +++ b/pkg/util/ucloud/host.go @@ -18,8 +18,9 @@ import ( "fmt" "yunion.io/x/jsonutils" + + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SHost struct { @@ -41,7 +42,7 @@ func (self *SHost) GetGlobalId() string { } func (self *SHost) GetStatus() string { - return models.HOST_STATUS_RUNNING + return api.HOST_STATUS_RUNNING } func (self *SHost) Refresh() error { @@ -98,7 +99,7 @@ func (self *SHost) GetEnabled() bool { } func (self *SHost) GetHostStatus() string { - return models.HOST_ONLINE + return api.HOST_ONLINE } func (self *SHost) GetAccessIp() string { @@ -144,11 +145,11 @@ func (self *SHost) GetStorageSizeMB() int { } func (self *SHost) GetStorageType() string { - return models.DISK_TYPE_HYBRID + return api.DISK_TYPE_HYBRID } func (self *SHost) GetHostType() string { - return models.HOST_TYPE_UCLOUD + return api.HOST_TYPE_UCLOUD } func (self *SHost) GetIsMaintenance() bool { diff --git a/pkg/util/ucloud/image.go b/pkg/util/ucloud/image.go index ad8d0b8146..eeaef518dc 100644 --- a/pkg/util/ucloud/image.go +++ b/pkg/util/ucloud/image.go @@ -20,8 +20,9 @@ import ( "time" "yunion.io/x/jsonutils" + + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/onecloud/pkg/util/imagetools" ) @@ -133,13 +134,13 @@ func (self *SImage) GetImageType() string { func (self *SImage) GetImageStatus() string { switch self.State { case "Available": - return models.CACHED_IMAGE_STATUS_READY + return api.CACHED_IMAGE_STATUS_READY case "Making": - return models.CACHED_IMAGE_STATUS_CACHING + return api.CACHED_IMAGE_STATUS_CACHING case "Unavailable": - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED default: - return models.CACHED_IMAGE_STATUS_CACHE_FAILED + return api.CACHED_IMAGE_STATUS_CACHE_FAILED } } diff --git a/pkg/util/ucloud/instance.go b/pkg/util/ucloud/instance.go index 147113978a..0b2bcfdd6d 100644 --- a/pkg/util/ucloud/instance.go +++ b/pkg/util/ucloud/instance.go @@ -20,10 +20,12 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" - "yunion.io/x/onecloud/pkg/util/billing" "yunion.io/x/pkg/util/osprofile" + + billing_api "yunion.io/x/onecloud/pkg/apis/billing" + api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/cloudprovider" + "yunion.io/x/onecloud/pkg/util/billing" ) type SInstance struct { @@ -138,21 +140,21 @@ func (self *SInstance) GetGlobalId() string { func (self *SInstance) GetStatus() string { switch self.State { case "Running": - return models.VM_RUNNING + return api.VM_RUNNING case "Stopped": - return models.VM_READY + return api.VM_READY case "Rebooting": - return models.VM_STOPPING + return api.VM_STOPPING case "Initializing": - return models.VM_INIT + return api.VM_INIT case "Starting": - return models.VM_STARTING + return api.VM_STARTING case "Stopping": - return models.VM_STOPPING + return api.VM_STOPPING case "Install Fail": - return models.VM_CREATE_FAILED + return api.VM_CREATE_FAILED default: - return models.VM_UNKNOWN + return api.VM_UNKNOWN } } @@ -189,9 +191,9 @@ func (self *SInstance) GetMetadata() *jsonutils.JSONDict { func (self *SInstance) GetBillingType() string { switch self.ChargeType { case "Year", "Month": - return models.BILLING_TYPE_PREPAID + return billing_api.BILLING_TYPE_PREPAID default: - return models.BILLING_TYPE_POSTPAID + return billing_api.BILLING_TYPE_POSTPAID } } @@ -222,7 +224,7 @@ func (self *SInstance) GetIDisks() ([]cloudprovider.ICloudDisk, error) { for i := 0; i < len(disks); i += 1 { idisks[i] = &disks[i] // 将系统盘放到第0个位置 - if disks[i].GetDiskType() == models.DISK_TYPE_SYS { + if disks[i].GetDiskType() == api.DISK_TYPE_SYS { idisks[0], idisks[i] = idisks[i], idisks[0] } } @@ -310,7 +312,7 @@ func (self *SInstance) SetSecurityGroups(secgroupIds []string) error { } func (self *SInstance) GetHypervisor() string { - return models.HYPERVISOR_UCLOUD + return api.HYPERVISOR_UCLOUD } func (self *SInstance) StartVM(ctx context.Context) error { diff --git a/pkg/util/ucloud/instancenic.go b/pkg/util/ucloud/instancenic.go index 94407722a8..8c08e5da2e 100644 --- a/pkg/util/ucloud/instancenic.go +++ b/pkg/util/ucloud/instancenic.go @@ -15,8 +15,9 @@ package ucloud import ( - "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/pkg/util/netutils" + + "yunion.io/x/onecloud/pkg/cloudprovider" ) type SInstanceNic struct { diff --git a/pkg/util/ucloud/network.go b/pkg/util/ucloud/network.go index 0f7a6b2b6b..58b04b79e8 100644 --- a/pkg/util/ucloud/network.go +++ b/pkg/util/ucloud/network.go @@ -19,9 +19,10 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/pkg/util/netutils" + + api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/cloudprovider" ) // https://docs.ucloud.cn/api/vpc2.0-api/describe_subnet @@ -67,7 +68,7 @@ func (self *SNetwork) GetGlobalId() string { } func (self *SNetwork) GetStatus() string { - return models.NETWORK_STATUS_AVAILABLE + return api.NETWORK_STATUS_AVAILABLE } func (self *SNetwork) Refresh() error { @@ -116,7 +117,7 @@ func (self *SNetwork) GetGateway() string { } func (self *SNetwork) GetServerType() string { - return models.NETWORK_TYPE_GUEST + return api.NETWORK_TYPE_GUEST } func (self *SNetwork) GetIsPublic() bool { diff --git a/pkg/util/ucloud/region.go b/pkg/util/ucloud/region.go index f98194e317..bc3400078a 100644 --- a/pkg/util/ucloud/region.go +++ b/pkg/util/ucloud/region.go @@ -19,9 +19,10 @@ import ( "strings" "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/pkg/util/secrules" + + api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/cloudprovider" ) type SRegion struct { @@ -56,7 +57,7 @@ func (self *SRegion) GetGlobalId() string { } func (self *SRegion) GetStatus() string { - return models.CLOUD_REGION_STATUS_INSERVER + return api.CLOUD_REGION_STATUS_INSERVER } func (self *SRegion) Refresh() error { @@ -222,9 +223,9 @@ func (self *SRegion) CreateEIP(name string, bwMbps int, chargeType string, bgpTy params.Set("Name", name) var payMode string switch chargeType { - case models.EIP_CHARGE_TYPE_BY_TRAFFIC: + case api.EIP_CHARGE_TYPE_BY_TRAFFIC: payMode = "Traffic" - case models.EIP_CHARGE_TYPE_BY_BANDWIDTH: + case api.EIP_CHARGE_TYPE_BY_BANDWIDTH: payMode = "Bandwidth" } params.Set("PayMode", payMode) diff --git a/pkg/util/ucloud/securitygroup.go b/pkg/util/ucloud/securitygroup.go index 3f7cc255a2..2fd34297ef 100644 --- a/pkg/util/ucloud/securitygroup.go +++ b/pkg/util/ucloud/securitygroup.go @@ -22,9 +22,10 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" "yunion.io/x/pkg/util/secrules" + + api "yunion.io/x/onecloud/pkg/apis/compute" + "yunion.io/x/onecloud/pkg/cloudprovider" ) // https://docs.ucloud.cn/api/unet-api/describe_firewall @@ -169,7 +170,7 @@ func (self *SSecurityGroup) GetRules() ([]secrules.SecurityRule, error) { func (self *SSecurityGroup) GetVpcId() string { // 无vpc关联的安全组统一返回normal - return models.NORMAL_VPC_ID + return api.NORMAL_VPC_ID } func (self *SRegion) GetSecurityGroupById(secGroupId string) (*SSecurityGroup, error) { diff --git a/pkg/util/ucloud/snapshot.go b/pkg/util/ucloud/snapshot.go index 5eceb572be..147dd9fe97 100644 --- a/pkg/util/ucloud/snapshot.go +++ b/pkg/util/ucloud/snapshot.go @@ -18,8 +18,8 @@ import ( "fmt" "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) // https://docs.ucloud.cn/api/udisk-api/describe_udisk_snapshot @@ -66,13 +66,13 @@ func (self *SSnapshot) GetGlobalId() string { func (self *SSnapshot) GetStatus() string { switch self.Status { case "Normal": - return models.SNAPSHOT_READY + return api.SNAPSHOT_READY case "Failed": - return models.SNAPSHOT_FAILED + return api.SNAPSHOT_FAILED case "Creating": - return models.SNAPSHOT_CREATING + return api.SNAPSHOT_CREATING default: - return models.SNAPSHOT_UNKNOWN + return api.SNAPSHOT_UNKNOWN } } @@ -108,9 +108,9 @@ func (self *SSnapshot) GetDiskId() string { // 磁盘类型,0:数据盘,1:系统盘 func (self *SSnapshot) GetDiskType() string { if self.DiskType == 1 { - return models.DISK_TYPE_SYS + return api.DISK_TYPE_SYS } else { - return models.DISK_TYPE_DATA + return api.DISK_TYPE_DATA } } diff --git a/pkg/util/ucloud/storage.go b/pkg/util/ucloud/storage.go index c3408e920e..68cfcd1c81 100644 --- a/pkg/util/ucloud/storage.go +++ b/pkg/util/ucloud/storage.go @@ -19,8 +19,9 @@ import ( "strings" "yunion.io/x/jsonutils" + + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SStorage struct { @@ -41,7 +42,7 @@ func (self *SStorage) GetGlobalId() string { } func (self *SStorage) GetStatus() string { - return models.STORAGE_ONLINE + return api.STORAGE_ONLINE } func (self *SStorage) Refresh() error { @@ -73,12 +74,12 @@ func (self *SStorage) GetIDisks() ([]cloudprovider.ICloudDisk, error) { filtedDisks := make([]SDisk, 0) for _, disk := range disks { // ssd 盘 - if self.storageType == models.STORAGE_UCLOUD_CLOUD_SSD && strings.Contains(disk.DiskType, "SSD") { + if self.storageType == api.STORAGE_UCLOUD_CLOUD_SSD && strings.Contains(disk.DiskType, "SSD") { filtedDisks = append(filtedDisks, disk) } // 普通盘 - if self.storageType == models.STORAGE_UCLOUD_CLOUD_NORMAL && strings.Contains(disk.DiskType, "SSD") { + if self.storageType == api.STORAGE_UCLOUD_CLOUD_NORMAL && strings.Contains(disk.DiskType, "SSD") { filtedDisks = append(filtedDisks, disk) } } @@ -96,10 +97,10 @@ func (self *SStorage) GetStorageType() string { } func (self *SStorage) GetMediumType() string { - if self.storageType == models.STORAGE_UCLOUD_CLOUD_SSD { - return models.DISK_TYPE_SSD + if self.storageType == api.STORAGE_UCLOUD_CLOUD_SSD { + return api.DISK_TYPE_SSD } else { - return models.DISK_TYPE_ROTATE + return api.DISK_TYPE_ROTATE } } diff --git a/pkg/util/ucloud/storagecache.go b/pkg/util/ucloud/storagecache.go index cefc4a1bba..c04464eafe 100644 --- a/pkg/util/ucloud/storagecache.go +++ b/pkg/util/ucloud/storagecache.go @@ -19,6 +19,7 @@ import ( "fmt" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/mcclient" ) diff --git a/pkg/util/ucloud/vpc.go b/pkg/util/ucloud/vpc.go index d19855b777..a6a3c5c0c1 100644 --- a/pkg/util/ucloud/vpc.go +++ b/pkg/util/ucloud/vpc.go @@ -19,8 +19,8 @@ import ( "strings" "yunion.io/x/jsonutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) type SVPC struct { @@ -67,7 +67,7 @@ func (self *SVPC) GetGlobalId() string { } func (self *SVPC) GetStatus() string { - return models.VPC_STATUS_AVAILABLE + return api.VPC_STATUS_AVAILABLE } func (self *SVPC) Refresh() error { diff --git a/pkg/util/ucloud/zone.go b/pkg/util/ucloud/zone.go index 927a60c68d..732f48197e 100644 --- a/pkg/util/ucloud/zone.go +++ b/pkg/util/ucloud/zone.go @@ -18,15 +18,16 @@ import ( "fmt" "yunion.io/x/jsonutils" + + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" - "yunion.io/x/onecloud/pkg/compute/models" ) // https://docs.ucloud.cn/api/udisk-api/create_udisk // UDisk 类型: DataDisk(普通数据盘),SSDDataDisk(SSD数据盘),默认值(DataDisk) var StorageTypes = []string{ - models.STORAGE_UCLOUD_CLOUD_NORMAL, - models.STORAGE_UCLOUD_CLOUD_SSD, + api.STORAGE_UCLOUD_CLOUD_NORMAL, + api.STORAGE_UCLOUD_CLOUD_SSD, } type SZone struct { @@ -91,7 +92,7 @@ func (self *SZone) GetGlobalId() string { } func (self *SZone) GetStatus() string { - return models.ZONE_ENABLE + return api.ZONE_ENABLE } func (self *SZone) Refresh() error {