64
63
inst_dict['addresses'] = dict(public=[], private=[])
66
65
# grab single private fixed ip
68
private_ip = inst['fixed_ip']['address']
70
inst_dict['addresses']['private'].append(private_ip)
72
LOG.debug(_("Failed to read private ip"))
66
private_ips = utils.get_from_path(inst, 'fixed_ip/address')
67
inst_dict['addresses']['private'] = private_ips
74
69
# grab all public floating ips
76
for floating in inst['fixed_ip']['floating_ips']:
77
inst_dict['addresses']['public'].append(floating['address'])
79
LOG.debug(_("Failed to read public ip(s)"))
70
public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address')
71
inst_dict['addresses']['public'] = public_ips
81
inst_dict['metadata'] = {}
82
73
inst_dict['hostId'] = ''
75
# Return the metadata as a dictionary
77
for item in inst['metadata']:
78
metadata[item['key']] = item['value']
79
inst_dict['metadata'] = metadata
84
81
return dict(server=inst_dict)
149
146
return image['properties'][param]
151
raise exception.NotFound(
152
149
_("%(param)s property not found for image %(_image_id)s") %
155
153
image_id = str(image_id)
156
154
image = self._image_service.show(req.environ['nova.context'], image_id)
163
161
return faults.Fault(exc.HTTPUnprocessableEntity())
165
key_pair = auth_manager.AuthManager.get_key_pairs(
166
req.environ['nova.context'])[0]
163
context = req.environ['nova.context']
164
key_pairs = auth_manager.AuthManager.get_key_pairs(context)
166
raise exception.NotFound(_("No keypairs defined"))
167
key_pair = key_pairs[0]
167
169
image_id = common.get_image_id_from_image_hash(self._image_service,
168
req.environ['nova.context'], env['server']['imageId'])
170
context, env['server']['imageId'])
169
171
kernel_id, ramdisk_id = self._get_kernel_ramdisk_from_image(
174
# Metadata is a list, not a Dictionary, because we allow duplicate keys
175
# (even though JSON can't encode this)
176
# In future, we may not allow duplicate keys.
177
# However, the CloudServers API is not definitive on this front,
178
# and we want to be compatible.
180
if env['server'].get('metadata'):
181
for k, v in env['server']['metadata'].items():
182
metadata.append({'key': k, 'value': v})
171
184
instances = self.compute_api.create(
172
req.environ['nova.context'],
173
186
instance_types.get_by_flavor_id(env['server']['flavorId']),
175
188
kernel_id=kernel_id,
178
191
display_description=env['server']['name'],
179
192
key_name=key_pair['name'],
180
193
key_data=key_pair['public_key'],
181
195
onset_files=env.get('onset_files', []))
182
196
return _translate_keys(instances[0])
326
340
return faults.Fault(exc.HTTPUnprocessableEntity())
327
341
return exc.HTTPAccepted()
343
def inject_network_info(self, req, id):
345
Inject network info for an instance (admin only).
348
context = req.environ['nova.context']
350
self.compute_api.inject_network_info(context, id)
352
readable = traceback.format_exc()
353
LOG.exception(_("Compute.api::inject_network_info %s"), readable)
354
return faults.Fault(exc.HTTPUnprocessableEntity())
355
return exc.HTTPAccepted()
329
357
def pause(self, req, id):
330
358
""" Permit Admins to Pause the server. """
331
359
ctxt = req.environ['nova.context']