4 #from time import sleep
6 from datetime import datetime
19 ##############################
21 ##############################
23 command="curl -s -o /dev/null -I -w \"%{http_code}\" -i <%= @protocol %>://<%= @catalog_ip %>:<%= @catalog_port %>/sdc2/rest/v1/user/jh0003"
25 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
26 (out, err) = proc.communicate()
31 def checkConsumer(consumerName):
32 command="curl -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 %>://<%= @catalog_ip %>:<%= @catalog_port %>/sdc2/rest/v1/consumers/" + consumerName
34 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
35 (out, err) = proc.communicate()
40 def createConsumer( consumerName, consumerSalt, consumerPass ):
41 print '[INFO] ' + consumerName
42 command="curl -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 %>://<%= @catalog_ip %>:<%= @catalog_port %>/sdc2/rest/v1/consumers/ -d '{\"consumerName\": '" + consumerName + "', \"consumerSalt\": '" + consumerSalt + "',\"consumerPassword\": '" + consumerPass + "'}'"
44 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE)
46 (out, err) = proc.communicate()
53 ##############################
55 ##############################
56 consumersList = [ "<%= @consumerName %>" ]
57 salt = "67fbde1c142bb25c7d6086252d6ab08d"
58 password = "d6e61a6859456cf4ded84f641ae59301ebf19d56cd5fc8a8f15b7cc54d3b6429"
62 ##############################
64 ##############################
67 myResult = checkBackend()
69 print '[INFO]: SDC Backend is up and running'
73 currentTime = datetime.now()
74 print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' SDC Backend not responding, try #' + str(i) + bcolors.ENDC
78 print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'SDC Backend is DOWN :-(' + bcolors.ENDC
81 for consumer in consumersList:
82 myResult = checkConsumer(consumer)
84 print '[INFO]: ' + consumer + ' already exists'
86 myResult = createConsumer( consumer, salt, password )
88 print '[INFO]: ' + consumer + ' created, result: [' + myResult + ']'
90 print '[ERROR]: ' + bcolors.FAIL + consumer + bcolors.ENDC + ' error creating , result: [' + myResult + ']'