Add attribute support to create zone cli

also format attributes for cli display

Change-Id: Ia338f607e6d4b70610132ab66e15381981beb038
This commit is contained in:
Graham Hayes 2017-01-31 23:00:38 +00:00
parent fad4e0ff58
commit f265eb18e9
2 changed files with 20 additions and 1 deletions

View File

@ -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 <key>:<value> formated"
raise osc_exc.CommandError(msg % attr)
if parsed_args.type == 'PRIMARY':
# email is just for PRIMARY.
if not parsed_args.email:

View File

@ -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):