class Chef::Knife::CloudstackTemplateList
Public Instance Methods
print_templates(template_list,templates,options={})
click to toggle source
# File lib/chef/knife/cloudstack_template_list.rb, line 55 def print_templates(template_list,templates,options={}) temp = templates if templateid = options[:templateid] temp.reject!{|t| t['id'] != templateid} end if zoneid = options[:zoneid] temp.reject!{|t| t['zoneid'] != zoneid} end if zone = options[:zone] temp.reject!{|t| t['zonename'] != zone} end if hypervisor = options[:hypervisor] temp.reject!{|t| t['hypervisor'] != hypervisor} end # Sorting to group by zone ID first, then ID sort1 = temp.sort_by { |hsh| hsh["id"] } sorted = sort1.sort_by { |hsh| hsh["zoneid"] } sorted.each do |template| template_list << template['id'].to_s template['hypervisor'] = ' ' if template['hypervisor'].nil? template_list << template['hypervisor'] template_size = template['size'].to_i template_size = template_size / 1024 / 1024 / 1024 template_list << template_size.to_s template_list << template['zonename'] template_list << template['zoneid'].to_s template_list << template['name'] end end
run()
click to toggle source
# File lib/chef/knife/cloudstack_template_list.rb, line 91 def run validate! template_list = [ ui.color('ID', :bold), ui.color('Hypervisor', :bold), ui.color('Size (in GB)', :bold), ui.color('Zone Name', :bold), ui.color('Zone ID', :bold), ui.color('Name', :bold) ] filter = locate_config_value(:filter) zone = locate_config_value(:zone) zoneid = locate_config_value(:zoneid) hypervisor = locate_config_value(:hypervisor) templateid = locate_config_value(:templateid) settings = connection.list_templates(filter) if response = settings['listtemplatesresponse'] Chef::Log.debug("Response: #{response}") if templates = response['template'] filters = {} filters[:hypervisor] = hypervisor unless hypervisor == 'all' filters[:zone] = zone unless zone == 'all' filters[:zoneid] = zoneid unless zoneid == 'all' filters[:templateid] = templateid unless templateid == 'all' print_templates(template_list,templates,filters) end puts ui.list(template_list, :uneven_columns_across, 6) end end