~sandy-walsh/nova/api-parity

« back to all changes in this revision

Viewing changes to nova/virt/xenapi/vm_utils.py

  • Committer: Sandy Walsh
  • Date: 2011-01-11 06:47:35 UTC
  • mfrom: (515.3.28 nova)
  • Revision ID: sandy.walsh@rackspace.com-20110111064735-ws352hz2hb2tj2fk
Changed shared_ip_group detail routing

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
their attributes like VDIs, VIFs, as well as their lookup functions.
20
20
"""
21
21
 
22
 
import logging
23
22
import pickle
24
23
import urllib
25
24
from xml.dom import minidom
27
26
from eventlet import event
28
27
from nova import exception
29
28
from nova import flags
 
29
from nova import log as logging
30
30
from nova import utils
31
31
from nova.auth.manager import AuthManager
32
32
from nova.compute import instance_types
37
37
 
38
38
 
39
39
FLAGS = flags.FLAGS
 
40
LOG = logging.getLogger("nova.virt.xenapi.vm_utils")
40
41
 
41
42
XENAPI_POWER_STATE = {
42
43
    'Halted': power_state.SHUTDOWN,
121
122
                rec['HVM_boot_params'] = {'order': 'dc'}
122
123
                rec['platform'] = {'acpi': 'true', 'apic': 'true',
123
124
                                   'pae': 'true', 'viridian': 'true'}
124
 
        logging.debug('Created VM %s...', instance.name)
 
125
        LOG.debug(_('Created VM %s...'), instance.name)
125
126
        vm_ref = session.call_xenapi('VM.create', rec)
126
 
        logging.debug(_('Created VM %s as %s.'), instance.name, vm_ref)
 
127
        LOG.debug(_('Created VM %s as %s.'), instance.name, vm_ref)
127
128
        return vm_ref
128
129
 
129
130
    @classmethod
143
144
        vbd_rec['qos_algorithm_type'] = ''
144
145
        vbd_rec['qos_algorithm_params'] = {}
145
146
        vbd_rec['qos_supported_algorithms'] = []
146
 
        logging.debug(_('Creating VBD for VM %s, VDI %s ... '),
147
 
                      vm_ref, vdi_ref)
 
147
        LOG.debug(_('Creating VBD for VM %s, VDI %s ... '), vm_ref, vdi_ref)
148
148
        vbd_ref = session.call_xenapi('VBD.create', vbd_rec)
149
 
        logging.debug(_('Created VBD %s for VM %s, VDI %s.'), vbd_ref, vm_ref,
 
149
        LOG.debug(_('Created VBD %s for VM %s, VDI %s.'), vbd_ref, vm_ref,
150
150
                      vdi_ref)
151
151
        return vbd_ref
152
152
 
161
161
                    if vbd_rec['userdevice'] == str(number):
162
162
                        return vbd
163
163
                except cls.XenAPI.Failure, exc:
164
 
                    logging.warn(exc)
 
164
                    LOG.exception(exc)
165
165
        raise StorageError(_('VBD not found in instance %s') % vm_ref)
166
166
 
167
167
    @classmethod
170
170
        try:
171
171
            vbd_ref = session.call_xenapi('VBD.unplug', vbd_ref)
172
172
        except cls.XenAPI.Failure, exc:
173
 
            logging.warn(exc)
 
173
            LOG.exception(exc)
174
174
            if exc.details[0] != 'DEVICE_ALREADY_DETACHED':
175
175
                raise StorageError(_('Unable to unplug VBD %s') % vbd_ref)
176
176
 
183
183
            #with Josh Kearney
184
184
            session.wait_for_task(0, task)
185
185
        except cls.XenAPI.Failure, exc:
186
 
            logging.warn(exc)
 
186
            LOG.exception(exc)
187
187
            raise StorageError(_('Unable to destroy VBD %s') % vbd_ref)
188
188
 
189
189
    @classmethod
199
199
        vif_rec['other_config'] = {}
200
200
        vif_rec['qos_algorithm_type'] = ''
201
201
        vif_rec['qos_algorithm_params'] = {}
202
 
        logging.debug(_('Creating VIF for VM %s, network %s.'), vm_ref,
203
 
                      network_ref)
 
202
        LOG.debug(_('Creating VIF for VM %s, network %s.'), vm_ref,
 
203
                  network_ref)
204
204
        vif_ref = session.call_xenapi('VIF.create', vif_rec)
205
 
        logging.debug(_('Created VIF %s for VM %s, network %s.'), vif_ref,
206
 
                      vm_ref, network_ref)
 
205
        LOG.debug(_('Created VIF %s for VM %s, network %s.'), vif_ref,
 
206
                  vm_ref, network_ref)
207
207
        return vif_ref
208
208
 
209
209
    @classmethod
213
213
        """
214
214
        #TODO(sirp): Add quiesce and VSS locking support when Windows support
215
215
        # is added
216
 
        logging.debug(_("Snapshotting VM %s with label '%s'..."),
217
 
                      vm_ref, label)
 
216
        LOG.debug(_("Snapshotting VM %s with label '%s'..."), vm_ref, label)
218
217
 
219
218
        vm_vdi_ref, vm_vdi_rec = get_vdi_for_vm_safely(session, vm_ref)
220
219
        vm_vdi_uuid = vm_vdi_rec["uuid"]
227
226
        template_vdi_rec = get_vdi_for_vm_safely(session, template_vm_ref)[1]
228
227
        template_vdi_uuid = template_vdi_rec["uuid"]
229
228
 
