Class: Fhcap::Tasks::Knife::Add

Inherits:
TaskBase
  • Object
show all
Defined in:
lib/fhcap/tasks/knife/add.rb

Instance Attribute Summary collapse

Attributes inherited from TaskBase

#config, #options, #thor, #verbose

Instance Method Summary collapse

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_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_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 FhcapHelper

#cluster_template_names

Constructor Details

#initialize(options) ⇒ Add

Returns a new instance of Add.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fhcap/tasks/knife/add.rb', line 12

def initialize(options)
  super
  @name = options[:name]
  @chef_server_url = options[:url]
  @node_name = options[:'node-name'] || Etc.getlogin
  @validation_client_name = options[:'validation-client-name'] || 'chef-validator'
  @import_file = options[:'import-file']
  @private_key = nil
  @validation_key = nil

  if @import_file
    import_cfg = JSON.parse(IO.read(@import_file), {:symbolize_names => true})
    @name = import_cfg[:name] || @name
    @chef_server_url = import_cfg[:chef_server_url]
    @node_name = import_cfg[:node_name]
    @validation_client_name = import_cfg[:validation_client_name]
    @private_key = import_cfg[:private_key]
    @validation_key = import_cfg[:validation_key]
  end

  @knife_config = config[:knife][@name.to_sym] || {}
  @knife_config = {
      chef_server_url: @chef_server_url,
      node_name: @node_name,
      validation_client_name: @validation_client_name,
  }.merge(@knife_config)

end

Instance Attribute Details

#import_fileObject (readonly)

Returns the value of attribute import_file.



10
11
12
# File 'lib/fhcap/tasks/knife/add.rb', line 10

def import_file
  @import_file
end

#knife_configObject (readonly)

Returns the value of attribute knife_config.



10
11
12
# File 'lib/fhcap/tasks/knife/add.rb', line 10

def knife_config
  @knife_config
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/fhcap/tasks/knife/add.rb', line 10

def name
  @name
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



10
11
12
# File 'lib/fhcap/tasks/knife/add.rb', line 10

def private_key
  @private_key
end

#validation_keyObject (readonly)

Returns the value of attribute validation_key.



10
11
12
# File 'lib/fhcap/tasks/knife/add.rb', line 10

def validation_key
  @validation_key
end

Instance Method Details

#runObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fhcap/tasks/knife/add.rb', line 41

def run
  thor.say "Knife::Add: name = #{name}", :yellow

  ask_config(required_config, @knife_config)

  config[:knife][name.to_sym] = @knife_config

  thor.create_file(config.default_config_file, JSON.pretty_generate(config.data), :force => true)
  config.reload
  create_knife_config
end