added admin api call for injecting network info, added api test for inject network info

This commit is contained in:
Trey Morris
2011-02-18 16:42:26 -06:00
parent fa29dc0433
commit e369f28424
6 changed files with 50 additions and 0 deletions

View File

@@ -80,6 +80,7 @@ class APIRouter(wsgi.Router):
server_members['suspend'] = 'POST'
server_members['resume'] = 'POST'
server_members['reset_network'] = 'POST'
server_members['inject_network_info'] = 'POST'
mapper.resource("server", "servers", controller=servers.Controller(),
collection={'detail': 'GET'},

View File

@@ -263,6 +263,20 @@ class Controller(wsgi.Controller):
return faults.Fault(exc.HTTPUnprocessableEntity())
return exc.HTTPAccepted()
def inject_network_info(self, req, id):
"""
Inject network info for an instance (admin only).
"""
context = req.environ['nova.context']
try:
self.compute_api.inject_network_info(context, id)
except:
readable = traceback.format_exc()
LOG.exception(_("Compute.api::inject_network_info %s"), readable)
return faults.Fault(exc.HTTPUnprocessableEntity())
return exc.HTTPAccepted()
def pause(self, req, id):
""" Permit Admins to Pause the server. """
ctxt = req.environ['nova.context']

View File

@@ -473,6 +473,13 @@ class API(base.Base):
"""
self._cast_compute_message('reset_network', context, instance_id)
def inject_network_info(self, context, instance_id):
"""
Inject network info for the instance.
"""
self._cast_compute_message('inject_network_info', context, instance_id)
def attach_volume(self, context, instance_id, volume_id, device):
if not re.match("^/dev/[a-z]d[a-z]+$", device):
raise exception.ApiError(_("Invalid device specified: %s. "

View File

@@ -510,6 +510,18 @@ class ComputeManager(manager.Manager):
context=context)
self.driver.reset_network(instance_ref)
@checks_instance_lock
def inject_network_info(self, context, instance_id):
"""
Inject network info for the instance.
"""
context = context.elevated()
instance_ref = self.db.instance_get(context, instance_id)
LOG.debug(_('instance %s: inject network info'), instance_id,
context=context)
self.driver.inject_network_info(instance_ref)
@exception.wrap_exception
def get_console_output(self, context, instance_id):
"""Send the console output for an instance."""

View File

@@ -293,6 +293,18 @@ class ServersTest(unittest.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
def test_server_inject_network_info(self):
FLAGS.allow_admin_api = True
body = dict(server=dict(
name='server_test', imageId=2, flavorId=2, metadata={},
personality={}))
req = webob.Request.blank('/v1.0/servers/1/inject_network_info')
req.method = 'POST'
req.content_type = 'application/json'
req.body = json.dumps(body)
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)
def test_server_diagnostics(self):
req = webob.Request.blank("/v1.0/servers/1/diagnostics")
req.method = "GET"

View File

@@ -192,6 +192,10 @@ class XenAPIConnection(object):
"""reset networking for specified instance"""
self._vmops.reset_network(instance)
def inject_network_info(self, instance):
"""inject network info for specified instance"""
self._vmops.inject_network_info(instance)
def get_info(self, instance_id):
"""Return data about VM instance"""
return self._vmops.get_info(instance_id)