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
@ -57,7 +57,7 @@ if __name__ == '__main__':
|
||||
conf_loc = '%s/%s' % (config.Config.get('here'), 'conf.d/guest_info')
|
||||
config.Config.append_to_config_values('reddwarf-guestagent',
|
||||
{'config_file': conf_loc}, None)
|
||||
# Now do the same for the /etc/guest_info file
|
||||
# Now do the same for the /etc/guest_info file
|
||||
# that is injected into the VM
|
||||
config.Config.append_to_config_values('reddwarf-guestagent',
|
||||
{'config_file': '/etc/guest_info'}, None)
|
||||
|
@ -55,5 +55,11 @@ class Mysql(extensions.ExtensionsDescriptor):
|
||||
parent={'member_name': 'instance',
|
||||
'collection_name': '{tenant_id}/instances'})
|
||||
resources.append(resource)
|
||||
resource = extensions.ResourceExtension(
|
||||
'root',
|
||||
service.RootController(),
|
||||
parent={'member_name': 'instance',
|
||||
'collection_name': '{tenant_id}/instances'})
|
||||
resources.append(resource)
|
||||
|
||||
return resources
|
||||
|
@ -30,17 +30,17 @@ from reddwarf.guestagent import api as guest_api
|
||||
CONFIG = config.Config
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def load_and_verify(context, instance_id):
|
||||
# Load InstanceServiceStatus to verify if its running
|
||||
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:
|
||||
raise exception.UnprocessableEntity(
|
||||
"Instance %s is not ready." % instance.id)
|
||||
else:
|
||||
return instance
|
||||
|
||||
|
||||
def populate_databases(dbs):
|
||||
"""
|
||||
Create a serializable request with user provided data
|
||||
@ -98,6 +98,22 @@ class User(object):
|
||||
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):
|
||||
|
||||
@classmethod
|
||||
|
@ -31,6 +31,31 @@ class BaseController(wsgi.Controller):
|
||||
"""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):
|
||||
"""Controller for instance functionality"""
|
||||
|
||||
|
@ -43,6 +43,25 @@ class UsersView(object):
|
||||
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):
|
||||
|
||||
def __init__(self, schema):
|
||||
|
@ -40,8 +40,6 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
def load_server(client, instance_id, server_id):
|
||||
"""Loads a server or raises an exception."""
|
||||
if uuid is None:
|
||||
raise TypeError("Argument uuid not defined.")
|
||||
try:
|
||||
server = client.servers.get(server_id)
|
||||
except nova_exceptions.NotFound, e:
|
||||
@ -125,8 +123,8 @@ class Instance(object):
|
||||
task_status=InstanceTasks.BUILDING)
|
||||
LOG.debug("Created new Reddwarf instance %s..." % db_info.id)
|
||||
client = create_nova_client(context)
|
||||
server = client.servers.create(name, image_id, flavor_ref,
|
||||
files={"/etc/guest_info":"guest_id=%s" % db_info.id})
|
||||
server = client.servers.create(name, image_id, flavor_ref,
|
||||
files={"/etc/guest_info": "guest_id=%s" % db_info.id})
|
||||
LOG.debug("Created new compute instance %s." % server.id)
|
||||
db_info.compute_instance_id = server.id
|
||||
db_info.save()
|
||||
|
Loading…
Reference in New Issue
Block a user