Revision 6e99c5a0 lib/rapi/rlib2.py

b/lib/rapi/rlib2.py
324 324
    @returns: a job id
325 325

  
326 326
    """
327
    opts = self.req.request_post_data
328

  
329
    beparams = baserlib.MakeParamsDict(opts, constants.BES_PARAMETERS)
330
    hvparams = baserlib.MakeParamsDict(opts, constants.HVS_PARAMETERS)
327
    if not isinstance(self.req.request_body, dict):
328
      raise http.HttpBadRequest("Invalid body contents, not a dictionary")
329

  
330
    beparams = baserlib.MakeParamsDict(self.req.request_body,
331
                                       constants.BES_PARAMETERS)
332
    hvparams = baserlib.MakeParamsDict(self.req.request_body,
333
                                       constants.HVS_PARAMETERS)
334
    fn = self.getBodyParameter
335

  
336
    # disk processing
337
    disk_data = fn('disks')
338
    if not isinstance(disk_data, list):
339
      raise http.HttpBadRequest("The 'disks' parameter should be a list")
340
    disks = []
341
    for idx, d in enumerate(disk_data):
342
      if not isinstance(d, int):
343
        raise http.HttpBadRequest("Disk %d specification wrong: should"
344
                                  " be an integer")
345
      disks.append({"size": d})
346
    # nic processing (one nic only)
347
    nics = [{"mac": fn("mac", constants.VALUE_AUTO),
348
             "ip": fn("ip", None),
349
             "bridge": fn("bridge", None)}]
331 350

  
332 351
    op = ganeti.opcodes.OpCreateInstance(
333
        instance_name=opts.get('name'),
334
        disk_size=opts.get('size', 20 * 1024),
335
        swap_size=opts.get('swap', 4 * 1024),
336
        disk_template=opts.get('disk_template', None),
337 352
        mode=constants.INSTANCE_CREATE,
338
        os_type=opts.get('os'),
339
        pnode=opts.get('pnode'),
340
        snode=opts.get('snode'),
341
        ip=opts.get('ip', 'none'),
342
        bridge=opts.get('bridge', None),
343
        start=opts.get('start', True),
344
        ip_check=opts.get('ip_check', True),
345
        wait_for_sync=opts.get('wait_for_sync', True),
346
        mac=opts.get('mac', 'auto'),
347
        hypervisor=opts.get('hypervisor', None),
353
        instance_name=fn('name'),
354
        disks=disks,
355
        disk_template=fn('disk_template'),
356
        os_type=fn('os'),
357
        pnode=fn('pnode', None),
358
        snode=fn('snode', None),
359
        iallocator=fn('iallocator', None),
360
        nics=nics,
361
        start=fn('start', True),
362
        ip_check=fn('ip_check', True),
363
        wait_for_sync=True,
364
        hypervisor=fn('hypervisor', None),
348 365
        hvparams=hvparams,
349 366
        beparams=beparams,
350
        iallocator=opts.get('iallocator', None),
351
        file_storage_dir=opts.get('file_storage_dir', None),
352
        file_driver=opts.get('file_driver', 'loop'),
367
        file_storage_dir=fn('file_storage_dir', None),
368
        file_driver=fn('file_driver', 'loop'),
353 369
        )
354 370

  
355 371
    job_id = ganeti.cli.SendJob([op])
......
373 389

  
374 390
    return baserlib.MapFields(I_FIELDS, result[0])
375 391

  
392
  def DELETE(self):
393
    """Delete an instance.
394

  
395
    """
396
    op = ganeti.opcodes.OpRemoveInstance(instance_name=self.items[0],
397
                                         ignore_failures=False)
398
    job_id = ganeti.cli.SendJob([op])
399
    return job_id
400

  
376 401

  
377 402
class R_2_instances_name_reboot(baserlib.R_Generic):
378 403
  """/2/instances/[instance_name]/reboot resource.
......
489 514
    you'll have back a job id.
490 515

  
491 516
    """
517
    if 'tag' not in self.queryargs:
518
      raise http.HttpBadRequest("Please specify tag(s) to add using the"
519
                                " the 'tag' parameter")
492 520
    return baserlib._Tags_PUT(self.TAG_LEVEL,
493
                              self.req.request_post_data, name=self.name)
521
                              self.queryargs['tag'], name=self.name)
494 522

  
495 523
  def DELETE(self):
496 524
    """Delete a tag.
......
502 530
    """
503 531
    if 'tag' not in self.queryargs:
504 532
      # no we not gonna delete all tags
505
      raise http.HttpNotImplemented()
533
      raise http.HttpBadRequest("Cannot delete all tags - please specify"
534
                                " tag(s) using the 'tag' parameter")
506 535
    return baserlib._Tags_DELETE(self.TAG_LEVEL,
507 536
                                 self.queryargs['tag'],
508 537
                                 name=self.name)

Also available in: Unified diff