Class: Fhcap::Tasks::Cluster::Info

Inherits:
ClusterTaskBase show all
Defined in:
lib/fhcap/tasks/cluster/info.rb

Instance Attribute Summary collapse

Attributes inherited from ClusterTaskBase

#cluster_config, #cluster_file, #name

Attributes inherited from TaskBase

#config, #options, #thor, #verbose

Instance Method Summary collapse

Methods inherited from ClusterTaskBase

#checkout_repos, #chef_task_options, #template_as_object

Methods inherited from TaskBase

#ask_config, #color_pad, #exit_with_error, #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

#initialize(options) ⇒ Info

Returns a new instance of Info.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fhcap/tasks/cluster/info.rb', line 12

def initialize(options)
  super
  @launch = options[:launch]
  @format = options[:format]
  unless @cluster_passwords
    @cluster_passwords = {}
    cluster_environments.each do |env|
      @cluster_passwords[env.to_sym] = {}
      @cluster_pwds_file = find_cluster_pwds(env)
      if @cluster_pwds_file
        @cluster_passwords[env.to_sym] = JSON.parse(IO.read(@cluster_pwds_file), {:symbolize_names => true})
      end
    end
  end
end

Instance Attribute Details

#cluster_passwordsObject (readonly)

Returns the value of attribute cluster_passwords.



10
11
12
# File 'lib/fhcap/tasks/cluster/info.rb', line 10

def cluster_passwords
  @cluster_passwords
end

#cluster_pwds_fileObject (readonly)

Returns the value of attribute cluster_pwds_file.



10
11
12
# File 'lib/fhcap/tasks/cluster/info.rb', line 10

def cluster_pwds_file
  @cluster_pwds_file
end

#formatObject (readonly)

Returns the value of attribute format.



10
11
12
# File 'lib/fhcap/tasks/cluster/info.rb', line 10

def format
  @format
end

#launchObject (readonly)

Returns the value of attribute launch.



10
11
12
# File 'lib/fhcap/tasks/cluster/info.rb', line 10

def launch
  @launch
end

Instance Method Details

#runObject



28
29
30
31
32
33
34
35
36
37
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
# File 'lib/fhcap/tasks/cluster/info.rb', line 28

def run
  suppress_stdout(print_json?) do
    thor.say "Cluster::Info: name = #{@name}", :yellow
    @cluster_data = {
        meta: {
            name: @name,
            template: cluster_config[:template],
            driver: cluster_config[:driver],
            domain: cluster_config[:domain],
            repo: cluster_config[:repo],
            chef_server: cluster_config[:chef_server],
            provider_id: cluster_config[:provider_id],
            file: cluster_file
        }
    }

    unless options[:only] && ([options[:only]] & %w{ips urls passwords}).empty?
      info_task = Chef::Server::Info.new(@options.dup.merge({:environments => cluster_environments}.merge(chef_task_options)))
      info_task.run
      @cluster_data[:environments] = info_task.cluster_data
      cluster_environments.each do |env|
        passwords(env, @cluster_data)
      end unless options[:only] && options[:only] != 'passwords'
    end

  end

  if launch && !print_json?
    info_task.urls.each do |env, urls|
      urls.each do |service, url|
        service = service.to_s
        if %w{nagios munin}.include? service
          user = 'team.eng'
          pwd = cluster_passwords[env.to_sym][:'henry_users.teameng']
          if user and pwd
            proto, host = url.split('://')
            url = "#{proto}://#{user}:#{pwd}@#{host}"
          end
        end
        thor.say_status 'launch', url
        Launchy.open(url)
      end
    end
  end

  thor.say JSON.pretty_generate(@cluster_data) if print_json?
end