From 1ce01dad25e40fbf4144efc5dcc6771c9bf14d20 Mon Sep 17 00:00:00 2001 From: Peter Mikus Date: Tue, 30 May 2017 14:10:14 +0200 Subject: CSIT-649 Add library for creating lxc container Add RF library for manipulating lxc container Add python library for manipulating lxc container Change-Id: I02140aa879c7ebd40360d588ab1438c58cf560a1 Signed-off-by: Peter Mikus --- resources/libraries/python/ssh.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'resources/libraries/python/ssh.py') diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py index f59bd02e25..db39a0701c 100644 --- a/resources/libraries/python/ssh.py +++ b/resources/libraries/python/ssh.py @@ -207,6 +207,29 @@ class SSH(object): command = 'sudo -S {c} <<< "{i}"'.format(c=cmd, i=cmd_input) return self.exec_command(command, timeout) + def exec_command_lxc(self, lxc_cmd, lxc_name, lxc_params='', sudo=True, + timeout=30): + """Execute command in LXC on a new SSH channel on the connected Node. + + :param lxc_cmd: Command to be executed. + :param lxc_name: LXC name. + :param lxc_params: Additional parameters for LXC attach. + :param sudo: Run in privileged LXC mode. Default: privileged + :param timeout: Timeout. + :type lxc_cmd: str + :type lxc_name: str + :type lxc_params: str + :type sudo: bool + :type timeout: int + :return: return_code, stdout, stderr + """ + command = "lxc-attach {p} --name {n} -- /bin/sh -c '{c}'"\ + .format(p=lxc_params, n=lxc_name, c=lxc_cmd) + + if sudo: + command = 'sudo -S {c}'.format(c=command) + return self.exec_command(command, timeout) + def interactive_terminal_open(self, time_out=30): """Open interactive terminal on a new channel on the connected Node. -- cgit 1.2.3-korg