Revision d0c8c01d lib/cmdlib.py

b/lib/cmdlib.py
998 998
  bep = cluster.FillBE(instance)
999 999
  hvp = cluster.FillHV(instance)
1000 1000
  args = {
1001
    'name': instance.name,
1002
    'primary_node': instance.primary_node,
1003
    'secondary_nodes': instance.secondary_nodes,
1004
    'os_type': instance.os,
1005
    'status': instance.admin_up,
1006
    'memory': bep[constants.BE_MEMORY],
1007
    'vcpus': bep[constants.BE_VCPUS],
1008
    'nics': _NICListToTuple(lu, instance.nics),
1009
    'disk_template': instance.disk_template,
1010
    'disks': [(disk.size, disk.mode) for disk in instance.disks],
1011
    'bep': bep,
1012
    'hvp': hvp,
1013
    'hypervisor_name': instance.hypervisor,
1014
    'tags': instance.tags,
1001
    "name": instance.name,
1002
    "primary_node": instance.primary_node,
1003
    "secondary_nodes": instance.secondary_nodes,
1004
    "os_type": instance.os,
1005
    "status": instance.admin_up,
1006
    "memory": bep[constants.BE_MEMORY],
1007
    "vcpus": bep[constants.BE_VCPUS],
1008
    "nics": _NICListToTuple(lu, instance.nics),
1009
    "disk_template": instance.disk_template,
1010
    "disks": [(disk.size, disk.mode) for disk in instance.disks],
1011
    "bep": bep,
1012
    "hvp": hvp,
1013
    "hypervisor_name": instance.hypervisor,
1014
    "tags": instance.tags,
1015 1015
  }
1016 1016
  if override:
1017 1017
    args.update(override)
......
2840 2840
          self._ErrorIf(test, self.ENODEHOOKS, node_name,
2841 2841
                        "Script %s failed, output:", script)
2842 2842
          if test:
2843
            output = self._HOOKS_INDENT_RE.sub('      ', output)
2843
            output = self._HOOKS_INDENT_RE.sub("      ", output)
2844 2844
            feedback_fn("%s" % output)
2845 2845
            lu_result = 0
2846 2846

  
......
4279 4279
          if field == "node":
4280 4280
            val = node
4281 4281
          elif field == "phys":
4282
            val = vol['dev']
4282
            val = vol["dev"]
4283 4283
          elif field == "vg":
4284
            val = vol['vg']
4284
            val = vol["vg"]
4285 4285
          elif field == "name":
4286
            val = vol['name']
4286
            val = vol["name"]
4287 4287
          elif field == "size":
4288
            val = int(float(vol['size']))
4288
            val = int(float(vol["size"]))
4289 4289
          elif field == "instance":
4290 4290
            val = vol2inst.get((node, vol["vg"] + "/" + vol["name"]), "-")
4291 4291
          else:
......
5526 5526
  nodeinfo = lu.rpc.call_node_info([node], None, hypervisor_name)
5527 5527
  nodeinfo[node].Raise("Can't get data from node %s" % node,
5528 5528
                       prereq=True, ecode=errors.ECODE_ENVIRON)
5529
  free_mem = nodeinfo[node].payload.get('memory_free', None)
5529
  free_mem = nodeinfo[node].payload.get("memory_free", None)
5530 5530
  if not isinstance(free_mem, int):
