Revision d6a02168 lib/cmdlib.py

b/lib/cmdlib.py
101 101
      raise errors.OpPrereqError("Cluster not initialized yet,"
102 102
                                 " use 'gnt-cluster init' first.")
103 103
    if self.REQ_MASTER:
104
      master = sstore.GetMasterNode()
104
      master = self.cfg.GetMasterNode()
105 105
      if master != utils.HostInfo().name:
106 106
        raise errors.OpPrereqError("Commands must be run on the master"
107 107
                                   " node %s" % master)
......
471 471
    Any errors are signalled by raising errors.OpPrereqError.
472 472

  
473 473
    """
474
    master = self.sstore.GetMasterNode()
474
    master = self.cfg.GetMasterNode()
475 475

  
476 476
    nodelist = self.cfg.GetNodeList()
477 477
    if len(nodelist) != 1 or nodelist[0] != master:
......
486 486
    """Destroys the cluster.
487 487

  
488 488
    """
489
    master = self.sstore.GetMasterNode()
489
    master = self.cfg.GetMasterNode()
490 490
    if not rpc.call_node_stop_master(master, False):
491 491
      raise errors.OpExecError("Could not disable the master role")
492 492
    priv_key, pub_key, _ = ssh.GetUserFiles(constants.GANETI_RUNAS)
......
735 735

  
736 736
    # FIXME: verify OS list
737 737
    # do local checksums
738
    file_names = list(self.sstore.GetFileList())
738
    file_names = []
739 739
    file_names.append(constants.SSL_CERT_FILE)
740 740
    file_names.append(constants.CLUSTER_CONF_FILE)
741 741
    local_checksums = utils.FingerprintFiles(file_names)
......
1006 1006
  HPATH = "cluster-rename"
1007 1007
  HTYPE = constants.HTYPE_CLUSTER
1008 1008
  _OP_REQP = ["name"]
1009
  REQ_WSSTORE = True
1010 1009

  
1011 1010
  def BuildHooksEnv(self):
1012 1011
    """Build hooks env.
1013 1012

  
1014 1013
    """
1015 1014
    env = {
1016
      "OP_TARGET": self.sstore.GetClusterName(),
1015
      "OP_TARGET": self.cfg.GetClusterName(),
1017 1016
      "NEW_NAME": self.op.name,
1018 1017
      }
1019
    mn = self.sstore.GetMasterNode()
1018
    mn = self.cfg.GetMasterNode()
1020 1019
    return env, [mn], [mn]
1021 1020

  
1022 1021
  def CheckPrereq(self):
......
1027 1026

  
1028 1027
    new_name = hostname.name
1029 1028
    self.ip = new_ip = hostname.ip
1030
    old_name = self.sstore.GetClusterName()
1031
    old_ip = self.sstore.GetMasterIP()
1029
    old_name = self.cfg.GetClusterName()
1030
    old_ip = self.cfg.GetMasterIP()
1032 1031
    if new_name == old_name and new_ip == old_ip:
1033 1032
      raise errors.OpPrereqError("Neither the name nor the IP address of the"
1034 1033
                                 " cluster has changed")
......
1046 1045
    """
1047 1046
    clustername = self.op.name
1048 1047
    ip = self.ip
1049
    ss = self.sstore
1050 1048

  
1051 1049
    # shutdown the master IP
1052
    master = ss.GetMasterNode()
1050
    master = self.cfg.GetMasterNode()
1053 1051
    if not rpc.call_node_stop_master(master, False):
1054 1052
      raise errors.OpExecError("Could not disable the master role")
1055 1053

  
1056 1054
    try:
1057 1055
      # modify the sstore
1056
      # TODO: sstore
1058 1057
      ss.SetKey(ss.SS_MASTER_IP, ip)
1059 1058
      ss.SetKey(ss.SS_CLUSTER_NAME, clustername)
