ztk 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,6 +10,10 @@ Zachary's (DevOp) Tool Kit is a general purpose utility gem, featuring a collect
10
10
 
11
11
  # RESOURCES
12
12
 
13
+ Documentation:
14
+
15
+ * http://zpatten.github.io/ztk/
16
+
13
17
  Source:
14
18
 
15
19
  * https://github.com/zpatten/ztk
@@ -18,10 +22,6 @@ Issues:
18
22
 
19
23
  * https://github.com/zpatten/ztk/issues
20
24
 
21
- Documentation:
22
-
23
- * http://zpatten.github.io/ztk/
24
-
25
25
  # LICENSE
26
26
 
27
27
  ZTK - Zachary's (DevOp) Tool Kit
data/lib/ztk/benchmark.rb CHANGED
@@ -81,7 +81,7 @@ module ZTK
81
81
  # after the block is yielded. This *String* should have an *sprintf*
82
82
  # floating point macro in it if the benchmark is desired to be embedded
83
83
  # in the given *String*.
84
- # @option options [Boolean] :use_spinner (true) Weither or not to use the
84
+ # @option options [Boolean] :use_spinner (true) Whether or not to use the
85
85
  # ZTK::Spinner while benchmarking.
86
86
  #
87
87
  # @yield Block should execute the tasks to be benchmarked.
data/lib/ztk/ssh.rb CHANGED
@@ -119,32 +119,40 @@ module ZTK
119
119
  autoload :Command, 'ztk/ssh/command'
120
120
  autoload :Download, 'ztk/ssh/download'
121
121
  autoload :Exec, 'ztk/ssh/exec'
122
+ autoload :File, 'ztk/ssh/file'
122
123
  autoload :Upload, 'ztk/ssh/upload'
123
124
 
124
125
  include ZTK::SSH::Bootstrap
125
126
  include ZTK::SSH::Command
126
127
  include ZTK::SSH::Download
127
128
  include ZTK::SSH::Exec
129
+ include ZTK::SSH::File
128
130
  include ZTK::SSH::Upload
129
131
 
130
132
  # @param [Hash] configuration Configuration options hash.
131
- # @option config [String] :host_name Server hostname to connect to.
132
- # @option config [String] :user Username to use for authentication.
133
- # @option config [String, Array<String>] :keys A single or series of
133
+ # @option configuration [String] :host_name Server hostname to connect to.
134
+ # @option configuration [String] :user Username to use for authentication.
135
+ # @option configuration [String, Array<String>] :keys A single or series of
134
136
  # identity files to use for authentication.
135
- # @option config [String] :password Password to use for authentication.
136
- # @option config [Integer] :timeout SSH connection timeout to use.
137
- # @option config [Boolean] :compression Weither or not to use compression
138
- # for this session.
139
- # @option config [Integer] :compression_level What level of compression to
140
- # use.
141
- # @option config [String] :proxy_host_name Server hostname to proxy through.
142
- # @option config [String] :proxy_user Username to use for proxy
137
+ # @option configuration [String] :password Password to use for authentication.
138
+ # @option configuration [Integer] :timeout (60) SSH connection timeout in
139
+ # seconds to use.
140
+ # @option configuration [Boolean] :compression (false) Whether or not to use
141
+ # compression for this session.
142
+ # @option configuration [Integer] :compression_level What level of
143
+ # compression to use.
144
+ # @option configuration [String] :proxy_host_name Server hostname to proxy
145
+ # through.
146
+ # @option configuration [String] :proxy_user Username to use for proxy
143
147
  # authentication.
144
- # @option config [Boolean] :request_pty Weither or not we should try to
145
- # obtain a PTY
146
- # @option config [String, Array<String>] :proxy_keys A single or series of
147
- # identity files to use for authentication with the proxy.
148
+ # @option configuration [Boolean] :request_pty (true) Whether or not we
149
+ # should try to obtain a PTY
150
+ # @option configuration [Boolean] :ignore_exit_status (false) Whether or not
151
+ # we should throw an exception if the exit status is not kosher.
152
+ # @option configuration [Boolean] :forward_agent (true) Whether or not to
153
+ # enable SSH agent forwarding.
154
+ # @option configuration [String, Array<String>] :proxy_keys A single or
155
+ # series of identity files to use for authentication with the proxy.
148
156
  def initialize(configuration={})
