mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
Automatic merge from release/2.2.0 -> release/2.3.0
* commit 'dec5b9c1a95372a2079cad8a4264c51c783557f6': 修正:删除guest时候没有正确清理eip的数据 allow snapshot-list --manager <cloud-provider-id-or-name> 修正:补充2.2.0 purge eip/snapshot接口
This commit is contained in:
@@ -187,4 +187,16 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type EipPurgeOptions struct {
|
||||
ID string `help:"ID or name of EIP"`
|
||||
}
|
||||
R(&EipPurgeOptions{}, "eip-purge", "Purge EIP db records", func(s *mcclient.ClientSession, args *EipPurgeOptions) error {
|
||||
result, err := modules.Elasticips.PerformAction(s, args.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ func init() {
|
||||
Share bool `help:"Show shared snapshots"`
|
||||
DiskType string `help: "Filter by disk type" choices:"sys|data"`
|
||||
Provider string `help: "Cloud provider" choices:"Aliyun|VMware|Azure"`
|
||||
|
||||
Manager string `help:"Show snapshots belongs to a specific cloud provider"`
|
||||
}
|
||||
R(&SnapshotsListOptions{}, "snapshot-list", "Show snapshots", func(s *mcclient.ClientSession, args *SnapshotsListOptions) error {
|
||||
params, err := args.BaseListOptions.Params()
|
||||
@@ -41,6 +43,9 @@ func init() {
|
||||
if len(args.Provider) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Provider), "provider")
|
||||
}
|
||||
if len(args.Manager) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Manager), "manager")
|
||||
}
|
||||
result, err := modules.Snapshots.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -84,4 +89,17 @@ func init() {
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
type SnapshotPurgeOptions struct {
|
||||
ID string `help:"ID or name of Snapshot"`
|
||||
}
|
||||
R(&SnapshotPurgeOptions{}, "snapshot-purge", "Purge Snapshot db records", func(s *mcclient.ClientSession, args *SnapshotPurgeOptions) error {
|
||||
result, err := modules.Snapshots.PerformAction(s, args.ID, "purge", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ func init() {
|
||||
type VpcListOptions struct {
|
||||
options.BaseListOptions
|
||||
Region string `help:"ID or Name of region"`
|
||||
Manager string `help:"Show regions belongs to the cloud provider"`
|
||||
Manager string `help:"Show vpcs belongs to the cloud provider"`
|
||||
}
|
||||
R(&VpcListOptions{}, "vpc-list", "List VPCs", func(s *mcclient.ClientSession, args *VpcListOptions) error {
|
||||
var params *jsonutils.JSONDict
|
||||
|
||||
@@ -812,3 +812,30 @@ func (manager *SElasticipManager) TotalCount(projectId string, rangeObj db.IStan
|
||||
usage.EIPUsedCount = q3.Count()
|
||||
return usage
|
||||
}
|
||||
|
||||
func (self *SElasticip) AllowPerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return userCred.IsSystemAdmin()
|
||||
}
|
||||
|
||||
func (self *SElasticip) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
provider := self.GetCloudprovider()
|
||||
if provider != nil {
|
||||
if provider.Enabled {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot purge elastic_ip on enabled cloud provider")
|
||||
}
|
||||
}
|
||||
err = self.RealDelete(ctx, userCred)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (self *SElasticip) DoPendingDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
if self.Mode == EIP_MODE_INSTANCE_PUBLICIP {
|
||||
self.SVirtualResourceBase.DoPendingDelete(ctx, userCred)
|
||||
return
|
||||
}
|
||||
self.Dissociate(ctx, userCred)
|
||||
}
|
||||
@@ -3127,6 +3127,10 @@ func (self *SGuest) StartChangeConfigTask(ctx context.Context, userCred mcclient
|
||||
}
|
||||
|
||||
func (self *SGuest) DoPendingDelete(ctx context.Context, userCred mcclient.TokenCredential) {
|
||||
eip, _ := self.GetEip()
|
||||
if eip != nil {
|
||||
eip.DoPendingDelete(ctx, userCred)
|
||||
}
|
||||
for _, guestdisk := range self.GetDisks() {
|
||||
disk := guestdisk.GetDisk()
|
||||
storage := disk.GetStorage()
|
||||
@@ -4539,10 +4543,18 @@ func (self *SGuest) DeleteEip(ctx context.Context, userCred mcclient.TokenCreden
|
||||
if eip == nil {
|
||||
return nil
|
||||
}
|
||||
err = eip.Delete(ctx, userCred)
|
||||
if err != nil {
|
||||
log.Errorf("Delete eip fail %s", err)
|
||||
return err
|
||||
if eip.Mode == EIP_MODE_INSTANCE_PUBLICIP {
|
||||
err = eip.RealDelete(ctx, userCred)
|
||||
if err != nil {
|
||||
log.Errorf("Delete eip on delete server fail %s", err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err = eip.Dissociate(ctx, userCred)
|
||||
if err != nil {
|
||||
log.Errorf("Dissociate eip on delete server fail %s", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -119,6 +119,18 @@ func (manager *SSnapshotManager) ListItemFilter(ctx context.Context, q *sqlchemy
|
||||
sq := cloudproviderTbl.Query(cloudproviderTbl.Field("id")).Equals("provider", provider)
|
||||
q = q.In("manager_id", sq)
|
||||
}
|
||||
|
||||
if managerStr := jsonutils.GetAnyString(query, []string{"manager", "manager_id"}); len(managerStr) > 0 {
|
||||
managerObj, err := CloudproviderManager.FetchByIdOrName("", managerStr)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewNotFoundError("manager %s not found", managerStr)
|
||||
}
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
q = q.Equals("manager_id", managerObj.GetId())
|
||||
}
|
||||
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -543,3 +555,22 @@ func (self *SSnapshot) GetISnapshotRegion() (cloudprovider.ICloudRegion, error)
|
||||
}
|
||||
return provider.GetIRegionById(region.GetExternalId())
|
||||
}
|
||||
|
||||
func (self *SSnapshot) AllowPerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return userCred.IsSystemAdmin()
|
||||
}
|
||||
|
||||
func (self *SSnapshot) PerformPurge(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
provider := self.GetCloudprovider()
|
||||
if provider != nil {
|
||||
if provider.Enabled {
|
||||
return nil, httperrors.NewInvalidStatusError("Cannot purge snapshot on enabled cloud provider")
|
||||
}
|
||||
}
|
||||
err = self.RealDelete(ctx, userCred)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ func (self *SStoragecachedimage) isDownloadSessionExpire() bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SStoragecachedimage) markDeleting(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
func (self *SStoragecachedimage) markDeleting(ctx context.Context, userCred mcclient.TokenCredential, isForce bool) error {
|
||||
err := self.ValidateDeleteCondition(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -237,7 +237,7 @@ func (self *SStoragecachedimage) markDeleting(ctx context.Context, userCred mccl
|
||||
lockman.LockJointObject(ctx, cache, image)
|
||||
defer lockman.ReleaseJointObject(ctx, cache, image)
|
||||
|
||||
if utils.IsInStringArray(self.Status, []string{CACHED_IMAGE_STATUS_READY, CACHED_IMAGE_STATUS_DELETING}) {
|
||||
if !isForce && ! utils.IsInStringArray(self.Status, []string{CACHED_IMAGE_STATUS_READY, CACHED_IMAGE_STATUS_DELETING}) {
|
||||
return httperrors.NewInvalidStatusError("Cannot uncache in status %s", self.Status)
|
||||
}
|
||||
_, err = self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
|
||||
@@ -318,7 +318,7 @@ func (self *SStoragecache) PerformUncacheImage(ctx context.Context, userCred mcc
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = scimg.markDeleting(ctx, userCred)
|
||||
err = scimg.markDeleting(ctx, userCred, isForce)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInvalidStatusError("Fail to mark cache status: %s", err)
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func (manager *SStorageManager) GetContextManager() []db.IModelManager {
|
||||
}
|
||||
|
||||
func (self *SStorage) ValidateDeleteCondition(ctx context.Context) error {
|
||||
if self.GetHostCount() > 0 || self.GetDiskCount() > 0 {
|
||||
if self.GetHostCount() > 0 || self.GetDiskCount() > 0 || self.GetSnapshotCount() > 0 {
|
||||
return httperrors.NewNotEmptyError("Not an empty storage provider")
|
||||
}
|
||||
return self.SEnabledStatusStandaloneResourceBase.ValidateDeleteCondition(ctx)
|
||||
@@ -103,6 +103,10 @@ func (self *SStorage) GetDiskCount() int {
|
||||
return DiskManager.Query().Equals("storage_id", self.Id).Count()
|
||||
}
|
||||
|
||||
func (self *SStorage) GetSnapshotCount() int {
|
||||
return SnapshotManager.Query().Equals("storage_id", self.Id).Count()
|
||||
}
|
||||
|
||||
func (self *SStorage) IsLocal() bool {
|
||||
return self.StorageType == STORAGE_LOCAL || self.StorageType == STORAGE_BAREMETAL
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user