1060 1059

  
......
1117 1116

  
1118 1117
    """
1119 1118
    env = {
1120
      "OP_TARGET": self.sstore.GetClusterName(),
1119
      "OP_TARGET": self.cfg.GetClusterName(),
1121 1120
      "NEW_VG_NAME": self.op.vg_name,
1122 1121
      }
1123
    mn = self.sstore.GetMasterNode()
1122
    mn = self.cfg.GetMasterNode()
1124 1123
    return env, [mn], [mn]
1125 1124

  
1126 1125
  def CheckPrereq(self):
......
1375 1374

  
1376 1375
    instance_list = self.cfg.GetInstanceList()
1377 1376

  
1378
    masternode = self.sstore.GetMasterNode()
1377
    masternode = self.cfg.GetMasterNode()
1379 1378
    if node.name == masternode:
1380 1379
      raise errors.OpPrereqError("Node is the master node,"
1381 1380
                                 " you need to failover first.")
......
1695 1694

  
1696 1695
    # check that the type of the node (single versus dual homed) is the
1697 1696
    # same as for the master
1698
    myself = cfg.GetNodeInfo(self.sstore.GetMasterNode())
1697
    myself = cfg.GetNodeInfo(self.cfg.GetMasterNode())
1699 1698
    master_singlehomed = myself.secondary_ip == myself.primary_ip
1700 1699
    newbie_singlehomed = secondary_ip == primary_ip
1701 1700
    if master_singlehomed != newbie_singlehomed:
......
1775 1774
                                 " you gave (%s). Please fix and re-run this"
1776 1775
                                 " command." % new_node.secondary_ip)
1777 1776

  
1778
    node_verify_list = [self.sstore.GetMasterNode()]
1777
    node_verify_list = [self.cfg.GetMasterNode()]
1779 1778
    node_verify_param = {
1780 1779
      'nodelist': [node],
1781 1780
      # TODO: do a node-net-test as well?
......
1794 1793

  
1795 1794
    # Distribute updated /etc/hosts and known_hosts to all nodes,
1796 1795
    # including the node just added
1797
    myself = self.cfg.GetNodeInfo(self.sstore.GetMasterNode())
1796
    myself = self.cfg.GetNodeInfo(self.cfg.GetMasterNode())
1798 1797
    dist_nodes = self.cfg.GetNodeList()
1799 1798
    if not self.op.readd:
1800 1799
      dist_nodes.append(node)
......
1809 1808
          logger.Error("copy of file %s to node %s failed" %
1810 1809
                       (fname, to_node))
1811 1810

  
1812
    to_copy = self.sstore.GetFileList()
1813
    if self.sstore.GetHypervisorType() == constants.HT_XEN_HVM31:
1811
    to_copy = []
1812
    if self.cfg.GetHypervisorType() == constants.HT_XEN_HVM31:
1814 1813
      to_copy.append(constants.VNC_PASSWORD_FILE)
1815 1814
    for fname in to_copy:
1816 1815
      result = rpc.call_upload_file([node], fname)
......
1845 1844

  
1846 1845
    """
1847 1846
    result = {
1848
      "name": self.sstore.GetClusterName(),
1847
      "name": self.cfg.GetClusterName(),
1849 1848
      "software_version": constants.RELEASE_VERSION,
1850 1849
      "protocol_version": constants.PROTOCOL_VERSION,
1851 1850
      "config_version": constants.CONFIG_VERSION,
1852 1851
      "os_api_version": constants.OS_API_VERSION,
1853 1852
      "export_version": constants.EXPORT_VERSION,
1854
      "master": self.sstore.GetMasterNode(),
1853
      "master": self.cfg.GetMasterNode(),
1855 1854
      "architecture": (platform.architecture()[0], platform.machine()),
1856
      "hypervisor_type": self.sstore.GetHypervisorType(),
1855
      "hypervisor_type": self.cfg.GetHypervisorType(),
1857 1856
      }
1858 1857

  
1859 1858
    return result
......
2141 2140
      "FORCE": self.op.force,
2142 2141
      }
2143 2142
    env.update(_BuildInstanceHookEnvByObject(self.instance))
2144
    nl = ([self.sstore.GetMasterNode(), self.instance.primary_node] +
2143
    nl = ([self.cfg.GetMasterNode(), self.instance.primary_node] +
2145 2144
          list(self.instance.secondary_nodes))
2146 2145
    return env, nl, nl
2147 2146

  
......
2217 2216
      "IGNORE_SECONDARIES": self.op.ignore_secondaries,
2218 2217
      }
2219 2218
    env.update(_BuildInstanceHookEnvByObject(self.instance))
