3 #from time import sleep
5 from datetime import datetime
8 BE_PORT="<%= @be_port %>"
9 PROTOCOL="<%= @protocol %>"
22 ##############################
24 ##############################
26 command="curl -k -s -o /dev/null -I -w \"%{http_code}\" -i "+PROTOCOL+"://" + BE_IP + ":" + BE_PORT + "/sdc2/rest/v1/user/jh0003"
28 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
29 (out, err) = proc.communicate()
31 return str(result, "UTF-8")
34 def checkConsumer(consumerName):
35 command="curl -k -s -o /dev/null -I -w \"%{http_code}\" -i -H \"Accept: application/json; charset=UTF-8\" -H \"Content-Type: application/json\" -H \"USER_ID: jh0003\" "+PROTOCOL+"://" + BE_IP + ":" + BE_PORT + "/sdc2/rest/v1/consumers/" + consumerName
37 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
38 (out, err) = proc.communicate()
40 return str(result, "UTF-8")
43 def createConsumer( consumerName, consumerSalt, consumerPass ):
44 print('[INFO] ' + consumerName)
45 command="curl -k -s -o /dev/null -w \"%{http_code}\" -X POST -i -H \"Accept: application/json; charset=UTF-8\" -H \"Content-Type: application/json\" -H \"USER_ID: jh0003\" "+PROTOCOL+"://" + BE_IP + ":" + BE_PORT + "/sdc2/rest/v1/consumers/ -d '{\"consumerName\": '" + consumerName + "', \"consumerSalt\": '" + consumerSalt + "',\"consumerPassword\": '" + consumerPass + "'}'"
47 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE)
49 (out, err) = proc.communicate()
51 return str(result, "UTF-8")
56 ##############################
58 ##############################
59 consumersList = [ "aai" , "appc" , "dcae" , "mso" , "sdnc" , "vid" , "cognita", "clamp" , "vfc" , "workflow" , "policy" , "pomba" , "multicloud", "cds", "modeling" ]
60 salt = "9cd4c3ad2a6f6ce3f3414e68b5157e63"
61 password = "35371c046f88c603ccba152cb3db34ec4475cb2e5713f2fc0a43bf18a5243495"
65 ##############################
67 ##############################
70 myResult = checkBackend()
72 print('[INFO]: Backend is up and running')
76 currentTime = datetime.now()
77 print('[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC)
81 print('[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC)
84 for consumer in consumersList:
85 myResult = checkConsumer(consumer)
87 print('[INFO]: ' + consumer + ' already exists')
89 myResult = createConsumer( consumer, salt, password )
91 print('[INFO]: ' + consumer + ' created, result: [' + myResult + ']')
93 print('[ERROR]: ' + bcolors.FAIL + consumer + bcolors.ENDC + ' error creating , result: [' + myResult + ']')