Class: Fhcap::Tasks::Provider::Add
- Defined in:
- lib/fhcap/tasks/provider/add.rb
Constant Summary collapse
- AWS_REQUIRED_CREDENTIALS =
%w{aws-access-key aws-secret-key}
- OS_REQUIRED_CREDENTIALS =
%w{os-auth-url os-tenant-id os-tenant-name os-username os-password}
- DNSMADEEASY_REQUIRED_CREDENTIALS =
%w{api-key secret-key}
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from TaskBase
#config, #options, #thor, #verbose
Instance Method Summary collapse
-
#initialize(options) ⇒ Add
constructor
A new instance of Add.
- #run ⇒ 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, #knife_config, #knife_config_dir, #knife_config_file_for
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
Constructor Details
#initialize(options) ⇒ Add
Returns a new instance of Add.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fhcap/tasks/provider/add.rb', line 15 def initialize() super @name = [:name] @type = [:type] @credentials = [:credentials] || {} if [:type] == 'aws' @required_credentials = AWS_REQUIRED_CREDENTIALS elsif [:type] == 'openstack' @required_credentials = OS_REQUIRED_CREDENTIALS elsif [:type] == 'dnsmadeeasy' @required_credentials = DNSMADEEASY_REQUIRED_CREDENTIALS end end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
9 10 11 |
# File 'lib/fhcap/tasks/provider/add.rb', line 9 def credentials @credentials end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/fhcap/tasks/provider/add.rb', line 9 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/fhcap/tasks/provider/add.rb', line 9 def type @type end |
Instance Method Details
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fhcap/tasks/provider/add.rb', line 29 def run thor.say "Provider::Add: name = #{name}, type = #{type}", :yellow config[:providers] = {} unless config[:providers] config[:providers][type.to_sym] = {} unless config[:providers][type.to_sym] config[:providers][type.to_sym][name.to_sym] = {} unless config[:providers][type.to_sym][name.to_sym] @provider_config = config[:providers][type.to_sym][name.to_sym] @provider_config[:provides] = [] unless @provider_config[:provides] @provider_config[:credentials] = {} unless @provider_config[:credentials] @provider_config[:credentials].merge!(credentials) @required_credentials.each do |rc| if !@provider_config[:credentials][rc.to_sym] || [:interactive] default = @provider_config[:credentials][rc.to_sym] || ENV[rc.to_s.upcase.gsub('-', '_')] @provider_config[:credentials][rc.to_sym] = thor.ask "#{rc}:", {default: default} end end send(:"#{type}_config", @provider_config) thor.create_file(config.default_config_file, JSON.pretty_generate(config.data), :force => true) config.reload end |