diff --git a/pkg/cloudprovider/consts.go b/pkg/cloudprovider/consts.go index a4c7137159..8013f2426a 100644 --- a/pkg/cloudprovider/consts.go +++ b/pkg/cloudprovider/consts.go @@ -5,10 +5,12 @@ import ( ) const ( - CloudVMStatusRunning = "running" - CloudVMStatusSuspend = "suspend" - CloudVMStatusStopped = "stopped" - CloudVMStatusOther = "other" + CloudVMStatusRunning = "running" + CloudVMStatusSuspend = "suspend" + CloudVMStatusStopped = "stopped" + CloudVMStatusChangeFlavor = "change_flavor" + CloudVMStatusDeploying = "deploying" + CloudVMStatusOther = "other" ) var ErrNotFound = errors.New("id not found") diff --git a/pkg/compute/guestdrivers/managedvirtual.go b/pkg/compute/guestdrivers/managedvirtual.go index 1e716a50a7..5df4cd8180 100644 --- a/pkg/compute/guestdrivers/managedvirtual.go +++ b/pkg/compute/guestdrivers/managedvirtual.go @@ -228,6 +228,10 @@ func (self *SManagedVirtualizedGuestDriver) RequestSyncstatusOnHost(ctx context. status = cloudprovider.CloudVMStatusStopped case models.VM_STOPPING: status = cloudprovider.CloudVMStatusRunning + case models.VM_CHANGE_FLAVOR: + status = cloudprovider.CloudVMStatusChangeFlavor + case models.VM_DEPLOYING: + status = cloudprovider.CloudVMStatusDeploying default: status = cloudprovider.CloudVMStatusOther } diff --git a/pkg/compute/guestdrivers/openstack.go b/pkg/compute/guestdrivers/openstack.go index b22ad00eb1..bc68a46f1a 100644 --- a/pkg/compute/guestdrivers/openstack.go +++ b/pkg/compute/guestdrivers/openstack.go @@ -76,6 +76,10 @@ func (self *SOpenStackGuestDriver) GetChangeConfigStatus() ([]string, error) { return []string{models.VM_READY, models.VM_RUNNING}, nil } +func (self *SOpenStackGuestDriver) IsNeedRestartForResetLoginInfo() bool { + return false +} + func (self *SOpenStackGuestDriver) GetDeployStatus() ([]string, error) { return []string{models.VM_RUNNING}, nil } diff --git a/pkg/compute/models/guest_actions.go b/pkg/compute/models/guest_actions.go index 2e374603ac..41ded2e50e 100644 --- a/pkg/compute/models/guest_actions.go +++ b/pkg/compute/models/guest_actions.go @@ -358,9 +358,11 @@ func (self *SGuest) PerformDeploy(ctx context.Context, userCred mcclient.TokenCr } if utils.IsInStringArray(self.Status, deployStatus) { - if (doRestart && self.Status == VM_RUNNING) || - jsonutils.QueryBoolean(kwargs, "auto_start", false) { + if (doRestart && self.Status == VM_RUNNING) || (self.Status != VM_RUNNING && (jsonutils.QueryBoolean(kwargs, "auto_start", false) || jsonutils.QueryBoolean(kwargs, "restart", false))) { kwargs.Set("restart", jsonutils.JSONTrue) + } else { + // 避免前端直接传restart参数, 越过校验 + kwargs.Set("restart", jsonutils.JSONFalse) } err := self.StartGuestDeployTask(ctx, userCred, kwargs, "deploy", "") if err != nil { diff --git a/pkg/util/openstack/flavor.go b/pkg/util/openstack/flavor.go index 748e48eef1..8835499aba 100644 --- a/pkg/util/openstack/flavor.go +++ b/pkg/util/openstack/flavor.go @@ -99,6 +99,9 @@ func (region *SRegion) syncFlavor(name string, cpu, memoryMb, diskGB int) (strin } func (region *SRegion) CreateFlavor(name string, cpu int, memoryMb int, diskGB int) (*SFlavor, error) { + if diskGB < 30 { + diskGB = 30 + } params := map[string]map[string]interface{}{ "flavor": { "name": name, diff --git a/pkg/util/openstack/host.go b/pkg/util/openstack/host.go index 2344cfc3d0..a9b69c6096 100644 --- a/pkg/util/openstack/host.go +++ b/pkg/util/openstack/host.go @@ -156,7 +156,7 @@ func (host *SHost) CreateVM(desc *cloudprovider.SManagedVMCreateConfig) (cloudpr return nil, err } - sysDiskSizeGB := image.Size / 1024 / 1024 + sysDiskSizeGB := image.Size / 1024 / 1024 / 1024 if desc.SysDisk.SizeGB < sysDiskSizeGB { desc.SysDisk.SizeGB = sysDiskSizeGB } diff --git a/pkg/util/openstack/instance.go b/pkg/util/openstack/instance.go index 14072850ba..82546ea8cf 100644 --- a/pkg/util/openstack/instance.go +++ b/pkg/util/openstack/instance.go @@ -298,8 +298,10 @@ func (instance *SInstance) GetStatus() string { return models.VM_MIGRATING case INSTANCE_STATUS_PAUSED, INSTANCE_STATUS_SUSPENDED: return models.VM_SUSPEND - case INSTANCE_STATUS_RESIZE, INSTANCE_STATUS_VERIFY_RESIZE: + case INSTANCE_STATUS_RESIZE: return models.VM_CHANGE_FLAVOR + case INSTANCE_STATUS_VERIFY_RESIZE: + return INSTANCE_STATUS_VERIFY_RESIZE case INSTANCE_STATUS_SHELVED, INSTANCE_STATUS_SHELVED_OFFLOADED, INSTANCE_STATUS_SHUTOFF, INSTANCE_STATUS_SOFT_DELETED: return models.VM_READY default: @@ -412,7 +414,13 @@ func (region *SRegion) ChangeConfig(instance *SInstance, flavorId string) error } _, maxVersion, _ := region.GetVersion("compute") _, _, err := region.Post("compute", fmt.Sprintf("/servers/%s/action", instance.ID), maxVersion, jsonutils.Marshal(params)) - return err + if err != nil { + return err + } + if err := cloudprovider.WaitStatus(instance, INSTANCE_STATUS_VERIFY_RESIZE, time.Second*3, time.Minute*4); err != nil { + return err + } + return region.instanceOperation(instance.ID, "confirmResize") } func (instance *SInstance) AttachDisk(ctx context.Context, diskId string) error { diff --git a/pkg/util/openstack/region.go b/pkg/util/openstack/region.go index 71aa555326..9a1010ba4d 100644 --- a/pkg/util/openstack/region.go +++ b/pkg/util/openstack/region.go @@ -171,12 +171,16 @@ func (region *SRegion) GetIStoragecaches() ([]cloudprovider.ICloudStoragecache, } func (region *SRegion) GetIVpcById(id string) (cloudprovider.ICloudVpc, error) { - vpc, err := region.GetVpc(id) + ivpcs, err := region.GetIVpcs() if err != nil { return nil, err } - vpc.region = region - return vpc, nil + for i := 0; i < len(ivpcs); i++ { + if ivpcs[i].GetGlobalId() == id { + return ivpcs[i], nil + } + } + return nil, cloudprovider.ErrNotFound } func (region *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) { diff --git a/pkg/util/openstack/securitygroup.go b/pkg/util/openstack/securitygroup.go index 8503fa8f50..bfb6cdef72 100644 --- a/pkg/util/openstack/securitygroup.go +++ b/pkg/util/openstack/securitygroup.go @@ -296,6 +296,10 @@ func (region *SRegion) delSecurityGroupRule(ruleId string) error { } func (region *SRegion) addSecurityGroupRules(secgroupId string, rule *secrules.SecurityRule) error { + if rule.Action == secrules.SecurityRuleDeny { + // openstack 不支持deny规则 + return nil + } direction := "ingress" if rule.Direction == secrules.SecurityRuleEgress { direction = "egress"