Created
April 4, 2016 01:22
-
-
Save ejcer/e5c3b35504647aaf671d98d87006806d to your computer and use it in GitHub Desktop.
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
def start_instance_elections(instance_ids): | |
session = boto3.session.Session(profile_name='default') | |
ec2_resource = session.resource('ec2')#high level resource level | |
key = paramiko.RSAKey.from_private_key_file('/home/edward/workspace/waka/mykeypair.pem') | |
Port = 22 | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
print('starting election on instances') | |
start_time = str(int(round(time.time() * 1000)) + 40000) | |
for instance_id in instance_ids: | |
print(instance_id) | |
instance = ec2_resource.Instance(instance_id) | |
ssh.connect(instance.public_ip_address, username='ubuntu', pkey=key) | |
stdin, stdout, stderr = ssh.exec_command('tmux send-keys -t wakasesh elect '+start_time) | |
print(stdout.readlines()) | |
print(stderr.readlines()) | |
stdin, stdout, stderr = ssh.exec_command('tmux send-keys -t wakasesh Enter') | |
print(stdout.readlines()) | |
print(stderr.readlines()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment