Merge "SDK Refactor: Prepare ip availability commands"
This commit is contained in:
commit
a9be7a6c73
@ -18,7 +18,7 @@ from osc_lib import utils
|
||||
|
||||
from openstackclient.i18n import _
|
||||
from openstackclient.identity import common as identity_common
|
||||
|
||||
from openstackclient.network import sdk_utils
|
||||
|
||||
_formatters = {
|
||||
'subnet_ip_availability': utils.format_list_of_dicts,
|
||||
@ -26,13 +26,14 @@ _formatters = {
|
||||
|
||||
|
||||
def _get_columns(item):
|
||||
columns = list(item.keys())
|
||||
if 'tenant_id' in columns:
|
||||
columns.remove('tenant_id')
|
||||
columns.append('project_id')
|
||||
return tuple(sorted(columns))
|
||||
column_map = {
|
||||
'tenant_id': 'project_id',
|
||||
}
|
||||
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
|
||||
|
||||
|
||||
# TODO(ankur-gupta-f): Use the SDK resource mapped attribute names once
|
||||
# the OSC minimum requirements include SDK 1.0.
|
||||
class ListIPAvailability(command.Lister):
|
||||
_description = _("List IP availability for network")
|
||||
|
||||
@ -84,6 +85,7 @@ class ListIPAvailability(command.Lister):
|
||||
parsed_args.project_domain,
|
||||
).id
|
||||
filters['tenant_id'] = project_id
|
||||
filters['project_id'] = project_id
|
||||
data = client.network_ip_availabilities(**filters)
|
||||
return (column_headers,
|
||||
(utils.get_item_properties(
|
||||
@ -107,6 +109,6 @@ class ShowIPAvailability(command.ShowOne):
|
||||
client = self.app.client_manager.network
|
||||
obj = client.find_network_ip_availability(parsed_args.network,
|
||||
ignore_missing=False)
|
||||
columns = _get_columns(obj)
|
||||
display_columns, columns = _get_columns(obj)
|
||||
data = utils.get_item_properties(obj, columns, formatters=_formatters)
|
||||
return (columns, data)
|
||||
return (display_columns, data)
|
||||
|
@ -194,15 +194,18 @@ class FakeIPAvailability(object):
|
||||
"""Fake one or more network ip availabilities."""
|
||||
|
||||
@staticmethod
|
||||
def create_one_ip_availability():
|
||||
def create_one_ip_availability(attrs=None):
|
||||
"""Create a fake list with ip availability stats of a network.
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object with network_name, network_id, etc.
|
||||
"""
|
||||
attrs = attrs or {}
|
||||
|
||||
# Set default attributes.
|
||||
network_ip_availability = {
|
||||
network_ip_attrs = {
|
||||
'network_id': 'network-id-' + uuid.uuid4().hex,
|
||||
'network_name': 'network-name-' + uuid.uuid4().hex,
|
||||
'tenant_id': '',
|
||||
@ -210,10 +213,13 @@ class FakeIPAvailability(object):
|
||||
'total_ips': 254,
|
||||
'used_ips': 6,
|
||||
}
|
||||
network_ip_attrs.update(attrs)
|
||||
|
||||
network_ip_availability = fakes.FakeResource(
|
||||
info=copy.deepcopy(network_ip_availability),
|
||||
info=copy.deepcopy(network_ip_attrs),
|
||||
loaded=True)
|
||||
network_ip_availability.project_id = network_ip_attrs['tenant_id']
|
||||
|
||||
return network_ip_availability
|
||||
|
||||
@staticmethod
|
||||
|
@ -107,6 +107,7 @@ class TestListIPAvailability(TestIPAvailability):
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
filters = {'tenant_id': self.project.id,
|
||||
'project_id': self.project.id,
|
||||
'ip_version': 4}
|
||||
|
||||
self.network.network_ip_availabilities.assert_called_once_with(
|
||||
|
Loading…
x
Reference in New Issue
Block a user