less code

This commit is contained in:
TangBin
2018-10-27 17:35:52 +08:00
parent 7dd4323fbf
commit 2dae75ca49
4 changed files with 16 additions and 14 deletions
+7 -11
View File
@@ -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
+1 -1
View File
@@ -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,
})
}
+1 -2
View File
@@ -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 {
+7
View File
@@ -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
}