From 70de3f412781ac90392c418990200f414c35db3d Mon Sep 17 00:00:00 2001 From: ioito Date: Mon, 24 Jan 2022 14:17:38 +0800 Subject: [PATCH] fix(region): nutanix duplicate vlan id --- pkg/multicloud/nutanix/vpc.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/multicloud/nutanix/vpc.go b/pkg/multicloud/nutanix/vpc.go index 09353eed00..8b8ad74371 100644 --- a/pkg/multicloud/nutanix/vpc.go +++ b/pkg/multicloud/nutanix/vpc.go @@ -21,6 +21,7 @@ import ( "strings" "yunion.io/x/jsonutils" + "yunion.io/x/pkg/errors" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" @@ -145,16 +146,26 @@ func (self *SRegion) CreateVpc(opts *cloudprovider.VpcCreateOptions) (*SVpc, err } } + vpcs, err := self.GetVpcs() + if err != nil { + return nil, errors.Wrapf(err, "GetVpcs") + } + vlanId := -1 + for i := range vpcs { + if vpcs[i].VlanID == vlanId+1 { + vlanId = vpcs[i].VlanID + } + } params := map[string]interface{}{ "name": opts.NAME, "annotation": opts.Desc, "ip_config": ipConfig, - "vlan_id": 0, + "vlan_id": vlanId + 1, } ret := struct { NetworkUUID string }{} - err := self.post("networks", jsonutils.Marshal(params), &ret) + err = self.post("networks", jsonutils.Marshal(params), &ret) if err != nil { return nil, err }