dtk-client 0.5.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +5 -0
- data/Gemfile_dev +12 -0
- data/README.md +78 -0
- data/bin/dtk +54 -0
- data/bin/dtk-shell +15 -0
- data/dtk-client.gemspec +49 -0
- data/lib/auxiliary.rb +13 -0
- data/lib/bundler_monkey_patch.rb +9 -0
- data/lib/client.rb +48 -0
- data/lib/command_helper.rb +16 -0
- data/lib/command_helpers/git_repo.rb +391 -0
- data/lib/command_helpers/jenkins_client/config_xml.rb +271 -0
- data/lib/command_helpers/jenkins_client.rb +91 -0
- data/lib/command_helpers/service_importer.rb +99 -0
- data/lib/command_helpers/service_link.rb +18 -0
- data/lib/command_helpers/ssh_processing.rb +43 -0
- data/lib/commands/common/thor/assembly_workspace.rb +1089 -0
- data/lib/commands/common/thor/clone.rb +39 -0
- data/lib/commands/common/thor/common.rb +34 -0
- data/lib/commands/common/thor/edit.rb +168 -0
- data/lib/commands/common/thor/list_diffs.rb +84 -0
- data/lib/commands/common/thor/pull_clone_changes.rb +11 -0
- data/lib/commands/common/thor/pull_from_remote.rb +99 -0
- data/lib/commands/common/thor/purge_clone.rb +26 -0
- data/lib/commands/common/thor/push_clone_changes.rb +45 -0
- data/lib/commands/common/thor/push_to_remote.rb +45 -0
- data/lib/commands/common/thor/reparse.rb +36 -0
- data/lib/commands/common/thor/set_required_params.rb +29 -0
- data/lib/commands/common/thor/task_status.rb +81 -0
- data/lib/commands/thor/account.rb +213 -0
- data/lib/commands/thor/assembly.rb +329 -0
- data/lib/commands/thor/attribute.rb +62 -0
- data/lib/commands/thor/component.rb +52 -0
- data/lib/commands/thor/component_module.rb +829 -0
- data/lib/commands/thor/component_template.rb +153 -0
- data/lib/commands/thor/dependency.rb +18 -0
- data/lib/commands/thor/developer.rb +105 -0
- data/lib/commands/thor/dtk.rb +117 -0
- data/lib/commands/thor/library.rb +107 -0
- data/lib/commands/thor/node.rb +411 -0
- data/lib/commands/thor/node_group.rb +211 -0
- data/lib/commands/thor/node_template.rb +88 -0
- data/lib/commands/thor/project.rb +17 -0
- data/lib/commands/thor/provider.rb +155 -0
- data/lib/commands/thor/repo.rb +35 -0
- data/lib/commands/thor/service.rb +656 -0
- data/lib/commands/thor/service_module.rb +806 -0
- data/lib/commands/thor/state_change.rb +10 -0
- data/lib/commands/thor/target.rb +94 -0
- data/lib/commands/thor/task.rb +100 -0
- data/lib/commands/thor/utils.rb +4 -0
- data/lib/commands/thor/workspace.rb +437 -0
- data/lib/commands.rb +40 -0
- data/lib/config/cacert.pem +3785 -0
- data/lib/config/client.conf.header +18 -0
- data/lib/config/configuration.rb +82 -0
- data/lib/config/default.conf +14 -0
- data/lib/config/disk_cacher.rb +60 -0
- data/lib/configurator.rb +92 -0
- data/lib/context_router.rb +23 -0
- data/lib/core.rb +460 -0
- data/lib/domain/git_adapter.rb +221 -0
- data/lib/domain/response.rb +234 -0
- data/lib/dtk-client/version.rb +3 -0
- data/lib/dtk_constants.rb +23 -0
- data/lib/dtk_logger.rb +96 -0
- data/lib/error.rb +74 -0
- data/lib/git-logs/git.log +0 -0
- data/lib/parser/adapters/option_parser.rb +53 -0
- data/lib/parser/adapters/thor/common_option_defs.rb +12 -0
- data/lib/parser/adapters/thor.rb +509 -0
- data/lib/require_first.rb +87 -0
- data/lib/search_hash.rb +27 -0
- data/lib/shell/context.rb +975 -0
- data/lib/shell/context_aux.rb +29 -0
- data/lib/shell/domain.rb +447 -0
- data/lib/shell/header_shell.rb +27 -0
- data/lib/shell/help_monkey_patch.rb +221 -0
- data/lib/shell/interactive_wizard.rb +233 -0
- data/lib/shell/parse_monkey_patch.rb +22 -0
- data/lib/shell/status_monitor.rb +105 -0
- data/lib/shell.rb +219 -0
- data/lib/util/console.rb +143 -0
- data/lib/util/dtk_puppet.rb +46 -0
- data/lib/util/os_util.rb +265 -0
- data/lib/view_processor/augmented_simple_list.rb +27 -0
- data/lib/view_processor/hash_pretty_print.rb +106 -0
- data/lib/view_processor/simple_list.rb +139 -0
- data/lib/view_processor/table_print.rb +277 -0
- data/lib/view_processor.rb +112 -0
- data/puppet/manifests/init.pp +72 -0
- data/puppet/manifests/params.pp +16 -0
- data/puppet/r8meta.puppet.yml +18 -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/assembly_spec.rb +50 -0
- data/spec/assembly_template_spec.rb +51 -0
- data/spec/component_template_spec.rb +40 -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 +105 -0
- data/spec/module_spec.rb +35 -0
- data/spec/node_spec.rb +43 -0
- data/spec/node_template_spec.rb +25 -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_spec.rb +41 -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 +351 -0
@@ -0,0 +1,153 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
class ComponentTemplate < CommandBaseThor
|
3
|
+
|
4
|
+
def self.pretty_print_cols()
|
5
|
+
PPColumns.get(:component)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.valid_children()
|
9
|
+
# Amar: attribute context commented out per Rich suggeston
|
10
|
+
#[:attribute]
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
|
14
|
+
# this includes children of children
|
15
|
+
def self.all_children()
|
16
|
+
# Amar: attribute context commented out per Rich suggeston
|
17
|
+
#[:attribute]
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.valid_child?(name_of_sub_context)
|
22
|
+
return ComponentTemplate.valid_children().include?(name_of_sub_context.to_sym)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.validation_list(context_params)
|
26
|
+
if context_params.is_there_identifier?("component-module")
|
27
|
+
component_module_id = context_params.retrieve_arguments([:component_module_id!])
|
28
|
+
res = get_cached_response(:component_template, "component_module/info_about", { :component_module_id => component_module_id, :about => :components})
|
29
|
+
else
|
30
|
+
get_cached_response(:component_template, "component/list", {:subtype => 'template'})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.override_allowed_methods()
|
35
|
+
return DTK::Shell::OverrideTasks.new({})
|
36
|
+
# Amar: attribute context commented out per Rich suggeston
|
37
|
+
#return DTK::Shell::OverrideTasks.new(
|
38
|
+
# {
|
39
|
+
# :command_only => {
|
40
|
+
# :attribute => [
|
41
|
+
# ['list',"list","List attributes for given component"]
|
42
|
+
# ]
|
43
|
+
# },
|
44
|
+
# :identifier_only => {
|
45
|
+
# :attribute => [
|
46
|
+
# ['list',"list","List attributes for given component"]
|
47
|
+
# ]
|
48
|
+
# }
|
49
|
+
#
|
50
|
+
#})
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "COMPONENT-TEMPLATE-NAME/ID info", "Get information about given component template."
|
54
|
+
method_option :list, :type => :boolean, :default => false
|
55
|
+
def info(context_params)
|
56
|
+
component_id = context_params.retrieve_arguments([:component_template_id!],method_argument_names)
|
57
|
+
data_type = :component
|
58
|
+
|
59
|
+
post_body = {
|
60
|
+
:component_id => component_id,
|
61
|
+
:subtype => 'template'
|
62
|
+
}
|
63
|
+
response = post rest_url("component/info"), post_body
|
64
|
+
|
65
|
+
response.render_table(data_type) unless options.list?
|
66
|
+
|
67
|
+
return response
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "COMPONENT-TEMPLATE-NAME/ID list-nodes [--module MODULE-NAME]", "List all nodes for given component template. Optional filter by modul name."
|
71
|
+
method_option :list, :type => :boolean, :default => false
|
72
|
+
method_option "module",:aliases => "-m" ,
|
73
|
+
:type => :string,
|
74
|
+
:banner => "MODULE-LIST-FILTER",
|
75
|
+
:desc => "Module list filter"
|
76
|
+
def list_nodes(context_params)
|
77
|
+
context_params.method_arguments = ["nodes"]
|
78
|
+
list(context_params)
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "list [--module MODULE-NAME]", "List all component templates. Optional filter by module name."
|
82
|
+
method_option :list, :type => :boolean, :default => false
|
83
|
+
method_option "module",:aliases => "-m" ,
|
84
|
+
:type => :string,
|
85
|
+
:banner => "MODULE-LIST-FILTER",
|
86
|
+
:desc => "Module list filter"
|
87
|
+
def list(context_params)
|
88
|
+
component_id, about, module_filter = context_params.retrieve_arguments([:component_template_id,:option_1,:option_1],method_argument_names)
|
89
|
+
about ||= 'none'
|
90
|
+
data_type = :component
|
91
|
+
|
92
|
+
# Case when user provided '--module' / '-m' 'MODUL-NAME'
|
93
|
+
if options.module
|
94
|
+
# Special case when user sends --module; until now --OPTION didn't have value attached to it
|
95
|
+
if options.module.eql?("module")
|
96
|
+
module_id = module_filter
|
97
|
+
else
|
98
|
+
module_id = options.module
|
99
|
+
end
|
100
|
+
|
101
|
+
context_params_for_service = DTK::Shell::ContextParams.new
|
102
|
+
context_params_for_service.add_context_to_params("component_module", "component_module", module_id)
|
103
|
+
|
104
|
+
response = DTK::Client::ContextRouter.routeTask("component_module", "list_components", context_params_for_service, @conn)
|
105
|
+
|
106
|
+
else # Case without module filter
|
107
|
+
|
108
|
+
post_body = {
|
109
|
+
:component_id => component_id,
|
110
|
+
:subtype => 'template',
|
111
|
+
:about => about
|
112
|
+
}
|
113
|
+
|
114
|
+
case about
|
115
|
+
when 'none'
|
116
|
+
response = post rest_url("component/list")
|
117
|
+
when 'nodes'
|
118
|
+
response = post rest_url("component/list"), post_body
|
119
|
+
else
|
120
|
+
raise_validation_error_method_usage('list')
|
121
|
+
end
|
122
|
+
|
123
|
+
response.render_table(data_type) unless options.list?
|
124
|
+
end
|
125
|
+
|
126
|
+
return response
|
127
|
+
end
|
128
|
+
|
129
|
+
desc "COMPONENT-TEMPLATE-NAME/ID stage NODE-NAME/ID", "Stage indentified node for given component template."
|
130
|
+
method_option :list, :type => :boolean, :default => false
|
131
|
+
def stage(context_params)
|
132
|
+
component_id, node_id = context_params.retrieve_arguments([:component_template_id!,:option_1!],method_argument_names)
|
133
|
+
data_type = :component
|
134
|
+
|
135
|
+
post_body = {
|
136
|
+
:component_id => component_id
|
137
|
+
}
|
138
|
+
|
139
|
+
unless node_id.nil?
|
140
|
+
post_body.merge!({:node_id => node_id})
|
141
|
+
end
|
142
|
+
|
143
|
+
response = post rest_url("component/stage"), post_body
|
144
|
+
@@invalidate_map << :component_template
|
145
|
+
|
146
|
+
response.render_table(data_type) unless options.list?
|
147
|
+
response
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
class Dependency < CommandBaseThor
|
3
|
+
desc "add-component COMPONENT-ID OTHER-COMPONENT-ID","Add before/require constraint"
|
4
|
+
def add_component(context_params)
|
5
|
+
component_id, other_component_id = context_params.retrieve_arguments([:option_1!,:option_2!],method_argument_names)
|
6
|
+
post_body = {
|
7
|
+
:component_id => component_id,
|
8
|
+
:other_component_id => other_component_id,
|
9
|
+
:type => "required by"
|
10
|
+
}
|
11
|
+
response = post rest_url("dependency/add_component_dependency"), post_body
|
12
|
+
@@invalidate_map << :component_template
|
13
|
+
|
14
|
+
return response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module DTK::Client
|
4
|
+
class Developer < CommandBaseThor
|
5
|
+
|
6
|
+
MATCH_FILE_NAME = /[a-zA-Z0-9_]+\.[a-zA-Z]+$/
|
7
|
+
GIT_LOG_LOCATION = File.expand_path('../../../lib/git-logs/git.log', File.dirname(__FILE__))
|
8
|
+
PROJECT_ROOT = File.expand_path('../../../', File.dirname(__FILE__))
|
9
|
+
|
10
|
+
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."
|
11
|
+
def upload_agent(context_params)
|
12
|
+
agent, node_pattern = context_params.retrieve_arguments([:option_1!, :option_2!],method_argument_names)
|
13
|
+
|
14
|
+
nodes = post rest_url("node/list"), { :is_list_all => true }
|
15
|
+
|
16
|
+
ids = []
|
17
|
+
# get all nodes which id starts with node_pattern
|
18
|
+
nodes["data"].collect{|a| ids<<a["id"].to_i if a["id"].to_s.start_with?(node_pattern.to_s)}
|
19
|
+
raise DTK::Client::DtkValidationError, "Unable to find nodes to match this pattern: '#{node_pattern}'." if ids.empty?
|
20
|
+
|
21
|
+
# if it doesn't contain extension upload both *.rb and *.ddl
|
22
|
+
files = (agent.match(MATCH_FILE_NAME) ? [agent] : ["#{agent}.rb","#{agent}.ddl"])
|
23
|
+
|
24
|
+
# read require files and encode them
|
25
|
+
request_body = {}
|
26
|
+
files.each do |file_name|
|
27
|
+
raise DTK::Client::DtkError, "Unable to load file: #{file_name}" unless File.exists?(file_name)
|
28
|
+
# reason for this to file dues to previus match
|
29
|
+
agent_name = file_name.match(MATCH_FILE_NAME)[0]
|
30
|
+
File.open(file_name) { |file| request_body.store(agent_name,Base64.encode64(file.read)) }
|
31
|
+
end
|
32
|
+
|
33
|
+
# send as binary post request
|
34
|
+
response = post_file rest_url("developer/inject_agent"), { :agent_files => request_body, :node_pattern => node_pattern, :node_list => ids }
|
35
|
+
puts "Agent uploaded successfully!";return if response.ok?
|
36
|
+
return response
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "remove-from-system SERVICE-NAME", "Removes objects associated with service, but does not destroy target isnatnces"
|
40
|
+
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
41
|
+
def remove_from_system(context_params)
|
42
|
+
assembly_id = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
43
|
+
unless options.force?
|
44
|
+
# Ask user if really want to delete assembly, if not then return to dtk-shell without deleting
|
45
|
+
what = "service"
|
46
|
+
return unless Console.confirmation_prompt("Are you sure you want to remove #{what} '#{assembly_id}' and its nodes from the system"+'?')
|
47
|
+
end
|
48
|
+
|
49
|
+
response = post rest_url("assembly/remove_from_system"), {:assembly_id => assembly_id}
|
50
|
+
# when changing context send request for getting latest assemblies instead of getting from cache
|
51
|
+
@@invalidate_map << :service
|
52
|
+
return response
|
53
|
+
end
|
54
|
+
|
55
|
+
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"
|
56
|
+
def apply_param_set(context_params)
|
57
|
+
assembly_id,path = context_params.retrieve_arguments([:option_1!,:option_2!],method_argument_names)
|
58
|
+
av_pairs = JSON.parse(File.open(path).read)
|
59
|
+
|
60
|
+
av_pairs.each do |a,v|
|
61
|
+
post_body = {
|
62
|
+
:assembly_id => assembly_id,
|
63
|
+
:pattern => a,
|
64
|
+
:value => v
|
65
|
+
}
|
66
|
+
response = post rest_url("assembly/set_attributes"), post_body
|
67
|
+
if response.ok?
|
68
|
+
pp response.data
|
69
|
+
else
|
70
|
+
return response
|
71
|
+
end
|
72
|
+
end
|
73
|
+
Response::Ok.new()
|
74
|
+
end
|
75
|
+
|
76
|
+
desc "commits", "View last commits that went into the gem"
|
77
|
+
def commits(context_params)
|
78
|
+
unless File.file?(GIT_LOG_LOCATION)
|
79
|
+
raise DTK::Client::DtkError, "Git log file not found, contact DTK support team."
|
80
|
+
end
|
81
|
+
|
82
|
+
File.readlines(GIT_LOG_LOCATION).reverse.each do |line|
|
83
|
+
puts line
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
desc "content FILE-NAME", "Get content of file name in DTK Client gem"
|
88
|
+
def content(context_params)
|
89
|
+
file_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
90
|
+
found_files = Dir["#{PROJECT_ROOT}/**/*.*"].select { |fname| fname.end_with?(file_name) }
|
91
|
+
|
92
|
+
if found_files.empty?
|
93
|
+
raise DTK::Client::DtkValidationError, "No files found with name '#{file_name}'."
|
94
|
+
else
|
95
|
+
found_files.each do |fname|
|
96
|
+
header = "*********************** #{fname} ***********************"
|
97
|
+
DTK::Client::OsUtil.print(header, :yellow)
|
98
|
+
puts File.open(fname).readlines
|
99
|
+
DTK::Client::OsUtil.print("*"*header.size, :yellow)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
|
2
|
+
module DTK::Client
|
3
|
+
|
4
|
+
# Following are descriptions of available commands
|
5
|
+
class Dtk < CommandBaseThor
|
6
|
+
|
7
|
+
# entities that are not available on root but later in n-context
|
8
|
+
def self.additional_entities()
|
9
|
+
['target','component','attribute','utils','node','task','component-template','assembly']
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "workspace","Sandbox for development and testing"
|
13
|
+
def workspace
|
14
|
+
# API descriptor, SYM_LINK!
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# NOTE
|
19
|
+
# Following methods are just api descriptors, invocation happens at "bin/dtk" entry point
|
20
|
+
desc "account","Account management for accessing DTK server"
|
21
|
+
def account
|
22
|
+
# API descriptor
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "service","Assembly instances that have been deployed via DTK."
|
26
|
+
def service
|
27
|
+
# API descriptor
|
28
|
+
end
|
29
|
+
|
30
|
+
# desc "assembly","Commands to stage or launch new assemblies and query assembly templates."
|
31
|
+
# def assembly
|
32
|
+
# # API descriptor
|
33
|
+
# end
|
34
|
+
|
35
|
+
#TODO: not exposed
|
36
|
+
#desc "dependency","DESCRIPTION TO BE ADDED."
|
37
|
+
#def dependency
|
38
|
+
# # API descriptor
|
39
|
+
#end
|
40
|
+
|
41
|
+
# desc "library", "Commands to list and query libraries."
|
42
|
+
# def library
|
43
|
+
# # API descriptor
|
44
|
+
# end
|
45
|
+
|
46
|
+
desc "component-module", "DTK definitions for modeling/defining individual configuration components."
|
47
|
+
def component_module
|
48
|
+
# API descriptor
|
49
|
+
end
|
50
|
+
|
51
|
+
# desc "node", "Commands to list, query, and delete/destroy node instances."
|
52
|
+
# def node
|
53
|
+
# # API descriptor
|
54
|
+
# end
|
55
|
+
|
56
|
+
# desc "node-group", "Add/Destroy/List available groups of nodes."
|
57
|
+
# def node_group
|
58
|
+
# # API descriptor
|
59
|
+
# end
|
60
|
+
|
61
|
+
desc "node-template", "Node Templates that map to machine images and containers."
|
62
|
+
def node_template
|
63
|
+
# API descriptor
|
64
|
+
end
|
65
|
+
|
66
|
+
# desc "component-template","Commands to list and query component templates."
|
67
|
+
# def component_template
|
68
|
+
# # API descriptor
|
69
|
+
# end
|
70
|
+
|
71
|
+
#TODO: remove
|
72
|
+
#desc "repo", "Part of dtk client which enables us to sync, destroy, view available repos."
|
73
|
+
#def repo
|
74
|
+
# # API descriptor
|
75
|
+
#end
|
76
|
+
|
77
|
+
#TODO: not supported yet
|
78
|
+
#desc "project", "View available projects."
|
79
|
+
#def project
|
80
|
+
# # API descriptor
|
81
|
+
#end
|
82
|
+
|
83
|
+
desc "service-module", "DTK definitions for modeling/defining distributed applications and services."
|
84
|
+
def service_module
|
85
|
+
# API descriptor
|
86
|
+
end
|
87
|
+
|
88
|
+
# TODO: not supported yet
|
89
|
+
# desc "state-change", "Commands to query what has been changed."
|
90
|
+
# def state_change
|
91
|
+
# # API descriptor
|
92
|
+
# end
|
93
|
+
|
94
|
+
# desc "task", "Commands to list and view current and past tasks."
|
95
|
+
# def task
|
96
|
+
# # API descriptor
|
97
|
+
# end
|
98
|
+
|
99
|
+
if ::DTK::Configuration.get(:development_mode)
|
100
|
+
desc "developer", "DEV tools only available to developers."
|
101
|
+
def developer
|
102
|
+
# API descriptor
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
desc "provider", "Manage infrastructure providers and deployment targets (ie: EC2 and us-east)"
|
108
|
+
def provider
|
109
|
+
# API descriptor
|
110
|
+
end
|
111
|
+
|
112
|
+
# we do not need help here
|
113
|
+
remove_task(:help,{:undefine => false})
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
|
3
|
+
class Library < CommandBaseThor
|
4
|
+
|
5
|
+
def self.pretty_print_cols()
|
6
|
+
PPColumns.get(:library)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.whoami()
|
10
|
+
return :library, "library/list", nil
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "[LIBRARY ID/NAME] info","Info for given library based on specified identifier."
|
14
|
+
def info(context_params)
|
15
|
+
library_id = context_params.retrieve_arguments([:library_id],method_argument_names)
|
16
|
+
not_implemented
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "LIBRARY ID/NAME list-nodes","Show nodes associated with library"
|
20
|
+
def list_nodes(context_params)
|
21
|
+
context_params.method_arguments = ["nodes"]
|
22
|
+
list(context_params)
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "LIBRARY ID/NAME list-components","Show components associated with library"
|
26
|
+
def list_components(context_params)
|
27
|
+
context_params.method_arguments = ["components"]
|
28
|
+
list(context_params)
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "LIBRARY ID/NAME list-assemblies","Show assemblies associated with library"
|
32
|
+
def list_assemblies(context_params)
|
33
|
+
context_params.method_arguments = ["assemblies"]
|
34
|
+
list(context_params)
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "list","Show nodes, components, or assemblies associated with library"
|
38
|
+
def list(context_params)
|
39
|
+
library_id, about = context_params.retrieve_arguments([:library_id, :option_1],method_argument_names||="")
|
40
|
+
if library_id.nil?
|
41
|
+
search_hash = SearchHash.new()
|
42
|
+
search_hash.cols = pretty_print_cols()
|
43
|
+
response = post rest_url("library/list"), search_hash.post_body_hash
|
44
|
+
response.render_table(:library)
|
45
|
+
else
|
46
|
+
# sets data type to be used when printing table
|
47
|
+
case about
|
48
|
+
when "assemblies"
|
49
|
+
data_type = :assembly_template
|
50
|
+
when "nodes"
|
51
|
+
data_type = :node_template
|
52
|
+
when "components"
|
53
|
+
data_type = :component
|
54
|
+
else
|
55
|
+
raise_validation_error_method_usage('list')
|
56
|
+
end
|
57
|
+
|
58
|
+
post_body = {
|
59
|
+
:library_id => library_id,
|
60
|
+
:about => about
|
61
|
+
}
|
62
|
+
response = post rest_url("library/info_about"), post_body
|
63
|
+
response.render_table(data_type)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "[LIBRARY ID/NAME] import-service-module REMOTE-SERVICE-MODULE[,...]", "Import remote service module into library"
|
68
|
+
def import_service_module(context_params)
|
69
|
+
library_id, service_modules = context_params.retrieve_arguments([:library_id, :option_1!],method_argument_names)
|
70
|
+
post_body = {
|
71
|
+
:remote_module_name => service_modules
|
72
|
+
}
|
73
|
+
post_body.merge!(:library_id => library_id) if library_id
|
74
|
+
|
75
|
+
post rest_url("service_module/import"), post_body
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "[LIBRARY ID/NAME] create-service-component SERVICE-MODULE-NAME", "Create an empty service module in library"
|
79
|
+
def create(context_params)
|
80
|
+
library_id, module_name = context_params.retrieve_arguments([:library_id, :option_1!],method_argument_names)
|
81
|
+
post_body = {
|
82
|
+
:module_name => module_name
|
83
|
+
}
|
84
|
+
post_body.merge!(:library_id => library_id) if library_id
|
85
|
+
response = post rest_url("service_module/create"), post_body
|
86
|
+
# when changing context send request for getting latest libraries instead of getting from cache
|
87
|
+
@@invalidate_map << :library
|
88
|
+
|
89
|
+
return response
|
90
|
+
end
|
91
|
+
|
92
|
+
desc "[LIBRARY ID/NAME] delete-service-component COMPONENT-MODULE-NAME","Delete component module and all items contained in it"
|
93
|
+
def delete(context_params)
|
94
|
+
library_id, component_module_id = context_params.retrieve_arguments([:library_id, :option_1!],method_argument_names)
|
95
|
+
post_body = {
|
96
|
+
:component_module_id => component_module_id
|
97
|
+
}
|
98
|
+
post_body.merge!(:library_id => library_id) if library_id
|
99
|
+
response = post rest_url("component_module/delete"), post_body
|
100
|
+
# when changing context send request for getting latest libraries instead of getting from cache
|
101
|
+
@@invalidate_map << :library
|
102
|
+
|
103
|
+
return response
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|