Class: Chef::Knife::VsphereCpuRatio
- Inherits:
-
BaseVsphereCommand
- Object
- Chef::Knife
- BaseVsphereCommand
- Chef::Knife::VsphereCpuRatio
- Defined in:
- lib/chef/knife/vsphere_cpu_ratio.rb
Instance Method Summary collapse
Methods inherited from BaseVsphereCommand
#choose_datastore, common_options, #datacenter, #fatal_exit, #find_all_in_folder, #find_datastore, #find_datastorecluster, #find_datastores_regex, #find_device, #find_folder, #find_in_folder, #find_network, #find_pool, #get_config, #get_path_to_object, #get_vm, #get_vms, #linux?, #password, #tcp_test_port, #tcp_test_port_vm, #traverse_folders_for_computeresources, #traverse_folders_for_dc, #traverse_folders_for_vm, #traverse_folders_for_vms, #vim_connection, #windows?
Methods inherited from Chef::Knife
Instance Method Details
#run ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/chef/knife/vsphere_cpu_ratio.rb', line 9 def run $stdout.sync = true cluster_name = @name_args[0] host_name = @name_args[1] vim_connection dc = datacenter hf = dc.hostFolder cluster = cluster_name.nil? ? hf.childEntity : hf.childEntity.select { |c| c.name == cluster_name } fatal_exit("Cluster #{cluster_name} not found.") if cluster.empty? cluster.each do |c| host = host_name.nil? ? c.host : c.host.select { |h| h.name == host_name } fatal_exit("Host not found in cluster #{c.name}.") if host.empty? puts "### Cluster #{c.name} ###" host.each do |h| v_cpu = h.vm.inject(0) { |a, e| a + e.config.hardware.numCPU } p_cpu = h.summary.hardware.numCpuThreads ratio = 1.0 * v_cpu / p_cpu puts "#{h.name}: #{ratio}" end puts '' end end |