| 1 |
# Copyright (c) 2016 Juniper networks Inc. |
| 2 |
# All Rights Reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
# |
| 16 |
|
| 17 |
from osc_lib.utils import columns as column_util |
| 18 |
|
| 19 |
from neutronclient._i18n import _ |
| 20 |
from neutronclient.osc.v2.networking_bgpvpn import constants |
| 21 |
from neutronclient.osc.v2.networking_bgpvpn.resource_association import\ |
| 22 |
CreateBgpvpnResAssoc |
| 23 |
from neutronclient.osc.v2.networking_bgpvpn.resource_association import\ |
| 24 |
DeleteBgpvpnResAssoc |
| 25 |
from neutronclient.osc.v2.networking_bgpvpn.resource_association import\ |
| 26 |
ListBgpvpnResAssoc |
| 27 |
from neutronclient.osc.v2.networking_bgpvpn.resource_association import\ |
| 28 |
SetBgpvpnResAssoc |
| 29 |
from neutronclient.osc.v2.networking_bgpvpn.resource_association import\ |
| 30 |
ShowBgpvpnResAssoc |
| 31 |
from neutronclient.osc.v2.networking_bgpvpn.resource_association import\ |
| 32 |
UnsetBgpvpnResAssoc |
| 33 |
|
| 34 |
|
| 35 |
class BgpvpnRouterAssoc(object): |
| 36 |
_assoc_res_name = constants.ROUTER_RESOURCE_NAME |
| 37 |
_resource = constants.ROUTER_ASSOC |
| 38 |
_resource_plural = constants.ROUTER_ASSOCS |
| 39 |
|
| 40 |
_attr_map = ( |
| 41 |
('id', 'ID', column_util.LIST_BOTH), |
| 42 |
('tenant_id', 'Project', column_util.LIST_LONG_ONLY), |
| 43 |
('%s_id' % _assoc_res_name, '%s ID' % _assoc_res_name.capitalize(), |
| 44 |
column_util.LIST_BOTH), |
| 45 |
('advertise_extra_routes', 'Advertise extra routes', |
| 46 |
column_util.LIST_LONG_ONLY), |
| 47 |
) |
| 48 |
_formatters = {} |
| 49 |
|
| 50 |
def _get_common_parser(self, parser): |
| 51 |
"""Adds to parser arguments common to create, set and unset commands. |
| 52 |
|
| 53 |
:params ArgumentParser parser: argparse object contains all command's |
| 54 |
arguments |
| 55 |
""" |
| 56 |
ADVERTISE_ROUTES = _("Routes will be advertised to the " |
| 57 |
"BGP VPN%s") % ( |
| 58 |
_(' (default)') if self._action == 'create' |
| 59 |
else "") |
| 60 |
NOT_ADVERTISE_ROUTES = _("Routes from the router will not be " |
| 61 |
"advertised to the BGP VPN") |
| 62 |
|
| 63 |
group_advertise_extra_routes = parser.add_mutually_exclusive_group() |
| 64 |
group_advertise_extra_routes.add_argument( |
| 65 |
'--advertise_extra_routes', |
| 66 |
action='store_true', |
| 67 |
help=NOT_ADVERTISE_ROUTES if self._action == 'unset' |
| 68 |
else ADVERTISE_ROUTES, |
| 69 |
) |
| 70 |
group_advertise_extra_routes.add_argument( |
| 71 |
'--no-advertise_extra_routes', |
| 72 |
action='store_true', |
| 73 |
help=ADVERTISE_ROUTES if self._action == 'unset' |
| 74 |
else NOT_ADVERTISE_ROUTES, |
| 75 |
) |
| 76 |
|
| 77 |
def _args2body(self, _, args): |
| 78 |
attrs = {'advertise_extra_routes': False} |
| 79 |
if args.advertise_extra_routes: |
| 80 |
attrs['advertise_extra_routes'] = self._action != 'unset' |
| 81 |
elif args.no_advertise_extra_routes: |
| 82 |
attrs['advertise_extra_routes'] = self._action == 'unset' |
| 83 |
|
| 84 |
return attrs |
| 85 |
|
| 86 |
|
| 87 |
class CreateBgpvpnRouterAssoc(BgpvpnRouterAssoc, CreateBgpvpnResAssoc): |
| 88 |
_description = _("Create a BGP VPN router association") |
| 89 |
pass |
| 90 |
|
| 91 |
|
| 92 |
class SetBgpvpnRouterAssoc(BgpvpnRouterAssoc, SetBgpvpnResAssoc): |
| 93 |
_description = _("Set BGP VPN router association properties") |
| 94 |
|
| 95 |
|
| 96 |
class UnsetBgpvpnRouterAssoc(BgpvpnRouterAssoc, UnsetBgpvpnResAssoc): |
| 97 |
_description = _("Unset BGP VPN router association properties") |
| 98 |
|
| 99 |
|
| 100 |
class DeleteBgpvpnRouterAssoc(BgpvpnRouterAssoc, DeleteBgpvpnResAssoc): |
| 101 |
_description = _("Delete a BGP VPN router association(s) for a given BGP " |
| 102 |
"VPN") |
| 103 |
pass |
| 104 |
|
| 105 |
|
| 106 |
class ListBgpvpnRouterAssoc(BgpvpnRouterAssoc, ListBgpvpnResAssoc): |
| 107 |
_description = _("List BGP VPN router associations for a given BGP VPN") |
| 108 |
pass |
| 109 |
|
| 110 |
|
| 111 |
class ShowBgpvpnRouterAssoc(BgpvpnRouterAssoc, ShowBgpvpnResAssoc): |
| 112 |
_description = _("Show information of a given BGP VPN router association") |
| 113 |
pass |