Add diagnostics to Python API and CLI
Change-Id: Ib26adada4a5610f7eb6a3458caa4ca4b18d804ca
This commit is contained in:
parent
d9737b5b2a
commit
67fec06719
79
monikerclient/cli/diagnostics.py
Normal file
79
monikerclient/cli/diagnostics.py
Normal file
@ -0,0 +1,79 @@
|
||||
# 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 logging
|
||||
from monikerclient.cli import base
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PingCommand(base.GetCommand):
|
||||
""" Ping a service on a given host """
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(PingCommand, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument('--service', help="Service Name (e.g. central)",
|
||||
required=True)
|
||||
parser.add_argument('--host', help="Hostname", required=True)
|
||||
|
||||
return parser
|
||||
|
||||
def execute(self, parsed_args):
|
||||
return self.client.diagnostics.ping(parsed_args.service,
|
||||
parsed_args.host)
|
||||
|
||||
|
||||
class SyncAllCommand(base.Command):
|
||||
""" Sync Everything """
|
||||
|
||||
def execute(self, parsed_args):
|
||||
self.client.diagnostics.sync_all()
|
||||
|
||||
LOG.info('Synchronization of all domains scheduled')
|
||||
|
||||
|
||||
class SyncDomainCommand(base.Command):
|
||||
""" Sync a single Domain """
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SyncDomainCommand, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument('domain_id', help="Domain ID")
|
||||
|
||||
return parser
|
||||
|
||||
def execute(self, parsed_args):
|
||||
self.client.diagnostics.sync_domain(parsed_args.domain_id)
|
||||
|
||||
LOG.info('Synchronization of domain scheduled')
|
||||
|
||||
|
||||
class SyncRecordCommand(base.Command):
|
||||
""" Sync a single Record """
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SyncRecordCommand, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument('domain_id', help="Domain ID")
|
||||
parser.add_argument('record_id', help="Record ID")
|
||||
|
||||
return parser
|
||||
|
||||
def execute(self, parsed_args):
|
||||
self.client.diagnostics.sync_record(parsed_args.domain_id,
|
||||
parsed_args.record_id)
|
||||
|
||||
LOG.info('Synchronization of record scheduled')
|
@ -16,6 +16,7 @@
|
||||
import requests
|
||||
from monikerclient import exceptions
|
||||
from monikerclient.auth import KeystoneAuth
|
||||
from monikerclient.v1 import diagnostics
|
||||
from monikerclient.v1 import domains
|
||||
from monikerclient.v1 import records
|
||||
from monikerclient.v1 import servers
|
||||
@ -56,6 +57,7 @@ class Client(object):
|
||||
self.requests.auth = auth
|
||||
self.requests.headers.update(headers)
|
||||
|
||||
self.diagnostics = diagnostics.DiagnosticsController(client=self)
|
||||
self.domains = domains.DomainsController(client=self)
|
||||
self.records = records.RecordsController(client=self)
|
||||
self.servers = servers.ServersController(client=self)
|
||||
|
@ -22,6 +22,10 @@ class Controller(object):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
|
||||
class CrudController(Controller):
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@abc.abstractmethod
|
||||
def list(self, *args, **kw):
|
||||
"""
|
||||
|
56
monikerclient/v1/diagnostics.py
Normal file
56
monikerclient/v1/diagnostics.py
Normal file
@ -0,0 +1,56 @@
|
||||
# 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.
|
||||
from monikerclient.v1.base import Controller
|
||||
|
||||
|
||||
# NOTE(kiall): The /../ is an awful hack.. But keystone only gives us a
|
||||
# versioned endpoint. Maybe we should make the diags calls part
|
||||
# of v1?
|
||||
class DiagnosticsController(Controller):
|
||||
def ping(self, service, host):
|
||||
"""
|
||||
Ping a service on a given host
|
||||
"""
|
||||
response = self.client.get('/../diagnostics/ping/%s/%s' %
|
||||
(service, host))
|
||||
|
||||
return response.json
|
||||
|
||||
def sync_all(self):
|
||||
"""
|
||||
Sync Everything
|
||||
"""
|
||||
response = self.client.post('/../diagnostics/sync/all')
|
||||
|
||||
return response.json
|
||||
|
||||
def sync_domain(self, domain_id):
|
||||
"""
|
||||
Sync Single Domain
|
||||
"""
|
||||
response = self.client.post('/../diagnostics/sync/domain/%s' %
|
||||
domain_id)
|
||||
|
||||
return response.json
|
||||
|
||||
def sync_record(self, domain_id, record_id):
|
||||
"""
|
||||
Sync Single Record
|
||||
"""
|
||||
response = self.client.post('/../diagnostics/sync/record/%s/%s' %
|
||||
(domain_id, record_id))
|
||||
|
||||
return response.json
|
@ -16,13 +16,13 @@
|
||||
import json
|
||||
from monikerclient import warlock
|
||||
from monikerclient import utils
|
||||
from monikerclient.v1.base import Controller
|
||||
from monikerclient.v1.base import CrudController
|
||||
|
||||
|
||||
Domain = warlock.model_factory(utils.load_schema('v1', 'domain'))
|
||||
|
||||
|
||||
class DomainsController(Controller):
|
||||
class DomainsController(CrudController):
|
||||
def list(self):
|
||||
"""
|
||||
Retrieve a list of domains
|
||||
|
@ -16,14 +16,14 @@
|
||||
import json
|
||||
from monikerclient import warlock
|
||||
from monikerclient import utils
|
||||
from monikerclient.v1.base import Controller
|
||||
from monikerclient.v1.base import CrudController
|
||||
from monikerclient.v1.domains import Domain
|
||||
|
||||
|
||||
Record = warlock.model_factory(utils.load_schema('v1', 'record'))
|
||||
|
||||
|
||||
class RecordsController(Controller):
|
||||
class RecordsController(CrudController):
|
||||
def list(self, domain):
|
||||
"""
|
||||
Retrieve a list of records
|
||||
|
@ -16,13 +16,13 @@
|
||||
import json
|
||||
from monikerclient import warlock
|
||||
from monikerclient import utils
|
||||
from monikerclient.v1.base import Controller
|
||||
from monikerclient.v1.base import CrudController
|
||||
|
||||
|
||||
Server = warlock.model_factory(utils.load_schema('v1', 'server'))
|
||||
|
||||
|
||||
class ServersController(Controller):
|
||||
class ServersController(CrudController):
|
||||
def list(self):
|
||||
"""
|
||||
Retrieve a list of servers
|
||||
|
7
setup.py
7
setup.py
@ -65,6 +65,13 @@ setup(
|
||||
server-create = monikerclient.cli.servers:CreateServerCommand
|
||||
server-update = monikerclient.cli.servers:UpdateServerCommand
|
||||
server-delete = monikerclient.cli.servers:DeleteServerCommand
|
||||
|
||||
diagnostics-ping = monikerclient.cli.diagnostics:PingCommand
|
||||
diagnostics-sync-all = monikerclient.cli.diagnostics:SyncAllCommand
|
||||
diagnostics-sync-domain = monikerclient.cli.diagnostics\
|
||||
:SyncDomainCommand
|
||||
diagnostics-sync-record = monikerclient.cli.diagnostics\
|
||||
:SyncRecordCommand
|
||||
"""),
|
||||
classifiers=[
|
||||
'Development Status :: 3 - Alpha',
|
||||
|
Loading…
x
Reference in New Issue
Block a user