From acbbdf10274e8b357c7b83418b5f5e131240a68e Mon Sep 17 00:00:00 2001 From: Craig Vyvial Date: Wed, 7 Mar 2012 20:53:17 -0600 Subject: [PATCH] updates to get create working --- development/bootstrap/bootstrap.sh | 2 +- development/development_enviroment.sh | 19 ++++++++++- etc/reddwarf/reddwarf.conf.sample | 2 ++ reddwarf/common/exception.py | 6 ++++ reddwarf/database/models.py | 31 +++++++++++++---- reddwarf/database/service.py | 48 ++++++++++++--------------- 6 files changed, 74 insertions(+), 34 deletions(-) diff --git a/development/bootstrap/bootstrap.sh b/development/bootstrap/bootstrap.sh index 17b4ba88d6..e5fa53862b 100755 --- a/development/bootstrap/bootstrap.sh +++ b/development/bootstrap/bootstrap.sh @@ -9,7 +9,7 @@ fi REDDWARF_TOKEN=$1 # # This takes about ~12 minutes to finish -sudo apt-get install kvm-pxe +sudo apt-get -y install kvm-pxe ubuntu-vm-builder VM_PATH=~/oneiric_mysql_image UBUNTU_DISTRO="ubuntu 11.10" UBUNTU_DISTRO_NAME=oneiric diff --git a/development/development_enviroment.sh b/development/development_enviroment.sh index c9b61c8b32..6e3dcdb26f 100644 --- a/development/development_enviroment.sh +++ b/development/development_enviroment.sh @@ -50,8 +50,11 @@ curl -d '{"auth":{"passwordCredentials":{"username": "reddwarf", "password": "RE # Also note that keystone uses the tenant id now and _not_ the name # curl -H"X-Auth-Token:$REDDWARF_TOKEN" http://0.0.0.0:8779/v0.1/$REDDWARF_TENANT/instances # curl -H"Content-type:application/json" -H"X-Auth-Token:$REDDWARF_TOKEN" \ -# http://0.0.0.0:8779/v0.1/$REDDWARF_TENANT/instances -d '{"name":"my_test","flavor":"1"}' + http://0.0.0.0:8779/v0.1/$REDDWARF_TENANT/instances -d '{"name":"my_test","flavor":"1"}' +# update the etc/reddwarf/reddwarf.conf.sample +# add this config setting +# reddwarf_tenant_id = f5f71240a97c411e977452370422d7cc # sync up the database on first run! # bin/reddwarf-manage --config-file=etc/reddwarf/reddwarf.conf.sample db_sync @@ -59,4 +62,18 @@ curl -d '{"auth":{"passwordCredentials":{"username": "reddwarf", "password": "RE # Also, you should start up the api node like this # bin/reddwarf-server --config-file=etc/reddwarf/reddwarf.conf.sample +# need to build the image before we can create a new instance +# need an rsa key to build the + +# ssh-keygen + +# build the image for reddwarf +# ./bootstrap/bootstrap.sh + +# add the image to the reddwarf database +# get the image id from glance +# glance index -A $REDDWARF_TOKEN +# (sqlite) +# sqlite3 ../../reddwarf_test.sqlite +# insert into service_images values ('a92615d7-a8ba-45ff-b29f-ec2baf6b8348','database', 'a92615d7-a8ba-45ff-b29f-ec2baf6b8348'); diff --git a/etc/reddwarf/reddwarf.conf.sample b/etc/reddwarf/reddwarf.conf.sample index de57750c20..cd080627dd 100644 --- a/etc/reddwarf/reddwarf.conf.sample +++ b/etc/reddwarf/reddwarf.conf.sample @@ -44,6 +44,8 @@ reddwarf_proxy_admin_user = admin reddwarf_proxy_admin_pass = 3de4922d8b6ac5a1aad9 reddwarf_proxy_admin_tenant_name = admin reddwarf_auth_url = http://0.0.0.0:5000/v2.0 +reddwarf_tenant_id = 60fdac4a02aa4a8e87d772c61081b16a + # ============ notifer queue kombu connection options ======================== diff --git a/reddwarf/common/exception.py b/reddwarf/common/exception.py index 9f5305a5d4..0a3ac08c8b 100644 --- a/reddwarf/common/exception.py +++ b/reddwarf/common/exception.py @@ -42,3 +42,9 @@ class DBConstraintError(ReddwarfError): class InvalidRPCConnectionReuse(ReddwarfError): message = _("Invalid RPC Connection Reuse") + + +class NotFound(ReddwarfError): + + message = _("Resource %(uuid)s cannot be found") + diff --git a/reddwarf/database/models.py b/reddwarf/database/models.py index 77ecbda04f..766640d301 100644 --- a/reddwarf/database/models.py +++ b/reddwarf/database/models.py @@ -23,9 +23,10 @@ import netaddr from reddwarf import db from reddwarf.common import config -from reddwarf.common import exception +from reddwarf.common import exception as rd_exceptions from reddwarf.common import utils from novaclient.v1_1.client import Client +from novaclient import exceptions as nova_exceptions CONFIG = config.Config LOG = logging.getLogger('reddwarf.database.models') @@ -115,12 +116,30 @@ class Instance(RemoteModelBase): _data_fields = ['name', 'status', 'updated', 'id', 'flavor'] - def __init__(self, proxy_token, uuid): - self._data_object = self.get_client(proxy_token).servers.get(uuid) + def __init__(self, server=None, proxy_token=None, uuid=None): + if server is None and proxy_token is None and uuid is None: + #TODO(cp16et): what to do now? + msg = "server, proxy_token, and uuid are not defined" + raise InvalidModelError(msg) + elif server is None: + self._data_object = self.get_client(proxy_token).servers.get(uuid) + else: + self._data_object = server @classmethod def delete(cls, proxy_token, uuid): - return cls.get_client(proxy_token).servers.delete(uuid) + try: + cls.get_client(proxy_token).servers.delete(uuid) + except nova_exceptions.NotFound, e: + raise rd_exceptions.NotFound(uuid=uuid) + except nova_exceptions.ClientException, e: + raise rd_exceptions.ReddwarfError() + + + @classmethod + def create(cls, proxy_token, name, image_id, flavor): + srv = cls.get_client(proxy_token).servers.create(name, image_id, flavor) + return Instance(server=srv) class Instances(Instance): @@ -194,7 +213,7 @@ def persisted_models(): } -class InvalidModelError(exception.ReddwarfError): +class InvalidModelError(rd_exceptions.ReddwarfError): message = _("The following values are invalid: %(errors)s") @@ -202,6 +221,6 @@ class InvalidModelError(exception.ReddwarfError): super(InvalidModelError, self).__init__(message, errors=errors) -class ModelNotFoundError(exception.ReddwarfError): +class ModelNotFoundError(rd_exceptions.ReddwarfError): message = _("Not Found") diff --git a/reddwarf/database/service.py b/reddwarf/database/service.py index 2c6266bec7..b68e763561 100644 --- a/reddwarf/database/service.py +++ b/reddwarf/database/service.py @@ -19,13 +19,13 @@ import logging import routes import webob.exc -from novaclient.v1_1.client import Client -from reddwarf.common import config +#TODO(cp16et) need to remove all novaclient references from the service +from novaclient import exceptions from reddwarf.common import wsgi +from reddwarf.common import config from reddwarf.database import models from reddwarf.database import views -from reddwarf.common import context -from reddwarf import rpc +from reddwarf.common import exception CONFIG = config.Config LOG = logging.getLogger('reddwarf.database.service') @@ -35,21 +35,7 @@ class BaseController(wsgi.Controller): """Base controller class.""" def __init__(self): - self.proxy_admin_user = CONFIG.get('reddwarf_proxy_admin_user', - 'admin') - self.proxy_admin_pass = CONFIG.get('reddwarf_proxy_admin_pass', - '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): - proxy_token = req.headers["X-Auth-Token"] - client = Client(self.proxy_admin_user, self.proxy_admin_pass, - self.proxy_admin_tenant_name, self.auth_url, token=proxy_token) - client.authenticate() - return client + pass class InstanceController(BaseController): @@ -60,21 +46,27 @@ class InstanceController(BaseController): servers = models.Instances(req.headers["X-Auth-Token"]).data() #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"}) + #TODO(cp16net): need to set the return code correctly return wsgi.Result(views.InstancesView(servers).data(), 201) def show(self, req, tenant_id, id): """Return a single instance.""" - server = models.Instance(req.headers["X-Auth-Token"], id).data() + server = models.Instance(proxy_token=req.headers["X-Auth-Token"], uuid=id).data() + #TODO(cp16net): need to set the return code correctly return wsgi.Result(views.InstanceView(server).data(), 201) def delete(self, req, tenant_id, id): """Delete a single instance.""" - result = models.Instance.delete(req.headers["X-Auth-Token"], id) + + models.Instance.delete(proxy_token=req.headers["X-Auth-Token"], uuid=id) + + # TODO(hub-cap): fixgure out why the result is coming back as None LOG.info("result of delete %s" % result) + #TODO(cp16net): need to set the return code correctly return wsgi.Result(202) def create(self, req, body, tenant_id): @@ -91,10 +83,14 @@ class InstanceController(BaseController): # This needs discussion. 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']) + server = models.Instance.create(req.headers["X-Auth-Token"], + body['name'], + image_id, + body['flavor']).data() + # Now wait for the response from the create to do additional work - return "server created %s" % server.__dict__ + #TODO(cp16net): need to set the return code correctly + return wsgi.Result(views.InstanceView(server).data(), 201) class API(wsgi.Router):