230
 
        logging.debug(_('Created snapshot %s from VM %s.'), template_vm_ref,
231
 
                      vm_ref)
 
229
        LOG.debug(_('Created snapshot %s from VM %s.'), template_vm_ref,
 
230
                  vm_ref)
232
231
 
233
232
        parent_uuid = wait_for_vhd_coalesce(
234
233
            session, instance_id, sr_ref, vm_vdi_ref, original_parent_uuid)
241
240
        """ Requests that the Glance plugin bundle the specified VDIs and
242
241
        push them into Glance using the specified human-friendly name.
243
242
        """
244
 
        logging.debug(_("Asking xapi to upload %s as '%s'"),
245
 
                      vdi_uuids, image_name)
 
243
        LOG.debug(_("Asking xapi to upload %s as '%s'"), vdi_uuids, image_name)
246
244
 
247
245
        params = {'vdi_uuids': vdi_uuids,
248
246
                  'image_name': image_name,
260
258
        """
261
259
        url = images.image_url(image)
262
260
        access = AuthManager().get_access_key(user, project)
263
 
        logging.debug("Asking xapi to fetch %s as %s", url, access)
 
261
        LOG.debug(_("Asking xapi to fetch %s as %s"), url, access)
264
262
        fn = (type != ImageType.KERNEL_RAMDISK) and 'get_vdi' or 'get_kernel'
265
263
        args = {}
266
264
        args['src_url'] = url
278
276
 
279
277
    @classmethod
280
278
    def lookup_image(cls, session, vdi_ref):
281
 
        logging.debug("Looking up vdi %s for PV kernel", vdi_ref)
 
279
        LOG.debug(_("Looking up vdi %s for PV kernel"), vdi_ref)
282
280
        fn = "is_vdi_pv"
283
281
        args = {}
284
282
        args['vdi-ref'] = vdi_ref
289
287
            pv = True
290
288
        elif pv_str.lower() == 'false':
291
289
            pv = False
292
 
        logging.debug("PV Kernel in VDI:%d", pv)
 
290
        LOG.debug(_("PV Kernel in VDI:%d"), pv)
293
291
        return pv
294
292
 
295
293
    @classmethod
317
315
                    vdi = session.get_xenapi().VBD.get_VDI(vbd)
318
316
                    # Test valid VDI
319
317
                    record = session.get_xenapi().VDI.get_record(vdi)
320
 
                    logging.debug(_('VDI %s is still available'),
321
 
                                  record['uuid'])
 
318
                    LOG.debug(_('VDI %s is still available'), record['uuid'])
322
319
                except cls.XenAPI.Failure, exc:
323
 
                    logging.warn(exc)
 
320
                    LOG.exception(exc)
324
321
                else:
325
322
                    vdis.append(vdi)
326
323
            if len(vdis) > 0:
331
328
    @classmethod
332
329
    def compile_info(cls, record):
333
330
        """Fill record with VM status information"""
334
 
        logging.info(_("(VM_UTILS) xenserver vm state -> |%s|"),
335
 
                     record['power_state'])
336
 
        logging.info(_("(VM_UTILS) xenapi power_state -> |%s|"),
337
 
                     XENAPI_POWER_STATE[record['power_state']])
 
331
        LOG.info(_("(VM_UTILS) xenserver vm state -> |%s|"),
 
332
                 record['power_state'])
 
333
        LOG.info(_("(VM_UTILS) xenapi power_state -> |%s|"),
 
334
                 XENAPI_POWER_STATE[record['power_state']])
338
335
        return {'state': XENAPI_POWER_STATE[record['power_state']],
339
336
                'max_mem': long(record['memory_static_max']) >> 10,
340
337
                'mem': long(record['memory_dynamic_max']) >> 10,
390
387
    """
391
388
    if 'vhd-parent' in vdi_rec['sm_config']:
392
389
        parent_uuid = vdi_rec['sm_config']['vhd-parent']
393
 
        #NOTE(sirp): changed xenapi -> get_xenapi()
394
390
        parent_ref = session.get_xenapi().VDI.get_by_uuid(parent_uuid)
395
391
        parent_rec = session.get_xenapi().VDI.get_record(parent_ref)
396
 
        #NOTE(sirp): changed log -> logging
397
 
        logging.debug(_("VHD %s has parent %s"), vdi_rec['uuid'], parent_ref)
 
392
        LOG.debug(_("VHD %s has parent %s"), vdi_rec['uuid'], parent_ref)
398
393
        return parent_ref, parent_rec
399
394
    else:
400
395
        return None
411
406
 
412
407
 
413
408
def scan_sr(session, instance_id, sr_ref):
414
 
    logging.debug(_("Re-scanning SR %s"), sr_ref)
 
409
    LOG.debug(_("Re-scanning SR %s"), sr_ref)
415
410
    task = session.call_xenapi('Async.SR.scan', sr_ref)
416
411
    session.wait_for_task(instance_id, task)
417
412
 
435
430
        scan_sr(session, instance_id, sr_ref)
436
431
        parent_uuid = get_vhd_parent_uuid(session, vdi_ref)
437
432
        if original_parent_uuid and (parent_uuid != original_parent_uuid):
438
 
            logging.debug(
439
 
                _("Parent %s doesn't match original parent %s, "
440
 
                  "waiting for coalesce..."),
441
 
                parent_uuid, original_parent_uuid)
 
433
            LOG.debug(_("Parent %s doesn't match original parent %s, "
 
434
                         "waiting for coalesce..."), parent_uuid,
 
435
                      original_parent_uuid)
442
436
        else:
443
437
            done.send(parent_uuid)
444
438