* See the License for the specific language governing permissions and
* limitations under the License.
*
-* ECOMP is a trademark and service mark of AT&T Intellectual Property.
* ============LICENSE_END=========================================================
*/
'''
def callback (Id, Result, Output, Log, returncode):
- print "***> in RestServer.callback"
+ print("***> in RestServer.callback")
if Id in TestRecord:
time_now = datetime.datetime.utcnow()
if key in TestRecord[Id]['Output']['Output']:
data["Results"][key]["Output"] = TestRecord[Id]['Output']['Output'][key]
- print " Posting to", TestRecord[Id]['CallBack']
+ print(" Posting to", TestRecord[Id]['CallBack'])
s = requests.Session()
r = s.post(TestRecord[Id]['CallBack'], data = json.dumps(data),
headers = {'content-type': 'application/json'})
- print " Response", r.status_code, r.text
+ print(" Response", r.status_code, r.text)
def RunAnsible_Playbook (callback, Id, Inventory, Playbook, NodeList, TestRecord,
Path, ArchiveFlag):
- print "***> in RestServer.RunAnsible_Playbook"
+ print("***> in RestServer.RunAnsible_Playbook")
# Run test in playbook for given target
Result = ''
f = open(Path + "/" + file, "r")
resultsData = f.read() # Not to pass vnf instance name
OutputP = json.loads(resultsData)
- Output['Output'] = OutputP
- cherrypy.log("Output = " + str(Output['Output']))
+ Output['Output'] = OutputP
+ cherrypy.log("Output = " + str(Output['Output']))
#Output['Output'][key] = f.read() # To pass vnf instance name
f.close()
if True:
if not input_json['Id'] in TestRecord:
- # check if Id exists in previous run dirctory
+ # check if Id exists in previous run dirctory
# if so retun error
s_cmd = 'ls ' + ansible_temp + '/*_' + input_json['Id']
#if subprocess.check_output([s_cmd, ]):
# cherrypy.log("EnvParameter object: " + i)
# cherrypy.log(" EnvParameter Value: " + EnvParameters[ i ])
- # Now get things out of EnvParameters
+ # Now get things out of EnvParameters
VNF_instance = None
VNF_instance = EnvParameters.get('vnf_instance')
# Verify VNF_instance was passed in EnvParameters
if VNF_instance != None:
- cherrypy.log( "Request Decode: VnfInstance " + VNF_instance)
+ cherrypy.log( "Request Decode: VnfInstance " + VNF_instance)
else:
- cherrypy.log( "StatusCode: 107, StatusMessage: VNF_instance NOT PROVIDED" )
+ cherrypy.log( "StatusCode: 107, StatusMessage: VNF_instance NOT PROVIDED" )
return {"StatusCode": 107,
"StatusMessage": "VNF_instance NOT PROVIDED"}
if inventory_names != None:
- cherrypy.log( "Request Decode: Inventory Names " + inventory_names)
+ cherrypy.log( "Request Decode: Inventory Names " + inventory_names)
else:
- cherrypy.log( "Request Decode: Inventory Names " + "Not provided")
-
- cherrypy.log( "Request Decode: PlaybookName " + PlaybookName)
- PlayBookFunction = PlaybookName.rsplit("/",2)[1]
- PlayBookFile = PlayBookFunction + "/site.yml"
- cherrypy.log( "Request Decode: PlaybookFunction " + PlayBookFunction)
- cherrypy.log( "Request Decode: Playbook file " + PlayBookFile)
-
+ cherrypy.log( "Request Decode: Inventory Names " + "Not provided")
+
+ cherrypy.log( "Request Decode: PlaybookName " + PlaybookName)
+ PlayBookFunction = PlaybookName.rsplit("/",2)[1]
+ PlayBookFile = PlayBookFunction + "/site.yml"
+ cherrypy.log( "Request Decode: PlaybookFunction " + PlayBookFunction)
+ cherrypy.log( "Request Decode: Playbook file " + PlayBookFile)
+
BaseDir = ansible_path + "/" + PlaybookName.rsplit("/",1)[0]
CopyDir = ansible_path + "/" + PlaybookName.rsplit("/",2)[0]
- cherrypy.log( "Request Decode: Basedir " + BaseDir)
- cherrypy.log( "Request Decode: Copydir " + CopyDir)
-
+ cherrypy.log( "Request Decode: Basedir " + BaseDir)
+ cherrypy.log( "Request Decode: Copydir " + CopyDir)
+
PlaybookDir = ansible_temp + "/" + \
VNF_instance + "_" + str_uuid + "_" + str(Id)
- # AnsibleInv is the directory where the host file to be run exsists
+ # AnsibleInv is the directory where the host file to be run exsists
AnsibleInv = ansible_path + "/" + VnfType + "/latest/ansible/inventory/" + VNF_instance
ArchiveFlag = False
- # Create base run directory if it doesn't exist
+ # Create base run directory if it doesn't exist
if not os.path.exists(ansible_temp):
cherrypy.log( "Creating Base Run Directory: " + ansible_temp)
os.makedirs(ansible_temp)
- if not os.path.exists( CopyDir ):
+ if not os.path.exists( CopyDir ):
cherrypy.log("Playbook Not Found")
return {"StatusCode": 101,
"StatusMessage": "PLAYBOOK NOT FOUND"}
cherrypy.log( "PlaybookDir: " + PlaybookDir)
cherrypy.log( "AnsibleInv: " + AnsibleInv)
- #location of host file
+ #location of host file
#HostFile = PlaybookDir + "/inventory/" + VNF_instance + "hosts"
#cherrypy.log("HostFile: " + HostFile)
#AnsibleInvFail = False # ???
HaveNodeList = True
- ###############################################################################
- ##### Host file processing ###########################
- ##### 1. Use file delivered with playbook ###########################
- ##### 2. If HostNames + NodeList generate and use ###########################
- ##### 3. If HostNames = VM or NVF copy and use. ###########################
- ###############################################################################
+ ###############################################################################
+ ##### Host file processing ###########################
+ ##### 1. Use file delivered with playbook ###########################
+ ##### 2. If HostNames + NodeList generate and use ###########################
+ ##### 3. If HostNames = VM or NVF copy and use. ###########################
+ ###############################################################################
- #location of host file - Default
+ #location of host file - Default
HostFile = PlaybookDir + "/inventory/" + VNF_instance + "hosts"
cherrypy.log("HostFile: " + HostFile)
if 'CallBack' in input_json:
callback_flag = input_json['CallBack']
- # if AnsibleServer is not set to 'na' don't send AnsibleServer in PENDING responce.
- if AnsibleServer != 'na':
- TestRecord[Id] = {'PlaybookName': PlaybookName,
+ # if AnsibleServer is not set to 'na' don't send AnsibleServer in PENDING responce.
+ if AnsibleServer != 'na':
+ TestRecord[Id] = {'PlaybookName': PlaybookName,
'Version': version,
'NodeList': NodeList,
'HostGroupList': hostgrouplist,
'Output': {},
'Path': PlaybookDir,
'Mandatory': None}
- else:
- TestRecord[Id] = {'PlaybookName': PlaybookName,
+ else:
+ TestRecord[Id] = {'PlaybookName': PlaybookName,
'Version': version,
'NodeList': NodeList,
'HostGroupList': hostgrouplist,
# Process playbook
- if os.path.exists( ansible_path + '/' + PlaybookName):
+ if os.path.exists( ansible_path + '/' + PlaybookName):
AnsiblePlaybookFail = False
if AnsiblePlaybookFail:
# PAP
f = open(playbook_path + "/vars/defaults.yml","a")
#for id, record in TestRecord.items():
- print TestRecord[Id]['LocalParameters']
+ print(TestRecord[Id]['LocalParameters'])
local_parms = TestRecord[Id]['LocalParameters']
- for key, value in local_parms.items():
+ for key, value in list(local_parms.items()):
f.write(key +"=" + value + "\n");
f.close()
###################################################
f.close()
f = open(playbook_path + "/JsonRequest.txt", "w")
#f.write(str(input_json))
- print( json.dumps(input_json, indent=4, sort_keys=True))
+ print(( json.dumps(input_json, indent=4, sort_keys=True)))
f.write( json.dumps(input_json, indent=4, sort_keys=True))
f.close()
cherrypy.log("Payload: " + str(input_data) + " Type " + input_data['Type'])
if 'LogRest' in input_data['Type']:
- sys.stdout.close()
- sys.stdout = open("/var/log/RestServer.log", "w")
+ sys.stdout.close()
+ sys.stdout = open("/var/log/RestServer.log", "w")
# Just a debug to dump any records
if 'GetStatus' in input_data['Type']:
cherrypy.log( "******** Dump Records **********")
- if TestRecord.items():
- for id, record in TestRecord.items():
+ if list(TestRecord.items()):
+ for id, record in list(TestRecord.items()):
cherrypy.log( " Id: " + id)
cherrypy.log( "Record: " + str(record))
else:
return out_obj
elif 'GetStatus' in input_data['Type']:
- print " Dump Records"
+ print(" Dump Records")
for id, record in TestRecord,items():
- print " id: " + id
- print " Record:" + str(reecord)
+ print(" id: " + id)
+ print(" Record:" + str(reecord))
elif 'GetOutput' in input_data['Type']:
else:
playbooknametxt = "NA"
- # Add code to get other items not just output.log from files
+ # Add code to get other items not just output.log from files
if os.path.exists( rdir + "/log.file"):
cherrypy.log("Found log.file")
out_results = "NA:"
line = f.readline()
while line :
- if "fatal" in line:
+ if "fatal" in line:
out_results = out_results + line
elif "RECAP" in line:
out_results = out_results + line
config_file_path = "RestServer_config"
if not os.path.exists(config_file_path):
- print '[INFO] The config file does not exist'
+ print('[INFO] The config file does not exist')
sys.exit(0)
ip = 'na'
# Point to certificate files
if not os.path.exists(pub):
- print '[INFO] The public certificate does not exist'
+ print('[INFO] The public certificate does not exist')
sys.exit(0)
if not os.path.exists(priv):
- print '[INFO] The private key does not exist'
+ print('[INFO] The private key does not exist')
sys.exit(0)
if not os.path.exists(intermediate):
- print '[INFO] The intermediate certificate does not exist'
+ print('[INFO] The intermediate certificate does not exist')
sys.exit(0)
if auth:
# Read in and build user dictionary
if not os.path.exists(users):
- print '[INFO] The users file does not exist: ' + users
+ print('[INFO] The users file does not exist: ' + users)
sys.exit(0)
userpassdict = {}
user_file = open(users, 'r')