opswalrus 1.0.53 → 1.0.54

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 007f1ac465143fdd629539509b94a8bf7230b034817526d1265768f97eae0786
4
- data.tar.gz: 9d0cc607ce7c9fcd06d9e402254b3eb5a75a68687a1ee485aa915b3cd488e2b6
3
+ metadata.gz: 50b82ac565a56bb1585653a90c4c0c09b06ba3490c3121da8717e9bdf085f48b
4
+ data.tar.gz: f38e88fa6db2769cd7ae59291ce28f337c1ca8a9bcd00509f8ccc00cd47b0890
5
5
  SHA512:
6
- metadata.gz: 83b67721de074efa3ad368ed21ec469d40928351c4ccc6f32d530e3bbda2cdd81b62f2b72692a4796b74d1efb7bbbfa31721db0eefb93864069dc277f8aa66fe
7
- data.tar.gz: b54d628df099de1f4c2eea591b86449b5fd254d495ccae38f89dd95f5d1137171aaf9e6c1bd2023613f1c33561b5e49bd12d5696d6bc197bc065ead0a79aed1d
6
+ metadata.gz: 751dfb54af8521b4e33a45cd8d38c0aa0b2c433006bd7030e412605584ffb4b7cba44d49fe26b64c7c2c4d0f2cea08a53cd02aea40c1d2341de7d20fbbe1ac35
7
+ data.tar.gz: a52102d80e0b0f966d7b357173f87cafcb6ddcfdf0e9d0b3aa369e115c5b7da03ef0ce1fb6ba8d25486ac296e2f3e06dc717ab0fe61f96cf3c904b0a14b3d87c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opswalrus (1.0.53)
4
+ opswalrus (1.0.54)
5
5
  activesupport (~> 7.0)
6
6
  bcrypt_pbkdf (~> 1.1)
7
7
  binding_of_caller (~> 1.0)
@@ -7,6 +7,5 @@ ssh in: :sequence do
7
7
  puts params.stringify_keys!
8
8
  desc "Running `#{params.ops_file.ops_file_path} #{params.operation_kv_args.join(' ')}` on #{to_s} (alias=#{self.alias})"
9
9
  # run_ops(ops_command, ops_command_options = nil, command_arguments, in_bundle_root_dir: true, ops_prompt_for_sudo_password: false)
10
- puts self.inspect
11
- self._invoke_remote(params.ops_file, *params.operation_kv_args)
10
+ _invoke_remote(params.ops_file, *params.operation_kv_args)
12
11
  end
@@ -56,7 +56,11 @@ module OpsWalrus
56
56
  # end
57
57
 
58
58
  def update()
59
- delete_pwd_bundle_directory
59
+ # delete_pwd_bundle_directory # this was causing problems when we do: ops run -r -b ... because a dynamic package reference was being
60
+ # downloaded to the bundle dir, and then update was being called afterward, which was blowing away
61
+ # the entire bundle dir, so when the bundle dir was copied to the remote host, the ops file being
62
+ # invoked was not present on the remote host, since it had never been copied over as a result
63
+ # of the bundle dir being blown away after the dynamic package reference had been downloaded
60
64
  ensure_pwd_bundle_directory_exists
61
65
 
62
66
  package_yaml_files = pwd.glob("./**/package.yaml") - pwd.glob("./**/#{BUNDLE_DIR}/**/package.yaml")
@@ -204,6 +208,8 @@ module OpsWalrus
204
208
 
205
209
  destination_package_path ||= dynamic_package_path_for_git_package(package_url, version)
206
210
 
211
+ App.instance.debug "Download git package #{package_url} version #{version.inspect} to #{destination_package_path}"
212
+
207
213
  return destination_package_path if destination_package_path.exist?
208
214
 
209
215
  if version
@@ -212,6 +218,8 @@ module OpsWalrus
212
218
  ::Git.clone(package_url, destination_package_path, config: ['submodule.recurse=true'])
213
219
  end
214
220
 
221
+ App.instance.debug "Downloaded git package #{package_url} version #{version.inspect} to #{destination_package_path}"
222
+
215
223
  destination_package_path
216
224
  end
217
225
 
@@ -82,10 +82,9 @@ module OpsWalrus
82
82
  end
83
83
 
84
84
  def _invoke_remote(ops_file, *args, **kwargs)
85
- puts "boom"
86
- is_invocation_a_call_to_package_in_bundle_dir = true
87
- invocation_context = RemoteImportInvocationContext.new(@runtime_env, self, ops_file, is_invocation_a_call_to_package_in_bundle_dir, ops_prompt_for_sudo_password: !!ssh_password)
88
- invocation_context._invoke(*args, **kwargs)
85
+ App.instance.debug "Remove invoke #{ops_file.relative_path_to_app_pwd} on host `#{to_s}` with args:\n #{args.inspect}\nkwargs:\n #{kwargs.inspect}"
86
+
87
+ RemoteInvocation.new(self, ops_file, ops_prompt_for_sudo_password: !!ssh_password).invoke(*args, **kwargs)
89
88
  end
90
89
 
91
90
  # returns [stdout, stderr, exit_status]
@@ -196,4 +196,62 @@ module OpsWalrus
196
196
 
197
197
  end
198
198
 
