"""
return os.path.exists(pathutils.CLUSTER_CONF_FILE)
+ def _UnlockedGetNdParams(self, node):
+ nodegroup = self._UnlockedGetNodeGroup(node.group)
+ return self._ConfigData().cluster.FillND(node, nodegroup)
+
@_ConfigSync(shared=1)
def GetNdParams(self, node):
"""Get the node params populated with cluster defaults.
@return: A dict with the filled in node params
"""
- nodegroup = self._UnlockedGetNodeGroup(node.group)
- return self._ConfigData().cluster.FillND(node, nodegroup)
+ return self._UnlockedGetNdParams(node)
@_ConfigSync(shared=1)
def GetNdGroupParams(self, nodegroup):
ssconf_values[ssconf_key] = all_hvparams[hv]
return ssconf_values
+ def _UnlockedGetSshPortMap(self, node_infos):
+ node_ports = dict([(node.name,
+ self._UnlockedGetNdParams(node).get(
+ constants.ND_SSH_PORT))
+ for node in node_infos])
+ return node_ports
+
def _UnlockedGetSsconfValues(self):
"""Return the values needed by ssconf.
self._ConfigData().networks.values()]
networks_data = fn(utils.NiceSort(networks))
+ ssh_ports = fn("%s=%s" % (node_name, port)
+ for node_name, port
+ in self._UnlockedGetSshPortMap(node_infos).items())
+
ssconf_values = {
constants.SS_CLUSTER_NAME: cluster.cluster_name,
constants.SS_CLUSTER_TAGS: cluster_tags,
constants.SS_NODEGROUPS: nodegroups_data,
constants.SS_NETWORKS: networks_data,
constants.SS_ENABLED_USER_SHUTDOWN: str(cluster.enabled_user_shutdown),
+ constants.SS_SSH_PORTS: ssh_ports,
}
ssconf_values = self._ExtendByAllHvparamsStrings(ssconf_values,
all_hvparams)
constants.SS_HVPARAMS_XEN_CHROOT,
constants.SS_HVPARAMS_XEN_LXC,
constants.SS_ENABLED_USER_SHUTDOWN,
+ constants.SS_SSH_PORTS,
])
#: Maximum size for ssconf files
nl = data.splitlines(False)
return nl
+ def _GetDictOfSsconfMap(self, ss_file_key):
+ """Reads a file with lines like key=value and returns a dict.
+
+ This utility function reads a file containing ssconf values of
+ the form "key=value", splits the lines at "=" and returns a
+ dictionary mapping the keys to the values.
+
+ @type ss_file_key: string
+ @param ss_file_key: the constant referring to an ssconf file
+ @rtype: dict of string to string
+ @return: a dictionary mapping the keys to the values
+
+ """
+ data = self._ReadFile(ss_file_key)
+ lines = data.splitlines(False)
+ mapping = {}
+ for line in lines:
+ (key, value) = line.split("=")
+ mapping[key] = value
+ return mapping
+
def GetMasterCandidatesCertMap(self):
"""Returns the map of master candidate UUIDs to ssl cert.
to their SSL certificate digests
"""
- data = self._ReadFile(constants.SS_MASTER_CANDIDATES_CERTS)
- lines = data.splitlines(False)
- certs = {}
- for line in lines:
- (node_uuid, cert_digest) = line.split("=")
- certs[node_uuid] = cert_digest
- return certs
+ return self._GetDictOfSsconfMap(constants.SS_MASTER_CANDIDATES_CERTS)
+
+ def GetSshPortMap(self):
+ """Returns the map of node names to SSH port.
+
+ @rtype: dict of string to string
+ @return: dictionary mapping the node names to their SSH port
+
+ """
+ return dict([(node_name, int(ssh_port)) for
+ node_name, ssh_port in
+ self._GetDictOfSsconfMap(constants.SS_SSH_PORTS).items()])
def GetMasterIP(self):
"""Get the IP of the master node for this cluster.
@returns: dictionary with hypervisor parameters
"""
- data = self._ReadFile(constants.SS_HVPARAMS_PREF + hvname)
- lines = data.splitlines(False)
- hvparams = {}
- for line in lines:
- (key, value) = line.split("=")
- hvparams[key] = value
- return hvparams
+ return self._GetDictOfSsconfMap(constants.SS_HVPARAMS_PREF + hvname)
def GetHvparams(self):
"""Return the hypervisor parameters of all hypervisors.
ssEnabledUserShutdown :: String
ssEnabledUserShutdown = "enabled_user_shutdown"
+ssSshPorts :: String
+ssSshPorts = "ssh_ports"
+
-- | Cluster wide default parameters
defaultEnabledHypervisor :: String
defaultEnabledHypervisor = htXenPvm
, ("SSNodegroups", C.ssNodegroups)
, ("SSNetworks", C.ssNetworks)
, ("SSEnabledUserShutdown", C.ssEnabledUserShutdown)
+ , ("SSSshPorts", C.ssSshPorts)
] ++
-- Automatically generate SSHvparamsXxx for each hypervisor type:
map ((("SSHvparams" ++) . show)
. configNetworks $ cdata)
, (SSEnabledUserShutdown, return . show . clusterEnabledUserShutdown
$ cluster)
+ , (SSSshPorts, mapLines (eqPair . (nodeName
+ &&& getSshPort cdata)) nodes)
] ++
map (first hvparamsSSKey) (mkSSConfHvparams cluster)
where
nodes = niceSortKey nodeName . toList $ configNodes cdata
(offline, online) = partition nodeOffline nodes
nodeGroups = niceSortKey groupName . toList $ configNodegroups cdata
+
+ -- This will return the empty string only for the situation where the
+ -- configuration is corrupted and no nodegroup can be found for that node.
+ getSshPort :: ConfigData -> Node -> String
+ getSshPort cfg node = maybe "" (show . ndpSshPort)
+ $ getNodeNdParams cfg node