2220
    nl = ([self.sstore.GetMasterNode(), self.instance.primary_node] +
2219
    nl = ([self.cfg.GetMasterNode(), self.instance.primary_node] +
2221 2220
          list(self.instance.secondary_nodes))
2222 2221
    return env, nl, nl
2223 2222

  
......
2287 2286

  
2288 2287
    """
2289 2288
    env = _BuildInstanceHookEnvByObject(self.instance)
2290
    nl = ([self.sstore.GetMasterNode(), self.instance.primary_node] +
2289
    nl = ([self.cfg.GetMasterNode(), self.instance.primary_node] +
2291 2290
          list(self.instance.secondary_nodes))
2292 2291
    return env, nl, nl
2293 2292

  
......
2339 2338

  
2340 2339
    """
2341 2340
    env = _BuildInstanceHookEnvByObject(self.instance)
2342
    nl = ([self.sstore.GetMasterNode(), self.instance.primary_node] +
2341
    nl = ([self.cfg.GetMasterNode(), self.instance.primary_node] +
2343 2342
          list(self.instance.secondary_nodes))
2344 2343
    return env, nl, nl
2345 2344

  
......
2418 2417
    """
2419 2418
    env = _BuildInstanceHookEnvByObject(self.instance)
2420 2419
    env["INSTANCE_NEW_NAME"] = self.op.new_name
2421
    nl = ([self.sstore.GetMasterNode(), self.instance.primary_node] +
2420
    nl = ([self.cfg.GetMasterNode(), self.instance.primary_node] +
2422 2421
          list(self.instance.secondary_nodes))
2423 2422
    return env, nl, nl
2424 2423

  
......
2532 2531

  
2533 2532
    """
2534 2533
    env = _BuildInstanceHookEnvByObject(self.instance)
2535
    nl = [self.sstore.GetMasterNode()]
2534
    nl = [self.cfg.GetMasterNode()]
2536 2535
    return env, nl, nl
2537 2536

  
2538 2537
  def CheckPrereq(self):
......
2772 2771
      "IGNORE_CONSISTENCY": self.op.ignore_consistency,
2773 2772
      }
2774 2773
    env.update(_BuildInstanceHookEnvByObject(self.instance))
2775
    nl = [self.sstore.GetMasterNode()] + list(self.instance.secondary_nodes)
2774
    nl = [self.cfg.GetMasterNode()] + list(self.instance.secondary_nodes)
2776 2775
    return env, nl, nl
2777 2776

  
2778 2777
  def CheckPrereq(self):
......
3257 3256
             {"size": self.op.swap_size, "mode": "w"}]
3258 3257
    nics = [{"mac": self.op.mac, "ip": getattr(self.op, "ip", None),
3259 3258
             "bridge": self.op.bridge}]
3260
    ial = IAllocator(self.cfg, self.sstore,
3259
    ial = IAllocator(self.cfg,
3261 3260
                     mode=constants.IALLOCATOR_MODE_ALLOC,
3262 3261
                     name=self.op.instance_name,
3263 3262
                     disk_template=self.op.disk_template,
......
3315 3314
      nics=[(self.inst_ip, self.op.bridge, self.op.mac)],
3316 3315
    ))
3317 3316

  
3318
    nl = ([self.sstore.GetMasterNode(), self.op.pnode] +
3317
    nl = ([self.cfg.GetMasterNode(), self.op.pnode] +
3319 3318
          self.secondaries)
3320 3319
    return env, nl, nl
3321 3320

  
......
3460 3459
                                   self.op.vnc_bind_address)
3461 3460

  
3462 3461
    # Xen HVM device type checks
3463
    if self.sstore.GetHypervisorType() == constants.HT_XEN_HVM31:
3462
    if self.cfg.GetHypervisorType() == constants.HT_XEN_HVM31:
3464 3463
      if self.op.hvm_nic_type not in constants.HT_HVM_VALID_NIC_TYPES:
3465 3464
        raise errors.OpPrereqError("Invalid NIC type %s specified for Xen HVM"
3466 3465
                                   " hypervisor" % self.op.hvm_nic_type)
......
3489 3488
    if self.inst_ip is not None:
3490 3489
      nic.ip = self.inst_ip
3491 3490

  
3492
    ht_kind = self.sstore.GetHypervisorType()
3491
    ht_kind = self.cfg.GetHypervisorType()
3493 3492
    if ht_kind in constants.HTS_REQ_PORT:
3494 3493
      network_port = self.cfg.AllocatePort()
3495 3494
    else:
......
3506 3505

  
3507 3506
    # build the full file storage dir path
3508 3507
    file_storage_dir = os.path.normpath(os.path.join(
3509
                                        self.sstore.GetFileStorageDir(),
3508
                                        self.cfg.GetFileStorageDir(),
3510 3509
                                        string_file_storage_dir, instance))
3511 3510

  
3512 3511

  
......
3693 3692
    """Compute a new secondary node using an IAllocator.
3694 3693

  
3695 3694
    """
3696
    ial = IAllocator(self.cfg, self.sstore,
3695
    ial = IAllocator(self.cfg,
3697 3696
                     mode=constants.IALLOCATOR_MODE_RELOC,
3698 3697
                     name=self.op.instance_name,
3699 3698
                     relocate_from=[self.sec_node])
......
3725 3724
      }
3726 3725
    env.update(_BuildInstanceHookEnvByObject(self.instance))
3727 3726
    nl = [
3728
      self.sstore.GetMasterNode(),
3727
      self.cfg.GetMasterNode(),
3729 3728
      self.instance.primary_node,
3730 3729
      ]
3731 3730
    if self.op.remote_node is not None:
......
4218 4217
      }
4219 4218
    env.update(_BuildInstanceHookEnvByObject(self.instance))
4220 4219
    nl = [
4221
      self.sstore.GetMasterNode(),
4220
      self.cfg.GetMasterNode(),
4222 4221
      self.instance.primary_node,
4223 4222
      ]
