knife-push 1.0.2 → 2.0.0

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
- SHA1:
3
- metadata.gz: 10bd3739e9d8155db578d60947f5149d825c011c
4
- data.tar.gz: d3d2037fe10e4ce7e31718a72256d9943a0445b7
2
+ SHA256:
3
+ metadata.gz: 636e6fa1d65f445cf9f4981f3d75b857854b756f507468f6950a4234e3b6f980
4
+ data.tar.gz: 11b1c0bbec31bb8a6e69469cafd3d385458d3f3f8f21e42b9afae6bd673c971f
5
5
  SHA512:
6
- metadata.gz: 0706958a8cad9e8426edb6049ced027b2ee04369bd1c625b7e57d5acc33adc9cf3ff87cbb9e4c8f2206d7e90bd46a6e8bee4cf03f93b3080e1878a5c9ce7fb57
7
- data.tar.gz: 065e930d0d88fc8fe5df166aaea51d48a85805011bb5a14e3cfe2bcf1761cfdf6fd802c15edefdde747a25c067bc32e3bb7a0811ff24d017c612e95415fe9eee
6
+ metadata.gz: 4ed039e98ff4e483ac41f03c2f17b7b58e344236d1e92954e3850ca947fef6a48c3333cb10cc75f7dad56868d27010f2a41439542160a3d4682011fb63844601
7
+ data.tar.gz: 25f6b27f874f515b06857c57c450652c824a6471dcba8114c9a92255e9eeffd591c935a5b7d2d026edb22090a2bd52dbaa804d766a382fd10120dfdac1f252ba
@@ -15,6 +15,8 @@
15
15
  # under the License.
16
16
  #
17
17
 
18
+ require "addressable/uri"
19
+
18
20
  class Chef
19
21
  class Knife
20
22
  module JobHelpers
@@ -22,11 +24,10 @@ class Chef
22
24
  node_names = []
23
25
  if search
24
26
  q = Chef::Search::Query.new
