-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: region/sync openstack routetables
- Loading branch information
lvyangyang
committed
Jul 9, 2020
1 parent
dd90c7c
commit eac0a79
Showing
5 changed files
with
228 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters