summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorTerry Howe <terrylhowe@gmail.com>2015-12-10 14:58:16 -0700
committerTerry Howe <terrylhowe@gmail.com>2015-12-10 15:22:38 -0700
commit1cf320302bee2e406ed7189d3cf3d08542770637 (patch)
treeb466f7c1823815cb435fb07f7bf9fcfe3fc34bc6 /openstackclient
parent823ba770e0baafa707c89723c576db060b1b4742 (diff)
downloadpython-openstackclient-1cf320302bee2e406ed7189d3cf3d08542770637.tar.gz
Map some of the SDK field names
The keys() method returns the keys returned from Neutron, but the SDK maps some things like tenant_id to project_id. This makes the output a little prettier. Change-Id: Ibd8c890b61ffc94021f93fc1051fcf5dabd1e9ea
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/network.py19
-rw-r--r--openstackclient/tests/network/v2/fakes.py5
-rw-r--r--openstackclient/tests/network/v2/test_network.py14
3 files changed, 26 insertions, 12 deletions
diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py
index 519356b4..6b2062dd 100644
--- a/openstackclient/network/v2/network.py
+++ b/openstackclient/network/v2/network.py
@@ -39,6 +39,17 @@ _formatters = {
}
+def _get_columns(item):
+ columns = item.keys()
+ if 'tenant_id' in columns:
+ columns.remove('tenant_id')
+ columns.append('project_id')
+ if 'router:external' in columns:
+ columns.remove('router:external')
+ columns.append('router_external')
+ return tuple(sorted(columns))
+
+
class CreateNetwork(show.ShowOne):
"""Create new network"""
@@ -91,9 +102,9 @@ class CreateNetwork(show.ShowOne):
client = self.app.client_manager.network
body = self.get_body(parsed_args)
obj = client.create_network(**body)
- columns = sorted(obj.keys())
+ columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
- return (tuple(columns), data)
+ return (columns, data)
def get_body(self, parsed_args):
body = {'name': str(parsed_args.name),
@@ -292,6 +303,6 @@ class ShowNetwork(show.ShowOne):
self.log.debug('take_action(%s)' % parsed_args)
client = self.app.client_manager.network
obj = client.find_network(parsed_args.identifier, ignore_missing=False)
- columns = sorted(obj.keys())
+ columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
- return (tuple(columns), data)
+ return (columns, data)
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py
index abb88ee4..0e601a72 100644
--- a/openstackclient/tests/network/v2/fakes.py
+++ b/openstackclient/tests/network/v2/fakes.py
@@ -73,11 +73,12 @@ class FakeNetwork(object):
router_external, status, subnets, tenant_id
"""
# Set default attributes.
+ project_id = 'project-id-' + uuid.uuid4().hex
network_attrs = {
'id': 'network-id-' + uuid.uuid4().hex,
'name': 'network-name-' + uuid.uuid4().hex,
'status': 'ACTIVE',
- 'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ 'tenant_id': project_id,
'admin_state_up': True,
'shared': False,
'subnets': ['a', 'b'],
@@ -101,6 +102,8 @@ class FakeNetwork(object):
network = fakes.FakeResource(info=copy.deepcopy(network_attrs),
methods=copy.deepcopy(network_methods),
loaded=True)
+ network.project_id = project_id
+
return network
@staticmethod
diff --git a/openstackclient/tests/network/v2/test_network.py b/openstackclient/tests/network/v2/test_network.py
index e8651492..df61b0db 100644
--- a/openstackclient/tests/network/v2/test_network.py
+++ b/openstackclient/tests/network/v2/test_network.py
@@ -44,20 +44,20 @@ class TestCreateNetworkIdentityV3(TestNetwork):
'admin_state_up',
'id',
'name',
+ 'project_id',
'router_external',
'status',
'subnets',
- 'tenant_id',
)
data = (
network._format_admin_state(_network.admin_state_up),
_network.id,
_network.name,
+ _network.project_id,
network._format_router_external(_network.router_external),
_network.status,
utils.format_list(_network.subnets),
- _network.tenant_id,
)
def setUp(self):
@@ -176,20 +176,20 @@ class TestCreateNetworkIdentityV2(TestNetwork):
'admin_state_up',
'id',
'name',
+ 'project_id',
'router_external',
'status',
'subnets',
- 'tenant_id',
)
data = (
network._format_admin_state(_network.admin_state_up),
_network.id,
_network.name,
+ _network.project_id,
network._format_router_external(_network.router_external),
_network.status,
utils.format_list(_network.subnets),
- _network.tenant_id,
)
def setUp(self):
@@ -330,7 +330,7 @@ class TestListNetwork(TestNetwork):
net.id,
net.name,
net.status,
- net.tenant_id,
+ net.project_id,
network._format_admin_state(net.admin_state_up),
net.shared,
utils.format_list(net.subnets),
@@ -475,20 +475,20 @@ class TestShowNetwork(TestNetwork):
'admin_state_up',
'id',
'name',
+ 'project_id',
'router_external',
'status',
'subnets',
- 'tenant_id',
)
data = (
network._format_admin_state(_network.admin_state_up),
_network.id,
_network.name,
+ _network.project_id,
network._format_router_external(_network.router_external),
_network.status,
utils.format_list(_network.subnets),
- _network.tenant_id,
)
def setUp(self):