cloudbox-server 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/.yardopts +3 -0
  2. data/README.md +17 -0
  3. data/bin/cb-cluster-allocate +5 -0
  4. data/bin/cb-cluster-create +5 -0
  5. data/bin/cb-cluster-delete +5 -0
  6. data/bin/cb-cluster-desallocate +5 -0
  7. data/bin/cb-cluster-info +5 -0
  8. data/bin/cb-cluster-ls +5 -0
  9. data/bin/cb-node-destroy +5 -0
  10. data/bin/cb-node-detach +6 -0
  11. data/bin/cb-node-info +5 -0
  12. data/bin/cb-node-install +5 -0
  13. data/bin/cb-node-ls +5 -0
  14. data/bin/cb-service-add +5 -0
  15. data/bin/cb-service-component-add +5 -0
  16. data/bin/cb-service-component-delete +5 -0
  17. data/bin/cb-service-component-detach +5 -0
  18. data/bin/cb-service-conf-apply +5 -0
  19. data/bin/cb-service-conf-create +5 -0
  20. data/bin/cb-service-conf-get +5 -0
  21. data/bin/cb-service-conf-ls +5 -0
  22. data/bin/cb-service-follow-request +5 -0
  23. data/bin/cb-service-info +5 -0
  24. data/bin/cb-service-install +5 -0
  25. data/bin/cb-service-ls +5 -0
  26. data/bin/cb-service-start +5 -0
  27. data/bin/cb-service-stop +5 -0
  28. data/lib/command.rb +61 -0
  29. data/lib/command/ambari_add_host.rb +19 -0
  30. data/lib/command/ambari_cluster_command.rb +26 -0
  31. data/lib/command/ambari_cluster_component_command.rb +26 -0
  32. data/lib/command/ambari_cluster_component_host_command.rb +26 -0
  33. data/lib/command/ambari_cluster_create.rb +19 -0
  34. data/lib/command/ambari_cluster_host_command.rb +27 -0
  35. data/lib/command/ambari_cluster_list.rb +20 -0
  36. data/lib/command/ambari_cluster_service_command.rb +26 -0
  37. data/lib/command/ambari_cluster_service_host_command.rb +26 -0
  38. data/lib/command/ambari_command.rb +21 -0
  39. data/lib/command/ambari_create_cluster_configuration.rb +39 -0
  40. data/lib/command/ambari_get_cluster_configuration.rb +29 -0
  41. data/lib/command/ambari_host_list.rb +19 -0
  42. data/lib/command/ambari_install_cluster.rb +19 -0
  43. data/lib/command/ambari_install_component.rb +19 -0
  44. data/lib/command/ambari_install_host.rb +19 -0
  45. data/lib/command/ambari_install_host_component.rb +19 -0
  46. data/lib/command/ambari_install_host_components.rb +19 -0
  47. data/lib/command/ambari_install_service_components.rb +19 -0
  48. data/lib/command/ambari_service_add.rb +27 -0
  49. data/lib/command/ambari_service_component_add.rb +21 -0
  50. data/lib/command/ambari_service_component_delete.rb +21 -0
  51. data/lib/command/ambari_service_component_detach.rb +21 -0
  52. data/lib/command/ambari_service_component_info.rb +29 -0
  53. data/lib/command/ambari_service_conf_apply.rb +31 -0
  54. data/lib/command/ambari_service_conf_ls.rb +30 -0
  55. data/lib/command/ambari_service_delete.rb +21 -0
  56. data/lib/command/ambari_service_info.rb +20 -0
  57. data/lib/command/ambari_service_list.rb +21 -0
  58. data/lib/command/ambari_start_cluster.rb +19 -0
  59. data/lib/command/ambari_start_component.rb +19 -0
  60. data/lib/command/ambari_start_host.rb +19 -0
  61. data/lib/command/ambari_start_host_component.rb +19 -0
  62. data/lib/command/ambari_start_host_components.rb +19 -0
  63. data/lib/command/ambari_start_service_components.rb +19 -0
  64. data/lib/command/ambari_stop_cluster.rb +19 -0
  65. data/lib/command/ambari_stop_component.rb +19 -0
  66. data/lib/command/ambari_stop_host.rb +19 -0
  67. data/lib/command/ambari_stop_host_component.rb +19 -0
  68. data/lib/command/ambari_stop_host_components.rb +19 -0
  69. data/lib/command/ambari_stop_service_components.rb +19 -0
  70. data/lib/command/basic_command.rb +44 -0
  71. data/lib/command/cluster_create.rb +50 -0
  72. data/lib/command/cluster_delete.rb +30 -0
  73. data/lib/command/cluster_info.rb +30 -0
  74. data/lib/command/cluster_ls.rb +30 -0
  75. data/lib/command/crowbar_cluster_allocate.rb +42 -0
  76. data/lib/command/crowbar_command.rb +30 -0
  77. data/lib/command/crowbar_get_barclamps_list.rb +30 -0
  78. data/lib/command/crowbar_node_command.rb +21 -0
  79. data/lib/command/crowbar_node_list.rb +40 -0
  80. data/lib/command/crowbar_vcluster_command.rb +20 -0
  81. data/lib/command/filter.rb +15 -0
  82. data/lib/command/node_destroy.rb +58 -0
  83. data/lib/command/node_detach.rb +44 -0
  84. data/lib/command/node_info.rb +27 -0
  85. data/lib/command/node_install.rb +46 -0
  86. data/lib/command/node_reinstall.rb +44 -0
  87. data/lib/command/state_filter.rb +16 -0
  88. data/lib/common.rb +11 -0
  89. data/lib/common/cb-lib-node-erase-hard-disk.sh +29 -0
  90. data/lib/common/cloudbox_exceptions.rb +631 -0
  91. data/lib/common/cloudbox_logger.rb +81 -0
  92. data/lib/common/cloudbox_logger_mock.rb +43 -0
  93. data/lib/common/color.rb +267 -0
  94. data/lib/common/config_properties.rb +2027 -0
  95. data/lib/common/services_description.rb +192 -0
  96. data/lib/exec.rb +35 -0
  97. data/lib/exec/check_parameter.rb +208 -0
  98. data/lib/exec/cluster_allocate.rb +163 -0
  99. data/lib/exec/cluster_create.rb +99 -0
  100. data/lib/exec/cluster_delete.rb +38 -0
  101. data/lib/exec/cluster_desallocate.rb +37 -0
  102. data/lib/exec/cluster_info.rb +177 -0
  103. data/lib/exec/cluster_ls.rb +150 -0
  104. data/lib/exec/command_option.rb +222 -0
  105. data/lib/exec/executable_command.rb +194 -0
  106. data/lib/exec/node_destroy.rb +101 -0
  107. data/lib/exec/node_detach.rb +98 -0
  108. data/lib/exec/node_info.rb +280 -0
  109. data/lib/exec/node_install.rb +234 -0
  110. data/lib/exec/node_ls.rb +160 -0
  111. data/lib/exec/service_add.rb +224 -0
  112. data/lib/exec/service_component_add.rb +39 -0
  113. data/lib/exec/service_component_delete.rb +37 -0
  114. data/lib/exec/service_component_detach.rb +37 -0
  115. data/lib/exec/service_conf_apply.rb +57 -0
  116. data/lib/exec/service_conf_create.rb +80 -0
  117. data/lib/exec/service_conf_get.rb +165 -0
  118. data/lib/exec/service_conf_ls.rb +103 -0
  119. data/lib/exec/service_follow_request.rb +49 -0
  120. data/lib/exec/service_info.rb +346 -0
  121. data/lib/exec/service_install.rb +87 -0
  122. data/lib/exec/service_ls.rb +124 -0
  123. data/lib/exec/service_start.rb +110 -0
  124. data/lib/exec/service_stop.rb +112 -0
  125. data/lib/receiver.rb +14 -0
  126. data/lib/receiver/ambari_receiver.rb +812 -0
  127. data/lib/receiver/ambari_rest_api_connector.rb +599 -0
  128. data/lib/receiver/basic_receiver.rb +28 -0
  129. data/lib/receiver/connector.rb +28 -0
  130. data/lib/receiver/crowbar_receiver.rb +588 -0
  131. data/lib/receiver/crowbar_rest_api_connector.rb +518 -0
  132. data/lib/receiver/crowbar_shell_api.rb +643 -0
  133. data/lib/receiver/rest_api_connector.rb +275 -0
  134. data/resources/ambari-configurations/HBASE/default_hbase-site +33 -0
  135. data/resources/ambari-configurations/HDFS/default_hdfs-site +49 -0
  136. data/resources/ambari-configurations/HIVE/default_hive-site +33 -0
  137. data/resources/ambari-configurations/MAPREDUCE/default_mapred-site +72 -0
  138. data/resources/ambari-configurations/OOZIE/default_oozie-site +28 -0
  139. data/resources/ambari-configurations/WEBHCAT/default_webhcat-site +18 -0
  140. data/resources/ambari-configurations/ZOOKEEPER/default_zookeeper-site +8 -0
  141. data/resources/ambari-configurations/default_core-site +22 -0
  142. data/resources/ambari-configurations/default_global +141 -0
  143. data/resources/cloudbox-server.conf +10 -0
  144. data/spec/common/services_description.rb +130 -0
  145. data/spec/exec/check_parameter.rb +152 -0
  146. data/spec/exec/command_option_spec.rb +97 -0
  147. metadata +328 -0
