73
73
is_vpn = image_id == FLAGS.vpn_image_id
75
75
image = self.image_service.show(context, image_id)
77
# If kernel_id/ramdisk_id isn't explicitly set in API call
78
# we take the defaults from the image's metadata
76
79
if kernel_id is None:
77
kernel_id = image.get('kernelId', FLAGS.default_kernel)
80
kernel_id = image.get('kernelId', None)
78
81
if ramdisk_id is None:
79
ramdisk_id = image.get('ramdiskId', FLAGS.default_ramdisk)
82
ramdisk_id = image.get('ramdiskId', None)
81
84
# Make sure we have access to kernel and ramdisk
82
self.image_service.show(context, kernel_id)
83
self.image_service.show(context, ramdisk_id)
86
self.image_service.show(context, kernel_id)
88
self.image_service.show(context, ramdisk_id)
85
90
if security_group is None:
86
91
security_group = ['default']
104
109
'reservation_id': utils.generate_uid('r'),
105
110
'image_id': image_id,
106
'kernel_id': kernel_id,
107
'ramdisk_id': ramdisk_id,
111
'kernel_id': kernel_id or '',
112
'ramdisk_id': ramdisk_id or '',
108
113
'state_description': 'scheduling',
109
114
'user_id': context.user_id,
110
115
'project_id': context.project_id,
121
126
elevated = context.elevated()
123
logging.debug("Going to run %s instances...", num_instances)
128
logging.debug(_("Going to run %s instances..."), num_instances)
124
129
for num in range(num_instances):
125
130
instance = dict(mac_address=utils.generate_mac(),
126
131
launch_index=num,
157
162
{"method": "setup_fixed_ip",
158
163
"args": {"address": address}})
160
logging.debug("Casting to scheduler for %s/%s's instance %s",
165
logging.debug(_("Casting to scheduler for %s/%s's instance %s"),
161
166
context.project_id, context.user_id, instance_id)
162
167
rpc.cast(context,
163
168
FLAGS.scheduler_topic,
204
209
instance = self.db.instance_get_by_internal_id(context,
206
211
except exception.NotFound as e:
207
logging.warning("Instance %d was not found during terminate",
212
logging.warning(_("Instance %d was not found during terminate"),
211
216
if (instance['state_description'] == 'terminating'):
212
logging.warning("Instance %d is already being terminated",
217
logging.warning(_("Instance %d is already being terminated"),
223
228
address = self.db.instance_get_floating_address(context,
226
logging.debug("Disassociating address %s" % address)
231
logging.debug(_("Disassociating address %s") % address)
227
232
# NOTE(vish): Right now we don't really care if the ip is
228
233
# disassociated. We may need to worry about
229
234
# checking this later. Perhaps in the scheduler?
235
240
address = self.db.instance_get_fixed_address(context, instance['id'])
237
logging.debug("Deallocating address %s" % address)
242
logging.debug(_("Deallocating address %s") % address)
238
243
# NOTE(vish): Currently, nothing needs to be done on the
239
244
# network node until release. If this changes,
240
245
# we will need to cast here.
275
280
{"method": "reboot_instance",
276
281
"args": {"instance_id": instance['id']}})
283
def pause(self, context, instance_id):
284
"""Pause the given instance."""
285
instance = self.db.instance_get_by_internal_id(context, instance_id)
286
host = instance['host']
288
self.db.queue_get_for(context, FLAGS.compute_topic, host),
289
{"method": "pause_instance",
290
"args": {"instance_id": instance['id']}})
292
def unpause(self, context, instance_id):
293
"""Unpause the given instance."""
294
instance = self.db.instance_get_by_internal_id(context, instance_id)
295
host = instance['host']
297
self.db.queue_get_for(context, FLAGS.compute_topic, host),
298
{"method": "unpause_instance",
299
"args": {"instance_id": instance['id']}})
278
301
def rescue(self, context, instance_id):
279
302
"""Rescue the given instance."""
280
303
instance = self.db.instance_get_by_internal_id(context, instance_id)