mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
add snapshot sync
This commit is contained in:
+10
-2
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
|
||||
type SRegion struct {
|
||||
@@ -190,7 +189,16 @@ func (self *SRegion) GetIEips() ([]cloudprovider.ICloudEIP, error) {
|
||||
}
|
||||
|
||||
func (self *SRegion) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) {
|
||||
return nil, httperrors.NewNotImplementedError("not implement")
|
||||
snapshots, _, err := self.GetSnapshots("", "", "", []string{}, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := make([]cloudprovider.ICloudSnapshot, len(snapshots))
|
||||
for i := 0; i < len(snapshots); i += 1 {
|
||||
ret[i] = &snapshots[i]
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIZoneById(id string) (cloudprovider.ICloudZone, error) {
|
||||
|
||||
@@ -3,9 +3,9 @@ package aws
|
||||
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"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
)
|
||||
|
||||
type SnapshotStatusType string
|
||||
@@ -92,9 +92,57 @@ func (self *SSnapshot) GetRegionId() string {
|
||||
}
|
||||
|
||||
func (self *SRegion) GetSnapshots(instanceId string, diskId string, snapshotName string, snapshotIds []string, offset int, limit int) ([]SSnapshot, int, error) {
|
||||
return nil, 0 , nil
|
||||
params := &ec2.DescribeSnapshotsInput{}
|
||||
filters := make([]*ec2.Filter, 0)
|
||||
// todo: not support search by instancesId. use Tag?
|
||||
// if len(instanceId) > o {
|
||||
// filters = AppendSingleValueFilter(filters, )
|
||||
// }
|
||||
|
||||
if len(diskId) > 0 {
|
||||
filters = AppendSingleValueFilter(filters, "volume-id", diskId)
|
||||
}
|
||||
|
||||
// not supported. use Tag?
|
||||
// if len(snapshotName) > 0 {
|
||||
// filters = AppendSingleValueFilter(filters, "volume-id", diskId)
|
||||
// }
|
||||
if len(filters) > 0 {
|
||||
params.SetFilters(filters)
|
||||
}
|
||||
|
||||
if len(snapshotIds) > 0 {
|
||||
params.SetSnapshotIds(ConvertedList(snapshotIds))
|
||||
}
|
||||
|
||||
ret, err := self.ec2Client.DescribeSnapshots(params)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
snapshots := []SSnapshot{}
|
||||
for _, item := range ret.Snapshots{
|
||||
snapshot := SSnapshot{}
|
||||
snapshot.SnapshotId = *item.SnapshotId
|
||||
snapshot.Status = SnapshotStatusType(*item.State)
|
||||
snapshot.region = self
|
||||
snapshot.Progress = *item.Progress
|
||||
snapshot.SnapshotName = *item.SnapshotId
|
||||
snapshot.SourceDiskId = *item.VolumeId
|
||||
snapshot.SourceDiskSize = int32(*item.VolumeSize)
|
||||
// snapshot.SourceDiskType
|
||||
snapshots = append(snapshots, snapshot)
|
||||
}
|
||||
|
||||
return snapshots, len(snapshots), nil
|
||||
}
|
||||
|
||||
func (self *SRegion) GetISnapshotById(snapshotId string) (cloudprovider.ICloudSnapshot, error) {
|
||||
return nil, httperrors.NewNotImplementedError("not implement")
|
||||
if snapshots, total, err := self.GetSnapshots("", "", "", []string{snapshotId}, 0, 1); err != nil {
|
||||
return nil, err
|
||||
} else if total != 1 {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
} else {
|
||||
return &snapshots[0], nil
|
||||
}
|
||||
}
|
||||
|
||||
+24
-1
@@ -8,6 +8,14 @@ import (
|
||||
"yunion.io/x/log"
|
||||
)
|
||||
|
||||
var StorageTypes = []string{
|
||||
models.STORAGE_GP2_SSD,
|
||||
models.STORAGE_IO1_SSD,
|
||||
models.STORAGE_ST1_HDD,
|
||||
models.STORAGE_SC1_SSD,
|
||||
models.STORAGE_STANDARD_SSD,
|
||||
}
|
||||
|
||||
type SZone struct {
|
||||
region *SRegion
|
||||
host *SHost
|
||||
@@ -18,6 +26,9 @@ type SZone struct {
|
||||
ZoneId string // 沿用阿里云ZoneId,对应Aws ZoneName
|
||||
LocalName string
|
||||
State string
|
||||
|
||||
/* 支持的磁盘种类集合 */
|
||||
storageTypes []string
|
||||
}
|
||||
|
||||
func (self *SZone) addWire(wire *SWire) {
|
||||
@@ -34,8 +45,20 @@ func (self *SZone) getHost() *SHost {
|
||||
return self.host
|
||||
}
|
||||
|
||||
func (self *SZone) getStorageType() {
|
||||
if len(self.storageTypes) == 0 {
|
||||
self.storageTypes = StorageTypes
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SZone) fetchStorages() error {
|
||||
// todo: implement me
|
||||
self.getStorageType()
|
||||
self.istorages = make([]cloudprovider.ICloudStorage, len(self.storageTypes))
|
||||
|
||||
for i, sc := range self.storageTypes {
|
||||
storage := SStorage{zone: self, storageType: sc}
|
||||
self.istorages[i] = &storage
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user