199
+
200
+
201
+
202
+
203
+ class RemoteInvocation
204
+ def initialize(host_proxy, ops_file, ops_prompt_for_sudo_password: nil)
205
+ @host_proxy = host_proxy
206
+ @ops_file = ops_file
207
+ @ops_prompt_for_sudo_password = ops_prompt_for_sudo_password
208
+ end
209
+
210
+ def invoke(*args, **kwargs)
211
+ # when there are args or kwargs, then the method invocation represents an attempt to run an OpsFile on a remote host,
212
+ # so we want to build up a command and send it to the remote host via HostDSL#run_ops
213
+ remote_run_command_args = @ops_file.relative_path_to_app_pwd.to_s
214
+
215
+ unless args.empty?
216
+ remote_run_command_args << " "
217
+ remote_run_command_args << args.join(" ")
218
+ end
219
+
220
+ begin
221
+ json = JSON.dump(kwargs) unless kwargs.empty?
222
+ if json
223
+ # write the kwargs to a tempfile
224
+ json_kwargs_tempfile = Tempfile.create('ops_invoke_kwargs')
225
+ json_kwargs_tempfile.write(json)
226
+ json_kwargs_tempfile.close() # we want to close the file without unlinking so that we can copy it to the remote host before deleting it
227
+
228
+ # upload the kwargs file to the remote host
229
+ json_kwargs_tempfile_path = json_kwargs_tempfile.path.to_pathname
230
+ remote_json_kwargs_tempfile_basename = json_kwargs_tempfile_path.basename
231
+ @host_proxy.upload(json_kwargs_tempfile_path, remote_json_kwargs_tempfile_basename)
232
+ end
233
+
234
+ # invoke the ops command on the remote host to run the specified ops script on the remote host
235
+ ops_command_options = ""
236
+ ops_command_options << "--pass" if @ops_prompt_for_sudo_password
237
+ ops_command_options << " --params #{remote_json_kwargs_tempfile_basename}" if remote_json_kwargs_tempfile_basename
238
+ retval = if ops_command_options.empty?
239
+ @host_proxy.run_ops(:run, remote_run_command_args, ops_prompt_for_sudo_password: @ops_prompt_for_sudo_password)
240
+ else
241
+ @host_proxy.run_ops(:run, ops_command_options, remote_run_command_args, ops_prompt_for_sudo_password: @ops_prompt_for_sudo_password)
242
+ end
243
+
244
+ retval
245
+ ensure
246
+ if json_kwargs_tempfile
247
+ json_kwargs_tempfile.close rescue nil
248
+ File.unlink(json_kwargs_tempfile) rescue nil
249
+ end
250
+ # todo: make sure this cleanup is present
251
+ if remote_json_kwargs_tempfile_basename
252
+ @host_proxy.execute(:rm, "-f", remote_json_kwargs_tempfile_basename)
253
+ end
254
+ end
255
+ end
256
+ end
199
257
  end
@@ -233,6 +233,13 @@ module OpsWalrus
233
233
  # end
234
234
  # end
235
235
 
236
+ # if ops_file_path is /home/david/sync/projects/ops/davidinfra/opswalrus_bundle/pkg_https---github.com-opswalrus-core_version_/file/exists.ops
237
+ # and the @app.pwd is /home/david/sync/projects/ops/davidinfra
238
+ # then this returns opswalrus_bundle/pkg_https---github.com-opswalrus-core_version_/file/exists.ops
239
+ def relative_path_to_app_pwd
240
+ @ops_file_path.relative_path_from(@app.pwd)
241
+ end
242
+
236
243
  # "/home/david/sync/projects/ops/ops/core/host/info.ops" => "/home/david/sync/projects/ops/ops/core/host"
237
244
  def dirname
238
245
  @ops_file_path.dirname
@@ -48,6 +48,7 @@ module OpsWalrus
48
48
 
49
49
 
50
50
  module OpsFileScriptDSL
51
+ # we run the block in the context of the host proxy object, s.t. `self` within the block evaluates to the host proxy object
51
52
  def ssh_noprep(*args, **kwargs, &block)
52
53
  runtime_env = @runtime_env
53
54
 
@@ -112,6 +113,7 @@ module OpsWalrus
112
113
  results
113
114
  end # def ssh
114
115
 
116
+ # we run the block in the context of the host proxy object, s.t. `self` within the block evaluates to the host proxy object
115
117
  def ssh(*args, **kwargs, &block)
116
118
  runtime_env = @runtime_env
117
119
 
@@ -122,7 +124,6 @@ module OpsWalrus
122
124
 
123
125
  results_lock = Thread::Mutex.new
124
126
  results = {}
125
- # bootstrap_shell_script = BootstrapLinuxHostShellScript
126
127
  # on sshkit_hosts do |sshkit_host|
127
128
  SSHKit::Coordinator.new(sshkit_hosts).each(in: kwargs[:in] || :parallel) do |sshkit_host|
128
129
  # in this context, self is an instance of one of the subclasses of SSHKit::Backend::Abstract, e.g. SSHKit::Backend::Netssh
@@ -1,3 +1,3 @@
1
1
  module OpsWalrus
2
- VERSION = "1.0.53"
2
+ VERSION = "1.0.54"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opswalrus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.53
4
+ version: 1.0.54
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Ellis