Revision bbcf7ad0
b/lib/hypervisor/hv_base.py | ||
---|---|---|
113 | 113 |
"""Start an instance.""" |
114 | 114 |
raise NotImplementedError |
115 | 115 |
|
116 |
def StopInstance(self, instance, force=False, retry=False): |
|
116 |
def StopInstance(self, instance, force=False, retry=False, name=None):
|
|
117 | 117 |
"""Stop an instance |
118 | 118 |
|
119 | 119 |
@type instance: L{objects.Instance} |
... | ... | |
122 | 122 |
@param force: whether to do a "hard" stop (destroy) |
123 | 123 |
@type retry: boolean |
124 | 124 |
@param retry: whether this is just a retry call |
125 |
@type name: string or None |
|
126 |
@param name: if this parameter is passed, the the instance object |
|
127 |
should not be used (will be passed as None), and the shutdown |
|
128 |
must be done by name only |
|
125 | 129 |
|
126 | 130 |
""" |
127 | 131 |
raise NotImplementedError |
b/lib/hypervisor/hv_chroot.py | ||
---|---|---|
177 | 177 |
raise HypervisorError("Can't run the chroot start script: %s" % |
178 | 178 |
result.output) |
179 | 179 |
|
180 |
def StopInstance(self, instance, force=False, retry=False): |
|
180 |
def StopInstance(self, instance, force=False, retry=False, name=None):
|
|
181 | 181 |
"""Stop an instance. |
182 | 182 |
|
183 | 183 |
This method has complicated cleanup tests, as we must: |
... | ... | |
186 | 186 |
- finally unmount the instance dir |
187 | 187 |
|
188 | 188 |
""" |
189 |
root_dir = self._InstanceDir(instance.name) |
|
189 |
if name is None: |
|
190 |
name = instance.name |
|
191 |
|
|
192 |
root_dir = self._InstanceDir(name) |
|
190 | 193 |
if not os.path.exists(root_dir) or not self._IsDirLive(root_dir): |
191 | 194 |
return |
192 | 195 |
|
b/lib/hypervisor/hv_fake.py | ||
---|---|---|
136 | 136 |
finally: |
137 | 137 |
fh.close() |
138 | 138 |
|
139 |
def _MarkDown(self, instance): |
|
139 |
def _MarkDown(self, instance_name):
|
|
140 | 140 |
"""Mark the instance as running. |
141 | 141 |
|
142 | 142 |
This does no checks, which should be done by its callers. |
143 | 143 |
|
144 | 144 |
""" |
145 |
file_name = self._InstanceFile(instance.name)
|
|
145 |
file_name = self._InstanceFile(instance_name)
|
|
146 | 146 |
utils.RemoveFile(file_name) |
147 | 147 |
|
148 | 148 |
def StartInstance(self, instance, block_devices): |
... | ... | |
162 | 162 |
raise errors.HypervisorError("Failed to start instance %s: %s" % |
163 | 163 |
(instance.name, err)) |
164 | 164 |
|
165 |
def StopInstance(self, instance, force=False, retry=False): |
|
165 |
def StopInstance(self, instance, force=False, retry=False, name=None):
|
|
166 | 166 |
"""Stop an instance. |
167 | 167 |
|
168 | 168 |
For the fake hypervisor, this just removes the file in the base |
169 | 169 |
dir, if it exist, otherwise we raise an exception. |
170 | 170 |
|
171 | 171 |
""" |
172 |
if not self._IsAlive(instance.name): |
|
172 |
if name is None: |
|
173 |
name = instance.name |
|
174 |
if not self._IsAlive(name): |
|
173 | 175 |
raise errors.HypervisorError("Failed to stop instance %s: %s" % |
174 |
(instance.name, "not running"))
|
|
175 |
self._MarkDown(instance)
|
|
176 |
(name, "not running")) |
|
177 |
self._MarkDown(name)
|
|
176 | 178 |
|
177 | 179 |
def RebootInstance(self, instance): |
178 | 180 |
"""Reboot an instance. |
... | ... | |
252 | 254 |
logging.debug("Fake hypervisor migrating %s to %s (live=%s)", |
253 | 255 |
instance, target, live) |
254 | 256 |
|
255 |
self._MarkDown(instance) |
|
257 |
self._MarkDown(instance.name)
|
|
256 | 258 |
|
257 | 259 |
def FinalizeMigration(self, instance, info, success): |
258 | 260 |
"""Finalize an instance migration. |
... | ... | |
267 | 269 |
self._MarkUp(instance) |
268 | 270 |
else: |
269 | 271 |
# ensure it's down |
270 |
self._MarkDown(instance) |
|
272 |
self._MarkDown(instance.name) |
b/lib/hypervisor/hv_kvm.py | ||
---|---|---|
613 | 613 |
|
614 | 614 |
return result |
615 | 615 |
|
616 |
def StopInstance(self, instance, force=False, retry=False): |
|
616 |
def StopInstance(self, instance, force=False, retry=False, name=None):
|
|
617 | 617 |
"""Stop an instance. |
618 | 618 |
|
619 | 619 |
""" |
620 |
pidfile, pid, alive = self._InstancePidAlive(instance.name) |
|
620 |
if name is not None and not force: |
|
621 |
raise errors.HypervisorError("Cannot shutdown cleanly by name only") |
|
622 |
if name is None: |
|
623 |
name = instance.name |
|
624 |
acpi = instance.hvparams[constants.HV_ACPI] |
|
625 |
else: |
|
626 |
acpi = False |
|
627 |
pidfile, pid, alive = self._InstancePidAlive(name) |
|
621 | 628 |
if pid > 0 and alive: |
622 |
if force or not instance.hvparams[constants.HV_ACPI]:
|
|
629 |
if force or not acpi:
|
|
623 | 630 |
utils.KillProcess(pid) |
624 | 631 |
else: |
625 |
self._CallMonitorCommand(instance.name, 'system_powerdown')
|
|
632 |
self._CallMonitorCommand(name, 'system_powerdown') |
|
626 | 633 |
|
627 |
if not self._InstancePidAlive(instance.name)[2]:
|
|
628 |
self._RemoveInstanceRuntimeFiles(pidfile, instance.name)
|
|
634 |
if not self._InstancePidAlive(name)[2]: |
|
635 |
self._RemoveInstanceRuntimeFiles(pidfile, name) |
|
629 | 636 |
return True |
630 | 637 |
else: |
631 | 638 |
return False |
b/lib/hypervisor/hv_xen.py | ||
---|---|---|
189 | 189 |
(instance.name, result.fail_reason, |
190 | 190 |
result.output)) |
191 | 191 |
|
192 |
def StopInstance(self, instance, force=False, retry=False): |
|
192 |
def StopInstance(self, instance, force=False, retry=False, name=None):
|
|
193 | 193 |
"""Stop an instance. |
194 | 194 |
|
195 | 195 |
""" |
196 |
self._RemoveConfigFile(instance.name) |
|
196 |
if name is None: |
|
197 |
name = instance.name |
|
198 |
self._RemoveConfigFile(name) |
|
197 | 199 |
if force: |
198 |
command = ["xm", "destroy", instance.name]
|
|
200 |
command = ["xm", "destroy", name] |
|
199 | 201 |
else: |
200 |
command = ["xm", "shutdown", instance.name]
|
|
202 |
command = ["xm", "shutdown", name] |
|
201 | 203 |
result = utils.RunCmd(command) |
202 | 204 |
|
203 | 205 |
if result.failed: |
204 | 206 |
raise errors.HypervisorError("Failed to stop instance %s: %s, %s" % |
205 |
(instance.name, result.fail_reason, |
|
206 |
result.output)) |
|
207 |
(name, result.fail_reason, result.output)) |
|
207 | 208 |
|
208 | 209 |
def RebootInstance(self, instance): |
209 | 210 |
"""Reboot an instance. |
Also available in: Unified diff