summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/floating_ip.py8
-rw-r--r--openstackclient/network/v2/port.py29
-rw-r--r--openstackclient/network/v2/router.py13
-rw-r--r--openstackclient/network/v2/subnet.py30
-rw-r--r--openstackclient/tests/functional/identity/v3/test_project.py2
-rw-r--r--openstackclient/tests/unit/network/v2/fakes.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_floating_ip.py9
-rw-r--r--openstackclient/tests/unit/network/v2/test_port.py44
-rw-r--r--openstackclient/tests/unit/network/v2/test_router.py7
-rw-r--r--openstackclient/tests/unit/network/v2/test_subnet.py33
10 files changed, 159 insertions, 18 deletions
diff --git a/openstackclient/network/v2/floating_ip.py b/openstackclient/network/v2/floating_ip.py
index 454335f1..bb75540c 100644
--- a/openstackclient/network/v2/floating_ip.py
+++ b/openstackclient/network/v2/floating_ip.py
@@ -55,6 +55,9 @@ def _get_attrs(client_manager, parsed_args):
if parsed_args.fixed_ip_address:
attrs['fixed_ip_address'] = parsed_args.fixed_ip_address
+ if parsed_args.description is not None:
+ attrs['description'] = parsed_args.description
+
return attrs
@@ -97,6 +100,11 @@ class CreateFloatingIP(common.NetworkAndComputeShowOne):
dest='fixed_ip_address',
help=_("Fixed IP address mapped to the floating IP")
)
+ parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_('Set floating IP description')
+ )
return parser
def take_action_network(self, client, parsed_args):
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 0df78e43..92b286a9 100644
--- a/openstackclient/network/v2/port.py
+++ b/openstackclient/network/v2/port.py
@@ -109,7 +109,6 @@ def _get_attrs(client_manager, parsed_args):
'The --host-id option is deprecated, '
'please use --host instead.'
))
-
if parsed_args.fixed_ip is not None:
attrs['fixed_ips'] = parsed_args.fixed_ip
if parsed_args.device:
@@ -428,8 +427,7 @@ class SetPort(command.Command):
metavar="<name>",
help=_("Set port name")
)
- fixed_ip = parser.add_mutually_exclusive_group()
- fixed_ip.add_argument(
+ parser.add_argument(
'--fixed-ip',
metavar='subnet=<subnet>,ip-address=<ip-address>',
action=parseractions.MultiKeyValueAction,
@@ -438,13 +436,14 @@ class SetPort(command.Command):
"subnet=<subnet>,ip-address=<ip-address> "
"(repeat option to set multiple fixed IP addresses)")
)
- fixed_ip.add_argument(
+ parser.add_argument(
'--no-fixed-ip',
action='store_true',
- help=_("Clear existing information of fixed IP addresses")
+ help=_("Clear existing information of fixed IP addresses."
+ "Specify both --fixed-ip and --no-fixed-ip "
+ "to overwrite the current fixed IP addresses.")
)
- binding_profile = parser.add_mutually_exclusive_group()
- binding_profile.add_argument(
+ parser.add_argument(
'--binding-profile',
metavar='<binding-profile>',
action=JSONKeyValueAction,
@@ -452,10 +451,12 @@ class SetPort(command.Command):
"be passed as <key>=<value> or JSON. "
"(repeat option to set multiple binding:profile data)")
)
- binding_profile.add_argument(
+ parser.add_argument(
'--no-binding-profile',
action='store_true',
- help=_("Clear existing information of binding:profile")
+ help=_("Clear existing information of binding:profile."
+ "Specify both --binding-profile and --no-binding-profile "
+ "to overwrite the current binding:profile information.")
)
parser.add_argument(
'port',
@@ -471,7 +472,11 @@ class SetPort(command.Command):
attrs = _get_attrs(self.app.client_manager, parsed_args)
obj = client.find_port(parsed_args.port, ignore_missing=False)
if 'binding:profile' in attrs:
- attrs['binding:profile'].update(obj.binding_profile)
+ # Do not modify attrs if both binding_profile/no_binding given
+ if not parsed_args.no_binding_profile:
+ tmp_binding_profile = copy.deepcopy(obj.binding_profile)
+ tmp_binding_profile.update(attrs['binding:profile'])
+ attrs['binding:profile'] = tmp_binding_profile
elif parsed_args.no_binding_profile:
attrs['binding:profile'] = {}
if 'fixed_ips' in attrs:
@@ -480,7 +485,9 @@ class SetPort(command.Command):
# would therefore add an empty dictionary, while we need
# to append the attrs['fixed_ips'] iff there is some info
# in the obj.fixed_ips. Therefore I have opted for this `for` loop
- attrs['fixed_ips'] += [ip for ip in obj.fixed_ips if ip]
+ # Do not modify attrs if fixed_ip/no_fixed_ip given
+ if not parsed_args.no_fixed_ip:
+ attrs['fixed_ips'] += [ip for ip in obj.fixed_ips if ip]
elif parsed_args.no_fixed_ip:
attrs['fixed_ips'] = []
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py
index 03134b8c..cb40d774 100644
--- a/openstackclient/network/v2/router.py
+++ b/openstackclient/network/v2/router.py
@@ -82,7 +82,8 @@ def _get_attrs(client_manager, parsed_args):
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
-
+ if parsed_args.description is not None:
+ attrs['description'] = parsed_args.description
# "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
@@ -180,6 +181,11 @@ class CreateRouter(command.ShowOne):
help=_("Create a distributed router")
)
parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_('Set router description')
+ )
+ parser.add_argument(
'--project',
metavar='<project>',
help=_("Owner's project (name or ID)")
@@ -370,6 +376,11 @@ class SetRouter(command.Command):
metavar='<name>',
help=_("Set router name")
)
+ parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_('Set router description')
+ )
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(
'--enable',
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py
index 76453487..2021d9f0 100644
--- a/openstackclient/network/v2/subnet.py
+++ b/openstackclient/network/v2/subnet.py
@@ -57,7 +57,7 @@ _formatters = {
}
-def _get_common_parse_arguments(parser):
+def _get_common_parse_arguments(parser, is_create=True):
parser.add_argument(
'--allocation-pool',
metavar='start=<ip-address>,end=<ip-address>',
@@ -68,6 +68,14 @@ def _get_common_parse_arguments(parser):
"e.g.: start=192.168.199.2,end=192.168.199.254 "
"(repeat option to add multiple IP addresses)")
)
+ if not is_create:
+ parser.add_argument(
+ '--no-allocation-pool',
+ action='store_true',
+ help=_("Clear associated allocation-pools from the subnet. "
+ "Specify both --allocation-pool and --no-allocation-pool "
+ "to overwrite the current allocation pool information.")
+ )
parser.add_argument(
'--dns-nameserver',
metavar='<dns-nameserver>',
@@ -88,6 +96,14 @@ def _get_common_parse_arguments(parser):
"gateway: nexthop IP address "
"(repeat option to add multiple routes)")
)
+ if not is_create:
+ parser.add_argument(
+ '--no-host-route',
+ action='store_true',
+ help=_("Clear associated host-routes from the subnet. "
+ "Specify both --host-route and --no-host-route "
+ "to overwrite the current host route information.")
+ )
parser.add_argument(
'--service-type',
metavar='<service-type>',
@@ -508,7 +524,7 @@ class SetSubnet(command.Command):
metavar='<description>',
help=_("Set subnet description")
)
- _get_common_parse_arguments(parser)
+ _get_common_parse_arguments(parser, is_create=False)
return parser
def take_action(self, parsed_args):
@@ -519,9 +535,15 @@ class SetSubnet(command.Command):
if 'dns_nameservers' in attrs:
attrs['dns_nameservers'] += obj.dns_nameservers
if 'host_routes' in attrs:
- attrs['host_routes'] += obj.host_routes
+ if not parsed_args.no_host_route:
+ attrs['host_routes'] += obj.host_routes
+ elif parsed_args.no_host_route:
+ attrs['host_routes'] = ''
if 'allocation_pools' in attrs:
- attrs['allocation_pools'] += obj.allocation_pools
+ if not parsed_args.no_allocation_pool:
+ attrs['allocation_pools'] += obj.allocation_pools
+ elif parsed_args.no_allocation_pool:
+ attrs['allocation_pools'] = ''
if 'service_types' in attrs:
attrs['service_types'] += obj.service_types
client.update_subnet(obj, **attrs)
diff --git a/openstackclient/tests/functional/identity/v3/test_project.py b/openstackclient/tests/functional/identity/v3/test_project.py
index 77438841..5639dc16 100644
--- a/openstackclient/tests/functional/identity/v3/test_project.py
+++ b/openstackclient/tests/functional/identity/v3/test_project.py
@@ -66,7 +66,7 @@ class ProjectTests(common.IdentityTests):
items = self.parse_listing(raw_output)
self.assert_table_structure(items, common.BASIC_LIST_HEADERS)
self.assertIn(project_name, raw_output)
- self.assertTrue(len(items) > 0)
+ self.assertGreater(len(items), 0)
def test_project_set(self):
project_name = self._create_dummy_project()
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index 91aebf9f..d7ebd0bc 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -654,6 +654,7 @@ class FakeRouter(object):
'name': 'router-name-' + uuid.uuid4().hex,
'status': 'ACTIVE',
'admin_state_up': True,
+ 'description': 'router-description-' + uuid.uuid4().hex,
'distributed': False,
'ha': False,
'tenant_id': 'project-id-' + uuid.uuid4().hex,
@@ -973,6 +974,7 @@ class FakeFloatingIP(object):
'router_id': 'router-id-' + uuid.uuid4().hex,
'port_id': 'port-id-' + uuid.uuid4().hex,
'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ 'description': 'floating-ip-description-' + uuid.uuid4().hex,
}
# Overwrite default attributes.
diff --git a/openstackclient/tests/unit/network/v2/test_floating_ip.py b/openstackclient/tests/unit/network/v2/test_floating_ip.py
index a77fb24b..1f30f2e9 100644
--- a/openstackclient/tests/unit/network/v2/test_floating_ip.py
+++ b/openstackclient/tests/unit/network/v2/test_floating_ip.py
@@ -49,6 +49,7 @@ class TestCreateFloatingIPNetwork(TestFloatingIPNetwork):
)
columns = (
+ 'description',
'dns_domain',
'dns_name',
'fixed_ip_address',
@@ -62,6 +63,7 @@ class TestCreateFloatingIPNetwork(TestFloatingIPNetwork):
)
data = (
+ floating_ip.description,
floating_ip.dns_domain,
floating_ip.dns_name,
floating_ip.fixed_ip_address,
@@ -117,14 +119,16 @@ class TestCreateFloatingIPNetwork(TestFloatingIPNetwork):
'--port', self.floating_ip.port_id,
'--floating-ip-address', self.floating_ip.floating_ip_address,
'--fixed-ip-address', self.floating_ip.fixed_ip_address,
+ '--description', self.floating_ip.description,
self.floating_ip.floating_network_id,
]
verifylist = [
('subnet', self.subnet.id),
('port', self.floating_ip.port_id),
- ('floating_ip_address', self.floating_ip.floating_ip_address),
('fixed_ip_address', self.floating_ip.fixed_ip_address),
('network', self.floating_ip.floating_network_id),
+ ('description', self.floating_ip.description),
+ ('floating_ip_address', self.floating_ip.floating_ip_address),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -136,6 +140,7 @@ class TestCreateFloatingIPNetwork(TestFloatingIPNetwork):
'floating_ip_address': self.floating_ip.floating_ip_address,
'fixed_ip_address': self.floating_ip.fixed_ip_address,
'floating_network_id': self.floating_ip.floating_network_id,
+ 'description': self.floating_ip.description,
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
@@ -269,6 +274,7 @@ class TestShowFloatingIPNetwork(TestFloatingIPNetwork):
floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip()
columns = (
+ 'description',
'dns_domain',
'dns_name',
'fixed_ip_address',
@@ -282,6 +288,7 @@ class TestShowFloatingIPNetwork(TestFloatingIPNetwork):
)
data = (
+ floating_ip.description,
floating_ip.dns_domain,
floating_ip.dns_name,
floating_ip.fixed_ip_address,
diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py
index 271e8160..a2aceab1 100644
--- a/openstackclient/tests/unit/network/v2/test_port.py
+++ b/openstackclient/tests/unit/network/v2/test_port.py
@@ -494,6 +494,50 @@ class TestSetPort(TestPort):
self.network.update_port.assert_called_once_with(_testport, **attrs)
self.assertIsNone(result)
+ def test_overwrite_binding_profile(self):
+ _testport = network_fakes.FakePort.create_one_port(
+ {'binding_profile': {'lok_i': 'visi_on'}})
+ self.network.find_port = mock.Mock(return_value=_testport)
+ arglist = [
+ '--binding-profile', 'lok_i=than_os',
+ '--no-binding-profile',
+ _testport.name,
+ ]
+ verifylist = [
+ ('binding_profile', {'lok_i': 'than_os'}),
+ ('no_binding_profile', True)
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+ attrs = {
+ 'binding:profile':
+ {'lok_i': 'than_os'},
+ }
+ self.network.update_port.assert_called_once_with(_testport, **attrs)
+ self.assertIsNone(result)
+
+ def test_overwrite_fixed_ip(self):
+ _testport = network_fakes.FakePort.create_one_port(
+ {'fixed_ips': [{'ip_address': '0.0.0.1'}]})
+ self.network.find_port = mock.Mock(return_value=_testport)
+ arglist = [
+ '--fixed-ip', 'ip-address=10.0.0.12',
+ '--no-fixed-ip',
+ _testport.name,
+ ]
+ verifylist = [
+ ('fixed_ip', [{'ip-address': '10.0.0.12'}]),
+ ('no_fixed_ip', True)
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+ attrs = {
+ 'fixed_ips': [
+ {'ip_address': '10.0.0.12'}],
+ }
+ self.network.update_port.assert_called_once_with(_testport, **attrs)
+ self.assertIsNone(result)
+
def test_set_this(self):
arglist = [
'--disable',
diff --git a/openstackclient/tests/unit/network/v2/test_router.py b/openstackclient/tests/unit/network/v2/test_router.py
index 5ed969b4..d12289e1 100644
--- a/openstackclient/tests/unit/network/v2/test_router.py
+++ b/openstackclient/tests/unit/network/v2/test_router.py
@@ -118,6 +118,7 @@ class TestCreateRouter(TestRouter):
'admin_state_up',
'availability_zone_hints',
'availability_zones',
+ 'description',
'distributed',
'external_gateway_info',
'ha',
@@ -131,6 +132,7 @@ class TestCreateRouter(TestRouter):
router._format_admin_state(new_router.admin_state_up),
osc_utils.format_list(new_router.availability_zone_hints),
osc_utils.format_list(new_router.availability_zones),
+ new_router.description,
new_router.distributed,
router._format_external_gateway_info(new_router.external_gateway_info),
new_router.ha,
@@ -502,12 +504,14 @@ class TestSetRouter(TestRouter):
'--enable',
'--distributed',
'--name', 'noob',
+ '--description', 'router',
]
verifylist = [
('router', self._router.name),
('enable', True),
('distributed', True),
('name', 'noob'),
+ ('description', 'router'),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -517,6 +521,7 @@ class TestSetRouter(TestRouter):
'admin_state_up': True,
'distributed': True,
'name': 'noob',
+ 'description': 'router',
}
self.network.update_router.assert_called_once_with(
self._router, **attrs)
@@ -680,6 +685,7 @@ class TestShowRouter(TestRouter):
'admin_state_up',
'availability_zone_hints',
'availability_zones',
+ 'description',
'distributed',
'external_gateway_info',
'ha',
@@ -693,6 +699,7 @@ class TestShowRouter(TestRouter):
router._format_admin_state(_router.admin_state_up),
osc_utils.format_list(_router.availability_zone_hints),
osc_utils.format_list(_router.availability_zones),
+ _router.description,
_router.distributed,
router._format_external_gateway_info(_router.external_gateway_info),
_router.ha,
diff --git a/openstackclient/tests/unit/network/v2/test_subnet.py b/openstackclient/tests/unit/network/v2/test_subnet.py
index 58506391..9c468f39 100644
--- a/openstackclient/tests/unit/network/v2/test_subnet.py
+++ b/openstackclient/tests/unit/network/v2/test_subnet.py
@@ -938,6 +938,39 @@ class TestSetSubnet(TestSubnet):
self.network.update_subnet.assert_called_with(self._subnet, **attrs)
self.assertIsNone(result)
+ def test_overwrite_options(self):
+ _testsubnet = network_fakes.FakeSubnet.create_one_subnet(
+ {'host_routes': [{'destination': '10.20.20.0/24',
+ 'nexthop': '10.20.20.1'}],
+ 'allocation_pools': [{'start': '8.8.8.200',
+ 'end': '8.8.8.250'}], })
+ self.network.find_subnet = mock.Mock(return_value=_testsubnet)
+ arglist = [
+ '--host-route', 'destination=10.30.30.30/24,gateway=10.30.30.1',
+ '--no-host-route',
+ '--allocation-pool', 'start=8.8.8.100,end=8.8.8.150',
+ '--no-allocation-pool',
+ _testsubnet.name,
+ ]
+ verifylist = [
+ ('host_routes', [{
+ "destination": "10.30.30.30/24", "gateway": "10.30.30.1"}]),
+ ('allocation_pools', [{
+ 'start': '8.8.8.100', 'end': '8.8.8.150'}]),
+ ('no_host_route', True),
+ ('no_allocation_pool', True),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+ attrs = {
+ 'host_routes': [{
+ "destination": "10.30.30.30/24", "nexthop": "10.30.30.1"}],
+ 'allocation_pools': [{'start': '8.8.8.100', 'end': '8.8.8.150'}],
+ }
+ self.network.update_subnet.assert_called_once_with(
+ _testsubnet, **attrs)
+ self.assertIsNone(result)
+
class TestShowSubnet(TestSubnet):
# The subnets to be shown