Revision d0d7d7cf lib/cmdlib/backup.py

b/lib/cmdlib/backup.py
136 136
    """Check prerequisites.
137 137

  
138 138
    """
139
    instance_name = self.op.instance_name
140

  
141
    self.instance = self.cfg.GetInstanceInfo(instance_name)
139
    self.instance = self.cfg.GetInstanceInfo(self.op.instance_name)
142 140
    assert self.instance is not None, \
143 141
          "Cannot retrieve locked instance %s" % self.op.instance_name
144 142
    CheckNodeOnline(self, self.instance.primary_node)
......
149 147
    """Prepares an instance for an export.
150 148

  
151 149
    """
152
    instance = self.instance
153

  
154 150
    if self.op.mode == constants.EXPORT_MODE_REMOTE:
155 151
      salt = utils.GenerateSecret(8)
156 152

  
157 153
      feedback_fn("Generating X509 certificate on %s" %
158
                  self.cfg.GetNodeName(instance.primary_node))
159
      result = self.rpc.call_x509_cert_create(instance.primary_node,
154
                  self.cfg.GetNodeName(self.instance.primary_node))
155
      result = self.rpc.call_x509_cert_create(self.instance.primary_node,
160 156
                                              constants.RIE_CERT_VALIDITY)
161 157
      result.Raise("Can't create X509 key and certificate on %s" %
162 158
                   self.cfg.GetNodeName(result.node))
......
263 259
    This checks that the instance and node names are valid.
264 260

  
265 261
    """
266
    instance_name = self.op.instance_name
267

  
268
    self.instance = self.cfg.GetInstanceInfo(instance_name)
262
    self.instance = self.cfg.GetInstanceInfo(self.op.instance_name)
269 263
    assert self.instance is not None, \
270 264
          "Cannot retrieve locked instance %s" % self.op.instance_name
271 265
    CheckNodeOnline(self, self.instance.primary_node)
......
293 287
      if len(self.op.target_node) != len(self.instance.disks):
294 288
        raise errors.OpPrereqError(("Received destination information for %s"
295 289
                                    " disks, but instance %s has %s disks") %
296
                                   (len(self.op.target_node), instance_name,
290
                                   (len(self.op.target_node),
291
                                    self.op.instance_name,
297 292
                                    len(self.instance.disks)),
298 293
                                   errors.ECODE_INVAL)
299 294

  
......
385 380
    """
386 381
    assert self.op.mode in constants.EXPORT_MODES
387 382

  
388
    instance = self.instance
389
    src_node_uuid = instance.primary_node
383
    src_node_uuid = self.instance.primary_node
390 384

  
391 385
    if self.op.shutdown:
392 386
      # shutdown the instance, but not the disks
393
      feedback_fn("Shutting down instance %s" % instance.name)
394
      result = self.rpc.call_instance_shutdown(src_node_uuid, instance,
387
      feedback_fn("Shutting down instance %s" % self.instance.name)
388
      result = self.rpc.call_instance_shutdown(src_node_uuid, self.instance,
395 389
                                               self.op.shutdown_timeout,
396 390
                                               self.op.reason)
397 391
      # TODO: Maybe ignore failures if ignore_remove_failures is set
398 392
      result.Raise("Could not shutdown instance %s on"
399
                   " node %s" % (instance.name,
393
                   " node %s" % (self.instance.name,
400 394
                                 self.cfg.GetNodeName(src_node_uuid)))
401 395

  
402 396
    # set the disks ID correctly since call_instance_start needs the
403 397
    # correct drbd minor to create the symlinks
404
    for disk in instance.disks:
398
    for disk in self.instance.disks:
405 399
      self.cfg.SetDiskID(disk, src_node_uuid)
406 400

  
407
    activate_disks = not instance.disks_active
401
    activate_disks = not self.instance.disks_active
408 402

  
409 403
    if activate_disks:
410 404
      # Activate the instance disks if we'exporting a stopped instance
411
      feedback_fn("Activating disks for %s" % instance.name)
412
      StartInstanceDisks(self, instance, None)
405
      feedback_fn("Activating disks for %s" % self.instance.name)
406
      StartInstanceDisks(self, self.instance, None)
413 407

  
414 408
    try:
415 409
      helper = masterd.instance.ExportInstanceHelper(self, feedback_fn,
416
                                                     instance)
410
                                                     self.instance)
417 411

  
418 412
      helper.CreateSnapshots()
419 413
      try:
420 414
        if (self.op.shutdown and
421
            instance.admin_state == constants.ADMINST_UP and
415
            self.instance.admin_state == constants.ADMINST_UP and
422 416
            not self.op.remove_instance):
423 417
          assert not activate_disks
424
          feedback_fn("Starting instance %s" % instance.name)
418
          feedback_fn("Starting instance %s" % self.instance.name)
425 419
          result = self.rpc.call_instance_start(src_node_uuid,
426
                                                (instance, None, None), False,
427
                                                 self.op.reason)
420
                                                (self.instance, None, None),
421
                                                False, self.op.reason)
428 422
          msg = result.fail_msg
429 423
          if msg:
430 424
            feedback_fn("Failed to start instance: %s" % msg)
431
            ShutdownInstanceDisks(self, instance)
425
            ShutdownInstanceDisks(self, self.instance)
432 426
            raise errors.OpExecError("Could not start instance: %s" % msg)
433 427

  
434 428
        if self.op.mode == constants.EXPORT_MODE_LOCAL:
......
450 444
        helper.Cleanup()
451 445

  
452 446
      # Check for backwards compatibility
453
      assert len(dresults) == len(instance.disks)
447
      assert len(dresults) == len(self.instance.disks)
454 448
      assert compat.all(isinstance(i, bool) for i in dresults), \
455 449
             "Not all results are boolean: %r" % dresults
456 450

  
457 451
    finally:
458 452
      if activate_disks:
459
        feedback_fn("Deactivating disks for %s" % instance.name)
460
        ShutdownInstanceDisks(self, instance)
453
        feedback_fn("Deactivating disks for %s" % self.instance.name)
454
        ShutdownInstanceDisks(self, self.instance)
461 455

  
462 456
    if not (compat.all(dresults) and fin_resu):
463 457
      failures = []
......
475 469

  
476 470
    # Remove instance if requested
477 471
    if self.op.remove_instance:
478
      feedback_fn("Removing instance %s" % instance.name)
479
      RemoveInstance(self, feedback_fn, instance,
472
      feedback_fn("Removing instance %s" % self.instance.name)
473
      RemoveInstance(self, feedback_fn, self.instance,
480 474
                     self.op.ignore_remove_failures)
481 475

  
482 476
    if self.op.mode == constants.EXPORT_MODE_LOCAL:

Also available in: Unified diff