Revision e3ed5316 lib/hypervisor/hv_lxc.py
b/lib/hypervisor/hv_lxc.py | ||
---|---|---|
88 | 88 |
_DIR_MODE = 0755 |
89 | 89 |
|
90 | 90 |
PARAMETERS = { |
91 |
constants.HV_CPU_MASK: hv_base.OPT_CPU_MASK_CHECK, |
|
91 | 92 |
} |
92 | 93 |
|
93 | 94 |
def __init__(self): |
... | ... | |
149 | 150 |
except EnvironmentError, err: |
150 | 151 |
raise errors.HypervisorError("Getting CPU list for instance" |
151 | 152 |
" %s failed: %s" % (instance_name, err)) |
152 |
# cpuset.cpus format: comma-separated list of CPU ids |
|
153 |
# or dash-separated id ranges |
|
154 |
# Example: "0-1,3" |
|
155 |
cpu_list = [] |
|
156 |
for range_def in cpus.split(","): |
|
157 |
boundaries = range_def.split("-") |
|
158 |
n_elements = len(boundaries) |
|
159 |
lower = int(boundaries[0]) |
|
160 |
higher = int(boundaries[n_elements - 1]) |
|
161 |
cpu_list.extend(range(lower, higher + 1)) |
|
162 |
return cpu_list |
|
153 |
|
|
154 |
return utils.ParseCpuMask(cpus) |
|
163 | 155 |
|
164 | 156 |
def ListInstances(self): |
165 | 157 |
"""Get the list of running instances. |
... | ... | |
207 | 199 |
return data |
208 | 200 |
|
209 | 201 |
def _CreateConfigFile(self, instance, root_dir): |
210 |
"""Create an lxc.conf file for an instance""" |
|
202 |
"""Create an lxc.conf file for an instance. |
|
203 |
|
|
204 |
""" |
|
211 | 205 |
out = [] |
212 | 206 |
# hostname |
213 | 207 |
out.append("lxc.utsname = %s" % instance.name) |
... | ... | |
231 | 225 |
|
232 | 226 |
# TODO: additional mounts, if we disable CAP_SYS_ADMIN |
233 | 227 |
|
228 |
# CPUs |
|
229 |
if instance.hvparams[constants.HV_CPU_MASK]: |
|
230 |
cpu_list = utils.ParseCpuMask(instance.hvparams[constants.HV_CPU_MASK]) |
|
231 |
cpus_in_mask = len(cpu_list) |
|
232 |
if cpus_in_mask != instance.beparams["vcpus"]: |
|
233 |
raise errors.HypervisorError("Number of VCPUs (%d) doesn't match" |
|
234 |
" the number of CPUs in the" |
|
235 |
" cpu_mask (%d)" % |
|
236 |
(instance.beparams["vcpus"], |
|
237 |
cpus_in_mask)) |
|
238 |
out.append("lxc.cgroup.cpuset.cpus = %s" % |
|
239 |
instance.hvparams[constants.HV_CPU_MASK]) |
|
240 |
|
|
234 | 241 |
# Device control |
235 | 242 |
# deny direct device access |
236 | 243 |
out.append("lxc.cgroup.devices.deny = a") |
... | ... | |
261 | 268 |
def StartInstance(self, instance, block_devices): |
262 | 269 |
"""Start an instance. |
263 | 270 |
|
264 |
For LCX, we try to mount the block device and execute 'lxc-start |
|
265 |
start' (we use volatile containers).
|
|
271 |
For LCX, we try to mount the block device and execute 'lxc-start'.
|
|
272 |
We use volatile containers.
|
|
266 | 273 |
|
267 | 274 |
""" |
268 | 275 |
root_dir = self._InstanceDir(instance.name) |
Also available in: Unified diff