dtk-shell 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile_dev +13 -0
- data/README.md +121 -0
- data/bin/dtk-execute +32 -0
- data/bin/dtk-run +92 -0
- data/bin/dtk-shell +31 -0
- data/dtk-shell.gemspec +50 -0
- data/lib/auxiliary.rb +61 -0
- data/lib/bundler_monkey_patch.rb +26 -0
- data/lib/client.rb +58 -0
- data/lib/command_helper.rb +33 -0
- data/lib/command_helpers/git_repo.rb +589 -0
- data/lib/command_helpers/git_repo/merge.rb +153 -0
- data/lib/command_helpers/jenkins_client.rb +106 -0
- data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
- data/lib/command_helpers/service_importer.rb +251 -0
- data/lib/command_helpers/service_link.rb +33 -0
- data/lib/command_helpers/test_module_creator.rb +69 -0
- data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
- data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
- data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
- data/lib/commands.rb +57 -0
- data/lib/commands/common/thor/access_control.rb +133 -0
- data/lib/commands/common/thor/action_result_handler.rb +74 -0
- data/lib/commands/common/thor/assembly_template.rb +92 -0
- data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
- data/lib/commands/common/thor/base_command_helper.rb +59 -0
- data/lib/commands/common/thor/clone.rb +82 -0
- data/lib/commands/common/thor/common.rb +88 -0
- data/lib/commands/common/thor/common_base.rb +49 -0
- data/lib/commands/common/thor/create_target.rb +70 -0
- data/lib/commands/common/thor/edit.rb +255 -0
- data/lib/commands/common/thor/inventory_parser.rb +98 -0
- data/lib/commands/common/thor/list_diffs.rb +128 -0
- data/lib/commands/common/thor/module.rb +1011 -0
- data/lib/commands/common/thor/module/import.rb +210 -0
- data/lib/commands/common/thor/node.rb +53 -0
- data/lib/commands/common/thor/poller.rb +65 -0
- data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
- data/lib/commands/common/thor/pull_from_remote.rb +152 -0
- data/lib/commands/common/thor/puppet_forge.rb +72 -0
- data/lib/commands/common/thor/purge_clone.rb +101 -0
- data/lib/commands/common/thor/push_clone_changes.rb +162 -0
- data/lib/commands/common/thor/push_to_remote.rb +94 -0
- data/lib/commands/common/thor/remotes.rb +71 -0
- data/lib/commands/common/thor/reparse.rb +40 -0
- data/lib/commands/common/thor/set_required_attributes.rb +46 -0
- data/lib/commands/thor/account.rb +239 -0
- data/lib/commands/thor/assembly.rb +356 -0
- data/lib/commands/thor/attribute.rb +79 -0
- data/lib/commands/thor/component.rb +70 -0
- data/lib/commands/thor/component_module.rb +501 -0
- data/lib/commands/thor/component_template.rb +174 -0
- data/lib/commands/thor/dependency.rb +34 -0
- data/lib/commands/thor/developer.rb +144 -0
- data/lib/commands/thor/dtk.rb +152 -0
- data/lib/commands/thor/library.rb +125 -0
- data/lib/commands/thor/node.rb +504 -0
- data/lib/commands/thor/node_template.rb +94 -0
- data/lib/commands/thor/project.rb +34 -0
- data/lib/commands/thor/provider.rb +233 -0
- data/lib/commands/thor/remotes.rb +49 -0
- data/lib/commands/thor/service.rb +941 -0
- data/lib/commands/thor/service_module.rb +914 -0
- data/lib/commands/thor/state_change.rb +25 -0
- data/lib/commands/thor/target.rb +250 -0
- data/lib/commands/thor/task.rb +116 -0
- data/lib/commands/thor/test_module.rb +310 -0
- data/lib/commands/thor/utils.rb +21 -0
- data/lib/commands/thor/workspace.rb +685 -0
- data/lib/config/cacert.pem +3785 -0
- data/lib/config/client.conf.header +20 -0
- data/lib/config/configuration.rb +99 -0
- data/lib/config/default.conf +16 -0
- data/lib/config/disk_cacher.rb +80 -0
- data/lib/configurator.rb +176 -0
- data/lib/context_router.rb +44 -0
- data/lib/core.rb +497 -0
- data/lib/domain/git_adapter.rb +412 -0
- data/lib/domain/git_error_handler.rb +64 -0
- data/lib/domain/response.rb +285 -0
- data/lib/domain/response/error_handler.rb +86 -0
- data/lib/dtk-shell/version.rb +20 -0
- data/lib/dtk_constants.rb +40 -0
- data/lib/dtk_error.rb +114 -0
- data/lib/dtk_logger.rb +126 -0
- data/lib/dtk_shell.rb +31 -0
- data/lib/error.rb +85 -0
- data/lib/execute.rb +29 -0
- data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
- data/lib/execute/command.rb +40 -0
- data/lib/execute/command/api_call.rb +60 -0
- data/lib/execute/command/api_call/map.rb +60 -0
- data/lib/execute/command/api_call/service.rb +91 -0
- data/lib/execute/command/api_call/translation_term.rb +119 -0
- data/lib/execute/command/rest_call.rb +37 -0
- data/lib/execute/command_processor.rb +30 -0
- data/lib/execute/command_processor/rest_call.rb +59 -0
- data/lib/execute/error_usage.rb +21 -0
- data/lib/execute/execute_context.rb +86 -0
- data/lib/execute/execute_context/result_store.rb +37 -0
- data/lib/execute/script.rb +64 -0
- data/lib/execute/script/add_tenant.rb +121 -0
- data/lib/git-logs/git.log +0 -0
- data/lib/parser/adapters/option_parser.rb +70 -0
- data/lib/parser/adapters/thor.rb +555 -0
- data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
- data/lib/require_first.rb +104 -0
- data/lib/search_hash.rb +44 -0
- data/lib/shell.rb +261 -0
- data/lib/shell/context.rb +1065 -0
- data/lib/shell/context_aux.rb +46 -0
- data/lib/shell/domain/active_context.rb +186 -0
- data/lib/shell/domain/context_entity.rb +89 -0
- data/lib/shell/domain/context_params.rb +223 -0
- data/lib/shell/domain/override_tasks.rb +88 -0
- data/lib/shell/domain/shadow_entity.rb +76 -0
- data/lib/shell/header_shell.rb +44 -0
- data/lib/shell/help_monkey_patch.rb +283 -0
- data/lib/shell/interactive_wizard.rb +225 -0
- data/lib/shell/message_queue.rb +63 -0
- data/lib/shell/parse_monkey_patch.rb +39 -0
- data/lib/shell/status_monitor.rb +124 -0
- data/lib/task_status.rb +83 -0
- data/lib/task_status/refresh_mode.rb +77 -0
- data/lib/task_status/snapshot_mode.rb +28 -0
- data/lib/task_status/stream_mode.rb +48 -0
- data/lib/task_status/stream_mode/element.rb +101 -0
- data/lib/task_status/stream_mode/element/format.rb +101 -0
- data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
- data/lib/task_status/stream_mode/element/no_results.rb +26 -0
- data/lib/task_status/stream_mode/element/render.rb +59 -0
- data/lib/task_status/stream_mode/element/stage.rb +84 -0
- data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
- data/lib/task_status/stream_mode/element/task_end.rb +35 -0
- data/lib/task_status/stream_mode/element/task_start.rb +37 -0
- data/lib/util/common_util.rb +37 -0
- data/lib/util/console.rb +235 -0
- data/lib/util/dtk_puppet.rb +65 -0
- data/lib/util/module_util.rb +66 -0
- data/lib/util/os_util.rb +385 -0
- data/lib/util/permission_util.rb +31 -0
- data/lib/util/remote_dependency_util.rb +84 -0
- data/lib/util/ssh_util.rb +94 -0
- data/lib/view_processor.rb +129 -0
- data/lib/view_processor/augmented_simple_list.rb +44 -0
- data/lib/view_processor/hash_pretty_print.rb +123 -0
- data/lib/view_processor/simple_list.rb +156 -0
- data/lib/view_processor/table_print.rb +309 -0
- data/lib/violation.rb +86 -0
- data/lib/violation/attribute.rb +76 -0
- data/lib/violation/fix.rb +26 -0
- data/lib/violation/fix/result.rb +73 -0
- data/lib/violation/fix/result/error.rb +34 -0
- data/lib/violation/fix/set_attribute.rb +41 -0
- data/lib/violation/sub_classes.rb +60 -0
- data/puppet/manifests/init.pp +72 -0
- data/puppet/manifests/params.pp +16 -0
- data/puppet/r8meta.puppet.yml +35 -0
- data/puppet/templates/bash_profile.erb +2 -0
- data/puppet/templates/client.conf.erb +1 -0
- data/puppet/templates/dtkclient.erb +2 -0
- data/spec/component_module_spec.rb +34 -0
- data/spec/dependency_spec.rb +6 -0
- data/spec/dtk_shell_spec.rb +13 -0
- data/spec/dtk_spec.rb +33 -0
- data/spec/lib/spec_helper.rb +10 -0
- data/spec/lib/spec_thor.rb +108 -0
- data/spec/node_template_spec.rb +24 -0
- data/spec/project_spec.rb +6 -0
- data/spec/repo_spec.rb +7 -0
- data/spec/response_spec.rb +52 -0
- data/spec/service_module_spec.rb +38 -0
- data/spec/service_spec.rb +50 -0
- data/spec/state_change_spec.rb +7 -0
- data/spec/table_print_spec.rb +48 -0
- data/spec/target_spec.rb +57 -0
- data/spec/task_spec.rb +28 -0
- data/views/assembly/augmented_simple_list.rb +12 -0
- data/views/assembly_template/augmented_simple_list.rb +12 -0
- data/views/list_task/augmented_simple_list.rb +12 -0
- metadata +421 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
module DTK::Client
|
|
19
|
+
class ComponentTemplate < CommandBaseThor
|
|
20
|
+
|
|
21
|
+
def self.pretty_print_cols()
|
|
22
|
+
PPColumns.get(:component)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.valid_children()
|
|
26
|
+
# Amar: attribute context commented out per Rich suggeston
|
|
27
|
+
#[:attribute]
|
|
28
|
+
[]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# this includes children of children
|
|
32
|
+
def self.all_children()
|
|
33
|
+
# Amar: attribute context commented out per Rich suggeston
|
|
34
|
+
#[:attribute]
|
|
35
|
+
[]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.valid_child?(name_of_sub_context)
|
|
39
|
+
return ComponentTemplate.valid_children().include?(name_of_sub_context.to_sym)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.validation_list(context_params)
|
|
43
|
+
if context_params.is_there_identifier?("component-module")
|
|
44
|
+
component_module_id = context_params.retrieve_arguments([:component_module_id!])
|
|
45
|
+
res = get_cached_response(:component_template, "component_module/info_about", { :component_module_id => component_module_id, :about => :components})
|
|
46
|
+
else
|
|
47
|
+
post_body = {:subtype => 'template', :ignore => 'test_module'}
|
|
48
|
+
if assembly_id = context_params.retrieve_arguments([[:service_id, :workspace_id]])
|
|
49
|
+
post_body.merge!(:assembly_id => assembly_id)
|
|
50
|
+
end
|
|
51
|
+
get_cached_response(:component_template, "component/list", post_body)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.override_allowed_methods()
|
|
56
|
+
return DTK::Shell::OverrideTasks.new({})
|
|
57
|
+
# Amar: attribute context commented out per Rich suggeston
|
|
58
|
+
#return DTK::Shell::OverrideTasks.new(
|
|
59
|
+
# {
|
|
60
|
+
# :command_only => {
|
|
61
|
+
# :attribute => [
|
|
62
|
+
# ['list',"list","List attributes for given component"]
|
|
63
|
+
# ]
|
|
64
|
+
# },
|
|
65
|
+
# :identifier_only => {
|
|
66
|
+
# :attribute => [
|
|
67
|
+
# ['list',"list","List attributes for given component"]
|
|
68
|
+
# ]
|
|
69
|
+
# }
|
|
70
|
+
#
|
|
71
|
+
#})
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
desc "COMPONENT-TEMPLATE-NAME/ID info", "Get information about given component template."
|
|
75
|
+
method_option :list, :type => :boolean, :default => false
|
|
76
|
+
def info(context_params)
|
|
77
|
+
component_id = context_params.retrieve_arguments([:component_template_id!],method_argument_names)
|
|
78
|
+
data_type = :component
|
|
79
|
+
|
|
80
|
+
post_body = {
|
|
81
|
+
:component_id => component_id,
|
|
82
|
+
:subtype => 'template'
|
|
83
|
+
}
|
|
84
|
+
response = post rest_url("component/info"), post_body
|
|
85
|
+
|
|
86
|
+
response.render_table(data_type) unless options.list?
|
|
87
|
+
|
|
88
|
+
return response
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
desc "COMPONENT-TEMPLATE-NAME/ID list-nodes [--module MODULE-NAME]", "List all nodes for given component template. Optional filter by modul name."
|
|
92
|
+
method_option :list, :type => :boolean, :default => false
|
|
93
|
+
method_option "module",:aliases => "-m" ,
|
|
94
|
+
:type => :string,
|
|
95
|
+
:banner => "MODULE-LIST-FILTER",
|
|
96
|
+
:desc => "Module list filter"
|
|
97
|
+
def list_nodes(context_params)
|
|
98
|
+
context_params.method_arguments = ["nodes"]
|
|
99
|
+
list(context_params)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
desc "list [--module MODULE-NAME]", "List all component templates. Optional filter by module name."
|
|
103
|
+
method_option :list, :type => :boolean, :default => false
|
|
104
|
+
method_option "module",:aliases => "-m" ,
|
|
105
|
+
:type => :string,
|
|
106
|
+
:banner => "MODULE-LIST-FILTER",
|
|
107
|
+
:desc => "Module list filter"
|
|
108
|
+
def list(context_params)
|
|
109
|
+
component_id, about, module_filter = context_params.retrieve_arguments([:component_template_id,:option_1,:option_1],method_argument_names)
|
|
110
|
+
about ||= 'none'
|
|
111
|
+
data_type = :component
|
|
112
|
+
|
|
113
|
+
# Case when user provided '--module' / '-m' 'MODUL-NAME'
|
|
114
|
+
if options.module
|
|
115
|
+
# Special case when user sends --module; until now --OPTION didn't have value attached to it
|
|
116
|
+
if options.module.eql?("module")
|
|
117
|
+
module_id = module_filter
|
|
118
|
+
else
|
|
119
|
+
module_id = options.module
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
context_params_for_service = DTK::Shell::ContextParams.new
|
|
123
|
+
context_params_for_service.add_context_to_params("component_module", "component_module", module_id)
|
|
124
|
+
|
|
125
|
+
response = DTK::Client::ContextRouter.routeTask("component_module", "list_components", context_params_for_service, @conn)
|
|
126
|
+
|
|
127
|
+
else # Case without module filter
|
|
128
|
+
|
|
129
|
+
post_body = {
|
|
130
|
+
:component_id => component_id,
|
|
131
|
+
:subtype => 'template',
|
|
132
|
+
:about => about
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
case about
|
|
136
|
+
when 'none'
|
|
137
|
+
response = post rest_url("component/list")
|
|
138
|
+
when 'nodes'
|
|
139
|
+
response = post rest_url("component/list"), post_body
|
|
140
|
+
else
|
|
141
|
+
raise_validation_error_method_usage('list')
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
response.render_table(data_type) unless options.list?
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
return response
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
desc "COMPONENT-TEMPLATE-NAME/ID stage NODE-NAME/ID", "Stage indentified node for given component template."
|
|
151
|
+
method_option :list, :type => :boolean, :default => false
|
|
152
|
+
def stage(context_params)
|
|
153
|
+
component_id, node_id = context_params.retrieve_arguments([:component_template_id!,:option_1!],method_argument_names)
|
|
154
|
+
data_type = :component
|
|
155
|
+
|
|
156
|
+
post_body = {
|
|
157
|
+
:component_id => component_id
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
unless node_id.nil?
|
|
161
|
+
post_body.merge!({:node_id => node_id})
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
response = post rest_url("component/stage"), post_body
|
|
165
|
+
@@invalidate_map << :component_template
|
|
166
|
+
|
|
167
|
+
response.render_table(data_type) unless options.list?
|
|
168
|
+
response
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
end
|
|
174
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
module DTK::Client
|
|
19
|
+
class Dependency < CommandBaseThor
|
|
20
|
+
desc "add-component COMPONENT-ID OTHER-COMPONENT-ID","Add before/require constraint"
|
|
21
|
+
def add_component(context_params)
|
|
22
|
+
component_id, other_component_id = context_params.retrieve_arguments([:option_1!,:option_2!],method_argument_names)
|
|
23
|
+
post_body = {
|
|
24
|
+
:component_id => component_id,
|
|
25
|
+
:other_component_id => other_component_id,
|
|
26
|
+
:type => "required by"
|
|
27
|
+
}
|
|
28
|
+
response = post rest_url("dependency/add_component_dependency"), post_body
|
|
29
|
+
@@invalidate_map << :component_template
|
|
30
|
+
|
|
31
|
+
return response
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
require 'base64'
|
|
19
|
+
dtk_require_common_commands('thor/action_result_handler')
|
|
20
|
+
|
|
21
|
+
module DTK::Client
|
|
22
|
+
class Developer < CommandBaseThor
|
|
23
|
+
|
|
24
|
+
no_tasks do
|
|
25
|
+
include ActionResultHandler
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
MATCH_FILE_NAME = /[a-zA-Z0-9_]+\.[a-zA-Z]+$/
|
|
29
|
+
GIT_LOG_LOCATION = File.expand_path('../../../lib/git-logs/git.log', File.dirname(__FILE__))
|
|
30
|
+
PROJECT_ROOT = File.expand_path('../../../', File.dirname(__FILE__))
|
|
31
|
+
|
|
32
|
+
desc "upload-agent PATH-TO-AGENT[.rb,.dll] NODE-ID-PATTERN", "Uploads agent and ddl file to requested nodes, pattern is regexp for filtering node ids."
|
|
33
|
+
def upload_agent(context_params)
|
|
34
|
+
agent, node_pattern = context_params.retrieve_arguments([:option_1!, :option_2!], method_argument_names)
|
|
35
|
+
|
|
36
|
+
nodes = post rest_url("node/list"), { :is_list_all => true }
|
|
37
|
+
|
|
38
|
+
ids = []
|
|
39
|
+
# get all nodes which id starts with node_pattern
|
|
40
|
+
nodes["data"].collect{|a| ids<<a["id"].to_i if a["id"].to_s.match(Regexp.new(node_pattern.to_s)) }
|
|
41
|
+
raise DTK::Client::DtkValidationError, "Unable to find nodes to match this pattern: '#{node_pattern}'." if ids.empty?
|
|
42
|
+
|
|
43
|
+
# if it doesn't contain extension upload both *.rb and *.ddl
|
|
44
|
+
files = (agent.match(MATCH_FILE_NAME) ? [agent] : ["#{agent}.rb","#{agent}.ddl"])
|
|
45
|
+
|
|
46
|
+
# read require files and encode them
|
|
47
|
+
request_body = {}
|
|
48
|
+
files.each do |file_name|
|
|
49
|
+
raise DTK::Client::DtkError, "Unable to load file: #{file_name}" unless File.exists?(file_name)
|
|
50
|
+
# reason for this to file dues to previus match
|
|
51
|
+
agent_name = file_name.match(MATCH_FILE_NAME)[0]
|
|
52
|
+
File.open(file_name) { |file| request_body.store(agent_name,Base64.encode64(file.read)) }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# send as binary post request
|
|
56
|
+
response = post_file rest_url("developer/inject_agent"), { :agent_files => request_body, :node_pattern => node_pattern, :node_list => ids }
|
|
57
|
+
puts "Agent uploaded successfully!";return if response.ok?
|
|
58
|
+
return response
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# run-agent haris1 dev_manager inject_agent "{ 'action_agent_branch': 'master', 'action_agent_url': 'git@github.com:rich-reactor8/dtk-action-agent.git' }"
|
|
62
|
+
desc "run-agent SERVICE-NAME AGENT-NAME AGENT-METHOD PARAMS", "Updates DTK Action Agent to provided branch, example: dev_manager inject_agent \"{ 'action_agent_branch': 'master', 'action_agent_url': 'url' }\""
|
|
63
|
+
def run_agent(context_params)
|
|
64
|
+
service_name, agent_name, agent_method, action_params = context_params.retrieve_arguments([:option_1!, :option_2!, :option_3!, :option_4!], method_argument_names)
|
|
65
|
+
|
|
66
|
+
action_params ||= "{}"
|
|
67
|
+
action_params.gsub!("'",'"')
|
|
68
|
+
|
|
69
|
+
response = post_file rest_url("developer/run_agent"), { :service_name => service_name, :agent_name => agent_name, :agent_method => agent_method, :agent_params => action_params }
|
|
70
|
+
return response unless response.ok?
|
|
71
|
+
|
|
72
|
+
action_results_id = response.data(:action_results_id)
|
|
73
|
+
print_simple_results(action_results_id)
|
|
74
|
+
|
|
75
|
+
nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
desc "remove-from-system SERVICE-NAME", "Removes objects associated with service, but does not destroy target isnatnces"
|
|
79
|
+
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
|
80
|
+
def remove_from_system(context_params)
|
|
81
|
+
assembly_id = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
|
82
|
+
unless options.force?
|
|
83
|
+
# Ask user if really want to delete assembly, if not then return to dtk-shell without deleting
|
|
84
|
+
what = "service"
|
|
85
|
+
return unless Console.confirmation_prompt("Are you sure you want to remove #{what} '#{assembly_id}' and its nodes from the system"+'?')
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
response = post rest_url("assembly/remove_from_system"), {:assembly_id => assembly_id}
|
|
89
|
+
# when changing context send request for getting latest assemblies instead of getting from cache
|
|
90
|
+
@@invalidate_map << :service
|
|
91
|
+
return response
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
desc "apply-param-set SERVICE-NAME/ID PARAM-SET-PATH", "Uses the parametrs set in the file PARAM-SET-PATH and appleis to the service"
|
|
95
|
+
def apply_param_set(context_params)
|
|
96
|
+
assembly_id,path = context_params.retrieve_arguments([:option_1!,:option_2!],method_argument_names)
|
|
97
|
+
av_pairs = JSON.parse(File.open(path).read)
|
|
98
|
+
|
|
99
|
+
av_pairs.each do |a,v|
|
|
100
|
+
post_body = {
|
|
101
|
+
:assembly_id => assembly_id,
|
|
102
|
+
:pattern => a,
|
|
103
|
+
:value => v
|
|
104
|
+
}
|
|
105
|
+
response = post rest_url("assembly/set_attributes"), post_body
|
|
106
|
+
if response.ok?
|
|
107
|
+
pp response.data
|
|
108
|
+
else
|
|
109
|
+
return response
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
Response::Ok.new()
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
desc "commits", "View last commits that went into the gem"
|
|
116
|
+
def commits(context_params)
|
|
117
|
+
unless File.file?(GIT_LOG_LOCATION)
|
|
118
|
+
raise DTK::Client::DtkError, "Git log file not found, contact DTK support team."
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
File.readlines(GIT_LOG_LOCATION).reverse.each do |line|
|
|
122
|
+
puts line
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
desc "content FILE-NAME", "Get content of file name in DTK Client gem"
|
|
127
|
+
def content(context_params)
|
|
128
|
+
file_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
|
129
|
+
found_files = Dir["#{PROJECT_ROOT}/**/*.*"].select { |fname| fname.end_with?(file_name) }
|
|
130
|
+
|
|
131
|
+
if found_files.empty?
|
|
132
|
+
raise DTK::Client::DtkValidationError, "No files found with name '#{file_name}'."
|
|
133
|
+
else
|
|
134
|
+
found_files.each do |fname|
|
|
135
|
+
header = "*********************** #{fname} ***********************"
|
|
136
|
+
DTK::Client::OsUtil.print(header, :yellow)
|
|
137
|
+
puts File.open(fname).readlines
|
|
138
|
+
DTK::Client::OsUtil.print("*"*header.size, :yellow)
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
module DTK::Client
|
|
20
|
+
|
|
21
|
+
# Following are descriptions of available commands
|
|
22
|
+
class Dtk < CommandBaseThor
|
|
23
|
+
|
|
24
|
+
# entities that are not available on root but later in n-context
|
|
25
|
+
def self.additional_entities()
|
|
26
|
+
['component','attribute','utils','node','task','component-template','assembly','remotes']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
if ::DTK::Configuration.get(:development_mode)
|
|
30
|
+
desc "workspace","Sandbox for development and testing"
|
|
31
|
+
def workspace
|
|
32
|
+
# API descriptor, SYM_LINK!
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
if ::DTK::Configuration.get(:development_mode)
|
|
37
|
+
desc "target","Targets"
|
|
38
|
+
def target
|
|
39
|
+
# API descriptor, SYM_LINK!
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# NOTE
|
|
45
|
+
# Following methods are just api descriptors, invocation happens at "bin/dtk" entry point
|
|
46
|
+
desc "account","Account management for accessing DTK server"
|
|
47
|
+
def account
|
|
48
|
+
# API descriptor
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
desc "service","Assembly instances that have been deployed via DTK."
|
|
52
|
+
def service
|
|
53
|
+
# API descriptor
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# desc "assembly","Commands to stage or launch new assemblies and query assembly templates."
|
|
57
|
+
# def assembly
|
|
58
|
+
# # API descriptor
|
|
59
|
+
# end
|
|
60
|
+
|
|
61
|
+
#TODO: not exposed
|
|
62
|
+
#desc "dependency","DESCRIPTION TO BE ADDED."
|
|
63
|
+
#def dependency
|
|
64
|
+
# # API descriptor
|
|
65
|
+
#end
|
|
66
|
+
|
|
67
|
+
# desc "library", "Commands to list and query libraries."
|
|
68
|
+
# def library
|
|
69
|
+
# # API descriptor
|
|
70
|
+
# end
|
|
71
|
+
|
|
72
|
+
desc "component-module", "DTK definitions for modeling/defining individual configuration components."
|
|
73
|
+
def component_module
|
|
74
|
+
# API descriptor
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
if ::DTK::Configuration.get(:development_mode)
|
|
78
|
+
desc "test-module", "DTK definitions for modeling/defining individual test components."
|
|
79
|
+
def test_module
|
|
80
|
+
# API descriptor
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# desc "node", "Commands to list, query, and delete/destroy node instances."
|
|
85
|
+
# def node
|
|
86
|
+
# # API descriptor
|
|
87
|
+
# end
|
|
88
|
+
|
|
89
|
+
# desc "node-group", "Add/Destroy/List available groups of nodes."
|
|
90
|
+
# def node_group
|
|
91
|
+
# # API descriptor
|
|
92
|
+
# end
|
|
93
|
+
|
|
94
|
+
if ::DTK::Configuration.get(:development_mode)
|
|
95
|
+
desc "node-template", "Node Templates that map to machine images and containers."
|
|
96
|
+
def node_template
|
|
97
|
+
# API descriptor
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# desc "component-template","Commands to list and query component templates."
|
|
102
|
+
# def component_template
|
|
103
|
+
# # API descriptor
|
|
104
|
+
# end
|
|
105
|
+
|
|
106
|
+
#TODO: remove
|
|
107
|
+
#desc "repo", "Part of dtk client which enables us to sync, destroy, view available repos."
|
|
108
|
+
#def repo
|
|
109
|
+
# # API descriptor
|
|
110
|
+
#end
|
|
111
|
+
|
|
112
|
+
#TODO: not supported yet
|
|
113
|
+
#desc "project", "View available projects."
|
|
114
|
+
#def project
|
|
115
|
+
# # API descriptor
|
|
116
|
+
#end
|
|
117
|
+
|
|
118
|
+
desc "service-module", "DTK definitions for modeling/defining distributed applications and services."
|
|
119
|
+
def service_module
|
|
120
|
+
# API descriptor
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# TODO: not supported yet
|
|
124
|
+
# desc "state-change", "Commands to query what has been changed."
|
|
125
|
+
# def state_change
|
|
126
|
+
# # API descriptor
|
|
127
|
+
# end
|
|
128
|
+
|
|
129
|
+
# desc "task", "Commands to list and view current and past tasks."
|
|
130
|
+
# def task
|
|
131
|
+
# # API descriptor
|
|
132
|
+
# end
|
|
133
|
+
|
|
134
|
+
if ::DTK::Configuration.get(:development_mode)
|
|
135
|
+
desc "developer", "DEV tools only available to developers."
|
|
136
|
+
def developer
|
|
137
|
+
# API descriptor
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
if ::DTK::Configuration.get(:development_mode)
|
|
142
|
+
desc "provider", "Manage infrastructure providers and deployment targets (ie: EC2 and us-east)"
|
|
143
|
+
def provider
|
|
144
|
+
# API descriptor
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# we do not need help here
|
|
149
|
+
remove_task(:help,{:undefine => false})
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
end
|