- # See if setns is installed. If it's not then we're probably not running
- # LXC.
- if not os.path.exists("/usr/sbin/setns.so"):
- return None
-
- # setns is part of lxcsu and is installed to /usr/sbin
- if not "/usr/sbin" in sys.path:
- sys.path.append("/usr/sbin")
- import setns
-
- (cgroup_fn, pid) = get_sliver_process(slice_name, "/sbin/init")
- if (not cgroup_fn) or (not pid):
- return None
-
- path = '/proc/%s/ns/net'%pid
-
- result = None
- try:
- setns.chcontext(path)
-
- args = ["/sbin/ifconfig", device]
- sub = subprocess.Popen(args, stderr = subprocess.PIPE, stdout = subprocess.PIPE)
- sub.wait()
-
- if (sub.returncode != 0):
- logger.log("get_slice_ifconfig: error in ifconfig: %s" % sub.stderr.read())
-
- result = sub.stdout.read()
- finally:
- setns.chcontext("/proc/1/ns/net")
-
- return result
-
-###################################################
-# Author: Guilherme Sperb Machado <gsm@machados.org>
-###################################################
-# Basically this method is just a copy from "get_sliver_ifconfig()", but,
-# instead, calls the "get_sliver_process_lxc()" method.
-# Only for LXC!
-# TODO: maybe merge both methods, and put the type as an argument, if
-# it is LXC or vserver
-###################################################
-def get_sliver_ifconfig_lxc(slice_name, device="eth0"):
- """ return the output of "ifconfig" run from inside the sliver.
-
- side effects: adds "/usr/sbin" to sys.path