root / lib / hypervisor / hv_lxc.py @ 4b5e40a5
History | View | Annotate | Download (10.8 kB)
1 | 4b5e40a5 | Iustin Pop | #
|
---|---|---|---|
2 | 4b5e40a5 | Iustin Pop | #
|
3 | 4b5e40a5 | Iustin Pop | |
4 | 4b5e40a5 | Iustin Pop | # Copyright (C) 2010 Google Inc.
|
5 | 4b5e40a5 | Iustin Pop | #
|
6 | 4b5e40a5 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | 4b5e40a5 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | 4b5e40a5 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | 4b5e40a5 | Iustin Pop | # (at your option) any later version.
|
10 | 4b5e40a5 | Iustin Pop | #
|
11 | 4b5e40a5 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | 4b5e40a5 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 4b5e40a5 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 4b5e40a5 | Iustin Pop | # General Public License for more details.
|
15 | 4b5e40a5 | Iustin Pop | #
|
16 | 4b5e40a5 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | 4b5e40a5 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | 4b5e40a5 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 4b5e40a5 | Iustin Pop | # 02110-1301, USA.
|
20 | 4b5e40a5 | Iustin Pop | |
21 | 4b5e40a5 | Iustin Pop | |
22 | 4b5e40a5 | Iustin Pop | """LXC hypervisor
|
23 | 4b5e40a5 | Iustin Pop |
|
24 | 4b5e40a5 | Iustin Pop | """
|
25 | 4b5e40a5 | Iustin Pop | |
26 | 4b5e40a5 | Iustin Pop | import os |
27 | 4b5e40a5 | Iustin Pop | import os.path |
28 | 4b5e40a5 | Iustin Pop | import time |
29 | 4b5e40a5 | Iustin Pop | import logging |
30 | 4b5e40a5 | Iustin Pop | |
31 | 4b5e40a5 | Iustin Pop | from ganeti import constants |
32 | 4b5e40a5 | Iustin Pop | from ganeti import errors # pylint: disable-msg=W0611 |
33 | 4b5e40a5 | Iustin Pop | from ganeti import utils |
34 | 4b5e40a5 | Iustin Pop | from ganeti.hypervisor import hv_base |
35 | 4b5e40a5 | Iustin Pop | from ganeti.errors import HypervisorError |
36 | 4b5e40a5 | Iustin Pop | |
37 | 4b5e40a5 | Iustin Pop | |
38 | 4b5e40a5 | Iustin Pop | class LXCHypervisor(hv_base.BaseHypervisor): |
39 | 4b5e40a5 | Iustin Pop | """LXC-based virtualization.
|
40 | 4b5e40a5 | Iustin Pop |
|
41 | 4b5e40a5 | Iustin Pop | Since current (Spring 2010) distributions are not yet ready for
|
42 | 4b5e40a5 | Iustin Pop | running under a container, the following changes must be done
|
43 | 4b5e40a5 | Iustin Pop | manually:
|
44 | 4b5e40a5 | Iustin Pop | - remove udev
|
45 | 4b5e40a5 | Iustin Pop | - disable the kernel log component of sysklogd/rsyslog/etc.,
|
46 | 4b5e40a5 | Iustin Pop | otherwise they will fail to read the log, and at least rsyslog
|
47 | 4b5e40a5 | Iustin Pop | will fill the filesystem with error messages
|
48 | 4b5e40a5 | Iustin Pop |
|
49 | 4b5e40a5 | Iustin Pop | TODO:
|
50 | 4b5e40a5 | Iustin Pop | - move hardcoded parameters into hypervisor parameters, once we
|
51 | 4b5e40a5 | Iustin Pop | have the container-parameter support
|
52 | 4b5e40a5 | Iustin Pop | - implement memory limits, but only optionally, depending on host
|
53 | 4b5e40a5 | Iustin Pop | kernel support
|
54 | 4b5e40a5 | Iustin Pop |
|
55 | 4b5e40a5 | Iustin Pop | Problems/issues:
|
56 | 4b5e40a5 | Iustin Pop | - LXC is very temperamental; in daemon mode, it succeeds or fails
|
57 | 4b5e40a5 | Iustin Pop | in launching the instance silently, without any error
|
58 | 4b5e40a5 | Iustin Pop | indication, and when failing it can leave network interfaces
|
59 | 4b5e40a5 | Iustin Pop | around, and future successful startups will list the instance
|
60 | 4b5e40a5 | Iustin Pop | twice
|
61 | 4b5e40a5 | Iustin Pop | - shutdown sequence of containers leaves the init 'dead', and the
|
62 | 4b5e40a5 | Iustin Pop | container effectively stopped, but LXC still believes the
|
63 | 4b5e40a5 | Iustin Pop | container to be running; need to investigate using the
|
64 | 4b5e40a5 | Iustin Pop | notify_on_release and release_agent feature of cgroups
|
65 | 4b5e40a5 | Iustin Pop |
|
66 | 4b5e40a5 | Iustin Pop | """
|
67 | 4b5e40a5 | Iustin Pop | _ROOT_DIR = constants.RUN_GANETI_DIR + "/lxc"
|
68 | 4b5e40a5 | Iustin Pop | _LOG_FILE = constants.LOG_DIR + "hv_lxc.log"
|
69 | 4b5e40a5 | Iustin Pop | _DEVS = [ |
70 | 4b5e40a5 | Iustin Pop | "c 1:3", # /dev/null |
71 | 4b5e40a5 | Iustin Pop | "c 1:5", # /dev/zero |
72 | 4b5e40a5 | Iustin Pop | "c 1:7", # /dev/full |
73 | 4b5e40a5 | Iustin Pop | "c 1:8", # /dev/random |
74 | 4b5e40a5 | Iustin Pop | "c 1:9", # /dev/urandom |
75 | 4b5e40a5 | Iustin Pop | "c 1:10", # /dev/aio |
76 | 4b5e40a5 | Iustin Pop | "c 5:0", # /dev/tty |
77 | 4b5e40a5 | Iustin Pop | "c 5:1", # /dev/console |
78 | 4b5e40a5 | Iustin Pop | "c 5:2", # /dev/ptmx |
79 | 4b5e40a5 | Iustin Pop | "c 136:*", # first block of Unix98 PTY slaves |
80 | 4b5e40a5 | Iustin Pop | ] |
81 | 4b5e40a5 | Iustin Pop | _DENIED_CAPABILITIES = [ |
82 | 4b5e40a5 | Iustin Pop | "mac_override", # Allow MAC configuration or state changes |
83 | 4b5e40a5 | Iustin Pop | # TODO: remove sys_admin too, for safety
|
84 | 4b5e40a5 | Iustin Pop | #"sys_admin", # Perform a range of system administration operations
|
85 | 4b5e40a5 | Iustin Pop | "sys_boot", # Use reboot(2) and kexec_load(2) |
86 | 4b5e40a5 | Iustin Pop | "sys_module", # Load and unload kernel modules |
87 | 4b5e40a5 | Iustin Pop | "sys_time", # Set system clock, set real-time (hardware) clock |
88 | 4b5e40a5 | Iustin Pop | ] |
89 | 4b5e40a5 | Iustin Pop | _DIR_MODE = 0755
|
90 | 4b5e40a5 | Iustin Pop | |
91 | 4b5e40a5 | Iustin Pop | PARAMETERS = { |
92 | 4b5e40a5 | Iustin Pop | } |
93 | 4b5e40a5 | Iustin Pop | |
94 | 4b5e40a5 | Iustin Pop | def __init__(self): |
95 | 4b5e40a5 | Iustin Pop | hv_base.BaseHypervisor.__init__(self)
|
96 | 4b5e40a5 | Iustin Pop | utils.EnsureDirs([(self._ROOT_DIR, self._DIR_MODE)]) |
97 | 4b5e40a5 | Iustin Pop | |
98 | 4b5e40a5 | Iustin Pop | @staticmethod
|
99 | 4b5e40a5 | Iustin Pop | def _GetMountSubdirs(path): |
100 | 4b5e40a5 | Iustin Pop | """Return the list of mountpoints under a given path.
|
101 | 4b5e40a5 | Iustin Pop |
|
102 | 4b5e40a5 | Iustin Pop | This function is Linux-specific.
|
103 | 4b5e40a5 | Iustin Pop |
|
104 | 4b5e40a5 | Iustin Pop | """
|
105 | 4b5e40a5 | Iustin Pop | #TODO(iustin): investigate and document non-linux options
|
106 | 4b5e40a5 | Iustin Pop | #(e.g. via mount output)
|
107 | 4b5e40a5 | Iustin Pop | data = [] |
108 | 4b5e40a5 | Iustin Pop | fh = open("/proc/mounts", "r") |
109 | 4b5e40a5 | Iustin Pop | try:
|
110 | 4b5e40a5 | Iustin Pop | for line in fh: |
111 | 4b5e40a5 | Iustin Pop | _, mountpoint, _ = line.split(" ", 2) |
112 | 4b5e40a5 | Iustin Pop | if (mountpoint.startswith(path) and |
113 | 4b5e40a5 | Iustin Pop | mountpoint != path): |
114 | 4b5e40a5 | Iustin Pop | data.append(mountpoint) |
115 | 4b5e40a5 | Iustin Pop | finally:
|
116 | 4b5e40a5 | Iustin Pop | fh.close() |
117 | 4b5e40a5 | Iustin Pop | data.sort(key=lambda x: x.count("/"), reverse=True) |
118 | 4b5e40a5 | Iustin Pop | return data
|
119 | 4b5e40a5 | Iustin Pop | |
120 | 4b5e40a5 | Iustin Pop | @classmethod
|
121 | 4b5e40a5 | Iustin Pop | def _InstanceDir(cls, instance_name): |
122 | 4b5e40a5 | Iustin Pop | """Return the root directory for an instance.
|
123 | 4b5e40a5 | Iustin Pop |
|
124 | 4b5e40a5 | Iustin Pop | """
|
125 | 4b5e40a5 | Iustin Pop | return utils.PathJoin(cls._ROOT_DIR, instance_name)
|
126 | 4b5e40a5 | Iustin Pop | |
127 | 4b5e40a5 | Iustin Pop | @classmethod
|
128 | 4b5e40a5 | Iustin Pop | def _InstanceConfFile(cls, instance_name): |
129 | 4b5e40a5 | Iustin Pop | """Return the configuration file for an instance.
|
130 | 4b5e40a5 | Iustin Pop |
|
131 | 4b5e40a5 | Iustin Pop | """
|
132 | 4b5e40a5 | Iustin Pop | return utils.PathJoin(cls._ROOT_DIR, instance_name + ".conf") |
133 | 4b5e40a5 | Iustin Pop | |
134 | 4b5e40a5 | Iustin Pop | def ListInstances(self): |
135 | 4b5e40a5 | Iustin Pop | """Get the list of running instances.
|
136 | 4b5e40a5 | Iustin Pop |
|
137 | 4b5e40a5 | Iustin Pop | """
|
138 | 4b5e40a5 | Iustin Pop | result = utils.RunCmd(["lxc-ls"])
|
139 | 4b5e40a5 | Iustin Pop | if result.failed:
|
140 | 4b5e40a5 | Iustin Pop | raise errors.HypervisorError("Can't run lxc-ls: %s" % result.output) |
141 | 4b5e40a5 | Iustin Pop | return result.stdout.splitlines()
|
142 | 4b5e40a5 | Iustin Pop | |
143 | 4b5e40a5 | Iustin Pop | def GetInstanceInfo(self, instance_name): |
144 | 4b5e40a5 | Iustin Pop | """Get instance properties.
|
145 | 4b5e40a5 | Iustin Pop |
|
146 | 4b5e40a5 | Iustin Pop | @type instance_name: string
|
147 | 4b5e40a5 | Iustin Pop | @param instance_name: the instance name
|
148 | 4b5e40a5 | Iustin Pop |
|
149 | 4b5e40a5 | Iustin Pop | @return: (name, id, memory, vcpus, stat, times)
|
150 | 4b5e40a5 | Iustin Pop |
|
151 | 4b5e40a5 | Iustin Pop | """
|
152 | 4b5e40a5 | Iustin Pop | # TODO: read container info from the cgroup mountpoint
|
153 | 4b5e40a5 | Iustin Pop | return (instance_name, 0, 0, 0, 0, 0) |
154 | 4b5e40a5 | Iustin Pop | |
155 | 4b5e40a5 | Iustin Pop | def GetAllInstancesInfo(self): |
156 | 4b5e40a5 | Iustin Pop | """Get properties of all instances.
|
157 | 4b5e40a5 | Iustin Pop |
|
158 | 4b5e40a5 | Iustin Pop | @return: [(name, id, memory, vcpus, stat, times),...]
|
159 | 4b5e40a5 | Iustin Pop |
|
160 | 4b5e40a5 | Iustin Pop | """
|
161 | 4b5e40a5 | Iustin Pop | # TODO: read container info from the cgroup mountpoint
|
162 | 4b5e40a5 | Iustin Pop | data = [] |
163 | 4b5e40a5 | Iustin Pop | for name in self.ListInstances(): |
164 | 4b5e40a5 | Iustin Pop | data.append((name, 0, 0, 0, 0, 0)) |
165 | 4b5e40a5 | Iustin Pop | return data
|
166 | 4b5e40a5 | Iustin Pop | |
167 | 4b5e40a5 | Iustin Pop | def _CreateConfigFile(self, instance, root_dir): |
168 | 4b5e40a5 | Iustin Pop | """Create an lxc.conf file for an instance"""
|
169 | 4b5e40a5 | Iustin Pop | out = [] |
170 | 4b5e40a5 | Iustin Pop | # hostname
|
171 | 4b5e40a5 | Iustin Pop | out.append("lxc.utsname = %s" % instance.name)
|
172 | 4b5e40a5 | Iustin Pop | |
173 | 4b5e40a5 | Iustin Pop | # separate pseudo-TTY instances
|
174 | 4b5e40a5 | Iustin Pop | out.append("lxc.pts = 255")
|
175 | 4b5e40a5 | Iustin Pop | # standard TTYs/console
|
176 | 4b5e40a5 | Iustin Pop | out.append("lxc.tty = 6")
|
177 | 4b5e40a5 | Iustin Pop | |
178 | 4b5e40a5 | Iustin Pop | # root FS
|
179 | 4b5e40a5 | Iustin Pop | out.append("lxc.rootfs = %s" % root_dir)
|
180 | 4b5e40a5 | Iustin Pop | |
181 | 4b5e40a5 | Iustin Pop | # TODO: additional mounts, if we disable CAP_SYS_ADMIN
|
182 | 4b5e40a5 | Iustin Pop | |
183 | 4b5e40a5 | Iustin Pop | # Device control
|
184 | 4b5e40a5 | Iustin Pop | # deny direct device access
|
185 | 4b5e40a5 | Iustin Pop | out.append("lxc.cgroup.devices.deny = a")
|
186 | 4b5e40a5 | Iustin Pop | for devinfo in self._DEVS: |
187 | 4b5e40a5 | Iustin Pop | out.append("lxc.cgroup.devices.allow = %s rw" % devinfo)
|
188 | 4b5e40a5 | Iustin Pop | |
189 | 4b5e40a5 | Iustin Pop | # Networking
|
190 | 4b5e40a5 | Iustin Pop | for idx, nic in enumerate(instance.nics): |
191 | 4b5e40a5 | Iustin Pop | out.append("# NIC %d" % idx)
|
192 | 4b5e40a5 | Iustin Pop | mode = nic.nicparams[constants.NIC_MODE] |
193 | 4b5e40a5 | Iustin Pop | link = nic.nicparams[constants.NIC_LINK] |
194 | 4b5e40a5 | Iustin Pop | if mode == constants.NIC_MODE_BRIDGED:
|
195 | 4b5e40a5 | Iustin Pop | out.append("lxc.network.type = veth")
|
196 | 4b5e40a5 | Iustin Pop | out.append("lxc.network.link = %s" % link)
|
197 | 4b5e40a5 | Iustin Pop | else:
|
198 | 4b5e40a5 | Iustin Pop | raise errors.HypervisorError("LXC hypervisor only supports" |
199 | 4b5e40a5 | Iustin Pop | " bridged mode (NIC %d has mode %s)" %
|
200 | 4b5e40a5 | Iustin Pop | (idx, mode)) |
201 | 4b5e40a5 | Iustin Pop | out.append("lxc.network.hwaddr = %s" % nic.mac)
|
202 | 4b5e40a5 | Iustin Pop | out.append("lxc.network.flags = up")
|
203 | 4b5e40a5 | Iustin Pop | |
204 | 4b5e40a5 | Iustin Pop | # Capabilities
|
205 | 4b5e40a5 | Iustin Pop | for cap in self._DENIED_CAPABILITIES: |
206 | 4b5e40a5 | Iustin Pop | out.append("lxc.cap.drop = %s" % cap)
|
207 | 4b5e40a5 | Iustin Pop | |
208 | 4b5e40a5 | Iustin Pop | return "\n".join(out) + "\n" |
209 | 4b5e40a5 | Iustin Pop | |
210 | 4b5e40a5 | Iustin Pop | def StartInstance(self, instance, block_devices): |
211 | 4b5e40a5 | Iustin Pop | """Start an instance.
|
212 | 4b5e40a5 | Iustin Pop |
|
213 | 4b5e40a5 | Iustin Pop | For LCX, we try to mount the block device and execute 'lxc-start
|
214 | 4b5e40a5 | Iustin Pop | start' (we use volatile containers).
|
215 | 4b5e40a5 | Iustin Pop |
|
216 | 4b5e40a5 | Iustin Pop | """
|
217 | 4b5e40a5 | Iustin Pop | root_dir = self._InstanceDir(instance.name)
|
218 | 4b5e40a5 | Iustin Pop | try:
|
219 | 4b5e40a5 | Iustin Pop | utils.EnsureDirs([(root_dir, self._DIR_MODE)])
|
220 | 4b5e40a5 | Iustin Pop | except errors.GenericError, err:
|
221 | 4b5e40a5 | Iustin Pop | raise HypervisorError("Cannot create instance directory: %s", str(err)) |
222 | 4b5e40a5 | Iustin Pop | |
223 | 4b5e40a5 | Iustin Pop | conf_file = self._InstanceConfFile(instance.name)
|
224 | 4b5e40a5 | Iustin Pop | utils.WriteFile(conf_file, data=self._CreateConfigFile(instance, root_dir))
|
225 | 4b5e40a5 | Iustin Pop | |
226 | 4b5e40a5 | Iustin Pop | if not os.path.ismount(root_dir): |
227 | 4b5e40a5 | Iustin Pop | if not block_devices: |
228 | 4b5e40a5 | Iustin Pop | raise HypervisorError("LXC needs at least one disk") |
229 | 4b5e40a5 | Iustin Pop | |
230 | 4b5e40a5 | Iustin Pop | sda_dev_path = block_devices[0][1] |
231 | 4b5e40a5 | Iustin Pop | result = utils.RunCmd(["mount", sda_dev_path, root_dir])
|
232 | 4b5e40a5 | Iustin Pop | if result.failed:
|
233 | 4b5e40a5 | Iustin Pop | raise HypervisorError("Can't mount the chroot dir: %s" % result.output) |
234 | 4b5e40a5 | Iustin Pop | # TODO: replace the global log file with a per-instance log file
|
235 | 4b5e40a5 | Iustin Pop | result = utils.RunCmd(["lxc-start", "-n", instance.name, |
236 | 4b5e40a5 | Iustin Pop | "-o", self._LOG_FILE, "-l", "DEBUG", |
237 | 4b5e40a5 | Iustin Pop | "-f", conf_file, "-d"]) |
238 | 4b5e40a5 | Iustin Pop | if result.failed:
|
239 | 4b5e40a5 | Iustin Pop | raise HypervisorError("Running the lxc-start script failed: %s" % |
240 | 4b5e40a5 | Iustin Pop | result.output) |
241 | 4b5e40a5 | Iustin Pop | |
242 | 4b5e40a5 | Iustin Pop | def StopInstance(self, instance, force=False, retry=False, name=None): |
243 | 4b5e40a5 | Iustin Pop | """Stop an instance.
|
244 | 4b5e40a5 | Iustin Pop |
|
245 | 4b5e40a5 | Iustin Pop | This method has complicated cleanup tests, as we must:
|
246 | 4b5e40a5 | Iustin Pop | - try to kill all leftover processes
|
247 | 4b5e40a5 | Iustin Pop | - try to unmount any additional sub-mountpoints
|
248 | 4b5e40a5 | Iustin Pop | - finally unmount the instance dir
|
249 | 4b5e40a5 | Iustin Pop |
|
250 | 4b5e40a5 | Iustin Pop | """
|
251 | 4b5e40a5 | Iustin Pop | if name is None: |
252 | 4b5e40a5 | Iustin Pop | name = instance.name |
253 | 4b5e40a5 | Iustin Pop | |
254 | 4b5e40a5 | Iustin Pop | root_dir = self._InstanceDir(name)
|
255 | 4b5e40a5 | Iustin Pop | if not os.path.exists(root_dir): |
256 | 4b5e40a5 | Iustin Pop | return
|
257 | 4b5e40a5 | Iustin Pop | |
258 | 4b5e40a5 | Iustin Pop | if name in self.ListInstances(): |
259 | 4b5e40a5 | Iustin Pop | # Signal init to shutdown; this is a hack
|
260 | 4b5e40a5 | Iustin Pop | if not retry and not force: |
261 | 4b5e40a5 | Iustin Pop | result = utils.RunCmd(["chroot", root_dir, "poweroff"]) |
262 | 4b5e40a5 | Iustin Pop | if result.failed:
|
263 | 4b5e40a5 | Iustin Pop | raise HypervisorError("Can't run 'poweroff' for the instance: %s" % |
264 | 4b5e40a5 | Iustin Pop | result.output) |
265 | 4b5e40a5 | Iustin Pop | time.sleep(2)
|
266 | 4b5e40a5 | Iustin Pop | result = utils.RunCmd(["lxc-stop", "-n", name]) |
267 | 4b5e40a5 | Iustin Pop | if result.failed:
|
268 | 4b5e40a5 | Iustin Pop | logging.warning("Error while doing lxc-stop for %s: %s", name,
|
269 | 4b5e40a5 | Iustin Pop | result.output) |
270 | 4b5e40a5 | Iustin Pop | |
271 | 4b5e40a5 | Iustin Pop | for mpath in self._GetMountSubdirs(root_dir): |
272 | 4b5e40a5 | Iustin Pop | result = utils.RunCmd(["umount", mpath])
|
273 | 4b5e40a5 | Iustin Pop | if result.failed:
|
274 | 4b5e40a5 | Iustin Pop | logging.warning("Error while umounting subpath %s for instance %s: %s",
|
275 | 4b5e40a5 | Iustin Pop | mpath, name, result.output) |
276 | 4b5e40a5 | Iustin Pop | |
277 | 4b5e40a5 | Iustin Pop | result = utils.RunCmd(["umount", root_dir])
|
278 | 4b5e40a5 | Iustin Pop | if result.failed and force: |
279 | 4b5e40a5 | Iustin Pop | msg = ("Processes still alive in the chroot: %s" %
|
280 | 4b5e40a5 | Iustin Pop | utils.RunCmd("fuser -vm %s" % root_dir).output)
|
281 | 4b5e40a5 | Iustin Pop | logging.error(msg) |
282 | 4b5e40a5 | Iustin Pop | raise HypervisorError("Can't umount the chroot dir: %s (%s)" % |
283 | 4b5e40a5 | Iustin Pop | (result.output, msg)) |
284 | 4b5e40a5 | Iustin Pop | |
285 | 4b5e40a5 | Iustin Pop | def RebootInstance(self, instance): |
286 | 4b5e40a5 | Iustin Pop | """Reboot an instance.
|
287 | 4b5e40a5 | Iustin Pop |
|
288 | 4b5e40a5 | Iustin Pop | This is not (yet) implemented (in Ganeti) for the LXC hypervisor.
|
289 | 4b5e40a5 | Iustin Pop |
|
290 | 4b5e40a5 | Iustin Pop | """
|
291 | 4b5e40a5 | Iustin Pop | # TODO: implement reboot
|
292 | 4b5e40a5 | Iustin Pop | raise HypervisorError("The LXC hypervisor doesn't implement the" |
293 | 4b5e40a5 | Iustin Pop | " reboot functionality")
|
294 | 4b5e40a5 | Iustin Pop | |
295 | 4b5e40a5 | Iustin Pop | def GetNodeInfo(self): |
296 | 4b5e40a5 | Iustin Pop | """Return information about the node.
|
297 | 4b5e40a5 | Iustin Pop |
|
298 | 4b5e40a5 | Iustin Pop | This is just a wrapper over the base GetLinuxNodeInfo method.
|
299 | 4b5e40a5 | Iustin Pop |
|
300 | 4b5e40a5 | Iustin Pop | @return: a dict with the following keys (values in MiB):
|
301 | 4b5e40a5 | Iustin Pop | - memory_total: the total memory size on the node
|
302 | 4b5e40a5 | Iustin Pop | - memory_free: the available memory on the node for instances
|
303 | 4b5e40a5 | Iustin Pop | - memory_dom0: the memory used by the node itself, if available
|
304 | 4b5e40a5 | Iustin Pop |
|
305 | 4b5e40a5 | Iustin Pop | """
|
306 | 4b5e40a5 | Iustin Pop | return self.GetLinuxNodeInfo() |
307 | 4b5e40a5 | Iustin Pop | |
308 | 4b5e40a5 | Iustin Pop | @classmethod
|
309 | 4b5e40a5 | Iustin Pop | def GetShellCommandForConsole(cls, instance, hvparams, beparams): |
310 | 4b5e40a5 | Iustin Pop | """Return a command for connecting to the console of an instance.
|
311 | 4b5e40a5 | Iustin Pop |
|
312 | 4b5e40a5 | Iustin Pop | """
|
313 | 4b5e40a5 | Iustin Pop | return "lxc-console -n %s" % instance.name |
314 | 4b5e40a5 | Iustin Pop | |
315 | 4b5e40a5 | Iustin Pop | def Verify(self): |
316 | 4b5e40a5 | Iustin Pop | """Verify the hypervisor.
|
317 | 4b5e40a5 | Iustin Pop |
|
318 | 4b5e40a5 | Iustin Pop | For the chroot manager, it just checks the existence of the base dir.
|
319 | 4b5e40a5 | Iustin Pop |
|
320 | 4b5e40a5 | Iustin Pop | """
|
321 | 4b5e40a5 | Iustin Pop | if not os.path.exists(self._ROOT_DIR): |
322 | 4b5e40a5 | Iustin Pop | return "The required directory '%s' does not exist." % self._ROOT_DIR |
323 | 4b5e40a5 | Iustin Pop | |
324 | 4b5e40a5 | Iustin Pop | @classmethod
|
325 | 4b5e40a5 | Iustin Pop | def PowercycleNode(cls): |
326 | 4b5e40a5 | Iustin Pop | """LXC powercycle, just a wrapper over Linux powercycle.
|
327 | 4b5e40a5 | Iustin Pop |
|
328 | 4b5e40a5 | Iustin Pop | """
|
329 | 4b5e40a5 | Iustin Pop | cls.LinuxPowercycle() |
330 | 4b5e40a5 | Iustin Pop | |
331 | 4b5e40a5 | Iustin Pop | def MigrateInstance(self, instance, target, live): |
332 | 4b5e40a5 | Iustin Pop | """Migrate an instance.
|
333 | 4b5e40a5 | Iustin Pop |
|
334 | 4b5e40a5 | Iustin Pop | @type instance: L{objects.Instance}
|
335 | 4b5e40a5 | Iustin Pop | @param instance: the instance to be migrated
|
336 | 4b5e40a5 | Iustin Pop | @type target: string
|
337 | 4b5e40a5 | Iustin Pop | @param target: hostname (usually ip) of the target node
|
338 | 4b5e40a5 | Iustin Pop | @type live: boolean
|
339 | 4b5e40a5 | Iustin Pop | @param live: whether to do a live or non-live migration
|
340 | 4b5e40a5 | Iustin Pop |
|
341 | 4b5e40a5 | Iustin Pop | """
|
342 | 4b5e40a5 | Iustin Pop | raise HypervisorError("Migration not supported by the LXC hypervisor") |