3 #from time import sleep
 
   5 from datetime import datetime
 
   8 BE_PORT="<%= @be_port %>"
 
  21 ##############################
 
  23 ##############################
 
  25     command="curl -s -o /dev/null -I -w \"%{http_code}\" -i http://" + BE_IP  + ":" + BE_PORT + "/sdc2/rest/v1/user/jh0003"
 
  27     proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
 
  28     (out, err) = proc.communicate()
 
  33 def checkConsumer(consumerName):
 
  34     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\"   http://" + BE_IP  + ":" + BE_PORT + "/sdc2/rest/v1/consumers/" + consumerName
 
  36     proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
 
  37     (out, err) = proc.communicate()
 
  42 def createConsumer( consumerName, consumerSalt, consumerPass ):
 
  43     print '[INFO] ' + consumerName
 
  44     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\" http://"  + ":" + BE_PORT + "/sdc2/rest/v1/consumers/ -d '{\"consumerName\": '" + consumerName + "', \"consumerSalt\": '" + consumerSalt + "',\"consumerPassword\": '" + consumerPass + "'}'"
 
  46     proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE)
 
  48     (out, err) = proc.communicate()
 
  55 ##############################
 
  57 ##############################
 
  58 consumersList = [ "aai" , "appc" , "dcae" , "mso" , "sdnc" , "vid" , "cognita", "clamp" , "vfc" , "workflow" , "policy" , "pomba" ]
 
  59 salt = "9cd4c3ad2a6f6ce3f3414e68b5157e63"
 
  60 password = "35371c046f88c603ccba152cb3db34ec4475cb2e5713f2fc0a43bf18a5243495"
 
  64 ##############################
 
  66 ##############################
 
  69     myResult = checkBackend()
 
  71         print '[INFO]: Backend is up and running'
 
  75         currentTime = datetime.now()
 
  76         print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC
 
  80     print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC
 
  83 for consumer in consumersList:
 
  84     myResult = checkConsumer(consumer)
 
  86         print '[INFO]: ' + consumer + ' already exists'
 
  88         myResult = createConsumer( consumer, salt, password )
 
  90             print '[INFO]: ' + consumer + ' created, result: [' + myResult + ']'
 
  92             print '[ERROR]: ' + bcolors.FAIL + consumer + bcolors.ENDC + ' error creating , result: [' + myResult + ']'