summaryrefslogtreecommitdiff
path: root/openstackclient/network
diff options
context:
space:
mode:
authorreedip <reedip.banerjee@nectechnologies.in>2016-04-14 18:11:52 +0900
committerReedip <reedip.banerjee@nectechnologies.in>2016-06-27 10:41:13 +0000
commited64788cf1a247ca03174770d43d8c7816cc0ad1 (patch)
treee813b11f9e747770d129d20fa553ac4c14540ed3 /openstackclient/network
parent7cda2b2a066cd45c7aeb9a6d92c1a83e49d48128 (diff)
downloadpython-openstackclient-ed64788cf1a247ca03174770d43d8c7816cc0ad1.tar.gz
Add command to unset information from Routers
This patch introduces the ``router unset`` command to clear the routing information from the routers. Implements: blueprint network-property-unset Change-Id: Iac8d32ca42fb28878805b4b58ab411b67fa6555b
Diffstat (limited to 'openstackclient/network')
-rw-r--r--openstackclient/network/v2/router.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py
index 6271a878..8a09543f 100644
--- a/openstackclient/network/v2/router.py
+++ b/openstackclient/network/v2/router.py
@@ -14,6 +14,7 @@
"""Router action implementations"""
import argparse
+import copy
import json
import logging
@@ -462,3 +463,45 @@ class ShowRouter(command.ShowOne):
columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters)
return (columns, data)
+
+
+class UnsetRouter(command.Command):
+ """Unset router properties"""
+
+ def get_parser(self, prog_name):
+ parser = super(UnsetRouter, self).get_parser(prog_name)
+ parser.add_argument(
+ '--route',
+ metavar='destination=<subnet>,gateway=<ip-address>',
+ action=parseractions.MultiKeyValueAction,
+ dest='routes',
+ default=None,
+ required_keys=['destination', 'gateway'],
+ help=_("Routes to be removed from the router "
+ "destination: destination subnet (in CIDR notation) "
+ "gateway: nexthop IP address "
+ "(repeat option to unset multiple routes)"))
+ parser.add_argument(
+ 'router',
+ metavar="<router>",
+ help=_("Router to modify (name or ID)")
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ client = self.app.client_manager.network
+ obj = client.find_router(parsed_args.router, ignore_missing=False)
+ tmp_routes = copy.deepcopy(obj.routes)
+ attrs = {}
+ if parsed_args.routes:
+ try:
+ for route in parsed_args.routes:
+ tmp_routes.remove(route)
+ except ValueError:
+ msg = (_("Router does not contain route %s") % route)
+ raise exceptions.CommandError(msg)
+ for route in tmp_routes:
+ route['nexthop'] = route.pop('gateway')
+ attrs['routes'] = tmp_routes
+ if attrs:
+ client.update_router(obj, **attrs)