Class: DTK::Client::Provider
- Inherits:
-
CommandBaseThor
- Object
- Thor
- CommandBaseThor
- DTK::Client::Provider
- Defined in:
- lib/commands/thor/provider.rb
Constant Summary
Constants inherited from CommandBaseThor
CommandBaseThor::ALT_IDENTIFIER_SEPARATOR, CommandBaseThor::EXTENDED_TIMEOUT, CommandBaseThor::HIDE_FROM_BASE_CONTEXT, CommandBaseThor::TIME_DIFF
Constants included from CommandHelperMixin
Constants included from ReparseMixin
ReparseMixin::YamlDTKMetaFiles
Constants included from Poller
DTK::Client::Poller::PERIOD_WAIT_TIME
Constants inherited from Thor
Thor::HIDE_FROM_BASE_CONTEXT_HELP
Class Method Summary collapse
- .all_children ⇒ Object
- .override_allowed_methods ⇒ Object
- .valid_child?(name_of_sub_context) ⇒ Boolean
- .valid_children ⇒ Object
- .validation_list(context_params) ⇒ Object
Instance Method Summary collapse
- #create_provider_ec2(context_params) ⇒ Object
- #create_provider_physical(context_params) ⇒ Object
- #delete_and_destroy(context_params) ⇒ Object
- #list(context_params) ⇒ Object
- #list_targets(context_params) ⇒ Object
Methods inherited from CommandBaseThor
action_on_revalidation_response, basename, create_context_arguments, execute_from_cli, generate_cached_id, get_cached_response, get_identifiers, get_usage_info, #help, #initialize, invalidate_entities, invisible_context_list, list_method_supported?, task_names, tiered_task_names, valid_id?
Methods included from CommandBase
#get, #get_connection, handle_argument_error, #post, #post_file, #rest_url, #rotate_args
Methods included from TaskStatusMixin
#list_task_info_aux, #task_status_aux, #task_status_stream
Methods included from Console
confirmation_prompt, confirmation_prompt_additional_options, confirmation_prompt_multiple_choice, confirmation_prompt_simple, unix_shell, wait_animation
Methods included from CommandHelperMixin
Methods included from ReparseMixin
Methods included from PushCloneChangesMixin
Methods included from CommandBaseThor::CommonOptionDefs::ClassMixin
Methods included from Poller
#poller_response, #print_response, #resolve_type
Methods inherited from Thor
get_alternative_identifiers, help, match_help_item_changes, overriden_help, printable_tasks, replace_if_matched!, set_context
Constructor Details
This class inherits a constructor from DTK::Client::CommandBaseThor
Class Method Details
.all_children ⇒ Object
25 26 27 |
# File 'lib/commands/thor/provider.rb', line 25 def self.all_children() [:target] end |
.override_allowed_methods ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/commands/thor/provider.rb', line 33 def self.override_allowed_methods() return DTK::Shell::OverrideTasks.new({ :command_only => { :target => [ ['delete-and-destroy',"delete-and-destroy TARGET-NAME","# Deletes target"], ['list',"list","# Lists available targets."] ] }, :identifier_only => { :target => [ ['list-nodes',"list-nodes","# Lists node instances in given targets."], ['list-services',"list-services","# Lists assembly instances in given targets."] ] } }) end |
.valid_child?(name_of_sub_context) ⇒ Boolean
51 52 53 |
# File 'lib/commands/thor/provider.rb', line 51 def self.valid_child?(name_of_sub_context) Provider.valid_children().include?(name_of_sub_context.to_sym) end |
.valid_children ⇒ Object
21 22 23 |
# File 'lib/commands/thor/provider.rb', line 21 def self.valid_children() [:target] end |
.validation_list(context_params) ⇒ Object
29 30 31 |
# File 'lib/commands/thor/provider.rb', line 29 def self.validation_list(context_params) get_cached_response(:provider, "target/list", {:subtype => :template }) end |
Instance Method Details
#create_provider_ec2(context_params) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/commands/thor/provider.rb', line 60 def create_provider_ec2(context_params) provider_name = context_params.retrieve_arguments([:option_1!],method_argument_names) provider_type = 'ec2' iaas_properties = Hash.new keypair, security_group = context_params.([:keypair, :security_group], ) iaas_properties.merge!(:keypair => keypair) if keypair if security_group if security_group.end_with?(',') raise DtkValidationError.new("Multiple security groups should be separated with ',' and without spaces between them (e.g. --security_groups gr1,gr2,gr3,...) ") end security_groups = security_group.split(',') if (security_groups.empty? || security_groups.size==1) iaas_properties.merge!(:security_group => security_group) else iaas_properties.merge!(:security_group_set => security_groups) end end result = Shell::InteractiveWizard::interactive_user_input( {'IAAS Credentials' => { :type => :group, :options => [ {:key => {}}, {:secret => {}} ]}}) access_key, secret_key = result['IAAS Credentials'].values_at(:key, :secret) iaas_properties.merge!(:key => access_key,:secret => secret_key) # Remove sensitive readline history OsUtil.pop_readline_history(2) post_body = { :iaas_properties => iaas_properties, :provider_name => provider_name, :iaas_type => 'ec2', :no_bootstrap => ! .bootstrap? } response = post rest_url("target/create_provider"), post_body @@invalidate_map << :provider response end |
#create_provider_physical(context_params) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/commands/thor/provider.rb', line 108 def create_provider_physical(context_params) provider_name = context_params.retrieve_arguments([:option_1!],method_argument_names) # Remove sensitive readline history OsUtil.pop_readline_history(2) post_body = { :provider_name => provider_name, :iaas_type => 'physical' } response = post rest_url("target/create_provider"), post_body @@invalidate_map << :provider response end |
#delete_and_destroy(context_params) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/commands/thor/provider.rb', line 195 def delete_and_destroy(context_params) provider_id = context_params.retrieve_arguments([:option_1!],method_argument_names) unless .force? return unless Console.confirmation_prompt("Are you sure you want to delete provider '#{provider_id}' and all target and service instances under it" +'?') end post_body = { :target_id => provider_id, :type => 'template' } @@invalidate_map << :provider response = post(rest_url("target/delete_and_destroy"),post_body) return response unless response.ok? if info_array = response.data['info'] info_array.each{|info_msg|OsUtil.print(info_msg, :yellow)} end Response::Ok.new() end |
#list(context_params) ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/commands/thor/provider.rb', line 167 def list(context_params) if context_params.is_there_command?(:"target") list_targets(context_params) else response = post rest_url("target/list"), { :subtype => :template } response.render_table(:provider) end end |
#list_targets(context_params) ⇒ Object
186 187 188 189 190 191 |
# File 'lib/commands/thor/provider.rb', line 186 def list_targets(context_params) provider_id = context_params.retrieve_arguments([:provider_id!],method_argument_names) response = post rest_url("target/list"), { :subtype => :instance, :parent_id => provider_id } response.render_table(:target) end |