vpcs: 自动删除wire

This commit is contained in:
Yousong Zhou
2020-01-17 17:44:29 +08:00
parent 81dc7fd91e
commit 93c2192b77
2 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -701,7 +701,7 @@ func (self *SVpc) Delete(ctx context.Context, userCred mcclient.TokenCredential)
}
func (self *SVpc) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
if len(self.ExternalId) > 0 {
if self.Id != api.DEFAULT_VPC_ID {
return self.StartDeleteVpcTask(ctx, userCred)
} else {
return self.RealDelete(ctx, userCred)
+17
View File
@@ -937,3 +937,20 @@ func (self *SWire) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict
}
return extra
}
func (man *SWireManager) removeWiresByVpc(ctx context.Context, userCred mcclient.TokenCredential, vpc *SVpc) error {
wires := []SWire{}
q := man.Query().Equals("vpc_id", vpc.Id)
err := db.FetchModelObjects(man, q, &wires)
if err != nil {
return err
}
var errs []error
for i := range wires {
wire := &wires[i]
if err := wire.Delete(ctx, userCred); err != nil {
errs = append(errs, err)
}
}
return errors.NewAggregate(errs)
}