@@ -0,0 +1,99 @@
1
+ # This file is part of cloudbox-server project
2
+ # Author: mbr (INGENSI)
3
+ # Created: 22/08/13 11:08
4
+
5
+ # You are a good developer if you document this class
6
+
7
+ require 'exec/executable_command'
8
+ require 'exec/check_parameter'
9
+ require 'common/cloudbox_exceptions'
10
+ require 'command/cluster_create'
11
+ require 'command/ambari_cluster_create'
12
+ require 'ipaddr'
13
+
14
+ include Exec::CheckParameter
15
+
16
+ module Exec
17
+ # Allows the user to create a cluster
18
+ class ClusterCreate < ExecutableCommand
19
+
20
+ attr_reader :network_address
21
+ attr_reader :vlan_id
22
+
23
+ public
24
+ # Default constructor of the class.
25
+ # @note Overrides default constructor by passing CustomCommandOption to super().
26
+ # @author mbretaud
27
+ def initialize(argv, stdin, stdout, stderr, command_name)
28
+ super(argv, stdin, stdout, stderr, command_name)
29
+ end
30
+
31
+ private
32
+ # Parse and check the parameters of the function.
33
+ # @author tnoguer
34
+ def set_options
35
+ @options.add_option("a", "address", "the adress Network and the cidr of the Cluster.", true, true, method(:check_network_address))
36
+ @options.add_option("C", "cluster", "The name of the vcluster .", true, true, method(:check_cluster_name))
37
+ @options.add_option("c", "cpu_weight", "CPU weight for each node in the virtual cluster .", false, true, method(:check_cpu_weight))
38
+ @options.add_option("d", "description", "Description of the cluster (put quotes).", false, true)
39
+ @options.add_option("i", "vlan_id", "Id VLAN.", false, true, method(:check_vlan_id))
40
+ @options.add_option("r", "ram", "Min ram assigned for each node in the virtual cluster.", false, true, method(:check_ram_size))
41
+ end
42
+
43
+ public
44
+ # The execution of the command.
45
+ # @author tnoguer
46
+ def exec
47
+ @logger.info("Exec::ClusterCreate Executing ClusterCreate")
48
+ @logger.info("Exec::ClusterCreate Create the vcluster '#{@values['cluster']}'...")
49
+ Color::print_log("NONE", "Create the vcluster '#{@values['cluster']}'...", @stdout)
50
+
51
+ default_cpu = 1024
52
+ default_ram= "1g"
53
+
54
+ cluster_name = @values['cluster']
55
+ @network_address = values['address']
56
+ address = @values['address'].split('/').first
57
+ cidr = @values['address'].split('/').last
58
+ if cidr == "8"
59
+ network_mask="255.0.0.0"
60
+ elsif cidr == "16"
61
+ network_mask="255.255.0.0"
62
+ else
63
+ network_mask="255.255.255.0"
64
+ end
65
+
66
+ if @values['cpu_weight'].nil?
67
+ cpu_weight = default_cpu
68
+ else
69
+ cpu_weight = @values['cpu_weight']
70
+ end
71
+
72
+ if @values['ram'].nil?
73
+ ram = default_ram
74
+ else
75
+ ram = @values['ram']
76
+ end
77
+
78
+ unless @values['vlan_id'].nil?
79
+ @vlan_id = values['vlan_id']
80
+ end
81
+
82
+ if @values['description'].nil?
83
+ description = ""
84
+ else
85
+ description = @values['description']
86
+ end
87
+
88
+ output = ""
89
+ cmd = Command::ClusterCreate.new(cluster_name, address, network_mask, cpu_weight, ram, @vlan_id, description)
90
+ output += cmd.exec()
91
+
92
+ cmd = Command::AmbariClusterCreate.new(cluster_name)
93
+ cmd.exec()
94
+
95
+ Color::echo_ok(@stdout)
96
+ @stdout.print output
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,38 @@
1
+ # This file is part of cloudbox-server project
2
+ # Author: mbr (INGENSI)
3
+ # Created: 22/08/13 11:08
4
+
5
+ require 'exec/executable_command'
6
+ require 'exec/check_parameter'
7
+ require 'common/cloudbox_exceptions'
8
+ require 'command/crowbar_node_command'
9
+
10
+ include Exec::CheckParameter
11
+
12
+ module Exec
13
+ # Allows the user to delete a cluster
14
+ class ClusterDelete < ExecutableCommand
15
+
16
+ private
17
+ # Parse and check the parameters of the function.
18
+ # @author tnoguer
19
+ def set_options
20
+ @options.add_option("C", "cluster", "The name of the vcluster .", true, true, method(:check_cluster_name))
21
+ end
22
+
23
+ # The execution of the command.
24
+ # @todo Implement ClusterDelete Exec body
25
+ # @author tnoguer
26
+ def exec
27
+ cluster_name = @values['cluster']
28
+
29
+ Color::print_log("NONE", "Delete the cluster '#{cluster_name}'...", @stdout)
30
+ Color::echo_fail(@stdout)
31
+
32
+ raise ClusterDeleteError.new("Not implemented command...")
33
+
34
+ #cmd = Command::ClusterDelete.new(cluster_name)
35
+ #cmd.exec()
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,37 @@
1
+ # This file is part of cloudbox-server project
2
+ # Author: mbr (INGENSI)
3
+ # Created: 22/08/13 11:08
4
+
5
+ # You are a good developer if you document this class
6
+
7
+ require 'exec/executable_command'
8
+ require 'exec/check_parameter'
9
+ require 'common/cloudbox_exceptions'
10
+ require 'command/crowbar_node_command'
11
+
12
+ include Exec::CheckParameter
13
+
14
+ module Exec
15
+ # Allows the user to desallocate a cluster
16
+ class ClusterDesallocate < ExecutableCommand
17
+
18
+ private
19
+ # Parse and check the parameters of the function.
20
+ # @author tnoguer
21
+ def set_options
22
+ @options.add_option("a", "all", "All nodes which are in the cluster .", false)
23
+ @options.add_option("C", "cluster_name", "The name of the vcluster .", true, true, method(:check_cluster_name))
24
+ @options.add_option("m", "node_name", "The list of nodes.", false, true, method(:check_crowbar_node_name))
25
+ end
26
+
27
+ # The execution of the command.
28
+ # @todo Implement ClusterDesallocate Exec body
29
+ # @author tnoguer
30
+ def exec
31
+ Color::print_log("NONE", "Desallocate cluster...", @stdout)
32
+ Color::echo_fail(@stdout)
33
+
34
+ raise ClusterDesallocateError.new("Not implemented command...")
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,177 @@
1
+ # This file is part of cloudbox-server project
2
+ # Author: mbr (INGENSI)
3
+ # Created: 22/08/13 11:08
4
+
5
+ # You are a good developer if you document this class
6
+
7
+ require 'exec/executable_command'
8
+ require 'exec/check_parameter'
9
+ require 'common/cloudbox_exceptions'
10
+ require 'command/crowbar_node_command'
11
+ require 'command/cluster_info'
12
+ require 'command/crowbar_get_barclamps_list'
13
+
14
+ include Exec::CheckParameter
15
+
16
+ module Exec
17
+ # Allows the user to display a information's cluster
18
+ class ClusterInfo < ExecutableCommand
19
+
20
+ public
21
+ # Default constructor of the class.
22
+ # @note Overrides default constructor by passing CustomCommandOption to super().
23
+ # @author mbretaud
24
+ def initialize(argv, stdin, stdout, stderr, command_name)
25
+ super(argv, stdin, stdout, stderr, command_name)
26
+ end
27
+
28
+ private
29
+ # Parse and check the parameters of the function.
30
+ # @author tnoguer
31
+ def set_options
32
+ @logger.info("Exec::ClusterInfo Setting options")
33
+ @options.add_option("C", "cluster", "The cluster name to display informations about.", true, true, method(:check_cluster_name))
34
+ end
35
+
36
+ # The execution of the command.
37
+ # @author tnoguer
38
+ def exec
39
+ @logger.info("Exec::ClusterInfo Executing ClusterInfo")
40
+ @logger.info("Exec::ClusterInfo Displays informations for the vcluster '#{@values['cluster']}'...")
41
+ Color::print_log("NONE", "Displays informations for the vcluster '#{@values['cluster']}'...", @stdout)
42
+
43
+ output = ""
44
+
45
+ cmd = Command::CrowbarGetBarclampsList.new(@logger)
46
+ p = cmd.exec()
47
+
48
+ barclamp_active = false
49
+ list_barclamps = Array.new
50
+ if p['i18n'] != nil
51
+ get_keys = p['i18n'].keys
52
+ get_keys.each{|e|
53
+ if p['i18n'][e]['proposal'] != nil && p['i18n'][e]['status'] != nil && p['i18n'][e]['status'] == "Active"
54
+ if e.include? "cb#{@values["cluster"]}"
55
+ barclamp_active = true
56
+ end
57
+ end
58
+ }
59
+ end
60
+
61
+ barclamp = "cb#{@values["cluster"]}"
62
+ role="#{barclamp}-server"
63
+ error="false"
64
+ output_error=""
65
+ output_machines=""
66
+
67
+ # Retrieves informations about the vcluster
68
+ cmd = Command::ClusterInfo.new(@values["cluster"], "default")
69
+ p = cmd.exec()
70
+
71
+ if p != nil
72
+ if p['deployment'][barclamp]['elements'][role] != nil
73
+ vcluster_exist="false"
74
+ p['deployment'][barclamp]['elements'][role].each do |machine|
75
+ ip_physique = `name_to_ip #{machine} > /dev/null 2>&1`
76
+ returnerr = $?
77
+ if returnerr == 0
78
+ ip_physique = `name_to_ip #{machine}`
79
+ machine2=`cat /etc/hosts | grep #{machine} | grep #{@values["cluster"]}- | awk '{ print $2 }'`
80
+ if machine2 == ""
81
+ output_error += "Error: The machine #{machine} doesn't exists in the file /etc/hosts" + "\n"
82
+ error="true"
83
+ else
84
+ subnet = p['attributes'][barclamp]['network']['address']
85
+ arraysubnet = Array.new
86
+ arraysubnet = subnet.scan(/[^\.]+/)
87
+ if p['attributes'][barclamp]['network']['mask']=="255.255.255.0"
88
+ lastip=ip_physique.split('.').last
89
+ arraysubnet[3]=lastip
90
+ ip_container=arraysubnet.join('.')
91
+ elsif p['attributes'][barclamp]['network']['mask']=="255.0.0.0"
92
+ lastip=ip_physique.split('.', 2).last
93
+ arraysubnet[1]=lastip
94
+ ip_container="#{arraysubnet[0]}.#{arraysubnet[1]}"
95
+ elsif p['attributes'][barclamp]['network']['mask']=="255.255.0.0"
96
+ lastip=ip_physique.split('.', 3).last
97
+ arraysubnet[2]=lastip
98
+ ip_container="#{arraysubnet[0]}.#{arraysubnet[1]}.#{arraysubnet[2]}"
99
+ end
100
+ if ip_physique != nil && ip_container != nil
101
+ output_machines += " -> " + machine2.strip + " " + ip_physique.strip + " " + ip_container.strip + "\n"
102
+ vcluster_exist="true"
103
+ else
104
+ output_error += " -> " + machine + " \"unknown ip: bad mask\"\n"
105
+ error="true"
106
+ end
107
+ end
108
+ else
109
+ output_error += " -> " + machine + " \"unknown ip: node not allocated\"\n"
110
+ error="true"
111
+ end
112
+ end
113
+ else
114
+ output_error += " Machines: no machine allocated\n"
115
+ error="true"
116
+ end
117
+
118
+ output += "Vcluster '#{@values["cluster"]}' informations:\n"
119
+ output += " Network address: " + p['attributes'][barclamp]['network']['address'] + "\n"
120
+ output += " Network mask: " + p['attributes'][barclamp]['network']['mask'] + "\n"
121
+ output += " Vlan ID: " + p['attributes'][barclamp]['network']['idvlan'] + "\n"
122
+ output += " Cpu weight: " + p['attributes'][barclamp]['resources']['cpu'] + "\n"
123
+ output += " Ram allowed: " + p['attributes'][barclamp]['resources']['ram'] + "\n"
124
+ output += " Description: " + p['description'] + "\n"
125
+ output += " Machines: hostname | ip_physique | ip_container \n"
126
+
127
+ if barclamp_active == false
128
+ Color::echo_warn(@stdout)
129
+ @stdout.print output
130
+ @stdout.print "\n"
131
+ #@stdout.print "The barclamp 'cb#{@values["cluster"]}' is not Active.\n"
132
+ Color::printf_red("The barclamp 'cb#{@values["cluster"]}' is not Active.\n")
133
+ error = "true"
134
+ else
135
+ if error == "true"
136
+ Color::echo_warn(@stdout)
137
+ @stdout.print output
138
+ @stdout.print "\n"
139
+ #@stdout.print output_error
140
+ Color::printf_red("#{output_error}")
141
+ else
142
+ if "#{vcluster_exist}" == "false"
143
+ Color::echo_warn(@stdout)
144
+ @stdout.print output
145
+ @stdout.print "\n"
146
+ #@stdout.print "No machines are allocated to the vcluster '" + @values["cluster"] + "'\n"
147
+ Color::printf_red("No machines are allocated to the vcluster '#{@values["cluster"]}'.\n")
148
+ error = "true"
149
+ end
150
+ end
151
+ end
152
+ else
153
+ Color::echo_warn(@stdout)
154
+ @stdout.print output
155
+ @stdout.print "\n"
156
+ #@stdout.print "The cluster '#{@values["cluster"]}' doesn't exists.\n"
157
+ Color::printf_red("The cluster '#{@values["cluster"]}' doesn't exists.\n")
158
+ error = "true"
159
+ end
160
+
161
+ if error == "false"
162
+ Color::echo_ok(@stdout)
163
+ @logger.info(output)
164
+ if !output.empty?
165
+ @stdout.print output
166
+ @stdout.print "\n"
167
+ @stdout.print output_machines
168
+ @stdout.print "\n"
169
+ else
170
+ @logger.info("Exec::ClusterLs No vclusters available!")
171
+ #@stdout.print "No vclusters available!\n"
172
+ Color::printf_red("No vclusters available!\n")
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,150 @@
1
+ # This file is part of cloudbox-server project
2
+ # Author: mbr (INGENSI)
3
+ # Created: 22/08/13 11:08
4
+
5
+ # You are a good developer if you document this class
6
+
7
+ require 'exec/executable_command'
8
+ require 'exec/check_parameter'
9
+ require 'common/cloudbox_exceptions'
10
+ require 'command/crowbar_node_command'
11
+ require 'command/cluster_ls'
12
+
13
+ include Exec::CheckParameter
14
+
15
+ module Exec
16
+ # Allows user to list a cluster
17
+ class ClusterLs < ExecutableCommand
18
+
19
+ public
20
+ # Default constructor of the class.
21
+ # @note Overrides default constructor by passing CustomCommandOption to super().
22
+ # @author mbretaud
23
+ def initialize(argv, stdin, stdout, stderr, command_name)
24
+ super(argv, stdin, stdout, stderr, command_name)
25
+ end
26
+
27
+ private
28
+ # Parse and check the parameters of the function.
29
+ # @author tnoguer
30
+ def set_options
31
+ @options.add_option("C", "cluster", "Displays informations about a Cluster.", false, true, method(:check_cluster_name))
32
+ end
33
+
34
+ # The execution of the command.
35
+ # @author tnoguer
36
+ def exec
37
+ @logger.info("Exec::ClusterLs Executing ClusterLs")
38
+ output = ""
39
+
40
+ ### Displays only vclusters ###
41
+ if !@values['cluster']
42
+ @logger.info("Exec::ClusterLs Displays vclusters into the bash screen...")
43
+ Color::print_log("NONE", "Display vclusters into the bash screen...", @stdout)
44
+
45
+ begin
46
+ # Getting vclusters list
47
+ list_clusters = Dir["/opt/dell/barclamps/cb*"]
48
+ list_clusters_to_diplay = Array.new
49
+ rescue => e
50
+ raise ClusterLsError.new("Retrieves the list of vclusters.")
51
+ end
52
+
53
+ begin
54
+ # Displays of the vclusters list
55
+ list_clusters.each { |dir|
56
+ if File::directory?(dir)
57
+ cluster = File.basename(dir)
58
+ list_clusters_to_diplay.<< " - #{cluster[2..-1]}\n"
59
+ end
60
+ }
61
+
62
+ unless list_clusters_to_diplay.empty?
63
+ output += "\n"
64
+ output += display_list(list_clusters_to_diplay)
65
+ output += "\n"
66
+ end
67
+ rescue => e
68
+ raise ClusterLsError.new("Displays the list of vclusters.")
69
+ end
70
+
71
+ Color::echo_ok(@stdout)
72
+ @logger.info(output)
73
+ if !output.empty?
74
+ @stdout.print output
75
+ else
76
+ raise ClusterLsError.new("No vclusters available.")
77
+ end
78
+ end
79
+
80
+ ### Displays machines associated with the vcluster ###
81
+ if @values['cluster']
82
+ @logger.info("Exec::ClusterLs Displays machines associated with the vcluster '#{@values['cluster']}' into the bash screen...")
83
+ Color::print_log("NONE", "Displays machines associated with the vcluster '#{@values['cluster']}' into the bash screen...", @stdout)
84
+
85
+ cluster_name = @values['cluster']
86
+ barclamp = "cb#{cluster_name}"
87
+ proposal_name = "default"
88
+ role = "#{barclamp}-server"
89
+
90
+ # Retrieves informations about the vcluster
91
+ cmd = Command::ClusterInfo.new(cluster_name, proposal_name)
92
+ p = cmd.exec()
93
+
94
+ error = "false"
95
+ out_error = ""
96
+
97
+ # Displays the list of machines on the vclusters associated
98
+ list_machines_to_display = Array.new
99
+
100
+ if p['deployment'][barclamp] != nil
101
+ if p['deployment'][barclamp]['elements'][role] != nil
102
+ p['deployment'][barclamp]['elements'][role].each do |machine|
103
+ machine2=`cat /etc/hosts | grep #{machine} | grep #{cluster_name} | awk '{ print $2 }'`
104
+ if machine2 == ""
105
+ out_error=out_error + "Error: The machine #{machine} doesn't exists in the file /etc/hosts" + "\n"
106
+ else
107
+ list_machines_to_display.<< " - #{cluster_name}-#{machine}\n"
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ if error == "true"
114
+ raise ClusterLsError.new(out_error)
115
+ elsif !list_machines_to_display.empty?
116
+ output += "\n"
117
+ output += display_list(list_machines_to_display)
118
+ output += "\n"
119
+ elsif list_machines_to_display.empty?
120
+ raise ClusterLsError.new("No machines are allocated to the vcluster '#{cluster_name}'.")
121
+ end
122
+
123
+ Color::echo_ok(@stdout)
124
+ @logger.info(output)
125
+ if !output.empty?
126
+ @stdout.print output
127
+ else
128
+ @logger.info("Exec::ClusterLs No vclusters available.")
129
+ @stdout.print "No vclusters available.\n"
130
+ end
131
+ end
132
+ end
133
+
134
+ private
135
+ # Displays the elements of the list
136
+ # @param list The list of elements
137
+ # @author mbretaud
138
+ def display_list(list)
139
+ output = ""
140
+ begin
141
+ list.sort.each { |element|
142
+ output += element
143
+ }
144
+ rescue
145
+ output += "Error: Displays the element of the list.\n"
146
+ end
147
+ return output
148
+ end
149
+ end
150
+ end