Revision 5eacbcae lib/cmdlib/cluster.py

b/lib/cmdlib/cluster.py
49 49
from ganeti import utils
50 50
from ganeti import vcluster
51 51

  
52
from ganeti.cmdlib.base import NoHooksLU, _QueryBase, LogicalUnit, \
52
from ganeti.cmdlib.base import NoHooksLU, QueryBase, LogicalUnit, \
53 53
  ResultWithJobs
54
from ganeti.cmdlib.common import _ShareAll, _RunPostHook, \
55
  _ComputeAncillaryFiles, _RedistributeAncillaryFiles, _UploadHelper, \
56
  _GetWantedInstances, _MergeAndVerifyHvState, _MergeAndVerifyDiskState, \
57
  _GetUpdatedIPolicy, _ComputeNewInstanceViolations, _GetUpdatedParams, \
58
  _CheckOSParams, _CheckHVParams, _AdjustCandidatePool, _CheckNodePVs, \
59
  _ComputeIPolicyInstanceViolation, _AnnotateDiskParams, \
60
  _SupportsOob
54
from ganeti.cmdlib.common import ShareAll, RunPostHook, \
55
  ComputeAncillaryFiles, RedistributeAncillaryFiles, UploadHelper, \
56
  GetWantedInstances, MergeAndVerifyHvState, MergeAndVerifyDiskState, \
57
  GetUpdatedIPolicy, ComputeNewInstanceViolations, GetUpdatedParams, \
58
  CheckOSParams, CheckHVParams, AdjustCandidatePool, CheckNodePVs, \
59
  ComputeIPolicyInstanceViolation, AnnotateDiskParams, SupportsOob
61 60

  
62 61
import ganeti.masterd.instance
63 62

  
......
99 98
  REQ_BGL = False
100 99

  
101 100
  def CheckArguments(self):
102
    self.cq = _ClusterQuery(None, self.op.output_fields, False)
101
    self.cq = ClusterQuery(None, self.op.output_fields, False)
103 102

  
104 103
  def ExpandNames(self):
105 104
    self.cq.ExpandNames(self)
......
164 163
    master_params = self.cfg.GetMasterNetworkParameters()
165 164

  
166 165
    # Run post hooks on master node before it's removed
167
    _RunPostHook(self, master_params.name)
166
    RunPostHook(self, master_params.name)
168 167

  
169 168
    ems = self.cfg.GetUseExternalMipScript()
170 169
    result = self.rpc.call_node_deactivate_master_ip(master_params.name,
......
204 203
    return True
205 204

  
206 205

  
207
class _ClusterQuery(_QueryBase):
206
class ClusterQuery(QueryBase):
208 207
  FIELDS = query.CLUSTER_FIELDS
209 208

  
210 209
  #: Do not sort (there is only one item)
......
344 343
      locking.LEVEL_NODE: locking.ALL_SET,
345 344
      locking.LEVEL_NODE_ALLOC: locking.ALL_SET,
346 345
    }
347
    self.share_locks = _ShareAll()
346
    self.share_locks = ShareAll()
348 347

  
349 348
  def Exec(self, feedback_fn):
350 349
    """Redistribute the configuration.
351 350

  
352 351
    """
353 352
    self.cfg.Update(self.cfg.GetClusterInfo(), feedback_fn)
354
    _RedistributeAncillaryFiles(self)
353
    RedistributeAncillaryFiles(self)
355 354

  
356 355

  
357 356
class LUClusterRename(LogicalUnit):
......
426 425
        node_list.remove(master_params.name)
427 426
      except ValueError:
428 427
        pass
429
      _UploadHelper(self, node_list, pathutils.SSH_KNOWN_HOSTS_FILE)
428
      UploadHelper(self, node_list, pathutils.SSH_KNOWN_HOSTS_FILE)
430 429
    finally:
431 430
      master_params.ip = new_ip
