Skip to content

Commit

Permalink
Update site-to-site VPN
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot authored Oct 23, 2024
2 parents 984773f + 821c43c commit 0143e32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/api/rest/server/infra/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,26 @@ func ExtractSitesInfoFromMciInfo(nsId, mciId string) (*networkSiteModel.SitesInf

// Get the last subnet
subnetCount := len(vNetInfo.SubnetInfoList)
if subnetCount == 0 {
log.Warn().Msgf("No subnets found for VNet ID: %s", vNetId)
continue
}
lastSubnet := vNetInfo.SubnetInfoList[subnetCount-1]
lastSubnetIdFromCSP := lastSubnet.CspResourceId

// Set VNet and the last subnet IDs
site.VNet = vm.CspVNetId
site.Subnet = lastSubnetIdFromCSP
site.Subnet = lastSubnet.CspResourceId

sitesInAws = append(sitesInAws, site)

case "azure":
// Parse vNet and resource group names
parts := strings.Split(vm.CspVNetId, "/")
log.Debug().Msgf("parts: %+v", parts)
if len(parts) < 9 {
log.Warn().Msgf("Invalid VNet ID format for Azure VM ID: %s", vm.Id)
continue
}
parsedResourceGroupName := parts[4]
parsedVirtualNetworkName := parts[8]

Expand All @@ -174,6 +181,10 @@ func ExtractSitesInfoFromMciInfo(nsId, mciId string) (*networkSiteModel.SitesInf

// Get the last subnet CIDR block
subnetCount := len(vNetInfo.SubnetInfoList)
if subnetCount == 0 {
log.Warn().Msgf("No subnets found for VNet ID: %s", vNetId)
continue
}
lastSubnet := vNetInfo.SubnetInfoList[subnetCount-1]
lastSubnetCidr := lastSubnet.IPv4_CIDR

Expand Down
6 changes: 3 additions & 3 deletions src/api/rest/server/model/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ var ProviderNames = map[string]string{

// SiteDetail struct represents the structure for detailed site information
type SiteDetail struct {
CSP string `json:"csp" example:"aws"`
Region string `json:"region" example:"ap-northeast-2"`
Zone string `json:"zone,omitempty" example:"ap-northeast-2a"`
CSP string `json:"csp" example:"aws"`
Region string `json:"region" example:"ap-northeast-2"`
// Zone string `json:"zone,omitempty" example:"ap-northeast-2a"`
VNet string `json:"vnet" example:"vpc-xxxxx"`
Subnet string `json:"subnet,omitempty" example:"subnet-xxxxx"`
GatewaySubnetCidr string `json:"gatewaySubnetCidr,omitempty" example:"xxx.xxx.xxx.xxx/xx"`
Expand Down
6 changes: 4 additions & 2 deletions src/core/resource/vnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func CreateVNet(nsId string, vNetReq *model.TbVNetReq) (model.TbVNetInfo, error)
})
}

log.Debug().Msgf("vNetInfo: %+v", vNetInfo)
log.Debug().Msgf("vNetInfo(initial): %+v", vNetInfo)

// Set a vNetKey for the vNet object
vNetKey := common.GenResourceKey(nsId, resourceType, vNetInfo.Id)
Expand Down Expand Up @@ -541,7 +541,7 @@ func CreateVNet(nsId string, vNetReq *model.TbVNetReq) (model.TbVNetInfo, error)
log.Warn().Msgf("The status of the vNet (%s) is unknown", vNetInfo.Id)
}

log.Debug().Msgf("vNetInfo: %+v", vNetInfo)
log.Debug().Msgf("vNetInfo(filled): %+v", vNetInfo)

// Store vNet object into the key-value store
value, err := json.Marshal(vNetInfo)
Expand Down Expand Up @@ -684,6 +684,8 @@ func GetVNet(nsId string, vNetId string) (model.TbVNetInfo, error) {
return emptyRet, err
}

log.Debug().Msgf("vNetInfo: %+v", vNetInfo)

/*
* Get vNet info
*/
Expand Down

0 comments on commit 0143e32

Please sign in to comment.