-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathceleryworkers.py
114 lines (95 loc) · 3.45 KB
/
celeryworkers.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
__author__ = 'Rene'
import boto.ec2
import aws_keys
import os
import time
from fabric.tasks import execute
from fabric.api import *
import matplotlib.pyplot as plt
print boto.ec2.regions()
conn = boto.ec2.connect_to_region("us-east-1",
aws_access_key_id=aws_keys.aws_access_key_id,
aws_secret_access_key=aws_keys.aws_secret_access_key)
reservations = conn.run_instances(
'ami-64566e0c', min_count=2, max_count=2,
key_name='rene',
instance_type='m3.medium',
security_groups=['launch-wizard-1'])
time.sleep(10)
for instance in reservations.instances:
while instance.state != "running":
time.sleep(5)
instance.update()
print instance.state
print instance.state
print "running"
# print "waiting..."
# time.sleep(40)
con=conn.get_all_instance_status()
for i,ins in enumerate(con):
while str(con[i].system_status) != "Status:ok":
time.sleep(5)
con=conn.get_all_instance_status()
print "Waiting"
print "Iniciadas"
def execute_task():
put(local_path="C:\Users\Rene\Desktop\mazon\conf\conf.yaml", remote_path="EvoPar2015/code/conf/conf.yaml")
put(local_path="C:\Users\Rene\Desktop\deap\deap\one_diversidad.py", remote_path="EvoPar2015/code/one_diversidad.py")
put(local_path="C:\Users\Rene\Desktop\deap\deap\one_all_cloud_n3.py", remote_path="EvoPar2015/code/one_all_cloud_n3.py")
#sudo('mkdir EvoPar2015/code/data')
#run("celery -A one_rastrigin worker --loglevel=info")
put(local_path='celeryd', remote_path="/etc/default/celeryd", use_sudo=True, mode=0640)
sudo("chown root /etc/default/celeryd")
sudo("service celeryd start")
def get_files(host):
env.hosts=[host]
env.user = 'ubuntu'
env.key_filename = 'rene.cer'
get(remote_path="EvoPar2015/code/data", local_path="C:\Users\Rene\Desktop\experientos\data"+ins.id)
path="C:\Users\Rene\Desktop\experientos\data"+ins.id+"\data"
# for filename in os.listdir(path):
# w12_file = open("%s/%s" % (path,filename))
# w12_records = [line.split(",") for line in w12_file if len(line.split(",")) == 3]
# y=tuple(x[1] for x in w12_records)
# x=range(0,len(w12_records))
# plt.plot(x,y)
# plt.ylabel('Tiempo Segundos')
# plt.xlabel('Experimento')
# plt.show()
print "Ok"
def execute_celery():
host=str(reservations.instances[0].public_dns_name)
env.hosts=[host]
env.user = 'ubuntu'
env.key_filename = 'rene.cer'
sudo('chown root EvoPar2015/code/conf')
sudo('chown root EvoPar2015/code/data')
sudo('python EvoPar2015/code/one_all_cloud_n3.py')
#get_files(host)
def tomar():
host=str(reservations.instances[0].public_dns_name)
env.hosts=[host]
env.user = 'ubuntu'
env.key_filename = 'rene.cer'
get_files(host)
for i, ins in enumerate(reservations.instances):
host=str(ins.public_dns_name)
env.hosts=[host]
env.user = 'ubuntu'
env.password='masterkey2010'
env.key_filename = 'rene.cer'
execute(execute_task)
print str(ins.public_dns_name) + 'Ok'
raw_input("Press enter to continue")
for i in range(100):
execute(execute_celery)
time.sleep(1)
if i == 1:
raw_input("Finished")
else:
pass
# execute(execute_celery)
#
# raw_input("Otra vez")
#
# execute(execute_celery)