-###################################################
-# Author: Guilherme Sperb Machado <gsm@machados.org>
-###################################################
-# Basically this method is just a copy from "get_sliver_process()", just
-# adding one more split() to correctly parse the processes for LXC.
-# Only for LXC!
-# TODO: maybe merge both methods, and put the type as an argument, if
-# it is LXC or vserver
-###################################################
-def get_sliver_process_lxc(slice_name, process_cmdline):
- """ Utility function to find a process inside of an LXC sliver. Returns
- (cgroup_fn, pid). cgroup_fn is the filename of the cgroup file for
- the process, for example /proc/2592/cgroup. Pid is the process id of
- the process. If the process is not found then (None, None) is returned.
- """
- try:
- cmd = 'grep %s /proc/*/cgroup | grep freezer'%slice_name
- output = os.popen(cmd).readlines()
- except:
- # the slice couldn't be found
- logger.log("get_sliver_process: couldn't find slice %s" % slice_name)
- return (None, None)
-
- cgroup_fn = None
- pid = None
- for e in output:
- try:
- l = e.rstrip()
- #logger.log("tools: l=%s" % (l) )
- path = l.split(':')[0]
- #logger.log("tools: path=%s" % (path) )
- comp = l.rsplit(':')[-1]
- #logger.log("tools: comp=%s" % (comp) )
- slice_name_check1 = comp.rsplit('/')[-1]
- #logger.log("tools: slice_name_check1=%s" % (slice_name_check1) )
- slice_name_check2 = slice_name_check1.rsplit('.')[0]
- #logger.log("tools: slice_name_check2=%s" % (slice_name_check2) )
-
- if (slice_name_check2 == slice_name):
- slice_path = path
- pid = slice_path.split('/')[2]
- #logger.log("tools: pid=%s" % (pid) )
- cmdline = open('/proc/%s/cmdline'%pid).read().rstrip('\n\x00')
- #logger.log("tools: cmdline=%s" % (cmdline) )
- #logger.log("tools: process_cmdline=%s" % (process_cmdline) )
- if (cmdline == process_cmdline):
- cgroup_fn = slice_path
- break
- except:
- #logger.log("tools: break!")
- break
-
- if (not cgroup_fn) or (not pid):
- logger.log("get_sliver_process: process %s not running in slice %s" % (process_cmdline, slice_name))
- return (None, None)
-
- return (cgroup_fn, pid)
-
-