Class: Fhcap::ThorBase

Inherits:
Thor
  • Object
show all
Includes:
ProvidersHelper, ReposHelper, Thor::Actions
Defined in:
lib/fhcap/thor_base.rb

Constant Summary collapse

@@shared_options =
{}
@@fhcap_config =
Fhcap::Config.new(
    :config_file => ENV['FHCAP_CFG_FILE']
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_entry_dependencies, #get_modified_cookbooks, #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 ProvidersHelper

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

Constructor Details

#initialize(*args) ⇒ ThorBase

Returns a new instance of ThorBase.



90
91
92
93
94
95
96
97
98
# File 'lib/fhcap/thor_base.rb', line 90

def initialize(*args)
  super
  self.class.source_root(Fhcap.source_root)
  #$stdout.sync = true
  @config = Fhcap::Config.new(
      :config_file => ENV['FHCAP_CFG_FILE']
  )
  @thor = self
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/fhcap/thor_base.rb', line 11

def config
  @config
end

#thorObject (readonly)

Returns the value of attribute thor.



11
12
13
# File 'lib/fhcap/thor_base.rb', line 11

def thor
  @thor
end

Class Method Details

.add_shared_option(name, options = {}) ⇒ Object



19
20
21
# File 'lib/fhcap/thor_base.rb', line 19

def add_shared_option(name, options = {})
  @@shared_options[name] = options
end

.chef_server_namesObject



63
64
65
# File 'lib/fhcap/thor_base.rb', line 63

def chef_server_names
  config_key_collection(:knife)
end

.cluster_template_namesObject



71
72
73
# File 'lib/fhcap/thor_base.rb', line 71

def cluster_template_names
  Fhcap::TEMPLATE_NAMES
end

.config_key_collection(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fhcap/thor_base.rb', line 31

def config_key_collection(name)
  if @@fhcap_config.exists? && @@fhcap_config[name.to_sym]
    @@fhcap_config[name.to_sym].collect do |key, val|
      if block_given?
        yield key.to_s, val
      else
        key.to_s
      end
    end
  else
    []
  end
end

.provider_namesObject



45
46
47
48
49
50
51
# File 'lib/fhcap/thor_base.rb', line 45

def provider_names
  config_key_collection(:providers) do |provider, cfg|
    cfg.collect do |id, pcfg|
      "#{provider}:#{id}"
    end
  end.flatten
end

.provider_names_for(service) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/fhcap/thor_base.rb', line 53

def provider_names_for(service)
  config_key_collection(:providers) do |provider, cfg|
    cfg.reject do |id, pcfg|
      !pcfg[:provides] || !pcfg[:provides].include?(service)
    end.collect do |id, pcfg|
      "#{provider}:#{id}"
    end
  end.flatten
end

.repo_namesObject



67
68
69
# File 'lib/fhcap/thor_base.rb', line 67

def repo_names
  config_key_collection(:repos)
end

.run_cmd(cmd, options) ⇒ Object



80
81
82
# File 'lib/fhcap/thor_base.rb', line 80

def run_cmd(cmd, options)
  run(cmd)
end

.run_knife_cmd(cmd, options) ⇒ Object



75
76
77
78
# File 'lib/fhcap/thor_base.rb', line 75

def run_knife_cmd(cmd, options)
  cmd = (['knife', cmd]).join(' ')
  run_cmd(cmd, options)
end

.shared_options(*option_names) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/fhcap/thor_base.rb', line 23

def shared_options(*option_names)
  option_names.each do |option_name|
    opt = @@shared_options[option_name]
    raise "Tried to access shared option '#{option_name}' but it was not previously defined" if opt.nil?
    option option_name, opt
  end
end