From 063c722a110031883e9615064092644de6df8da2 Mon Sep 17 00:00:00 2001 From: reedip Date: Fri, 15 Apr 2016 15:27:18 +0900 Subject: Add command to unset information from Subnet-pools This patch introduces the ``subnet pool unset`` command to clear the pool prefix information from the subnet-pools. Change-Id: I84b7259d6e26e695343d41cea6d807396faaf69a Implements: blueprint network-property-unset --- openstackclient/network/v2/subnet_pool.py | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'openstackclient/network') diff --git a/openstackclient/network/v2/subnet_pool.py b/openstackclient/network/v2/subnet_pool.py index 55dfed83..ed2bb0ef 100644 --- a/openstackclient/network/v2/subnet_pool.py +++ b/openstackclient/network/v2/subnet_pool.py @@ -12,6 +12,7 @@ # """Subnet pool action implementations""" +import copy import logging @@ -337,3 +338,43 @@ class ShowSubnetPool(command.ShowOne): columns = _get_columns(obj) data = utils.get_item_properties(obj, columns, formatters=_formatters) return (columns, data) + + +class UnsetSubnetPool(command.Command): + """Unset subnet pool properties""" + + def get_parser(self, prog_name): + parser = super(UnsetSubnetPool, self).get_parser(prog_name) + parser.add_argument( + '--pool-prefix', + metavar='', + action='append', + dest='prefixes', + help=_('Remove subnet pool prefixes (in CIDR notation). ' + '(repeat option to unset multiple prefixes).'), + ) + parser.add_argument( + 'subnet_pool', + metavar="", + help=_("Subnet pool to modify (name or ID)") + ) + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.network + obj = client.find_subnet_pool( + parsed_args.subnet_pool, ignore_missing=False) + tmp_prefixes = copy.deepcopy(obj.prefixes) + attrs = {} + if parsed_args.prefixes: + for prefix in parsed_args.prefixes: + try: + tmp_prefixes.remove(prefix) + except ValueError: + msg = _( + "Subnet pool does not " + "contain prefix %s") % prefix + raise exceptions.CommandError(msg) + attrs['prefixes'] = tmp_prefixes + if attrs: + client.update_subnet_pool(obj, **attrs) -- cgit v1.2.1