-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpingAgent.py
executable file
·95 lines (76 loc) · 2.43 KB
/
pingAgent.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
#!.pyenv/bin/python
#from gevent import monkey
# monkey.patch_all()
import os
import sys
from subprocess import Popen, PIPE
from utils.general import readConfig, now, getSystemInfo, getBenchmark
from utils.client_tools import getServerUrl, connectToServer, getImageInfo, getRenderTools, MAC
import psutil
from utils.decorators import only_one
import datetime
import time
import requests
import ujson
import json
from requests import HTTPError, ConnectionError
from datetime import timedelta
import re
from copy import copy
import anydbm
CONFIG = readConfig()
# celery setup
ldbpath = 'lcache.db'
db = anydbm.open(ldbpath, 'c')
if not db.keys():
print '*' * 80
print " Seems it's first time you are running Flipfarm worker"
slaveName = raw_input(' Please Enter a name for this machine: ')
print ' Now let me benchmark "%s" for speed and performance. please wait ...' % slaveName.title()
qmark = getBenchmark()
db['slaveName'] = slaveName.title()
db['qmark'] = str(qmark)
print '*' * 80
slaveName = db['slaveName']
qmark = int(db['qmark'])
db.close()
redis_host = CONFIG.get('server').get('redis_host')
redis_port = CONFIG.get('server').get('redis_port')
BROKER_URL = 'redis://{host}:{port}/10'.format(host=redis_host,
port=int(redis_port))
CELERY_RESULT_BACKEND = 'redis://{host}:{port}/10'.\
format(host=redis_host, port=int(redis_port))
from celery import Celery
pa = Celery('pingAgent', broker=BROKER_URL, backend=CELERY_RESULT_BACKEND)
pa.config_from_object('pingAgentConfig')
@pa.task(name='pingAgent.ping')
def ping():
''' This method pings server'''
systemInfo = getSystemInfo()
'''Now lets read browser database info which is send to us'''
payload = copy(systemInfo)
payload['render_tools'] = getRenderTools()
payload['os'] = sys.platform
payload['identity'] = slaveName
payload['qmark'] = qmark
payload['MAC'] = MAC
data = connectToServer(
'/api/ping', data=ujson.dumps(payload), packit=False)
if data:
return 'PONG'
@pa.task(name='clientAgent.getCommand')
def runCommand(cmd):
''' gets a command and runs it on client '''
import os
os.system(cmd)
print 'happy %s' % cmd
if __name__ == '__main__':
'''Lets ping before start'''
argv = [
'worker',
'--loglevel=INFO',
'--hostname=%s' % (MAC),
'--pidfile=pingAgent.pid',
'--beat'
]
pa.worker_main(argv)