Revision 3e06e001 lib/cmdlib.py

b/lib/cmdlib.py
3905 3905

  
3906 3906
  def ExpandNames(self):
3907 3907
    self._ExpandAndLockInstance()
3908

  
3908 3909
    self.needed_locks[locking.LEVEL_NODE] = []
3909 3910
    self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
3910 3911

  
3912
    self._migrater = TLMigrateInstance(self, self.op.instance_name,
3913
                                       self.op.live, self.op.cleanup)
3914
    self.tasklets.append(self._migrater)
3915

  
3911 3916
  def DeclareLocks(self, level):
3912 3917
    if level == locking.LEVEL_NODE:
3913 3918
      self._LockInstancesNodes()
......
3918 3923
    This runs on master, primary and secondary nodes of the instance.
3919 3924

  
3920 3925
    """
3921
    env = _BuildInstanceHookEnvByObject(self, self.instance)
3926
    instance = self._migrater.instance
3927
    env = _BuildInstanceHookEnvByObject(self, instance)
3922 3928
    env["MIGRATE_LIVE"] = self.op.live
3923 3929
    env["MIGRATE_CLEANUP"] = self.op.cleanup
3924
    nl = [self.cfg.GetMasterNode()] + list(self.instance.secondary_nodes)
3930
    nl = [self.cfg.GetMasterNode()] + list(instance.secondary_nodes)
3925 3931
    return env, nl, nl
3926 3932

  
3933

  
3934
class TLMigrateInstance(Tasklet):
3935
  def __init__(self, lu, instance_name, live, cleanup):
3936
    """Initializes this class.
3937

  
3938
    """
3939
    # Parameters
3940
    self.lu = lu
3941
    self.instance_name = instance_name
3942
    self.live = live
3943
    self.cleanup = cleanup
3944

  
3945
    # Shortcuts
3946
    self.cfg = lu.cfg
3947
    self.rpc = lu.rpc
3948

  
3927 3949
  def CheckPrereq(self):
3928 3950
    """Check prerequisites.
3929 3951

  
......
3931 3953

  
3932 3954
    """
3933 3955
    instance = self.cfg.GetInstanceInfo(
3934
      self.cfg.ExpandInstanceName(self.op.instance_name))
3956
      self.cfg.ExpandInstanceName(self.instance_name))
3935 3957
    if instance is None:
3936 3958
      raise errors.OpPrereqError("Instance '%s' not known" %
3937
                                 self.op.instance_name)
3959
                                 self.instance_name)
3938 3960

  
3939 3961
    if instance.disk_template != constants.DT_DRBD8:
3940 3962
      raise errors.OpPrereqError("Instance's disk layout is not"
......
3956 3978
    # check bridge existance
3957 3979
    _CheckInstanceBridgesExist(self, instance, node=target_node)
3958 3980

  
3959
    if not self.op.cleanup:
3981
    if not self.cleanup:
3960 3982
      _CheckNodeNotDrained(self, target_node)
3961 3983
      result = self.rpc.call_instance_migratable(instance.primary_node,
3962 3984
                                                 instance)
......
4103 4125
      self._GoReconnect(False)
4104 4126
      self._WaitUntilSync()
4105 4127
    except errors.OpExecError, err:
4106
      self.LogWarning("Migration failed and I can't reconnect the"
4107
                      " drives: error '%s'\n"
4108
                      "Please look and recover the instance status" %
4109
                      str(err))
4128
      self.lu.LogWarning("Migration failed and I can't reconnect the"
4129
                         " drives: error '%s'\n"
4130
                         "Please look and recover the instance status" %
4131
                         str(err))
4110 4132

  
4111 4133
  def _AbortMigration(self):
4112 4134
    """Call the hypervisor code to abort a started migration.
......
4186 4208
    time.sleep(10)
4187 4209
    result = self.rpc.call_instance_migrate(source_node, instance,
4188 4210
                                            self.nodes_ip[target_node],
4189
                                            self.op.live)
4211
                                            self.live)
4190 4212
    msg = result.fail_msg
4191 4213
    if msg:
4192 4214
      logging.error("Instance migration failed, trying to revert"
......
4233 4255
      self.source_node: self.cfg.GetNodeInfo(self.source_node).secondary_ip,
4234 4256
      self.target_node: self.cfg.GetNodeInfo(self.target_node).secondary_ip,
4235 4257
      }
4236
    if self.op.cleanup:
4258

  
4259
    if self.cleanup:
4237 4260
      return self._ExecCleanup()
4238 4261
    else:
4239 4262
      return self._ExecMigration()

Also available in: Unified diff