diff options
Diffstat (limited to 'docker/docker_be/chef-repo/cookbooks/Deploy-DCAE/templates/default/consumers.py.erb')
-rw-r--r-- | docker/docker_be/chef-repo/cookbooks/Deploy-DCAE/templates/default/consumers.py.erb | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/docker/docker_be/chef-repo/cookbooks/Deploy-DCAE/templates/default/consumers.py.erb b/docker/docker_be/chef-repo/cookbooks/Deploy-DCAE/templates/default/consumers.py.erb new file mode 100644 index 0000000..c6b412c --- /dev/null +++ b/docker/docker_be/chef-repo/cookbooks/Deploy-DCAE/templates/default/consumers.py.erb @@ -0,0 +1,97 @@ +#!/usr/bin/python +import sys +import subprocess +#from time import sleep +import time +from datetime import datetime + + +class BColors: + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + + +############################## +# Functions +############################## +def check_backend(): + command="curl -s -k --cacert org.onap.sdc.key -o /dev/null -I -w \"%{http_code}\" " \ + "-i <%= @protocol %>://<%= @catalog_ip %>:<%= @catalog_port %>/sdc2/rest/v1/user/jh0003" + + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + (out, err) = proc.communicate() + result = out.strip() + return result + + +def check_consumer(consumer_name): + command="curl -s -k --cacert org.onap.sdc.key -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/" + consumer_name + + proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + (out, err) = proc.communicate() + result = out.strip() + return result + + +def create_consumer(consumerName, consumerSalt, consumerPass): + print '[INFO] ' + consumerName + command="curl -s -k --cacert org.onap.sdc.key -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 + "'}'" + + proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE) + (out, err) = proc.communicate() + result = out.strip() + return result + + +############################## +# Definitions +############################## +consumers_list = ["<%= @consumerName %>"] +salt = "67fbde1c142bb25c7d6086252d6ab08d" +password = "d6e61a6859456cf4ded84f641ae59301ebf19d56cd5fc8a8f15b7cc54d3b6429" +beStat=0 + + +############################## +# Main +############################## + +for i in range(1,10): + my_result = check_backend() + if my_result == '200': + print '[INFO]: SDC Backend is up and running' + beStat=1 + break + else: + currentTime = datetime.now() + print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + BColors.FAIL + \ + ' SDC Backend not responding, try #' + str(i) + BColors.ENDC + time.sleep(10) + +if beStat == 0: + print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + BColors.FAIL + 'SDC Backend is DOWN :-(' + BColors.ENDC + sys.exit(0) + +for consumer in consumers_list: + my_result = check_consumer(consumer) + if my_result == '200': + print '[INFO]: ' + consumer + ' already exists' + else: + my_result = create_consumer(consumer, salt, password) + if my_result == '201': + print '[INFO]: ' + consumer + ' created, result: [' + my_result + ']' + else: + print '[ERROR]: ' + BColors.FAIL + consumer + BColors.ENDC + ' error creating , result: [' + my_result + ']' |