opsworks-cli 0.3.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61ce9cc1bf75c7a559b0adb4a905ef560706df8a
4
- data.tar.gz: 3411f737526fc1212a710a0a63eba9842065c244
3
+ metadata.gz: 8db33372954155ca2aa7df0535f12e67decbaa83
4
+ data.tar.gz: 0a98b7220142d4f68b99c525db8e459af142a7cf
5
5
  SHA512:
6
- metadata.gz: f7111a5b4d35f7f402b427ac916b7de4d75073667b62286de98ff1317adb6d9cd26d67165cd8a895dadacf06d6ce154a2bc5a5d82e97e4e98a96fdafc71ecae6
7
- data.tar.gz: c0d2f3e0431d8bd6a2fbcba477508f3696f88c0b189bcd42d1be00e60c48120224e93cda35621d5c664f6edd65cfef86dc5a0d2156ba311b83128f020d5df008
6
+ metadata.gz: 2f7eabb9792ff89932746e8d3c187bb6074a0e5e4b5e41c7231a8901078693fefecb3f40e4634af17fea9b9f02676df7366b46940f5ec78c34515db1a235b786
7
+ data.tar.gz: c938ebc4718cee2eb56a16637dad7ffc753b826c7b7bd6961544d58e71e168e18de18721831de789c07232839891f550a5b0c3084a50f953acd8050482a4dbd2
data/README.md CHANGED
@@ -29,6 +29,8 @@ Commands:
29
29
  opsworks apps:create APP [--stack STACK] # Create a new OpsWorks app
30
30
  opsworks apps:deploy APP [--stack STACK] # Deploy an OpsWorks app
31
31
  opsworks apps:status APP [--stack STACK] # Display the most recent deployment of an app
32
+ opsworks chef:configure [--stack STACK] # Configure Chef/Berkshelf
33
+ opsworks chef:sync [--stack STACK] # Sync OpsWorks custom cookbooks
32
34
  opsworks config:get KEY [--stack STACK] # Get a single config value
33
35
  opsworks config:set KEY VALUE [--stack STACK] # Set a config value
34
36
  opsworks config:unset KEY [--stack STACK] # Unset a config value
@@ -36,9 +38,8 @@ Commands:
36
38
  opsworks iam:allow USER [--stack STACK] # Allow an IAM user on a stack
37
39
  opsworks iam:lockdown [--stack STACK] # Remove all stack permissions
38
40
  opsworks recipes:add LAYER EVENT RECIPE [--stack STACK] # Add a recipe to a given layer and lifecycle event
41
+ opsworks recipes:rm LAYER EVENT RECIPE [--stack STACK] # Remove a recipe from a given layer and lifecycle event
39
42
  opsworks recipes:run RECIPE [--stack STACK] # Execute a Chef recipe
40
- opsworks update [--stack STACK] # Update OpsWorks custom cookbooks
41
- opsworks upgrade-chef [--stack STACK] # Upgrade Chef version
42
43
  opsworks version # Print OpsWorks CLI version
