Merge pull request #67 from sacharya/mgmt-framework
Started the mgmt framework.
This commit is contained in:
commit
b9d93cd1dc
56
reddwarf/extensions/mgmt.py
Normal file
56
reddwarf/extensions/mgmt.py
Normal file
@ -0,0 +1,56 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 reddwarf.common import extensions
|
||||
from reddwarf.common import wsgi
|
||||
from reddwarf.extensions.mgmt import service
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Mgmt(extensions.ExtensionsDescriptor):
|
||||
|
||||
def get_name(self):
|
||||
return "Mgmt"
|
||||
|
||||
def get_description(self):
|
||||
return "MGMT services such as details diagnostics"
|
||||
|
||||
def get_alias(self):
|
||||
return "Mgmt"
|
||||
|
||||
def get_namespace(self):
|
||||
return "http://TBD"
|
||||
|
||||
def get_updated(self):
|
||||
return "2011-01-22T13:25:27-06:00"
|
||||
|
||||
def get_resources(self):
|
||||
resources = []
|
||||
serializer = wsgi.ReddwarfResponseSerializer(
|
||||
body_serializers={'application/xml':
|
||||
wsgi.ReddwarfXMLDictSerializer()})
|
||||
resource = extensions.ResourceExtension('{tenant_id}/mgmt/instances',
|
||||
service.MgmtInstanceController(),
|
||||
deserializer=wsgi.RequestDeserializer(),
|
||||
serializer=serializer)
|
||||
resources.append(resource)
|
||||
|
||||
return resources
|
16
reddwarf/extensions/mgmt/__init__.py
Normal file
16
reddwarf/extensions/mgmt/__init__.py
Normal file
@ -0,0 +1,16 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
59
reddwarf/extensions/mgmt/service.py
Normal file
59
reddwarf/extensions/mgmt/service.py
Normal file
@ -0,0 +1,59 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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
|
||||
import webob.exc
|
||||
|
||||
from reddwarf.common import exception
|
||||
from reddwarf.common import wsgi
|
||||
from reddwarf.instance import models as instance_models
|
||||
from reddwarf.extensions.mgmt import views
|
||||
from reddwarf.instance.service import InstanceController
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MgmtInstanceController(InstanceController):
|
||||
"""Controller for instance functionality"""
|
||||
|
||||
def index(self, req, tenant_id, detailed=False):
|
||||
"""Return all instances."""
|
||||
LOG.info(_("req : '%s'\n\n") % req)
|
||||
LOG.info(_("Indexing a database instance for tenant '%s'") % tenant_id)
|
||||
# TODO(sacharya): Load all servers from nova?
|
||||
context = req.environ[wsgi.CONTEXT_KEY]
|
||||
servers = instance_models.Instances.load(context)
|
||||
|
||||
view_cls = views.InstancesView
|
||||
return wsgi.Result(view_cls(servers,
|
||||
add_addresses=self.add_addresses).data(), 200)
|
||||
|
||||
def show(self, req, tenant_id, id):
|
||||
"""Return a single instance."""
|
||||
LOG.info(_("req : '%s'\n\n") % req)
|
||||
LOG.info(_("Showing a database instance for tenant '%s'") % tenant_id)
|
||||
LOG.info(_("id : '%s'\n\n") % id)
|
||||
|
||||
context = req.environ[wsgi.CONTEXT_KEY]
|
||||
try:
|
||||
server = instance_models.Instance.load(context=context, id=id)
|
||||
except exception.ReddwarfError, e:
|
||||
LOG.error(e)
|
||||
return wsgi.Result(str(e), 404)
|
||||
return wsgi.Result(views.InstanceView(server,
|
||||
add_addresses=self.add_addresses).data(), 200)
|
||||
|
63
reddwarf/extensions/mgmt/views.py
Normal file
63
reddwarf/extensions/mgmt/views.py
Normal file
@ -0,0 +1,63 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
def get_ip_address(addresses):
|
||||
if addresses is not None and \
|
||||
addresses.get('private') is not None and \
|
||||
len(addresses['private']) > 0:
|
||||
return [addr.get('addr') for addr in addresses['private']]
|
||||
|
||||
|
||||
class InstanceView(object):
|
||||
|
||||
def __init__(self, instance, add_addresses=False):
|
||||
self.instance = instance
|
||||
self.add_addresses = add_addresses
|
||||
|
||||
def data(self):
|
||||
ip = get_ip_address(self.instance.addresses)
|
||||
instance_dict = {
|
||||
"tenant_id": self.instance.server.tenant_id,
|
||||
"id": self.instance.id,
|
||||
"name": self.instance.name,
|
||||
"status": self.instance.status,
|
||||
"links": self.instance.links,
|
||||
"created": self.instance.created,
|
||||
"flavor": self.instance.flavor,
|
||||
"updated": self.instance.updated
|
||||
}
|
||||
if self.add_addresses and ip is not None and len(ip) > 0:
|
||||
instance_dict['ip'] = ip
|
||||
return {"instance": instance_dict}
|
||||
|
||||
class InstancesView(InstanceView):
|
||||
|
||||
def __init__(self, instances, add_addresses=False):
|
||||
self.instances = instances
|
||||
self.add_addresses = add_addresses
|
||||
|
||||
def data(self):
|
||||
data = []
|
||||
# These are model instances
|
||||
for instance in self.instances:
|
||||
data.append(self.data_for_instance(instance))
|
||||
return {'instances': data}
|
||||
|
||||
def data_for_instance(self, instance):
|
||||
return InstanceView(instance,
|
||||
self.add_addresses).data()['instance']
|
Loading…
x
Reference in New Issue
Block a user