~nova-coresec/nova/bexar-translations

« back to all changes in this revision

Viewing changes to nova/virt/hyperv.py

  • Committer: Ed Leafe
  • Date: 2011-01-19 02:00:28 UTC
  • mto: This revision was merged to the branch mainline in revision 607.
  • Revision ID: ed@leafe.com-20110119020028-3hthda2qccp2uawa
Completed first pass at converting all localized strings with multiple format substitutions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
129
129
        vm = self._lookup(instance.name)
130
130
        if vm is not None:
131
131
            raise exception.Duplicate(_('Attempt to create duplicate vm %s') %
132
 
                            instance.name)
 
132
                    instance.name)
133
133
 
134
134
        user = manager.AuthManager().get_user(instance['user_id'])
135
135
        project = manager.AuthManager().get_project(instance['project_id'])
159
159
        vs_gs_data = self._conn.Msvm_VirtualSystemGlobalSettingData.new()
160
160
        vs_gs_data.ElementName = instance['name']
161
161
        (job, ret_val) = vs_man_svc.DefineVirtualSystem(
162
 
                                        [], None, vs_gs_data.GetText_(1))[1:]
 
162
                [], None, vs_gs_data.GetText_(1))[1:]
163
163
        if ret_val == WMI_JOB_STATUS_STARTED:
164
164
            success = self._check_job_status(job)
165
165
        else:
184
184
        memsetting.Limit = mem
185
185
 
186
186
        (job, ret_val) = vs_man_svc.ModifyVirtualSystemResources(
187
 
                                        vm.path_(), [memsetting.GetText_(1)])
 
187
                vm.path_(), [memsetting.GetText_(1)])
188
188
        LOG.debug(_('Set memory for vm %s...'), instance.name)
189
189
        procsetting = vmsetting.associators(
190
 
                          wmi_result_class='Msvm_ProcessorSettingData')[0]
 
190
                wmi_result_class='Msvm_ProcessorSettingData')[0]
191
191
        vcpus = long(instance['vcpus'])
192
192
        procsetting.VirtualQuantity = vcpus
193
193
        procsetting.Reservation = vcpus
194
194
        procsetting.Limit = vcpus
195
195
 
196
196
        (job, ret_val) = vs_man_svc.ModifyVirtualSystemResources(
197
 
                                        vm.path_(), [procsetting.GetText_(1)])
 
197
                vm.path_(), [procsetting.GetText_(1)])
198
198
        LOG.debug(_('Set vcpus for vm %s...'), instance.name)
199
199
 
200
200
    def _create_disk(self, vm_name, vhdfile):
205
205
        vms = self._conn.MSVM_ComputerSystem(ElementName=vm_name)
206
206
        vm = vms[0]
207
207
        vmsettings = vm.associators(
208
 
                        wmi_result_class='Msvm_VirtualSystemSettingData')
 
208
                wmi_result_class='Msvm_VirtualSystemSettingData')
209
209
        rasds = vmsettings[0].associators(
210
 
                        wmi_result_class='MSVM_ResourceAllocationSettingData')
 
210
                wmi_result_class='MSVM_ResourceAllocationSettingData')
211
211
        ctrller = [r for r in rasds
212
212
                   if r.ResourceSubType == 'Microsoft Emulated IDE Controller'\
213
 
                                         and r.Address == "0"]
 
213
                   and r.Address == "0"]
214
214
        #Find the default disk drive object for the vm and clone it.
215
215
        diskdflt = self._conn.query(
216
 
                  "SELECT * FROM Msvm_ResourceAllocationSettingData \
217
 
                   WHERE ResourceSubType LIKE 'Microsoft Synthetic Disk Drive'\
218
 
                   AND InstanceID LIKE '%Default%'")[0]
 
216
                "SELECT * FROM Msvm_ResourceAllocationSettingData \
 
217
                WHERE ResourceSubType LIKE 'Microsoft Synthetic Disk Drive'\
 
218
                AND InstanceID LIKE '%Default%'")[0]
219
219
        diskdrive = self._clone_wmi_obj(
220
 
                    'Msvm_ResourceAllocationSettingData', diskdflt)
 
220
                'Msvm_ResourceAllocationSettingData', diskdflt)
221
221
        #Set the IDE ctrller as parent.
222
222
        diskdrive.Parent = ctrller[0].path_()
223
223
        diskdrive.Address = 0
263
263
        default_nic_data = [n for n in emulatednics_data
264
264
                            if n.InstanceID.rfind('Default') > 0]
265
265
        new_nic_data = self._clone_wmi_obj(
266
 
                                      'Msvm_EmulatedEthernetPortSettingData',
267
 
                                      default_nic_data[0])
 
266
                'Msvm_EmulatedEthernetPortSettingData',
 
267
                default_nic_data[0])
268
268
        #Create a port on the vswitch.
269
269
        (new_port, ret_val) = switch_svc.CreateSwitchPort(vm_name, vm_name,
270
270
                                            "", extswitch.path_())
271
271
        if ret_val != 0:
