Revision c4d3e57f
b/lib/hypervisor/hv_lxc.py | ||
---|---|---|
123 | 123 |
""" |
124 | 124 |
return utils.PathJoin(cls._ROOT_DIR, instance_name + ".conf") |
125 | 125 |
|
126 |
@classmethod |
|
127 |
def _GetCgroupMountPoint(cls): |
|
128 |
for _, mountpoint, fstype, _ in utils.GetMounts(): |
|
129 |
if fstype == "cgroup": |
|
130 |
return mountpoint |
|
131 |
raise errors.HypervisorError("The cgroup filesystem is not mounted") |
|
132 |
|
|
133 |
@classmethod |
|
134 |
def _GetCgroupCpuList(cls, instance_name): |
|
135 |
"""Return the list of CPU ids for an instance. |
|
136 |
|
|
137 |
""" |
|
138 |
cgroup = cls._GetCgroupMountPoint() |
|
139 |
try: |
|
140 |
cpus = utils.ReadFile(utils.PathJoin(cgroup, |
|
141 |
instance_name, |
|
142 |
"cpuset.cpus")) |
|
143 |
except EnvironmentError, err: |
|
144 |
raise errors.HypervisorError("Getting CPU list for instance" |
|
145 |
" %s failed: %s" % (instance_name, err)) |
|
146 |
# cpuset.cpus format: comma-separated list of CPU ids |
|
147 |
# or dash-separated id ranges |
|
148 |
# Example: "0-1,3" |
|
149 |
cpu_list = [] |
|
150 |
for range_def in cpus.split(","): |
|
151 |
boundaries = range_def.split("-") |
|
152 |
n_elements = len(boundaries) |
|
153 |
lower = int(boundaries[0]) |
|
154 |
higher = int(boundaries[n_elements - 1]) |
|
155 |
cpu_list.extend(range(lower, higher + 1)) |
|
156 |
return cpu_list |
|
157 |
|
|
126 | 158 |
def ListInstances(self): |
127 | 159 |
"""Get the list of running instances. |
128 | 160 |
|
... | ... | |
150 | 182 |
# 'ganeti-lxc-test1' is STOPPED |
151 | 183 |
# 'ganeti-lxc-test1' is RUNNING |
152 | 184 |
_, state = result.stdout.rsplit(None, 1) |
185 |
|
|
186 |
cpu_list = self._GetCgroupCpuList(instance_name) |
|
187 |
|
|
153 | 188 |
if state == "RUNNING": |
154 |
return (instance_name, 0, 0, 0, 0, 0)
|
|
189 |
return (instance_name, 0, 0, len(cpu_list), 0, 0)
|
|
155 | 190 |
return None |
156 | 191 |
|
157 | 192 |
def GetAllInstancesInfo(self): |
Also available in: Unified diff