Class: Utils
- Inherits:
-
Object
- Object
- Utils
- Defined in:
- lib/vmfloaty/utils.rb
Class Method Summary collapse
-
.format_hosts(hostname_hash) ⇒ Object
TODO: Takes the json response body from an HTTP GET request and “pretty prints” it.
- .generate_os_hash(os_args) ⇒ Object
- .get_vm_info(hosts, verbose, url) ⇒ Object
- .prettyprint_hosts(hosts, verbose, url) ⇒ Object
Class Method Details
.format_hosts(hostname_hash) ⇒ Object
TODO: Takes the json response body from an HTTP GET request and “pretty prints” it
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vmfloaty/utils.rb', line 7 def self.format_hosts(hostname_hash) host_hash = {} hostname_hash.delete("ok") hostname_hash.each do |type, hosts| if type == "domain" host_hash[type] = hosts else host_hash[type] = hosts["hostname"] end end host_hash.to_json end |
.generate_os_hash(os_args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vmfloaty/utils.rb', line 22 def self.generate_os_hash(os_args) # expects args to look like: # ["centos", "debian=5", "windows=1"] # Build vm hash where # # [operating_system_type1 -> total, # operating_system_type2 -> total, # ...] os_types = {} os_args.each do |arg| os_arr = arg.split("=") if os_arr.size == 1 # assume they didn't specify an = sign if split returns 1 size os_types[os_arr[0]] = 1 else os_types[os_arr[0]] = os_arr[1].to_i end end os_types end |
.get_vm_info(hosts, verbose, url) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vmfloaty/utils.rb', line 44 def self.get_vm_info(hosts, verbose, url) vms = {} hosts.each do |host| vm_info = Pooler.query(verbose, url, host) if vm_info['ok'] vms[host] = {} vms[host]['domain'] = vm_info[host]['domain'] vms[host]['template'] = vm_info[host]['template'] vms[host]['lifetime'] = vm_info[host]['lifetime'] vms[host]['running'] = vm_info[host]['running'] end end vms end |
.prettyprint_hosts(hosts, verbose, url) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vmfloaty/utils.rb', line 59 def self.prettyprint_hosts(hosts, verbose, url) puts "Running VMs:" vm_info = get_vm_info(hosts, verbose, url) vm_info.each do |vm,info| domain = info['domain'] template = info['template'] lifetime = info['lifetime'] running = info['running'] puts "- #{vm}.#{domain} (#{template}, #{running}/#{lifetime} hours)" end end |