From 3085df0c07c136d922a5f1ca0fe0563cb525b242 Mon Sep 17 00:00:00 2001 From: TangBin Date: Tue, 16 Oct 2018 17:03:32 +0800 Subject: [PATCH] add snapshot --- pkg/util/aws/snapshot.go | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/pkg/util/aws/snapshot.go b/pkg/util/aws/snapshot.go index 8d3601d946..048ad53594 100644 --- a/pkg/util/aws/snapshot.go +++ b/pkg/util/aws/snapshot.go @@ -4,6 +4,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/httperrors" + "fmt" + "yunion.io/x/onecloud/pkg/compute/models" ) type SnapshotStatusType string @@ -28,43 +30,57 @@ type SSnapshot struct { } func (self *SSnapshot) GetId() string { - panic("implement me") + return self.SnapshotId } func (self *SSnapshot) GetName() string { - panic("implement me") + return self.SnapshotName } func (self *SSnapshot) GetGlobalId() string { - panic("implement me") + return fmt.Sprintf("%s", self.SnapshotId) } func (self *SSnapshot) GetStatus() string { - panic("implement me") + // todo: implement me + if self.Status == SnapshotStatusAccomplished { + return models.SNAPSHOT_READY + } else if self.Status == SnapshotStatusProgress { + return models.SNAPSHOT_CREATING + } else { // if self.Status == SnapshotStatusFailed + return models.SNAPSHOT_FAILED + } } func (self *SSnapshot) Refresh() error { - panic("implement me") + if snapshots, total, err := self.region.GetSnapshots("", "", "", []string{self.SnapshotId}, 0, 1); err != nil { + return err + } else if total != 1 { + return cloudprovider.ErrNotFound + } else if err := jsonutils.Update(self, snapshots[0]); err != nil { + return err + } + return nil } func (self *SSnapshot) IsEmulated() bool { - panic("implement me") + return false } func (self *SSnapshot) GetMetadata() *jsonutils.JSONDict { - panic("implement me") + return nil } func (self *SSnapshot) GetManagerId() string { - panic("implement me") + return self.region.client.providerId } func (self *SSnapshot) GetSize() int32 { - panic("implement me") + return self.SourceDiskSize } func (self *SSnapshot) GetDiskId() string { - panic("implement me") + return self.SourceDiskId } func (self *SSnapshot) Delete() error { @@ -72,7 +88,7 @@ func (self *SSnapshot) Delete() error { } func (self *SSnapshot) GetRegionId() string { - panic("implement me") + return self.region.GetId() } func (self *SRegion) GetSnapshots(instanceId string, diskId string, snapshotName string, snapshotIds []string, offset int, limit int) ([]SSnapshot, int, error) {