opsworks 0.0.15 → 0.0.16

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
  SHA1:
3
- metadata.gz: 1eb7d340b41fc33fe2c070c36d46b402bba81e90
4
- data.tar.gz: 7bf399ca7517b62676b5d0b5b9602b231040f4ab
3
+ metadata.gz: db03944410eebab622aef8a4dbde1123e0aa18b7
4
+ data.tar.gz: d00be8c47178d207ad0827f4c6a940e401f66498
5
5
  SHA512:
6
- metadata.gz: 85eb67216bedb0b999205144f0d0122d38885dd07a2cf093bdced82df147f19c3f6493ccf3cb67bcb724d8958b2bd882bd491a052f523a720189b89e073c00ba
7
- data.tar.gz: c5e50da7f78c72c270ed6fbc5da92fc62668c7ba8224e4abddf4e6cec3dcfb4bb794540169a87686e0b0f1ad35f236e4c87607f924055b6577018ea205fbdf2f
6
+ metadata.gz: b1828c97f2654843d59aa206dbcb08c011f582c24e1dded8d9d30929f6eda5ea9ce1ac2a63711a8dbd273ad8fd1118d5ac0a05c1e0e514f0b004f1d7ff5f0a5e
7
+ data.tar.gz: 146edebb50bc1e77d51e25ae11631676031498c09625ea112700aadb2b0bc4d64242dccb2001a4c3b14f3debda2e11c4461d29da1d661857ef910a4a11dd6c51
data/README.md CHANGED
@@ -12,6 +12,12 @@ Run `opsworks` with one of the following commands:
12
12
  instances with the same name in multiple stacks, the one from the first
13
13
  stack will be used by SSH.
14
14
 
15
+ * `dsh` Generate and update dsh configuration files.
16
+
17
+ Instances are added in stack order to the dsh machines.list in $HOME/.dsh,
18
+ as per `ssh` above. A file is created in $HOME/.dsh/group for each layer
19
+ in each stack.
20
+
15
21
  ## Configuration
16
22
 
17
23
  This gem uses the same configuration file as the [AWS CLI][aws_cli]. This
@@ -28,7 +34,8 @@ The stack ID can be found in the stack settings, under _OpsWorks ID_ (or in the
28
34
  address bar of your browser as
29
35
  `console.aws.amazon.com/opsworks/home?#/stack/<STACK_ID>/stack`). You can add
30
36
  several stack IDs belonging to the same IAM account separated by commas
31
- (`stack-id=STACK1,...,STACKN`).
37
+ (`stack-id=STACK1,...,STACKN`). If no stack-id is specified all accessible stacks
38
+ are used.
32
39
 
33
40
  The `ssh-user-name` value should be set to the username you want to use when
34
41
  logging in remotely, most probably the user name from your _My Settings_ page
@@ -1,6 +1,8 @@
1
1
  require "opsworks/meta"
2
2
  require "opsworks/config"
3
+ require "opsworks/commands/file_util"
3
4
  require "opsworks/commands/ssh"
5
+ require "opsworks/commands/dsh"
4
6
 
5
7
  class String
6
8
  def unindent
@@ -10,4 +12,3 @@ end
10
12
 
11
13
  module OpsWorks
12
14
  end
13
-
@@ -3,7 +3,7 @@ require 'opsworks'
3
3
 
4
4
  class OpsWorks::CLI
5
5
  def self.start
6
- commands = %w(ssh)
6
+ commands = %w(ssh dsh)
7
7
 
8
8
  Trollop::options do
9
9
  version "opsworks #{OpsWorks::VERSION} " <<
@@ -15,6 +15,7 @@ class OpsWorks::CLI
15
15
 
16
16
  Commands
17
17
  ssh #{OpsWorks::Commands::SSH.banner}
18
+ dsh #{OpsWorks::Commands::DSH.banner}
18
19
 
19
20
  For help with specific commands, run:
20
21
  opsworks COMMAND -h/--help
@@ -28,6 +29,8 @@ class OpsWorks::CLI
28
29
  case command
29
30
  when "ssh"
30
31
  OpsWorks::Commands::SSH.run
32
+ when "dsh"
33
+ OpsWorks::Commands::DSH.run
31
34
  when nil
32
35
  Trollop::die "no command specified"
33
36
  else
