designate/moniker/manage/powerdns.py
Kiall Mac Innes e9f30a85cc Commands should extend our Base Command, rather than cliff.Command
Change-Id: I42c8f1b95217964130aa5c77c21124f5f305ef9a
2013-04-11 12:24:22 +00:00

62 lines
2.3 KiB
Python

# 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.
import os
from migrate.exceptions import DatabaseAlreadyControlledError
from migrate.versioning import api as versioning_api
from moniker.openstack.common import log as logging
from moniker.openstack.common import cfg
from moniker.manage import base
LOG = logging.getLogger(__name__)
REPOSITORY = os.path.abspath(os.path.join(os.path.dirname(__file__), '..',
'backend', 'impl_powerdns',
'migrate_repo'))
cfg.CONF.import_opt('database_connection', 'moniker.backend.impl_powerdns',
group='backend:powerdns')
class DatabaseInitCommand(base.Command):
""" Init PowerDNS database """
def execute(self, parsed_args):
url = cfg.CONF['backend:powerdns'].database_connection
if not os.path.exists(REPOSITORY):
raise Exception('Migration Respository Not Found')
try:
LOG.info('Attempting to initialize database')
versioning_api.version_control(url=url, repository=REPOSITORY)
LOG.info('Database initialized sucessfully')
except DatabaseAlreadyControlledError:
raise Exception('Database already initialized')
class DatabaseSyncCommand(base.Command):
""" Sync PowerDNS database """
def execute(self, parsed_args):
# TODO: Support specifying version
url = cfg.CONF['backend:powerdns'].database_connection
if not os.path.exists(REPOSITORY):
raise Exception('Migration Respository Not Found')
LOG.info('Attempting to synchronize database')
versioning_api.upgrade(url=url, repository=REPOSITORY,
version=None)
LOG.info('Database synchronized sucessfully')