summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-02-03 21:00:48 +0000
committerGerrit Code Review <review@openstack.org>2016-02-03 21:00:48 +0000
commit66df8d1413004bbb2d225ff199767dab8696fd45 (patch)
tree839670ee446f995e017201adfe8efb8da374284d /openstackclient
parentca1eeaf207e701ba54e5fb7e5a5e2ec77e4fc7d7 (diff)
parentc0d2120883080ba1a4326dc97e078d95de170a51 (diff)
downloadpython-openstackclient-66df8d1413004bbb2d225ff199767dab8696fd45.tar.gz
Merge "Add availability zone support for router commands"
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/router.py17
-rw-r--r--openstackclient/tests/network/v2/fakes.py2
-rw-r--r--openstackclient/tests/network/v2/test_router.py28
3 files changed, 47 insertions, 0 deletions
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py
index 6c8acb63..c31df8a3 100644
--- a/openstackclient/network/v2/router.py
+++ b/openstackclient/network/v2/router.py
@@ -35,6 +35,8 @@ def _format_external_gateway_info(info):
_formatters = {
'admin_state_up': _format_admin_state,
'external_gateway_info': _format_external_gateway_info,
+ 'availability_zones': utils.format_list,
+ 'availability_zone_hints': utils.format_list,
}
@@ -46,6 +48,9 @@ def _get_attrs(client_manager, parsed_args):
attrs['admin_state_up'] = parsed_args.admin_state_up
if parsed_args.distributed is not None:
attrs['distributed'] = parsed_args.distributed
+ if ('availability_zone_hints' in parsed_args
+ and parsed_args.availability_zone_hints is not None):
+ attrs['availability_zone_hints'] = parsed_args.availability_zone_hints
# "router set" command doesn't support setting project.
if 'project' in parsed_args and parsed_args.project is not None:
identity_client = client_manager.identity
@@ -99,6 +104,16 @@ class CreateRouter(command.ShowOne):
metavar='<poroject>',
help="Owner's project (name or ID)",
)
+ parser.add_argument(
+ '--availability-zone-hint',
+ metavar='<availability-zone>',
+ action='append',
+ dest='availability_zone_hints',
+ help='Availability Zone in which to create this router '
+ '(requires the Router Availability Zone extension, '
+ 'this option can be repeated).',
+ )
+
identity_common.add_project_domain_option_to_parser(parser)
return parser
@@ -176,10 +191,12 @@ class ListRouter(command.Lister):
columns = columns + (
'routes',
'external_gateway_info',
+ 'availability_zones'
)
column_headers = column_headers + (
'Routes',
'External gateway info',
+ 'Availability zones'
)
data = client.routers()
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py
index 4c862bd3..95c5aca6 100644
--- a/openstackclient/tests/network/v2/fakes.py
+++ b/openstackclient/tests/network/v2/fakes.py
@@ -263,6 +263,8 @@ class FakeRouter(object):
'tenant_id': 'project-id-' + uuid.uuid4().hex,
'routes': [],
'external_gateway_info': {},
+ 'availability_zone_hints': [],
+ 'availability_zones': [],
}
# Overwrite default attributes.
diff --git a/openstackclient/tests/network/v2/test_router.py b/openstackclient/tests/network/v2/test_router.py
index fba6e192..98e9f17a 100644
--- a/openstackclient/tests/network/v2/test_router.py
+++ b/openstackclient/tests/network/v2/test_router.py
@@ -14,6 +14,7 @@
import mock
from openstackclient.common import exceptions
+from openstackclient.common import utils as osc_utils
from openstackclient.network.v2 import router
from openstackclient.tests.network.v2 import fakes as network_fakes
from openstackclient.tests import utils as tests_utils
@@ -88,6 +89,31 @@ class TestCreateRouter(TestRouter):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
+ def test_create_with_AZ_hints(self):
+ arglist = [
+ self.new_router.name,
+ '--availability-zone-hint', 'fake-az',
+ '--availability-zone-hint', 'fake-az2',
+ ]
+ verifylist = [
+ ('name', self.new_router.name),
+ ('availability_zone_hints', ['fake-az', 'fake-az2']),
+ ('admin_state_up', True),
+ ('distributed', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = (self.cmd.take_action(parsed_args))
+ self.network.create_router.assert_called_with(**{
+ 'admin_state_up': True,
+ 'name': self.new_router.name,
+ 'distributed': False,
+ 'availability_zone_hints': ['fake-az', 'fake-az2'],
+ })
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
class TestDeleteRouter(TestRouter):
@@ -135,6 +161,7 @@ class TestListRouter(TestRouter):
columns_long = columns + (
'Routes',
'External gateway info',
+ 'Availability zones'
)
data = []
@@ -155,6 +182,7 @@ class TestListRouter(TestRouter):
data[i] + (
r.routes,
router._format_external_gateway_info(r.external_gateway_info),
+ osc_utils.format_list(r.availability_zones),
)
)