@@ -35,4 +38,4 @@ class OpsWorks::CLI
35
38
  end
36
39
 
37
40
  end
38
- end
41
+ end
@@ -0,0 +1,118 @@
1
+ require 'aws-sdk'
2
+ require 'trollop'
3
+
4
+ require 'opsworks'
5
+
6
+ DSH_PREFIX = "# --- OpsWorks ---"
7
+ DSH_POSTFIX = "# --- End of OpsWorks ---"
8
+
9
+ module OpsWorks::Commands
10
+ class DSH
11
+ def self.banner
12
+ "Generate and update DSH configuration files"
13
+ end
14
+
15
+ def self.run
16
+ options = Trollop::options do
17
+ banner <<-EOS.unindent
18
+ #{DSH.banner}
19
+
20
+ Options:
21
+ EOS
22
+ opt :update, "Update ~/.dsh config files directly"
23
+ opt :backup, "Backup old DSH config before updating"
24
+ end
25
+
26
+ config = OpsWorks.config
27
+
28
+ client = AWS::OpsWorks::Client.new
29
+
30
+ instances = []
31
+ layers_by_stack = {}
32
+ instances_by_layer = {}
33
+
34
+ config.stacks.each do |stack_id|
35
+ result = client.describe_stacks(stack_ids: [stack_id])
36
+ stack_name = result.stacks.first.name
37
+
38
+ result = client.describe_instances(stack_id: stack_id)
39
+ instances += result.instances.select { |i| i[:status] != "stopped" }
40
+
41
+ layers_by_stack[stack_name] = []
42
+ result = client.describe_layers(stack_id: stack_id)
43
+ layers_by_stack[stack_name] += result.layers
44
+
45
+
46
+ instances_by_layer[stack_name] = {}
47
+
48
+ layers_by_stack[stack_name].each do |layer|
49
+ layer_inst = []
50
+ result = client.describe_instances(layer_id: layer[:layer_id])
51
+ layer_inst = result.instances.select { |i| i[:status] != "stopped" }
52
+
53
+ layer_inst.map! do |instance|
54
+ instance[:hostname]
55
+ end
56
+
57
+ instances_by_layer[stack_name][layer[:shortname]] =
58
+ "\n\n#{DSH_PREFIX}\n" <<
59
+ "#{layer_inst.join("\n")}\n" <<
60
+ "#{DSH_POSTFIX}\n\n"
61
+
62
+ # puts layer[:shortname]
63
+ # puts instances_by_layer[stack_name][layer[:shortname]]
64
+ end
65
+ layers_by_stack[stack_name].map! do |layer|
66
+ layer[:shortname]
67
+ end
68
+ end
69
+
70
+ instances.reject! { |i| i[:elastic_ip].nil? && i[:public_ip].nil? }
71
+ instances.map! do |instance|
72
+ instance[:hostname]
73
+ end
74
+
75
+ new_machine_contents = "\n\n#{DSH_PREFIX}\n" <<
76
+ "#{instances.join("\n")}\n" <<
77
+ "#{DSH_POSTFIX}\n\n"
78
+
79
+ if options[:update]
80
+ dsh_config_dir = "#{ENV['HOME']}/.dsh"
81
+
82
+ machines_list = "#{dsh_config_dir}/machines.list"
83
+ groups_dir = "#{dsh_config_dir}/group"
84
+
85
+ [dsh_config_dir, groups_dir].each do |dir|
86
+ unless Dir.exists? dir
87
+ Dir.mkdir dir
88
+ end
89
+ end
90
+
91
+ if options[:backup]
92
+ OpsWorks::Commands::FileUtil.backup(dsh_config_dir)
93
+ end
94
+
95
+ OpsWorks::Commands::FileUtil.update_file(machines_list, new_machine_contents)
96
+ puts "Successfully updated #{machines_list} with " <<
97
+ "#{instances.length} instances!"
98
+
99
+ layers_by_stack.keys.each do |stack|
100
+ puts stack
101
+ layers_by_stack[stack].each do |layer|
102
+ puts layer
103
+ contents = instances_by_layer[stack][layer]
104
+ group_file = "#{groups_dir}/#{stack}_#{layer}"
105
+ puts group_file
106
+ OpsWorks::Commands::FileUtil.update_file(group_file, contents)
107
+ puts "Successfully updated group/#{group_file}!"
108
+ end
109
+ end
110
+
111
+ puts "Successfully updated #{machines_list} with " <<
112
+ "#{instances.length} instances!"
113
+ else
114
+ puts new_machine_contents.strip
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,42 @@
1
+ require 'fileutils'
2
+ require 'trollop'
3
+
4
+ require 'opsworks'
5
+
6
+ module OpsWorks::Commands
7
+ class FileUtil
8
+
9
+ def self.backup (source)
10
+ if File.exists? source
11
+ base_name = source + ".backup"
12
+ if File.exists? base_name
13
+ number = 0
14
+ backup = "#{base_name}-#{number}"
15
+ while base_name.class.exists? backup
16
+ backup = "#{base_name}-#{number += 1}"
17
+ end
18
+ else
19
+ backup = base_name
20
+ end
21
+
22
+ FileUtils.cp_r(source, backup)
23
+ end
24
+ end
25
+
26
+ def self.update_file (f, new_contents)
27
+ options = Trollop::options
28
+
29
+ old_contents = (File.exists? f) ? File.read(f) : ""
30
+
31
+ File.open(f, "w") do |file|
32
+ unless old_contents == ""
33
+ file.puts old_contents.gsub(
34
+ /\n?\n?#{SSH_PREFIX}.*#{SSH_POSTFIX}\n?\n?/m,
35
+ ''
36
+ )
37
+ end
38
+ file.puts new_contents
39
+ end
40
+ end
41
+ end
42
+ end
@@ -33,7 +33,14 @@ module OpsWorks::Commands
33
33
 
