Revision c744425f lib/rapi/rlib2.py

b/lib/rapi/rlib2.py
93 93
# Feature string for instance creation request data version 1
94 94
_INST_CREATE_REQV1 = "instance-create-reqv1"
95 95

  
96
# Feature string for instance reinstall request version 1
97
_INST_REINSTALL_REQV1 = "instance-reinstall-reqv1"
98

  
96 99
# Timeout for /2/jobs/[job_id]/wait. Gives job up to 10 seconds to change.
97 100
_WFJC_TIMEOUT = 10
98 101

  
......
134 137
    """Returns list of optional RAPI features implemented.
135 138

  
136 139
    """
137
    return [_INST_CREATE_REQV1]
140
    return [_INST_CREATE_REQV1, _INST_REINSTALL_REQV1]
138 141

  
139 142

  
140 143
class R_2_os(baserlib.R_Generic):
......
838 841
    return baserlib.SubmitJob([op])
839 842

  
840 843

  
844
def _ParseInstanceReinstallRequest(name, data):
845
  """Parses a request for reinstalling an instance.
846

  
847
  """
848
  if not isinstance(data, dict):
849
    raise http.HttpBadRequest("Invalid body contents, not a dictionary")
850

  
851
  ostype = baserlib.CheckParameter(data, "os")
852
  start = baserlib.CheckParameter(data, "start", exptype=bool,
853
                                  default=True)
854
  osparams = baserlib.CheckParameter(data, "osparams", default=None)
855

  
856
  ops = [
857
    opcodes.OpShutdownInstance(instance_name=name),
858
    opcodes.OpReinstallInstance(instance_name=name, os_type=ostype,
859
                                osparams=osparams),
860
    ]
861

  
862
  if start:
863
    ops.append(opcodes.OpStartupInstance(instance_name=name, force=False))
864

  
865
  return ops
866

  
867

  
841 868
class R_2_instances_name_reinstall(baserlib.R_Generic):
842 869
  """/2/instances/[instance_name]/reinstall resource.
843 870

  
......
852 879
    automatically.
853 880

  
854 881
    """
855
    instance_name = self.items[0]
856
    ostype = self._checkStringVariable('os')
857
    nostartup = self._checkIntVariable('nostartup')
858
    ops = [
859
      opcodes.OpShutdownInstance(instance_name=instance_name),
860
      opcodes.OpReinstallInstance(instance_name=instance_name, os_type=ostype),
861
      ]
862
    if not nostartup:
863
      ops.append(opcodes.OpStartupInstance(instance_name=instance_name,
864
                                           force=False))
882
    if self.request_body:
883
      if self.queryargs:
884
        raise http.HttpBadRequest("Can't combine query and body parameters")
885

  
886
      body = self.request_body
887
    else:
888
      if not self.queryargs:
889
        raise http.HttpBadRequest("Missing query parameters")
890
      # Legacy interface, do not modify/extend
891
      body = {
892
        "os": self._checkStringVariable("os"),
893
        "start": not self._checkIntVariable("nostartup"),
894
        }
895

  
896
    ops = _ParseInstanceReinstallRequest(self.items[0], body)
897

  
865 898
    return baserlib.SubmitJob(ops)
866 899

  
867 900

  

Also available in: Unified diff