2012-11-28 13:28:14 +00:00
|
|
|
# Copyright 2012 Managed I.T.
|
|
|
|
#
|
|
|
|
# Author: Kiall Mac Innes <kiall@managedit.ie>
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
2013-12-16 15:41:51 +01:00
|
|
|
|
2012-11-28 13:28:14 +00:00
|
|
|
import logging
|
2013-12-16 15:41:51 +01:00
|
|
|
|
2013-06-09 21:18:36 +01:00
|
|
|
from designateclient.cli import base
|
|
|
|
from designateclient.v1.records import Record
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class ListRecordsCommand(base.ListCommand):
|
2014-07-10 21:54:50 +02:00
|
|
|
"""List Records"""
|
2012-11-28 13:28:14 +00:00
|
|
|
|
2014-04-16 18:58:59 +10:00
|
|
|
columns = ['id', 'type', 'name', 'data']
|
2013-04-11 12:50:28 +01:00
|
|
|
|
2012-11-28 13:28:14 +00:00
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(ListRecordsCommand, self).get_parser(prog_name)
|
|
|
|
|
|
|
|
parser.add_argument('domain_id', help="Domain ID")
|
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def execute(self, parsed_args):
|
|
|
|
return self.client.records.list(parsed_args.domain_id)
|
|
|
|
|
|
|
|
|
|
|
|
class GetRecordCommand(base.GetCommand):
|
2014-07-10 21:54:50 +02:00
|
|
|
"""Get Record"""
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(GetRecordCommand, self).get_parser(prog_name)
|
|
|
|
|
|
|
|
parser.add_argument('domain_id', help="Domain ID")
|
|
|
|
parser.add_argument('id', help="Record ID")
|
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def execute(self, parsed_args):
|
|
|
|
return self.client.records.get(parsed_args.domain_id, parsed_args.id)
|
|
|
|
|
|
|
|
|
|
|
|
class CreateRecordCommand(base.CreateCommand):
|
2014-07-10 21:54:50 +02:00
|
|
|
"""Create Record"""
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(CreateRecordCommand, self).get_parser(prog_name)
|
|
|
|
|
|
|
|
parser.add_argument('domain_id', help="Domain ID")
|
|
|
|
parser.add_argument('--name', help="Record Name", required=True)
|
|
|
|
parser.add_argument('--type', help="Record Type", required=True)
|
|
|
|
parser.add_argument('--data', help="Record Data", required=True)
|
|
|
|
parser.add_argument('--ttl', type=int, help="Record TTL")
|
2012-12-29 19:21:25 +00:00
|
|
|
parser.add_argument('--priority', type=int, help="Record Priority")
|
2013-10-30 18:22:54 +00:00
|
|
|
parser.add_argument('--description', help="Description")
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def execute(self, parsed_args):
|
|
|
|
record = Record(
|
|
|
|
name=parsed_args.name,
|
|
|
|
type=parsed_args.type,
|
|
|
|
data=parsed_args.data,
|
|
|
|
)
|
|
|
|
|
2012-12-14 13:04:30 -08:00
|
|
|
if parsed_args.ttl:
|
|
|
|
record.ttl = parsed_args.ttl
|
|
|
|
|
2012-12-29 19:21:25 +00:00
|
|
|
if parsed_args.priority:
|
|
|
|
record.priority = parsed_args.priority
|
|
|
|
|
2013-10-30 18:22:54 +00:00
|
|
|
if parsed_args.description:
|
|
|
|
record.description = parsed_args.description
|
|
|
|
|
2012-11-28 13:28:14 +00:00
|
|
|
return self.client.records.create(parsed_args.domain_id, record)
|
|
|
|
|
|
|
|
|
|
|
|
class UpdateRecordCommand(base.UpdateCommand):
|
2014-07-10 21:54:50 +02:00
|
|
|
"""Update Record"""
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(UpdateRecordCommand, self).get_parser(prog_name)
|
|
|
|
|
|
|
|
parser.add_argument('domain_id', help="Domain ID")
|
|
|
|
parser.add_argument('id', help="Record ID")
|
|
|
|
parser.add_argument('--name', help="Record Name")
|
|
|
|
parser.add_argument('--type', help="Record Type")
|
|
|
|
parser.add_argument('--data', help="Record Data")
|
2012-12-14 13:04:30 -08:00
|
|
|
|
2013-10-30 18:22:54 +00:00
|
|
|
description_group = parser.add_mutually_exclusive_group()
|
|
|
|
description_group.add_argument('--description', help="Description")
|
|
|
|
description_group.add_argument('--no-description', action='store_true')
|
|
|
|
|
2012-12-14 13:04:30 -08:00
|
|
|
ttl_group = parser.add_mutually_exclusive_group()
|
|
|
|
ttl_group.add_argument('--ttl', type=int,
|
|
|
|
help="Record Time To Live (Seconds)")
|
|
|
|
ttl_group.add_argument('--no-ttl', action='store_true')
|
2012-11-28 13:28:14 +00:00
|
|
|
|
2013-03-26 12:54:15 +00:00
|
|
|
priotity_group = parser.add_mutually_exclusive_group()
|
|
|
|
priotity_group.add_argument('--priority', type=int,
|
|
|
|
help="Record Priority")
|
|
|
|
priotity_group.add_argument('--no-priority', action='store_true')
|
2012-12-29 19:21:25 +00:00
|
|
|
|
2012-11-28 13:28:14 +00:00
|
|
|
return parser
|
|
|
|
|
|
|
|
def execute(self, parsed_args):
|
2013-06-09 15:06:11 +01:00
|
|
|
# TODO(kiall): API needs updating.. this get is silly
|
2012-11-28 13:28:14 +00:00
|
|
|
record = self.client.records.get(parsed_args.domain_id, parsed_args.id)
|
|
|
|
|
2012-12-14 13:04:30 -08:00
|
|
|
if parsed_args.name:
|
|
|
|
record.name = parsed_args.name
|
|
|
|
|
|
|
|
if parsed_args.type:
|
|
|
|
record.type = parsed_args.type
|
|
|
|
|
|
|
|
if parsed_args.data:
|
|
|
|
record.data = parsed_args.data
|
|
|
|
|
|
|
|
if parsed_args.no_ttl:
|
|
|
|
record.ttl = None
|
|
|
|
elif parsed_args.ttl:
|
|
|
|
record.ttl = parsed_args.ttl
|
2012-11-28 13:28:14 +00:00
|
|
|
|
2013-03-26 12:54:15 +00:00
|
|
|
if parsed_args.no_priority:
|
|
|
|
record.priority = None
|
|
|
|
elif parsed_args.priority:
|
|
|
|
record.priority = parsed_args.priority
|
|
|
|
|
2013-10-30 18:22:54 +00:00
|
|
|
if parsed_args.no_description:
|
|
|
|
record.description = None
|
|
|
|
elif parsed_args.description:
|
|
|
|
record.description = parsed_args.description
|
|
|
|
|
2012-11-28 13:28:14 +00:00
|
|
|
return self.client.records.update(parsed_args.domain_id, record)
|
|
|
|
|
|
|
|
|
|
|
|
class DeleteRecordCommand(base.DeleteCommand):
|
2014-07-10 21:54:50 +02:00
|
|
|
"""Delete Record"""
|
2012-11-28 13:28:14 +00:00
|
|
|
|
|
|
|
def get_parser(self, prog_name):
|
|
|
|
parser = super(DeleteRecordCommand, self).get_parser(prog_name)
|
|
|
|
|
|
|
|
parser.add_argument('domain_id', help="Domain ID")
|
|
|
|
parser.add_argument('id', help="Record ID")
|
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
def execute(self, parsed_args):
|
|
|
|
return self.client.records.delete(parsed_args.domain_id,
|
|
|
|
parsed_args.id)
|