From f265eb18e95a707d99fe4d52a856c6e661b9982f Mon Sep 17 00:00:00 2001 From: Graham Hayes Date: Tue, 31 Jan 2017 23:00:38 +0000 Subject: [PATCH] Add attribute support to create zone cli also format attributes for cli display Change-Id: Ia338f607e6d4b70610132ab66e15381981beb038 --- designateclient/v2/cli/zones.py | 16 ++++++++++++++++ designateclient/v2/zones.py | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/designateclient/v2/cli/zones.py b/designateclient/v2/cli/zones.py index 40c64c9..3782652 100644 --- a/designateclient/v2/cli/zones.py +++ b/designateclient/v2/cli/zones.py @@ -31,6 +31,10 @@ LOG = logging.getLogger(__name__) def _format_zone(zone): zone.pop('links', None) zone['masters'] = ", ".join(zone['masters']) + attrib = '' + for attr in zone['attributes']: + attrib += "%s:%s\n" % (attr, zone['attributes'][attr]) + zone['attributes'] = attrib def _format_zone_export_record(zone_export_record): @@ -131,6 +135,7 @@ class CreateZoneCommand(command.ShowOne): parser.add_argument('--ttl', type=int, help="Time To Live (Seconds)") parser.add_argument('--description', help="Description") parser.add_argument('--masters', help="Zone Masters", nargs='+') + parser.add_argument('--attributes', help="Zone Attributes", nargs='+') common.add_all_common_options(parser) @@ -145,6 +150,17 @@ class CreateZoneCommand(command.ShowOne): if parsed_args.description: payload["description"] = parsed_args.description + if parsed_args.attributes: + payload["attributes"] = {} + for attr in parsed_args.attributes: + try: + k, v = attr.split(':') + payload["attributes"][k] = v + except ValueError: + msg = "Attribute '%s' is in an incorrect format. "\ + "Attributes are : formated" + raise osc_exc.CommandError(msg % attr) + if parsed_args.type == 'PRIMARY': # email is just for PRIMARY. if not parsed_args.email: diff --git a/designateclient/v2/zones.py b/designateclient/v2/zones.py index c960da7..7e862a7 100644 --- a/designateclient/v2/zones.py +++ b/designateclient/v2/zones.py @@ -19,7 +19,7 @@ from designateclient.v2 import utils as v2_utils class ZoneController(V2Controller): def create(self, name, type_=None, email=None, description=None, ttl=None, - masters=None): + masters=None, attributes=None): type_ = type_ or "PRIMARY" data = { @@ -40,6 +40,9 @@ class ZoneController(V2Controller): if description is not None: data["description"] = description + if attributes is not None: + data["attributes"] = attributes + return self._post('/zones', data=data) def list(self, criterion=None, marker=None, limit=None):