forked from liguoyu1/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseOperator.py
executable file
·75 lines (65 loc) · 1.61 KB
/
DatabaseOperator.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
#-*- utf-8 -*-
# writer : lgy
# time :2015-10-19
import sys
sys.path.append('/home/ovsdoc/Documents/DockerManagement') #system path
import config
from pymongo import MongoClient
import traceback
class DataOperation:
def __init__(self):
pass
#connect mongodb database
def connectMongo(self,host,port):
try:
self.client = MongoClient(host,port)
except:
print str(traceback.format_exc())
#get OVS_info table's dta
def getDataOvs_info(self):
OVS_IP = []
try:
db = self.client.ovs
table = db.ovs_info
for data in table.find():
OVS_IP.append(data)
except:
print str(traceback.format_exc())
return OVS_IP
#get Ovs switch node link relationship
def getDataOvs_Link_info(self):
OVS_LINK = []
try:
db = self.client.ovs
table = db.ovs_link
for link in table.find():
OVS_LINK.append(link)
except:
print str(traceback.format_exc())
return OVS_LINK
# Insert Operation record to Operator_Log_data table
def InsertOperator_Log_data(self,Opr_log):
try:
db = self.client.ovs
table = db.Operator_Log_Info
if len(Opr_log) > 0:
table.insert(Opr_log)
except:
print str(traceback.format_exc())
return -1
return 0
# Insert device status record into Stats_log_Info table
def InsertStats_log_data(self,stat_log):
try:
db = self.client.ovs
table = db.Stats_Log_Info
if len(stat_log) > 0:
table.insert(stat_log)
except:
print str(traceback.format_exc())
return -1
return 0
# op = DataOperation()
# print config.MongoDB_Host,config.MongoDB_Port
# op.connectMongo(config.MongoDB_Host,config.MongoDB_Port)
# print op.getDataOvs_Link_info()