Revision d975f482 lib/rapi/rlib2.py

b/lib/rapi/rlib2.py
83 83
  "R": _NR_REGULAR,
84 84
  }
85 85

  
86
# Request data version field
87
_REQ_DATA_VERSION = "__version__"
88

  
86 89
# Timeout for /2/jobs/[job_id]/wait. Gives job up to 10 seconds to change.
87 90
_WFJC_TIMEOUT = 10
88 91

  
......
491 494
      return baserlib.BuildUriList(instanceslist, "/2/instances/%s",
492 495
                                   uri_fields=("id", "uri"))
493 496

  
494
  def POST(self):
495
    """Create an instance.
497
  def _ParseVersion0CreateRequest(self):
498
    """Parses an instance creation request version 0.
496 499

  
497
    @return: a job id
500
    @rtype: L{opcodes.OpCreateInstance}
501
    @return: Instance creation opcode
498 502

  
499 503
    """
500
    if not isinstance(self.req.request_body, dict):
501
      raise http.HttpBadRequest("Invalid body contents, not a dictionary")
502

  
503 504
    beparams = baserlib.MakeParamsDict(self.req.request_body,
504 505
                                       constants.BES_PARAMETERS)
505 506
    hvparams = baserlib.MakeParamsDict(self.req.request_body,
......
516 517
        raise http.HttpBadRequest("Disk %d specification wrong: should"
517 518
                                  " be an integer" % idx)
518 519
      disks.append({"size": d})
520

  
519 521
    # nic processing (one nic only)
520 522
    nics = [{"mac": fn("mac", constants.VALUE_AUTO)}]
521 523
    if fn("ip", None) is not None:
......
527 529
    if fn("bridge", None) is not None:
528 530
      nics[0]["bridge"] = fn("bridge")
529 531

  
530
    op = opcodes.OpCreateInstance(
532
    return opcodes.OpCreateInstance(
531 533
      mode=constants.INSTANCE_CREATE,
532 534
      instance_name=fn('name'),
533 535
      disks=disks,
......
549 551
      dry_run=bool(self.dryRun()),
550 552
      )
551 553

  
554
  def POST(self):
555
    """Create an instance.
556

  
557
    @return: a job id
558

  
559
    """
560
    if not isinstance(self.req.request_body, dict):
561
      raise http.HttpBadRequest("Invalid body contents, not a dictionary")
562

  
563
    # Default to request data version 0
564
    data_version = self.getBodyParameter(_REQ_DATA_VERSION, 0)
565

  
566
    if data_version == 0:
567
      op = self._ParseVersion0CreateRequest()
568
    else:
569
      raise http.HttpBadRequest("Unsupported request data version %s" %
570
                                request_version)
571

  
552 572
    return baserlib.SubmitJob([op])
553 573

  
554 574

  

Also available in: Unified diff