34
34
  instances = []
35
35
 
36
- config.stacks.each do |stack_id|
36
+ stack_ids = if config.stacks.empty?
37
+ stacks = client.describe_stacks[:stacks]
38
+ stacks.map{|s| s[:stack_id]}
39
+ else
40
+ config.stacks
41
+ end
42
+
43
+ stack_ids.each do |stack_id|
37
44
  result = client.describe_instances(stack_id: stack_id)
38
45
  instances += result.instances.select { |i| i[:status] != "stopped" }
39
46
  end
@@ -1,7 +1,8 @@
1
1
  module OpsWorks
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  AUTHORS = ["Adam Lindberg"]
4
4
  EMAIL = ["hello@alind.io"]
5
5
  DESCRIPTION = "Amazon OpsWorks CLI"
6
6
  SUMMARY = "Command line interface for Amazon OpsWorks"
7
7
  end
8
+
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsworks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Lindberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-14 00:00:00.000000000 Z
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inifile
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.0.2
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
26
  version: 2.0.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: aws-sdk
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.11.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.11.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: trollop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: awesome_print
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Amazon OpsWorks CLI
@@ -102,18 +102,20 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - bin/opsworks
105
+ - ".gitignore"
106
106
  - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/opsworks
111
+ - lib/opsworks.rb
107
112
  - lib/opsworks/cli.rb
113
+ - lib/opsworks/commands/dsh.rb
114
+ - lib/opsworks/commands/file_util.rb
108
115
  - lib/opsworks/commands/ssh.rb
109
116
  - lib/opsworks/config.rb
110
117
  - lib/opsworks/meta.rb
111
- - lib/opsworks.rb
112
- - LICENSE.txt
113
118
  - opsworks.gemspec
114
- - Rakefile
115
- - README.md
116
- - .gitignore
117
119
  homepage: https://github.com/eproxus/opsworks
118
120
  licenses:
119
121
  - MIT
@@ -124,17 +126,17 @@ require_paths:
124
126
  - lib
125
127
  required_ruby_version: !ruby/object:Gem::Requirement
126
128
  requirements:
127
- - - '>='
129
+ - - ">="
128
130
  - !ruby/object:Gem::Version
129
131
  version: '0'
130
132
  required_rubygems_version: !ruby/object:Gem::Requirement
131
133
  requirements:
132
- - - '>='
134
+ - - ">="
133
135
  - !ruby/object:Gem::Version
134
136
  version: '0'
135
137
  requirements: []
136
138
  rubyforge_project:
137
- rubygems_version: 2.1.9
139
+ rubygems_version: 2.2.2
138
140
  signing_key:
139
141
  specification_version: 4
140
142
  summary: Command line interface for Amazon OpsWorks