api: add serial console API calls v2.1/v3
This is a followup patch to:
api: add serial console API calls v2
    (https://review.openstack.org/#/c/113966/)
To add missing v3 APIs
Change-Id: I56a045d9b690ea36753513575a2023582da58e42
Patial-Implements: blueprint v2-on-v3-api
			
			
This commit is contained in:
		@@ -0,0 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
    "os-getSerialConsole": {
 | 
			
		||||
        "type": "serial"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
    "console": {
 | 
			
		||||
        "type": "serial",
 | 
			
		||||
        "url":"ws://127.0.0.1:6083/?token=f9906a48-b71e-4f18-baca-c987da3ebdb3"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -123,6 +123,32 @@ class RemoteConsolesController(wsgi.Controller):
 | 
			
		||||
 | 
			
		||||
        return {'console': {'type': console_type, 'url': output['url']}}
 | 
			
		||||
 | 
			
		||||
    @extensions.expected_errors((404, 409, 501))
 | 
			
		||||
    @wsgi.action('os-getSerialConsole')
 | 
			
		||||
    @validation.schema(remote_consoles.get_serial_console)
 | 
			
		||||
    def get_serial_console(self, req, id, body):
 | 
			
		||||
        """Get connection to a serial console."""
 | 
			
		||||
        context = req.environ['nova.context']
 | 
			
		||||
        authorize(context)
 | 
			
		||||
 | 
			
		||||
        # If type is not supplied or unknown get_serial_console below will cope
 | 
			
		||||
        console_type = body['os-getSerialConsole'].get('type')
 | 
			
		||||
        try:
 | 
			
		||||
            instance = self.compute_api.get(context, id, want_objects=True)
 | 
			
		||||
            output = self.compute_api.get_serial_console(context,
 | 
			
		||||
                                                         instance,
 | 
			
		||||
                                                         console_type)
 | 
			
		||||
        except exception.InstanceNotFound as e:
 | 
			
		||||
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
 | 
			
		||||
        except exception.InstanceNotReady as e:
 | 
			
		||||
            raise webob.exc.HTTPConflict(explanation=e.format_message())
 | 
			
		||||
        except NotImplementedError:
 | 
			
		||||
            msg = _("Unable to get serial console, "
 | 
			
		||||
                    "functionality not implemented")
 | 
			
		||||
            raise webob.exc.HTTPNotImplemented(explanation=msg)
 | 
			
		||||
 | 
			
		||||
        return {'console': {'type': console_type, 'url': output['url']}}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class RemoteConsoles(extensions.V3APIExtensionBase):
 | 
			
		||||
    """Interactive Console support."""
 | 
			
		||||
 
 | 
			
		||||
@@ -68,3 +68,22 @@ get_rdp_console = {
 | 
			
		||||
    'required': ['os-getRDPConsole'],
 | 
			
		||||
    'additionalProperties': False,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
get_serial_console = {
 | 
			
		||||
    'type': 'object',
 | 
			
		||||
    'properties': {
 | 
			
		||||
        'os-getSerialConsole': {
 | 
			
		||||
            'type': 'object',
 | 
			
		||||
            'properties': {
 | 
			
		||||
                'type': {
 | 
			
		||||
                    'type': 'string',
 | 
			
		||||
                    'enum': ['serial'],
 | 
			
		||||
                },
 | 
			
		||||
            },
 | 
			
		||||
            'required': ['type'],
 | 
			
		||||
            'additionalProperties': False,
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
    'required': ['os-getSerialConsole'],
 | 
			
		||||
    'additionalProperties': False,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
    "os-getSerialConsole": {
 | 
			
		||||
        "type": "serial"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
    "console": {
 | 
			
		||||
        "type": "serial",
 | 
			
		||||
        "url": "ws://127.0.0.1:6083/?token=%(uuid)s"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -24,6 +24,7 @@ class ConsolesSampleJsonTests(test_servers.ServersSampleBase):
 | 
			
		||||
        self.flags(vnc_enabled=True)
 | 
			
		||||
        self.flags(enabled=True, group='spice')
 | 
			
		||||
        self.flags(enabled=True, group='rdp')
 | 
			
		||||
        self.flags(enabled=True, group='serial_console')
 | 
			
		||||
 | 
			
		||||
    def test_get_vnc_console(self):
 | 
			
		||||
        uuid = self._post_server()
 | 
			
		||||
@@ -56,3 +57,14 @@ class ConsolesSampleJsonTests(test_servers.ServersSampleBase):
 | 
			
		||||
            "((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)"
 | 
			
		||||
        self._verify_response('get-rdp-console-post-resp', subs,
 | 
			
		||||
                              response, 200)
 | 
			
		||||
 | 
			
		||||
    def test_get_serial_console(self):
 | 
			
		||||
        uuid = self._post_server()
 | 
			
		||||
        response = self._do_post('servers/%s/action' % uuid,
 | 
			
		||||
                                 'get-serial-console-post-req',
 | 
			
		||||
                                {'action': 'os-getSerialConsole'})
 | 
			
		||||
        subs = self._get_regexes()
 | 
			
		||||
        subs["url"] = \
 | 
			
		||||
            "((ws?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)"
 | 
			
		||||
        self._verify_response('get-serial-console-post-resp', subs,
 | 
			
		||||
                              response, 200)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user