diff options
author | Vincenzo Maffione <v.maffione@gmail.com> | 2017-04-28 15:57:47 +0200 |
---|---|---|
committer | Vincenzo Maffione <v.maffione@gmail.com> | 2017-04-28 15:57:47 +0200 |
commit | 5db6829d150669bb577565c0b6b26c5b03f8b421 (patch) | |
tree | 83529ce850a6f22e05b8c445c01d2f30e1070a65 | |
parent | 41e472bd8fd5dc14c21aac0e5a0009a02e6ea95b (diff) | |
download | rumba-5db6829d150669bb577565c0b6b26c5b03f8b421.tar.gz rumba-5db6829d150669bb577565c0b6b26c5b03f8b421.zip |
prototypes: rlite: add sudo when needed
-rw-r--r-- | rumba/prototypes/rlite.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/rumba/prototypes/rlite.py b/rumba/prototypes/rlite.py index a35f2f1..d35c5d5 100644 --- a/rumba/prototypes/rlite.py +++ b/rumba/prototypes/rlite.py @@ -38,17 +38,21 @@ class Experiment(mod.Experiment): ssh.execute_commands(self.testbed, node.ssh_config, cmds, time_out=None) + # Prepend sudo to all commands if the user is not 'root' + def may_sudo(self, cmds): + if self.testbed.username != 'root': + for i in range(len(cmds)): + cmds[i] = "sudo %s" % cmds[i] + def init_nodes(self): + # Load kernel modules and start the uipcps daemon cmds = ["modprobe rlite", "modprobe rlite-normal", "modprobe rlite-shim-eth", "modprobe rlite-shim-udp4", "modprobe rlite-shim-loopback", "rlite-uipcps -v DBG -k 0 &> uipcp.log &"] - - # Load kernel modules - - # Start the uipcps daemon + self.may_sudo(cmds) for node in self.nodes: self.execute_commands(node, cmds) @@ -80,6 +84,7 @@ class Experiment(mod.Experiment): cmds.append("rlite-ctl ipcp-config %s netdev %s" % (ipcp.name, ipcp.ifname)) + self.may_sudo(cmds) self.execute_commands(node, cmds) def register_ipcps(self): @@ -91,6 +96,7 @@ class Experiment(mod.Experiment): cmds.append("rlite-ctl ipcp-register %s %s" % (ipcp.name, lower.name)) + self.may_sudo(cmds) self.execute_commands(node, cmds) def enroll_ipcps(self): @@ -103,7 +109,9 @@ class Experiment(mod.Experiment): } cmd = "rlite-ctl ipcp-enroll %(enrollee)s %(dif)s "\ "%(lower_dif)s %(enroller)s" % d - self.execute_commands(e['enrollee'].node, [cmd]) + cmds = [cmd] + self.may_sudo(cmds) + self.execute_commands(e['enrollee'].node, cmds) time.sleep(1) def install_prototype(self): |