43
44
  ```
44
45
 
@@ -4,8 +4,7 @@ require 'aws'
4
4
  require_relative 'helpers/credentials'
5
5
  require_relative 'helpers/options'
6
6
 
7
- require_relative 'subcommands/update'
8
- require_relative 'subcommands/upgrade_chef'
7
+ require_relative 'subcommands/chef'
9
8
  require_relative 'subcommands/recipes'
10
9
  require_relative 'subcommands/apps'
11
10
  require_relative 'subcommands/iam'
@@ -19,8 +18,7 @@ module OpsWorks
19
18
  include Helpers::Credentials
20
19
  include Helpers::Options
21
20
 
22
- include Subcommands::Update
23
- include Subcommands::UpgradeChef
21
+ include Subcommands::Chef
24
22
  include Subcommands::Recipes
25
23
  include Subcommands::Apps
26
24
  include Subcommands::IAM
@@ -1,22 +1,41 @@
1
1
  require 'aws'
2
- require 'opsworks/deployment'
2
+ require 'opsworks/stack'
3
3
 
4
4
  module OpsWorks
5
5
  module CLI
6
6
  module Subcommands
7
- module Update
7
+ module Chef
8
8
  # rubocop:disable MethodLength
9
9
  # rubocop:disable CyclomaticComplexity
10
10
  def self.included(thor)
11
11
  thor.class_eval do
12
- desc 'update [--stack STACK]', 'Update OpsWorks custom cookbooks'
12
+ desc 'chef:configure [--stack STACK]', 'Configure Chef/Berkshelf'
13
+ option :stack, type: :array
14
+ option :version, default: OpsWorks::Stack.latest_chef_version
15
+ option :manage_berkshelf, type: :boolean, default: false
16
+ option :berkshelf_version, default: '3.2.0'
17
+ option :cookbook_git_url
18
+ option :cookbook_branch
19
+ option :cookbook_s3_url
20
+ option :cookbook_username
21
+ option :cookbook_password
22
+ define_method 'chef:configure' do
23
+ fetch_credentials unless env_credentials?
24
+ stacks = parse_stacks(options.merge(active: true))
25
+ stacks.each do |stack|
26
+ say "Configuring Chef #{options[:version]} on #{stack.name}..."
27
+ stack.update_chef(options)
28
+ end
29
+ end
30
+
31
+ desc 'chef:sync [--stack STACK]', 'Sync OpsWorks custom cookbooks'
13
32
  option :stack, type: :array
14
33
  option :timeout, type: :numeric, default: 300
15
- def update
34
+ define_method 'chef:sync' do
16
35
  fetch_credentials unless env_credentials?
17
36
  stacks = parse_stacks(options.merge(active: true))
18
37
  deployments = stacks.map do |stack|
19
- say "Updating #{stack.name}..."
38
+ say "Syncing #{stack.name}..."
20
39
  stack.update_custom_cookbooks
21
40
  end
22
41
  OpsWorks::Deployment.wait(deployments, options[:timeout])
@@ -43,6 +43,22 @@ module OpsWorks
43
43
  layer.add_custom_recipe(event, recipe)
44
44
  end
45
45
  end
46
+
47
+ desc 'recipes:rm LAYER EVENT RECIPE [--stack STACK]',
48
+ 'Remove a recipe from a given layer and lifecycle event'
49
+ option :stack, type: :array
50
+ define_method 'recipes:rm' do |layername, event, recipe|
51
+ fetch_credentials unless env_credentials?
52
+ stacks = parse_stacks(options)
53
+ stacks.each do |stack|
54
+ layer = stack.layers.find { |l| l.shortname == layername }
55
+ next unless layer
56
+ next unless layer.custom_recipes[event].include?(recipe)
57
+
58
+ say "Removing recipe from #{stack.name}."
59
+ layer.remove_custom_recipe(event, recipe)
60
+ end
61
+ end
46
62
  end
47
63
  end
48
64
  # rubocop:enable CyclomaticComplexity
@@ -1,5 +1,5 @@
1
1
  module OpsWorks
2
2
  module CLI
3
- VERSION = '0.3.5'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -32,5 +32,15 @@ module OpsWorks
32
32
  custom_recipes: custom_recipes
33
33
  )
34
34
  end
35
+
36
+ def remove_custom_recipe(event, recipe)
37
+ return unless custom_recipes[event].include?(recipe)
38
+
39
+ custom_recipes[event].delete recipe
40
+ self.class.client.update_layer(
41
+ layer_id: id,
42
+ custom_recipes: custom_recipes
43
+ )
44
+ end
35
45
  end
36
46
  end
@@ -60,12 +60,30 @@ module OpsWorks
60
60
  @layers ||= initialize_layers
61
61
  end
62
62
 
63
- def upgrade_chef(version, options = {})
64
- self.class.client.update_stack(
63
+ def update_chef(options)
64
+ params = {
65
65
  stack_id: id,
66
- configuration_manager: { name: 'Chef', version: version },
67
- chef_configuration: { manage_berkshelf: options[:manage_berkshelf] }
68
- )
66
+ configuration_manager: { name: 'Chef', version: options[:version] },
67
+ chef_configuration: {
68
+ manage_berkshelf: options[:manage_berkshelf],
69
+ berkshelf_version: options[:berkshelf_version]
70
+ }
71
+ }
72
+ if options[:cookbook_git_url]
73
+ params[:custom_cookbooks_source] = {
74
+ type: 'git',
75
+ url: options[:cookbook_git_url],
76
+ revision: options[:cookbook_branch] || 'master'
77
+ }
78
+ elsif options[:cookbook_s3_url]
79
+ params[:custom_cookbooks_source] = {
80
+ type: 's3',
81
+ url: options[:cookbook_s3_url],
82
+ username: options[:cookbook_username],
83
+ password: options[:cookbook_password]
84
+ }
85
+ end
86
+ self.class.client.update_stack(params)
69
87
  end
70
88
 
71
89
  def update_custom_cookbooks
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OpsWorks::CLI::Agent do
4
- describe '#update' do
4
+ describe 'chef:sync' do
5
5
  let(:stacks) { 2.times.map { Fabricate(:stack) } }
6
6
  let(:deployment) { Fabricate(:deployment, status: 'successful') }
7
7
 
@@ -13,7 +13,7 @@ describe OpsWorks::CLI::Agent do
13
13
  it 'should update custom cookbooks on all stacks' do
14
14
  expect(stacks[0]).to receive(:update_custom_cookbooks) { deployment }
15
15
  expect(stacks[1]).to receive(:update_custom_cookbooks) { deployment }
16
- subject.update
16
+ subject.send('chef:sync')
17
17
  end
18
18
 
19
19
  it 'should optionally run on a subset of stacks' do
@@ -21,7 +21,7 @@ describe OpsWorks::CLI::Agent do
21
21
  expect(stacks[1]).not_to receive(:update_custom_cookbooks)
22
22
 
23
23
  allow(subject).to receive(:options) { { stack: [stacks[0].name] } }
24
- subject.update
24
+ subject.send('chef:sync')
25
25
  end
26
26
 
27
27
  it 'should fail if any update fails' do
@@ -29,7 +29,7 @@ describe OpsWorks::CLI::Agent do
29
29
  expect(stacks[0]).to receive(:update_custom_cookbooks) { failure }
30
30
 
31
31
  allow(subject).to receive(:options) { { stack: [stacks[0].name] } }
32
- expect { subject.update }.to raise_error
32
+ expect { subject.send('chef:sync') }.to raise_error
33
33
  end
34
34
  end
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsworks-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-13 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -186,11 +186,10 @@ files:
186
186
  - lib/opsworks/cli/helpers/credentials.rb
187
187
  - lib/opsworks/cli/helpers/options.rb
188
188
  - lib/opsworks/cli/subcommands/apps.rb
189
+ - lib/opsworks/cli/subcommands/chef.rb
189
190
  - lib/opsworks/cli/subcommands/config.rb
190
191
  - lib/opsworks/cli/subcommands/iam.rb
191
192
  - lib/opsworks/cli/subcommands/recipes.rb
192
- - lib/opsworks/cli/subcommands/update.rb
193
- - lib/opsworks/cli/subcommands/upgrade_chef.rb
194
193
  - lib/opsworks/cli/version.rb
195
194
  - lib/opsworks/deployment.rb
196
195
  - lib/opsworks/instance.rb
@@ -205,10 +204,10 @@ files:
205
204
  - spec/fabricators/opsworks/stack_fabricator.rb
206
205
  - spec/opsworks/cli/agent_spec.rb
207
206
  - spec/opsworks/cli/subcommands/apps_spec.rb
207
+ - spec/opsworks/cli/subcommands/chef_spec.rb
208
208
  - spec/opsworks/cli/subcommands/config_spec.rb
209
209
  - spec/opsworks/cli/subcommands/iam_spec.rb
210
210
  - spec/opsworks/cli/subcommands/recipes_spec.rb
211
- - spec/opsworks/cli/subcommands/update_spec.rb
212
211
  - spec/spec_helper.rb
213
212
  homepage: https://github.com/aptible/opsworks-cli
214
213
  licenses:
@@ -241,8 +240,8 @@ test_files:
241
240
  - spec/fabricators/opsworks/stack_fabricator.rb
242
241
  - spec/opsworks/cli/agent_spec.rb
243
242
  - spec/opsworks/cli/subcommands/apps_spec.rb
243
+ - spec/opsworks/cli/subcommands/chef_spec.rb
244
244
  - spec/opsworks/cli/subcommands/config_spec.rb
245
245
  - spec/opsworks/cli/subcommands/iam_spec.rb
246
246
  - spec/opsworks/cli/subcommands/recipes_spec.rb
247
- - spec/opsworks/cli/subcommands/update_spec.rb
248
247
  - spec/spec_helper.rb
@@ -1,32 +0,0 @@
1
- require 'aws'
2
- require 'opsworks/stack'
3
-
4
- module OpsWorks
5
- module CLI
6
- module Subcommands
7
- module UpgradeChef
8
- # rubocop:disable MethodLength
9
- # rubocop:disable CyclomaticComplexity
10
- def self.included(thor)
11
- thor.class_eval do
12
- desc 'upgrade-chef [--stack STACK]', 'Upgrade Chef version'
13
- option :stack, type: :array
14
- option :version
15
- option :manage_berkshelf, type: :boolean, default: false
16
- def upgrade_chef
17
- fetch_credentials unless env_credentials?
18
- stacks = parse_stacks(options.merge(active: true))
19
- version = OpsWorks::Stack.latest_chef_version
20
- stacks.each do |stack|
21
- say "Upgrading #{stack.name} to #{version}..."
22
- stack.upgrade_chef(version, options)
23
- end
24
- end
25
- end
26
- end
27
- # rubocop:enable CyclomaticComplexity
28
- # rubocop:enable MethodLength
29
- end
30
- end
31
- end
32
- end