Merge pull request #518 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-snapshot-region-id to release/2.2.0

* commit '503bec34c86f2b00ed54736ec988ab5a4f11bc9e':
  去除不需要接口
  避免公有云找不到对应的cloudregion
This commit is contained in:
邱剑
2018-11-16 23:03:30 +08:00
6 changed files with 15 additions and 35 deletions
-2
View File
@@ -249,12 +249,10 @@ type ICloudDisk interface {
type ICloudSnapshot interface {
ICloudResource
GetManagerId() string
GetSize() int32
GetDiskId() string
GetDiskType() string
Delete() error
GetRegionId() string
}
type ICloudVpc interface {
@@ -368,8 +368,6 @@ func (self *SManagedVirtualizedGuestDriver) RequestDiskSnapshot(ctx context.Cont
}
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
+10 -5
View File
@@ -273,6 +273,7 @@ func (self *SSnapshotManager) CreateSnapshot(ctx context.Context, userCred mccli
return nil, err
}
disk := iDisk.(*SDisk)
storage := disk.GetStorage()
snapshot := &SSnapshot{}
snapshot.SetModelManager(self)
snapshot.ProjectId = userCred.GetProjectId()
@@ -282,6 +283,8 @@ func (self *SSnapshotManager) CreateSnapshot(ctx context.Context, userCred mccli
snapshot.DiskType = disk.DiskType
snapshot.Location = location
snapshot.CreatedBy = createdBy
snapshot.ManagerId = storage.ManagerId
snapshot.CloudregionId = storage.getZone().GetRegion().GetId()
snapshot.Name = name
snapshot.Status = SNAPSHOT_CREATING
err = SnapshotManager.TableSpec().Insert(snapshot)
@@ -437,10 +440,12 @@ func totalSnapshotCount(projectId string) int {
return count
}
func (self *SSnapshot) SyncWithCloudSnapshot(userCred mcclient.TokenCredential, ext cloudprovider.ICloudSnapshot) error {
func (self *SSnapshot) SyncWithCloudSnapshot(userCred mcclient.TokenCredential, ext cloudprovider.ICloudSnapshot, region *SCloudregion) error {
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
self.Name = ext.GetName()
self.Status = ext.GetStatus()
self.DiskType = ext.GetDiskType()
self.CloudregionId = region.Id
return nil
})
if err != nil {
@@ -449,7 +454,7 @@ func (self *SSnapshot) SyncWithCloudSnapshot(userCred mcclient.TokenCredential,
return err
}
func (manager *SSnapshotManager) newFromCloudSnapshot(userCred mcclient.TokenCredential, extSnapshot cloudprovider.ICloudSnapshot, region *SCloudregion) (*SSnapshot, error) {
func (manager *SSnapshotManager) newFromCloudSnapshot(userCred mcclient.TokenCredential, extSnapshot cloudprovider.ICloudSnapshot, region *SCloudregion, provider *SCloudprovider) (*SSnapshot, error) {
snapshot := SSnapshot{}
snapshot.SetModelManager(manager)
@@ -467,7 +472,7 @@ func (manager *SSnapshotManager) newFromCloudSnapshot(userCred mcclient.TokenCre
snapshot.DiskType = extSnapshot.GetDiskType()
snapshot.Size = int(extSnapshot.GetSize()) * 1024
snapshot.ManagerId = extSnapshot.GetManagerId()
snapshot.ManagerId = provider.Id
snapshot.CloudregionId = region.Id
snapshot.ProjectId = userCred.GetProjectId()
@@ -518,7 +523,7 @@ func (manager *SSnapshotManager) SyncSnapshots(ctx context.Context, userCred mcc
}
}
for i := 0; i < len(commondb); i += 1 {
err = commondb[i].SyncWithCloudSnapshot(userCred, commonext[i])
err = commondb[i].SyncWithCloudSnapshot(userCred, commonext[i], region)
if err != nil {
syncResult.UpdateError(err)
} else {
@@ -526,7 +531,7 @@ func (manager *SSnapshotManager) SyncSnapshots(ctx context.Context, userCred mcc
}
}
for i := 0; i < len(added); i += 1 {
_, err := manager.newFromCloudSnapshot(userCred, added[i], region)
_, err := manager.newFromCloudSnapshot(userCred, added[i], region, provider)
if err != nil {
syncResult.AddError(err)
} else {
+3 -10
View File
@@ -52,32 +52,25 @@ func (self *GuestDiskSnapshotTask) DoDiskSnapshot(ctx context.Context, guest *mo
func (self *GuestDiskSnapshotTask) OnDiskSnapshotComplete(ctx context.Context, guest *models.SGuest, data jsonutils.JSONObject) {
res := data.(*jsonutils.JSONDict)
snapshotId, _ := self.Params.GetString("snapshot_id")
iSnapshot, _ := models.SnapshotManager.FetchById(snapshotId)
snapshot := iSnapshot.(*models.SSnapshot)
if guest.Hypervisor == models.HYPERVISOR_KVM {
location, err := res.GetString("location")
if err != nil {
log.Infof("OnDiskSnapshotComplete called with data no location")
return
}
snapshotId, _ := self.Params.GetString("snapshot_id")
iSnapshot, _ := models.SnapshotManager.FetchById(snapshotId)
snapshot := iSnapshot.(*models.SSnapshot)
models.SnapshotManager.TableSpec().Update(snapshot, func() error {
snapshot.Location = location
snapshot.Status = models.SNAPSHOT_READY
return nil
})
} else {
snapshotId, _ := self.Params.GetString("snapshot_id")
iSnapshot, _ := models.SnapshotManager.FetchById(snapshotId)
snapshot := iSnapshot.(*models.SSnapshot)
extSnapshotId, _ := data.GetString("snapshot_id")
cloudregionId, _ := data.GetString("cloudregion_id")
managerId, _ := data.GetString("manager_id")
models.SnapshotManager.TableSpec().Update(snapshot, func() error {
snapshot.CloudregionId = cloudregionId
snapshot.ExternalId = extSnapshotId
snapshot.Status = models.SNAPSHOT_READY
snapshot.ManagerId = managerId
return nil
})
}
-8
View File
@@ -51,14 +51,6 @@ func (self *SSnapshot) GetStatus() string {
}
}
func (self *SSnapshot) GetManagerId() string {
return self.region.client.providerId
}
func (self *SSnapshot) GetRegionId() string {
return self.region.GetId()
}
func (self *SSnapshot) GetSize() int32 {
return self.SourceDiskSize
}
+2 -8
View File
@@ -154,9 +154,11 @@ func (self *SRegion) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) {
classicSnapshots = append(classicSnapshots, _classicSnapshots...)
isnapshots := make([]cloudprovider.ICloudSnapshot, len(snapshots)+len(classicSnapshots))
for i := 0; i < len(snapshots); i++ {
snapshots[i].region = self
isnapshots[i] = &snapshots[i]
}
for i := 0; i < len(classicSnapshots); i++ {
classicSnapshots[i].region = self
isnapshots[len(snapshots)+i] = &classicSnapshots[i]
}
return isnapshots, nil
@@ -166,14 +168,6 @@ func (self *SSnapshot) GetDiskId() string {
return self.Properties.CreationData.SourceResourceID
}
func (self *SSnapshot) GetManagerId() string {
return self.region.client.providerId
}
func (self *SSnapshot) GetRegionId() string {
return self.region.GetId()
}
func (self *SSnapshot) GetDiskType() string {
return ""
}