Merge "Adds implementation for VNC console extension"

This commit is contained in:
Jenkins
2013-07-23 03:45:40 +00:00
committed by Gerrit Code Review
5 changed files with 120 additions and 0 deletions

View File

@@ -131,3 +131,8 @@ class ComputeHypervisors(object):
class InstanceAuthStrategies(object):
PASSWORD = 'password'
KEY = 'key'
class VncConsoleTypes(object):
NOVNC = 'novnc'
XVPVNC = 'xvpvnc'

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,46 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from cafe.engine.clients.rest import AutoMarshallingRestClient
from cloudcafe.compute.extensions.vnc_console_api.models.vnc_console import \
GetConsole, VncConsole
class VncConsoleClient(AutoMarshallingRestClient):
def __init__(self, url, auth_token, serialize_format=None,
deserialize_format=None):
super(VncConsoleClient, self).__init__(serialize_format,
deserialize_format)
self.auth_token = auth_token
self.default_headers['X-Auth-Token'] = auth_token
ct = ''.join(['application/', self.serialize_format])
accept = ''.join(['application/', self.deserialize_format])
self.default_headers['Content-Type'] = ct
self.default_headers['Accept'] = accept
self.url = url
def get_vnc_console(self, server_id, vnc_type, tenant_id=None,
requestslib_kwargs=None):
request = GetConsole(vnc_type=vnc_type, tenant_id=tenant_id)
url = '{base_url}/servers/{server_id}/action'.format(
base_url=self.url, server_id=server_id)
resp = self.request('POST', url,
response_entity_type=VncConsole,
request_entity=request,
requestslib_kwargs=requestslib_kwargs)
return resp

View File

@@ -0,0 +1,15 @@
"""
Copyright 2013 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

View File

@@ -0,0 +1,39 @@
import json
from cafe.engine.models.base import AutoMarshallingModel
class GetConsole(AutoMarshallingModel):
def __init__(self, vnc_type=None, tenant_id=None):
super(GetConsole, self).__init__()
self.vnc_type = vnc_type
self.tenant_id = tenant_id
def _obj_to_json(self):
ret = {'os-getVNCConsole': self._obj_to_dict()}
return json.dumps(ret)
def _obj_to_dict(self):
ret = {}
ret['type'] = self.vnc_type
ret['tenant_id'] = self.tenant_id
self._remove_empty_values(ret)
return ret
class VncConsole(AutoMarshallingModel):
def __init__(self, vnc_type=None, url=None):
super(VncConsole, self).__init__()
self.type = vnc_type
self.url = url
@classmethod
def _json_to_obj(cls, serialized_str):
json_dict = json.loads(serialized_str)
console_dict = json_dict.get('console')
console = VncConsole(vnc_type=console_dict.get('type'),
url=console_dict.get('url'))
return console