summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorRick Harris <rick.harris@rackspace.com>2010-12-30 11:26:21 -0600
committerRick Harris <rick.harris@rackspace.com>2010-12-30 11:26:21 -0600
commit2a08bed775aef2574d362cee6b7883469bbd2e09 (patch)
tree89d43a89758150efccca52900d0829dc48653a55 /nova
parentcc906e48c13012da552cc346146d9586afc6092e (diff)
parent0880026253d0de67afd7c80415b332f72764457d (diff)
Merging trunk
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/__init__.py2
-rw-r--r--nova/api/openstack/backup_schedules.py15
-rw-r--r--nova/api/openstack/ratelimiting/__init__.py4
-rw-r--r--nova/api/openstack/servers.py33
-rw-r--r--nova/api/openstack/sharedipgroups.py39
-rw-r--r--nova/tests/test_scheduler.py1
-rw-r--r--nova/tests/test_virt.py1
-rw-r--r--nova/virt/libvirt_conn.py17
-rw-r--r--nova/wsgi.py2
9 files changed, 83 insertions, 31 deletions
diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py
index bebcdc18c..66aceee2d 100644
--- a/nova/api/openstack/__init__.py
+++ b/nova/api/openstack/__init__.py
@@ -100,7 +100,7 @@ class APIRouter(wsgi.Router):
collection={'detail': 'GET'},
member=server_members)
- mapper.resource("backup_schedule", "backup_schedules",
+ mapper.resource("backup_schedule", "backup_schedule",
controller=backup_schedules.Controller(),
parent_resource=dict(member_name='server',
collection_name='servers'))
diff --git a/nova/api/openstack/backup_schedules.py b/nova/api/openstack/backup_schedules.py
index fc70b5c6c..fcc07bdd3 100644
--- a/nova/api/openstack/backup_schedules.py
+++ b/nova/api/openstack/backup_schedules.py
@@ -23,13 +23,25 @@ from nova.api.openstack import faults
import nova.image.service
+def _translate_keys(inst):
+ """ Coerces the backup schedule into proper dictionary format """
+ return dict(backupSchedule=inst)
+
+
class Controller(wsgi.Controller):
+ """ The backup schedule API controller for the Openstack API """
+
+ _serialization_metadata = {
+ 'application/xml': {
+ 'attributes': {
+ 'backupSchedule': []}}}
def __init__(self):
pass
def index(self, req, server_id):
- return faults.Fault(exc.HTTPNotFound())
+ """ Returns the list of backup schedules for a given instance """
+ return _translate_keys({})
def create(self, req, server_id):
""" No actual update method required, since the existing API allows
@@ -37,4 +49,5 @@ class Controller(wsgi.Controller):
return faults.Fault(exc.HTTPNotFound())
def delete(self, req, server_id, id):
+ """ Deletes an existing backup schedule """
return faults.Fault(exc.HTTPNotFound())
diff --git a/nova/api/openstack/ratelimiting/__init__.py b/nova/api/openstack/ratelimiting/__init__.py
index 91a8b2e55..cbb4b897e 100644
--- a/nova/api/openstack/ratelimiting/__init__.py
+++ b/nova/api/openstack/ratelimiting/__init__.py
@@ -64,9 +64,9 @@ class RateLimitingMiddleware(wsgi.Middleware):
If the request should be rate limited, return a 413 status with a
Retry-After header giving the time when the request would succeed.
"""
- return self.limited_request(req, self.application)
+ return self.rate_limited_request(req, self.application)
- def limited_request(self, req, application):
+ def rate_limited_request(self, req, application):
"""Rate limit the request.
If the request should be rate limited, return a 413 status with a
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 10c397384..845183258 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -35,14 +35,11 @@ LOG = logging.getLogger('server')
LOG.setLevel(logging.DEBUG)
-def _entity_list(entities):
- """ Coerces a list of servers into proper dictionary format """
- return dict(servers=entities)
-
-
-def _entity_detail(inst):
- """ Maps everything to Rackspace-like attributes for return"""
+def _translate_detail_keys(inst):
+ """ Coerces into dictionary format, mapping everything to Rackspace-like
+ attributes for return"""
power_mapping = {
+ None: 'build',
power_state.NOSTATE: 'build',
power_state.RUNNING: 'active',
power_state.BLOCKED: 'active',
@@ -67,8 +64,9 @@ def _entity_detail(inst):
return dict(server=inst_dict)
-def _entity_inst(inst):
- """ Filters all model attributes save for id and name """
+def _translate_keys(inst):
+ """ Coerces into dictionary format, excluding all model attributes
+ save for id and name """
return dict(server=dict(id=inst['internal_id'], name=inst['display_name']))
@@ -87,29 +85,29 @@ class Controller(wsgi.Controller):
def index(self, req):
""" Returns a list of server names and ids for a given user """
- return self._items(req, entity_maker=_entity_inst)
+ return self._items(req, entity_maker=_translate_keys)
def detail(self, req):
""" Returns a list of server details for a given user """
- return self._items(req, entity_maker=_entity_detail)
+ return self._items(req, entity_maker=_translate_detail_keys)
def _items(self, req, entity_maker):
"""Returns a list of servers for a given user.
- entity_maker - either _entity_detail or _entity_inst
+ entity_maker - either _translate_detail_keys or _translate_keys
"""
instance_list = self.compute_api.get_instances(
req.environ['nova.context'])
limited_list = common.limited(instance_list, req)
res = [entity_maker(inst)['server'] for inst in limited_list]
- return _entity_list(res)
+ return dict(servers=res)
def show(self, req, id):
""" Returns server details by server id """
try:
instance = self.compute_api.get_instance(
req.environ['nova.context'], int(id))
- return _entity_detail(instance)
+ return _translate_detail_keys(instance)
except exception.NotFound:
return faults.Fault(exc.HTTPNotFound())
@@ -138,7 +136,7 @@ class Controller(wsgi.Controller):
description=env['server']['name'],
key_name=key_pair['name'],
key_data=key_pair['public_key'])
- return _entity_inst(instances[0])
+ return _translate_keys(instances[0])
def update(self, req, id):
""" Updates the server name or password """
@@ -153,8 +151,9 @@ class Controller(wsgi.Controller):
update_dict['display_name'] = inst_dict['server']['name']
try:
- self.compute_api.update_instance(req.environ['nova.context'],
- instance['id'],
+ ctxt = req.environ['nova.context']
+ self.compute_api.update_instance(ctxt,
+ id,
**update_dict)
except exception.NotFound:
return faults.Fault(exc.HTTPNotFound())
diff --git a/nova/api/openstack/sharedipgroups.py b/nova/api/openstack/sharedipgroups.py
index 75d02905c..845f5bead 100644
--- a/nova/api/openstack/sharedipgroups.py
+++ b/nova/api/openstack/sharedipgroups.py
@@ -15,26 +15,51 @@
# License for the specific language governing permissions and limitations
# under the License.
+from webob import exc
+
from nova import wsgi
+from nova.api.openstack import faults
+
+
+def _translate_keys(inst):
+ """ Coerces a shared IP group instance into proper dictionary format """
+ return dict(sharedIpGroup=inst)
+
+
+def _translate_detail_keys(inst):
+ """ Coerces a shared IP group instance into proper dictionary format with
+ correctly mapped attributes """
+ return dict(sharedIpGroup=inst)
class Controller(wsgi.Controller):
""" The Shared IP Groups Controller for the Openstack API """
+ _serialization_metadata = {
+ 'application/xml': {
+ 'attributes': {
+ 'sharedIpGroup': []}}}
+
def index(self, req):
- raise NotImplementedError
+ """ Returns a list of Shared IP Groups for the user """
+ return dict(sharedIpGroups=[])
def show(self, req, id):
- raise NotImplementedError
+ """ Shows in-depth information on a specific Shared IP Group """
+ return _translate_keys({})
def update(self, req, id):
- raise NotImplementedError
+ """ You can't update a Shared IP Group """
+ raise faults.Fault(exc.HTTPNotImplemented())
def delete(self, req, id):
- raise NotImplementedError
+ """ Deletes a Shared IP Group """
+ raise faults.Fault(exc.HTTPNotFound())
- def detail(self, req):
- raise NotImplementedError
+ def detail(self, req, id):
+ """ Returns a complete list of Shared IP Groups """
+ return _translate_detail_keys({})
def create(self, req):
- raise NotImplementedError
+ """ Creates a new Shared IP group """
+ raise faults.Fault(exc.HTTPNotFound())
diff --git a/nova/tests/test_scheduler.py b/nova/tests/test_scheduler.py
index 91517cc5d..78e4a1c77 100644
--- a/nova/tests/test_scheduler.py
+++ b/nova/tests/test_scheduler.py
@@ -33,6 +33,7 @@ from nova.scheduler import driver
FLAGS = flags.FLAGS
flags.DECLARE('max_cores', 'nova.scheduler.simple')
+flags.DECLARE('stub_network', 'nova.compute.manager')
class TestDriver(driver.Scheduler):
diff --git a/nova/tests/test_virt.py b/nova/tests/test_virt.py
index 1c155abe4..4aa489d08 100644
--- a/nova/tests/test_virt.py
+++ b/nova/tests/test_virt.py
@@ -33,6 +33,7 @@ flags.DECLARE('instances_path', 'nova.compute.manager')
class LibvirtConnTestCase(test.TestCase):
def setUp(self):
super(LibvirtConnTestCase, self).setUp()
+ libvirt_conn._late_load_cheetah()
self.flags(fake_call=True)
self.manager = manager.AuthManager()
self.user = self.manager.create_user('fake', 'fake', 'fake',
diff --git a/nova/virt/libvirt_conn.py b/nova/virt/libvirt_conn.py
index 5606865fe..3a9e58b50 100644
--- a/nova/virt/libvirt_conn.py
+++ b/nova/virt/libvirt_conn.py
@@ -58,10 +58,9 @@ from nova.compute import instance_types
from nova.compute import power_state
from nova.virt import images
-from Cheetah.Template import Template
-
libvirt = None
libxml2 = None
+Template = None
FLAGS = flags.FLAGS
@@ -69,6 +68,9 @@ FLAGS = flags.FLAGS
flags.DEFINE_string('rescue_image_id', 'ami-rescue', 'Rescue ami image')
flags.DEFINE_string('rescue_kernel_id', 'aki-rescue', 'Rescue aki image')
flags.DEFINE_string('rescue_ramdisk_id', 'ari-rescue', 'Rescue ari image')
+flags.DEFINE_string('injected_network_template',
+ utils.abspath('virt/interfaces.template'),
+ 'Template file for injected network')
flags.DEFINE_string('libvirt_xml_template',
utils.abspath('virt/libvirt.xml.template'),
'Libvirt XML Template')
@@ -88,15 +90,26 @@ flags.DEFINE_bool('allow_project_net_traffic',
def get_connection(read_only):
# These are loaded late so that there's no need to install these
# libraries when not using libvirt.
+ # Cheetah is separate because the unit tests want to load Cheetah,
+ # but not libvirt.
global libvirt
global libxml2
if libvirt is None:
libvirt = __import__('libvirt')
if libxml2 is None:
libxml2 = __import__('libxml2')
+ _late_load_cheetah()
return LibvirtConnection(read_only)
+def _late_load_cheetah():
+ global Template
+ if Template is None:
+ t = __import__('Cheetah.Template', globals(), locals(), ['Template'],
+ -1)
+ Template = t.Template
+
+
def _get_net_and_mask(cidr):
net = IPy.IP(cidr)
return str(net.net()), str(net.netmask())
diff --git a/nova/wsgi.py b/nova/wsgi.py
index c7ee9ed14..b5d6b96c1 100644
--- a/nova/wsgi.py
+++ b/nova/wsgi.py
@@ -270,7 +270,7 @@ class Serializer(object):
needed to serialize a dictionary to that type.
"""
self.metadata = metadata or {}
- req = webob.Request(environ)
+ req = webob.Request.blank('', environ)
suffix = req.path_info.split('.')[-1].lower()
if suffix == 'json':
self.handler = self._to_json