Created
October 10, 2013 00:58
-
-
Save fspot/6911309 to your computer and use it in GitHub Desktop.
Usage : "saltshell.py" to get the list of minions (+ os and ip), "saltshell.py foo" to virtually ssh into foo minion. A lot of restrictions. May not work if your salt master is properly configured.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
import sys | |
import os | |
from os.path import join | |
if len(sys.argv) == 1: | |
print "\n### Wanna see the list of connected minions, and their respective OS ? k." | |
print "### Wait a little... like 10s...\n" | |
os.system("salt -v '*' grains.item os ipv4") | |
sys.exit(0) | |
print "\n### I suppose you're root, in /root." | |
print "### Do not trust that and test whoami and pwd. On Windows ? Ha-ha !" | |
print "### Also, don't forget : any command here does not affect next commands." | |
print "### So, forget 'source venv/bin/activate', 'export PATH=truc', 'screen -r', etc." | |
print "### Also, use only finishing-commands like ls or cat. Forget less, htop, vim, nano, screen, tail -f...\n" | |
dest = sys.argv[1] | |
rep = '/root' | |
while True: | |
cmd = raw_input('>>> root@%s:%s # ' % (dest, rep)) | |
if cmd == 'cd': | |
cmd = 'cd /root' | |
if cmd.startswith('cd /') or cmd.startswith('cd ') and cmd[4] == ':': | |
rep = cmd[3:] | |
elif cmd.startswith('cd '): | |
rep = join(rep, cmd[3:]) | |
else: | |
os.system("salt '%s' cmd.run 'cd %s && %s'" % (dest, rep, cmd)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment