72
72
raise exc.HTTPUnprocessableEntity()
74
if not 'server' in body:
75
raise exc.HTTPUnprocessableEntity()
77
server_dict = body['server']
74
78
context = req.environ['nova.context']
76
password = self.controller._get_server_admin_password(body['server'])
79
password = self.controller._get_server_admin_password(server_dict)
107
110
msg = _("Invalid flavorRef provided.")
108
111
raise exc.HTTPBadRequest(explanation=msg)
110
if not 'name' in body['server']:
113
if not 'name' in server_dict:
111
114
msg = _("Server name is not defined")
112
115
raise exc.HTTPBadRequest(explanation=msg)
114
zone_blob = body['server'].get('blob')
115
name = body['server']['name']
117
zone_blob = server_dict.get('blob')
118
name = server_dict['name']
116
119
self._validate_server_name(name)
117
120
name = name.strip()
119
reservation_id = body['server'].get('reservation_id')
120
min_count = body['server'].get('min_count')
121
max_count = body['server'].get('max_count')
122
reservation_id = server_dict.get('reservation_id')
123
min_count = server_dict.get('min_count')
124
max_count = server_dict.get('max_count')
122
125
# min_count and max_count are optional. If they exist, they come
123
126
# in as strings. We want to default 'min_count' to 1, and default
124
127
# 'max_count' to be 'min_count'.
145
148
display_description=name,
146
149
key_name=key_name,
147
150
key_data=key_data,
148
metadata=body['server'].get('metadata', {}),
151
metadata=server_dict.get('metadata', {}),
149
152
injected_files=injected_files,
150
153
admin_password=password,
151
154
zone_blob=zone_blob,
299
302
def _extract_server(self, node):
300
303
"""Marshal the server attribute of a parsed request"""
302
server_node = self._find_first_child_named(node, 'server')
305
server_node = self.find_first_child_named(node, 'server')
303
306
for attr in ["name", "imageId", "flavorId", "imageRef", "flavorRef"]:
304
307
if server_node.getAttribute(attr):
305
308
server[attr] = server_node.getAttribute(attr)
306
metadata = self._extract_metadata(server_node)
309
metadata_node = self.find_first_child_named(server_node, "metadata")
310
metadata = self.extract_metadata(metadata_node)
307
311
if metadata is not None:
308
312
server["metadata"] = metadata
309
313
personality = self._extract_personality(server_node)
311
315
server["personality"] = personality
314
def _extract_metadata(self, server_node):
315
"""Marshal the metadata attribute of a parsed request"""
316
metadata_node = self._find_first_child_named(server_node, "metadata")
317
if metadata_node is None:
320
for meta_node in self._find_children_named(metadata_node, "meta"):
321
key = meta_node.getAttribute("key")
322
metadata[key] = self._extract_text(meta_node)
325
318
def _extract_personality(self, server_node):
326
319
"""Marshal the personality attribute of a parsed request"""
327
320
personality_node = \
328
self._find_first_child_named(server_node, "personality")
321
self.find_first_child_named(server_node, "personality")
329
322
if personality_node is None:
332
for file_node in self._find_children_named(personality_node, "file"):
325
for file_node in self.find_children_named(personality_node, "file"):
334
327
if file_node.hasAttribute("path"):
335
328
item["path"] = file_node.getAttribute("path")
336
item["contents"] = self._extract_text(file_node)
329
item["contents"] = self.extract_text(file_node)
337
330
personality.append(item)
338
331
return personality
340
def _find_first_child_named(self, parent, name):
341
"""Search a nodes children for the first child with a given name"""
342
for node in parent.childNodes:
343
if node.nodeName == name:
347
def _find_children_named(self, parent, name):
348
"""Return all of a nodes children who have the given name"""
349
for node in parent.childNodes:
350
if node.nodeName == name:
353
def _extract_text(self, node):
354
"""Get the text field contained by the given node"""
355
if len(node.childNodes) == 1:
356
child = node.childNodes[0]
357
if child.nodeType == child.TEXT_NODE:
358
return child.nodeValue