From 93c2192b778f3f17c0cd9242f663f8b1c7cdc90a Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Mon, 18 Nov 2019 13:42:56 +0000 Subject: [PATCH] =?UTF-8?q?vpcs:=20=E8=87=AA=E5=8A=A8=E5=88=A0=E9=99=A4wir?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/vpcs.go | 2 +- pkg/compute/models/wires.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/compute/models/vpcs.go b/pkg/compute/models/vpcs.go index f0ad6f4eec..65edba3b67 100644 --- a/pkg/compute/models/vpcs.go +++ b/pkg/compute/models/vpcs.go @@ -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) diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index bc76c88f4c..df4d7eb41c 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -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) +}