Revision 2e5a6203
b/lib/hypervisor/hv_lxc.py | ||
---|---|---|
40 | 40 |
class LXCHypervisor(hv_base.BaseHypervisor): |
41 | 41 |
"""LXC-based virtualization. |
42 | 42 |
|
43 |
Since current (Spring 2010) distributions are not yet ready for |
|
44 |
running under a container, the following changes must be done |
|
45 |
manually: |
|
46 |
- remove udev |
|
47 |
- disable the kernel log component of sysklogd/rsyslog/etc., |
|
48 |
otherwise they will fail to read the log, and at least rsyslog |
|
49 |
will fill the filesystem with error messages |
|
50 |
|
|
51 | 43 |
TODO: |
52 | 44 |
- move hardcoded parameters into hypervisor parameters, once we |
53 | 45 |
have the container-parameter support |
... | ... | |
60 | 52 |
indication, and when failing it can leave network interfaces |
61 | 53 |
around, and future successful startups will list the instance |
62 | 54 |
twice |
63 |
- shutdown sequence of containers leaves the init 'dead', and the |
|
64 |
container effectively stopped, but LXC still believes the |
|
65 |
container to be running; need to investigate using the |
|
66 |
notify_on_release and release_agent feature of cgroups |
|
67 | 55 |
|
68 | 56 |
""" |
69 | 57 |
_ROOT_DIR = pathutils.RUN_DIR + "/lxc" |
... | ... | |
146 | 134 |
""" |
147 | 135 |
cgroup = cls._GetCgroupMountPoint() |
148 | 136 |
try: |
149 |
cpus = utils.ReadFile(utils.PathJoin(cgroup, |
|
137 |
cpus = utils.ReadFile(utils.PathJoin(cgroup, 'lxc',
|
|
150 | 138 |
instance_name, |
151 | 139 |
"cpuset.cpus")) |
152 | 140 |
except EnvironmentError, err: |
... | ... | |
159 | 147 |
"""Get the list of running instances. |
160 | 148 |
|
161 | 149 |
""" |
162 |
result = utils.RunCmd(["lxc-ls"]) |
|
163 |
if result.failed: |
|
164 |
raise errors.HypervisorError("Running lxc-ls failed: %s" % result.output) |
|
165 |
return result.stdout.splitlines() |
|
150 |
return [ iinfo[0] for iinfo in self.GetAllInstancesInfo() ] |
|
166 | 151 |
|
167 | 152 |
def GetInstanceInfo(self, instance_name): |
168 | 153 |
"""Get instance properties. |
... | ... | |
175 | 160 |
""" |
176 | 161 |
# TODO: read container info from the cgroup mountpoint |
177 | 162 |
|
178 |
result = utils.RunCmd(["lxc-info", "-n", instance_name]) |
|
163 |
result = utils.RunCmd(["lxc-info", "-s", "-n", instance_name])
|
|
179 | 164 |
if result.failed: |
180 | 165 |
raise errors.HypervisorError("Running lxc-info failed: %s" % |
181 | 166 |
result.output) |
182 | 167 |
# lxc-info output examples: |
183 |
# 'ganeti-lxc-test1' is STOPPED
|
|
184 |
# 'ganeti-lxc-test1' is RUNNING
|
|
168 |
# 'state: STOPPED
|
|
169 |
# 'state: RUNNING
|
|
185 | 170 |
_, state = result.stdout.rsplit(None, 1) |
186 | 171 |
if state != "RUNNING": |
187 | 172 |
return None |
... | ... | |
196 | 181 |
|
197 | 182 |
""" |
198 | 183 |
data = [] |
199 |
for name in self.ListInstances(): |
|
200 |
data.append(self.GetInstanceInfo(name)) |
|
184 |
for name in os.listdir(self._ROOT_DIR): |
|
185 |
try: |
|
186 |
info = self.GetInstanceInfo(name) |
|
187 |
except errors.HypervisorError: |
|
188 |
continue |
|
189 |
if info: |
|
190 |
data.append(info) |
|
201 | 191 |
return data |
202 | 192 |
|
203 | 193 |
def _CreateConfigFile(self, instance, root_dir): |
... | ... | |
270 | 260 |
def StartInstance(self, instance, block_devices, startup_paused): |
271 | 261 |
"""Start an instance. |
272 | 262 |
|
273 |
For LCX, we try to mount the block device and execute 'lxc-start'.
|
|
263 |
For LXC, we try to mount the block device and execute 'lxc-start'.
|
|
274 | 264 |
We use volatile containers. |
275 | 265 |
|
276 | 266 |
""" |
... | ... | |
338 | 328 |
logging.warning("Error while doing lxc-stop for %s: %s", name, |
339 | 329 |
result.output) |
340 | 330 |
|
331 |
if not os.path.ismount(root_dir): |
|
332 |
return |
|
333 |
|
|
341 | 334 |
for mpath in self._GetMountSubdirs(root_dir): |
342 | 335 |
result = utils.RunCmd(["umount", mpath]) |
343 | 336 |
if result.failed: |
Also available in: Unified diff