25
- escaped_query = URI.escape(search,
26
- Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
27
+ escaped_query = Addressable::URI.encode_component(search, Addressable::URI::CharacterClasses::QUERY)
27
28
  begin
28
29
  nodes = q.search(:node, escaped_query).first
29
- rescue Net::HTTPServerException => e
30
+ rescue Net::HTTPClientException => e
30
31
  msg Chef::JSONCompat.from_json(e.response.body)["error"].first
31
32
  ui.error("knife search failed: #{msg}")
32
33
  exit 1
@@ -41,7 +42,7 @@ class Chef
41
42
  exit 1
42
43
  end
43
44
 
44
- return node_names
45
+ node_names
45
46
  end
46
47
 
47
48
  def status_string(job)
@@ -81,8 +82,8 @@ class Chef
81
82
 
82
83
  def status_code(job)
83
84
  if job["status"] == "complete" && job["nodes"].keys.all? do |key|
84
- key == "succeeded" || key == "nacked" || key == "unavailable"
85
- end
85
+ key == "succeeded" || key == "nacked" || key == "unavailable"
86
+ end
86
87
  0
87
88
  else
88
89
  1
@@ -117,7 +118,7 @@ class Chef
117
118
  exit 1
118
119
  end
119
120
  contents = ""
120
- if File.exists?(file_name)
121
+ if File.exist?(file_name)
121
122
  File.open(file_name, "rb") do |file|
122
123
  contents = file.read
123
124
  end
@@ -125,7 +126,7 @@ class Chef
125
126
  ui.error "#{file_name} not found"
126
127
  exit 1
127
128
  end
128
- return contents
129
+ contents
129
130
  end
130
131
 
131
132
  def get_env(config)
@@ -21,9 +21,9 @@ class Chef
21
21
  banner "knife job output <job id> <node> [<node> ...]"
22
22
 
23
23
  option :channel,
24
- :long => "--channel stdout|stderr",
25
- :default => "stdout",
26
- :description => "Which output channel to fetch (default stdout)."
24
+ long: "--channel stdout|stderr",
25
+ default: "stdout",
26
+ description: "Which output channel to fetch (default stdout)."
27
27
 
28
28
  def run
29
29
  job_id = name_args[0]
@@ -38,17 +38,11 @@ class Chef
38
38
  end
39
39
 
40
40
  def get_channel(channel)
41
- channel = channel || "stdout"
42
- case channel
43
- when "stdout"
44
- return channel
45
- when "stderr"
46
- return channel
47
- else
48
- raise "Invalid Format please enter stdout or stderr"
49
- end
50
- end
41
+ channel ||= "stdout"
42
+ return channel if channel == "stdout" || channel == "stderr"
51
43
 
44
+ raise "Invalid Format please enter stdout or stderr"
45
+ end
52
46
  end
53
47
  end
54
48
  end
@@ -15,7 +15,7 @@
15
15
  # under the License.
16
16
  #
17
17
 
18
- require "chef/knife/job_helpers"
18
+ require_relative "job_helpers"
19
19
 
20
20
  class Chef
21
21
  class Knife
@@ -24,7 +24,6 @@ class Chef
24
24
  include JobHelpers
25
25
 
26
26
  deps do
27
- require "chef/rest"
28
27
  require "chef/node"
29
28
  require "chef/search/query"
30
29
  end
@@ -32,58 +31,58 @@ class Chef
32
31
  banner "knife job start <command> [<node> <node> ...]"
33
32
 
34
33
  option :run_timeout,
35
- :long => "--timeout TIMEOUT",
36
- :description => "Maximum time the job will be allowed to run (in seconds)."
34
+ long: "--timeout TIMEOUT",
35
+ description: "Maximum time the job will be allowed to run (in seconds)."
37
36
 
38
37
  option :quorum,
39
- :short => "-q QUORUM",
40
- :long => "--quorum QUORUM",
41
- :default => "100%",
42
- :description => "Pushy job quorum. Percentage (-q 50%) or Count (-q 145)."
38
+ short: "-q QUORUM",
39
+ long: "--quorum QUORUM",
40
+ default: "100%",
41
+ description: "Pushy job quorum. Percentage (-q 50%) or Count (-q 145)."
43
42
 
44
43
  option :search,
45
- :short => "-s QUERY",
46
- :long => "--search QUERY",
47
- :required => false,
48
- :description => "Solr query for list of job candidates."
44
+ short: "-s QUERY",
45
+ long: "--search QUERY",
46
+ required: false,
47
+ description: "Solr query for list of job candidates."
49
48
 
50
49
  option :send_file,
51
- :long => "--file FILE",
52
- :default => nil,
53
- :description => "File to send to job."
50
+ long: "--file FILE",
51
+ default: nil,
52
+ description: "File to send to job."
54
53
 
55
54
  option :capture_output,
56
- :long => "--capture",
57
- :boolean => true,
58
- :default => false,
59
- :description => "Capture job output."
55
+ long: "--capture",
56
+ boolean: true,
57
+ default: false,
58
+ description: "Capture job output."
60
59
 
61
60
  option :with_env,
62
- :long => "--with-env ENV",
63
- :default => nil,
64
- :description => "JSON blob of environment variables to set."
61
+ long: "--with-env ENV",
62
+ default: nil,
63
+ description: "JSON blob of environment variables to set."
65
64
 
66
65
  option :as_user,
67
- :long => "--as-user USER",
68
- :default => nil,
69
- :description => "User id to run as."
66
+ long: "--as-user USER",
67
+ default: nil,
68
+ description: "User id to run as."
70
69
 
71
70
  option :in_dir,
72
- :long => "--in-dir DIR",
73
- :default => nil,
74
- :description => "Directory to execute the command in."
71
+ long: "--in-dir DIR",
72
+ default: nil,
73
+ description: "Directory to execute the command in."
75
74
 
76
75
  option :nowait,
77
- :long => "--nowait",
78
- :short => "-b",
79
- :boolean => true,
80
- :default => false,
81
- :description => "Rather than waiting for each job to complete, exit immediately after starting the job."
76
+ long: "--nowait",
77
+ short: "-b",
78
+ boolean: true,
79
+ default: false,
80
+ description: "Rather than waiting for each job to complete, exit immediately after starting the job."
82
81
 
83
82
  option :poll_interval,
84
- :long => "--poll-interval RATE",
85
- :default => 1.0,
86
- :description => "Repeat interval for job status update (in seconds)."
83
+ long: "--poll-interval RATE",
84
+ default: 1.0,
85
+ description: "Repeat interval for job status update (in seconds)."
87
86
 
88
87
  def run
89
88
  job_name = @name_args[0]
@@ -114,7 +113,7 @@ class Chef
114
113
 
115
114
  begin
116
115
  job = run_helper(config, v2_json)
117
- rescue Net::HTTPServerException => e
116
+ rescue Net::HTTPClientException => e
118
117
  raise e if e.response.code != "400"
119
118
 
120
119
  ui.warn "Falling back to Push Jobs v1 mode."
@@ -139,8 +138,6 @@ class Chef
139
138
  exit(status_code(job))
140
139
  end
141
140
 
142
- private
143
-
144
141
  end
145
142
  end
146
143
  end
@@ -22,7 +22,7 @@ class Chef
22
22
 
23
23
  def run
24
24
  get_node_statuses(name_args).each do |node_status|
25
- puts "#{node_status['node_name']}\t#{node_status['availability']}"
25
+ puts "#{node_status["node_name"]}\t#{node_status["availability"]}"
26
26
  end
27
27
  end
28
28
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Knife
3
3
  module Push
4
- VERSION = "1.0.2"
4
+ VERSION = "2.0.0".freeze
5
5
  MAJOR, MINOR, TINY = VERSION.split(".")
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-push
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-21 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -16,25 +16,35 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 12.7.2
19
+ version: '15.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 12.7.2
27
- description: Knife plugin for Chef push
26
+ version: '15.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: addressable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Knife plugin for Chef Push Jobs
28
42
  email: jkeiser@chef.io
29
43
  executables: []
30
44
  extensions: []
31
- extra_rdoc_files:
32
- - README.md
33
- - LICENSE
45
+ extra_rdoc_files: []
34
46
  files:
35
47
  - LICENSE
36
- - README.md
37
- - Rakefile
38
48
  - lib/chef/knife/job_helpers.rb
39
49
  - lib/chef/knife/job_list.rb
40
50
  - lib/chef/knife/job_output.rb
@@ -42,7 +52,7 @@ files:
42
52
  - lib/chef/knife/job_status.rb
43
53
  - lib/chef/knife/node_status.rb
44
54
  - lib/knife-push/version.rb
45
- homepage: https://www.chef.io
55
+ homepage: https://github.com/chef/knife-push/
46
56
  licenses:
47
57
  - Apache-2.0
48
58
  metadata: {}
@@ -54,16 +64,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
64
  requirements:
55
65
  - - ">="
56
66
  - !ruby/object:Gem::Version
57
- version: 2.2.2
67
+ version: '2.5'
58
68
  required_rubygems_version: !ruby/object:Gem::Requirement
59
69
  requirements:
60
70
  - - ">="
61
71
  - !ruby/object:Gem::Version
62
72
  version: '0'
63
73
  requirements: []
64
- rubyforge_project:
65
- rubygems_version: 2.5.1
74
+ rubygems_version: 3.0.3
66
75
  signing_key:
67
76
  specification_version: 4
68
- summary: Knife plugin for Chef push
77
+ summary: Knife plugin for Chef Push Jobs
69
78
  test_files: []
data/README.md DELETED
@@ -1,177 +0,0 @@
1
- # Knife Push
2
-
3
- [![Gem Version](https://badge.fury.io/rb/knife-push.svg)](https://badge.fury.io/rb/knife-push) [![Build Status](https://travis-ci.org/chef/knife-push.svg?branch=master)](https://travis-ci.org/chef/knife-push)
4
-
5
- The knife push plugin is used by the Chef workstation to interact with the Push API to start jobs, view job status, view job lists, and view node status.
6
-
7
- ## Requirements
8
-
9
- - Chef 12.0 higher
10
- - Ruby 2.2.2 or higher
11
-
12
- ## Installation:
13
-
14
- To build and install the plugin, run:
15
-
16
- ```shell
17
- rake install
18
- ```
19
-
20
- ## Configuration:
21
-
22
- If push server is running on the same host as the Chef Server, then no reconfiguration is required on the Chef workstation.
23
-
24
- ## Subcommands:
25
-
26
- This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a `--help` flag.
27
-
28
- ### job list
29
-
30
- The `job list` subcommand is used to view a list of Push jobs.
31
-
32
- #### Syntax $ knife job list
33
-
34
- ### job start
35
-
36
- The `job start` subcommand is used to start a Push job.
37
-
38
- #### Syntax
39
-
40
- ```shell
41
- knife job start (options) COMMAND [NODE, NODE, ...]
42
- ```
43
-
44
- #### Options
45
-
46
- This argument has the following options:
47
-
48
- `--timeout TIMEOUT`
49
-
50
- The maximum amount of time (in seconds) by which a job must complete, before it will be stopped.
51
-
52
- `-q QUORUM --quorum QUORUM`
53
-
54
- The minimum number of nodes that match the search criteria, are available, and acknowledge the job request. This can be expressed as a percentage (e.g. 50%) or as an absolute number of nodes (e.g. 145). Default value: 100%
55
-
56
- `-b --nowait`
57
-
58
- Exit immediately after starting a job instead of waiting for it to complete.
59
-
60
- `--with-env ENVIRONMENT`
61
-
62
- Accept a json blob of environment variables and use those to set the variables for the client. For example '{"test": "foo"}' will set the push client environment variable "test" to "foo". (Push 2.0 and later)
63
-
64
- `--in-dir DIR`
65
-
66
- Execute the remote command in the directory DIR. (Push 2.0 and later)
67
-
68
- `--file DATAFILE`
69
-
70
- Send the file to the client. (Push 2.0 and later)
71
-
72
- `--capture`
73
-
74
- Capture stdin and stdout for this job. (Push 2.0 and later)
75
-
76
- #### Examples
77
-
78
- For example, to search for nodes assigned the role "webapp", and where 90% of those nodes must be available, enter:
79
-
80
- ```shell
81
- knife job start -quorum 90% 'chef-client' --search 'role:webapp'
82
- ```
83
-
84
- To search for a specific set of nodes (named chico, harpo, groucho, gummo, zeppo), and where 90% of those nodes must be available, enter:
85
-
86
- ```shell
87
- knife job start --quorum 90% 'chef-client' chico harpo groucho gummo zeppo
88
- ```
89
-
90
- Use the `knife job start` subcommand to run a job with the following syntax:
91
-
92
- ```shell
93
- knife job start job_name node_name
94
- ```
95
-
96
- For example, to run a job named add-glasses against a node named "ricardosalazar", enter the following:
97
-
98
- ```shell
99
- knife job start add-glasses 'ricardosalazar'
100
- ```
101
-
102
- ### job output
103
-
104
- The `job output` command is used to view the output of Push jobs. (Push 2.0 and later). The output capture flag must have been set on job start; see the --capture option.
105
-
106
- #### Syntax
107
-
108
- ```shell
109
- knife job output JOBID
110
- ```
111
-
112
- #### Examples
113
-
114
- ```shell
115
- knife job output 26e98ba162fa7ba6fb2793125553c7ae test --channel stdout
116
- ```
117
-
118
- #### Options
119
-
120
- --channel [stderr|stdout]
121
-
122
- The output channel to capture.
123
-
124
- ### job status
125
-
126
- The `job status` command is used to view the status of Push jobs.
127
-
128
- #### Syntax
129
-
130
- ```shell
131
- knife job status JOBID
132
- ```
133
-
134
- #### Examples
135
-
136
- For example, to view the status of a job that has the identifier of "235", enter:
137
-
138
- ```shell
139
- knife job status 235
140
- ```
141
-
142
- ### node status
143
-
144
- The `node status` argument is used to identify nodes that Push may interact with.
145
-
146
- #### Syntax
147
-
148
- ```shell
149
- knife node status
150
- ```
151
-
152
- ## Contributing
153
-
154
- For information on contributing to this project see <https://github.com/chef/chef/blob/master/CONTRIBUTING.md>
155
-
156
-
157
- ## License
158
-
159
- **Author:** John Keiser([jkeiser@chef.io](mailto:jkeiser@chef.io))
160
-
161
- **Copyright:** Copyright 2008-2016, Chef Software, Inc.
162
-
163
- **License:** Apache License, Version 2.0
164
-
165
- ```text
166
- Licensed under the Apache License, Version 2.0 (the "License");
167
- you may not use this file except in compliance with the License.
168
- You may obtain a copy of the License at
169
-
170
- http://www.apache.org/licenses/LICENSE-2.0
171
-
172
- Unless required by applicable law or agreed to in writing, software
173
- distributed under the License is distributed on an "AS IS" BASIS,
174
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
175
- See the License for the specific language governing permissions and
176
- limitations under the License.
177
- ```
data/Rakefile DELETED
@@ -1,14 +0,0 @@
1
- require "bundler"
2
- require "rubygems"
3
- require "rspec/core/rake_task"
4
-
5
- Bundler::GemHelper.install_tasks
6
-
7
- task :default => :spec
8
-
9
- desc "Run specs"
10
- RSpec::Core::RakeTask.new(:spec) do |spec|
11
- spec.pattern = "spec/**/*_spec.rb"
12
- end
13
-
14
- gem_spec = eval(File.read("knife-push.gemspec"))