diff options
author | Peter Mikus <pmikus@cisco.com> | 2017-05-30 14:10:14 +0200 |
---|---|---|
committer | Peter Mikus <pmikus@cisco.com> | 2017-06-15 11:48:15 +0000 |
commit | 1ce01dad25e40fbf4144efc5dcc6771c9bf14d20 (patch) | |
tree | 4676a4051c91f6adc4cbd401d13edaeebe476194 /resources/libraries/python/ssh.py | |
parent | 01e8dbf3aa23c43c2ffd668c694d31d8af12abe7 (diff) |
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 <pmikus@cisco.com>
Diffstat (limited to 'resources/libraries/python/ssh.py')
-rw-r--r-- | resources/libraries/python/ssh.py | 23 |
1 files changed, 23 insertions, 0 deletions
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. |