Revision aa922d64 lib/backend.py
b/lib/backend.py | ||
---|---|---|
122 | 122 |
return utils.PathJoin(pathutils.INSTANCE_REASON_DIR, instance_name) |
123 | 123 |
|
124 | 124 |
|
125 |
class InstReason(object): |
|
126 |
"""Class representing the reason for a change of state of a VM. |
|
127 |
|
|
128 |
It is used to allow an easy serialization of the reason, so that it can be |
|
129 |
written on a file. |
|
130 |
|
|
131 |
""" |
|
132 |
def __init__(self, source, text): |
|
133 |
"""Initialize the class with all the required values. |
|
134 |
|
|
135 |
@type text: string |
|
136 |
@param text: The textual description of the reason for changing state |
|
137 |
@type source: string |
|
138 |
@param source: The source of the state change (RAPI, CLI, ...) |
|
139 |
|
|
140 |
""" |
|
141 |
self.source = source |
|
142 |
self.text = text |
|
143 |
|
|
144 |
def GetJson(self): |
|
145 |
"""Get the JSON representation of the InstReason. |
|
146 |
|
|
147 |
@rtype: string |
|
148 |
@return : The JSON representation of the object |
|
149 |
|
|
150 |
""" |
|
151 |
return serializer.DumpJson(dict(source=self.source, text=self.text)) |
|
152 |
|
|
153 |
def Store(self, instance_name): |
|
154 |
"""Serialize on a file the reason for the last state change of an instance. |
|
155 |
|
|
156 |
The exact location of the file depends on the name of the instance and on |
|
157 |
the configuration of the Ganeti cluster defined at deploy time. |
|
158 |
|
|
159 |
@type instance_name: string |
|
160 |
@param instance_name: The name of the instance |
|
161 |
@rtype: None |
|
162 |
|
|
163 |
""" |
|
164 |
filename = GetInstReasonFilename(instance_name) |
|
165 |
utils.WriteFile(filename, data=self.GetJson()) |
|
166 |
|
|
167 |
|
|
168 | 125 |
def _Fail(msg, *args, **kwargs): |
169 | 126 |
"""Log an error and the raise an RPCFail exception. |
170 | 127 |
|
... | ... | |
1451 | 1408 |
_RemoveBlockDevLinks(iname, instance.disks) |
1452 | 1409 |
|
1453 | 1410 |
|
1454 |
def InstanceReboot(instance, reboot_type, shutdown_timeout, reason):
|
|
1411 |
def InstanceReboot(instance, reboot_type, shutdown_timeout): |
|
1455 | 1412 |
"""Reboot an instance. |
1456 | 1413 |
|
1457 | 1414 |
@type instance: L{objects.Instance} |
... | ... | |
1481 | 1438 |
if reboot_type == constants.INSTANCE_REBOOT_SOFT: |
1482 | 1439 |
try: |
1483 | 1440 |
hyper.RebootInstance(instance) |
1484 |
reason.Store(instance.name) |
|
1485 | 1441 |
except errors.HypervisorError, err: |
1486 | 1442 |
_Fail("Failed to soft reboot instance %s: %s", instance.name, err) |
1487 | 1443 |
elif reboot_type == constants.INSTANCE_REBOOT_HARD: |
1488 | 1444 |
try: |
1489 | 1445 |
InstanceShutdown(instance, shutdown_timeout) |
1490 | 1446 |
result = StartInstance(instance, False) |
1491 |
reason.Store(instance.name) |
|
1492 | 1447 |
return result |
1493 | 1448 |
except errors.HypervisorError, err: |
1494 | 1449 |
_Fail("Failed to hard reboot instance %s: %s", instance.name, err) |
Also available in: Unified diff