149
157
  super({
150
158
  :forward_agent => true,
@@ -181,7 +189,6 @@ module ZTK
181
189
  # process.
182
190
  #
183
191
  # @example Launch a console:
184
- # $logger = ZTK::Logger.new(STDOUT)
185
192
  # ssh = ZTK::SSH.new
186
193
  # ssh.config do |config|
187
194
  # config.user = ENV["USER"]
@@ -26,7 +26,7 @@ module ZTK
26
26
  def bootstrap(content, use_sudo=true)
27
27
  tempfile = Tempfile.new("bootstrap")
28
28
 
29
- File.open(tempfile, 'w') do |file|
29
+ ::File.open(tempfile, 'w') do |file|
30
30
  file.puts(content)
31
31
  file.respond_to?(:flush) and file.flush
32
32
  end
@@ -0,0 +1,65 @@
1
+ ################################################################################
2
+ #
3
+ # Author: Zachary Patten <zachary@jovelabs.net>
4
+ # Copyright: Copyright (c) Zachary Patten
5
+ # License: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ ################################################################################
20
+ module ZTK
21
+ class SSH
22
+
23
+ module File
24
+ require 'tempfile'
25
+
26
+ # Opens a temporary local file, yielding this to the supplied block. Once
27
+ # the block returns the temporary file is uploaded to the remote host and
28
+ # installed as the supplied target.
29
+ #
30
+ # If the optional 'chown' or 'chmod' options are supplied then their
31
+ # respective actions will be taken on the target file on the remote host.
32
+ #
33
+ # @param [Hash] options The options hash.
34
+ # @option options [String] :target The target file on the remote host.
35
+ # @option options [String] :chown A user:group representation of who
36
+ # to change ownership of the target file to (i.e. 'root:root').
37
+ # @option options [String] :chmod An octal file mode which to set the
38
+ # target file to (i.e. '0755').
39
+ # @return [Boolean] Returns true if successfull.
40
+ def file(options={}, &block)
41
+ target = options[:target]
42
+ chown = options[:chown]
43
+ chmod = options[:chmod]
44
+
45
+ target.nil? and raise SSHError, "You must supply a target file!"
46
+ !block_given? and raise SSHError, "You must supply a block!"
47
+
48
+ tempfile = Tempfile.new("tempfile")
49
+ ::File.open(tempfile, 'w') do |file|
50
+ yield(file)
51
+ end
52
+ self.upload(tempfile.path, tempfile.path)
53
+
54
+ self.exec(%(sudo mv -v #{tempfile.path} #{target}), :silence => true)
55
+
56
+ self.exec(%(sudo chown -v #{chown} #{target}), :silence => true) if !chown.nil?
57
+ self.exec(%(sudo chmod -v #{chmod} #{target}), :silence => true) if !chmod.nil?
58
+
59
+ true
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
@@ -101,7 +101,7 @@ module ZTK
101
101
  # method will timeout and return false after the amount of seconds specified
102
102
  # in *config.timeout* has passed if the socket has not become ready.
103
103
  #
104
- # @return [Boolean] Returns true or false depending on weither the socket
104
+ # @return [Boolean] Returns true or false depending on Whether the socket
105
105
  # is ready or not.
106
106
  def ready?
107
107
  config.host.nil? and log_and_raise(TCPSocketCheckError, "You must supply a host!")
@@ -128,7 +128,7 @@ module ZTK
128
128
  # method will timeout and return false after the amount of seconds specified
129
129
  # in *config.wait* has passed if the socket has not become ready.
130
130
  #
131
- # @return [Boolean] Returns true or false depending on weither the socket
131
+ # @return [Boolean] Returns true or false depending on Whether the socket
132
132
  # became ready or not.
133
133
  def wait
134
134
  config.ui.logger.debug { "Waiting for socket to become available; timeout after #{config.wait} seconds." }
data/lib/ztk/version.rb CHANGED
@@ -21,6 +21,6 @@
21
21
  module ZTK
22
22
 
23
23
  # ZTK Version String
24
- VERSION = "1.2.0"
24
+ VERSION = "1.3.0"
25
25
 
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ztk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-27 00:00:00.000000000 Z
12
+ date: 2013-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erubis
@@ -204,6 +204,7 @@ files:
204
204
  - lib/ztk/ssh/command.rb
205
205
  - lib/ztk/ssh/download.rb
206
206
  - lib/ztk/ssh/exec.rb
207
+ - lib/ztk/ssh/file.rb
207
208
  - lib/ztk/ssh/upload.rb
208
209
  - lib/ztk/tcp_socket_check.rb
209
210
  - lib/ztk/template.rb
@@ -245,7 +246,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
246
  version: '0'
246
247
  segments:
247
248
  - 0
248
- hash: 1781664085234422223
249
+ hash: 2390490628279422468
249
250
  required_rubygems_version: !ruby/object:Gem::Requirement
250
251
  none: false
251
252
  requirements:
@@ -254,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
255
  version: '0'
255
256
  segments:
256
257
  - 0
257
- hash: 1781664085234422223
258
+ hash: 2390490628279422468
258
259
  requirements: []
259
260
  rubyforge_project:
260
261
  rubygems_version: 1.8.25