summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/image/v2/image.py2
-rw-r--r--openstackclient/network/v2/floating_ip.py11
-rw-r--r--openstackclient/network/v2/port.py11
-rw-r--r--openstackclient/tests/unit/image/v2/test_image.py3
-rw-r--r--openstackclient/tests/unit/network/v2/test_floating_ip_network.py57
-rw-r--r--openstackclient/tests/unit/network/v2/test_port.py18
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume.py2
-rw-r--r--openstackclient/volume/v2/volume.py16
8 files changed, 100 insertions, 20 deletions
diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py
index 4c7c815f..5c7d32d4 100644
--- a/openstackclient/image/v2/image.py
+++ b/openstackclient/image/v2/image.py
@@ -585,7 +585,7 @@ class ListImage(command.Lister):
property_field='properties',
)
- data = utils.sort_items(data, parsed_args.sort)
+ data = utils.sort_items(data, parsed_args.sort, str)
return (
column_headers,
diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py
index 1bb2c069..958480a5 100644
--- a/openstackclient/network/v2/floating_ip.py
+++ b/openstackclient/network/v2/floating_ip.py
@@ -347,11 +347,10 @@ class SetFloatingIP(command.Command):
parser.add_argument(
'floating_ip',
metavar='<floating-ip>',
- help=_("Floating IP to associate (IP address or ID)"))
+ help=_("Floating IP to modify (IP address or ID)"))
parser.add_argument(
'--port',
metavar='<port>',
- required=True,
help=_("Associate the floating IP with port (name or ID)")),
parser.add_argument(
'--fixed-ip-address',
@@ -383,9 +382,11 @@ class SetFloatingIP(command.Command):
parsed_args.floating_ip,
ignore_missing=False,
)
- port = client.find_port(parsed_args.port,
- ignore_missing=False)
- attrs['port_id'] = port.id
+ if parsed_args.port:
+ port = client.find_port(parsed_args.port,
+ ignore_missing=False)
+ attrs['port_id'] = port.id
+
if parsed_args.fixed_ip_address:
attrs['fixed_ip_address'] = parsed_args.fixed_ip_address
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index f13ee7b9..af6efa9d 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -215,6 +215,9 @@ def _prepare_filter_fixed_ips(client_manager, parsed_args):
if 'ip-address' in ip_spec:
ips.append('ip_address=%s' % ip_spec['ip-address'])
+
+ if 'ip-substring' in ip_spec:
+ ips.append('ip_address_substr=%s' % ip_spec['ip-substring'])
return ips
@@ -531,11 +534,13 @@ class ListPort(command.Lister):
identity_common.add_project_domain_option_to_parser(parser)
parser.add_argument(
'--fixed-ip',
- metavar='subnet=<subnet>,ip-address=<ip-address>',
+ metavar=('subnet=<subnet>,ip-address=<ip-address>,'
+ 'ip-substring=<ip-substring>'),
action=parseractions.MultiKeyValueAction,
- optional_keys=['subnet', 'ip-address'],
+ optional_keys=['subnet', 'ip-address', 'ip-substring'],
help=_("Desired IP and/or subnet for filtering ports "
- "(name or ID): subnet=<subnet>,ip-address=<ip-address> "
+ "(name or ID): subnet=<subnet>,ip-address=<ip-address>,"
+ "ip-substring=<ip-substring> "
"(repeat option to set multiple fixed IP addresses)"),
)
_tag.add_tag_filtering_option_to_parser(parser, _('ports'))
diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py
index b769d1f6..e7cd34c3 100644
--- a/openstackclient/tests/unit/image/v2/test_image.py
+++ b/openstackclient/tests/unit/image/v2/test_image.py
@@ -708,7 +708,8 @@ class TestImageList(TestImage):
)
si_mock.assert_called_with(
[self._image],
- 'name:asc'
+ 'name:asc',
+ str,
)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip_network.py b/openstackclient/tests/unit/network/v2/test_floating_ip_network.py
index 65d87377..822d3ae8 100644
--- a/openstackclient/tests/unit/network/v2/test_floating_ip_network.py
+++ b/openstackclient/tests/unit/network/v2/test_floating_ip_network.py
@@ -747,6 +747,31 @@ class TestSetFloatingIP(TestFloatingIPNetwork):
self.network.update_ip.assert_called_once_with(
self.floating_ip, **attrs)
+ def test_qos_policy_option(self):
+ qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
+ self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
+ arglist = [
+ "--qos-policy", qos_policy.id,
+ self.floating_ip.id,
+ ]
+ verifylist = [
+ ('qos_policy', qos_policy.id),
+ ('floating_ip', self.floating_ip.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.cmd.take_action(parsed_args)
+
+ attrs = {
+ 'qos_policy_id': qos_policy.id,
+ }
+ self.network.find_ip.assert_called_once_with(
+ self.floating_ip.id,
+ ignore_missing=False,
+ )
+ self.network.update_ip.assert_called_once_with(
+ self.floating_ip, **attrs)
+
def test_port_and_qos_policy_option(self):
qos_policy = network_fakes.FakeNetworkQosPolicy.create_one_qos_policy()
self.network.find_qos_policy = mock.Mock(return_value=qos_policy)
@@ -775,6 +800,29 @@ class TestSetFloatingIP(TestFloatingIPNetwork):
self.network.update_ip.assert_called_once_with(
self.floating_ip, **attrs)
+ def test_no_qos_policy_option(self):
+ arglist = [
+ "--no-qos-policy",
+ self.floating_ip.id,
+ ]
+ verifylist = [
+ ('no_qos_policy', True),
+ ('floating_ip', self.floating_ip.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.cmd.take_action(parsed_args)
+
+ attrs = {
+ 'qos_policy_id': None,
+ }
+ self.network.find_ip.assert_called_once_with(
+ self.floating_ip.id,
+ ignore_missing=False,
+ )
+ self.network.update_ip.assert_called_once_with(
+ self.floating_ip, **attrs)
+
def test_port_and_no_qos_policy_option(self):
arglist = [
"--no-qos-policy",
@@ -810,16 +858,13 @@ class TestSetFloatingIP(TestFloatingIPNetwork):
arglist = ['--no-tag']
verifylist = [('no_tag', True)]
expected_args = []
- arglist.extend(['--port', self.floating_ip.port_id,
- self.floating_ip.id])
- verifylist.extend([
- ('port', self.floating_ip.port_id),
- ('floating_ip', self.floating_ip.id)])
+ arglist.extend([self.floating_ip.id])
+ verifylist.extend([('floating_ip', self.floating_ip.id)])
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
- self.assertTrue(self.network.update_ip.called)
+ self.assertFalse(self.network.update_ip.called)
self.network.set_tags.assert_called_once_with(
self.floating_ip,
tests_utils.CompareBySet(expected_args))
diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py
index 03e1d841..78d7fd6c 100644
--- a/openstackclient/tests/unit/network/v2/test_port.py
+++ b/openstackclient/tests/unit/network/v2/test_port.py
@@ -867,6 +867,24 @@ class TestListPort(TestPort):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, list(data))
+ def test_port_list_fixed_ip_opt_ip_address_substr(self):
+ ip_address_ss = self._ports[0].fixed_ips[0]['ip_address'][:-1]
+ arglist = [
+ '--fixed-ip', "ip-substring=%s" % ip_address_ss,
+ ]
+ verifylist = [
+ ('fixed_ip', [{'ip-substring': ip_address_ss}])
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.ports.assert_called_once_with(**{
+ 'fixed_ips': ['ip_address_substr=%s' % ip_address_ss]})
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, list(data))
+
def test_port_list_fixed_ip_opt_subnet_id(self):
subnet_id = self._ports[0].fixed_ips[0]['subnet_id']
arglist = [
diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py
index 2fa924b8..304aa91c 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume.py
@@ -430,7 +430,7 @@ class TestVolumeCreate(TestVolume):
columns, data = self.cmd.take_action(parsed_args)
self.volumes_mock.create.assert_called_once_with(
- size=None,
+ size=snapshot.size,
snapshot_id=snapshot.id,
name=self.new_volume.name,
description=None,
diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py
index 61f846b0..ee3d2f20 100644
--- a/openstackclient/volume/v2/volume.py
+++ b/openstackclient/volume/v2/volume.py
@@ -186,11 +186,21 @@ class CreateVolume(command.ShowOne):
image_client.images,
parsed_args.image).id
+ size = parsed_args.size
+
snapshot = None
if parsed_args.snapshot:
- snapshot = utils.find_resource(
+ snapshot_obj = utils.find_resource(
volume_client.volume_snapshots,
- parsed_args.snapshot).id
+ parsed_args.snapshot)
+ snapshot = snapshot_obj.id
+ # Cinder requires a value for size when creating a volume
+ # even if creating from a snapshot. Cinder will create the
+ # volume with at least the same size as the snapshot anyway,
+ # so since we have the object here, just override the size
+ # value if it's either not given or is smaller than the
+ # snapshot size.
+ size = max(size or 0, snapshot_obj.size)
project = None
if parsed_args.project:
@@ -205,7 +215,7 @@ class CreateVolume(command.ShowOne):
parsed_args.user).id
volume = volume_client.volumes.create(
- size=parsed_args.size,
+ size=size,
snapshot_id=snapshot,
name=parsed_args.name,
description=parsed_args.description,