import errno
import re
import subprocess
+import random
from ganeti import logger
from ganeti import errors
utils.RemoveFile(priv_key)
utils.RemoveFile(pub_key)
+ # Return a reassuring string to the caller, and quit
+ raise errors.QuitGanetiException(False, 'Shutdown scheduled')
+
def GetNodeInfo(vgname):
"""Gives back a hash with different informations about the node.
if 'nodelist' in what:
result['nodelist'] = {}
+ random.shuffle(what['nodelist'])
for node in what['nodelist']:
success, message = _GetSshRunner().VerifyNodeHostname(node)
if not success:
result['nodelist'][node] = message
+ if 'node-net-test' in what:
+ result['node-net-test'] = {}
+ my_name = utils.HostInfo().name
+ my_pip = my_sip = None
+ for name, pip, sip in what['node-net-test']:
+ if name == my_name:
+ my_pip = pip
+ my_sip = sip
+ break
+ if not my_pip:
+ result['node-net-test'][my_name] = ("Can't find my own"
+ " primary/secondary IP"
+ " in the node list")
+ else:
+ port = ssconf.SimpleStore().GetNodeDaemonPort()
+ for name, pip, sip in what['node-net-test']:
+ fail = []
+ if not utils.TcpPing(pip, port, source=my_pip):
+ fail.append("primary")
+ if sip != pip:
+ if not utils.TcpPing(sip, port, source=my_sip):
+ fail.append("secondary")
+ if fail:
+ result['node-net-test'][name] = ("failure using the %s"
+ " interface(s)" %
+ " and ".join(fail))
+
return result
return True
+def MigrateInstance(instance, target, live):
+ """Migrates an instance to another node.
+
+ """
+ hyper = hypervisor.GetHypervisor()
+
+ try:
+ hyper.MigrateInstance(instance, target, live)
+ except errors.HypervisorError, err:
+ msg = "Failed to migrate instance: %s" % str(err)
+ logger.Error(msg)
+ return (False, msg)
+ return (True, "Migration successfull")
+
+
def CreateBlockDevice(disk, size, owner, on_primary, info):
"""Creates a block device for an instance.
constants.CLUSTER_CONF_FILE,
constants.ETC_HOSTS,
constants.SSH_KNOWN_HOSTS_FILE,
+ constants.VNC_PASSWORD_FILE,
]
allowed_files.extend(ssconf.SimpleStore().GetFileList())
if file_name not in allowed_files:
api_version=api_version)
+def GrowBlockDevice(disk, amount):
+ """Grow a stack of block devices.
+
+ This function is called recursively, with the childrens being the
+ first one resize.
+
+ Args:
+ disk: the disk to be grown
+
+ Returns: a tuple of (status, result), with:
+ status: the result (true/false) of the operation
+ result: the error message if the operation failed, otherwise not used
+
+ """
+ r_dev = _RecursiveFindBD(disk)
+ if r_dev is None:
+ return False, "Cannot find block device %s" % (disk,)
+
+ try:
+ r_dev.Grow(amount)
+ except errors.BlockDeviceError, err:
+ return False, str(err)
+
+ return True, None
+
+
def SnapshotBlockDevice(disk):
"""Create a snapshot copy of a block device.
Args:
file_storage_dir: string with path
-
+
Returns:
normalized file_storage_dir (string) if valid, None otherwise
return result
+def CloseBlockDevices(disks):
+ """Closes the given block devices.
+
+ This means they will be switched to secondary mode (in case of DRBD).
+
+ """
+ bdevs = []
+ for cf in disks:
+ rd = _RecursiveFindBD(cf)
+ if rd is None:
+ return (False, "Can't find device %s" % cf)
+ bdevs.append(rd)
+
+ msg = []
+ for rd in bdevs:
+ try:
+ rd.Close()
+ except errors.BlockDeviceError, err:
+ msg.append(str(err))
+ if msg:
+ return (False, "Can't make devices secondary: %s" % ",".join(msg))
+ else:
+ return (True, "All devices secondary")
+
+
class HooksRunner(object):
"""Hook runner.