2008-04-05 23:22:12 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-07-05 11:00:34 +02:00
|
|
|
#
|
2008-04-05 23:22:12 +02:00
|
|
|
# Copyright (C) 2007, 2008 by Jan Dittberner.
|
2007-07-05 11:00:34 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
# USA.
|
|
|
|
#
|
|
|
|
# Version: $Id$
|
2008-06-06 21:20:18 +02:00
|
|
|
import CliCommand
|
|
|
|
import sys
|
2007-07-05 11:00:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
class RecordCli(CliCommand.CliCommand):
|
|
|
|
"""Command line interface command for DNS record management."""
|
|
|
|
|
|
|
|
name = "record"
|
|
|
|
description = "manage DNS records"
|
|
|
|
_optionmap = {
|
2008-06-06 21:20:18 +02:00
|
|
|
'create': ("creates a new record",
|
|
|
|
[(["-n", "--name"], "name",
|
|
|
|
"the record name", True),
|
|
|
|
(["-t", "--type"], "type",
|
|
|
|
"record type", True),
|
|
|
|
(["-c", "--content"], "content",
|
|
|
|
"record content", True),
|
|
|
|
(["-p", "--prio"], "prio",
|
|
|
|
"MX record priority", False),
|
|
|
|
(["--ttl"], "ttl",
|
|
|
|
"time to live", False),
|
|
|
|
(["-d", "--domainid"], "domainid",
|
|
|
|
"domain id", True)]),
|
|
|
|
'list': ("lists existing records",
|
|
|
|
[(["-d", "--domainid"], "domainid",
|
|
|
|
"domain id", False)]),
|
|
|
|
'delete': ("delete a record",
|
|
|
|
[(["-r", "--recordid"], "recordid",
|
|
|
|
"the record id", True)])}
|
2007-07-05 11:00:34 +02:00
|
|
|
|
|
|
|
def _execute(self, subcommand):
|
2007-07-09 08:46:36 +02:00
|
|
|
self.logger.debug("execute %s with data %s", subcommand,
|
|
|
|
str(self._data))
|
2007-07-05 11:00:34 +02:00
|
|
|
from gnuviechadmin.backend.record import RecordHandler
|
|
|
|
from gnuviechadmin import exceptions
|
|
|
|
if subcommand == "create":
|
|
|
|
try:
|
|
|
|
myrecord = RecordHandler(self._verbose).create(
|
|
|
|
**self._data)
|
|
|
|
if self._verbose:
|
|
|
|
print myrecord
|
|
|
|
except exceptions.CreationFailedError, cfe:
|
|
|
|
self._usage()
|
|
|
|
print cfe
|
|
|
|
sys.exit(2)
|
|
|
|
elif subcommand == "list":
|
2007-07-09 08:46:36 +02:00
|
|
|
records = RecordHandler(self._verbose).fetchall(**self._data)
|
2007-07-05 11:00:34 +02:00
|
|
|
for record in records:
|
|
|
|
print record
|
|
|
|
elif subcommand == "delete":
|
|
|
|
RecordHandler(self._verbose).delete(self._data["recordid"])
|
|
|
|
|
|
|
|
def __init__(self, argv):
|
|
|
|
CliCommand.CliCommand.__init__(self, argv)
|