272
272
            LOG.error(_('Failed creating a port on the external vswitch'))
273
273
            raise Exception(_('Failed creating port for %s'),
274
 
                                             vm_name)
275
 
        LOG.debug(_("Created switch port %s on switch %s"),
276
 
                  vm_name, extswitch.path_())
 
274
                    vm_name)
 
275
        ext_path = extswitch.path_()
 
276
        LOG.debug(_("Created switch port %(vm_name)s on switch %(ext_path)s")
 
277
                % locals())
277
278
        #Connect the new nic to the new port.
278
279
        new_nic_data.Connection = [new_port]
279
280
        new_nic_data.ElementName = vm_name + ' nic'
283
284
        new_resources = self._add_virt_resource(new_nic_data, vm)
284
285
        if new_resources is None:
285
286
            raise Exception(_('Failed to add nic to VM %s'),
286
 
                                             vm_name)
 
287
                    vm_name)
287
288
        LOG.info(_("Created nic for %s "), vm_name)
288
289
 
289
290
    def _add_virt_resource(self, res_setting_data, target_vm):
319
320
        if job.JobState != WMI_JOB_STATE_COMPLETED:
320
321
            LOG.debug(_("WMI job failed: %s"), job.ErrorSummaryDescription)
321
322
            return False
322
 
        LOG.debug(_("WMI job succeeded: %s, Elapsed=%s "), job.Description,
323
 
                  job.ElapsedTime)
 
323
        desc = job.Description
 
324
        elap = job.ElapsedTime
 
325
        LOG.debug(_("WMI job succeeded: %(desc)s, Elapsed=%(elap)s ")
 
326
                % locals())
324
327
        return True
325
328
 
326
329
    def _find_external_network(self):
386
389
            vhdfile = self._cim_conn.CIM_DataFile(Name=disk)
387
390
            for vf in vhdfile:
388
391
                vf.Delete()
389
 
                LOG.debug(_("Del: disk %s vm %s"), vhdfile, instance.name)
 
392
                instance_name = instance.name
 
393
                LOG.debug(_("Del: disk %(vhdfile)s vm %(instance_name)s")
 
394
                        % locals())
390
395
 
391
396
    def get_info(self, instance_id):
392
397
        """Get information about the VM"""
402
407
        summary_info = vs_man_svc.GetSummaryInformation(
403
408
                                       [4, 100, 103, 105], settings_paths)[1]
404
409
        info = summary_info[0]
405
 
        LOG.debug(_("Got Info for vm %s: state=%s, mem=%s, num_cpu=%s, \
406
 
                    cpu_time=%s"), instance_id,
407
 
                  str(HYPERV_POWER_STATE[info.EnabledState]),
408
 
                  str(info.MemoryUsage),
409
 
                  str(info.NumberOfProcessors),
410
 
                  str(info.UpTime))
 
410
        state = str(HYPERV_POWER_STATE[info.EnabledState])
 
411
        memusage = str(info.MemoryUsage)
 
412
        numprocs = str(info.NumberOfProcessors)
 
413
        uptime = str(info.UpTime)
 
414
 
 
415
        LOG.debug(_("Got Info for vm %(instance_id)s: state=%(state)s,"
 
416
                " mem=%(memusage)s, num_cpu=%(numprocs)s,"
 
417
                " cpu_time=%(uptime)s") % locals())
411
418
 
412
419
        return {'state': HYPERV_POWER_STATE[info.EnabledState],
413
420
                'max_mem': info.MemoryUsage,
441
448
            #already in the state requested
442
449
            success = True
443
450
        if success:
444
 
            LOG.info(_("Successfully changed vm state of %s to %s"), vm_name,
445
 
                     req_state)
 
451
            LOG.info(_("Successfully changed vm state of %(vm_name)s"
 
452
                    " to %(req_state)s") % locals())
446
453
        else:
447
 
            LOG.error(_("Failed to change vm state of %s to %s"), vm_name,
448
 
                      req_state)
449
 
            raise Exception(_("Failed to change vm state of %s to %s"),
450
 
                                        vm_name, req_state)
 
454
            msg = _("Failed to change vm state of %(vm_name)s"
 
455
                    " to %(req_state)s") % locals()
 
456
            LOG.error(msg)
 
457
            raise Exception(msg)
451
458
 
452
459
    def attach_volume(self, instance_name, device_path, mountpoint):
453
460
        vm = self._lookup(instance_name)
454
461
        if vm is None:
455
 
            raise exception.NotFound('Cannot attach volume to missing %s vm' %
456
 
                            instance_name)
 
462
            raise exception.NotFound('Cannot attach volume to missing %s vm'
 
463
                    % instance_name)
457
464
 
458
465
    def detach_volume(self, instance_name, mountpoint):
459
466
        vm = self._lookup(instance_name)
460
467
        if vm is None:
461
 
            raise exception.NotFound('Cannot detach volume from missing %s ' %
462
 
                            instance_name)
 
468
            raise exception.NotFound('Cannot detach volume from missing %s '
 
469
                    % instance_name)