for consumption here or from the node daemon.
@rtype: tuple
- @return: master_netdev, master_ip, master_name
+ @return: master_netdev, master_ip, master_name, primary_ip_family
@raise RPCFail: in case of errors
"""
master_netdev = cfg.GetMasterNetdev()
master_ip = cfg.GetMasterIP()
master_node = cfg.GetMasterNode()
+ primary_ip_family = cfg.GetPrimaryIPFamily()
except errors.ConfigurationError, err:
_Fail("Cluster configuration incomplete: %s", err, exc=True)
- return (master_netdev, master_ip, master_node)
+ return (master_netdev, master_ip, master_node, primary_ip_family)
def StartMaster(start_daemons, no_voting):
"""
# GetMasterInfo will raise an exception if not able to return data
- master_netdev, master_ip, _ = GetMasterInfo()
+ master_netdev, master_ip, _, family = GetMasterInfo()
err_msgs = []
# either start the master and rapi daemons
logging.error(msg)
err_msgs.append(msg)
else:
- result = utils.RunCmd(["ip", "address", "add", "%s/32" % master_ip,
+ ipcls = netutils.IP4Address
+ if family == netutils.IP6Address.family:
+ ipcls = netutils.IP6Address
+
+ result = utils.RunCmd(["ip", "address", "add",
+ "%s/%d" % (master_ip, ipcls.iplen),
"dev", master_netdev, "label",
"%s:0" % master_netdev])
if result.failed:
logging.error(msg)
err_msgs.append(msg)
- result = utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_netdev,
- "-s", master_ip, master_ip])
- # we'll ignore the exit code of arping
+ # we ignore the exit code of the following cmds
+ if ipcls == netutils.IP4Address:
+ utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_netdev, "-s",
+ master_ip, master_ip])
+ elif ipcls == netutils.IP6Address:
+ try:
+ utils.RunCmd(["ndisc6", "-q", "-r 3", master_ip, master_netdev])
+ except errors.OpExecError:
+ # TODO: Better error reporting
+ logging.warning("Can't execute ndisc6, please install if missing")
if err_msgs:
_Fail("; ".join(err_msgs))
# need to decide in which case we fail the RPC for this
# GetMasterInfo will raise an exception if not able to return data
- master_netdev, master_ip, _ = GetMasterInfo()
+ master_netdev, master_ip, _, family = GetMasterInfo()
- result = utils.RunCmd(["ip", "address", "del", "%s/32" % master_ip,
+ ipcls = netutils.IP4Address
+ if family == netutils.IP6Address.family:
+ ipcls = netutils.IP6Address
+
+ result = utils.RunCmd(["ip", "address", "del",
+ "%s/%d" % (master_ip, ipcls.iplen),
"dev", master_netdev])
if result.failed:
logging.error("Can't remove the master IP, error: %s", result.output)
result.cmd, result.exit_code, result.output)
-def AddNode(dsa, dsapub, rsa, rsapub, sshkey, sshpub):
- """Joins this node to the cluster.
-
- This does the following:
- - updates the hostkeys of the machine (rsa and dsa)
- - adds the ssh private key to the user
- - adds the ssh public key to the users' authorized_keys file
-
- @type dsa: str
- @param dsa: the DSA private key to write
- @type dsapub: str
- @param dsapub: the DSA public key to write
- @type rsa: str
- @param rsa: the RSA private key to write
- @type rsapub: str
- @param rsapub: the RSA public key to write
- @type sshkey: str
- @param sshkey: the SSH private key to write
- @type sshpub: str
- @param sshpub: the SSH public key to write
- @rtype: boolean
- @return: the success of the operation
+def EtcHostsModify(mode, host, ip):
+ """Modify a host entry in /etc/hosts.
- """
- sshd_keys = [(constants.SSH_HOST_RSA_PRIV, rsa, 0600),
- (constants.SSH_HOST_RSA_PUB, rsapub, 0644),
- (constants.SSH_HOST_DSA_PRIV, dsa, 0600),
- (constants.SSH_HOST_DSA_PUB, dsapub, 0644)]
- for name, content, mode in sshd_keys:
- utils.WriteFile(name, data=content, mode=mode)
+ @param mode: The mode to operate. Either add or remove entry
+ @param host: The host to operate on
+ @param ip: The ip associated with the entry
- try:
- priv_key, pub_key, auth_keys = ssh.GetUserFiles(constants.GANETI_RUNAS,
- mkdir=True)
- except errors.OpExecError, err:
- _Fail("Error while processing user ssh files: %s", err, exc=True)
-
- for name, content in [(priv_key, sshkey), (pub_key, sshpub)]:
- utils.WriteFile(name, data=content, mode=0600)
-
- utils.AddAuthorizedKey(auth_keys, sshpub)
-
- result = utils.RunCmd([constants.DAEMON_UTIL, "reload-ssh-keys"])
- if result.failed:
- _Fail("Unable to reload SSH keys (command %r, exit code %s, output %r)",
- result.cmd, result.exit_code, result.output)
+ """
+ if mode == constants.ETC_HOSTS_ADD:
+ if not ip:
+ RPCFail("Mode 'add' needs 'ip' parameter, but parameter not"
+ " present")
+ utils.AddHostToEtcHosts(host, ip)
+ elif mode == constants.ETC_HOSTS_REMOVE:
+ if ip:
+ RPCFail("Mode 'remove' does not allow 'ip' parameter, but"
+ " parameter is present")
+ utils.RemoveHostFromEtcHosts(host)
+ else:
+ RPCFail("Mode not supported")
def LeaveCluster(modify_ssh_setup):
"""
result = {}
- my_name = netutils.HostInfo().name
+ my_name = netutils.Hostname.GetSysName()
port = netutils.GetDaemonPort(constants.NODED)
if constants.NV_HYPERVISOR in what:
"""
(key_pem, cert_pem) = \
- utils.GenerateSelfSignedX509Cert(netutils.HostInfo.SysName(),
+ utils.GenerateSelfSignedX509Cert(netutils.Hostname.GetSysName(),
min(validity, _MAX_SSL_CERT_VALIDITY))
cert_dir = tempfile.mkdtemp(dir=cryptodir,
"""
# set the correct physical ID
- my_name = netutils.HostInfo().name
+ my_name = netutils.Hostname.GetSysName()
for cf in disks:
cf.SetPhysicalID(my_name, nodes_ip)