class DTK::Client::ServiceModule
Constants
- PULL_CATALOGS
Public Class Methods
all_children()
click to toggle source
# File lib/commands/thor/service_module.rb, line 191 def self.all_children() [:assembly] end
extended_context()
click to toggle source
# File lib/commands/thor/service_module.rb, line 160 def self.extended_context() { :command => { :stage => { :endpoint => "service_module", :url => "service_module/list_assemblies", :opts => {} }, :stage_target => { :endpoint => "service_module", :url => "service_module/list_assemblies", :opts => {} }, :deploy_target => { :endpoint => "service_module", :url => "service_module/list_assemblies", :opts => {} }, :deploy => { :endpoint => "service_module", :url => "service_module/list_assemblies", :opts => {} } } } end
multi_context_children()
click to toggle source
# File lib/commands/thor/service_module.rb, line 195 def self.multi_context_children() [[:assembly], [:remotes], [:assembly, :remotes]] end
override_allowed_methods()
click to toggle source
# File lib/commands/thor/service_module.rb, line 215 def self.override_allowed_methods() return DTK::Shell::OverrideTasks.new({ :command_only => { :self => [ ["list"," list [--remote] [--diff] [-n NAMESPACE]","# List service modules (local/remote). Use --diff to compare loaded and remote modules."] ], :assembly => [ ["list","list","# List assemblies for given service module."] ], :remotes => [ ["push-remote", "push-remote [REMOTE-NAME] [--force]", "# Push local changes to remote git repository"], ["list-remotes", "list-remotes", "# List git remotes for given module"], ["add-remote", "add-remote REMOTE-NAME REMOTE-URL", "# Add git remote for given module"], ["remove-remote", "remove-remote REPO-NAME [-y]", "# Remove git remote for given module"] ] }, :identifier_only => { :self => [ ["list-assemblies","list-assemblies","# List assemblies associated with service module."], ["list-modules","list-modules","# List modules associated with service module."] ], :assembly => [ ["info","info","# Info for given assembly in current service module."], # ["stage", "stage [INSTANCE-NAME] [-t TARGET-NAME/ID] [--node-size NODE-SIZE-SPEC] [--os-type OS-TYPE] [-v VERSION]", "# Stage assembly in target."], # ["deploy","deploy [-v VERSION] [INSTANCE-NAME] [-t TARGET-NAME/ID] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."], # ["deploy","deploy [INSTANCE-NAME] [-t TARGET-NAME/ID] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."], # ["deploy","deploy [INSTANCE-NAME] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."], ["stage-target","stage-target [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "# Stage assembly as target instance."], ["stage","stage [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "# Stage assembly in target."], ["deploy-target","deploy-target [INSTANCE-NAME] [-v VERSION] [--no-auto-complete]", "# Deploy assembly as target instance."], ["deploy","deploy [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "# Deploy assembly in target."], ["list-nodes","list-nodes", "# List all nodes for given assembly."], ["list-components","list-components", "# List all components for given assembly."], ["list-settings","list-settings", "# List all settings for given assembly."] ] } }) end
pretty_print_cols()
click to toggle source
# File lib/commands/thor/service_module.rb, line 203 def self.pretty_print_cols() PPColumns.get(:service_module) end
valid_child?(name_of_sub_context)
click to toggle source
# File lib/commands/thor/service_module.rb, line 199 def self.valid_child?(name_of_sub_context) return ServiceModule.valid_children().include?(name_of_sub_context.to_sym) end
valid_children()
click to toggle source
# File lib/commands/thor/service_module.rb, line 187 def self.valid_children() [:assembly, :remotes] end
validation_list(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 207 def self.validation_list(context_params) get_cached_response(:service_module, "service_module/list", {}) end
whoami()
click to toggle source
# File lib/commands/thor/service_module.rb, line 211 def self.whoami() return :service_module, "service_module/list", nil end
Public Instance Methods
SERVICE-MODULE-NAME/ID clone [-n] [-v VERSION]()
click to toggle source
internal_trigger: this flag means that other method (internal) has trigger this.
This will change behaviour of method
desc “SERVICE-MODULE-NAME/ID clone [-v VERSION] [-n]”, “Locally clone the service module files. Use -n to skip edit prompt” version_method_option
# File lib/commands/thor/service_module.rb, line 557 desc "SERVICE-MODULE-NAME/ID clone [-n] [-v VERSION]", "Locally clone the service module files. Use -n to skip edit prompt"
add_collaborators(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 532 def add_collaborators(context_params) add_collaborators_module_aux(context_params) end
add_remote(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 805 def add_remote(context_params) remote_add_aux(context_params) end
chmod(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 512 def chmod(context_params) chmod_module_aux(context_params) end
clone(context_params, internal_trigger=false)
click to toggle source
# File lib/commands/thor/service_module.rb, line 560 def clone(context_params, internal_trigger=false) clone_module_aux(context_params, internal_trigger) end
create_new_version(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 821 def create_new_version(context_params) create_new_version_aux(context_params) end
delete(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 766 def delete(context_params) response = delete_module_aux(context_params, :delete_all => true) @@invalidate_map << :service_module if response && response.ok? response end
delete_all(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 867 def delete_all(context_params) return unless Console.confirmation_prompt("This will DELETE ALL service modules, are you sure"+'?') response = list(context_params) response.data().each do |e| run_shell_command("delete #{e['display_name']} -y -p") end end
delete_assembly(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 783 def delete_assembly(context_params) response = delete_assembly_aux(context_params) @@invalidate_map << :assembly if response && response.ok? response end
delete_from_catalog(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 777 def delete_from_catalog(context_params) delete_from_catalog_aux(context_params) end
delete_version(context_params, method_opts = {})
click to toggle source
# File lib/commands/thor/service_module.rb, line 756 def delete_version(context_params, method_opts = {}) response = delete_module_aux(context_params, method_opts) @@invalidate_map << :service_module if response && response.ok? response end
deploy(context_params)
click to toggle source
method_option :settings, :type => :string, :aliases => '-s'
# File lib/commands/thor/service_module.rb, line 851 def deploy(context_params) response = deploy_aux(context_params) return response unless response.ok? @@invalidate_map << :service @@invalidate_map << :assembly response end
deploy_aux(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 125 def deploy_aux(context_params) forwarded_options = context_params.get_forwarded_options() context_params.forward_options(forwarded_options.merge!(:do_not_encode => true)) stage_response = stage_aux(context_params) return stage_response unless stage_response.ok? if service_instance = stage_response.data['new_service_instance'] instance_name = service_instance['name'] DTK::Client::OsUtil.print("Service instance '/service/#{instance_name}' has been created!",:yellow) new_context_params = DTK::Shell::ContextParams.new new_context_params.add_context_to_params("service", "service") new_context_params.add_context_name_to_params("service", "service", instance_name) new_context_params.forward_options(:instance_name => instance_name) response = ContextRouter.routeTask("service", "set_required_attributes_and_converge", new_context_params, @conn) # change context to newly created service instance MainContext.get_context.change_context(["/service/#{instance_name}"]) return response unless response.ok? if forwarded_options['stream-results'] || options['stream-results'] forwarded_options = new_context_params.get_forwarded_options() task_status_stream(instance_name) unless forwarded_options[:violations] end response else fail DtkError.new('Service instance is not staged properly, please try again!') end end
deploy_target(context_params)
click to toggle source
method_option :settings, :type => :string, :aliases => '-s'
# File lib/commands/thor/service_module.rb, line 833 def deploy_target(context_params) response = deploy_aux(context_params) return response unless response.ok? @@invalidate_map << :service @@invalidate_map << :assembly response end
edit(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 567 def edit(context_params) edit_module_aux(context_params) end
fork(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 816 def fork(context_params) fork_aux(context_params) end
get_name_and_version_from_assembly_template(assembly_template_name)
click to toggle source
# File lib/commands/thor/service_module.rb, line 49 def get_name_and_version_from_assembly_template(assembly_template_name) name = assembly_template_name version = nil if assembly_template_name.match(/(.*)(\-v\d{1,2}\.\d{1,2}\.\d{1,2}\Z)/) name, version = [$1,$2] end if version version.gsub!('-v','') else version = 'base' end return name, version end
get_service_module_name(service_module_id)
click to toggle source
# File lib/commands/thor/service_module.rb, line 45 def get_service_module_name(service_module_id) get_name_from_id_helper(service_module_id) end
import(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 573 def import(context_params) module_name = context_params.retrieve_arguments([:option_1!],method_argument_names) namespace, local_module_name = get_namespace_and_name(module_name, ':') # first check that there is a directory there and it is not already a git repo, and it ha appropriate content response = Helper(:git_repo).check_local_dir_exists_with_content(:service_module, local_module_name, nil, namespace) return response unless response.ok? service_directory = response.data(:module_directory) #check for yaml/json parsing errors before import reparse_aux(service_directory) # first call to create empty module response = post rest_url("service_module/create"), { :module_name => local_module_name, :module_namespace => namespace } return response unless response.ok? @@invalidate_map << :service_module # initial commit for given service module service_module_id, repo_info = response.data(:service_module_id, :repo_info) repo_url,repo_id,module_id,branch,new_module_name = [:repo_url,:repo_id,:module_id,:workspace_branch,:full_module_name].map { |k| repo_info[k.to_s] } response = Helper(:git_repo).rename_and_initialize_clone_and_push(:service_module, local_module_name, new_module_name,branch,repo_url,service_directory) return response unless (response && response.ok?) repo_obj,commit_sha = response.data(:repo_obj,:commit_sha) module_final_dir = repo_obj.repo_dir old_dir = response.data[:old_dir] context_params.add_context_to_params(local_module_name, :"service-module", module_id) response = push(context_params,true) unless response.ok? # remove new directory and leave the old one if import without namespace failed if old_dir and (old_dir != module_final_dir) FileUtils.rm_rf(module_final_dir) unless namespace end return response end # remove the old one if no errors while importing # DTK-1768: removed below; and replaced by removing old dir if unequal to final dir # was not sure why clause namespace was in so kept this condition #FileUtils.rm_rf(old_dir) unless namespace if old_dir and (old_dir != module_final_dir) FileUtils.rm_rf(old_dir) unless namespace end DTK::Client::OsUtil.print("Module '#{new_module_name}' has been created and module directory moved to #{repo_obj.repo_dir}",:yellow) unless namespace response end
info(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 257 def info(context_params) module_info_aux(context_params) end
install(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 387 def install(context_params) response = install_module_aux(context_params) @@invalidate_map << :service_module if response && response.ok? response end
list(context_params)
click to toggle source
method_option :with_versions, :type => :boolean, :default => false, :aliases => “with-versions”
# File lib/commands/thor/service_module.rb, line 289 def list(context_params) service_module_id, about, service_module_name = context_params.retrieve_arguments([:service_module_id, :option_1, :option_2],method_argument_names) datatype = nil if context_params.is_there_command?(:"assembly") about = "assembly" end if service_module_id.nil? && !service_module_name.nil? service_module_id = service_module_name end remote = options.remote? namespace = options.namespace # If user is on service level, list task can't have about value set if (context_params.last_entity_name == :"service-module") and about.nil? action = remote ? "list_remote" : "list" post_body = (remote ? { :rsa_pub_key => SSHUtil.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]}) post_body[:diff] = options.diffs? ? options.diffs : {} post_body.merge!(:module_namespace => namespace) if namespace if post_body[:detail_to_include] post_body[:detail_to_include] << 'versions' # if options.with_versions? else post_body[:detail_to_include] end response = post rest_url("service_module/#{action}"), post_body # If user is on service identifier level, list task can't have '--remote' option. else # TODO: this is temp; will shortly support this # raise DTK::Client::DtkValidationError.new("Not supported '--remote' option when listing service module assemblies, component templates or modules", true) if options.remote? 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") post_body = { :service_module_id => service_module_id } if about case about when "assembly" version = options.version data_type = :assembly_template_description action = "list_assemblies" post_body.merge!(:version => version) if version if remote data_type = :remote_assembly_template_description action = "list_remote_assemblies" path_to_key = SSHUtil.default_rsa_pub_key_path() rsa_pub_key = File.file?(path_to_key) && File.open(path_to_key){|f|f.read}.chomp post_body.merge!(:remote_namespace => namespace) if namespace post_body.merge!(:rsa_pub_key => rsa_pub_key) end when "modules" data_type = remote ? :component_remote : :component_module action = "list_component_modules" else raise_validation_error_method_usage('list') end end response = post rest_url("service_module/#{action}"), post_body end unless response.nil? if options.with_versions? response.render_table(:module_with_versions, true) else response.render_table(data_type) end end response end
list_assemblies(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 264 def list_assemblies(context_params) context_params.method_arguments = ["assembly"] if version = options.version check_version_format(options.version) if !version.eql?('master') && !version.eql?('base') end list(context_params) end
list_collaborators(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 546 def list_collaborators(context_params) list_collaborators_module_aux(context_params) end
list_component_modules(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 276 def list_component_modules(context_params) context_params.method_arguments = ["modules"] list(context_params) end
list_diffs(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 747 def list_diffs(context_params) list_remote_module_diffs(context_params) # list_diffs_module_aux(context_params) end
list_instances(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 363 def list_instances(context_params) list_instances_aux(context_params) end
list_remote_versions(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 375 def list_remote_versions(context_params) response = list_remote_versions_aux(context_params) return response unless response.ok? response.render_table(:list_versions, true) end
list_remotes(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 800 def list_remotes(context_params) remote_list_aux(context_params) end
list_versions(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 368 def list_versions(context_params) response = list_versions_aux(context_params) return response unless response.ok? response.render_table(:list_versions, true) end
make_private(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 524 def make_private(context_params) make_private_module_aux(context_params) end
make_public(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 518 def make_public(context_params) make_public_module_aux(context_params) end
publish(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 454 def publish(context_params) publish_module_aux(context_params) end
pull_dtkn(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 506 def pull_dtkn(context_params) pull_dtkn_aux(context_params) end
push(context_params, internal_trigger=false)
click to toggle source
# File lib/commands/thor/service_module.rb, line 726 def push(context_params, internal_trigger=false) push_module_aux(context_params, internal_trigger) end
push_dtkn(context_params, internal_trigger=false)
click to toggle source
# File lib/commands/thor/service_module.rb, line 741 def push_dtkn(context_params, internal_trigger=false) push_dtkn_module_aux(context_params, internal_trigger) end
push_remote(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 795 def push_remote(context_params) push_remote_module_aux(context_params) end
remove_collaborators(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 540 def remove_collaborators(context_params) remove_collaborators_module_aux(context_params) end
remove_remote(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 811 def remove_remote(context_params) remote_remove_aux(context_params) end
stage(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 650 def stage(context_params) response = stage_aux(context_params) return response unless response.ok? # when changing context send request for getting latest assemblies instead of getting from cache @@invalidate_map << :service @@invalidate_map << :assembly return response end
stage_aux(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 66 def stage_aux(context_params) if context_params.is_there_identifier?(:assembly) service_module_id, service_module_name, assembly_template_name, name = context_params.retrieve_arguments([:service_module_id!, :service_module_name!, :assembly_name!, :option_2], method_argument_names) else service_module_id, service_module_name, assembly_template_name, name = context_params.retrieve_arguments([:service_module_id!, :service_module_name!, :option_1!, :option_2], method_argument_names) end post_body = { :assembly_id => assembly_template_name } # special case when we need service module id context_params.pure_cli_mode = true post_body[:service_module_id] = service_module_id if context_params.pure_cli_mode # using this to make sure cache will be invalidated after new assembly is created from other commands e.g. # 'assembly-create', 'install' etc. @@invalidate_map << :assembly fwd_options = context_params.get_forwarded_options() instance_bindings = options["instance-bindings"] settings = parse_service_settings(options["settings"]) node_size = fwd_options[:node_size]||options.node_size os_type = fwd_options[:os_type]||options.os_type version = fwd_options[:version]||options.version no_auto_complete = fwd_options[:no_auto_complete]||options.no_auto_complete parent_service = fwd_options[:parent_service]||options.parent_service is_target = fwd_options[:is_target]||options.is_target? do_not_encode = fwd_options[:do_not_encode] assembly_list = Assembly.assembly_list() if assembly_template_name.to_s =~ /^[0-9]+$/ assembly_template_name = DTK::Client::Assembly.get_assembly_template_name_for_service(assembly_template_name, service_module_name) assembly_template_name, version = get_name_and_version_from_assembly_template(assembly_template_name) else namespace, module_name = get_namespace_and_name(service_module_name, ':') assembly_template_name = "#{module_name}/#{assembly_template_name}" end assembly_template_name.gsub!(/(::)|(\/)/,'-') if assembly_template_name if name raise DTK::Client::DtkValidationError, "Unable to stage service with name '#{name}'. Service with specified name exists already!" if assembly_list.include?(name) else name = get_assembly_stage_name(assembly_list, assembly_template_name) end post_body.merge!(:name => name) if name post_body.merge!(:instance_bindings => instance_bindings) if instance_bindings post_body.merge!(:settings_json_form => JSON.generate(settings)) if settings post_body.merge!(:node_size => node_size) if node_size post_body.merge!(:os_type => os_type) if os_type post_body.merge!(:version => version) if version post_body.merge!(:service_module_name => service_module_name) if service_module_name post_body.merge!(:no_auto_complete => no_auto_complete) if no_auto_complete post_body.merge!(:parent_service => parent_service) if parent_service post_body.merge!(:is_target => is_target) if is_target post_body.merge!(:do_not_encode => do_not_encode) if do_not_encode response = post rest_url("assembly/stage"), post_body end
stage_target(context_params)
click to toggle source
# File lib/commands/thor/service_module.rb, line 632 def stage_target(context_params) response = stage_aux(context_params) return response unless response.ok? # when changing context send request for getting latest assemblies instead of getting from cache @@invalidate_map << :service @@invalidate_map << :assembly return response end