432 431
      result = self.rpc.call_node_activate_master_ip(master_params.name,
......
447 446

  
448 447
  def ExpandNames(self):
449 448
    if self.op.instances:
450
      self.wanted_names = _GetWantedInstances(self, self.op.instances)
449
      self.wanted_names = GetWantedInstances(self, self.op.instances)
451 450
      # Not getting the node allocation lock as only a specific set of
452 451
      # instances (and their nodes) is going to be acquired
453 452
      self.needed_locks = {
......
633 632
      locking.LEVEL_NODEGROUP: locking.ALL_SET,
634 633
      locking.LEVEL_NODE_ALLOC: locking.ALL_SET,
635 634
    }
636
    self.share_locks = _ShareAll()
635
    self.share_locks = ShareAll()
637 636

  
638 637
  def BuildHooksEnv(self):
639 638
    """Build hooks env.
......
727 726
            constants.NDC_DEFAULTS[constants.ND_OOB_PROGRAM]
728 727

  
729 728
    if self.op.hv_state:
730
      new_hv_state = _MergeAndVerifyHvState(self.op.hv_state,
731
                                            self.cluster.hv_state_static)
729
      new_hv_state = MergeAndVerifyHvState(self.op.hv_state,
730
                                           self.cluster.hv_state_static)
732 731
      self.new_hv_state = dict((hv, cluster.SimpleFillHvState(values))
733 732
                               for hv, values in new_hv_state.items())
734 733

  
735 734
    if self.op.disk_state:
736
      new_disk_state = _MergeAndVerifyDiskState(self.op.disk_state,
737
                                                self.cluster.disk_state_static)
735
      new_disk_state = MergeAndVerifyDiskState(self.op.disk_state,
736
                                               self.cluster.disk_state_static)
738 737
      self.new_disk_state = \
739 738
        dict((storage, dict((name, cluster.SimpleFillDiskState(values))
740 739
                            for name, values in svalues.items()))
741 740
             for storage, svalues in new_disk_state.items())
742 741

  
743 742
    if self.op.ipolicy:
744
      self.new_ipolicy = _GetUpdatedIPolicy(cluster.ipolicy, self.op.ipolicy,
745
                                            group_policy=False)
743
      self.new_ipolicy = GetUpdatedIPolicy(cluster.ipolicy, self.op.ipolicy,
744
                                           group_policy=False)
746 745

  
747 746
      all_instances = self.cfg.GetAllInstancesInfo().values()
748 747
      violations = set()
......
752 751
                                             for node in inst.all_nodes)])
753 752
        new_ipolicy = objects.FillIPolicy(self.new_ipolicy, group.ipolicy)
754 753
        ipol = masterd.instance.CalculateGroupIPolicy(cluster, group)
755
        new = _ComputeNewInstanceViolations(ipol,
756
                                            new_ipolicy, instances, self.cfg)
754
        new = ComputeNewInstanceViolations(ipol,
755
                                           new_ipolicy, instances, self.cfg)
757 756
        if new:
758 757
          violations.update(new)
759 758

  
......
831 830
        if os_name not in self.new_osp:
832 831
          self.new_osp[os_name] = {}
833 832

  
834
        self.new_osp[os_name] = _GetUpdatedParams(self.new_osp[os_name], osp,
835
                                                  use_none=True)
833
        self.new_osp[os_name] = GetUpdatedParams(self.new_osp[os_name], osp,
834
                                                 use_none=True)
836 835

  
837 836
        if not self.new_osp[os_name]:
838 837
          # we removed all parameters
839 838
          del self.new_osp[os_name]
840 839
        else:
841 840
          # check the parameter validity (remote check)
842
          _CheckOSParams(self, False, [self.cfg.GetMasterNode()],
843
                         os_name, self.new_osp[os_name])
841
          CheckOSParams(self, False, [self.cfg.GetMasterNode()],
842
                        os_name, self.new_osp[os_name])
844 843

  
845 844
    # changes to the hypervisor list
846 845
    if self.op.enabled_hypervisors is not None:
......
868 867
          hv_class = hypervisor.GetHypervisorClass(hv_name)
869 868
          utils.ForceDictType(hv_params, constants.HVS_PARAMETER_TYPES)
870 869
          hv_class.CheckParameterSyntax(hv_params)
871
          _CheckHVParams(self, node_list, hv_name, hv_params)
870
          CheckHVParams(self, node_list, hv_name, hv_params)
872 871

  
873 872
    self._CheckDiskTemplateConsistency()
874 873

  
......
883 882
          new_osp = objects.FillDict(cluster_defaults, hv_params)
884 883
          hv_class = hypervisor.GetHypervisorClass(hv_name)
885 884
          hv_class.CheckParameterSyntax(new_osp)
886
          _CheckHVParams(self, node_list, hv_name, new_osp)
885
          CheckHVParams(self, node_list, hv_name, new_osp)
887 886

  
888 887
    if self.op.default_iallocator:
889 888
      alloc_script = utils.FindFile(self.op.default_iallocator,
......
963 962
    if self.op.candidate_pool_size is not None:
964 963
      self.cluster.candidate_pool_size = self.op.candidate_pool_size
965 964
      # we need to update the pool size here, otherwise the save will fail
966
      _AdjustCandidatePool(self, [])
965
      AdjustCandidatePool(self, [])
967 966

  
968 967
    if self.op.maintain_node_health is not None:
969 968
      if self.op.maintain_node_health and not constants.ENABLE_CONFD:
......
1242 1241

  
1243 1242
  def ExpandNames(self):
1244 1243
    self.needed_locks = dict.fromkeys(locking.LEVELS, locking.ALL_SET)
1245
    self.share_locks = _ShareAll()
1244
    self.share_locks = ShareAll()
1246 1245

  
1247 1246
  def CheckPrereq(self):
1248 1247
    """Check prerequisites.
......
1399 1398
      locking.LEVEL_NODE_ALLOC: locking.ALL_SET,
1400 1399
      }
