Expose the API of getting console info

Change-Id: I41c95d924b29885148077e418e0453e3ed001c9e
Partially-Implements: bp console-support
This commit is contained in:
liusheng 2017-03-14 14:39:50 +08:00
parent 4119c0012d
commit ddf694a7c8
6 changed files with 71 additions and 3 deletions

View File

@ -0,0 +1,35 @@
.. -*- rst -*-
========================
Instance Serial Console
========================
Instances Serial Console can be managed through serial_console sub-resource.
Instance Serial Console Summary
===============================
.. rest_method:: GET /v1/instances/{instance_uuid}/serial_console
Get the console url info of the Instance.
Normal response code: 200
Request
-------
.. rest_parameters:: parameters.yaml
- instance_uuid: instance_ident
Response
--------
.. rest_parameters:: parameters.yaml
- console: console_info
**Example instance network:**
.. literalinclude:: samples/instance_console/instance-serial-console-get.json

View File

@ -0,0 +1,5 @@
{
"console": {
"url": "http://127.0.0.1:8866/?token=b4f5cb4a-8b01-40ea-ae46-67f0db4969b3"
}
}

View File

@ -470,6 +470,29 @@ class InstanceCollection(base.APIBase):
return collection
class InstanceConsole(base.APIBase):
"""API representation of the console of an instance."""
console = {wtypes.text: types.jsontype}
"""The console information of the instance"""
class InstanceSerialConsoleController(InstanceControllerBase):
"""REST controller for Instance."""
@policy.authorize_wsgi("mogan:instance", "get_serial_console")
@expose.expose(InstanceConsole, types.uuid)
def get(self, instance_uuid):
"""Get the serial console info of the instance.
:param instance_uuid: the UUID of a instance.
"""
instance_obj = self._resource or self._get_resource(instance_uuid)
console = pecan.request.engine_api.get_serial_console(
pecan.request.context, instance_obj)
return InstanceConsole(console=console)
class InstanceController(InstanceControllerBase):
"""REST controller for Instance."""
@ -479,6 +502,9 @@ class InstanceController(InstanceControllerBase):
networks = InstanceNetworksController()
"""Expose the network controller action as a sub-element of instances"""
serial_console = InstanceSerialConsoleController()
"""Expose the console controller of instances"""
_custom_actions = {
'detail': ['GET']
}

View File

@ -32,8 +32,7 @@ def main():
# Parse config file and command line options, then start logging
mogan_service.prepare_service(sys.argv)
mgr = mogan_service.RPCService(CONF.host,
'mogan.consoleauth.manager',
mgr = mogan_service.RPCService('mogan.consoleauth.manager',
'ConsoleAuthManager',
constants.MANAGER_CONSOLEAUTH_TOPIC)

View File

@ -108,6 +108,9 @@ instance_policies = [
policy.RuleDefault('mogan:instance:set_provision_state',
'rule:default',
description='Set the provision state of an instance'),
policy.RuleDefault('mogan:instance:get_serial_console',
'rule:default',
description='Get serial console for an instance'),
]

View File

@ -82,4 +82,4 @@ class EngineAPI(object):
def get_serial_console(self, context, instance):
cctxt = self.client.prepare(topic=self.topic, server=CONF.host)
return cctxt.call(context, 'get_serial_console',
instance_uuid=instance)
instance=instance)