Revision e0ac6ce6

b/lib/rapi/client.py
931 931
                             ("/%s/instances/%s/export" %
932 932
                              (GANETI_RAPI_VERSION, instance)), None, body)
933 933

  
934
  def MigrateInstance(self, instance, mode=None, cleanup=None):
935
    """Starts up an instance.
936

  
937
    @type instance: string
938
    @param instance: Instance name
939
    @type mode: string
940
    @param mode: Migration mode
941
    @type cleanup: bool
942
    @param cleanup: Whether to clean up a previously failed migration
943

  
944
    """
945
    body = {}
946

  
947
    if mode is not None:
948
      body["mode"] = mode
949

  
950
    if cleanup is not None:
951
      body["cleanup"] = cleanup
952

  
953
    return self._SendRequest(HTTP_PUT,
954
                             ("/%s/instances/%s/migrate" %
955
                              (GANETI_RAPI_VERSION, instance)), None, body)
956

  
934 957
  def GetJobs(self):
935 958
    """Gets all jobs for the cluster.
936 959

  
b/test/ganeti.rapi.client_unittest.py
698 698
    self.assertEqual(data["destination"], "nodeX")
699 699
    self.assertEqual(data["shutdown"], True)
700 700

  
701
  def testMigrateInstanceDefaults(self):
702
    self.rapi.AddResponse("24873")
703
    job_id = self.client.MigrateInstance("inst91")
704
    self.assertEqual(job_id, 24873)
705
    self.assertHandler(rlib2.R_2_instances_name_migrate)
706
    self.assertItems(["inst91"])
707

  
708
    data = serializer.LoadJson(self.rapi.GetLastRequestData())
709
    self.assertFalse(data)
710

  
711
  def testMigrateInstance(self):
712
    for mode in constants.HT_MIGRATION_MODES:
713
      for cleanup in [False, True]:
714
        self.rapi.AddResponse("31910")
715
        job_id = self.client.MigrateInstance("inst289", mode=mode,
716
                                             cleanup=cleanup)
717
        self.assertEqual(job_id, 31910)
718
        self.assertHandler(rlib2.R_2_instances_name_migrate)
719
        self.assertItems(["inst289"])
720

  
721
        data = serializer.LoadJson(self.rapi.GetLastRequestData())
722
        self.assertEqual(len(data), 2)
723
        self.assertEqual(data["mode"], mode)
724
        self.assertEqual(data["cleanup"], cleanup)
725

  
701 726
  def testGetJobs(self):
702 727
    self.rapi.AddResponse('[ { "id": "123", "uri": "\\/2\\/jobs\\/123" },'
703 728
                          '  { "id": "124", "uri": "\\/2\\/jobs\\/124" } ]')

Also available in: Unified diff