44
44
cfg.BoolOpt('limit_cpu_features',
46
46
help='Required for live migration among '
47
'hosts with different CPU features'),
47
'hosts with different CPU features',
48
deprecated_group='DEFAULT'),
48
49
cfg.BoolOpt('config_drive_inject_password',
50
help='Sets the admin password in the config drive image'),
51
help='Sets the admin password in the config drive image',
52
deprecated_group='DEFAULT'),
51
53
cfg.StrOpt('qemu_img_cmd',
52
54
default="qemu-img.exe",
53
55
help='qemu-img is used to convert between '
54
'different image types'),
56
'different image types',
57
deprecated_group='DEFAULT'),
55
58
cfg.BoolOpt('config_drive_cdrom',
57
60
help='Attaches the Config Drive image as a cdrom drive '
58
'instead of a disk drive')
61
'instead of a disk drive',
62
deprecated_group='DEFAULT')
62
CONF.register_opts(hyperv_opts)
66
CONF.register_opts(hyperv_opts, 'hyperv')
63
67
CONF.import_opt('use_cow_images', 'nova.virt.driver')
64
68
CONF.import_opt('network_api_class', 'nova.network')
111
115
'num_cpu': info['NumberOfProcessors'],
112
116
'cpu_time': info['UpTime']}
114
def _create_boot_vhd(self, context, instance):
118
def _create_root_vhd(self, context, instance):
115
119
base_vhd_path = self._imagecache.get_cached_image(context, instance)
116
boot_vhd_path = self._pathutils.get_vhd_path(instance['name'])
118
if CONF.use_cow_images:
119
LOG.debug(_("Creating differencing VHD. Parent: "
120
"%(base_vhd_path)s, Target: %(boot_vhd_path)s")
122
self._vhdutils.create_differencing_vhd(boot_vhd_path,
125
self._pathutils.copyfile(base_vhd_path, boot_vhd_path)
120
root_vhd_path = self._pathutils.get_vhd_path(instance['name'])
123
if CONF.use_cow_images:
124
LOG.debug(_("Creating differencing VHD. Parent: "
125
"%(base_vhd_path)s, Target: %(root_vhd_path)s")
127
self._vhdutils.create_differencing_vhd(root_vhd_path,
130
LOG.debug(_("Copying VHD image %(base_vhd_path)s to target: "
131
"%(root_vhd_path)s") % locals())
132
self._pathutils.copyfile(base_vhd_path, root_vhd_path)
134
base_vhd_info = self._vhdutils.get_vhd_info(base_vhd_path)
135
base_vhd_size = base_vhd_info['MaxInternalSize']
136
root_vhd_size = instance['root_gb'] * 1024 ** 3
138
if root_vhd_size < base_vhd_size:
139
raise vmutils.HyperVException(_("Cannot resize a VHD to a "
141
elif root_vhd_size > base_vhd_size:
142
LOG.debug(_("Resizing VHD %(root_vhd_path)s to new "
143
"size %(root_vhd_size)s") % locals())
144
self._vhdutils.resize_vhd(root_vhd_path, root_vhd_size)
146
with excutils.save_and_reraise_exception():
147
if self._pathutils.exists(root_vhd_path):
148
self._pathutils.remove(root_vhd_path)
128
152
def spawn(self, context, instance, image_meta, injected_files,
129
153
admin_password, network_info, block_device_info=None):
135
159
raise exception.InstanceExists(name=instance_name)
137
161
if self._volumeops.ebs_root_in_block_devices(block_device_info):
140
boot_vhd_path = self._create_boot_vhd(context, instance)
164
root_vhd_path = self._create_root_vhd(context, instance)
143
167
self.create_instance(instance, network_info, block_device_info,
146
170
if configdrive.required_by(instance):
147
171
self._create_config_drive(instance, injected_files,
154
178
raise vmutils.HyperVException(_('Spawn instance failed'))
156
180
def create_instance(self, instance, network_info,
157
block_device_info, boot_vhd_path):
181
block_device_info, root_vhd_path):
158
182
instance_name = instance['name']
160
184
self._vmutils.create_vm(instance_name,
161
185
instance['memory_mb'],
162
186
instance['vcpus'],
163
CONF.limit_cpu_features)
187
CONF.hyperv.limit_cpu_features)
166
190
self._vmutils.attach_ide_drive(instance_name,
170
194
constants.IDE_DISK)
190
214
LOG.info(_('Using config drive for instance: %s'), instance=instance)
193
if admin_password and CONF.config_drive_inject_password:
217
if admin_password and CONF.hyperv.config_drive_inject_password:
194
218
extra_md['admin_pass'] = admin_password
196
220
inst_md = instance_metadata.InstanceMetadata(instance,
211
235
LOG.error(_('Creating config drive failed with error: %s'),
212
236
e, instance=instance)
214
if not CONF.config_drive_cdrom:
238
if not CONF.hyperv.config_drive_cdrom:
215
239
drive_type = constants.IDE_DISK
216
240
configdrive_path = os.path.join(instance_path,
217
241
'configdrive.vhd')
218
utils.execute(CONF.qemu_img_cmd,
242
utils.execute(CONF.hyperv.qemu_img_cmd,
239
263
def _delete_disk_files(self, instance_name):
240
264
self._pathutils.get_instance_dir(instance_name,
244
def destroy(self, instance, network_info=None, cleanup=True,
268
def destroy(self, instance, network_info=None, block_device_info=None,
245
269
destroy_disks=True):
246
270
instance_name = instance['name']
247
271
LOG.info(_("Got request to destroy instance: %s"), instance_name)