补充Azure创建快照功能

This commit is contained in:
屈轩
2018-11-15 12:01:22 +08:00
parent 44801052b5
commit ce70ab3300
4 changed files with 43 additions and 26 deletions
-23
View File
@@ -483,26 +483,3 @@ func (self *SAliyunGuestDriver) OnGuestDeployTaskDataReceived(ctx context.Contex
func (self *SAliyunGuestDriver) AllowReconfigGuest() bool {
return true
}
func (self *SAliyunGuestDriver) RequestDiskSnapshot(ctx context.Context, guest *models.SGuest, task taskman.ITask, snapshotId, diskId string) error {
iDisk, _ := models.DiskManager.FetchById(diskId)
disk := iDisk.(*models.SDisk)
providerDisk, err := disk.GetIDisk()
if err != nil {
return err
}
iSnapshot, _ := models.SnapshotManager.FetchById(snapshotId)
snapshot := iSnapshot.(*models.SSnapshot)
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
cloudSnapshot, err := providerDisk.CreateISnapshot(snapshot.Name, "")
if err != nil {
return nil, err
}
res := jsonutils.NewDict()
res.Set("snapshot_id", jsonutils.NewString(cloudSnapshot.GetId()))
res.Set("manager_id", jsonutils.NewString(cloudSnapshot.GetManagerId()))
res.Set("cloudregion_id", jsonutils.NewString(cloudSnapshot.GetRegionId()))
return res, nil
})
return nil
}
@@ -351,3 +351,26 @@ func (self *SManagedVirtualizedGuestDriver) RequestSyncConfigOnHost(ctx context.
})
return nil
}
func (self *SManagedVirtualizedGuestDriver) RequestDiskSnapshot(ctx context.Context, guest *models.SGuest, task taskman.ITask, snapshotId, diskId string) error {
iDisk, _ := models.DiskManager.FetchById(diskId)
disk := iDisk.(*models.SDisk)
providerDisk, err := disk.GetIDisk()
if err != nil {
return err
}
iSnapshot, _ := models.SnapshotManager.FetchById(snapshotId)
snapshot := iSnapshot.(*models.SSnapshot)
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
cloudSnapshot, err := providerDisk.CreateISnapshot(snapshot.Name, "")
if err != nil {
return nil, err
}
res := jsonutils.NewDict()
res.Set("snapshot_id", jsonutils.NewString(cloudSnapshot.GetId()))
res.Set("manager_id", jsonutils.NewString(cloudSnapshot.GetManagerId()))
res.Set("cloudregion_id", jsonutils.NewString(cloudSnapshot.GetRegionId()))
return res, nil
})
return nil
}
+1 -1
View File
@@ -274,7 +274,7 @@ func (self *SAzureClient) checkParams(body jsonutils.JSONObject, params []string
for i := 0; i < len(params); i++ {
data, err := body.GetString(params[i])
if err != nil {
return nil, fmt.Errorf("Missing %s params")
return nil, fmt.Errorf("Missing %s params", params[i])
}
result[params[i]] = data
}
+19 -2
View File
@@ -22,8 +22,9 @@ type SSnapshot struct {
Name string
Location string
ManagedBy string
Sku SnapshotSku
Sku *SnapshotSku
Properties DiskProperties
Type string
}
func (self *SSnapshot) GetId() string {
@@ -57,7 +58,23 @@ func (self *SSnapshot) IsEmulated() bool {
}
func (self *SRegion) CreateSnapshot(diskId, snapName, desc string) (*SSnapshot, error) {
snapshot := SSnapshot{}
disk, err := self.GetDisk(diskId)
if err != nil {
return nil, err
}
snapshot := SSnapshot{
region: self,
Name: snapName,
Location: self.Name,
Properties: DiskProperties{
CreationData: CreationData{
CreateOption: "Copy",
SourceResourceID: diskId,
},
DiskSizeGB: disk.Properties.DiskSizeGB,
},
Type: "Microsoft.Compute/snapshots",
}
return &snapshot, self.client.Create(jsonutils.Marshal(snapshot), &snapshot)
}