diff --git a/api-ref/source/v1/instance_serial_console.inc b/api-ref/source/v1/instance_serial_console.inc new file mode 100644 index 00000000..0e828a71 --- /dev/null +++ b/api-ref/source/v1/instance_serial_console.inc @@ -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 diff --git a/api-ref/source/v1/samples/instance_console/instance-serial-console-get.json b/api-ref/source/v1/samples/instance_console/instance-serial-console-get.json new file mode 100644 index 00000000..eefffc09 --- /dev/null +++ b/api-ref/source/v1/samples/instance_console/instance-serial-console-get.json @@ -0,0 +1,5 @@ +{ + "console": { + "url": "http://127.0.0.1:8866/?token=b4f5cb4a-8b01-40ea-ae46-67f0db4969b3" + } +} \ No newline at end of file diff --git a/mogan/api/controllers/v1/instances.py b/mogan/api/controllers/v1/instances.py index f6399c67..56969698 100644 --- a/mogan/api/controllers/v1/instances.py +++ b/mogan/api/controllers/v1/instances.py @@ -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'] } diff --git a/mogan/cmd/consoleauth.py b/mogan/cmd/consoleauth.py index 4cb50e1c..f3c5f059 100644 --- a/mogan/cmd/consoleauth.py +++ b/mogan/cmd/consoleauth.py @@ -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) diff --git a/mogan/common/policy.py b/mogan/common/policy.py index 214cca16..8f15058b 100644 --- a/mogan/common/policy.py +++ b/mogan/common/policy.py @@ -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'), ] diff --git a/mogan/engine/rpcapi.py b/mogan/engine/rpcapi.py index fb01ba11..3919b2ef 100644 --- a/mogan/engine/rpcapi.py +++ b/mogan/engine/rpcapi.py @@ -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)