85
85
min_count=1, max_count=1,
86
86
display_name='', display_description='',
87
87
key_name=None, key_data=None, security_group='default',
88
availability_zone=None, user_data=None,
88
availability_zone=None, user_data=None, metadata=[],
90
90
"""Create the number of instances requested if quota and
91
91
other arguments check out ok.
100
100
"run %s more instances of this type.") %
101
101
num_instances, "InstanceLimitExceeded")
103
is_vpn = image_id == FLAGS.vpn_image_id
105
image = self.image_service.show(context, image_id)
106
if kernel_id is None:
107
kernel_id = image.get('kernel_id', None)
108
if ramdisk_id is None:
109
ramdisk_id = image.get('ramdisk_id', None)
110
# No kernel and ramdisk for raw images
111
if kernel_id == str(FLAGS.null_kernel):
114
LOG.debug(_("Creating a raw instance"))
115
# Make sure we have access to kernel and ramdisk (if not raw)
116
logging.debug("Using Kernel=%s, Ramdisk=%s" %
117
(kernel_id, ramdisk_id))
119
self.image_service.show(context, kernel_id)
121
self.image_service.show(context, ramdisk_id)
103
num_metadata = len(metadata)
104
quota_metadata = quota.allowed_metadata_items(context, num_metadata)
105
if quota_metadata < num_metadata:
106
pid = context.project_id
107
msg = (_("Quota exceeeded for %(pid)s,"
108
" tried to set %(num_metadata)s metadata properties")
111
raise quota.QuotaError(msg, "MetadataLimitExceeded")
113
# Because metadata is stored in the DB, we hard-code the size limits
114
# In future, we may support more variable length strings, so we act
115
# as if this is quota-controlled for forwards compatibility
116
for metadata_item in metadata:
117
k = metadata_item['key']
118
v = metadata_item['value']
119
if len(k) > 255 or len(v) > 255:
120
pid = context.project_id
121
msg = (_("Quota exceeeded for %(pid)s,"
122
" metadata property key or value too long")
125
raise quota.QuotaError(msg, "MetadataLimitExceeded")
127
image = self.image_service.show(context, image_id)
128
if kernel_id is None:
129
kernel_id = image.get('kernel_id', None)
130
if ramdisk_id is None:
131
ramdisk_id = image.get('ramdisk_id', None)
132
# No kernel and ramdisk for raw images
133
if kernel_id == str(FLAGS.null_kernel):
136
LOG.debug(_("Creating a raw instance"))
137
# Make sure we have access to kernel and ramdisk (if not raw)
138
logging.debug("Using Kernel=%s, Ramdisk=%s" %
139
(kernel_id, ramdisk_id))
141
self.image_service.show(context, kernel_id)
143
self.image_service.show(context, ramdisk_id)
123
145
if security_group is None:
124
146
security_group = ['default']
449
472
{'method': 'authorize_ajax_console',
450
473
'args': {'token': output['token'], 'host': output['host'],
451
474
'port': output['port']}})
452
return {'url': '%s?token=%s' % (FLAGS.ajax_console_proxy_url,
475
return {'url': '%s/?token=%s' % (FLAGS.ajax_console_proxy_url,
453
476
output['token'])}
455
478
def get_console_output(self, context, instance_id):
479
502
self._cast_compute_message('reset_network', context, instance_id)
504
def inject_network_info(self, context, instance_id):
506
Inject network info for the instance.
509
self._cast_compute_message('inject_network_info', context, instance_id)
481
511
def attach_volume(self, context, instance_id, volume_id, device):
482
512
if not re.match("^/dev/[a-z]d[a-z]+$", device):
483
513
raise exception.ApiError(_("Invalid device specified: %s. "