summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorDan Prince <dan.prince@rackspace.com>2011-09-07 09:28:45 -0400
committerDan Prince <dan.prince@rackspace.com>2011-09-07 09:28:45 -0400
commit1a22d1da448eb08fc4559619b450d716757b6e11 (patch)
treefca9749f448d370d8101c29316ed6cb04b9c465b /nova/api
parent2c16115e236760f3933eadd3a5d7d20dda39866d (diff)
parentd01010583d5d581591c9edcf36c4da54f0c78da9 (diff)
downloadnova-1a22d1da448eb08fc4559619b450d716757b6e11.tar.gz
nova-1a22d1da448eb08fc4559619b450d716757b6e11.tar.xz
nova-1a22d1da448eb08fc4559619b450d716757b6e11.zip
Merge w/ trunk.
Fix test_rescue_with_preset_password.
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/ec2/cloud.py13
-rw-r--r--nova/api/openstack/contrib/createserverext.py26
-rw-r--r--nova/api/openstack/schemas/v1.1/server.rng2
-rw-r--r--nova/api/openstack/servers.py22
-rw-r--r--nova/api/openstack/views/servers.py2
5 files changed, 49 insertions, 16 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index fe44191c8..049ca6f93 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -1020,14 +1020,6 @@ class CloudController(object):
'status': volume['attach_status'],
'volumeId': ec2utils.id_to_ec2_vol_id(volume_id)}
- @staticmethod
- def _convert_to_set(lst, label):
- if lst is None or lst == []:
- return None
- if not isinstance(lst, list):
- lst = [lst]
- return [{label: x} for x in lst]
-
def _format_kernel_id(self, instance_ref, result, key):
kernel_id = instance_ref['kernel_id']
if kernel_id is None:
@@ -1186,7 +1178,7 @@ class CloudController(object):
if instance.get('security_groups'):
for security_group in instance['security_groups']:
security_group_names.append(security_group['name'])
- result['groupSet'] = CloudController._convert_to_set(
+ result['groupSet'] = utils.convert_to_list_dict(
security_group_names, 'groupId')
def _format_instances(self, context, instance_id=None, use_v6=False,
@@ -1250,7 +1242,8 @@ class CloudController(object):
i['keyName'] = '%s (%s, %s)' % (i['keyName'],
instance['project_id'],
instance['host'])
- i['productCodesSet'] = self._convert_to_set([], 'product_codes')
+ i['productCodesSet'] = utils.convert_to_list_dict([],
+ 'product_codes')
self._format_instance_type(instance, i)
i['launchTime'] = instance['created_at']
i['amiLaunchIndex'] = instance['launch_index']
diff --git a/nova/api/openstack/contrib/createserverext.py b/nova/api/openstack/contrib/createserverext.py
index ba72fdb0b..af7f37f13 100644
--- a/nova/api/openstack/contrib/createserverext.py
+++ b/nova/api/openstack/contrib/createserverext.py
@@ -14,18 +14,34 @@
# License for the specific language governing permissions and limitations
# under the License
+from nova import utils
from nova.api.openstack import create_instance_helper as helper
from nova.api.openstack import extensions
from nova.api.openstack import servers
from nova.api.openstack import wsgi
-class Createserverext(extensions.ExtensionDescriptor):
- """The servers create ext
+class CreateServerController(servers.ControllerV11):
+ def _build_view(self, req, instance, is_detail=False):
+ server = super(CreateServerController, self)._build_view(req,
+ instance,
+ is_detail)
+ if is_detail:
+ self._build_security_groups(server['server'], instance)
+ return server
+
+ def _build_security_groups(self, response, inst):
+ sg_names = []
+ sec_groups = inst.get('security_groups')
+ if sec_groups:
+ sg_names = [sec_group['name'] for sec_group in sec_groups]
- Exposes addFixedIp and removeFixedIp actions on servers.
+ response['security_groups'] = utils.convert_to_list_dict(sg_names,
+ 'name')
- """
+
+class Createserverext(extensions.ExtensionDescriptor):
+ """The servers create ext"""
def get_name(self):
return "Createserverext"
@@ -58,7 +74,7 @@ class Createserverext(extensions.ExtensionDescriptor):
deserializer = wsgi.RequestDeserializer(body_deserializers)
res = extensions.ResourceExtension('os-create-server-ext',
- controller=servers.ControllerV11(),
+ controller=CreateServerController(),
deserializer=deserializer,
serializer=serializer)
resources.append(res)
diff --git a/nova/api/openstack/schemas/v1.1/server.rng b/nova/api/openstack/schemas/v1.1/server.rng
index dbd169a83..ef835e408 100644
--- a/nova/api/openstack/schemas/v1.1/server.rng
+++ b/nova/api/openstack/schemas/v1.1/server.rng
@@ -1,6 +1,8 @@
<element name="server" ns="http://docs.openstack.org/compute/api/v1.1"
xmlns="http://relaxng.org/ns/structure/1.0">
<attribute name="name"> <text/> </attribute>
+ <attribute name="userId"> <text/> </attribute>
+ <attribute name="tenantId"> <text/> </attribute>
<attribute name="id"> <text/> </attribute>
<attribute name="uuid"> <text/> </attribute>
<attribute name="updated"> <text/> </attribute>
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 3506a4bca..49f267eb9 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -881,6 +881,8 @@ class ServerXMLSerializer(wsgi.XMLDictSerializer):
def _add_server_attributes(self, node, server):
node.setAttribute('id', str(server['id']))
+ node.setAttribute('userId', str(server['user_id']))
+ node.setAttribute('tenantId', str(server['tenant_id']))
node.setAttribute('uuid', str(server['uuid']))
node.setAttribute('hostId', str(server['hostId']))
node.setAttribute('name', server['name'])
@@ -936,6 +938,11 @@ class ServerXMLSerializer(wsgi.XMLDictSerializer):
server['addresses'])
server_node.appendChild(addresses_node)
+ if 'security_groups' in server:
+ security_groups_node = self._create_security_groups_node(xml_doc,
+ server['security_groups'])
+ server_node.appendChild(security_groups_node)
+
return server_node
def _server_list_to_xml(self, xml_doc, servers, detailed):
@@ -988,6 +995,19 @@ class ServerXMLSerializer(wsgi.XMLDictSerializer):
server_dict['server'])
return self.to_xml_string(node, True)
+ def _security_group_to_xml(self, doc, security_group):
+ node = doc.createElement('security_group')
+ node.setAttribute('name', str(security_group.get('name')))
+ return node
+
+ def _create_security_groups_node(self, xml_doc, security_groups):
+ security_groups_node = xml_doc.createElement('security_groups')
+ if security_groups:
+ for security_group in security_groups:
+ node = self._security_group_to_xml(xml_doc, security_group)
+ security_groups_node.appendChild(node)
+ return security_groups_node
+
def create_resource(version='1.0'):
controller = {
@@ -999,7 +1019,7 @@ def create_resource(version='1.0'):
"attributes": {
"server": ["id", "imageId", "name", "flavorId", "hostId",
"status", "progress", "adminPass", "flavorRef",
- "imageRef"],
+ "imageRef", "userId", "tenantId"],
"link": ["rel", "type", "href"],
},
"dict_collections": {
diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py
index 3a13d15f1..ac09b5864 100644
--- a/nova/api/openstack/views/servers.py
+++ b/nova/api/openstack/views/servers.py
@@ -66,6 +66,8 @@ class ViewBuilder(object):
inst_dict = {
'id': inst['id'],
'name': inst['display_name'],
+ 'user_id': inst.get('user_id', ''),
+ 'tenant_id': inst.get('project_id', ''),
'status': common.status_from_state(vm_state, task_state)}
# Return the metadata as a dictionary