Browse Source
- backend for domains - settings for immutable things and config encapsulation git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@229 a67ec6bc-e5d5-0310-a910-815c51eb3124master
22 changed files with 434 additions and 52 deletions
@ -0,0 +1,4 @@ |
|||
This is a database migration repository. |
|||
|
|||
More information at |
|||
http://trac.erosson.com/migrate |
@ -0,0 +1,4 @@ |
|||
#!/usr/bin/python |
|||
from migrate.versioning.shell import main |
|||
|
|||
main(repository='data/dbrepo') |
@ -0,0 +1,20 @@ |
|||
[db_settings] |
|||
# Used to identify which repository this database is versioned under. |
|||
# You can use the name of your project. |
|||
repository_id=Gnuviechadmin Schema Repository |
|||
|
|||
# The name of the database table used to track the schema version. |
|||
# This name shouldn't already be used by your project. |
|||
# If this is changed once a database is under version control, you'll need to |
|||
# change the table name in each database too. |
|||
version_table=migrate_version |
|||
|
|||
# When committing a change script, Migrate will attempt to generate the |
|||
# sql for all supported databases; normally, if one of them fails - probably |
|||
# because you don't have that database installed - it is ignored and the |
|||
# commit continues, perhaps ending successfully. |
|||
# Databases in this list MUST compile successfully during a commit, or the |
|||
# entire commit will fail. List the databases your application will actually |
|||
# be using to ensure your updates to that database work properly. |
|||
# This must be a list; example: ['postgres','sqlite'] |
|||
required_dbs=[] |
@ -0,0 +1 @@ |
|||
DROP SCHEMA gva; |
@ -0,0 +1 @@ |
|||
CREATE SCHEMA gva; |
@ -0,0 +1,84 @@ |
|||
from sqlalchemy import * |
|||
from migrate import * |
|||
from gnuviechadmin.backend.settings import dbschema |
|||
|
|||
meta = BoundMetaData(migrate_engine) |
|||
client = Table( |
|||
'client', meta, |
|||
Column('clientid', Integer, primary_key=True), |
|||
Column('title', String(10)), |
|||
Column('firstname', String(64), nullable=False), |
|||
Column('lastname', String(64), nullable=False), |
|||
Column('address1', String(64), nullable=False), |
|||
Column('address2', String(64)), |
|||
Column('zip', String(7), nullable=False), |
|||
Column('city', String(64), nullable=False), |
|||
Column('country', String(5), nullable=False), |
|||
Column('phone', String(32), nullable=False), |
|||
Column('mobile', String(32)), |
|||
Column('fax', String(32)), |
|||
Column('email', String(64), unique=True, nullable=False), |
|||
schema = dbschema |
|||
) |
|||
sysuser = Table( |
|||
'sysuser', meta, |
|||
Column('sysuserid', Integer, primary_key=True), |
|||
Column('username', String(12), nullable=False, unique=True), |
|||
Column('usertype', Integer, nullable=False, default=0, index=True), |
|||
Column('home', String(128)), |
|||
Column('shell', Boolean, nullable=False, default=False), |
|||
Column('clearpass', String(64)), |
|||
Column('md5pass', String(34)), |
|||
Column('clientid', Integer, ForeignKey("client.clientid"), |
|||
nullable=False), |
|||
Column('sysuid', Integer, nullable=False, unique=True), |
|||
Column('lastchange', DateTime, default=func.now()), |
|||
schema = dbschema |
|||
) |
|||
domain = Table( |
|||
'domain', meta, |
|||
Column('domainid', Integer, primary_key=True), |
|||
Column('name', String(255), nullable=False, unique=True), |
|||
Column('master', String(20)), |
|||
Column('last_check', Integer), |
|||
Column('type', String(6), nullable=False), |
|||
Column('notified_serial', Integer), |
|||
Column('sysuserid', Integer, ForeignKey("sysuser.sysuserid"), |
|||
nullable=False), |
|||
schema = dbschema |
|||
) |
|||
record = Table( |
|||
'record', meta, |
|||
Column('recordid', Integer, primary_key=True), |
|||
Column('domainid', Integer, ForeignKey("domain.domainid"), |
|||
nullable=False), |
|||
Column('name', String(255)), |
|||
Column('type', String(6)), |
|||
Column('content', String(255)), |
|||
Column('ttl', Integer), |
|||
Column('prio', Integer), |
|||
Column('change_date', Integer), |
|||
schema = dbschema |
|||
) |
|||
supermaster = Table( |
|||
'supermaster', meta, |
|||
Column('ip', String(25), nullable=False), |
|||
Column('nameserver', String(255), nullable=False), |
|||
Column('account', Integer, ForeignKey("sysuser.sysuserid"), |
|||
nullable=False), |
|||
schema = dbschema |
|||
) |
|||
|
|||
def upgrade(): |
|||
client.create() |
|||
sysuser.create() |
|||
domain.create() |
|||
record.create() |
|||
supermaster.create() |
|||
|
|||
def downgrade(): |
|||
supermaster.drop() |
|||
record.drop() |
|||
domain.drop() |
|||
sysuser.drop() |
|||
client.drop() |
@ -0,0 +1,31 @@ |
|||
# -*- coding: UTF-8 -*- |
|||
# |
|||
# Copyright (C) 2007 by Jan Dittberner. |
|||
# |
|||
# 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$ |
|||
|
|||
import ConfigParser, os |
|||
|
|||
# global settings which must not be user configurable |
|||
required_version = 2 |
|||
dbschema = 'gva' |
|||
|
|||
# load user configuration |
|||
config = ConfigParser.ConfigParser() |
|||
config.readfp(open('gnuviechadmin/defaults.cfg')) |
|||
config.read(['gnuviechadmin/gva.cfg', os.path.expanduser('~/.gva.cfg')]) |
@ -0,0 +1,66 @@ |
|||
# -*- coding: UTF-8 -*- |
|||
# |
|||
# Copyright (C) 2007 by Jan Dittberner. |
|||
# |
|||
# 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$ |
|||
|
|||
import CliCommand, sys |
|||
|
|||
class DomainCli(CliCommand.CliCommand): |
|||
"""Command line interface command for domain management.""" |
|||
|
|||
name = "domain" |
|||
description = "manage domains" |
|||
_optionmap = { |
|||
'create' : ("creates a new domain", |
|||
[(["-n", "--name"], "name", |
|||
"the domain name", True), |
|||
(["-t", "--type"], "type", |
|||
"domain type m for master or s for slave", False), |
|||
(["-m", "--master"], "master", |
|||
"master server for slave domains", False), |
|||
(["-s", "--sysuserid"], "sysuserid", |
|||
"system user id", True)]), |
|||
'list' : ("lists existing domains", |
|||
[]), |
|||
'delete' : ("delete a domain", |
|||
[(["-d", "--domainid"], "domainid", |
|||
"the domain id", True)])} |
|||
|
|||
def _execute(self, subcommand): |
|||
from gnuviechadmin.backend.domain import DomainHandler |
|||
from gnuviechadmin import exceptions |
|||
if subcommand == "create": |
|||
try: |
|||
mydomain = DomainHandler(self._verbose).create( |
|||
**self._data) |
|||
if self._verbose: |
|||
print mydomain |
|||
except exceptions.CreationFailedError, cfe: |
|||
self._usage() |
|||
print cfe |
|||
sys.exit(2) |
|||
elif subcommand == "list": |
|||
domains = DomainHandler(self._verbose).fetchall() |
|||
for domain in domains: |
|||
print domain |
|||
elif subcommand == "delete": |
|||
DomainHandler(self._verbose).delete(self._data["domainid"]) |
|||
|
|||
def __init__(self, argv): |
|||
CliCommand.CliCommand.__init__(self, argv) |
@ -0,0 +1,70 @@ |
|||
# -*- coding: UTF-8 -*- |
|||
# |
|||
# Copyright (C) 2007 by Jan Dittberner. |
|||
# |
|||
# 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$ |
|||
|
|||
import CliCommand, sys |
|||
|
|||
class RecordCli(CliCommand.CliCommand): |
|||
"""Command line interface command for DNS record management.""" |
|||
|
|||
name = "record" |
|||
description = "manage DNS records" |
|||
_optionmap = { |
|||
'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", |
|||
[]), |
|||
'delete' : ("delete a record", |
|||
[(["-r", "--recordid"], "recordid", |
|||
"the record id", True)])} |
|||
|
|||
def _execute(self, subcommand): |
|||
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": |
|||
records = RecordHandler(self._verbose).fetchall() |
|||
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) |
Loading…
Reference in new issue