Class: OpsWalrus::App
- Inherits:
-
Object
- Object
- OpsWalrus::App
- Defined in:
- lib/opswalrus/app.rb
Constant Summary collapse
- LOCAL_SUDO_PASSWORD_PROMPT =
"[opswalrus] Please enter sudo password to run sudo in local environment: "
- SCRIPT_RESULT_HEADER =
"#### OpsWalrus Script Result JSON ".ljust(80, '#')
Instance Attribute Summary collapse
-
#identity_file_paths ⇒ Object
readonly
Returns the value of attribute identity_file_paths.
-
#local_hostname ⇒ Object
readonly
Returns the value of attribute local_hostname.
Class Method Summary collapse
Instance Method Summary collapse
- #bootstrap ⇒ Object
- #bundle_dir ⇒ Object
- #bundle_status ⇒ Object
- #bundle_update(force = false) ⇒ Object
- #bundler ⇒ Object
- #debug(*args) ⇒ Object
- #debug? ⇒ Boolean
- #decrypt_inventory(file_path, output_file_path) ⇒ Object
- #dry_run! ⇒ Object
- #dry_run? ⇒ Boolean
- #edit_inventory(file_path) ⇒ Object
- #encrypt_inventory(file_path, output_file_path) ⇒ Object
- #error(*args) ⇒ Object
- #error? ⇒ Boolean
- #fatal(*args) ⇒ Object
- #fatal? ⇒ Boolean
-
#find_entry_point_ops_file_in_dir(base_dir, package_operation_and_args) ⇒ Object
returns pair of the form: [ ops_file_path, operation_kv_args ].
-
#get_entry_point_ops_file_and_args(package_operation_and_args) ⇒ Object
package_operation_and_args can take one of the following forms: - [“github.com/davidkellis/my-package”, “operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”] - [“foo.zip”, “foo/myfile.ops”, “arg1:val1”, “arg2:val2”, “arg3:val3”] - [“davidkellis/my-package”, “operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”] - [“davidkellis/my-package”, “operation1”] - [“my-package/operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”] - [“./my-package/operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”] - [“../../my-package/operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”] - [“../../my-package/operation1”].
- #info(*args) ⇒ Object (also: #log)
- #info? ⇒ Boolean
-
#initialize(pwd = Dir.pwd) ⇒ App
constructor
A new instance of App.
- #inspect ⇒ Object
-
#inventory(tag_selection = nil, host_references_override = nil) ⇒ Object
tag_selection is an array of strings.
- #load_entry_point_ops_file(ops_file_path, tmp_bundle_root_dir) ⇒ Object
- #pretty_print_mode! ⇒ Object
- #pretty_print_mode? ⇒ Boolean
- #print_script_result(result) ⇒ Object
- #print_version ⇒ Object
- #prompt_sudo_password ⇒ Object
- #pwd ⇒ Object
- #reboot ⇒ Object
- #report_inventory(host_references, tags: nil) ⇒ Object
-
#run(package_operation_and_args, update_bundle: false) ⇒ Object
package_operation_and_args is of the form [“github.com/davidkellis/my-package/sub-package1”, “operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”] if the first argument is the path to a .ops file, then treat it as a local path, and add the containing package to the load path otherwise, copy the returns the exit status code that the script should terminate with.
- #run_internal(ops_file_name, params = @params) ⇒ Object
-
#run_remote(package_operation_and_args, update_bundle: false) ⇒ Object
package_operation_and_args is of the form [“github.com/davidkellis/my-package/sub-package1”, “operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”] if the first argument is the path to a .ops file, then treat it as a local path, and add the containing package to the load path otherwise, copy the returns the exit status code that the script should terminate with.
- #script_mode! ⇒ Object
- #script_mode? ⇒ Boolean
- #set_identity_files(*paths) ⇒ Object
- #set_inventory_hosts(*hosts) ⇒ Object
- #set_inventory_tags(*tags) ⇒ Object
- #set_local_hostname(hostname) ⇒ Object
-
#set_log_level(log_level) ⇒ Object
log_level = :fatal, :error, :warn, :info, :debug, :trace.
-
#set_params(file_path_or_json_string) ⇒ Object
params is a string that specifies a file path OR it is a string representation of a JSON object: ‘{}’ | ‘… , …’.
- #set_pwd(pwd) ⇒ Object
-
#set_pwd_and_rebase_ops_file(new_working_directory, ops_file) ⇒ Object
returns a new OpsFile that points at the revised pathname when considered as relative to the new working directory.
-
#set_pwd_to_ops_file_package_directory(ops_file) ⇒ Object
sets the App’s pwd to the ops file’s package directory and returns a new OpsFile that points at the revised pathname when considered as relative to the package file’s directory.
- #set_pwd_to_parent_of_bundle_dir(ops_file) ⇒ Object
- #set_sudo_password(password) ⇒ Object
- #set_sudo_user(user) ⇒ Object
- #shell(command) ⇒ Object
- #sudo_password ⇒ Object
- #sudo_user ⇒ Object
- #to_s ⇒ Object
- #trace(*args) ⇒ Object
- #trace? ⇒ Boolean
- #unzip(zip_bundle_file = nil, output_dir = nil) ⇒ Object
- #verbose? ⇒ Boolean
- #warn(*args) ⇒ Object (also: #important)
- #warn? ⇒ Boolean
- #zip ⇒ Object
Constructor Details
#initialize(pwd = Dir.pwd) ⇒ App
Returns a new instance of App.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/opswalrus/app.rb', line 41 def initialize(pwd = Dir.pwd) SemanticLogger.default_level = :warn # SemanticLogger.add_appender(file_name: 'development.log', formatter: :color) # Log to a file, and use the colorized formatter SemanticLogger.add_appender(io: $stdout, formatter: :color) # Log errors and above to standard error: @logger = SemanticLogger[OpsWalrus] # Logger.new($stdout, level: Logger::INFO) @logger.level = :warn # :trace or 'trace' # @logger.warn Style.yellow("warn"), foo: "bar", baz: {qux: "quux"} # @logger.info Style.yellow("info"), foo: "bar", baz: {qux: "quux"} # @logger.debug Style.yellow("debug"), foo: "bar", baz: {qux: "quux"} # @logger.trace Style.yellow("trace"), foo: "bar", baz: {qux: "quux"} @sudo_user = nil @sudo_password = nil @identity_file_paths = [] @inventory_host_references = [] @inventory_tag_selections = [] @params = nil @pwd = pwd.to_pathname @bundler = Bundler.new(self, @pwd) @local_hostname = "localhost" @mode = nil @dry_run = false @zip_mutex = Thread::Mutex.new end |
Instance Attribute Details
#identity_file_paths ⇒ Object (readonly)
Returns the value of attribute identity_file_paths.
39 40 41 |
# File 'lib/opswalrus/app.rb', line 39 def identity_file_paths @identity_file_paths end |
#local_hostname ⇒ Object (readonly)
Returns the value of attribute local_hostname.
38 39 40 |
# File 'lib/opswalrus/app.rb', line 38 def local_hostname @local_hostname end |
Class Method Details
.instance(*args) ⇒ Object
31 32 33 |
# File 'lib/opswalrus/app.rb', line 31 def self.instance(*args) @instance ||= new(*args) end |
Instance Method Details
#bootstrap ⇒ Object
228 229 230 |
# File 'lib/opswalrus/app.rb', line 228 def bootstrap() run_internal("_bootstrap.ops") end |
#bundle_dir ⇒ Object
122 123 124 |
# File 'lib/opswalrus/app.rb', line 122 def bundle_dir @bundler.bundle_dir end |
#bundle_status ⇒ Object
475 476 |
# File 'lib/opswalrus/app.rb', line 475 def bundle_status end |
#bundle_update(force = false) ⇒ Object
478 479 480 |
# File 'lib/opswalrus/app.rb', line 478 def bundle_update(force = false) bundler.update(force) end |
#bundler ⇒ Object
118 119 120 |
# File 'lib/opswalrus/app.rb', line 118 def bundler @bundler end |
#debug(*args) ⇒ Object
161 162 163 |
# File 'lib/opswalrus/app.rb', line 161 def debug(*args) @logger.debug(*args) end |
#debug? ⇒ Boolean
164 165 166 |
# File 'lib/opswalrus/app.rb', line 164 def debug? @logger.debug? end |
#decrypt_inventory(file_path, output_file_path) ⇒ Object
514 515 516 517 518 519 |
# File 'lib/opswalrus/app.rb', line 514 def decrypt_inventory(file_path, output_file_path) raise "File not found: #{file_path}" unless File.exist?(file_path) hosts_file = HostsFile.new(file_path) hosts_file.decrypt(output_file_path) end |
#dry_run! ⇒ Object
95 96 97 |
# File 'lib/opswalrus/app.rb', line 95 def dry_run! @dry_run = true end |
#dry_run? ⇒ Boolean
91 92 93 |
# File 'lib/opswalrus/app.rb', line 91 def dry_run? @dry_run end |
#edit_inventory(file_path) ⇒ Object
501 502 503 504 505 |
# File 'lib/opswalrus/app.rb', line 501 def edit_inventory(file_path) raise "File not found: #{file_path}" unless File.exist?(file_path) HostsFile.edit(file_path) end |
#encrypt_inventory(file_path, output_file_path) ⇒ Object
507 508 509 510 511 512 |
# File 'lib/opswalrus/app.rb', line 507 def encrypt_inventory(file_path, output_file_path) raise "File not found: #{file_path}" unless File.exist?(file_path) hosts_file = HostsFile.new(file_path) hosts_file.encrypt(output_file_path) end |
#error(*args) ⇒ Object
138 139 140 |
# File 'lib/opswalrus/app.rb', line 138 def error(*args) @logger.error(*args) end |
#error? ⇒ Boolean
141 142 143 |
# File 'lib/opswalrus/app.rb', line 141 def error? @logger.error? end |
#fatal(*args) ⇒ Object
131 132 133 |
# File 'lib/opswalrus/app.rb', line 131 def fatal(*args) @logger.fatal(*args) end |
#fatal? ⇒ Boolean
134 135 136 |
# File 'lib/opswalrus/app.rb', line 134 def fatal? @logger.fatal? end |
#find_entry_point_ops_file_in_dir(base_dir, package_operation_and_args) ⇒ Object
returns pair of the form: [ ops_file_path, operation_kv_args ]
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/opswalrus/app.rb', line 451 def find_entry_point_ops_file_in_dir(base_dir, package_operation_and_args) ops_file_path = nil base_path = Pathname.new(base_dir) path_parts = 0 package_operation_and_args.each do |candidate_path_arg| candidate_base_path = base_path.join(candidate_path_arg) candidate_ops_file = candidate_base_path.sub_ext(".ops") if candidate_ops_file.exist? path_parts += 1 ops_file_path = candidate_ops_file break elsif candidate_base_path.exist? path_parts += 1 else raise Error, "Operation not found in: #{candidate_base_path}" end base_path = candidate_base_path end operation_kv_args = package_operation_and_args.drop(path_parts) [ops_file_path, operation_kv_args] end |
#get_entry_point_ops_file_and_args(package_operation_and_args) ⇒ Object
package_operation_and_args can take one of the following forms:
- “github.com/davidkellis/my-package”, “operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”
- “foo.zip”, “foo/myfile.ops”, “arg1:val1”, “arg2:val2”, “arg3:val3”
- “davidkellis/my-package”, “operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”
- “davidkellis/my-package”, “operation1”
- “my-package/operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”
- “./my-package/operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”
- “../../my-package/operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”
- “../../my-package/operation1”
returns 3-tuple of the form: [ ops_file_path, operation_kv_args, optional_tmp_bundle_root_dir ] such that the third item - optional_tmp_bundle_root_dir - if present, should be deleted after the script has completed running
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/opswalrus/app.rb', line 408 def get_entry_point_ops_file_and_args(package_operation_and_args) package_operation_and_args = package_operation_and_args.dup package_or_ops_file_reference = package_operation_and_args.slice!(0, 1).first tmp_bundle_root_dir = nil case when Dir.exist?(package_or_ops_file_reference) dir = package_or_ops_file_reference ops_file_path, operation_kv_args = find_entry_point_ops_file_in_dir(dir, package_operation_and_args) [ops_file_path, operation_kv_args, tmp_bundle_root_dir] when File.exist?(package_or_ops_file_reference) first_filepath = package_or_ops_file_reference.to_pathname.realpath ops_file_path, operation_kv_args = case first_filepath.extname.downcase when ".ops" [first_filepath, package_operation_and_args] when ".zip" tmp_bundle_root_dir = Dir.mktmpdir.to_pathname # this is the temporary bundle root dir # unzip the bundle into the temp directory DirZipper.unzip(first_filepath, tmp_bundle_root_dir) find_entry_point_ops_file_in_dir(tmp_bundle_root_dir, package_operation_and_args) else raise Error, "Unknown file type for entrypoint: #{first_filepath}" end # operation_kv_args = package_operation_and_args [ops_file_path, operation_kv_args, tmp_bundle_root_dir] when repo_url = Git.repo?(package_or_ops_file_reference) destination_package_path = bundler.download_git_package(repo_url) ops_file_path, operation_kv_args = find_entry_point_ops_file_in_dir(destination_package_path, package_operation_and_args) # for an original package_operation_and_args of ["github.com/davidkellis/my-package", "operation1", "arg1:val1", "arg2:val2", "arg3:val3"] # we return: [ "#{pwd}/#{Bundler::BUNDLE_DIR}/github-com-davidkellis-my-package/operation1.ops", ["arg1:val1", "arg2:val2", "arg3:val3"] ] [ops_file_path, operation_kv_args, tmp_bundle_root_dir] else raise Error, "Unknown operation reference: #{package_or_ops_file_reference.inspect}" end end |
#info(*args) ⇒ Object Also known as: log
153 154 155 |
# File 'lib/opswalrus/app.rb', line 153 def info(*args) @logger.info(*args) end |
#info? ⇒ Boolean
157 158 159 |
# File 'lib/opswalrus/app.rb', line 157 def info? @logger.info? end |
#inspect ⇒ Object
71 72 73 |
# File 'lib/opswalrus/app.rb', line 71 def inspect "" # return empty string because we won't want anyone accidentally printing or inspecting @sudo_password end |
#inventory(tag_selection = nil, host_references_override = nil) ⇒ Object
tag_selection is an array of strings
491 492 493 494 495 496 497 498 499 |
# File 'lib/opswalrus/app.rb', line 491 def inventory(tag_selection = nil, host_references_override = nil) host_references = host_references_override || @inventory_host_references = @inventory_tag_selections + (tag_selection || []) .uniq! host_references = [HostsFile::DEFAULT_FILE_NAME] if (host_references.nil? || host_references.empty?) && File.exist?(HostsFile::DEFAULT_FILE_NAME) Inventory.new(host_references, ) end |
#load_entry_point_ops_file(ops_file_path, tmp_bundle_root_dir) ⇒ Object
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/opswalrus/app.rb', line 350 def load_entry_point_ops_file(ops_file_path, tmp_bundle_root_dir) ops_file = OpsFile.new(self, ops_file_path) # we are running the ops file from within a temporary bundle root directory created by unzipping a zip bundle workspace if tmp_bundle_root_dir return set_pwd_and_rebase_ops_file(tmp_bundle_root_dir, ops_file) end # if the ops file is contained within a bundle directory, then that means we're probably running this command invocation # on a remote host, e.g. /home/linuxbrew/.linuxbrew/bin/gem exec -g opswalrus ops run --script /tmp/d20230822-18829-2j5ij2 opswalrus_bundle docker install install # and the corresponding entry point, e.g. /tmp/d20230822-18829-2j5ij2/opswalrus_bundle/docker/install/install.ops # is actually being run from a temporary zip bundle root directory # so we want to set the app's pwd to be the parent directory of the Bundler::BUNDLE_DIR directory, e.g. /tmp/d20230822-18829-2j5ij2 if ops_file.ops_file_path.to_s =~ /#{Bundler::BUNDLE_DIR}/ return set_pwd_to_parent_of_bundle_dir(ops_file) end # if the ops file is part of a package, then set the package directory as the app's pwd if ops_file.package_file && ops_file.package_file.dirname.to_s !~ /#{Bundler::BUNDLE_DIR}/ return set_pwd_to_ops_file_package_directory(ops_file) end ops_file end |
#pretty_print_mode! ⇒ Object
79 80 81 |
# File 'lib/opswalrus/app.rb', line 79 def pretty_print_mode! @mode = :pretty end |
#pretty_print_mode? ⇒ Boolean
87 88 89 |
# File 'lib/opswalrus/app.rb', line 87 def pretty_print_mode? @mode == :pretty end |
#print_script_result(result) ⇒ Object
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/opswalrus/app.rb', line 331 def print_script_result(result) if script_mode? || pretty_print_mode? SemanticLogger.flush output = StringIO.open do |io| io.puts(SCRIPT_RESULT_HEADER) if script_mode? obj = case result when Invocation::Success result.value when Invocation::Error result.serialize_error end io.puts JSON.pretty_generate(obj) io.string end # puts "print_script_result - #{Time.now.strftime('%s%L')}" puts output end end |
#print_version ⇒ Object
521 522 523 |
# File 'lib/opswalrus/app.rb', line 521 def print_version puts VERSION end |
#prompt_sudo_password ⇒ Object
200 201 202 203 204 |
# File 'lib/opswalrus/app.rb', line 200 def prompt_sudo_password password = IO::console.getpass(LOCAL_SUDO_PASSWORD_PROMPT) set_sudo_password(password) nil end |
#pwd ⇒ Object
184 185 186 |
# File 'lib/opswalrus/app.rb', line 184 def pwd @pwd || raise("No working directory specified") end |
#reboot ⇒ Object
236 237 238 |
# File 'lib/opswalrus/app.rb', line 236 def reboot() run_internal("_reboot.ops") end |
#report_inventory(host_references, tags: nil) ⇒ Object
482 483 484 485 486 487 488 |
# File 'lib/opswalrus/app.rb', line 482 def report_inventory(host_references, tags: nil) selected_hosts = inventory(, host_references).hosts selected_hosts.each do |host| puts host.summary(verbose?) end end |
#run(package_operation_and_args, update_bundle: false) ⇒ Object
package_operation_and_args is of the form [“github.com/davidkellis/my-package/sub-package1”, “operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”] if the first argument is the path to a .ops file, then treat it as a local path, and add the containing package
to the load path
otherwise, copy the returns the exit status code that the script should terminate with
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/opswalrus/app.rb', line 304 def run(package_operation_and_args, update_bundle: false) return 0 if package_operation_and_args.empty? ops_file_path, operation_kv_args, tmp_bundle_root_dir = get_entry_point_ops_file_and_args(package_operation_and_args) ops_file = load_entry_point_ops_file(ops_file_path, tmp_bundle_root_dir) bundler.update(true) if update_bundle debug "Running: #{ops_file.ops_file_path}" op = OperationRunner.new(self, ops_file) result = op.run(operation_kv_args, params_json_hash: @params) exit_status = result.exit_status print_script_result(result) exit_status rescue Error => e = "Runtime error: #{e.}" puts print_script_result() 1 ensure FileUtils.remove_entry(tmp_bundle_root_dir) if tmp_bundle_root_dir end |
#run_internal(ops_file_name, params = @params) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/opswalrus/app.rb', line 240 def run_internal(ops_file_name, params = @params) set_pwd(__FILE__.to_pathname.dirname) internal_ops_file = OpsFile.new(self, __FILE__.to_pathname.dirname.join(ops_file_name)) op = OperationRunner.new(self, internal_ops_file) result = op.run([], params_json_hash: params) # puts "result class=#{result.class}" exit_status = result.exit_status # when we are using the shell method # puts result.value.class # EasyNavProxy # puts result.value # Hash looking object stdout = JSON.pretty_generate(result.value.to_h) output = if exit_status == 0 Style.green(stdout) else Style.red(stdout) end puts output exit_status rescue Error => e = "Runtime error: #{e.}" puts print_script_result() 1 end |
#run_remote(package_operation_and_args, update_bundle: false) ⇒ Object
package_operation_and_args is of the form [“github.com/davidkellis/my-package/sub-package1”, “operation1”, “arg1:val1”, “arg2:val2”, “arg3:val3”] if the first argument is the path to a .ops file, then treat it as a local path, and add the containing package
to the load path
otherwise, copy the returns the exit status code that the script should terminate with
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/opswalrus/app.rb', line 270 def run_remote(package_operation_and_args, update_bundle: false) return 0 if package_operation_and_args.empty? ops_file_path, operation_kv_args, tmp_bundle_root_dir = get_entry_point_ops_file_and_args(package_operation_and_args) ops_file = load_entry_point_ops_file(ops_file_path, tmp_bundle_root_dir) bundler.update(true) if update_bundle debug "Running: #{ops_file.ops_file_path}" internal_ops_file = OpsFile.new(self, __FILE__.to_pathname.dirname.join("_run_remote.ops")) op = OperationRunner.new(self, internal_ops_file) result = op.run([], params_json_hash: {ops_file: ops_file, operation_kv_args: operation_kv_args}.stringify_keys) exit_status = result.exit_status print_script_result(result) exit_status rescue Error => e = "Runtime error: #{e.}" puts print_script_result() 1 ensure FileUtils.remove_entry(tmp_bundle_root_dir) if tmp_bundle_root_dir end |
#script_mode! ⇒ Object
75 76 77 |
# File 'lib/opswalrus/app.rb', line 75 def script_mode! @mode = :script end |
#script_mode? ⇒ Boolean
83 84 85 |
# File 'lib/opswalrus/app.rb', line 83 def script_mode? @mode == :script end |
#set_identity_files(*paths) ⇒ Object
104 105 106 |
# File 'lib/opswalrus/app.rb', line 104 def set_identity_files(*paths) @identity_file_paths = paths.flatten.compact.uniq end |
#set_inventory_hosts(*hosts) ⇒ Object
108 109 110 111 |
# File 'lib/opswalrus/app.rb', line 108 def set_inventory_hosts(*hosts) hosts.flatten!.compact! @inventory_host_references.concat(hosts).compact! end |
#set_inventory_tags(*tags) ⇒ Object
113 114 115 116 |
# File 'lib/opswalrus/app.rb', line 113 def (*) .flatten!.compact! @inventory_tag_selections.concat().compact! end |
#set_local_hostname(hostname) ⇒ Object
99 100 101 102 |
# File 'lib/opswalrus/app.rb', line 99 def set_local_hostname(hostname) hostname = hostname.strip @local_hostname = hostname.empty? ? "localhost" : hostname end |
#set_log_level(log_level) ⇒ Object
log_level = :fatal, :error, :warn, :info, :debug, :trace
127 128 129 |
# File 'lib/opswalrus/app.rb', line 127 def set_log_level(log_level) @logger.level = log_level end |
#set_params(file_path_or_json_string) ⇒ Object
params is a string that specifies a file path OR it is a string representation of a JSON object: ‘{}’ | ‘… , …’
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/opswalrus/app.rb', line 211 def set_params(file_path_or_json_string) params = if File.exist?(file_path_or_json_string) File.read(file_path_or_json_string) else file_path_or_json_string end json_hash = JSON.parse(params) rescue nil json_hash = json_hash.is_a?(Hash) ? json_hash : nil if App.instance.info? info("runtime params:") info(json_hash.inspect) end @params = json_hash # @params returns a Hash or nil end |
#set_pwd(pwd) ⇒ Object
179 180 181 182 |
# File 'lib/opswalrus/app.rb', line 179 def set_pwd(pwd) @pwd = pwd.to_pathname @bundler = Bundler.new(self, @pwd) end |
#set_pwd_and_rebase_ops_file(new_working_directory, ops_file) ⇒ Object
returns a new OpsFile that points at the revised pathname when considered as relative to the new working directory
388 389 390 391 392 393 394 |
# File 'lib/opswalrus/app.rb', line 388 def set_pwd_and_rebase_ops_file(new_working_directory, ops_file) set_pwd(new_working_directory) rebased_ops_file_relative_path = ops_file.ops_file_path.relative_path_from(new_working_directory) # note: rebased_ops_file_relative_path is a relative path that is relative to new_working_directory absolute_ops_file_path = new_working_directory.join(rebased_ops_file_relative_path) OpsFile.new(self, absolute_ops_file_path) end |
#set_pwd_to_ops_file_package_directory(ops_file) ⇒ Object
sets the App’s pwd to the ops file’s package directory and returns a new OpsFile that points at the revised pathname when considered as relative to the package file’s directory
383 384 385 |
# File 'lib/opswalrus/app.rb', line 383 def set_pwd_to_ops_file_package_directory(ops_file) set_pwd_and_rebase_ops_file(ops_file.package_file.dirname, ops_file) end |
#set_pwd_to_parent_of_bundle_dir(ops_file) ⇒ Object
375 376 377 378 379 |
# File 'lib/opswalrus/app.rb', line 375 def set_pwd_to_parent_of_bundle_dir(ops_file) match = /^(.*)#{Bundler::BUNDLE_DIR}.*$/.match(ops_file.ops_file_path.to_s) parent_directory_path = match.captures.first.to_pathname.cleanpath set_pwd_and_rebase_ops_file(parent_directory_path, ops_file) end |
#set_sudo_password(password) ⇒ Object
196 197 198 |
# File 'lib/opswalrus/app.rb', line 196 def set_sudo_password(password) @sudo_password = password end |
#set_sudo_user(user) ⇒ Object
188 189 190 |
# File 'lib/opswalrus/app.rb', line 188 def set_sudo_user(user) @sudo_user = user end |
#shell(command) ⇒ Object
232 233 234 |
# File 'lib/opswalrus/app.rb', line 232 def shell(command) run_internal("_shell.ops", {"command" => command}) end |
#sudo_password ⇒ Object
206 207 208 |
# File 'lib/opswalrus/app.rb', line 206 def sudo_password @sudo_password end |
#sudo_user ⇒ Object
192 193 194 |
# File 'lib/opswalrus/app.rb', line 192 def sudo_user @sudo_user || "root" end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/opswalrus/app.rb', line 67 def to_s "" # return empty string because we won't want anyone accidentally printing or inspecting @sudo_password end |
#trace(*args) ⇒ Object
168 169 170 |
# File 'lib/opswalrus/app.rb', line 168 def trace(*args) @logger.trace(*args) end |
#trace? ⇒ Boolean
171 172 173 |
# File 'lib/opswalrus/app.rb', line 171 def trace? @logger.trace? end |
#unzip(zip_bundle_file = nil, output_dir = nil) ⇒ Object
525 526 527 |
# File 'lib/opswalrus/app.rb', line 525 def unzip(zip_bundle_file = nil, output_dir = nil) bundler.unzip(zip_bundle_file, output_dir) end |
#verbose? ⇒ Boolean
175 176 177 |
# File 'lib/opswalrus/app.rb', line 175 def verbose? info? || debug? || trace? end |
#warn(*args) ⇒ Object Also known as: important
145 146 147 |
# File 'lib/opswalrus/app.rb', line 145 def warn(*args) @logger.warn(*args) end |
#warn? ⇒ Boolean
149 150 151 |
# File 'lib/opswalrus/app.rb', line 149 def warn? @logger.warn? end |