osc, bgpvpn: add support for 'local_pref' BGPVPN attribute

This change adds support for the 'local_pref' attribute of
the BGPVPN resource.

Change-Id: I330a18212d4d68faf79ef5a16e304bc3406ce7ff
Partially-Implements: blueprint routes-control
This commit is contained in:
Thomas Morin
2018-01-19 10:56:38 +01:00
parent 0e61b3ba1c
commit 288aa63756
3 changed files with 16 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ _attr_map = (
('routers', 'Associated Routers', nc_osc_utils.LIST_LONG_ONLY),
('ports', 'Associated Ports', nc_osc_utils.LIST_LONG_ONLY),
('vni', 'VNI', nc_osc_utils.LIST_LONG_ONLY),
('local_pref', 'Local Pref', nc_osc_utils.LIST_LONG_ONLY),
)
_formatters = {
'route_targets': format_columns.ListColumn,
@@ -151,6 +152,11 @@ def _get_common_parser(parser, update=None):
'--vni', type=int,
help=_('VXLAN Network Identifier to be used for this BGPVPN '
'when a VXLAN encapsulation is used'))
parser.add_argument(
'--local-pref', type=int,
dest='local_pref',
help=_('Default BGP LOCAL_PREF to use in route advertisements'
'towards this BGPVPN.'))
def _args2body(client_manager, id, action, args):
@@ -169,6 +175,9 @@ def _args2body(client_manager, id, action, args):
if 'vni' in args and args.vni is not None:
attrs['vni'] = args.vni
if 'local_pref' in args and args.local_pref is not None:
attrs['local_pref'] = args.local_pref
if args.purge_route_target:
attrs['route_targets'] = []
elif args.route_targets:
@@ -247,6 +256,8 @@ class CreateBgpvpn(command.ShowOne):
attrs['route_distinguishers'] = parsed_args.route_distinguishers
if parsed_args.vni is not None:
attrs['vni'] = parsed_args.vni
if parsed_args.local_pref is not None:
attrs['local_pref'] = parsed_args.local_pref
if 'project' in parsed_args and parsed_args.project is not None:
project_id = nc_osc_utils.find_project(
self.app.client_manager.identity,

View File

@@ -77,6 +77,7 @@ class FakeBgpvpn(object):
'routers': [],
'ports': [],
'vni': 100,
'local_pref': 777,
}
# Overwrite default attributes.

View File

@@ -64,6 +64,7 @@ class TestCreateBgpvpn(fakes.TestNeutronClientBgpvpn):
('name', None),
('type', 'l3'),
('vni', None),
('local_pref', None),
('route_targets', None),
('import_targets', None),
('export_targets', None),
@@ -85,6 +86,7 @@ class TestCreateBgpvpn(fakes.TestNeutronClientBgpvpn):
'name': 'fake_name',
'type': 'l2',
'vni': 100,
'local_pref': 777,
'route_targets': ['fake_rt1', 'fake_rt2', 'fake_rt3'],
'import_targets': ['fake_irt1', 'fake_irt2', 'fake_irt3'],
'export_targets': ['fake_ert1', 'fake_ert2', 'fake_ert3'],
@@ -98,6 +100,7 @@ class TestCreateBgpvpn(fakes.TestNeutronClientBgpvpn):
'--name', fake_bgpvpn['name'],
'--type', fake_bgpvpn['type'],
'--vni', str(fake_bgpvpn['vni']),
'--local-pref', str(fake_bgpvpn['local_pref']),
]
for rt in fake_bgpvpn['route_targets']:
arglist.extend(['--route-target', rt])
@@ -112,6 +115,7 @@ class TestCreateBgpvpn(fakes.TestNeutronClientBgpvpn):
('name', fake_bgpvpn['name']),
('type', fake_bgpvpn['type']),
('vni', fake_bgpvpn['vni']),
('local_pref', fake_bgpvpn['local_pref']),
('route_targets', fake_bgpvpn['route_targets']),
('import_targets', fake_bgpvpn['import_targets']),
('export_targets', fake_bgpvpn['export_targets']),