-
Notifications
You must be signed in to change notification settings - Fork 0
/
recepter.py
113 lines (102 loc) · 3.54 KB
/
recepter.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import memcache,json,subprocess,time,uuid,os
import ConfigParser,MySQLdb
#Khayam lanuched in pycharm
#----------------------------------
# Fireant working environment setup
#----------------------------------
config = ConfigParser.ConfigParser()
home_directory = os.path.expanduser('~')
config.read(home_directory + '/.fireantenv')
folder_path = config.get('directory','path')
config = ConfigParser.ConfigParser()
config.read('/etc/nova/fireant.conf')
local_ip = config.get('Local','ip')
shared = memcache.Client(['127.0.0.1:11211'], debug=0)
data = {}
data['vm_alias'] = shared.get('name')
data['flavor'] = shared.get('flavor')
if shared.get('vlantag') == -1 :
data['ID'] = 'empty'
else :
data['ID'] = shared.get('vlantag')
data['image'] = shared.get('image')
data['vnitag']= shared.get('vnitag')
if shared.get('ipaddr') is not None:
data['vm_ip'] = shared.get('ipaddr')
data['host_ip'] = local_ip #'172.16.10.83'
data['service'] = 'dbserver'
data['bin_name'] = 'dbserver.bin'
data['hop_count'] = shared.get('hopcount')
data2 = {}
data2['request'] = data
json_data = json.dumps(data2)
capabilities = {}
cap = {}
cap['virtulization'] = 'full'
cap['image_protocol'] = 'ccnx'
cap['network'] = 'ethernet'
capabilities = cap
firstreq = {}
firstreq['id']= shared.get('name')
firstreq['capabilites'] = capabilities
firstreq['properties'] = data
resource ={}
resource['resources'] = [firstreq]
connections = {}
connections = [[shared.get('name'),'vx1']]
resource['connections'] = connections
request = {}
request['request'] = resource
# Khayam: adding IP & MAC into request
dip=config.get('Local', 'ip')
dbase=config.get('sql', 'db')
duser=config.get('sql', 'user')
dpass=config.get('sql', 'pass')
db = MySQLdb.connect(host=dip,
user=duser, # your username
passwd=dpass, # your password
db=dbase) # name of the data base
cur = db.cursor()
netinfo = {}
cur.execute("select mac,ip,vlan,cluster from vms where cluster='CB_"+dip+"'")
for idx, row in enumerate(cur.fetchall()):
current = {}
current['mac']=row[0]
current['ip']=row[1]
current['vlan']=row[2]
cluster_name = row[3]
cluster_ip = cluster_name.split('_')
current['cluster'] = cluster_ip[1]
netinfo[idx]=current
request['netinfo']=netinfo
# Ke: add uuid into the request json 09/14/2015
request_uuid = str(uuid.uuid4())
request['request']['uuid'] = request_uuid
common = memcache.Client([local_ip+':11211'], debug=0)
common.set('vm', 'noone')
demotype = shared.get('demotype')
if int(demotype) == 1:
request['request']['forward_type'] = 'broadcast'
else:
request['request']['forward_type'] = 'unicast'
new_data = json.dumps(request)
#file = open('/home/dell/Documents/fireant/sockreq.json','w')
file = open(folder_path+'SharedData/sockreq.json','w')
file.write(new_data)
file.close()
'''
if int(demotype) == 1:
cmd = "python /home/dell/Documents/fireant/socket_request.py > /home/dell/request_log"
else:
cmd = "python /home/dell/Documents/fireant/unicast_request.py > /home/dell/request_log"
#cmd = "python /home/dell/Documents/fireant/fireant_request_temp.py > /home/dell/output_log"
'''
# New fireant code tested by Ke 09082015
cmd = "echo 'recepter.py here...' >> "+folder_path+"Log/fireant.log"
subprocess.Popen(cmd,shell=True)
cmd = folder_path+"MessageManagement/LocalRequestHandler.py "+folder_path+"/SharedData/sockreq.json >> "+folder_path+"Log/fireant.log"
#cmd = "./kenew/Code/MessageManagement/LocalRequestHandler.py ./kenew/Code/SharedData/sockreq.json"
subprocess.call(cmd,shell=True)
#time.sleep(5)