4224 4223
    return env, nl, nl
......
4393 4392
        "vcpus": instance.vcpus,
4394 4393
        }
4395 4394

  
4396
      htkind = self.sstore.GetHypervisorType()
4395
      htkind = self.cfg.GetHypervisorType()
4397 4396
      if htkind == constants.HT_XEN_PVM30:
4398 4397
        idict["kernel_path"] = instance.kernel_path
4399 4398
        idict["initrd_path"] = instance.initrd_path
......
4470 4469
        mac = self.instance.nics[0].mac
4471 4470
      args['nics'] = [(ip, bridge, mac)]
4472 4471
    env = _BuildInstanceHookEnvByObject(self.instance, override=args)
4473
    nl = [self.sstore.GetMasterNode(),
4472
    nl = [self.cfg.GetMasterNode(),
4474 4473
          self.instance.primary_node] + list(self.instance.secondary_nodes)
4475 4474
    return env, nl, nl
4476 4475

  
......
4618 4617
                           " node %s" % node)
4619 4618

  
4620 4619
    # Xen HVM device type checks
4621
    if self.sstore.GetHypervisorType() == constants.HT_XEN_HVM31:
4620
    if self.cfg.GetHypervisorType() == constants.HT_XEN_HVM31:
4622 4621
      if self.op.hvm_nic_type is not None:
4623 4622
        if self.op.hvm_nic_type not in constants.HT_HVM_VALID_NIC_TYPES:
4624 4623
          raise errors.OpPrereqError("Invalid NIC type %s specified for Xen"
......
4766 4765
      "EXPORT_DO_SHUTDOWN": self.op.shutdown,
4767 4766
      }
4768 4767
    env.update(_BuildInstanceHookEnvByObject(self.instance))
4769
    nl = [self.sstore.GetMasterNode(), self.instance.primary_node,
4768
    nl = [self.cfg.GetMasterNode(), self.instance.primary_node,
4770 4769
          self.op.target_node]
4771 4770
    return env, nl, nl
4772 4771

  
......
5123 5122
  """IAllocator framework.
5124 5123

  
5125 5124
  An IAllocator instance has three sets of attributes:
5126
    - cfg/sstore that are needed to query the cluster
5125
    - cfg that is needed to query the cluster
5127 5126
    - input data (all members of the _KEYS class attribute are required)
5128 5127
    - four buffer attributes (in|out_data|text), that represent the
5129 5128
      input (to the external script) in text and data structure format,
......
5140 5139
    "relocate_from",
5141 5140
    ]
5142 5141

  
5143
  def __init__(self, cfg, sstore, mode, name, **kwargs):
5142
  def __init__(self, cfg, mode, name, **kwargs):
5144 5143
    self.cfg = cfg
5145
    self.sstore = sstore
5146 5144
    # init buffer variables
5147 5145
    self.in_text = self.out_text = self.in_data = self.out_data = None
5148 5146
    # init all input fields so that pylint is happy
......
5183 5181
    # cluster data
5184 5182
    data = {
5185 5183
      "version": 1,
5186
      "cluster_name": self.sstore.GetClusterName(),
5184
      "cluster_name": self.cfg.GetClusterName(),
5187 5185
      "cluster_tags": list(cfg.GetClusterInfo().GetTags()),
5188
      "hypervisor_type": self.sstore.GetHypervisorType(),
5186
      "hypervisor_type": self.cfg.GetHypervisorType(),
5189 5187
      # we don't have job IDs
5190 5188
      }
5191 5189

  
......
5348 5346
    """
5349 5347
    data = self.in_text
5350 5348

  
5351
    result = call_fn(self.sstore.GetMasterNode(), name, self.in_text)
5349
    result = call_fn(self.cfg.GetMasterNode(), name, self.in_text)
5352 5350

  
5353 5351
    if not isinstance(result, (list, tuple)) or len(result) != 4:
5354 5352
      raise errors.OpExecError("Invalid result from master iallocator runner")
......
5461 5459

  
5462 5460
    """
5463 5461
    if self.op.mode == constants.IALLOCATOR_MODE_ALLOC:
5464
      ial = IAllocator(self.cfg, self.sstore,
5462
      ial = IAllocator(self.cfg,
5465 5463
                       mode=self.op.mode,
5466 5464
                       name=self.op.name,
5467 5465
                       mem_size=self.op.mem_size,
......
5473 5471
                       vcpus=self.op.vcpus,
5474 5472
                       )
5475 5473
    else:
5476
      ial = IAllocator(self.cfg, self.sstore,
5474
      ial = IAllocator(self.cfg,
5477 5475
                       mode=self.op.mode,
5478 5476
                       name=self.op.name,
5479 5477
                       relocate_from=list(self.relocate_from),

Also available in: Unified diff