Class: DTK::Client::Target
Constant Summary
collapse
- ValidImportTypes =
["file"]
CommandBaseThor::ALT_IDENTIFIER_SEPARATOR, CommandBaseThor::EXTENDED_TIMEOUT, CommandBaseThor::HIDE_FROM_BASE_CONTEXT, CommandBaseThor::TIME_DIFF
CommandHelperMixin::Loaded
ReparseMixin::YamlDTKMetaFiles
Constants included
from Poller
Poller::PERIOD_WAIT_TIME
Constants inherited
from Thor
Thor::HIDE_FROM_BASE_CONTEXT_HELP
Class Method Summary
collapse
Instance Method Summary
collapse
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?
#get, #get_connection, handle_argument_error, #post, #post_file, #rest_url, #rotate_args
#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
#Helper
#reparse_aux
#push_clone_changes_aux
#version_method_option
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
Class Method Details
.alternate_identifiers ⇒ Object
30
31
32
|
# File 'lib/commands/thor/target.rb', line 30
def self.alternate_identifiers()
return ['PROVIDER']
end
|
.extended_context ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/commands/thor/target.rb', line 34
def self.extended_context()
{
:context => {
"--provider" => "provider"
}
}
end
|
.pretty_print_cols ⇒ Object
26
27
28
|
# File 'lib/commands/thor/target.rb', line 26
def self.pretty_print_cols()
PPColumns.get(:target)
end
|
.validation_list(context_params) ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/commands/thor/target.rb', line 138
def self.validation_list(context_params)
provider_id = context_params.retrieve_arguments([:provider_id])
if provider_id
post_body = {
:subtype => :instance,
:parent_id => provider_id
}
response = get_cached_response(:provider_target, "target/list", post_body)
else
response = get_cached_response(:target, "target/list", { :subtype => :instance })
end
response
end
|
Instance Method Details
#create_target_ec2_classic(context_params) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/commands/thor/target.rb', line 111
def create_target_ec2_classic(context_params)
option_list = [:provider!, :region!, :keypair, :security_group]
response = Common::CreateTarget.new(self, context_params).execute(:ec2_classic,option_list)
@@invalidate_map << :target
response
end
|
#create_target_ec2_vpc(context_params) ⇒ Object
124
125
126
127
128
129
|
# File 'lib/commands/thor/target.rb', line 124
def create_target_ec2_vpc(context_params)
option_list = [:provider!, :subnet!, :region!, :keypair, :security_group]
response = Common::CreateTarget.new(self, context_params).execute(:ec2_vpc,option_list)
@@invalidate_map << :target
response
end
|
#delete_and_destroy(context_params) ⇒ Object
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/commands/thor/target.rb', line 193
def delete_and_destroy(context_params)
target_id = context_params.retrieve_arguments([:option_1!],method_argument_names)
unless options.force?
return unless Console.confirmation_prompt("Are you sure you want to delete target '#{target_id}' (all services/nodes that belong to this target will be deleted as well)'"+'?')
end
post_body = {
:target_id => target_id,
:type => 'instance'
}
@@invalidate_map << :target
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
|
#import_nodes(context_params) ⇒ Object
59
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
|
# File 'lib/commands/thor/target.rb', line 59
def import_nodes(context_params)
target_id = context_params.retrieve_arguments([:target_id!],method_argument_names)
source = context_params.retrieve_thor_options([:source!], options)
parsed_source = source.match(/^(\w+):(.+)/)
raise DtkValidationError, "Invalid source! Valid source should contain source_type:source_path (e.g. --source file:path/to/file.yaml)." unless parsed_source
import_type = parsed_source[1]
path = parsed_source[2]
raise DtkValidationError, "We do not support '#{import_type}' as import source at the moment. Valid sources: #{ValidImportTypes}" unless ValidImportTypes.include?(import_type)
post_body = {:target_id => target_id}
if import_type.eql?('file')
inventory_data = parse_inventory_file(path)
post_body.merge!(:inventory_data => inventory_data)
end
response = post rest_url("target/import_nodes"), post_body
return response unless response.ok?
if response.data.empty?
OsUtil.print("No new nodes to import!", :yellow)
else
OsUtil.print("Successfully imported nodes:", :yellow)
response.data.each do |node|
OsUtil.print("#{node}", :yellow)
end
end
end
|
#info(context_params) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/commands/thor/target.rb', line 50
def info(context_params)
target_id = context_params.retrieve_arguments([:target_id!],method_argument_names)
post_body = {:target_id => target_id}
post rest_url('target/info'), post_body
end
|
#install_agents(context_params) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/commands/thor/target.rb', line 99
def install_agents(context_params)
target_id = context_params.retrieve_arguments([:target_id!],method_argument_names)
post_body = {:target_id => target_id}
post rest_url("target/install_agents"), post_body
end
|
#list(context_params) ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/commands/thor/target.rb', line 158
def list(context_params)
provider_id, target_id, about = context_params.retrieve_arguments([:provider_id, :target_id, :option_1],method_argument_names||="")
if target_id.nil?
post_body = {
:subtype => :instance,
:parent_id => provider_id
}
response = post rest_url("target/list"), post_body
response.render_table(:target)
else
post_body = {
:target_id => target_id,
:about => about
}
case about
when "nodes"
response = post rest_url("target/info_about"), post_body
data_type = :node
when "assemblies"
post_body.merge!(:detail_level => 'nodes', :include_workspace => true)
response = post rest_url("target/info_about"), post_body
data_type = :assembly
else
raise_validation_error_method_usage('list')
end
response.render_table(data_type)
end
end
|
#list_nodes(context_params) ⇒ Object
44
45
46
47
|
# File 'lib/commands/thor/target.rb', line 44
def list_nodes(context_params)
context_params.method_arguments = ["nodes"]
list(context_params)
end
|
#list_services(context_params) ⇒ Object
133
134
135
136
|
# File 'lib/commands/thor/target.rb', line 133
def list_services(context_params)
context_params.method_arguments = ["assemblies"]
list(context_params)
end
|
#set_default_target(context_params) ⇒ Object
93
94
95
96
|
# File 'lib/commands/thor/target.rb', line 93
def set_default_target(context_params)
target_id = context_params.retrieve_arguments([:option_1!],method_argument_names)
post rest_url("target/set_default"), { :target_id => target_id }
end
|