Adding root enabled.
* Added the MVC for root enabled. * Fixed a small bug in instance/models.py. * Pep8 compliance
This commit is contained in:
parent
d5a3a4e737
commit
abfdcaa08a
@ -55,5 +55,11 @@ class Mysql(extensions.ExtensionsDescriptor):
|
|||||||
parent={'member_name': 'instance',
|
parent={'member_name': 'instance',
|
||||||
'collection_name': '{tenant_id}/instances'})
|
'collection_name': '{tenant_id}/instances'})
|
||||||
resources.append(resource)
|
resources.append(resource)
|
||||||
|
resource = extensions.ResourceExtension(
|
||||||
|
'root',
|
||||||
|
service.RootController(),
|
||||||
|
parent={'member_name': 'instance',
|
||||||
|
'collection_name': '{tenant_id}/instances'})
|
||||||
|
resources.append(resource)
|
||||||
|
|
||||||
return resources
|
return resources
|
||||||
|
@ -30,17 +30,17 @@ from reddwarf.guestagent import api as guest_api
|
|||||||
CONFIG = config.Config
|
CONFIG = config.Config
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def load_and_verify(context, instance_id):
|
def load_and_verify(context, instance_id):
|
||||||
# Load InstanceServiceStatus to verify if its running
|
# Load InstanceServiceStatus to verify if its running
|
||||||
instance = base_models.Instance.load(context, instance_id)
|
instance = base_models.Instance.load(context, instance_id)
|
||||||
LOG.info("found instance %s" % instance)
|
|
||||||
LOG.info("is sql running %s" % instance.is_sql_running)
|
|
||||||
if not instance.is_sql_running:
|
if not instance.is_sql_running:
|
||||||
raise exception.UnprocessableEntity(
|
raise exception.UnprocessableEntity(
|
||||||
"Instance %s is not ready." % instance.id)
|
"Instance %s is not ready." % instance.id)
|
||||||
else:
|
else:
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
def populate_databases(dbs):
|
def populate_databases(dbs):
|
||||||
"""
|
"""
|
||||||
Create a serializable request with user provided data
|
Create a serializable request with user provided data
|
||||||
@ -98,6 +98,22 @@ class User(object):
|
|||||||
guest_api.API().delete_user(context, instance_id, username)
|
guest_api.API().delete_user(context, instance_id, username)
|
||||||
|
|
||||||
|
|
||||||
|
class Root(object):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load(cls, context, instance_id):
|
||||||
|
load_and_verify(context, instance_id)
|
||||||
|
return guest_api.API().is_root_enabled(context, instance_id)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create(cls, context, instance_id):
|
||||||
|
load_and_verify(context, instance_id)
|
||||||
|
root = guest_api.API().enable_root(context, instance_id)
|
||||||
|
root_user = guest_models.MySQLUser()
|
||||||
|
root_user.deserialize(root)
|
||||||
|
return root_user
|
||||||
|
|
||||||
|
|
||||||
class Users(object):
|
class Users(object):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -31,6 +31,31 @@ class BaseController(wsgi.Controller):
|
|||||||
"""Base controller class."""
|
"""Base controller class."""
|
||||||
|
|
||||||
|
|
||||||
|
class RootController(BaseController):
|
||||||
|
"""Controller for instance functionality"""
|
||||||
|
|
||||||
|
def index(self, req, tenant_id, instance_id):
|
||||||
|
""" Returns True if root is enabled for the given instance;
|
||||||
|
False otherwise. """
|
||||||
|
LOG.info("Getting root enabled for instance '%s'" % instance_id)
|
||||||
|
LOG.info("req : '%s'\n\n" % req)
|
||||||
|
context = rd_context.ReddwarfContext(
|
||||||
|
auth_tok=req.headers["X-Auth-Token"],
|
||||||
|
tenant=tenant_id)
|
||||||
|
is_root_enabled = models.Root.load(context, instance_id)
|
||||||
|
return views.RootEnabledView(is_root_enabled).data()
|
||||||
|
|
||||||
|
def create(self, req, body, tenant_id, instance_id):
|
||||||
|
""" Enable the root user for the db instance """
|
||||||
|
LOG.info("Enabling root for instance '%s'" % instance_id)
|
||||||
|
LOG.info("req : '%s'\n\n" % req)
|
||||||
|
context = rd_context.ReddwarfContext(
|
||||||
|
auth_tok=req.headers["X-Auth-Token"],
|
||||||
|
tenant=tenant_id)
|
||||||
|
root = models.Root.create(context, instance_id)
|
||||||
|
return views.RootCreatedView(root).data()
|
||||||
|
|
||||||
|
|
||||||
class UserController(BaseController):
|
class UserController(BaseController):
|
||||||
"""Controller for instance functionality"""
|
"""Controller for instance functionality"""
|
||||||
|
|
||||||
|
@ -43,6 +43,25 @@ class UsersView(object):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
class RootCreatedView(UserView):
|
||||||
|
|
||||||
|
def data(self):
|
||||||
|
user_dict = {
|
||||||
|
"name": self.user.name,
|
||||||
|
"password": self.user.password
|
||||||
|
}
|
||||||
|
return {"user": user_dict}
|
||||||
|
|
||||||
|
|
||||||
|
class RootEnabledView(object):
|
||||||
|
|
||||||
|
def __init__(self, is_root_enabled):
|
||||||
|
self.is_root_enabled = is_root_enabled
|
||||||
|
|
||||||
|
def data(self):
|
||||||
|
return {'rootEnabled': self.is_root_enabled}
|
||||||
|
|
||||||
|
|
||||||
class SchemaView(object):
|
class SchemaView(object):
|
||||||
|
|
||||||
def __init__(self, schema):
|
def __init__(self, schema):
|
||||||
|
@ -40,8 +40,6 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def load_server(client, instance_id, server_id):
|
def load_server(client, instance_id, server_id):
|
||||||
"""Loads a server or raises an exception."""
|
"""Loads a server or raises an exception."""
|
||||||
if uuid is None:
|
|
||||||
raise TypeError("Argument uuid not defined.")
|
|
||||||
try:
|
try:
|
||||||
server = client.servers.get(server_id)
|
server = client.servers.get(server_id)
|
||||||
except nova_exceptions.NotFound, e:
|
except nova_exceptions.NotFound, e:
|
||||||
@ -126,7 +124,7 @@ class Instance(object):
|
|||||||
LOG.debug("Created new Reddwarf instance %s..." % db_info.id)
|
LOG.debug("Created new Reddwarf instance %s..." % db_info.id)
|
||||||
client = create_nova_client(context)
|
client = create_nova_client(context)
|
||||||
server = client.servers.create(name, image_id, flavor_ref,
|
server = client.servers.create(name, image_id, flavor_ref,
|
||||||
files={"/etc/guest_info":"guest_id=%s" % db_info.id})
|
files={"/etc/guest_info": "guest_id=%s" % db_info.id})
|
||||||
LOG.debug("Created new compute instance %s." % server.id)
|
LOG.debug("Created new compute instance %s." % server.id)
|
||||||
db_info.compute_instance_id = server.id
|
db_info.compute_instance_id = server.id
|
||||||
db_info.save()
|
db_info.save()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user