dtk-shell 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,59 @@
|
|
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 BaseCommandHelper
|
20
|
+
def initialize(command,context_params=nil)
|
21
|
+
@command = command
|
22
|
+
@context_params = context_params
|
23
|
+
@options = command.options
|
24
|
+
end
|
25
|
+
|
26
|
+
def print_external_dependencies(external_dependencies, location)
|
27
|
+
ambiguous = external_dependencies["ambiguous"]||[]
|
28
|
+
amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
|
29
|
+
inconsistent = external_dependencies["inconsistent"]||[]
|
30
|
+
possibly_missing = external_dependencies["possibly_missing"]||[]
|
31
|
+
|
32
|
+
OsUtil.print("There are inconsistent module dependencies mentioned #{location}: #{inconsistent.join(', ')}", :red) unless inconsistent.empty?
|
33
|
+
OsUtil.print("There are missing module dependencies mentioned #{location}: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
|
34
|
+
OsUtil.print("There are ambiguous module dependencies mentioned #{location}: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) if ambiguous && !ambiguous.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def context_params()
|
39
|
+
@context_params || raise(DtkError, "[ERROR] @context_params is nil")
|
40
|
+
end
|
41
|
+
|
42
|
+
def retrieve_arguments(mapping, method_info = nil)
|
43
|
+
context_params.retrieve_arguments(mapping, method_info || @command.method_argument_names)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_namespace_and_name(*args)
|
47
|
+
@command.get_namespace_and_name(*args)
|
48
|
+
end
|
49
|
+
|
50
|
+
def rest_url(*args)
|
51
|
+
@command.rest_url(*args)
|
52
|
+
end
|
53
|
+
|
54
|
+
def post(*args)
|
55
|
+
@command.post(*args)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,82 @@
|
|
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
|
+
dtk_require_common_commands('thor/common')
|
19
|
+
module DTK::Client
|
20
|
+
module CloneMixin
|
21
|
+
extend Console
|
22
|
+
include CommonMixin
|
23
|
+
##
|
24
|
+
#
|
25
|
+
# internal_trigger: this flag means that other method (internal) has trigger this.
|
26
|
+
# This will change behaviour of method
|
27
|
+
# module_type: will be :component_module or :service_module
|
28
|
+
|
29
|
+
def clone_aux(module_type, module_id, version, internal_trigger = false, omit_output = false, opts = {})
|
30
|
+
# if version = base do not clone latest, just base
|
31
|
+
if version && version.eql?('base')
|
32
|
+
version = nil
|
33
|
+
opts[:use_latest] = false
|
34
|
+
end
|
35
|
+
|
36
|
+
module_name, module_namespace, repo_url, branch, not_ok_response, version = workspace_branch_info(module_type, module_id, version, opts)
|
37
|
+
return not_ok_response if not_ok_response
|
38
|
+
|
39
|
+
# clone base version first if not cloned already
|
40
|
+
clone_base_aux(module_type, module_id, "#{module_namespace}:#{module_name}") if opts[:use_latest] && version
|
41
|
+
|
42
|
+
# TODO: DTK-2358: comenyed out because causing error in this jira; see if need to put in in revisedform to avoid this error; below is checking wromg thing ( module_location is set to wromg thing to check)
|
43
|
+
# module_location = OsUtil.module_location(module_type, "#{module_namespace}:#{module_name}", version)
|
44
|
+
# raise DTK::Client::DtkValidationError, "#{module_type.to_s.gsub('_',' ').capitalize} '#{module_name}#{version && "-#{version}"}' already cloned!" if File.directory?(module_location) && !opts[:skip_if_exist_check]
|
45
|
+
|
46
|
+
full_module_name = ModuleUtil.resolve_name(module_name, module_namespace)
|
47
|
+
|
48
|
+
# TODO: should we use instead Helper(:git_repo).create_clone_from_optional_branch
|
49
|
+
response = Helper(:git_repo).create_clone_with_branch(module_type,module_name,repo_url,branch,version,module_namespace,opts)
|
50
|
+
|
51
|
+
if response.ok?
|
52
|
+
print_name = "Module '#{full_module_name}'"
|
53
|
+
print_name << " version '#{version}'" if version
|
54
|
+
puts "#{print_name} has been successfully cloned!" unless omit_output
|
55
|
+
# when puppet forge import, print successfully imported instead of cloned
|
56
|
+
DTK::Client::OsUtil.print("#{print_name} has been successfully imported!", :yellow) if omit_output && opts[:print_imported]
|
57
|
+
unless internal_trigger
|
58
|
+
if Console.confirmation_prompt("Would you like to edit module now?")
|
59
|
+
context_params_for_module = create_context_for_module(full_module_name, module_type)
|
60
|
+
return edit(context_params_for_module)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
response
|
66
|
+
end
|
67
|
+
|
68
|
+
# clone base module version
|
69
|
+
def clone_base_aux(module_type, module_id, full_module_name)
|
70
|
+
base_module_location = OsUtil.module_location(module_type, full_module_name, nil)
|
71
|
+
unless File.directory?(base_module_location)
|
72
|
+
clone_aux(module_type, module_id, nil, true)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_context_for_module(full_module_name, module_type)
|
77
|
+
context_params_for_module = DTK::Shell::ContextParams.new
|
78
|
+
context_params_for_module.add_context_to_params(full_module_name, module_type.to_s.gsub!(/\_/,'-').to_sym, full_module_name)
|
79
|
+
return context_params_for_module
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,88 @@
|
|
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
|
+
module CommonMixin
|
20
|
+
private
|
21
|
+
# returns module_name, module_namespace, repo_url, branch, not_ok_response( only if error)
|
22
|
+
def workspace_branch_info(module_type, module_id, version, opts={})
|
23
|
+
# shortcut if have info about workspace branch already
|
24
|
+
if info = opts[:workspace_branch_info]
|
25
|
+
name_or_full_module_name = info[:module_name]
|
26
|
+
module_namespace, module_name = ModuleUtil.full_module_name_parts?(name_or_full_module_name)
|
27
|
+
module_namespace ||= info[:module_namespace]
|
28
|
+
ret = [module_name, module_namespace, info[:repo_url], info[:branch]]
|
29
|
+
unless ret.find{|r|r.nil?}
|
30
|
+
return ret
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# if 'base' returned as version set to nil; 'base' = 'master' = nil
|
35
|
+
version = nil if version == 'base'
|
36
|
+
|
37
|
+
post_body = get_workspace_branch_info_post_body(module_type, module_id, version, opts)
|
38
|
+
response = post(rest_url("#{module_type}/get_workspace_branch_info"),post_body)
|
39
|
+
unless response.ok?
|
40
|
+
ret = [nil, nil, nil, nil, response, nil]
|
41
|
+
else
|
42
|
+
m_name, m_namespace, repo_url, w_branch, version = response.data(:module_name, :module_namespace, :repo_url, :workspace_branch, :version)
|
43
|
+
ret = [m_name, m_namespace, repo_url, w_branch, nil]
|
44
|
+
ret << version if opts[:use_latest]
|
45
|
+
end
|
46
|
+
ret
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_workspace_branch_info_post_body(module_type, module_id, version_explicit, opts={})
|
50
|
+
id_field = "#{module_type}_id"
|
51
|
+
post_body = {
|
52
|
+
id_field => module_id
|
53
|
+
}
|
54
|
+
assembly_module = opts[:assembly_module]
|
55
|
+
if version = version_explicit||(assembly_module && assembly_module[:version])
|
56
|
+
post_body.merge!(:version => version)
|
57
|
+
end
|
58
|
+
if assembly_module
|
59
|
+
post_body.merge!(:assembly_module => true,:assembly_name => assembly_module[:assembly_name])
|
60
|
+
end
|
61
|
+
if use_latest = opts[:use_latest]
|
62
|
+
post_body.merge!(:use_latest => use_latest)
|
63
|
+
end
|
64
|
+
post_body
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_remote_module_info_aux(module_type, module_id, remote_namespace, version=nil, module_refs_content=nil, local_namespace=nil)
|
68
|
+
id_field = "#{module_type}_id"
|
69
|
+
rsa_pub_value = SSHUtil.rsa_pub_key_content()
|
70
|
+
|
71
|
+
post_body = {
|
72
|
+
id_field => module_id,
|
73
|
+
:rsa_pub_key => rsa_pub_value,
|
74
|
+
:access_rights => "rw",
|
75
|
+
:action => "push"
|
76
|
+
}
|
77
|
+
post_body.merge!(:version => version) if version
|
78
|
+
post_body.merge!(:remote_namespace => remote_namespace) if remote_namespace
|
79
|
+
post_body.merge!(:local_namespace => local_namespace) if local_namespace
|
80
|
+
post_body.merge!(:module_ref_content => module_refs_content) if module_refs_content && !module_refs_content.empty?
|
81
|
+
|
82
|
+
response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
83
|
+
RemoteDependencyUtil.print_dependency_warnings(response)
|
84
|
+
response
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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
|
+
module Commands
|
20
|
+
module Common
|
21
|
+
class Base
|
22
|
+
def initialize(command_base,context_params)
|
23
|
+
@command_base = command_base
|
24
|
+
@context_params = context_params
|
25
|
+
end
|
26
|
+
private
|
27
|
+
def retrieve_arguments(mapping)
|
28
|
+
@context_params.retrieve_arguments(mapping,@command_base.method_argument_names())
|
29
|
+
end
|
30
|
+
|
31
|
+
def retrieve_option_hash(option_list)
|
32
|
+
ret = Hash.new
|
33
|
+
option_values = @context_params.retrieve_thor_options(option_list,@command_base.options)
|
34
|
+
option_values.each_with_index do |val,i|
|
35
|
+
unless val.nil?
|
36
|
+
key = option_list[i].to_s.gsub(/\!$/,'').to_sym
|
37
|
+
ret.merge!(key => val)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
ret
|
41
|
+
end
|
42
|
+
|
43
|
+
def post(url_path,body=nil)
|
44
|
+
@command_base.post(@command_base.rest_url(url_path),body)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,70 @@
|
|
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
|
+
dtk_require('common_base')
|
19
|
+
module DTK; module Client; module Commands::Common
|
20
|
+
class CreateTarget < Base
|
21
|
+
# option_list is of form [:provider!, :region, :keypair, :security_group!] indcating what is optional and what is required
|
22
|
+
def execute(type, option_list)
|
23
|
+
# we use :target_id but that will return provider_id (another name for target template ID)
|
24
|
+
target_name = retrieve_arguments([:option_1])
|
25
|
+
iaas_properties = iaas_properties(type,option_list)
|
26
|
+
provider = iaas_properties.delete(:provider)
|
27
|
+
post_body = {
|
28
|
+
:type => type.to_s,
|
29
|
+
:provider_id => provider,
|
30
|
+
:iaas_properties => iaas_properties
|
31
|
+
}
|
32
|
+
|
33
|
+
# cleanup for target name not being sterilazied correctly
|
34
|
+
post_body.merge!(:target_name => target_name.split(' ').first) if target_name
|
35
|
+
|
36
|
+
post 'target/create', post_body
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def iaas_properties(type, option_list)
|
41
|
+
iaas_properties = retrieve_option_hash(option_list)
|
42
|
+
special_processing_security_groups!(iaas_properties)
|
43
|
+
special_processing_region!(iaas_properties)
|
44
|
+
iaas_properties
|
45
|
+
end
|
46
|
+
|
47
|
+
def special_processing_region!(iaas_properties)
|
48
|
+
if region = iaas_properties[:region]
|
49
|
+
Shell::InteractiveWizard.validate_region(region)
|
50
|
+
end
|
51
|
+
iaas_properties
|
52
|
+
end
|
53
|
+
|
54
|
+
def special_processing_security_groups!(iaas_properties)
|
55
|
+
if security_group = iaas_properties[:security_group]
|
56
|
+
if security_group.end_with?(',')
|
57
|
+
raise DtkValidationError.new("Multiple security groups should be separated with ',' and without spaces between them (e.g. --security_groups gr1,gr2,gr3,...) ")
|
58
|
+
end
|
59
|
+
security_groups = security_group.split(',')
|
60
|
+
|
61
|
+
unless security_groups.empty? || security_groups.size==1
|
62
|
+
iaas_properties.delete(:security_group)
|
63
|
+
iaas_properties.merge!(:security_group_set => security_groups)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
iaas_properties
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end; end; end
|
@@ -0,0 +1,255 @@
|
|
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
|
+
dtk_require_common_commands('thor/clone')
|
19
|
+
dtk_require_common_commands('thor/push_clone_changes')
|
20
|
+
dtk_require_common_commands('thor/pull_clone_changes')
|
21
|
+
dtk_require_common_commands('thor/reparse')
|
22
|
+
require 'yaml'
|
23
|
+
|
24
|
+
module DTK::Client
|
25
|
+
module EditMixin
|
26
|
+
include CloneMixin
|
27
|
+
include PushCloneChangesMixin
|
28
|
+
include PullCloneChangesMixin
|
29
|
+
include ReparseMixin
|
30
|
+
|
31
|
+
##
|
32
|
+
#
|
33
|
+
# module_type: will be one of
|
34
|
+
# :component_module
|
35
|
+
# :service_module
|
36
|
+
def edit_aux(module_type,module_id,module_name,version,opts={})
|
37
|
+
module_location = OsUtil.module_location(module_type,module_name,version,opts)
|
38
|
+
|
39
|
+
pull_if_needed = opts[:pull_if_needed]
|
40
|
+
# check if there is repository cloned
|
41
|
+
unless File.directory?(module_location)
|
42
|
+
if opts[:automatically_clone] or Console.confirmation_prompt("Edit not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
|
43
|
+
internal_trigger = true
|
44
|
+
omit_output = true
|
45
|
+
response = clone_aux(module_type,module_id,version,internal_trigger,omit_output,opts)
|
46
|
+
# if error return
|
47
|
+
return response unless response.ok?
|
48
|
+
pull_if_needed = false
|
49
|
+
else
|
50
|
+
# user choose not to clone needed module
|
51
|
+
return
|
52
|
+
end
|
53
|
+
end
|
54
|
+
# here we should have desired module cloned
|
55
|
+
|
56
|
+
if pull_if_needed
|
57
|
+
response = pull_clone_changes?(module_type,module_id,version,opts)
|
58
|
+
return response unless response.ok?
|
59
|
+
end
|
60
|
+
grit_adapter = Helper(:git_repo).create(module_location)
|
61
|
+
if edit_info = opts[:edit_file]
|
62
|
+
#TODO: cleanup so dont need :base_file_name
|
63
|
+
file_to_edit =
|
64
|
+
if edit_info.kind_of?(String)
|
65
|
+
edit_info
|
66
|
+
else #edit_info.kind_of?(Hash) and has key :base_file_name
|
67
|
+
base_file = edit_info[:base_file_name]
|
68
|
+
(File.exists?("#{module_location}/#{base_file}.yaml") ? "#{base_file}.yaml" : "#{base_file}.json")
|
69
|
+
end
|
70
|
+
OsUtil.edit("#{module_location}/#{file_to_edit}")
|
71
|
+
OsUtil.print("If you want to use different editor please set environment variable EDITOR and log back into dtk-shell!", :yellow) unless ENV['EDITOR']
|
72
|
+
else
|
73
|
+
Console.unix_shell(module_location, module_id, module_type, version)
|
74
|
+
end
|
75
|
+
|
76
|
+
unless grit_adapter.repo_exists?
|
77
|
+
puts "Local module has been removed, skipping changes."
|
78
|
+
return Response::Ok.new()
|
79
|
+
end
|
80
|
+
|
81
|
+
unless grit_adapter.changed?
|
82
|
+
puts "No changes to repository"
|
83
|
+
return Response::Ok.new()
|
84
|
+
end
|
85
|
+
|
86
|
+
unless file_to_edit
|
87
|
+
grit_adapter.print_status
|
88
|
+
end
|
89
|
+
|
90
|
+
# check to see if auto commit flag
|
91
|
+
auto_commit = ::DTK::Configuration.get(:auto_commit_changes)
|
92
|
+
confirmed_ok = false
|
93
|
+
|
94
|
+
# if there is no auto commit ask for confirmation
|
95
|
+
unless auto_commit
|
96
|
+
confirm_msg =
|
97
|
+
if file_to_edit
|
98
|
+
"Would you like to commit changes to the file?"
|
99
|
+
else
|
100
|
+
"Would you like to commit ALL the changes?"
|
101
|
+
end
|
102
|
+
confirmed_ok = Console.confirmation_prompt_simple(confirm_msg)
|
103
|
+
end
|
104
|
+
if (auto_commit || confirmed_ok)
|
105
|
+
if auto_commit
|
106
|
+
puts "[NOTICE] You are using auto-commit option, all changes you have made will be commited."
|
107
|
+
end
|
108
|
+
commit_msg = user_input("Commit message")
|
109
|
+
|
110
|
+
# remove qoutes if they are not closed properly in commit_msg
|
111
|
+
commit_msg.gsub!(/\"/,'') unless commit_msg.count('"') % 2 ==0
|
112
|
+
|
113
|
+
internal_trigger=true
|
114
|
+
reparse_aux(module_location)
|
115
|
+
|
116
|
+
# use_impl_id - if edit-component-module which has version use impl_id from assembly--<assembly_name> version of component instance
|
117
|
+
opts.merge!(:force_parse => true, :update_from_includes => true, :print_dependencies => true, :use_impl_id => true)
|
118
|
+
response = push_clone_changes_aux(module_type,module_id,version,commit_msg,internal_trigger,opts)
|
119
|
+
|
120
|
+
# if error return
|
121
|
+
return response unless response.ok?
|
122
|
+
end
|
123
|
+
|
124
|
+
#TODO: temporary took out; wil put back in
|
125
|
+
#puts "DTK SHELL TIP: Adding the client configuration parameter <config param name>=true will have the client automatically commit each time you exit edit mode" unless auto_commit
|
126
|
+
Response::Ok.new()
|
127
|
+
end
|
128
|
+
|
129
|
+
# returns text string with edited yaml content
|
130
|
+
def attributes_editor(yaml_input)
|
131
|
+
dtk_folder = OsUtil.dtk_local_folder
|
132
|
+
file_path = "#{dtk_folder}/temp_attrs.yaml"
|
133
|
+
File.open(file_path, 'w'){|f| f << yaml_input}
|
134
|
+
OsUtil.edit(file_path)
|
135
|
+
OsUtil.print("If you want to use different editor please set environment variable EDITOR and log back into dtk-shell!", :yellow) unless ENV['EDITOR']
|
136
|
+
edited_yaml = File.open(file_path,'r'){|f|f.read}
|
137
|
+
File.unlink(file_path)
|
138
|
+
edited_yaml
|
139
|
+
end
|
140
|
+
private
|
141
|
+
# removes any nil values and returns hash; also modifies any term that does not serialize
|
142
|
+
def post_process(object)
|
143
|
+
ret = Hash.new
|
144
|
+
if object.kind_of?(Hash)
|
145
|
+
post_process__hash(object)
|
146
|
+
elsif object.kind_of?(Array)
|
147
|
+
post_process__array(object)
|
148
|
+
elsif object.kind_of?(FalseClass)
|
149
|
+
Response::Term::Boolean.false
|
150
|
+
else
|
151
|
+
object
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def post_process__hash(hash)
|
156
|
+
ret = Hash.new
|
157
|
+
hash.each_pair do |k,v|
|
158
|
+
processed_val = post_process(v)
|
159
|
+
#processed_val can be false so explicitly checking against nil
|
160
|
+
unless processed_val.nil?
|
161
|
+
ret.merge!(k => processed_val)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
ret
|
165
|
+
end
|
166
|
+
|
167
|
+
def post_process__array(array)
|
168
|
+
ret = Array.new
|
169
|
+
array.each do |a|
|
170
|
+
# explicit nil not removed
|
171
|
+
if a.nil?
|
172
|
+
ret << Response::Term.nil()
|
173
|
+
else
|
174
|
+
processed_val = post_process(a)
|
175
|
+
#processed_val can be false so explicitly checking against nil
|
176
|
+
unless processed_val.nil?
|
177
|
+
ret << processed_val
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
ret
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
=begin
|
188
|
+
# TODO: probably deprecate
|
189
|
+
def attribute_header()
|
190
|
+
header_string =
|
191
|
+
"#############################\n#### REQUIRED ATTRIBUTES\n#############################\n#\n"
|
192
|
+
end
|
193
|
+
# TODO: probably deprecate
|
194
|
+
def attributes_editor_old_form(attributes,format)
|
195
|
+
if (format.eql?('yaml'))
|
196
|
+
dtk_folder = OsUtil.dtk_local_folder
|
197
|
+
file_path = "#{dtk_folder}/temp_attrs.yaml"
|
198
|
+
|
199
|
+
first_iteration_keys, first_iteration_values = [], []
|
200
|
+
second_iteration_keys, second_iteration_values = [], []
|
201
|
+
required_attributes = []
|
202
|
+
|
203
|
+
attribute_pairs = YAML.load(attributes)
|
204
|
+
|
205
|
+
attribute_pairs.each do |k,v|
|
206
|
+
first_iteration_keys << k
|
207
|
+
|
208
|
+
#prepare required attributes for editor display
|
209
|
+
if v.eql?("*REQUIRED*")
|
210
|
+
required_attributes << k
|
211
|
+
attribute_pairs[k] = nil
|
212
|
+
v = nil
|
213
|
+
end
|
214
|
+
|
215
|
+
first_iteration_values << v
|
216
|
+
end
|
217
|
+
|
218
|
+
File.open(file_path, 'w') do |out|
|
219
|
+
# print out required attributes
|
220
|
+
unless required_attributes.empty?
|
221
|
+
out.write(attribute_header())
|
222
|
+
required_attributes.each do |req_attr|
|
223
|
+
out.write("##{req_attr}\n")
|
224
|
+
end
|
225
|
+
out.write("#\n")
|
226
|
+
end
|
227
|
+
|
228
|
+
YAML.dump(attribute_pairs, out)
|
229
|
+
end
|
230
|
+
|
231
|
+
OsUtil.edit(file_path)
|
232
|
+
OsUtil.print("If you want to use different editor please set environment variable EDITOR and log back into dtk-shell!", :yellow) unless ENV['EDITOR']
|
233
|
+
begin
|
234
|
+
edited = YAML.load_file(file_path)
|
235
|
+
rescue Psych::SyntaxError => e
|
236
|
+
raise DSLParsing::YAMLParsing.new("YAML parsing error #{e} in file",file_path)
|
237
|
+
end
|
238
|
+
|
239
|
+
edited.each do |k,v|
|
240
|
+
second_iteration_keys << k
|
241
|
+
second_iteration_values << v
|
242
|
+
end
|
243
|
+
|
244
|
+
unless first_iteration_keys == second_iteration_keys
|
245
|
+
edited_keys = second_iteration_keys.select{|k| !first_iteration_keys.include?(k)}
|
246
|
+
raise DtkValidationError, "You have changed key(s) '#{edited_keys}'. We do not support key editing yet!"
|
247
|
+
end
|
248
|
+
|
249
|
+
raise DtkValidationError, "No attribute changes have been made." if ((first_iteration_keys == second_iteration_keys) && (first_iteration_values == second_iteration_values))
|
250
|
+
edited
|
251
|
+
else
|
252
|
+
raise DtkValidationError, "Unsupported format type '#{format.to_s}'!"
|
253
|
+
end
|
254
|
+
end
|
255
|
+
=end
|