Class: Exec::ClusterInfo
- Inherits:
-
ExecutableCommand
- Object
- ExecutableCommand
- Exec::ClusterInfo
- Defined in:
- lib/exec/cluster_info.rb
Overview
Allows the user to display a information’s cluster
Instance Attribute Summary
Attributes inherited from ExecutableCommand
#argv, #command_name, #logger, #options, #stderr, #stdin, #stdout, #values
Instance Method Summary collapse
-
#exec ⇒ Object
private
The execution of the command.
-
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ ClusterInfo
constructor
Default constructor of the class.
-
#set_options ⇒ Object
private
Parse and check the parameters of the function.
Methods inherited from ExecutableCommand
#check_parameters, #create_logger, #run
Constructor Details
#initialize(argv, stdin, stdout, stderr, command_name) ⇒ ClusterInfo
Note:
Overrides default constructor by passing CustomCommandOption to super().
Default constructor of the class.
24 25 26 |
# File 'lib/exec/cluster_info.rb', line 24 def initialize(argv, stdin, stdout, stderr, command_name) super(argv, stdin, stdout, stderr, command_name) end |
Instance Method Details
#exec ⇒ Object (private)
The execution of the command.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/exec/cluster_info.rb', line 38 def exec @logger.info("Exec::ClusterInfo Executing ClusterInfo") @logger.info("Exec::ClusterInfo Displays informations for the vcluster '#{@values['cluster']}'...") Color::print_log("NONE", "Displays informations for the vcluster '#{@values['cluster']}'...", @stdout) output = "" cmd = Command::CrowbarGetBarclampsList.new(@logger) p = cmd.exec() = false = Array.new if p['i18n'] != nil get_keys = p['i18n'].keys get_keys.each{|e| if p['i18n'][e]['proposal'] != nil && p['i18n'][e]['status'] != nil && p['i18n'][e]['status'] == "Active" if e.include? "cb#{@values["cluster"]}" = true end end } end = "cb#{@values["cluster"]}" role="#{}-server" error="false" output_error="" output_machines="" # Retrieves informations about the vcluster cmd = Command::ClusterInfo.new(@values["cluster"], "default") p = cmd.exec() if p != nil if p['deployment'][]['elements'][role] != nil vcluster_exist="false" p['deployment'][]['elements'][role].each do |machine| ip_physique = `name_to_ip #{machine} > /dev/null 2>&1` returnerr = $? if returnerr == 0 ip_physique = `name_to_ip #{machine}` machine2=`cat /etc/hosts | grep #{machine} | grep #{@values["cluster"]}- | awk '{ print $2 }'` if machine2 == "" output_error += "Error: The machine #{machine} doesn't exists in the file /etc/hosts" + "\n" error="true" else subnet = p['attributes'][]['network']['address'] arraysubnet = Array.new arraysubnet = subnet.scan(/[^\.]+/) if p['attributes'][]['network']['mask']=="255.255.255.0" lastip=ip_physique.split('.').last arraysubnet[3]=lastip ip_container=arraysubnet.join('.') elsif p['attributes'][]['network']['mask']=="255.0.0.0" lastip=ip_physique.split('.', 2).last arraysubnet[1]=lastip ip_container="#{arraysubnet[0]}.#{arraysubnet[1]}" elsif p['attributes'][]['network']['mask']=="255.255.0.0" lastip=ip_physique.split('.', 3).last arraysubnet[2]=lastip ip_container="#{arraysubnet[0]}.#{arraysubnet[1]}.#{arraysubnet[2]}" end if ip_physique != nil && ip_container != nil output_machines += " -> " + machine2.strip + " " + ip_physique.strip + " " + ip_container.strip + "\n" vcluster_exist="true" else output_error += " -> " + machine + " \"unknown ip: bad mask\"\n" error="true" end end else output_error += " -> " + machine + " \"unknown ip: node not allocated\"\n" error="true" end end else output_error += " Machines: no machine allocated\n" error="true" end output += "Vcluster '#{@values["cluster"]}' informations:\n" output += " Network address: " + p['attributes'][]['network']['address'] + "\n" output += " Network mask: " + p['attributes'][]['network']['mask'] + "\n" output += " Vlan ID: " + p['attributes'][]['network']['idvlan'] + "\n" output += " Cpu weight: " + p['attributes'][]['resources']['cpu'] + "\n" output += " Ram allowed: " + p['attributes'][]['resources']['ram'] + "\n" output += " Description: " + p['description'] + "\n" output += " Machines: hostname | ip_physique | ip_container \n" if == false Color::echo_warn(@stdout) @stdout.print output @stdout.print "\n" #@stdout.print "The barclamp 'cb#{@values["cluster"]}' is not Active.\n" Color::printf_red("The barclamp 'cb#{@values["cluster"]}' is not Active.\n") error = "true" else if error == "true" Color::echo_warn(@stdout) @stdout.print output @stdout.print "\n" #@stdout.print output_error Color::printf_red("#{output_error}") else if "#{vcluster_exist}" == "false" Color::echo_warn(@stdout) @stdout.print output @stdout.print "\n" #@stdout.print "No machines are allocated to the vcluster '" + @values["cluster"] + "'\n" Color::printf_red("No machines are allocated to the vcluster '#{@values["cluster"]}'.\n") error = "true" end end end else Color::echo_warn(@stdout) @stdout.print output @stdout.print "\n" #@stdout.print "The cluster '#{@values["cluster"]}' doesn't exists.\n" Color::printf_red("The cluster '#{@values["cluster"]}' doesn't exists.\n") error = "true" end if error == "false" Color::echo_ok(@stdout) @logger.info(output) if !output.empty? @stdout.print output @stdout.print "\n" @stdout.print output_machines @stdout.print "\n" else @logger.info("Exec::ClusterLs No vclusters available!") #@stdout.print "No vclusters available!\n" Color::printf_red("No vclusters available!\n") end end end |
#set_options ⇒ Object (private)
Parse and check the parameters of the function.
31 32 33 34 |
# File 'lib/exec/cluster_info.rb', line 31 def @logger.info("Exec::ClusterInfo Setting options") @options.add_option("C", "cluster", "The cluster name to display informations about.", true, true, method(:check_cluster_name)) end |