mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
add: region/sync openstack routetables
This commit is contained in:
@@ -40,6 +40,7 @@ type SRegion struct {
|
||||
ivpcs []cloudprovider.ICloudVpc
|
||||
|
||||
storageCache *SStoragecache
|
||||
routers []SRouter
|
||||
}
|
||||
|
||||
func (region *SRegion) GetILoadBalancerBackendGroups() ([]cloudprovider.ICloudLoadbalancerBackendGroup, error) {
|
||||
@@ -542,3 +543,28 @@ func (region *SRegion) CreateISecurityGroup(conf *cloudprovider.SecurityGroupCre
|
||||
func (region *SRegion) GetCapabilities() []string {
|
||||
return region.client.GetCapabilities()
|
||||
}
|
||||
|
||||
func (region *SRegion) GetRouters() ([]SRouter, error) {
|
||||
_, resp, err := region.Get("network", "/v2.0/routers", "", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "region.Get routes")
|
||||
}
|
||||
routers := []SRouter{}
|
||||
err = resp.Unmarshal(&routers, "routers")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "resp.Unmarshal")
|
||||
}
|
||||
return routers, nil
|
||||
}
|
||||
|
||||
func (region *SRegion) fetchrouters() error {
|
||||
if len(region.routers) > 0 {
|
||||
return nil
|
||||
}
|
||||
routers, err := region.GetRouters()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "region.GetRouters()")
|
||||
}
|
||||
region.routers = routers
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package openstack
|
||||
|
||||
type SExternalFixedIP struct {
|
||||
IPAddress string `json:"ip_address"`
|
||||
SubnetID string `json:"subnet_id"`
|
||||
}
|
||||
type SExternalGatewayInfo struct {
|
||||
EnableSnat bool `json:"enable_snat"`
|
||||
ExtrernalFiedIps []SExternalFixedIP `json:"external_fixed_ips"`
|
||||
NetworkID string `json:"network_id"`
|
||||
}
|
||||
|
||||
type SConntrackHelper struct {
|
||||
Protocol string `json:"protocol"`
|
||||
Helper string `json:"helper"`
|
||||
Port int `json:"port"`
|
||||
}
|
||||
type SRouter struct {
|
||||
AdminStateUp bool `json:"admin_state_up"`
|
||||
Description string `json:"description"`
|
||||
FlavorID string `json:"flavor_id"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Routes []SRouteEntry `json:"routes"`
|
||||
Status string `json:"status"`
|
||||
ProjectID string `json:"project_id"`
|
||||
TenantID string `json:"tenant_id"`
|
||||
Tags []string `json:"tags"`
|
||||
ConntrackHelpers []SConntrackHelper `json:"conntrack_helpers"`
|
||||
ExternalGatewayInfo SExternalGatewayInfo `json:"external_gateway_info"`
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package openstack
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
type SRouteEntry struct {
|
||||
Destination string `json:"destination"`
|
||||
Nexthop string `json:"nexthop"`
|
||||
}
|
||||
|
||||
func (route *SRouteEntry) GetType() string {
|
||||
return api.ROUTE_ENTRY_TYPE_CUSTOM
|
||||
}
|
||||
|
||||
func (route *SRouteEntry) GetCidr() string {
|
||||
return route.Destination
|
||||
}
|
||||
|
||||
func (route *SRouteEntry) GetNextHopType() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (route *SRouteEntry) GetNextHop() string {
|
||||
return route.Nexthop
|
||||
}
|
||||
|
||||
type SRouteTable struct {
|
||||
vpc *SVpc
|
||||
entries []SRouteEntry
|
||||
router *SRouter
|
||||
}
|
||||
|
||||
func (self *SRouteTable) GetDescription() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SRouteTable) GetId() string {
|
||||
return self.GetGlobalId()
|
||||
}
|
||||
|
||||
func (self *SRouteTable) GetGlobalId() string {
|
||||
return self.router.ID
|
||||
}
|
||||
|
||||
func (self *SRouteTable) GetName() string {
|
||||
return self.router.Name
|
||||
}
|
||||
|
||||
func (self *SRouteTable) GetMetadata() *jsonutils.JSONDict {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SRouteTable) GetRegionId() string {
|
||||
return self.vpc.region.GetId()
|
||||
}
|
||||
|
||||
func (self *SRouteTable) GetType() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SRouteTable) GetVpcId() string {
|
||||
return self.vpc.GetId()
|
||||
}
|
||||
|
||||
func (self *SRouteTable) GetIRoutes() ([]cloudprovider.ICloudRoute, error) {
|
||||
ret := []cloudprovider.ICloudRoute{}
|
||||
for index := range self.entries {
|
||||
ret = append(ret, &self.entries[index])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *SRouteTable) GetStatus() string {
|
||||
return self.router.Status
|
||||
}
|
||||
|
||||
func (self *SRouteTable) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SRouteTable) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package shell
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/multicloud/openstack"
|
||||
"yunion.io/x/onecloud/pkg/util/shellutils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type RouterListOptions struct {
|
||||
}
|
||||
shellutils.R(&RouterListOptions{}, "router-list", "List routers", func(cli *openstack.SRegion, args *RouterListOptions) error {
|
||||
routers, err := cli.GetRouters()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
printList(routers, 0, 0, 0, nil)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -133,8 +133,29 @@ func (vpc *SVpc) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, erro
|
||||
}
|
||||
|
||||
func (vpc *SVpc) GetIRouteTables() ([]cloudprovider.ICloudRouteTable, error) {
|
||||
rts := []cloudprovider.ICloudRouteTable{}
|
||||
return rts, 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
|
||||
}
|
||||
routeTable := SRouteTable{}
|
||||
routeTable.entries = router.Routes
|
||||
routeTable.router = &vpc.region.routers[index]
|
||||
routeTable.vpc = vpc
|
||||
routeTables = append(routeTables, routeTable)
|
||||
}
|
||||
}
|
||||
ret := []cloudprovider.ICloudRouteTable{}
|
||||
for i := range routeTables {
|
||||
ret = append(ret, &routeTables[i])
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (vpc *SVpc) fetchWires() error {
|
||||
|
||||
Reference in New Issue
Block a user