mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
less code
This commit is contained in:
+7
-11
@@ -368,21 +368,17 @@ func (self *SRegion) resetDisk(diskId, snapshotId string) error {
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateDisk(zoneId string, category string, name string, sizeGb int, desc string) (string, error) {
|
||||
tagspec := TagSpec{ResourceType: "volume"}
|
||||
tagspec.SetNameTag(name)
|
||||
tagspec.SetDescTag(desc)
|
||||
ec2Tags, _ := tagspec.GetTagSpecifications()
|
||||
|
||||
params := &ec2.CreateVolumeInput{}
|
||||
params.SetAvailabilityZone(zoneId)
|
||||
params.SetVolumeType(category)
|
||||
params.SetSize(int64(sizeGb))
|
||||
// todo: less code here
|
||||
tagSpec := &ec2.TagSpecification{}
|
||||
tagSpec.SetResourceType(ec2.ResourceTypeVolume)
|
||||
nameTag := &ec2.Tag{}
|
||||
nameTag.SetKey("Name")
|
||||
nameTag.SetValue(name)
|
||||
descTag := &ec2.Tag{}
|
||||
descTag.SetKey("Description")
|
||||
descTag.SetValue(desc)
|
||||
tagSpec.SetTags([]*ec2.Tag{nameTag, descTag})
|
||||
params.SetTagSpecifications([]*ec2.TagSpecification{tagSpec})
|
||||
params.SetTagSpecifications([]*ec2.TagSpecification{ec2Tags})
|
||||
|
||||
ret, err := self.ec2Client.CreateVolume(params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -202,6 +202,7 @@ func getRootDiskSize(image *ec2.Image) (int, error) {
|
||||
|
||||
return 0, fmt.Errorf("image size not found: %s", image.String())
|
||||
}
|
||||
|
||||
func (self *SRegion) GetImages(status ImageStatusType, owner ImageOwnerType, imageId []string, name string, offset int, limit int) ([]SImage, int, error) {
|
||||
params := &ec2.DescribeImagesInput{}
|
||||
filters := make([]*ec2.Filter, 0)
|
||||
@@ -253,7 +254,6 @@ func (self *SRegion) GetImages(status ImageStatusType, owner ImageOwnerType, ima
|
||||
CreationTime: *image.CreationDate,
|
||||
Size: size,
|
||||
// Usage: "",
|
||||
//Size: image.,
|
||||
// OSName: *image.Platform,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ func init() {
|
||||
}
|
||||
|
||||
shellutils.R(&SnapshotDeleteOptions{}, "snapshot-delete", "Delete snapshot", func(cli *aws.SRegion, args *SnapshotDeleteOptions) error {
|
||||
// todo://
|
||||
return nil
|
||||
return cli.DeleteSnapshot(args.ID)
|
||||
})
|
||||
|
||||
type SnapshotCreateOptions struct {
|
||||
|
||||
@@ -169,3 +169,10 @@ func (self *SRegion) CreateSnapshot(diskId, name, desc string) (string, error) {
|
||||
_, err := self.ec2Client.CreateSnapshot(params)
|
||||
return "", err
|
||||
}
|
||||
|
||||
func (self *SRegion) DeleteSnapshot(snapshotId string) error {
|
||||
params := &ec2.DeleteSnapshotInput{}
|
||||
params.SetSnapshotId(snapshotId)
|
||||
_, err := self.ec2Client.DeleteSnapshot(params)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user