mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #7139 from lvyangyang/fix_openstack_routeble
fix:修复路由表映射到public网络的问题
This commit is contained in:
@@ -17,6 +17,7 @@ package openstack
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -554,6 +555,13 @@ func (region *SRegion) GetRouters() ([]SRouter, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "resp.Unmarshal")
|
||||
}
|
||||
for i := 0; i < len(routers); i++ {
|
||||
ports, err := region.GetPortsByDeviceId(routers[i].ID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "vpc.region.GetPortsByDeviceId")
|
||||
}
|
||||
routers[i].ports = ports
|
||||
}
|
||||
return routers, nil
|
||||
}
|
||||
|
||||
@@ -568,3 +576,15 @@ func (region *SRegion) fetchrouters() error {
|
||||
region.routers = routers
|
||||
return nil
|
||||
}
|
||||
|
||||
func (region *SRegion) GetPortsByDeviceId(routerId string) ([]SPort, error) {
|
||||
query := url.Values{}
|
||||
query.Set("device_id", routerId)
|
||||
_, resp, err := region.Get("network", "/v2.0/ports?"+query.Encode(), "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "region.Get routes")
|
||||
}
|
||||
ports := []SPort{}
|
||||
return ports, resp.Unmarshal(&ports, "ports")
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ type SConntrackHelper struct {
|
||||
Port int `json:"port"`
|
||||
}
|
||||
type SRouter struct {
|
||||
ports []SPort
|
||||
AdminStateUp bool `json:"admin_state_up"`
|
||||
Description string `json:"description"`
|
||||
FlavorID string `json:"flavor_id"`
|
||||
|
||||
@@ -35,7 +35,7 @@ func (route *SRouteEntry) GetCidr() string {
|
||||
}
|
||||
|
||||
func (route *SRouteEntry) GetNextHopType() string {
|
||||
return ""
|
||||
return route.Nexthop
|
||||
}
|
||||
|
||||
func (route *SRouteEntry) GetNextHop() string {
|
||||
|
||||
@@ -64,6 +64,9 @@ type SVpc struct {
|
||||
VlanTransparent bool
|
||||
Fescription string
|
||||
IsDefault bool
|
||||
NetworkType string `json:"provider:network_type"`
|
||||
PhysicalNetwork string `json:"provider:physical_network"`
|
||||
SegmentationId string `json:"provider:segmentation_id"`
|
||||
}
|
||||
|
||||
func (vpc *SVpc) GetMetadata() *jsonutils.JSONDict {
|
||||
@@ -133,22 +136,27 @@ func (vpc *SVpc) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, erro
|
||||
}
|
||||
|
||||
func (vpc *SVpc) GetIRouteTables() ([]cloudprovider.ICloudRouteTable, error) {
|
||||
if vpc.PhysicalNetwork == "public" {
|
||||
return []cloudprovider.ICloudRouteTable{}, nil
|
||||
}
|
||||
err := vpc.region.fetchrouters()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "vpc.region.fetchrouters()")
|
||||
}
|
||||
routeTables := []SRouteTable{}
|
||||
for index, router := range vpc.region.routers {
|
||||
if router.ExternalGatewayInfo.NetworkID == vpc.GetId() {
|
||||
|
||||
if len(router.Routes) < 1 {
|
||||
continue
|
||||
if len(router.Routes) < 1 {
|
||||
continue
|
||||
}
|
||||
for _, port := range router.ports {
|
||||
if port.NetworkID == vpc.GetId() {
|
||||
routeTable := SRouteTable{}
|
||||
routeTable.entries = router.Routes
|
||||
routeTable.router = &vpc.region.routers[index]
|
||||
routeTable.vpc = vpc
|
||||
routeTables = append(routeTables, routeTable)
|
||||
break
|
||||
}
|
||||
routeTable := SRouteTable{}
|
||||
routeTable.entries = router.Routes
|
||||
routeTable.router = &vpc.region.routers[index]
|
||||
routeTable.vpc = vpc
|
||||
routeTables = append(routeTables, routeTable)
|
||||
}
|
||||
}
|
||||
ret := []cloudprovider.ICloudRouteTable{}
|
||||
|
||||
Reference in New Issue
Block a user