Class: Fhcap::Tasks::Cluster::List

Inherits:
TaskBase
  • Object
show all
Defined in:
lib/fhcap/tasks/cluster/list.rb

Instance Attribute Summary

Attributes inherited from TaskBase

#config, #options, #thor, #verbose

Instance Method Summary collapse

Methods inherited from TaskBase

#ask_config, #color_pad, #exit_with_error, #initialize, #set_color, #suppress_stdout, #table_header, #table_row, #with_progress

Methods included from KnifeHelper

#chef_server_config_for, #chef_server_config_hash_for, #chef_server_names, #delete_chef_object, #knife_config, #knife_config_dir, #knife_config_file_for, #knife_data_bag_delete, #knife_download, #knife_environment_delete, #knife_upload, #local_chef_server?, #with_chef_server, #with_local_chef_server

Methods included from ProvidersHelper

#provider_availability_zones, #provider_config, #provider_credentials, #provider_for, #provider_names, #provider_names_for, #provider_regions, #provider_type, #providers_config

Methods included from ReposHelper

#find_cluster, #find_cluster_pwds, #find_cluster_pwds_with_repo, #find_cluster_with_repo, #find_data_bag, #find_data_bag_item, #find_environment, #find_repo_item, #find_role, #get_cookbook_deps, #get_cookbook_meta, #get_cookbook_versions, #get_cookbooks, #get_dirty_cookbooks, #get_entry_dependencies, #get_modified_cookbooks, #git_diff, #is_dirty?, #modified?, #repo_cfg, #repo_clusters_dir, #repo_cookbook_paths, #repo_dir, #repo_names, #repo_paths, #repos_config, #repos_dir, #run_inside_repo_dir

Methods included from FhcapHelper

#cluster_template_names

Constructor Details

This class inherits a constructor from Fhcap::Tasks::TaskBase

Instance Method Details

#runObject



8
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
# File 'lib/fhcap/tasks/cluster/list.rb', line 8

def run
  thor.say "Cluster::List", :yellow

  table_contents = [table_header('Name', 'Repo', 'Template', 'Driver', 'Chef Server', 'Provider ID', 'Environments', 'Domains', 'No. Instances')]

  repos_config.each do |repo_name, cfg|
    clusters_dir = File.join(repo_dir(repo_name), repo_clusters_dir(repo_name))
    if Dir.exists?(clusters_dir)
      Dir.glob("#{clusters_dir}/*.json").reject { |f| f =~ /passwords/ }.each do |json_file|
        conf = JSON.parse(IO.read(json_file), {:symbolize_names => true})
        environments = {}
        if conf[:environments]
          conf[:environments].each do |env_name, env_cfg|
            env_name = [conf[:id].to_s, env_name.to_s].uniq.join('-')
            environments[env_name] = {}
            environments[env_name][:domain] = env_cfg[:domain]
            environments[env_name][:instances] = (env_cfg[:instances] || {}).keys.collect { |e| "#{env_name}-#{e}" }
          end
        end
        environment_names = environments.keys.join(',')
        domain_names = environments.values.collect { |env| env[:domain] }.compact.join(',')
        instance_names = environments.values.collect { |env| env[:instances] }.flatten
        table_contents << table_row(conf[:id], conf[:repo], conf[:template], conf[:driver], conf[:chef_server], conf[:provider_id], environment_names, domain_names, instance_names.count)
      end
    end
  end
  thor.print_table table_contents
end