"""
-def GetInstReasonFilename(instance_name):
+def _GetInstReasonFilename(instance_name):
"""Path of the file containing the reason of the instance status change.
@type instance_name: string
return utils.PathJoin(pathutils.INSTANCE_REASON_DIR, instance_name)
-class InstReason(object):
- """Class representing the reason for a change of state of a VM.
+def _StoreInstReasonTrail(instance_name, trail):
+ """Serialize a reason trail related to an instance change of state to file.
- It is used to allow an easy serialization of the reason, so that it can be
- written on a file.
+ The exact location of the file depends on the name of the instance and on
+ the configuration of the Ganeti cluster defined at deploy time.
- """
- def __init__(self, source, text):
- """Initialize the class with all the required values.
-
- @type text: string
- @param text: The textual description of the reason for changing state
- @type source: string
- @param source: The source of the state change (RAPI, CLI, ...)
-
- """
- self.source = source
- self.text = text
-
- def GetJson(self):
- """Get the JSON representation of the InstReason.
-
- @rtype: string
- @return : The JSON representation of the object
-
- """
- return serializer.DumpJson(dict(source=self.source, text=self.text))
-
- def Store(self, instance_name):
- """Serialize on a file the reason for the last state change of an instance.
-
- The exact location of the file depends on the name of the instance and on
- the configuration of the Ganeti cluster defined at deploy time.
-
- @type instance_name: string
- @param instance_name: The name of the instance
- @rtype: None
+ @type instance_name: string
+ @param instance_name: The name of the instance
+ @rtype: None
- """
- filename = GetInstReasonFilename(instance_name)
- utils.WriteFile(filename, data=self.GetJson())
+ """
+ json = serializer.DumpJson(trail)
+ filename = _GetInstReasonFilename(instance_name)
+ utils.WriteFile(filename, data=json)
def _Fail(msg, *args, **kwargs):
_RemoveBlockDevLinks(iname, instance.disks)
-def InstanceReboot(instance, reboot_type, shutdown_timeout, reason):
+def InstanceReboot(instance, reboot_type, shutdown_timeout):
"""Reboot an instance.
@type instance: L{objects.Instance}
if reboot_type == constants.INSTANCE_REBOOT_SOFT:
try:
hyper.RebootInstance(instance)
- reason.Store(instance.name)
except errors.HypervisorError, err:
_Fail("Failed to soft reboot instance %s: %s", instance.name, err)
elif reboot_type == constants.INSTANCE_REBOOT_HARD:
try:
InstanceShutdown(instance, shutdown_timeout)
result = StartInstance(instance, False)
- reason.Store(instance.name)
return result
except errors.HypervisorError, err:
_Fail("Failed to hard reboot instance %s: %s", instance.name, err)
if nic.netinfo:
nobj = objects.Network.FromDict(nic.netinfo)
result.update(nobj.HooksDict("NIC_%d_" % idx))
- elif nic.network:
- # FIXME: broken network reference: the instance NIC specifies a network,
- # but the relevant network entry was not in the config. This should be
- # made impossible.
- result["INSTANCE_NIC%d_NETWORK" % idx] = nic.network
if constants.HV_NIC_TYPE in instance.hvparams:
result["NIC_%d_FRONTEND_TYPE" % idx] = \
instance.hvparams[constants.HV_NIC_TYPE]
# Write and replace the file atomically
utils.WriteFile(file_name, data=_Decompress(content), uid=getents.masterd_uid,
- gid=getents.masterd_gid)
+ gid=getents.daemons_gid, mode=constants.JOB_QUEUE_FILES_PERMS)
def JobQueueRename(old, new):
getents = runtime.GetEnts()
- utils.RenameFile(old, new, mkdir=True, mkdir_mode=0700,
- dir_uid=getents.masterd_uid, dir_gid=getents.masterd_gid)
+ utils.RenameFile(old, new, mkdir=True, mkdir_mode=0750,
+ dir_uid=getents.masterd_uid, dir_gid=getents.daemons_gid)
def BlockdevClose(instance_name, disks):