diff --git a/pkg/multicloud/nutanix/image.go b/pkg/multicloud/nutanix/image.go index 18523dd939..77b61a3fa0 100644 --- a/pkg/multicloud/nutanix/image.go +++ b/pkg/multicloud/nutanix/image.go @@ -207,7 +207,7 @@ func (self *SRegion) CreateImage(storageId string, opts *cloudprovider.SImageCre return nil, errors.Wrapf(err, "upload") } resp.Unmarshal(&ret) - err = cloudprovider.Wait(time.Second*5, time.Minute*10, func() (bool, error) { + err = cloudprovider.Wait(time.Second*10, time.Hour*2, func() (bool, error) { task, err := self.GetTask(ret.TaskUUID) if err != nil { return false, err diff --git a/pkg/multicloud/nutanix/instance.go b/pkg/multicloud/nutanix/instance.go index 09037f14d5..6b6d6b7319 100644 --- a/pkg/multicloud/nutanix/instance.go +++ b/pkg/multicloud/nutanix/instance.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "net/url" + "sort" "strings" "yunion.io/x/jsonutils" @@ -147,10 +148,16 @@ func (self *SInstance) CreateDisk(ctx context.Context, opts *cloudprovider.Guest if !utils.IsInStringArray(driver, []string{"ide", "scsi", "pci", "sata"}) { driver = "scsi" } - idx := -1 + idx, ids := -1, []int{} for _, disk := range self.VMDiskInfo { - if disk.DiskAddress.DeviceBus == driver && disk.DiskAddress.DeviceIndex > idx && disk.DiskAddress.DeviceIndex == idx+1 { - idx = disk.DiskAddress.DeviceIndex + if disk.DiskAddress.DeviceBus == driver { + ids = append(ids, disk.DiskAddress.DeviceIndex) + } + } + sort.Ints(ids) + for _, id := range ids { + if id == idx+1 { + idx = id } } params := map[string]interface{}{ @@ -365,7 +372,11 @@ func (self *SInstance) StartVM(ctx context.Context) error { } func (self *SInstance) StopVM(ctx context.Context, opts *cloudprovider.ServerStopOptions) error { - return self.host.zone.region.SetInstancePowerState(self.UUID, "acpi_shutdown") + act := "acpi_shutdown" + if opts.IsForce { + act = "off" + } + return self.host.zone.region.SetInstancePowerState(self.UUID, act) } func (self *SInstance) UpdateUserData(userData string) error { diff --git a/pkg/multicloud/nutanix/vpc.go b/pkg/multicloud/nutanix/vpc.go index 8b8ad74371..c962d5256a 100644 --- a/pkg/multicloud/nutanix/vpc.go +++ b/pkg/multicloud/nutanix/vpc.go @@ -17,6 +17,7 @@ package nutanix import ( "fmt" "net/url" + "sort" "strconv" "strings" @@ -150,10 +151,14 @@ func (self *SRegion) CreateVpc(opts *cloudprovider.VpcCreateOptions) (*SVpc, err if err != nil { return nil, errors.Wrapf(err, "GetVpcs") } - vlanId := -1 + vlanId, vlanIds := -1, []int{} for i := range vpcs { - if vpcs[i].VlanID == vlanId+1 { - vlanId = vpcs[i].VlanID + vlanIds = append(vlanIds, vpcs[i].VlanID) + } + sort.Ints(vlanIds) + for _, vlan := range vlanIds { + if vlan == vlanId+1 { + vlanId = vlan } } params := map[string]interface{}{