Fixed Pep8 errors.
This commit is contained in:
parent
292410dccb
commit
3e141fd79d
@ -301,4 +301,3 @@ def main():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ from reddwarf.common import config
|
|||||||
from reddwarf.common import wsgi
|
from reddwarf.common import wsgi
|
||||||
from reddwarf.db import db_api
|
from reddwarf.db import db_api
|
||||||
|
|
||||||
|
|
||||||
def create_options(parser):
|
def create_options(parser):
|
||||||
"""Sets up the CLI and config-file options
|
"""Sets up the CLI and config-file options
|
||||||
|
|
||||||
@ -69,4 +70,3 @@ if __name__ == '__main__':
|
|||||||
import traceback
|
import traceback
|
||||||
print traceback.format_exc()
|
print traceback.format_exc()
|
||||||
sys.exit("ERROR: %s" % error)
|
sys.exit("ERROR: %s" % error)
|
||||||
|
|
||||||
|
@ -54,4 +54,3 @@ if __name__ == '__main__':
|
|||||||
import traceback
|
import traceback
|
||||||
print traceback.format_exc()
|
print traceback.format_exc()
|
||||||
sys.exit("ERROR: %s" % error)
|
sys.exit("ERROR: %s" % error)
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ from nova import log as logging
|
|||||||
LOG = logging.getLogger('reddwarf.api.database')
|
LOG = logging.getLogger('reddwarf.api.database')
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
|
||||||
|
|
||||||
class APIRouter(nova.api.openstack.APIRouter):
|
class APIRouter(nova.api.openstack.APIRouter):
|
||||||
"""
|
"""
|
||||||
Routes requests on the OpenStack API to the appropriate controller
|
Routes requests on the OpenStack API to the appropriate controller
|
||||||
@ -51,5 +52,3 @@ class APIRouter(nova.api.openstack.APIRouter):
|
|||||||
controller=self.resources['instances'],
|
controller=self.resources['instances'],
|
||||||
collection={'detail': 'GET'},
|
collection={'detail': 'GET'},
|
||||||
member={'action': 'POST'})
|
member={'action': 'POST'})
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,12 +22,14 @@ from nova import log as logging
|
|||||||
|
|
||||||
LOG = logging.getLogger('reddwarf.api.database.contrib.databases')
|
LOG = logging.getLogger('reddwarf.api.database.contrib.databases')
|
||||||
|
|
||||||
|
|
||||||
class DatabasesController(object):
|
class DatabasesController(object):
|
||||||
|
|
||||||
def index(self, req):
|
def index(self, req):
|
||||||
LOG.info("index call databases")
|
LOG.info("index call databases")
|
||||||
return "This is a index of databases"
|
return "This is a index of databases"
|
||||||
|
|
||||||
|
|
||||||
class UsersController(object):
|
class UsersController(object):
|
||||||
|
|
||||||
def index(self, req):
|
def index(self, req):
|
||||||
@ -35,12 +37,6 @@ class UsersController(object):
|
|||||||
return "This is a index of users"
|
return "This is a index of users"
|
||||||
|
|
||||||
|
|
||||||
#class DatabasesControllerExtension(wsgi.Controller):
|
|
||||||
# @wsgi.action('test_func')
|
|
||||||
# def _test_func(self, req, id, body):
|
|
||||||
#
|
|
||||||
# return "Test Func called."
|
|
||||||
|
|
||||||
class Databases(extensions.ExtensionDescriptor):
|
class Databases(extensions.ExtensionDescriptor):
|
||||||
"""The Databases Extension"""
|
"""The Databases Extension"""
|
||||||
|
|
||||||
|
@ -30,10 +30,12 @@ reddwarf_opts = [
|
|||||||
help='User by which you make proxy requests to the nova api with'),
|
help='User by which you make proxy requests to the nova api with'),
|
||||||
cfg.StrOpt('reddwarf_proxy_admin_pass',
|
cfg.StrOpt('reddwarf_proxy_admin_pass',
|
||||||
default='3de4922d8b6ac5a1aad9',
|
default='3de4922d8b6ac5a1aad9',
|
||||||
help='Password for the admin user defined in reddwarf_proxy_admin_user'),
|
help='Password for the admin user defined in '
|
||||||
|
'reddwarf_proxy_admin_user'),
|
||||||
cfg.StrOpt('reddwarf_proxy_admin_tenant_name',
|
cfg.StrOpt('reddwarf_proxy_admin_tenant_name',
|
||||||
default='admin',
|
default='admin',
|
||||||
help='Tenant name fro teh admin user defined in reddwarf_proxy_admin_user'),
|
help='Tenant name for the admin user defined in '
|
||||||
|
'reddwarf_proxy_admin_user'),
|
||||||
cfg.StrOpt('reddwarf_auth_url',
|
cfg.StrOpt('reddwarf_auth_url',
|
||||||
default='http://0.0.0.0:5000/v2.0',
|
default='http://0.0.0.0:5000/v2.0',
|
||||||
help='Auth url for authing against reddwarf_proxy_admin_user'),
|
help='Auth url for authing against reddwarf_proxy_admin_user'),
|
||||||
@ -52,8 +54,11 @@ class Controller(wsgi.Controller):
|
|||||||
|
|
||||||
def get_client(self, req):
|
def get_client(self, req):
|
||||||
proxy_token = req.headers["X-Auth-Token"]
|
proxy_token = req.headers["X-Auth-Token"]
|
||||||
client = Client(FLAGS.reddwarf_proxy_admin_user, FLAGS.reddwarf_proxy_admin_pass,
|
client = Client(FLAGS.reddwarf_proxy_admin_user,
|
||||||
FLAGS.reddwarf_proxy_admin_tenant_name, FLAGS.reddwarf_auth_url, token=proxy_token)
|
FLAGS.reddwarf_proxy_admin_pass,
|
||||||
|
FLAGS.reddwarf_proxy_admin_tenant_name,
|
||||||
|
FLAGS.reddwarf_auth_url,
|
||||||
|
token=proxy_token)
|
||||||
client.authenticate()
|
client.authenticate()
|
||||||
return client
|
return client
|
||||||
|
|
||||||
@ -74,7 +79,8 @@ class Controller(wsgi.Controller):
|
|||||||
@wsgi.deserializers(xml=CreateDeserializer)
|
@wsgi.deserializers(xml=CreateDeserializer)
|
||||||
def create(self, req, body):
|
def create(self, req, body):
|
||||||
"""Creates an instance"""
|
"""Creates an instance"""
|
||||||
server = self.get_client(req).servers.create(body['name'], body['image'], body['flavor'])
|
server = self.get_client(req).servers.create(
|
||||||
|
body['name'], body['image'], body['flavor'])
|
||||||
LOG.info(server)
|
LOG.info(server)
|
||||||
robj = wsgi.ResponseObject(server)
|
robj = wsgi.ResponseObject(server)
|
||||||
|
|
||||||
|
@ -43,7 +43,8 @@ class ViewBuilder(object):
|
|||||||
"instance": {
|
"instance": {
|
||||||
"id": instance.id,
|
"id": instance.id,
|
||||||
"name": instance.name,
|
"name": instance.name,
|
||||||
"links": self.servers_viewbuilder._get_links(request, instance.id),
|
"links": self.servers_viewbuilder._get_links(request,
|
||||||
|
instance.id),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,191 +55,13 @@ class ViewBuilder(object):
|
|||||||
def _list_view(self, func, request, servers):
|
def _list_view(self, func, request, servers):
|
||||||
"""Provide a view for a list of instances."""
|
"""Provide a view for a list of instances."""
|
||||||
# This is coming back as a server entity but we change it to instances
|
# This is coming back as a server entity but we change it to instances
|
||||||
instance_list = [func(request, instance)["instance"] for instance in servers]
|
instance_list = [func(request, instance)["instance"]
|
||||||
servers_links = self.servers_viewbuilder._get_collection_links(request, servers)
|
for instance in servers]
|
||||||
|
servers_links = self.servers_viewbuilder._get_collection_links(
|
||||||
|
request, servers)
|
||||||
instances_dict = dict(instances=instance_list)
|
instances_dict = dict(instances=instance_list)
|
||||||
|
|
||||||
if servers_links:
|
if servers_links:
|
||||||
instances_dict["servers_links"] = servers_links
|
instances_dict["servers_links"] = servers_links
|
||||||
|
|
||||||
return instances_dict
|
return instances_dict
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# def _build_basic(self, server, req, status_lookup):
|
|
||||||
# """Build the very basic information for an instance"""
|
|
||||||
# instance = {}
|
|
||||||
# instance['id'] = server['uuid']
|
|
||||||
# instance['name'] = server['name']
|
|
||||||
# instance['status'] = status_lookup.get_status_from_server(server).status
|
|
||||||
# instance['links'] = self._build_links(req, instance)
|
|
||||||
# return instance
|
|
||||||
#
|
|
||||||
# def _build_detail(self, server, req, instance):
|
|
||||||
# """Build out a more detailed view of the instance"""
|
|
||||||
# flavor_view = flavors.ViewBuilder(_base_url(req), _project_id(req))
|
|
||||||
# instance['flavor'] = server['flavor']
|
|
||||||
# instance['flavor']['links'] = flavor_view._build_links(instance['flavor'])
|
|
||||||
# instance['created'] = server['created']
|
|
||||||
# instance['updated'] = server['updated']
|
|
||||||
# # Add the hostname
|
|
||||||
# if 'hostname' in server:
|
|
||||||
# instance['hostname'] = server['hostname']
|
|
||||||
#
|
|
||||||
# # Add volume information
|
|
||||||
# dbvolume = self.build_volume(server)
|
|
||||||
# if dbvolume:
|
|
||||||
# instance['volume'] = dbvolume
|
|
||||||
# return instance
|
|
||||||
#
|
|
||||||
# @staticmethod
|
|
||||||
# def _build_links(req, instance):
|
|
||||||
# """Build the links for the instance"""
|
|
||||||
# base_url = _base_url(req)
|
|
||||||
# href = os.path.join(base_url, _project_id(req),
|
|
||||||
# "instances", str(instance['id']))
|
|
||||||
# bookmark = os.path.join(nova_common.remove_version_from_href(base_url),
|
|
||||||
# "instances", str(instance['id']))
|
|
||||||
# links = [
|
|
||||||
# {
|
|
||||||
# 'rel': 'self',
|
|
||||||
# 'href': href
|
|
||||||
# },
|
|
||||||
# {
|
|
||||||
# 'rel': 'bookmark',
|
|
||||||
# 'href': bookmark
|
|
||||||
# }
|
|
||||||
# ]
|
|
||||||
# return links
|
|
||||||
#
|
|
||||||
# def build_index(self, server, req, status_lookup):
|
|
||||||
# """Build the response for an instance index call"""
|
|
||||||
# return self._build_basic(server, req, status_lookup)
|
|
||||||
#
|
|
||||||
# def build_detail(self, server, req, status_lookup):
|
|
||||||
# """Build the response for an instance detail call"""
|
|
||||||
# instance = self._build_basic(server, req, status_lookup)
|
|
||||||
# instance = self._build_detail(server, req, instance)
|
|
||||||
# return instance
|
|
||||||
#
|
|
||||||
# def build_single(self, server, req, status_lookup, databases=None,
|
|
||||||
# root_enabled=False, create=False):
|
|
||||||
# """
|
|
||||||
# Given a server (obtained from the servers API) returns an instance.
|
|
||||||
# """
|
|
||||||
# instance = self._build_basic(server, req, status_lookup)
|
|
||||||
# instance = self._build_detail(server, req, instance)
|
|
||||||
# if not create:
|
|
||||||
# # Add Database and root_enabled
|
|
||||||
# instance['databases'] = databases
|
|
||||||
# instance['rootEnabled'] = root_enabled
|
|
||||||
#
|
|
||||||
# return instance
|
|
||||||
#
|
|
||||||
# @staticmethod
|
|
||||||
# def build_volume(server):
|
|
||||||
# """Given a server dict returns the instance volume dict."""
|
|
||||||
# try:
|
|
||||||
# volumes = server['volumes']
|
|
||||||
# volume_dict = volumes[0]
|
|
||||||
# except (KeyError, IndexError):
|
|
||||||
# return None
|
|
||||||
# if len(volumes) > 1:
|
|
||||||
# error_msg = {'instanceId': server['id'],
|
|
||||||
# 'msg': "> 1 volumes in the underlying instance!"}
|
|
||||||
# LOG.error(error_msg)
|
|
||||||
# notifier.notify(notifier.publisher_id("reddwarf-api"),
|
|
||||||
# 'reddwarf.instance.list', notifier.ERROR,
|
|
||||||
# error_msg)
|
|
||||||
# return {'size': volume_dict['size']}
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#class MgmtViewBuilder(ViewBuilder):
|
|
||||||
# """Management views for an instance"""
|
|
||||||
#
|
|
||||||
# def __init__(self):
|
|
||||||
# super(MgmtViewBuilder, self).__init__()
|
|
||||||
#
|
|
||||||
# def build_mgmt_single(self, server, instance_ref, req, status_lookup):
|
|
||||||
# """Build out the management view for a single instance"""
|
|
||||||
# instance = self._build_basic(server, req, status_lookup)
|
|
||||||
# instance = self._build_detail(server, req, instance)
|
|
||||||
# instance = self._build_server_details(server, instance)
|
|
||||||
# instance = self._build_compute_api_details(instance_ref, instance)
|
|
||||||
# return instance
|
|
||||||
#
|
|
||||||
# def build_guest_info(self, instance, status=None, dbs=None, users=None,
|
|
||||||
# root_enabled=None):
|
|
||||||
# """Build out all possible information for a guest"""
|
|
||||||
# instance['guest_status'] = status.get_guest_status()
|
|
||||||
# instance['databases'] = dbs
|
|
||||||
# instance['users'] = users
|
|
||||||
# root_history = self.build_root_history(instance['id'],
|
|
||||||
# root_enabled)
|
|
||||||
# instance['root_enabled_at'] = root_history['root_enabled_at']
|
|
||||||
# instance['root_enabled_by'] = root_history['root_enabled_by']
|
|
||||||
# return instance
|
|
||||||
#
|
|
||||||
# def build_root_history(self, id, root_enabled):
|
|
||||||
# if root_enabled is not None:
|
|
||||||
# return {
|
|
||||||
# 'id': id,
|
|
||||||
# 'root_enabled_at': root_enabled.created_at,
|
|
||||||
# 'root_enabled_by': root_enabled.user_id}
|
|
||||||
# else:
|
|
||||||
# return {
|
|
||||||
# 'id': id,
|
|
||||||
# 'root_enabled_at': 'Never',
|
|
||||||
# 'root_enabled_by': 'Nobody'
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# @staticmethod
|
|
||||||
# def _build_server_details(server, instance):
|
|
||||||
# """Build more information from the servers api"""
|
|
||||||
# instance['addresses'] = server['addresses']
|
|
||||||
# del instance['links']
|
|
||||||
# return instance
|
|
||||||
#
|
|
||||||
# @staticmethod
|
|
||||||
# def _build_compute_api_details(instance_ref, instance):
|
|
||||||
# """Build out additional information from the compute api"""
|
|
||||||
# instance['server_state_description'] = instance_ref['vm_state']
|
|
||||||
# instance['host'] = instance_ref['host']
|
|
||||||
# instance['account_id'] = instance_ref['user_id']
|
|
||||||
# return instance
|
|
||||||
#
|
|
||||||
# @staticmethod
|
|
||||||
# def build_volume(server):
|
|
||||||
# """Build out a more detailed volumes view"""
|
|
||||||
# if 'volumes' in server:
|
|
||||||
# volumes = server['volumes']
|
|
||||||
# volume_dict = volumes[0]
|
|
||||||
# else:
|
|
||||||
# volume_dict = None
|
|
||||||
# return volume_dict
|
|
||||||
|
@ -52,7 +52,8 @@ class AuthorizationMiddleware(wsgi.Middleware):
|
|||||||
|
|
||||||
class TenantBasedAuth(object):
|
class TenantBasedAuth(object):
|
||||||
|
|
||||||
# The paths differ from melange, so the regex must differ as well, reddwarf starts with a tenant_id
|
# The paths differ from melange, so the regex must differ as well,
|
||||||
|
# reddwarf starts with a tenant_id
|
||||||
tenant_scoped_url = re.compile("/(?P<tenant_id>.*?)/.*")
|
tenant_scoped_url = re.compile("/(?P<tenant_id>.*?)/.*")
|
||||||
|
|
||||||
def authorize(self, request, tenant_id, roles):
|
def authorize(self, request, tenant_id, roles):
|
||||||
@ -67,4 +68,3 @@ class TenantBasedAuth(object):
|
|||||||
return True
|
return True
|
||||||
raise webob.exc.HTTPForbidden(_("User with tenant id %s cannot "
|
raise webob.exc.HTTPForbidden(_("User with tenant id %s cannot "
|
||||||
"access this resource") % tenant_id)
|
"access this resource") % tenant_id)
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ context or provide additional information in their specific WSGI pipeline.
|
|||||||
from reddwarf.openstack.common import context
|
from reddwarf.openstack.common import context
|
||||||
from reddwarf.common import utils
|
from reddwarf.common import utils
|
||||||
|
|
||||||
|
|
||||||
class ReddwarfContext(context.RequestContext):
|
class ReddwarfContext(context.RequestContext):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -24,6 +24,7 @@ ProcessExecutionError = openstack_exception.ProcessExecutionError
|
|||||||
DatabaseMigrationError = openstack_exception.DatabaseMigrationError
|
DatabaseMigrationError = openstack_exception.DatabaseMigrationError
|
||||||
wrap_exception = openstack_exception.wrap_exception
|
wrap_exception = openstack_exception.wrap_exception
|
||||||
|
|
||||||
|
|
||||||
class ReddwarfError(openstack_exception.OpenstackException):
|
class ReddwarfError(openstack_exception.OpenstackException):
|
||||||
"""Base exception that all custom reddwarf app exceptions inherit from."""
|
"""Base exception that all custom reddwarf app exceptions inherit from."""
|
||||||
|
|
||||||
@ -41,6 +42,3 @@ class DBConstraintError(ReddwarfError):
|
|||||||
class InvalidRPCConnectionReuse(ReddwarfError):
|
class InvalidRPCConnectionReuse(ReddwarfError):
|
||||||
|
|
||||||
message = _("Invalid RPC Connection Reuse")
|
message = _("Invalid RPC Connection Reuse")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ from reddwarf.openstack.common import extensions
|
|||||||
ExtensionsDescriptor = extensions.ExtensionDescriptor
|
ExtensionsDescriptor = extensions.ExtensionDescriptor
|
||||||
ResourceExtension = extensions.ResourceExtension
|
ResourceExtension = extensions.ResourceExtension
|
||||||
|
|
||||||
|
|
||||||
def factory(global_config, **local_config):
|
def factory(global_config, **local_config):
|
||||||
"""Paste factory."""
|
"""Paste factory."""
|
||||||
def _factory(app):
|
def _factory(app):
|
||||||
|
@ -35,6 +35,7 @@ bool_from_string = openstack_utils.bool_from_string
|
|||||||
execute = openstack_utils.execute
|
execute = openstack_utils.execute
|
||||||
isotime = openstack_utils.isotime
|
isotime = openstack_utils.isotime
|
||||||
|
|
||||||
|
|
||||||
def stringify_keys(dictionary):
|
def stringify_keys(dictionary):
|
||||||
if dictionary is None:
|
if dictionary is None:
|
||||||
return None
|
return None
|
||||||
@ -78,6 +79,7 @@ class cached_property(object):
|
|||||||
setattr(obj, self.__name__, value)
|
setattr(obj, self.__name__, value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
class MethodInspector(object):
|
class MethodInspector(object):
|
||||||
|
|
||||||
def __init__(self, func):
|
def __init__(self, func):
|
||||||
|
@ -83,7 +83,8 @@ class Request(openstack_wsgi.Request):
|
|||||||
if format in ['json', 'xml']:
|
if format in ['json', 'xml']:
|
||||||
return 'application/{0}'.format(parts[1])
|
return 'application/{0}'.format(parts[1])
|
||||||
|
|
||||||
ctypes = {'application/vnd.openstack.reddwarf+json': "application/json",
|
ctypes = {'application/vnd.openstack.reddwarf+json':
|
||||||
|
"application/json",
|
||||||
'application/vnd.openstack.reddwarf+xml': "application/xml",
|
'application/vnd.openstack.reddwarf+xml': "application/xml",
|
||||||
'application/json': "application/json",
|
'application/json': "application/json",
|
||||||
'application/xml': "application/xml"}
|
'application/xml': "application/xml"}
|
||||||
|
@ -27,13 +27,18 @@ from reddwarf.common import exception
|
|||||||
from reddwarf.common import utils
|
from reddwarf.common import utils
|
||||||
from novaclient.v1_1.client import Client
|
from novaclient.v1_1.client import Client
|
||||||
|
|
||||||
|
CONFIG = config.Config
|
||||||
LOG = logging.getLogger('reddwarf.database.models')
|
LOG = logging.getLogger('reddwarf.database.models')
|
||||||
|
|
||||||
PROXY_ADMIN_USER = config.Config.get('reddwarf_proxy_admin_user', 'admin')
|
PROXY_ADMIN_USER = CONFIG.get('reddwarf_proxy_admin_user', 'admin')
|
||||||
PROXY_ADMIN_PASS = config.Config.get('reddwarf_proxy_admin_pass', '3de4922d8b6ac5a1aad9')
|
PROXY_ADMIN_PASS = CONFIG.get('reddwarf_proxy_admin_pass',
|
||||||
PROXY_ADMIN_TENANT_NAME = config.Config.get('reddwarf_proxy_admin_tenant_name', 'admin')
|
'3de4922d8b6ac5a1aad9')
|
||||||
PROXY_AUTH_URL = config.Config.get('reddwarf_auth_url', 'http://0.0.0.0:5000/v2.0')
|
PROXY_ADMIN_TENANT_NAME = CONFIG.get('reddwarf_proxy_admin_tenant_name',
|
||||||
PROXY_TENANT_ID = config.Config.get('reddwarf_tenant_id', 'f5f71240a97c411e977452370422d7cc')
|
'admin')
|
||||||
|
PROXY_AUTH_URL = CONFIG.get('reddwarf_auth_url', 'http://0.0.0.0:5000/v2.0')
|
||||||
|
PROXY_TENANT_ID = CONFIG.get('reddwarf_tenant_id',
|
||||||
|
'f5f71240a97c411e977452370422d7cc')
|
||||||
|
|
||||||
|
|
||||||
class ModelBase(object):
|
class ModelBase(object):
|
||||||
|
|
||||||
@ -92,7 +97,8 @@ class RemoteModelBase(ModelBase):
|
|||||||
|
|
||||||
def data_item(self, data_object):
|
def data_item(self, data_object):
|
||||||
data_fields = self._data_fields + self._auto_generated_attrs
|
data_fields = self._data_fields + self._auto_generated_attrs
|
||||||
return dict([(field, getattr(data_object,field)) for field in data_fields])
|
return dict([(field, getattr(data_object, field))
|
||||||
|
for field in data_fields])
|
||||||
|
|
||||||
# data magic that will allow for a list of _data_object or a single item
|
# data magic that will allow for a list of _data_object or a single item
|
||||||
# if the object is a list, it will turn it into a list of hash's again
|
# if the object is a list, it will turn it into a list of hash's again
|
||||||
@ -104,6 +110,7 @@ class RemoteModelBase(ModelBase):
|
|||||||
else:
|
else:
|
||||||
return self.data_item(self._data_object)
|
return self.data_item(self._data_object)
|
||||||
|
|
||||||
|
|
||||||
class Instance(RemoteModelBase):
|
class Instance(RemoteModelBase):
|
||||||
|
|
||||||
_data_fields = ['name', 'status', 'updated', 'id', 'flavor']
|
_data_fields = ['name', 'status', 'updated', 'id', 'flavor']
|
||||||
@ -115,6 +122,7 @@ class Instance(RemoteModelBase):
|
|||||||
def delete(cls, proxy_token, uuid):
|
def delete(cls, proxy_token, uuid):
|
||||||
return cls.get_client(proxy_token).servers.delete(uuid)
|
return cls.get_client(proxy_token).servers.delete(uuid)
|
||||||
|
|
||||||
|
|
||||||
class Instances(Instance):
|
class Instances(Instance):
|
||||||
|
|
||||||
def __init__(self, proxy_token):
|
def __init__(self, proxy_token):
|
||||||
@ -174,15 +182,18 @@ class DatabaseModelBase(ModelBase):
|
|||||||
class DBInstance(DatabaseModelBase):
|
class DBInstance(DatabaseModelBase):
|
||||||
_data_fields = ['name', 'status']
|
_data_fields = ['name', 'status']
|
||||||
|
|
||||||
|
|
||||||
class ServiceImage(DatabaseModelBase):
|
class ServiceImage(DatabaseModelBase):
|
||||||
_data_fields = ['service_name', 'image_id']
|
_data_fields = ['service_name', 'image_id']
|
||||||
|
|
||||||
|
|
||||||
def persisted_models():
|
def persisted_models():
|
||||||
return {
|
return {
|
||||||
'instance': DBInstance,
|
'instance': DBInstance,
|
||||||
'service_image': ServiceImage,
|
'service_image': ServiceImage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InvalidModelError(exception.ReddwarfError):
|
class InvalidModelError(exception.ReddwarfError):
|
||||||
|
|
||||||
message = _("The following values are invalid: %(errors)s")
|
message = _("The following values are invalid: %(errors)s")
|
||||||
|
@ -27,6 +27,7 @@ from reddwarf.database import views
|
|||||||
from reddwarf.common import context
|
from reddwarf.common import context
|
||||||
from reddwarf import rpc
|
from reddwarf import rpc
|
||||||
|
|
||||||
|
CONFIG = config.Config
|
||||||
LOG = logging.getLogger('reddwarf.database.service')
|
LOG = logging.getLogger('reddwarf.database.service')
|
||||||
|
|
||||||
|
|
||||||
@ -34,10 +35,14 @@ class BaseController(wsgi.Controller):
|
|||||||
"""Base controller class."""
|
"""Base controller class."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.proxy_admin_user = config.Config.get('reddwarf_proxy_admin_user', 'admin')
|
self.proxy_admin_user = CONFIG.get('reddwarf_proxy_admin_user',
|
||||||
self.proxy_admin_pass = config.Config.get('reddwarf_proxy_admin_pass', '3de4922d8b6ac5a1aad9')
|
'admin')
|
||||||
self.proxy_admin_tenant_name = config.Config.get('reddwarf_proxy_admin_tenant_name', 'admin')
|
self.proxy_admin_pass = CONFIG.get('reddwarf_proxy_admin_pass',
|
||||||
self.auth_url = config.Config.get('reddwarf_auth_url', 'http://0.0.0.0:5000/v2.0')
|
'3de4922d8b6ac5a1aad9')
|
||||||
|
self.proxy_admin_tenant_name = CONFIG.get(
|
||||||
|
'reddwarf_proxy_admin_tenant_name', 'admin')
|
||||||
|
self.auth_url = CONFIG.get('reddwarf_auth_url',
|
||||||
|
'http://0.0.0.0:5000/v2.0')
|
||||||
|
|
||||||
def get_client(self, req):
|
def get_client(self, req):
|
||||||
proxy_token = req.headers["X-Auth-Token"]
|
proxy_token = req.headers["X-Auth-Token"]
|
||||||
@ -46,6 +51,7 @@ class BaseController(wsgi.Controller):
|
|||||||
client.authenticate()
|
client.authenticate()
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
class InstanceController(BaseController):
|
class InstanceController(BaseController):
|
||||||
"""Controller for instance functionality"""
|
"""Controller for instance functionality"""
|
||||||
|
|
||||||
@ -53,7 +59,8 @@ class InstanceController(BaseController):
|
|||||||
"""Return all instances."""
|
"""Return all instances."""
|
||||||
servers = models.Instances(req.headers["X-Auth-Token"]).data()
|
servers = models.Instances(req.headers["X-Auth-Token"]).data()
|
||||||
#TODO(hub-cap): Remove this, this is only for testing communication between services
|
#TODO(hub-cap): Remove this, this is only for testing communication between services
|
||||||
rpc.cast(context.ReddwarfContext(), "taskmanager.None", {"method":"test_method", "BARRRR":"ARGGGGG"})
|
rpc.cast(context.ReddwarfContext(), "taskmanager.None",
|
||||||
|
{"method": "test_method", "BARRRR": "ARGGGGG"})
|
||||||
|
|
||||||
return wsgi.Result(views.InstancesView(servers).data(), 201)
|
return wsgi.Result(views.InstancesView(servers).data(), 201)
|
||||||
|
|
||||||
@ -70,17 +77,21 @@ class InstanceController(BaseController):
|
|||||||
return wsgi.Result(202)
|
return wsgi.Result(202)
|
||||||
|
|
||||||
def create(self, req, body, tenant_id):
|
def create(self, req, body, tenant_id):
|
||||||
# find the service id (cant be done yet at startup due to inconsitencies w/ the load app paste
|
# find the service id (cant be done yet at startup due to
|
||||||
|
# inconsitencies w/ the load app paste
|
||||||
# TODO(hub-cap): figure out how to get this to work in __init__ time
|
# TODO(hub-cap): figure out how to get this to work in __init__ time
|
||||||
# TODO(hub-cap): The problem with this in __init__ is that the paste config
|
# TODO(hub-cap): The problem with this in __init__ is that the paste
|
||||||
# is generated w/ the same config file as the db flags that are needed
|
# config is generated w/ the same config file as the db flags that
|
||||||
# for init. These need to be split so the db can be init'd w/o the paste
|
# are needed for init. These need to be split so the db can be init'd
|
||||||
# stuff. Since the paste stuff inits the database.service module, it
|
# w/o the paste stuff. Since the paste stuff inits the
|
||||||
# is a chicken before the egg problem. Simple refactor will fix it and
|
# database.service module, it is a chicken before the egg problem.
|
||||||
# we can move this into the __init__ code. Or maybe we shouldnt due to
|
# Simple refactor will fix it and we can move this into the __init__
|
||||||
# the nature of changing images. This needs discussion.
|
# code. Or maybe we shouldnt due to the nature of changing images.
|
||||||
image_id = models.ServiceImage.find_by(service_name="database")['image_id']
|
# This needs discussion.
|
||||||
server = self.get_client(req).servers.create(body['name'], image_id, body['flavor'])
|
database = models.ServiceImage.find_by(service_name="database")
|
||||||
|
image_id = database['image_id']
|
||||||
|
server = self.get_client(req).servers.create(body['name'], image_id,
|
||||||
|
body['flavor'])
|
||||||
# Now wait for the response from the create to do additional work
|
# Now wait for the response from the create to do additional work
|
||||||
return "server created %s" % server.__dict__
|
return "server created %s" % server.__dict__
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
class InstanceView(object):
|
class InstanceView(object):
|
||||||
|
|
||||||
def __init__(self, instance):
|
def __init__(self, instance):
|
||||||
@ -30,6 +31,7 @@ class InstanceView(object):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class InstancesView(object):
|
class InstancesView(object):
|
||||||
|
|
||||||
def __init__(self, instances):
|
def __init__(self, instances):
|
||||||
|
@ -28,7 +28,9 @@ def map(engine, models):
|
|||||||
return
|
return
|
||||||
|
|
||||||
orm.mapper(models['instance'], Table('instances', meta, autoload=True))
|
orm.mapper(models['instance'], Table('instances', meta, autoload=True))
|
||||||
orm.mapper(models['service_image'], Table('service_images', meta, autoload=True))
|
orm.mapper(models['service_image'],
|
||||||
|
Table('service_images', meta, autoload=True))
|
||||||
|
|
||||||
|
|
||||||
def mapping_exists(model):
|
def mapping_exists(model):
|
||||||
try:
|
try:
|
||||||
|
@ -21,6 +21,8 @@ from novaclient.v1_1.client import Client
|
|||||||
from reddwarf.common import config
|
from reddwarf.common import config
|
||||||
from reddwarf.common import extensions
|
from reddwarf.common import extensions
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG = config.Config
|
||||||
LOG = logging.getLogger('reddwarf.extensions.mysql')
|
LOG = logging.getLogger('reddwarf.extensions.mysql')
|
||||||
|
|
||||||
|
|
||||||
@ -28,11 +30,14 @@ class BaseController(object):
|
|||||||
"""Base controller class."""
|
"""Base controller class."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.proxy_admin_user = config.Config.get('reddwarf_proxy_admin_user', 'admin')
|
self.proxy_admin_user = CONFIG.get('reddwarf_proxy_admin_user',
|
||||||
self.proxy_admin_pass = config.Config.get('reddwarf_proxy_admin_pass', '3de4922d8b6ac5a1aad9')
|
'admin')
|
||||||
self.proxy_admin_tenant_name = config.Config.get('reddwarf_proxy_admin_tenant_name', 'admin')
|
self.proxy_admin_pass = CONFIG.get('reddwarf_proxy_admin_pass',
|
||||||
self.auth_url = config.Config.get('reddwarf_auth_url', 'http://0.0.0.0:5000/v2.0')
|
'3de4922d8b6ac5a1aad9')
|
||||||
|
self.proxy_admin_tenant_name = CONFIG.get(
|
||||||
|
'reddwarf_proxy_admin_tenant_name', 'admin')
|
||||||
|
self.auth_url = CONFIG.get('reddwarf_auth_url',
|
||||||
|
'http://0.0.0.0:5000/v2.0')
|
||||||
|
|
||||||
def get_client(self, req):
|
def get_client(self, req):
|
||||||
proxy_token = req.headers["X-Auth-Token"]
|
proxy_token = req.headers["X-Auth-Token"]
|
||||||
@ -41,6 +46,7 @@ class BaseController(object):
|
|||||||
client.authenticate()
|
client.authenticate()
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
class UserController(BaseController):
|
class UserController(BaseController):
|
||||||
"""Controller for instance functionality"""
|
"""Controller for instance functionality"""
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
rpc_backend_opt = config.Config.get('rpc_backend', 'reddwarf.rpc.impl_kombu')
|
rpc_backend_opt = config.Config.get('rpc_backend', 'reddwarf.rpc.impl_kombu')
|
||||||
|
|
||||||
|
|
||||||
def create_connection(new=True):
|
def create_connection(new=True):
|
||||||
"""Create a connection to the message bus used for rpc.
|
"""Create a connection to the message bus used for rpc.
|
||||||
|
|
||||||
|
@ -43,11 +43,13 @@ from reddwarf.common import context
|
|||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Pool(pools.Pool):
|
class Pool(pools.Pool):
|
||||||
"""Class that implements a Pool of Connections."""
|
"""Class that implements a Pool of Connections."""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.connection_cls = kwargs.pop("connection_cls", None)
|
self.connection_cls = kwargs.pop("connection_cls", None)
|
||||||
kwargs.setdefault("max_size", config.Config.get('rpc_conn_pool_size', 30))
|
kwargs.setdefault("max_size",
|
||||||
|
config.Config.get('rpc_conn_pool_size', 30))
|
||||||
kwargs.setdefault("order_as_stack", True)
|
kwargs.setdefault("order_as_stack", True)
|
||||||
super(Pool, self).__init__(*args, **kwargs)
|
super(Pool, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
@ -205,7 +207,8 @@ class ProxyCallback(object):
|
|||||||
|
|
||||||
def __init__(self, proxy, connection_pool):
|
def __init__(self, proxy, connection_pool):
|
||||||
self.proxy = proxy
|
self.proxy = proxy
|
||||||
self.pool = greenpool.GreenPool(config.Config.get('rpc_thread_pool_size',1024))
|
self.pool = greenpool.GreenPool(
|
||||||
|
config.Config.get('rpc_thread_pool_size', 1024))
|
||||||
self.connection_pool = connection_pool
|
self.connection_pool = connection_pool
|
||||||
|
|
||||||
def __call__(self, message_data):
|
def __call__(self, message_data):
|
||||||
@ -265,8 +268,8 @@ class ProxyCallback(object):
|
|||||||
class MulticallWaiter(object):
|
class MulticallWaiter(object):
|
||||||
def __init__(self, connection, timeout):
|
def __init__(self, connection, timeout):
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
self._iterator = connection.iterconsume(
|
timeout = timeout or config.Config.get('rpc_response_timeout', 3600)
|
||||||
timeout=timeout or config.Config.get('rpc_response_timeout', 3600))
|
self._iterator = connection.iterconsume(timeout)
|
||||||
self._result = None
|
self._result = None
|
||||||
self._done = False
|
self._done = False
|
||||||
self._got_ending = False
|
self._got_ending = False
|
||||||
|
@ -26,6 +26,7 @@ from reddwarf.common import exception
|
|||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RemoteError(exception.ReddwarfError):
|
class RemoteError(exception.ReddwarfError):
|
||||||
"""Signifies that a remote class has raised an exception.
|
"""Signifies that a remote class has raised an exception.
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ from reddwarf.rpc import common as rpc_common
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
SSL_VERSION = "SSLv2"
|
SSL_VERSION = "SSLv2"
|
||||||
|
|
||||||
|
|
||||||
class ConsumerBase(object):
|
class ConsumerBase(object):
|
||||||
"""Consumer base class."""
|
"""Consumer base class."""
|
||||||
|
|
||||||
@ -149,7 +150,8 @@ class TopicConsumer(ConsumerBase):
|
|||||||
Other kombu options may be passed
|
Other kombu options may be passed
|
||||||
"""
|
"""
|
||||||
# Default options
|
# Default options
|
||||||
options = {'durable': config.Config.get('rabbit_durable_queues', False),
|
options = {'durable': config.Config.get('rabbit_durable_queues',
|
||||||
|
False),
|
||||||
'auto_delete': False,
|
'auto_delete': False,
|
||||||
'exclusive': False}
|
'exclusive': False}
|
||||||
options.update(kwargs)
|
options.update(kwargs)
|
||||||
@ -255,7 +257,8 @@ class TopicPublisher(Publisher):
|
|||||||
|
|
||||||
Kombu options may be passed as keyword args to override defaults
|
Kombu options may be passed as keyword args to override defaults
|
||||||
"""
|
"""
|
||||||
options = {'durable': config.Config.get('rabbit_durable_queues', False),
|
options = {'durable': config.Config.get('rabbit_durable_queues',
|
||||||
|
False),
|
||||||
'auto_delete': False,
|
'auto_delete': False,
|
||||||
'exclusive': False }
|
'exclusive': False }
|
||||||
options.update(kwargs)
|
options.update(kwargs)
|
||||||
@ -288,7 +291,8 @@ class NotifyPublisher(TopicPublisher):
|
|||||||
"""Publisher class for 'notify'"""
|
"""Publisher class for 'notify'"""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.durable = kwargs.pop('durable', config.Config.get('rabbit_durable_queues', False))
|
default = config.Config.get('rabbit_durable_queues', False)
|
||||||
|
self.durable = kwargs.pop('durable', default)
|
||||||
super(NotifyPublisher, self).__init__(*args, **kwargs)
|
super(NotifyPublisher, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def reconnect(self, channel):
|
def reconnect(self, channel):
|
||||||
@ -332,11 +336,15 @@ class Connection(object):
|
|||||||
p_key = server_params_to_kombu_params.get(sp_key, sp_key)
|
p_key = server_params_to_kombu_params.get(sp_key, sp_key)
|
||||||
params[p_key] = value
|
params[p_key] = value
|
||||||
|
|
||||||
params.setdefault('hostname', config.Config.get('rabbit_host','127.0.0.1'))
|
params.setdefault('hostname', config.Config.get('rabbit_host',
|
||||||
|
'127.0.0.1'))
|
||||||
params.setdefault('port', config.Config.get('rabbit_port', 5672))
|
params.setdefault('port', config.Config.get('rabbit_port', 5672))
|
||||||
params.setdefault('userid', config.Config.get('rabbit_userid','guest'))
|
params.setdefault('userid',
|
||||||
params.setdefault('password', config.Config.get('rabbit_password','f7999d1955c5014aa32c'))
|
config.Config.get('rabbit_userid', 'guest'))
|
||||||
params.setdefault('virtual_host', config.Config.get('rabbit_virtual_host','/'))
|
params.setdefault('password',
|
||||||
|
config.Config.get('rabbit_password', 'guest'))
|
||||||
|
params.setdefault('virtual_host',
|
||||||
|
config.Config.get('rabbit_virtual_host', '/'))
|
||||||
|
|
||||||
self.params = params
|
self.params = params
|
||||||
|
|
||||||
@ -570,7 +578,8 @@ class Connection(object):
|
|||||||
|
|
||||||
def _publish():
|
def _publish():
|
||||||
publisher = cls(self.channel, topic, **kwargs)
|
publisher = cls(self.channel, topic, **kwargs)
|
||||||
LOG.info("_publish info%s %s %s %s" % (self.channel, topic, kwargs,publisher))
|
LOG.info("_publish info%s %s %s %s" % (self.channel, topic,
|
||||||
|
kwargs, publisher))
|
||||||
publisher.send(msg)
|
publisher.send(msg)
|
||||||
|
|
||||||
self.ensure(_error_callback, _publish)
|
self.ensure(_error_callback, _publish)
|
||||||
|
@ -74,4 +74,3 @@ class API(wsgi.Router):
|
|||||||
|
|
||||||
def app_factory(global_conf, **local_conf):
|
def app_factory(global_conf, **local_conf):
|
||||||
return API()
|
return API()
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
# The code below enables nosetests to work with i18n _() blocks
|
# The code below enables nosetests to work with i18n _() blocks
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import __builtin__
|
import __builtin__
|
||||||
setattr(__builtin__, '_', lambda x: x)
|
setattr(__builtin__, '_', lambda x: x)
|
||||||
|
|
||||||
|
@ -45,4 +45,3 @@ def vcs_version_string():
|
|||||||
|
|
||||||
def version_string_with_vcs():
|
def version_string_with_vcs():
|
||||||
return "%s-%s" % (canonical_version_string(), vcs_version_string())
|
return "%s-%s" % (canonical_version_string(), vcs_version_string())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user