dtk-client 0.5.14 → 0.5.15
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 +5 -13
- data/lib/commands/common/thor/assembly_workspace.rb +95 -0
- data/lib/commands/common/thor/common.rb +7 -4
- data/lib/commands/common/thor/edit.rb +1 -1
- data/lib/commands/common/thor/inventory_parser.rb +78 -0
- data/lib/commands/common/thor/pull_from_remote.rb +14 -10
- data/lib/commands/common/thor/push_to_remote.rb +0 -21
- data/lib/commands/thor/account.rb +2 -2
- data/lib/commands/thor/component_module.rb +45 -42
- data/lib/commands/thor/library.rb +2 -1
- data/lib/commands/thor/provider.rb +42 -36
- data/lib/commands/thor/service.rb +39 -30
- data/lib/commands/thor/service_module.rb +59 -60
- data/lib/commands/thor/target.rb +85 -15
- data/lib/commands/thor/workspace.rb +1 -1
- data/lib/config/disk_cacher.rb +4 -1
- data/lib/configurator.rb +1 -8
- data/lib/core.rb +4 -2
- data/lib/domain/response.rb +13 -2
- data/lib/dtk-client/version.rb +1 -1
- data/lib/dtk_logger.rb +4 -4
- data/lib/shell/context.rb +96 -77
- data/lib/shell/help_monkey_patch.rb +19 -17
- data/lib/util/os_util.rb +12 -12
- data/lib/util/remote_dependency_util.rb +36 -0
- data/lib/util/ssh_util.rb +2 -1
- data/spec/component_module_spec.rb +34 -0
- data/spec/dtk_spec.rb +1 -1
- data/spec/node_template_spec.rb +0 -1
- data/spec/service_module_spec.rb +38 -0
- data/spec/service_spec.rb +20 -11
- metadata +12 -16
- data/spec/assembly_spec.rb +0 -50
- data/spec/assembly_template_spec.rb +0 -51
- data/spec/component_template_spec.rb +0 -40
- data/spec/module_spec.rb +0 -35
- data/spec/node_spec.rb +0 -43
@@ -19,6 +19,8 @@ dtk_require_common_commands('thor/common')
|
|
19
19
|
module DTK::Client
|
20
20
|
class ServiceModule < CommandBaseThor
|
21
21
|
|
22
|
+
PULL_CATALOGS = ["dtkn"]
|
23
|
+
|
22
24
|
no_tasks do
|
23
25
|
include CloneMixin
|
24
26
|
include PushToRemoteMixin
|
@@ -82,15 +84,15 @@ module DTK::Client
|
|
82
84
|
|
83
85
|
})
|
84
86
|
end
|
85
|
-
|
87
|
+
|
86
88
|
##MERGE-QUESTION: need to add options of what info is about
|
87
89
|
desc "SERVICE-MODULE-NAME/ID info", "Provides information about specified service module"
|
88
90
|
def info(context_params)
|
89
91
|
if context_params.is_there_identifier?(:assembly)
|
90
92
|
response = DTK::Client::ContextRouter.routeTask("assembly", "info", context_params, @conn)
|
91
|
-
else
|
93
|
+
else
|
92
94
|
service_module_id = context_params.retrieve_arguments([:service_module_id!],method_argument_names)
|
93
|
-
|
95
|
+
|
94
96
|
post_body = {
|
95
97
|
:service_module_id => service_module_id
|
96
98
|
}
|
@@ -128,20 +130,20 @@ module DTK::Client
|
|
128
130
|
if service_module_id.nil? && !service_module_name.nil?
|
129
131
|
service_module_id = service_module_name
|
130
132
|
end
|
131
|
-
|
133
|
+
|
132
134
|
# If user is on service level, list task can't have about value set
|
133
135
|
if (context_params.last_entity_name == :"service-module") and about.nil?
|
134
136
|
action = options.remote? ? "list_remote" : "list"
|
135
137
|
post_body = (options.remote? ? { :rsa_pub_key => SSHUtil.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]})
|
136
138
|
post_body[:diff] = options.diff? ? options.diff : {}
|
137
|
-
|
139
|
+
|
138
140
|
response = post rest_url("service_module/#{action}"), post_body
|
139
141
|
# If user is on service identifier level, list task can't have '--remote' option.
|
140
142
|
else
|
141
143
|
# TODO: this is temp; will shortly support this
|
142
144
|
raise DTK::Client::DtkValidationError.new("Not supported '--remote' option when listing service module assemblies, component templates or modules", true) if options.remote?
|
143
145
|
raise DTK::Client::DtkValidationError.new("Not supported type '#{about}' for list for current context level. Possible type options: 'assembly'", true) unless(about == "assembly" || about == "modules")
|
144
|
-
|
146
|
+
|
145
147
|
if about
|
146
148
|
case about
|
147
149
|
when "assembly"
|
@@ -153,7 +155,7 @@ module DTK::Client
|
|
153
155
|
action = "list_component_modules"
|
154
156
|
else
|
155
157
|
raise_validation_error_method_usage('list')
|
156
|
-
end
|
158
|
+
end
|
157
159
|
end
|
158
160
|
response = post rest_url("service_module/#{action}"), { :service_module_id => service_module_id }
|
159
161
|
end
|
@@ -170,7 +172,7 @@ module DTK::Client
|
|
170
172
|
:service_module_id => service_module_id,
|
171
173
|
}
|
172
174
|
response = post rest_url("service_module/list_instances"), post_body
|
173
|
-
|
175
|
+
|
174
176
|
response.render_table(:assembly_template)
|
175
177
|
end
|
176
178
|
|
@@ -196,7 +198,7 @@ module DTK::Client
|
|
196
198
|
resolve_direct_access(::DTK::Client::Configurator.check_direct_access)
|
197
199
|
remote_module_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
198
200
|
ignore_component_error = options.ignore?
|
199
|
-
|
201
|
+
|
200
202
|
remote_namespace, local_module_name = get_namespace_and_name(remote_module_name)
|
201
203
|
|
202
204
|
version = options["version"]
|
@@ -209,8 +211,9 @@ module DTK::Client
|
|
209
211
|
:local_module_name => local_module_name,
|
210
212
|
:rsa_pub_key => SSHUtil.rsa_pub_key_content()
|
211
213
|
}
|
212
|
-
|
214
|
+
|
213
215
|
response = post rest_url("service_module/import"), post_body
|
216
|
+
RemoteDependencyUtil.print_dependency_warnings(response)
|
214
217
|
|
215
218
|
# case when we need to import additional components
|
216
219
|
if (response.ok? && (missing_components = response.data(:missing_module_components)))
|
@@ -224,13 +227,13 @@ module DTK::Client
|
|
224
227
|
post_body.merge!(opts)
|
225
228
|
response = post rest_url("service_module/import"), post_body
|
226
229
|
end
|
227
|
-
|
230
|
+
|
228
231
|
return response unless response.ok?
|
229
232
|
@@invalidate_map << :service_module
|
230
233
|
|
231
234
|
if error = response.data(:dsl_parsed_info)
|
232
235
|
dsl_parsed_message = ServiceImporter.error_message(remote_module_name, error)
|
233
|
-
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
236
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
234
237
|
end
|
235
238
|
|
236
239
|
service_module_id, module_name, namespace, repo_url, branch = response.data(:module_id, :module_name, :namespace, :repo_url, :workspace_branch)
|
@@ -277,7 +280,7 @@ module DTK::Client
|
|
277
280
|
|
278
281
|
# if error = response.data(:dsl_parsed_info)
|
279
282
|
# dsl_parsed_message = ServiceImporter.error_message("#{module_name}-#{version}", error)
|
280
|
-
# DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
283
|
+
# DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
281
284
|
# end
|
282
285
|
|
283
286
|
# #TODO: need to check if local clone directory exists
|
@@ -307,14 +310,17 @@ module DTK::Client
|
|
307
310
|
:rsa_pub_key => SSHUtil.rsa_pub_key_content()
|
308
311
|
}
|
309
312
|
|
310
|
-
post rest_url("service_module/export"), post_body
|
311
|
-
|
313
|
+
response = post rest_url("service_module/export"), post_body
|
314
|
+
return response unless response.ok?
|
315
|
+
RemoteDependencyUtil.print_dependency_warnings(response, "Module has been successfully published!")
|
316
|
+
nil
|
317
|
+
end
|
312
318
|
|
313
319
|
# desc "SERVICE-MODULE-NAME/ID push-to-dtkn [-n NAMESPACE] [-v VERSION]", "Push local copy of service module to remote repository."
|
314
320
|
# version_method_option
|
315
321
|
# desc "SERVICE-MODULE-NAME/ID push-to-dtkn [-n NAMESPACE]", "Push local copy of service module to remote repository."
|
316
322
|
# method_option "namespace",:aliases => "-n",
|
317
|
-
# :type => :string,
|
323
|
+
# :type => :string,
|
318
324
|
# :banner => "NAMESPACE",
|
319
325
|
# :desc => "Remote namespace"
|
320
326
|
# def push_to_dtkn(context_params)
|
@@ -332,7 +338,7 @@ module DTK::Client
|
|
332
338
|
# unless File.directory?(module_location)
|
333
339
|
# if Console.confirmation_prompt("Unable to push to remote because module '#{service_module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
|
334
340
|
# response = clone_aux(:service_module,service_module_id,version,false)
|
335
|
-
|
341
|
+
|
336
342
|
# if(response.nil? || response.ok?)
|
337
343
|
# reparse_aux(module_location)
|
338
344
|
# push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], version) if Console.confirmation_prompt("Would you like to push changes to remote"+'?')
|
@@ -344,7 +350,7 @@ module DTK::Client
|
|
344
350
|
# return
|
345
351
|
# end
|
346
352
|
# end
|
347
|
-
|
353
|
+
|
348
354
|
# reparse_aux(module_location)
|
349
355
|
# push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], options["version"])
|
350
356
|
# end
|
@@ -352,15 +358,15 @@ module DTK::Client
|
|
352
358
|
# desc "SERVICE-MODULE-NAME/ID pull-from-dtkn [-n NAMESPACE] [-v VERSION]", "Update local service module from remote repository."
|
353
359
|
desc "SERVICE-MODULE-NAME/ID pull-dtkn [-n NAMESPACE]", "Update local service module from remote repository."
|
354
360
|
method_option "namespace",:aliases => "-n",
|
355
|
-
:type => :string,
|
361
|
+
:type => :string,
|
356
362
|
:banner => "NAMESPACE",
|
357
363
|
:desc => "Remote namespace"
|
358
364
|
def pull_dtkn(context_params)
|
359
365
|
service_module_id, service_module_name = context_params.retrieve_arguments([:service_module_id!,:service_module_name],method_argument_names)
|
360
366
|
catalog = 'dtkn'
|
361
367
|
version = options["version"]
|
362
|
-
|
363
|
-
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{
|
368
|
+
|
369
|
+
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PULL_CATALOGS}" unless catalog
|
364
370
|
|
365
371
|
if service_module_name.to_s =~ /^[0-9]+$/
|
366
372
|
service_module_id = service_module_name
|
@@ -384,17 +390,9 @@ module DTK::Client
|
|
384
390
|
#elsif catalog.to_s.eql?("origin")
|
385
391
|
#needs to be implemented
|
386
392
|
else
|
387
|
-
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{
|
393
|
+
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PULL_CATALOGS}"
|
388
394
|
end
|
389
395
|
end
|
390
|
-
PullCatalogs = ["dtkn"]
|
391
|
-
|
392
|
-
desc "SERVICE-MODULE-NAME/ID chown REMOTE-USER", "Set remote module owner"
|
393
|
-
method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
|
394
|
-
def chown(context_params)
|
395
|
-
service_module_id, remote_user = context_params.retrieve_arguments([:service_module_id!,:option_1!],method_argument_names)
|
396
|
-
chown_aux(service_module_id, remote_user, options.namespace)
|
397
|
-
end
|
398
396
|
|
399
397
|
desc "SERVICE-MODULE-NAME/ID chmod PERMISSION-SELECTOR", "Update remote permissions e.g. ug+rw , user and group get RW permissions"
|
400
398
|
method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
|
@@ -439,7 +437,7 @@ module DTK::Client
|
|
439
437
|
method_option "namespace",:aliases => "-n",:type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
|
440
438
|
def list_collaborators(context_params)
|
441
439
|
service_module_id = context_params.retrieve_arguments([:service_module_id!],method_argument_names)
|
442
|
-
response = collaboration_list_aux(
|
440
|
+
response = collaboration_list_aux(service_module_id, options.namespace)
|
443
441
|
response.render_table(:module_collaborators)
|
444
442
|
response
|
445
443
|
end
|
@@ -525,7 +523,7 @@ module DTK::Client
|
|
525
523
|
# post_body = {
|
526
524
|
# :service_module_id => service_module_id,
|
527
525
|
# :component_module_id => component_module_id,
|
528
|
-
# :version => version
|
526
|
+
# :version => version
|
529
527
|
# }
|
530
528
|
# response = post rest_url("service_module/set_component_module_version"), post_body
|
531
529
|
# @@invalidate_map << :service_module
|
@@ -543,18 +541,18 @@ module DTK::Client
|
|
543
541
|
response = Helper(:git_repo).check_local_dir_exists_with_content(:service_module,module_name)
|
544
542
|
return response unless response.ok?
|
545
543
|
service_directory = response.data(:module_directory)
|
546
|
-
|
544
|
+
|
547
545
|
#check for yaml/json parsing errors before import
|
548
546
|
reparse_aux(service_directory)
|
549
547
|
|
550
548
|
# first call to create empty module
|
551
|
-
response = post rest_url("service_module/create"), { :module_name => module_name }
|
549
|
+
response = post rest_url("service_module/create"), { :module_name => module_name }
|
552
550
|
return response unless response.ok?
|
553
551
|
@@invalidate_map << :service_module
|
554
|
-
|
552
|
+
|
555
553
|
if error = response.data(:dsl_parsed_info)
|
556
554
|
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
|
557
|
-
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
555
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
558
556
|
end
|
559
557
|
|
560
558
|
# initial commit for given service module
|
@@ -574,11 +572,11 @@ module DTK::Client
|
|
574
572
|
=begin
|
575
573
|
desc "SERVICE-MODULE-NAME/ID push origin|dtkn [-n NAMESPACE] [-m COMMIT-MSG]", "Push changes from local copy of service module to server (origin) or to remote repository (dtkn)."
|
576
574
|
method_option "message",:aliases => "-m" ,
|
577
|
-
:type => :string,
|
575
|
+
:type => :string,
|
578
576
|
:banner => "COMMIT-MSG",
|
579
577
|
:desc => "Commit message"
|
580
578
|
method_option "namespace",:aliases => "-n",
|
581
|
-
:type => :string,
|
579
|
+
:type => :string,
|
582
580
|
:banner => "NAMESPACE",
|
583
581
|
:desc => "Remote namespace"
|
584
582
|
#hidden option for dev
|
@@ -586,7 +584,7 @@ module DTK::Client
|
|
586
584
|
def push(context_params, internal_trigger=false)
|
587
585
|
service_module_id, service_module_name, catalog = context_params.retrieve_arguments([:service_module_id!, :service_module_name, :option_1],method_argument_names)
|
588
586
|
version = options["version"]
|
589
|
-
|
587
|
+
|
590
588
|
raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}" unless catalog
|
591
589
|
|
592
590
|
if service_module_name.to_s =~ /^[0-9]+$/
|
@@ -604,7 +602,7 @@ module DTK::Client
|
|
604
602
|
unless File.directory?(module_location)
|
605
603
|
if Console.confirmation_prompt("Unable to push to remote because module '#{service_module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
|
606
604
|
response = clone_aux(:service_module,service_module_id,version,false)
|
607
|
-
|
605
|
+
|
608
606
|
if(response.nil? || response.ok?)
|
609
607
|
reparse_aux(module_location)
|
610
608
|
push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], version) if Console.confirmation_prompt("Would you like to push changes to remote"+'?')
|
@@ -616,7 +614,7 @@ module DTK::Client
|
|
616
614
|
return
|
617
615
|
end
|
618
616
|
end
|
619
|
-
|
617
|
+
|
620
618
|
push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], options["version"])
|
621
619
|
else
|
622
620
|
raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}"
|
@@ -628,7 +626,7 @@ module DTK::Client
|
|
628
626
|
# desc "SERVICE-MODULE-NAME/ID push [-m COMMIT-MSG]", "Push changes from local copy to server (origin)."
|
629
627
|
desc "SERVICE-MODULE-NAME/ID push", "Push changes from local copy to server."
|
630
628
|
method_option "message",:aliases => "-m" ,
|
631
|
-
:type => :string,
|
629
|
+
:type => :string,
|
632
630
|
:banner => "COMMIT-MSG",
|
633
631
|
:desc => "Commit message"
|
634
632
|
#hidden option for dev
|
@@ -651,18 +649,18 @@ module DTK::Client
|
|
651
649
|
# desc "SERVICE-MODULE-NAME/ID push-dtkn [-n NAMESPACE] [-m COMMIT-MSG]", "Push changes from local copy of service module to remote repository (dtkn)."
|
652
650
|
desc "SERVICE-MODULE-NAME/ID push-dtkn [-n NAMESPACE]", "Push changes from local copy of service module to remote repository (dtkn)."
|
653
651
|
method_option "message",:aliases => "-m" ,
|
654
|
-
:type => :string,
|
652
|
+
:type => :string,
|
655
653
|
:banner => "COMMIT-MSG",
|
656
654
|
:desc => "Commit message"
|
657
655
|
method_option "namespace",:aliases => "-n",
|
658
|
-
:type => :string,
|
656
|
+
:type => :string,
|
659
657
|
:banner => "NAMESPACE",
|
660
658
|
:desc => "Remote namespace"
|
661
659
|
def push_dtkn(context_params, internal_trigger=false)
|
662
660
|
service_module_id, service_module_name = context_params.retrieve_arguments([:service_module_id!, :service_module_name],method_argument_names)
|
663
661
|
catalog = 'dtkn'
|
664
662
|
version = options["version"]
|
665
|
-
|
663
|
+
|
666
664
|
if service_module_name.to_s =~ /^[0-9]+$/
|
667
665
|
service_module_id = service_module_name
|
668
666
|
service_module_name = get_service_module_name(service_module_id)
|
@@ -673,7 +671,8 @@ module DTK::Client
|
|
673
671
|
reparse_aux(module_location) unless internal_trigger
|
674
672
|
|
675
673
|
if catalog.to_s.eql?("dtkn")
|
676
|
-
|
674
|
+
module_refs_content = RemoteDependencyUtil.module_ref_content(module_location)
|
675
|
+
remote_module_info = get_remote_module_info_aux(:service_module, service_module_id, options["namespace"], version, module_refs_content)
|
677
676
|
return remote_module_info unless remote_module_info.ok?
|
678
677
|
|
679
678
|
unless File.directory?(module_location)
|
@@ -686,7 +685,7 @@ module DTK::Client
|
|
686
685
|
|
687
686
|
return response
|
688
687
|
end
|
689
|
-
|
688
|
+
|
690
689
|
push_to_remote_aux(remote_module_info, :service_module)
|
691
690
|
else
|
692
691
|
raise DtkValidationError, "You have to provide valid catalog to push changes to!"
|
@@ -710,13 +709,13 @@ module DTK::Client
|
|
710
709
|
return unless Console.confirmation_prompt("Are you sure you want to delete service-module #{version.nil? ? '' : 'version '}'#{service_module_name}#{version.nil? ? '' : ('-' + version.to_s)}' and all items contained in it"+'?')
|
711
710
|
end
|
712
711
|
|
713
|
-
response =
|
712
|
+
response =
|
714
713
|
if options.purge?
|
715
714
|
opts = {:module_name => service_module_name}
|
716
715
|
if version then opts.merge!(:version => version)
|
717
716
|
else opts.merge!(:delete_all_versions => true)
|
718
717
|
end
|
719
|
-
|
718
|
+
|
720
719
|
purge_clone_aux(:service_module,opts)
|
721
720
|
else
|
722
721
|
Helper(:git_repo).unlink_local_clone?(:service_module,service_module_name,version)
|
@@ -733,7 +732,7 @@ module DTK::Client
|
|
733
732
|
response = post rest_url("service_module/#{action}"), post_body
|
734
733
|
return response unless response.ok?
|
735
734
|
module_name = response.data(:module_name)
|
736
|
-
|
735
|
+
|
737
736
|
# when changing context send request for getting latest services instead of getting from cache
|
738
737
|
@@invalidate_map << :service_module
|
739
738
|
|
@@ -749,7 +748,7 @@ module DTK::Client
|
|
749
748
|
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
750
749
|
def delete_from_catalog(context_params)
|
751
750
|
remote_service_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
752
|
-
|
751
|
+
|
753
752
|
unless options.force?
|
754
753
|
# Ask user if really want to delete service module and all items contained in it, if not then return to dtk-shell without deleting
|
755
754
|
return unless Console.confirmation_prompt("Are you sure you want to delete remote service-module '#{remote_service_name}' and all items contained in it"+'?')
|
@@ -779,20 +778,20 @@ module DTK::Client
|
|
779
778
|
end
|
780
779
|
|
781
780
|
return unless Console.confirmation_prompt("Are you sure you want to delete assembly '#{assembly_template_name||assembly_template_id}'"+'?') unless options.force?
|
782
|
-
|
781
|
+
|
783
782
|
post_body = {
|
784
783
|
:service_module_id => service_module_id,
|
785
784
|
:assembly_id => assembly_template_id,
|
786
|
-
:subtype => :template
|
785
|
+
:subtype => :template
|
787
786
|
}
|
788
787
|
|
789
788
|
response = post rest_url("service_module/delete_assembly_template"), post_body
|
790
789
|
return response unless response.ok?
|
791
|
-
|
790
|
+
|
792
791
|
modules_path = OsUtil.service_clone_location()
|
793
792
|
module_location = "#{modules_path}/#{service_module_name}" if service_module_name
|
794
|
-
assembly_template_location = "#{module_location}/assemblies/#{assembly_template_name}" if (module_location && assembly_template_name)
|
795
|
-
|
793
|
+
assembly_template_location = "#{module_location}/assemblies/#{assembly_template_name}" if (module_location && assembly_template_name)
|
794
|
+
|
796
795
|
if File.directory?(assembly_template_location)
|
797
796
|
unless (assembly_template_location.nil? || ("#{module_location}/assemblies/" == assembly_template_location))
|
798
797
|
FileUtils.rm_rf("#{assembly_template_location}")
|
@@ -806,17 +805,17 @@ module DTK::Client
|
|
806
805
|
Response::Ok.new()
|
807
806
|
end
|
808
807
|
=begin
|
809
|
-
desc "SERVICE-NAME/ID assembly-templates list", "List assembly templates optionally filtered by service ID/NAME."
|
808
|
+
desc "SERVICE-NAME/ID assembly-templates list", "List assembly templates optionally filtered by service ID/NAME."
|
810
809
|
def assembly_template(context_params)
|
811
810
|
|
812
811
|
service_id, method_name = context_params.retrieve_arguments([:service_name!, :option_1!],method_argument_names)
|
813
812
|
|
814
813
|
options_args = ["-s", service_id]
|
815
|
-
|
814
|
+
|
816
815
|
entity_name = "assembly_template"
|
817
816
|
load_command(entity_name)
|
818
817
|
entity_class = DTK::Client.const_get "#{cap_form(entity_name)}"
|
819
|
-
|
818
|
+
|
820
819
|
response = entity_class.execute_from_cli(@conn, method_name, DTK::Shell::ContextParams.new, options_args, false)
|
821
820
|
|
822
821
|
end
|
@@ -840,7 +839,7 @@ TODO: needs to be rewritten
|
|
840
839
|
#TODO: right now JenkinsClient wil throw error if problem; better to create an error resonse
|
841
840
|
response
|
842
841
|
end
|
843
|
-
=end
|
842
|
+
=end
|
844
843
|
end
|
845
844
|
end
|
846
845
|
|
data/lib/commands/thor/target.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
dtk_require_common_commands('thor/inventory_parser')
|
1
2
|
module DTK::Client
|
2
3
|
class Target < CommandBaseThor
|
4
|
+
include InventoryParserMixin
|
3
5
|
|
4
6
|
def self.pretty_print_cols()
|
5
7
|
PPColumns.get(:target)
|
@@ -9,20 +11,51 @@ module DTK::Client
|
|
9
11
|
return ['PROVIDER']
|
10
12
|
end
|
11
13
|
|
14
|
+
def self.extended_context()
|
15
|
+
{
|
16
|
+
:context => {
|
17
|
+
# want auto complete for --provider option
|
18
|
+
"--provider" => "provider"
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
12
23
|
desc "TARGET-NAME/ID list-nodes","Lists node instances in given targets."
|
13
24
|
def list_nodes(context_params)
|
14
25
|
context_params.method_arguments = ["nodes"]
|
15
|
-
|
26
|
+
list(context_params)
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "TARGET-NAME/ID info","Provides information about specified target"
|
30
|
+
def info(context_params)
|
31
|
+
target_id = context_params.retrieve_arguments([:target_id!],method_argument_names)
|
32
|
+
|
33
|
+
post_body = {:target_id => target_id}
|
34
|
+
response = post rest_url('target/info'), post_body
|
35
|
+
response.render_custom_info("target")
|
16
36
|
end
|
17
37
|
|
18
|
-
desc "TARGET-NAME/ID import-nodes","Reads from inventory dsl and populates the node instance objects
|
38
|
+
desc "TARGET-NAME/ID import-nodes --source SOURCE","Reads from inventory dsl and populates the node instance objects (SOURCE: file:/path/to/file.yaml)."
|
39
|
+
method_option :source, :type => :string
|
19
40
|
def import_nodes(context_params)
|
20
41
|
target_id = context_params.retrieve_arguments([:target_id!],method_argument_names)
|
42
|
+
source = context_params.retrieve_thor_options([:source!], options)
|
21
43
|
|
22
|
-
|
23
|
-
|
24
|
-
|
44
|
+
parsed_source = source.match(/^(\w+):(.+)/)
|
45
|
+
raise DTK::Client::DtkValidationError, "Invalid source! Valid source should contain source_type:source_path (e.g. --source file:path/to/file.yaml)." unless parsed_source
|
46
|
+
|
47
|
+
import_type = parsed_source[1]
|
48
|
+
path = parsed_source[2]
|
49
|
+
|
50
|
+
raise DTK::Client::DtkValidationError, "We do not support '#{import_type}' as import source at the moment. Valid sources: #{ValidImportTypes}" unless ValidImportTypes.include?(import_type)
|
25
51
|
|
52
|
+
post_body = {:target_id => target_id}
|
53
|
+
|
54
|
+
if import_type.eql?('file')
|
55
|
+
inventory_data = parse_inventory_file(path)
|
56
|
+
post_body.merge!(:inventory_data => inventory_data)
|
57
|
+
end
|
58
|
+
|
26
59
|
response = post rest_url("target/import_nodes"), post_body
|
27
60
|
return response unless response.ok?
|
28
61
|
|
@@ -35,14 +68,50 @@ module DTK::Client
|
|
35
68
|
end
|
36
69
|
end
|
37
70
|
end
|
71
|
+
ValidImportTypes = ["file"]
|
72
|
+
|
73
|
+
desc "set-default-target TARGET-IDENTIFIER","Sets the default target."
|
74
|
+
def set_default_target(context_params)
|
75
|
+
target_id = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
76
|
+
post rest_url("target/set_default"), { :target_id => target_id }
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "TARGET-NAME/ID install-agents","Install node agents on imported physical nodes."
|
80
|
+
def install_agents(context_params)
|
81
|
+
target_id = context_params.retrieve_arguments([:target_id!],method_argument_names)
|
82
|
+
|
83
|
+
post_body = {:target_id => target_id}
|
84
|
+
post rest_url("target/install_agents"), post_body
|
85
|
+
end
|
86
|
+
|
87
|
+
desc "create-target [TARGET-NAME] --provider PROVIDER --region REGION", "Create target based on given provider"
|
88
|
+
method_option :provider, :type => :string
|
89
|
+
method_option :region, :type => :string
|
90
|
+
def create_target(context_params)
|
91
|
+
# we use :target_id but that will retunr provider_id (another name for target template ID)
|
92
|
+
target_name = context_params.retrieve_arguments([:option_1],method_argument_names)
|
93
|
+
provider = context_params.retrieve_thor_options([:provider!], options)
|
94
|
+
region = context_params.retrieve_thor_options([:region], options)
|
95
|
+
|
96
|
+
DTK::Shell::InteractiveWizard.validate_region(region) if region
|
97
|
+
|
98
|
+
post_body = {
|
99
|
+
:provider_id => provider
|
100
|
+
}
|
101
|
+
post_body.merge!(:target_name => target_name) if target_name
|
102
|
+
post_body.merge!(:region => region) if region
|
103
|
+
response = post rest_url("target/create"), post_body
|
104
|
+
|
105
|
+
@@invalidate_map << :target
|
106
|
+
return response
|
107
|
+
end
|
38
108
|
|
39
109
|
desc "TARGET-NAME/ID list-services","Lists service instances in given targets."
|
40
110
|
def list_services(context_params)
|
41
111
|
context_params.method_arguments = ["assemblies"]
|
42
|
-
|
112
|
+
list(context_params)
|
43
113
|
end
|
44
114
|
|
45
|
-
|
46
115
|
def self.validation_list(context_params)
|
47
116
|
provider_id = context_params.retrieve_arguments([:provider_id])
|
48
117
|
|
@@ -62,8 +131,8 @@ module DTK::Client
|
|
62
131
|
response
|
63
132
|
end
|
64
133
|
|
65
|
-
desc "list
|
66
|
-
def
|
134
|
+
desc "list","Lists available targets."
|
135
|
+
def list(context_params)
|
67
136
|
provider_id, target_id, about = context_params.retrieve_arguments([:provider_id, :target_id, :option_1],method_argument_names||="")
|
68
137
|
|
69
138
|
if target_id.nil?
|
@@ -82,13 +151,14 @@ module DTK::Client
|
|
82
151
|
|
83
152
|
case about
|
84
153
|
when "nodes"
|
85
|
-
|
86
|
-
|
154
|
+
response = post rest_url("target/info_about"), post_body
|
155
|
+
data_type = :node
|
87
156
|
when "assemblies"
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
157
|
+
post_body.merge!(:detail_level => 'nodes', :include_workspace => true)
|
158
|
+
response = post rest_url("target/info_about"), post_body
|
159
|
+
data_type = :assembly
|
160
|
+
else
|
161
|
+
raise_validation_error_method_usage('list')
|
92
162
|
end
|
93
163
|
|
94
164
|
response.render_table(data_type)
|
@@ -382,7 +382,7 @@ module DTK::Client
|
|
382
382
|
end
|
383
383
|
|
384
384
|
desc "WORKSPACE-NAME/ID list-component-modules","List component modules associated with workspace."
|
385
|
-
def
|
385
|
+
def list_component_modules(context_params)
|
386
386
|
list_modules_aux(context_params)
|
387
387
|
end
|
388
388
|
|
data/lib/config/disk_cacher.rb
CHANGED
@@ -16,11 +16,14 @@ class DiskCacher
|
|
16
16
|
|
17
17
|
def initialize(cache_dir=DTK::Client::OsUtil.get_temp_location())
|
18
18
|
@cache_dir = cache_dir
|
19
|
+
@current_user = ::DTK::Client::Configurator.client_username
|
19
20
|
end
|
20
21
|
|
21
22
|
def fetch(file_name, max_age=0, use_mock_up=true)
|
22
23
|
file = Digest::MD5.hexdigest(file_name)
|
23
|
-
|
24
|
+
# current user is important so that there are no clashes in writting to temp file
|
25
|
+
# between multiple users on same machine
|
26
|
+
file_path = File.join(@cache_dir, "#{@current_user}::#{file}")
|
24
27
|
|
25
28
|
# we check if the file -- a MD5 hexdigest of the URL -- exists
|
26
29
|
# in the dir. If it does and the data is fresh, we just read
|
data/lib/configurator.rb
CHANGED
@@ -9,18 +9,11 @@ module DTK
|
|
9
9
|
CONFIG_FILE = File.join(OsUtil.dtk_local_folder, "client.conf")
|
10
10
|
CRED_FILE = File.join(OsUtil.dtk_local_folder, ".connection")
|
11
11
|
DIRECT_ACCESS = File.join(OsUtil.dtk_local_folder, ".add_direct_access")
|
12
|
+
NODE_SSH_CREDENTIALS = File.join(OsUtil.dtk_local_folder, "ssh_credentials.yaml")
|
12
13
|
|
13
14
|
require 'fileutils'
|
14
15
|
FileUtils.mkdir(OsUtil.dtk_local_folder) unless File.directory?(OsUtil.dtk_local_folder)
|
15
16
|
|
16
|
-
def self.CONFIG_FILE
|
17
|
-
CONFIG_FILE
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.CRED_FILE
|
21
|
-
CRED_FILE
|
22
|
-
end
|
23
|
-
|
24
17
|
def self.check_config_exists
|
25
18
|
exists = true
|
26
19
|
if !File.exists?(CONFIG_FILE)
|
data/lib/core.rb
CHANGED
@@ -14,6 +14,8 @@ dtk_require_from_base('util/os_util')
|
|
14
14
|
dtk_require_from_base('util/ssh_util')
|
15
15
|
dtk_require_from_base('util/common_util')
|
16
16
|
dtk_require_from_base('util/permission_util')
|
17
|
+
dtk_require_from_base('util/remote_dependency_util')
|
18
|
+
|
17
19
|
dtk_require("config/configuration")
|
18
20
|
|
19
21
|
def top_level_execute(entity_name, method_name, context_params=nil, options_args=nil, shell_execute=false)
|
@@ -231,8 +233,8 @@ module DTK
|
|
231
233
|
include ParseFile
|
232
234
|
dtk_require_from_base('configurator')
|
233
235
|
|
234
|
-
CONFIG_FILE = ::DTK::Client::Configurator
|
235
|
-
CRED_FILE = ::DTK::Client::Configurator
|
236
|
+
CONFIG_FILE = ::DTK::Client::Configurator::CONFIG_FILE
|
237
|
+
CRED_FILE = ::DTK::Client::Configurator::CRED_FILE
|
236
238
|
|
237
239
|
REQUIRED_KEYS = [:server_host]
|
238
240
|
|
data/lib/domain/response.rb
CHANGED
@@ -116,14 +116,25 @@ module DTK
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def get_custom_labels(label, type)
|
119
|
-
mappings = {
|
119
|
+
mappings = {}
|
120
|
+
|
121
|
+
mappings["module"] = {
|
120
122
|
"id" => "ID:",
|
121
123
|
"display_name" => "NAME:",
|
122
124
|
"versions" => "VERSION(S):",
|
123
125
|
"remote_repos" => "LINKED REMOTE(S):",
|
124
126
|
"dsl_parsed" => "DSL PARSED:"
|
125
127
|
}
|
126
|
-
|
128
|
+
|
129
|
+
mappings["target"] = {
|
130
|
+
"id" => "ID:",
|
131
|
+
"display_name" => "NAME:",
|
132
|
+
"type" => "TYPE:",
|
133
|
+
"iaas_type" => "PROVIDER_TYPE:",
|
134
|
+
"provider_name" => "PROVIDER_NAME:"
|
135
|
+
}
|
136
|
+
|
137
|
+
mappings[type][label] if mappings[type]
|
127
138
|
end
|
128
139
|
|
129
140
|
def array_to_string(array_data)
|
data/lib/dtk-client/version.rb
CHANGED