Skip to content

Commit

Permalink
Add the SINGLE_VPC property to Driver CapabilityInfo to avoid creatin…
Browse files Browse the repository at this point in the history
…g another VPC
  • Loading branch information
powerkimhub committed May 23, 2022
1 parent 7a98e53 commit bb56508
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
20 changes: 20 additions & 0 deletions api-runtime/common-runtime/CCMCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ func CreateVPC(connectionName string, rsType string, reqInfo cres.VPCReqInfo) (*

vpcRWLock.Lock()
defer vpcRWLock.Unlock()

// (1) check exist(NameID)
bool_ret, err := iidRWLock.IsExistIID(iidm.IIDSGROUP, connectionName, rsType, reqInfo.IId)
if err != nil {
Expand All @@ -938,6 +939,25 @@ func CreateVPC(connectionName string, rsType string, reqInfo cres.VPCReqInfo) (*
return nil, err
}

// check the Cloud Connection has the VPC already, when the CSP supports only 1 VPC.
drv, err := ccm.GetCloudDriver(connectionName)
if err != nil {
cblog.Error(err)
return nil, err
}
if (drv.GetDriverCapability().SINGLE_VPC == true) {
list_ret, err := iidRWLock.ListIID(iidm.IIDSGROUP, connectionName, rsType)
if err != nil {
cblog.Error(err)
return nil, err
}
if list_ret != nil && len(list_ret) > 0 {
err := fmt.Errorf(rsType + "-" + connectionName + " can have only 1 VPC, but already have a VPC " + list_ret[0].IId.NameId)
cblog.Error(err)
return nil, err
}
}

// (2) generate SP-XID and create reqIID, driverIID
// ex) SP-XID {"vm-01-9m4e2mr0ui3e8a215n4g"}
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func (ClouditDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
drvCapabilityInfo.PublicIPHandler = false
drvCapabilityInfo.VMHandler = true

drvCapabilityInfo.SINGLE_VPC = true

return drvCapabilityInfo
}

Expand Down
6 changes: 4 additions & 2 deletions cloud-control-manager/cloud-driver/interfaces/CloudDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
)

type DriverCapabilityInfo struct {
FIXED_SUBNET_CIDR bool // support: true, do not support: false
VPC_CIDR bool // support: true, do not support: false
ImageHandler bool // support: true, do not support: false
VPCHandler bool // support: true, do not support: false
//VNetworkHandler bool // support: true, do not support: false
Expand All @@ -26,6 +24,10 @@ type DriverCapabilityInfo struct {
PublicIPHandler bool // support: true, do not support: false
VMHandler bool // support: true, do not support: false
VMSpecHandler bool // support: true, do not support: false

FIXED_SUBNET_CIDR bool // support: true, do not support: false
VPC_CIDR bool // support: true, do not support: false
SINGLE_VPC bool // support: true, do not support: false
}

type CredentialInfo struct {
Expand Down

0 comments on commit bb56508

Please sign in to comment.