-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsaEE.py
90 lines (76 loc) · 2.67 KB
/
psaEE.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
#
# File: psaEE.py
# Created: 27/08/2014
# Author: BSC
#
# Description:
# Web service running on the PSA interacting with the PSC
#
#
import falcon
import json
import Config
import logging
import subprocess
from execInterface import execInterface
from getConfiguration import getConfiguration
from psaExceptions import psaExceptions
from dumpLogFile import dumpLogFile
#old
conf = Config.Configuration()
date_format = "%m/%d/%Y %H:%M:%S"
log_format = "[%(asctime)s.%(msecs)d] [%(module)s] %(message)s"
logging.basicConfig(filename=conf.LOG_FILE,level=logging.DEBUG,format=log_format, datefmt=date_format)
#older logging
#logging.basicConfig(filename=conf.LOG_FILE,level=logging.DEBUG,format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
pscAddr = conf.PSC_ADDRESS
configsPath = conf.PSA_CONFIG_PATH
psaID = conf.PSA_ID
#confID = conf.CONF_ID
logging.info("--------")
logging.info("PSA EE init.")
logging.info("PSA ID: " + str(psaID))
logging.info("PSA NAME: " + str(conf.PSA_NAME))
logging.info("PSA VERSION: " + str(conf.PSA_VERSION))
logging.info("PSA-PSC API version: " + str(conf.PSA_API_VERSION))
logging.info("PSA log location: " + str(conf.PSA_LOG_LOCATION))
logging.info("--------")
# instantiate class object to manage REST interface to the PSC
execIntf = execInterface(configsPath, conf.PSA_SCRIPTS_PATH, conf.PSA_LOG_LOCATION, psaID)
#confHand = getConfiguration(pscAddr, configsPath, confID, psaID)
confHand = getConfiguration(pscAddr, configsPath, conf.PSA_SCRIPTS_PATH, psaID, str(conf.PSA_API_VERSION))
# start the HTTP falcon proxy and adds reachable resources as routes
app = falcon.API()
#app.add_route('/execInterface', excIntf)
app.add_route("/" + str(conf.PSA_API_VERSION) + '/execInterface/{command}', execIntf)
dumpLog = dumpLogFile()
#FOR DEBUGGING ONLY, REMOVE IN PRODUCTION
app.add_route("/" + str(conf.PSA_API_VERSION) + '/execInterface/dump-log-ctrl', dumpLog)
logging.info("execInterface routes added.")
# Inform our PSC that we are up
#TODO
'''
try:
start_res = confHand.send_start_event()
# We don't need to enable anything
#proc = subprocess.Popen(confScript, stdout=subprocess.PIPE, shell=True)
#(out, err) = proc.communicate()
except psaExceptions as exc:
pass
'''
# Pull configuration and start the PSA.
try:
confScript = confHand.pullPSAconf()
execIntf.callStartScript()
except psaExceptions as exc:
pass
logging.info("PSA start done.")
# http request to ask for the configuration and start the script
'''
try:
confScript = confHand.pullPSAconf()
proc = subprocess.Popen(confScript, stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
except psaExceptions as exc:
pass
'''