-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.py
38 lines (30 loc) · 1.1 KB
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Change the IP addresses of the given hosts.
Uses https://github.com/micahjmartin/detcord to interact with the remote hosts
"""
from detcord import action, display
from networking import getRandomIps
env = dict()
env['user'] = 'root'
env['pass'] = 'changeme'
env['hosts'] = [] # DYNAMICALLY GENERATED IN getHosts()
env['silent'] = False
env['threading'] = True
NEWIPS = {}
@action
def update(host):
"""Update the IP addresses in workers.txt with a new, random IP
"""
sudo = host.user != "root" # Only use sudo if we are not root
display(host.local("echo Setting the IP to {}, sudo = {}".format(NEWIPS[host.host], sudo)))
def getHosts():
"""Read the workers IP addresses from a file"""
with open("workers.txt") as fil:
workers = [worker.strip() for worker in fil.readlines()]
new_ips = getRandomIps(len(workers)) # Get a new Ip address for each worker
for worker in workers:
env['hosts'].append(worker)
NEWIPS[worker] = new_ips.pop()
getHosts()
def on_detcord_end(detfile=""):
print("Saving the new IP addresses:{}\n".format("\n".join(NEWIPS.values())))