mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #430 from swordqiu/hotfix/qj-move-models-consts-to-apis
fix: move all consts in compute/models to apis/compute
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package billing
|
||||
|
||||
const (
|
||||
BILLING_TYPE_POSTPAID = "postpaid"
|
||||
BILLING_TYPE_PREPAID = "prepaid"
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
package billing // import "yunion.io/x/onecloud/pkg/apis/billing"
|
||||
@@ -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
|
||||
)
|
||||
@@ -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
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
package compute
|
||||
|
||||
const (
|
||||
CLOUD_REGION_STATUS_INSERVER = "inservice"
|
||||
CLOUD_REGION_STATUS_OUTOFSERVICE = "outofservice"
|
||||
|
||||
DEFAULT_REGION_ID = "default"
|
||||
)
|
||||
@@ -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
|
||||
)
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
@@ -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"
|
||||
)
|
||||
@@ -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
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
package compute
|
||||
|
||||
const (
|
||||
ZONE_INIT = "init"
|
||||
ZONE_ENABLE = "enable"
|
||||
ZONE_DISABLE = "disable"
|
||||
ZONE_SOLDOUT = "soldout"
|
||||
// ZONE_LACK = "lack"
|
||||
)
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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}) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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(
|
||||
|
||||
+38
-76
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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, ",")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
+91
-87
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+15
-42
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")))
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
+13
-28
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+14
-22
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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, "")
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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, "")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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, "")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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, "")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user