Refactoring the sdc-BE-init python scripts
[sdc.git] / catalog-be / sdc-backend-init / chef-repo / cookbooks / sdc-catalog-be-setup / recipes / 1_create_consumer_and_user.rb
1 if node['disableHttp']
2   protocol = "https"
3   https_flag = "--https"
4   be_port = node['BE']['https_port']
5 else
6   protocol = "http"
7   https_flag = ""
8   be_port = node['BE']['http_port']
9 end
10
11 if node['BE']['user_conf']
12   user_conf_dir = "--conf " + node['BE']['user_conf']
13 else
14   # set default user configuration file
15   user_conf_dir = ""
16 end
17
18 bash "executing-create_user" do
19   code <<-EOH
20     sdcuserinit -i #{node['Nodes']['BE']} -p #{be_port} #{user_conf_dir} #{https_flag}
21     rc=$?
22     if [[ $rc != 0 ]]; then exit $rc; fi
23   EOH
24 end
25
26 template "/var/tmp/consumers.py" do
27   source "consumers.py.erb"
28   sensitive true
29   mode 0755
30   variables({
31     :protocol => protocol,
32     :be_ip => node['Nodes']['BE'],
33     :be_port => be_port
34   })
35 end
36
37 bash "executing-consumers" do
38   code <<-EOH
39     python /var/tmp/consumers.py
40     rc=$?
41     if [[ $rc != 0 ]]; then exit $rc; fi
42   EOH
43 end