Merge "Add attribute support to create zone cli"

This commit is contained in:
Jenkins
2017-02-01 16:28:43 +00:00
committed by Gerrit Code Review
2 changed files with 20 additions and 1 deletions

View File

@@ -31,6 +31,10 @@ LOG = logging.getLogger(__name__)
def _format_zone(zone): def _format_zone(zone):
zone.pop('links', None) zone.pop('links', None)
zone['masters'] = ", ".join(zone['masters']) 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): 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('--ttl', type=int, help="Time To Live (Seconds)")
parser.add_argument('--description', help="Description") parser.add_argument('--description', help="Description")
parser.add_argument('--masters', help="Zone Masters", nargs='+') parser.add_argument('--masters', help="Zone Masters", nargs='+')
parser.add_argument('--attributes', help="Zone Attributes", nargs='+')
common.add_all_common_options(parser) common.add_all_common_options(parser)
@@ -145,6 +150,17 @@ class CreateZoneCommand(command.ShowOne):
if parsed_args.description: if parsed_args.description:
payload["description"] = 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': if parsed_args.type == 'PRIMARY':
# email is just for PRIMARY. # email is just for PRIMARY.
if not parsed_args.email: if not parsed_args.email:

View File

@@ -19,7 +19,7 @@ from designateclient.v2 import utils as v2_utils
class ZoneController(V2Controller): class ZoneController(V2Controller):
def create(self, name, type_=None, email=None, description=None, ttl=None, def create(self, name, type_=None, email=None, description=None, ttl=None,
masters=None): masters=None, attributes=None):
type_ = type_ or "PRIMARY" type_ = type_ or "PRIMARY"
data = { data = {
@@ -40,6 +40,9 @@ class ZoneController(V2Controller):
if description is not None: if description is not None:
data["description"] = description data["description"] = description
if attributes is not None:
data["attributes"] = attributes
return self._post('/zones', data=data) return self._post('/zones', data=data)
def list(self, criterion=None, marker=None, limit=None): def list(self, criterion=None, marker=None, limit=None):