updates to get create working

This commit is contained in:
Craig Vyvial 2012-03-07 20:53:17 -06:00
parent 64c73ab996
commit acbbdf1027
6 changed files with 74 additions and 34 deletions

View File

@ -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

View File

@ -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');

View File

@ -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 ========================

View File

@ -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")

View File

@ -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")

View File

@ -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):