5531 5531
    raise errors.OpPrereqError("Can't compute free memory on node %s, result"
5532 5532
                               " was '%s'" % (node, free_mem),
......
8432 8432

  
8433 8433
      disk_images = []
8434 8434
      for idx in range(export_disks):
8435
        option = 'disk%d_dump' % idx
8435
        option = "disk%d_dump" % idx
8436 8436
        if export_info.has_option(constants.INISECT_INS, option):
8437 8437
          # FIXME: are the old os-es, disk sizes, etc. useful?
8438 8438
          export_name = export_info.get(constants.INISECT_INS, option)
......
8443 8443

  
8444 8444
      self.src_images = disk_images
8445 8445

  
8446
      old_name = export_info.get(constants.INISECT_INS, 'name')
8446
      old_name = export_info.get(constants.INISECT_INS, "name")
8447 8447
      try:
8448
        exp_nic_count = export_info.getint(constants.INISECT_INS, 'nic_count')
8448
        exp_nic_count = export_info.getint(constants.INISECT_INS, "nic_count")
8449 8449
      except (TypeError, ValueError), err:
8450 8450
        raise errors.OpPrereqError("Invalid export file, nic_count is not"
8451 8451
                                   " an integer: %s" % str(err),
......
8453 8453
      if self.op.instance_name == old_name:
8454 8454
        for idx, nic in enumerate(self.nics):
8455 8455
          if nic.mac == constants.VALUE_AUTO and exp_nic_count >= idx:
8456
            nic_mac_ini = 'nic%d_mac' % idx
8456
            nic_mac_ini = "nic%d_mac" % idx
8457 8457
            nic.mac = export_info.get(constants.INISECT_INS, nic_mac_ini)
8458 8458

  
8459 8459
    # ENDIF: self.op.mode == constants.INSTANCE_IMPORT
......
10374 10374
            raise errors.OpPrereqError("Invalid IP address '%s'" % nic_ip,
10375 10375
                                       errors.ECODE_INVAL)
10376 10376

  
10377
      nic_bridge = nic_dict.get('bridge', None)
10377
      nic_bridge = nic_dict.get("bridge", None)
10378 10378
      nic_link = nic_dict.get(constants.INIC_LINK, None)
10379 10379
      if nic_bridge and nic_link:
10380 10380
        raise errors.OpPrereqError("Cannot pass 'bridge' and 'link'"
10381 10381
                                   " at the same time", errors.ECODE_INVAL)
10382 10382
      elif nic_bridge and nic_bridge.lower() == constants.VALUE_NONE:
10383
        nic_dict['bridge'] = None
10383
        nic_dict["bridge"] = None
10384 10384
      elif nic_link and nic_link.lower() == constants.VALUE_NONE:
10385 10385
        nic_dict[constants.INIC_LINK] = None
10386 10386

  
......
10423 10423
    """
10424 10424
    args = dict()
10425 10425
    if constants.BE_MEMORY in self.be_new:
10426
      args['memory'] = self.be_new[constants.BE_MEMORY]
10426
      args["memory"] = self.be_new[constants.BE_MEMORY]
10427 10427
    if constants.BE_VCPUS in self.be_new:
10428
      args['vcpus'] = self.be_new[constants.BE_VCPUS]
10428
      args["vcpus"] = self.be_new[constants.BE_VCPUS]
10429 10429
    # TODO: export disk changes. Note: _BuildInstanceHookEnv* don't export disk
10430 10430
    # information at all.
10431 10431
    if self.op.nics:
10432
      args['nics'] = []
10432
      args["nics"] = []
10433 10433
      nic_override = dict(self.op.nics)
10434 10434
      for idx, nic in enumerate(self.instance.nics):
10435 10435
        if idx in nic_override:
......
10450 10450
          nicparams = self.cluster.SimpleFillNIC(nic.nicparams)
10451 10451
        mode = nicparams[constants.NIC_MODE]
10452 10452
        link = nicparams[constants.NIC_LINK]
10453
        args['nics'].append((ip, mac, mode, link))
10453
        args["nics"].append((ip, mac, mode, link))
10454 10454
      if constants.DDM_ADD in nic_override:
10455 10455
        ip = nic_override[constants.DDM_ADD].get(constants.INIC_IP, None)
10456 10456
        mac = nic_override[constants.DDM_ADD][constants.INIC_MAC]
10457 10457
        nicparams = self.nic_pnew[constants.DDM_ADD]
10458 10458
        mode = nicparams[constants.NIC_MODE]
10459 10459
        link = nicparams[constants.NIC_LINK]
10460
        args['nics'].append((ip, mac, mode, link))
10460
        args["nics"].append((ip, mac, mode, link))
10461 10461
      elif constants.DDM_REMOVE in nic_override:
10462
        del args['nics'][-1]
10462
        del args["nics"][-1]
10463 10463

  
10464 10464
    env = _BuildInstanceHookEnvByObject(self, self.instance, override=args)
10465 10465
    if self.op.disk_template:
......
10577 10577
        # Assume the primary node is unreachable and go ahead
10578 10578
        self.warn.append("Can't get info from primary node %s: %s" %
10579 10579
                         (pnode,  msg))
10580
      elif not isinstance(pninfo.payload.get('memory_free', None), int):
10580
      elif not isinstance(pninfo.payload.get("memory_free", None), int):
10581 10581
        self.warn.append("Node data from primary node %s doesn't contain"
10582 10582
                         " free memory information" % pnode)
10583 10583
      elif instance_info.fail_msg:
......
10585 10585
                        instance_info.fail_msg)
10586 10586
      else:
10587 10587
        if instance_info.payload:
10588
          current_mem = int(instance_info.payload['memory'])
10588
          current_mem = int(instance_info.payload["memory"])
10589 10589
        else:
10590 10590
          # Assume instance not running
10591 10591
          # (there is a slight race condition here, but it's not very probable,
10592 10592
          # and we have no other way to check)
10593 10593
          current_mem = 0
10594 10594
        miss_mem = (be_new[constants.BE_MEMORY] - current_mem -
10595
                    pninfo.payload['memory_free'])
10595
                    pninfo.payload["memory_free"])
10596 10596
        if miss_mem > 0:
10597 10597
          raise errors.OpPrereqError("This change will prevent the instance"
10598 10598
                                     " from starting, due to %d MB of memory"
......
10605 10605
            continue
10606 10606
          nres.Raise("Can't get info from secondary node %s" % node,
10607 10607
                     prereq=True, ecode=errors.ECODE_STATE)
10608
          if not isinstance(nres.payload.get('memory_free', None), int):
10608
          if not isinstance(nres.payload.get("memory_free", None), int):
10609 10609
            raise errors.OpPrereqError("Secondary node %s didn't return free"
10610 10610
                                       " memory information" % node,
10611 10611
                                       errors.ECODE_STATE)
10612
          elif be_new[constants.BE_MEMORY] > nres.payload['memory_free']:
10612
          elif be_new[constants.BE_MEMORY] > nres.payload["memory_free"]:
10613 10613
            raise errors.OpPrereqError("This change will prevent the instance"
10614 10614
                                       " from failover to its secondary node"
10615 10615
                                       " %s, due to not enough memory" % node,
......
10645 10645
                                 for key in constants.NICS_PARAMETERS
10646 10646
                                 if key in nic_dict])
10647 10647

  
10648
      if 'bridge' in nic_dict:
10649
        update_params_dict[constants.NIC_LINK] = nic_dict['bridge']
10648
      if "bridge" in nic_dict:
10649
        update_params_dict[constants.NIC_LINK] = nic_dict["bridge"]
10650 10650

  
10651 10651
      new_nic_params = _GetUpdatedParams(old_nic_params,
10652 10652
                                         update_params_dict)
......
10672 10672
        else:
10673 10673
          nic_ip = old_nic_ip
10674 10674
        if nic_ip is None:
10675
          raise errors.OpPrereqError('Cannot set the nic ip to None'
10676
                                     ' on a routed nic', errors.ECODE_INVAL)
10675
          raise errors.OpPrereqError("Cannot set the nic ip to None"
10676
                                     " on a routed nic", errors.ECODE_INVAL)
10677 10677
      if constants.INIC_MAC in nic_dict:
10678 10678
        nic_mac = nic_dict[constants.INIC_MAC]
10679 10679
        if nic_mac is None:
10680
          raise errors.OpPrereqError('Cannot set the nic mac to None',
10680
          raise errors.OpPrereqError("Cannot set the nic mac to None",
10681 10681
                                     errors.ECODE_INVAL)
10682 10682
        elif nic_mac in (constants.VALUE_AUTO, constants.VALUE_GENERATE):
10683 10683
          # otherwise generate the mac
......
12565 12565
                                nname)
12566 12566
        remote_info = nresult.payload
12567 12567

  
12568
        for attr in ['memory_total', 'memory_free', 'memory_dom0',
12569
                     'vg_size', 'vg_free', 'cpu_total']:
12568
        for attr in ["memory_total", "memory_free", "memory_dom0",
12569
                     "vg_size", "vg_free", "cpu_total"]:
12570 12570
          if attr not in remote_info:
12571 12571
            raise errors.OpExecError("Node '%s' didn't return attribute"
12572 12572
                                     " '%s'" % (nname, attr))
......
12582 12582
            if iinfo.name not in node_iinfo[nname].payload:
12583 12583
              i_used_mem = 0
12584 12584
            else:
12585
              i_used_mem = int(node_iinfo[nname].payload[iinfo.name]['memory'])
12585
              i_used_mem = int(node_iinfo[nname].payload[iinfo.name]["memory"])
12586 12586
            i_mem_diff = beinfo[constants.BE_MEMORY] - i_used_mem
12587
            remote_info['memory_free'] -= max(0, i_mem_diff)
12587
            remote_info["memory_free"] -= max(0, i_mem_diff)
12588 12588

  
12589 12589
            if iinfo.admin_up:
12590 12590
              i_p_up_mem += beinfo[constants.BE_MEMORY]
12591 12591

  
12592 12592
        # compute memory used by instances
12593 12593
        pnr_dyn = {
12594
          "total_memory": remote_info['memory_total'],
12595
          "reserved_memory": remote_info['memory_dom0'],
12596
          "free_memory": remote_info['memory_free'],
12597
          "total_disk": remote_info['vg_size'],
12598
          "free_disk": remote_info['vg_free'],
12599
          "total_cpus": remote_info['cpu_total'],
12594
          "total_memory": remote_info["memory_total"],
12595
          "reserved_memory": remote_info["memory_dom0"],
12596
          "free_memory": remote_info["memory_free"],
12597
          "total_disk": remote_info["vg_size"],
12598
          "free_disk": remote_info["vg_free"],
12599
          "total_cpus": remote_info["cpu_total"],
12600 12600
          "i_pri_memory": i_p_mem,
12601 12601
          "i_pri_up_memory": i_p_up_mem,
12602 12602
          }

Also available in: Unified diff