1401 1400

  
1402
    self.share_locks = _ShareAll()
1401
    self.share_locks = ShareAll()
1403 1402

  
1404 1403
  def DeclareLocks(self, level):
1405 1404
    if level == locking.LEVEL_NODE:
......
1607 1606
      _ErrorIf(vgstatus, constants.CV_ENODELVM, node, vgstatus)
1608 1607

  
1609 1608
    # Check PVs
1610
    (errmsgs, pvminmax) = _CheckNodePVs(nresult, self._exclusive_storage)
1609
    (errmsgs, pvminmax) = CheckNodePVs(nresult, self._exclusive_storage)
1611 1610
    for em in errmsgs:
1612 1611
      self._Error(constants.CV_ENODELVM, node, em)
1613 1612
    if pvminmax is not None:
......
1748 1747
    cluster = self.cfg.GetClusterInfo()
1749 1748
    ipolicy = ganeti.masterd.instance.CalculateGroupIPolicy(cluster,
1750 1749
                                                            self.group_info)
1751
    err = _ComputeIPolicyInstanceViolation(ipolicy, inst_config, self.cfg)
1750
    err = ComputeIPolicyInstanceViolation(ipolicy, inst_config, self.cfg)
1752 1751
    _ErrorIf(err, constants.CV_EINSTANCEPOLICY, instance, utils.CommaJoin(err),
1753 1752
             code=self.ETYPE_WARNING)
1754 1753

  
......
2354 2353
      # _AnnotateDiskParams makes already copies of the disks
2355 2354
      devonly = []
2356 2355
      for (inst, dev) in disks:
2357
        (anno_disk,) = _AnnotateDiskParams(instanceinfo[inst], [dev], self.cfg)
2356
        (anno_disk,) = AnnotateDiskParams(instanceinfo[inst], [dev], self.cfg)
2358 2357
        self.cfg.SetDiskID(anno_disk, nname)
2359 2358
        devonly.append(anno_disk)
2360 2359

  
......
2505 2504
    # FIXME: verify OS list
2506 2505

  
2507 2506
    # File verification
2508
    filemap = _ComputeAncillaryFiles(cluster, False)
2507
    filemap = ComputeAncillaryFiles(cluster, False)
2509 2508

  
2510 2509
    # do local checksums
2511 2510
    master_node = self.master_node = self.cfg.GetMasterNode()
......
2580 2579
    # Gather OOB paths
2581 2580
    oob_paths = []
2582 2581
    for node in self.all_node_info.values():
2583
      path = _SupportsOob(self.cfg, node)
2582
      path = SupportsOob(self.cfg, node)
2584 2583
      if path and path not in oob_paths:
2585 2584
        oob_paths.append(path)
2586 2585

  
......
2862 2861
  REQ_BGL = False
2863 2862

  
2864 2863
  def ExpandNames(self):
2865
    self.share_locks = _ShareAll()
2864
    self.share_locks = ShareAll()
2866 2865
    self.needed_locks = {
2867 2866
      locking.LEVEL_NODEGROUP: locking.ALL_SET,
2868 2867
      }

Also available in: Unified diff