~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/virt/hyperv/vmops.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, James Page
  • Date: 2013-03-20 12:59:22 UTC
  • mfrom: (1.1.69)
  • Revision ID: package-import@ubuntu.com-20130320125922-ohvfav96lemn9wlz
Tags: 1:2013.1~rc1-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/patches/avoid_setuptools_git_dependency.patch: Refreshed.
* debian/control: Clean up dependencies:
  - Dropped python-gflags no longer needed.
  - Dropped python-daemon no longer needed.
  - Dropped python-glance no longer needed.
  - Dropped python-lockfile no longer needed.
  - Dropped python-simplejson no longer needed.
  - Dropped python-tempita no longer needed.
  - Dropped python-xattr no longer needed.
  - Add sqlite3 required for the testsuite.

[ James Page ]
* d/watch: Update uversionmangle to deal with upstream versioning
  changes, remove tarballs.openstack.org. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
    cfg.BoolOpt('limit_cpu_features',
45
45
                default=False,
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',
49
50
                default=False,
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',
56
59
                default=False,
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')
59
63
]
60
64
 
61
65
CONF = cfg.CONF
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')
65
69
 
111
115
                'num_cpu': info['NumberOfProcessors'],
112
116
                'cpu_time': info['UpTime']}
113
117
 
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'])
117
 
 
118
 
        if CONF.use_cow_images:
119
 
            LOG.debug(_("Creating differencing VHD. Parent: "
120
 
                        "%(base_vhd_path)s, Target: %(boot_vhd_path)s")
121
 
                      % locals())
122
 
            self._vhdutils.create_differencing_vhd(boot_vhd_path,
123
 
                                                   base_vhd_path)
124
 
        else:
125
 
            self._pathutils.copyfile(base_vhd_path, boot_vhd_path)
126
 
        return boot_vhd_path
 
120
        root_vhd_path = self._pathutils.get_vhd_path(instance['name'])
 
121
 
 
122
        try:
 
123
            if CONF.use_cow_images:
 
124
                LOG.debug(_("Creating differencing VHD. Parent: "
 
125
                            "%(base_vhd_path)s, Target: %(root_vhd_path)s")
 
126
                          % locals())
 
127
                self._vhdutils.create_differencing_vhd(root_vhd_path,
 
128
                                                       base_vhd_path)
 
129
            else:
 
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)
 
133
 
 
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
 
137
 
 
138
                if root_vhd_size < base_vhd_size:
 
139
                    raise vmutils.HyperVException(_("Cannot resize a VHD to a "
 
140
                                                    "smaller size"))
 
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)
 
145
        except Exception:
 
146
            with excutils.save_and_reraise_exception():
 
147
                if self._pathutils.exists(root_vhd_path):
 
148
                    self._pathutils.remove(root_vhd_path)
 
149
 
 
150
        return root_vhd_path
127
151
 
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)
136
160
 
137
161
        if self._volumeops.ebs_root_in_block_devices(block_device_info):
138
 
            boot_vhd_path = None
 
162
            root_vhd_path = None
139
163
        else:
140
 
            boot_vhd_path = self._create_boot_vhd(context, instance)
 
164
            root_vhd_path = self._create_root_vhd(context, instance)
141
165
 
142
166
        try:
143
167
            self.create_instance(instance, network_info, block_device_info,
144
 
                                 boot_vhd_path)
 
168
                                 root_vhd_path)
145
169
 
146
170
            if configdrive.required_by(instance):
147
171
                self._create_config_drive(instance, injected_files,
154
178
            raise vmutils.HyperVException(_('Spawn instance failed'))
155
179
 
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']
159
183
 
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)
164
188
 
165
 
        if boot_vhd_path:
 
189
        if root_vhd_path:
166
190
            self._vmutils.attach_ide_drive(instance_name,
167
 
                                           boot_vhd_path,
 
191
                                           root_vhd_path,
168
192
                                           0,
169
193
                                           0,
170
194
                                           constants.IDE_DISK)
173
197
 
174
198
        self._volumeops.attach_volumes(block_device_info,
175
199
                                       instance_name,
176
 
                                       boot_vhd_path is None)
 
200
                                       root_vhd_path is None)
177
201
 
178
202
        for vif in network_info:
179
203
            LOG.debug(_('Creating nic for instance: %s'), instance_name)
190
214
        LOG.info(_('Using config drive for instance: %s'), instance=instance)
191
215
 
192
216
        extra_md = {}
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
195
219
 
196
220
        inst_md = instance_metadata.InstanceMetadata(instance,
211
235
                    LOG.error(_('Creating config drive failed with error: %s'),
212
236
                              e, instance=instance)
213
237
 
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,
219
243
                          'convert',
220
244
                          '-f',
221
245
                          'raw',
238
262
 
239
263
    def _delete_disk_files(self, instance_name):
240
264
        self._pathutils.get_instance_dir(instance_name,
241
 
                                          create_dir=False,
242
 
                                          remove_dir=True)
 
265
                                         create_dir=False,
 
266
                                         remove_dir=True)
243
267
 
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)