fix eip projcet source & snapshot bugfix

This commit is contained in:
TangBin
2019-06-29 17:41:53 +08:00
parent d5f4e5eecf
commit 675d7649a4
7 changed files with 57 additions and 15 deletions
+15
View File
@@ -15,6 +15,10 @@
package guestdrivers
import (
"fmt"
"yunion.io/x/pkg/utils"
api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/compute/models"
)
@@ -74,6 +78,17 @@ func (self *SUCloudGuestDriver) GetGuestInitialStateAfterRebuild() string {
return api.VM_RUNNING
}
func (self *SUCloudGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
if !utils.IsInStringArray(guest.Status, []string{api.VM_READY}) {
return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
}
if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_UCLOUD_CLOUD_SSD, api.STORAGE_UCLOUD_CLOUD_NORMAL}) {
return fmt.Errorf("Cannot resize disk with unsupported volumes type %s", storage.StorageType)
}
return nil
}
func init() {
driver := SUCloudGuestDriver{}
models.RegisterGuestDriver(&driver)
+1
View File
@@ -976,6 +976,7 @@ func (manager *SElasticipManager) AllocateEipAndAssociateVM(ctx context.Context,
eip.Bandwidth = bw
eip.ChargeType = chargeType
eip.ProjectId = vm.ProjectId
eip.ProjectSrc = string(db.PROJECT_SOURCE_LOCAL)
eip.ManagerId = host.ManagerId
eip.CloudregionId = region.Id
eip.Name = fmt.Sprintf("eip-for-%s", vm.GetName())
+24 -5
View File
@@ -226,7 +226,17 @@ func (self *SDisk) CreateISnapshot(ctx context.Context, name string, desc string
return nil, err
}
return self.GetISnapshot(snapshot)
isnapshot, err := self.GetISnapshot(snapshot)
if err != nil {
return nil, err
}
err = cloudprovider.WaitStatus(isnapshot, api.SNAPSHOT_READY, time.Second*10, time.Second*300)
if err != nil {
return nil, err
}
return isnapshot, nil
}
func (self *SDisk) getSnapshot(snapshotId string) (*SSnapshot, error) {
@@ -329,9 +339,9 @@ func (self *SRegion) GetDisks(zoneId string, diskType string, diskIds []string)
if len(diskIds) > 0 {
filtedDisks := make([]SDisk, 0)
for _, disk := range disks {
if utils.IsInStringArray(disk.UDiskID, diskIds) {
filtedDisks = append(filtedDisks, disk)
for i := range disks {
if utils.IsInStringArray(disks[i].UDiskID, diskIds) {
filtedDisks = append(filtedDisks, disks[i])
}
}
@@ -411,7 +421,7 @@ func (self *SRegion) resetDisk(zoneId, diskId, snapshotId string) error {
params.Set("SnapshotId", snapshotId)
}
return self.DoAction("UDisk-RestoreUDisk", params, nil)
return self.DoAction("RestoreUDisk", params, nil)
}
// https://docs.ucloud.cn/api/udisk-api/attach_udisk
@@ -426,6 +436,15 @@ func (self *SRegion) AttachDisk(zoneId string, instanceId string, diskId string)
// https://docs.ucloud.cn/api/udisk-api/detach_udisk
func (self *SRegion) DetachDisk(zoneId string, instanceId string, diskId string) error {
idisks, err := self.GetDisk(diskId)
if err != nil {
return err
}
if idisks.Status == "Available" {
return nil
}
params := NewUcloudParams()
params.Set("Zone", zoneId)
params.Set("UHostId", instanceId)
+3 -3
View File
@@ -247,9 +247,9 @@ func (self *SRegion) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) {
}
isnapshots := make([]cloudprovider.ICloudSnapshot, 0)
for _, snapshot := range snapshots {
snapshot.region = self
isnapshots = append(isnapshots, &snapshot)
for i := range snapshots {
snapshots[i].region = self
isnapshots = append(isnapshots, &snapshots[i])
}
return isnapshots, nil
+3 -2
View File
@@ -34,11 +34,12 @@ func init() {
})
type SnapshotDeleteOptions struct {
ID string `help:"Snapshot ID"`
ID string `help:"Snapshot ID"`
Zone string `help:"Snapshot zone id"`
}
shellutils.R(&SnapshotDeleteOptions{}, "snapshot-delete", "Delete snapshot", func(cli *ucloud.SRegion, args *SnapshotDeleteOptions) error {
return cli.DeleteSnapshot(args.ID)
return cli.DeleteSnapshot(args.ID, args.Zone)
})
type SnapshotCreateOptions struct {
+8 -2
View File
@@ -116,7 +116,12 @@ func (self *SSnapshot) GetDiskType() string {
// https://docs.ucloud.cn/api/udisk-api/delete_udisk_snapshot
func (self *SSnapshot) Delete() error {
return self.region.DeleteSnapshot(self.GetId())
idisk, err := self.region.GetDisk(self.UDiskID)
if err != nil {
return err
}
return self.region.DeleteSnapshot(self.GetId(), idisk.Zone)
}
func (self *SRegion) GetSnapshotById(snapshotId string) (SSnapshot, error) {
@@ -158,9 +163,10 @@ func (self *SRegion) GetSnapshots(diskId string, snapshotId string) ([]SSnapshot
}
// https://docs.ucloud.cn/api/udisk-api/delete_udisk_snapshot
func (self *SRegion) DeleteSnapshot(snapshotId string) error {
func (self *SRegion) DeleteSnapshot(snapshotId string, zoneId string) error {
params := NewUcloudParams()
params.Set("SnapshotId", snapshotId)
params.Set("Zone", zoneId)
return self.DoAction("DeleteUDiskSnapshot", params, nil)
}
+3 -3
View File
@@ -288,9 +288,9 @@ func (self *SRegion) GetImageByName(name string) (*SImage, error) {
return nil, err
}
for _, image := range images {
if image.GetName() == name {
return &image, nil
for i := range images {
if images[i].GetName() == name {
return &images[i], nil
}
}