cloud_info 0.1.5 → 0.1.6

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.
data/TODO CHANGED
@@ -1,2 +1,28 @@
1
+ 0.1.6
2
+ * dont overwrite cache if the hosts is empty
3
+
4
+ TODO:
5
+ * support regex filter
6
+ * port rake br:setup -> cloud_info --update-ssh-config
1
7
  * clean up the messy code
2
8
  * write real specs
9
+
10
+
11
+
12
+ CloudInfo::Instances outline
13
+ 1. connect to ec2
14
+
15
+ 2. find instances that are in the ey-env
16
+ find ey instances from ey-recipes for specific environment
17
+ grab aws_group from one of the instances in the ey-env
18
+ instances in group
19
+ I can simply also just grab the instances from ey-recipes instead of working back from the aws_group..
20
+
21
+ 3. connect to instances (ssh) and build info
22
+ connect to servers
23
+ download json and store in dictionary lookup
24
+ at this point we have enough data about the servers to build up the info we want
25
+
26
+ 4. hosts
27
+ {:prod_app0 => 'xx.xx.xx.xx', :prod_app1 => 'xx.xx.xx.xx'}
28
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'cloud_info/cli'
4
+
5
+ CloudInfo::CLI.run(ARGV)
@@ -5,8 +5,9 @@ prod_br:
5
5
  prod_br_memcached0: ec2-204-236-244-26.compute-1.amazonaws.com
6
6
  prod_br_util1: ec2-174-129-111-60.compute-1.amazonaws.com
7
7
  prod_br_memcached1: ec2-184-73-18-219.compute-1.amazonaws.com
8
- prod_br_app1: ec2-174-129-55-203.compute-1.amazonaws.com
9
- prod_br_app2: ec2-75-101-183-44.compute-1.amazonaws.com
10
- prod_br_app3: ec2-184-73-5-255.compute-1.amazonaws.com
8
+ prod_br_app1: ec2-75-101-183-44.compute-1.amazonaws.com
9
+ prod_br_app2: ec2-184-73-92-49.compute-1.amazonaws.com
10
+ prod_br_app3: ec2-174-129-48-17.compute-1.amazonaws.com
11
11
  prod_br_db0: ec2-174-129-47-164.compute-1.amazonaws.com
12
12
  prod_br_db1: ec2-72-44-44-156.compute-1.amazonaws.com
13
+ prod_br_dj0: ec2-184-73-13-18.compute-1.amazonaws.com
data/gemspec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'lib/cloud_info/version'
2
+
1
3
  GEM_NAME = 'cloud_info'
2
4
  GEM_FILES = FileList['**/*'] - FileList['coverage', 'coverage/**/*', 'pkg', 'pkg/**/*']
3
5
  GEM_SPEC = Gem::Specification.new do |s|
@@ -16,5 +18,5 @@ GEM_SPEC = Gem::Specification.new do |s|
16
18
  s.name = GEM_NAME
17
19
  s.platform = Gem::Platform::RUBY
18
20
  s.require_path = "lib"
19
- s.version = "0.1.5"
21
+ s.version = CloudInfo::Version
20
22
  end
@@ -1,8 +1,19 @@
1
1
  require 'rubygems'
2
2
  require 'yaml'
3
3
  require 'pp'
4
+ require File.join(%W/#{File.dirname(__FILE__)} cloud_info version/)
4
5
  require File.join(%W/#{File.dirname(__FILE__)} cloud_info instances/)
6
+ require File.join(%W/#{File.dirname(__FILE__)} cloud_info cli/)
5
7
 
8
+ # usage:
9
+ # require "cloud_info"
10
+ # irb(main):003:0> cloud_info = CloudInfo.new("prod",:private_key => "~/.ssh/id_rsa-private-key")
11
+ # irb(main):005:0> pp cloud_info.apps
12
+ # [["prod_app0", "xxx.xxx.xxx.xxx"],
13
+ # ["prod_app1", "xxx.xxx.xxx.xxx"],
14
+ # ["prod_app2", "xxx.xxx.xxx.xxx"],
15
+ # ["prod_app3", "xxx.xxx.xxx.xxx"]]
16
+ #
6
17
  class CloudInfo
7
18
  attr_reader :env_name
8
19
  def initialize(env_name, options = {})
@@ -28,7 +39,7 @@ class CloudInfo
28
39
  else
29
40
  all_hosts = {}
30
41
  end
31
- all_hosts[env_name] = @hosts
42
+ all_hosts[env_name] = @hosts unless @hosts.empty? # do not replace cached version if its empty
32
43
  CloudInfo.write_yaml(@cache_path, all_hosts)
33
44
  end
34
45
  @hosts
@@ -43,6 +54,9 @@ class CloudInfo
43
54
  def utils
44
55
  utils = hosts.select{|k,v| k =~ Regexp.new("#{@env_name}_util")}.sort {|a,b| a[0] <=> b[0] }
45
56
  end
57
+ def djs
58
+ utils = hosts.select{|k,v| k =~ Regexp.new("#{@env_name}_dj")}.sort {|a,b| a[0] <=> b[0] }
59
+ end
46
60
 
47
61
  def self.all_hosts(options = {})
48
62
  all_hosts = {}
@@ -0,0 +1,85 @@
1
+ require 'optparse'
2
+ require 'logger'
3
+ require 'pp'
4
+
5
+ class CloudInfo
6
+ class CLI
7
+
8
+ def self.run(args)
9
+ cli = new(args)
10
+ cli.parse_options!
11
+ cli.run
12
+ end
13
+
14
+ # The array of (unparsed) command-line options
15
+ attr_reader :args
16
+ # The hash of (parsed) command-line options
17
+ attr_reader :options
18
+
19
+ def initialize(args)
20
+ @args = args.dup
21
+ end
22
+
23
+ # Return an OptionParser instance that defines the acceptable command
24
+ # line switches for cloud_info, and what their corresponding behaviors
25
+ # are.
26
+ def option_parser
27
+ # @logger = Logger.new
28
+ @option_parser ||= OptionParser.new do |opts|
29
+ opts.banner = "Usage: #{File.basename($0)} [options] action ..."
30
+
31
+ opts.on("-d", "--debug",
32
+ "Debug mode, more output"
33
+ ) { |value| options[:debug] = true }
34
+
35
+ opts.on("-u", "--user USER",
36
+ "ssh user"
37
+ ) { |value| options[:user] = value }
38
+
39
+ opts.on("-h", "--help", "Display this help message.") do
40
+ puts opts
41
+ exit
42
+ end
43
+
44
+ opts.on("-V", "--version",
45
+ "Display the cloud_info version, and exit."
46
+ ) do
47
+ require 'cloud_info/version'
48
+ puts "CloudInfo v#{CloudInfo::Version}"
49
+ exit
50
+ end
51
+
52
+ end
53
+ end
54
+
55
+ def parse_options!
56
+ @options = {:actions => []}
57
+
58
+ if args.empty?
59
+ warn "Please specifiy an action to execute."
60
+ warn option_parser
61
+ exit 1
62
+ end
63
+
64
+ option_parser.parse!(args)
65
+ coerce_variable_types!
66
+ extract_environment_variables!
67
+
68
+ options[:actions].concat(args)
69
+ end
70
+
71
+ # Extracts name=value pairs from the remaining command-line arguments
72
+ # and assigns them as environment variables.
73
+ def extract_environment_variables! #:nodoc:
74
+ args.delete_if do |arg|
75
+ next unless arg.match(/^(\w+)=(.*)$/)
76
+ ENV[$1] = $2
77
+ end
78
+ end
79
+
80
+ def run
81
+ puts "TODO FINISH LOGIC"
82
+ pp options
83
+ end
84
+ end
85
+ end
@@ -129,22 +129,6 @@ class CloudInfo
129
129
  h
130
130
  end
131
131
 
132
- module Aws
133
- def aws_instances
134
- @@aws_instances ||= @ec2.describe_instances
135
- end
136
-
137
- def aws_groups
138
- @@aws_groups ||= aws_instances.collect{|x| x[:aws_groups]}.flatten.uniq
139
- end
140
-
141
- def aws_group_for_instance_id(instance_id)
142
- instance = aws_instances.find{|x| x[:aws_instance_id] == instance_id}
143
- aws_group = instance[:aws_groups].first
144
- end
145
- end
146
- include Aws
147
-
148
132
  def self.ey_recipes
149
133
  @@ey_recipes ||= `ey-recipes`
150
134
  end
@@ -179,6 +163,22 @@ class CloudInfo
179
163
  instance_ids
180
164
  end
181
165
 
166
+ module Aws
167
+ def aws_instances
168
+ @@aws_instances ||= @ec2.describe_instances
169
+ end
170
+
171
+ def aws_groups
172
+ @@aws_groups ||= aws_instances.collect{|x| x[:aws_groups]}.flatten.uniq
173
+ end
174
+
175
+ def aws_group_for_instance_id(instance_id)
176
+ instance = aws_instances.find{|x| x[:aws_instance_id] == instance_id}
177
+ aws_group = instance[:aws_groups].first
178
+ end
179
+ end
180
+ include Aws
181
+
182
182
  end
183
183
  end
184
184
 
@@ -0,0 +1,3 @@
1
+ class CloudInfo
2
+ Version = "0.1.6"
3
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 5
9
- version: 0.1.5
8
+ - 6
9
+ version: 0.1.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tung Nguyen
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-11 00:00:00 -08:00
17
+ date: 2010-03-24 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -71,7 +71,9 @@ files:
71
71
  - bin/cloud_info
72
72
  - config/cloud_info.yml
73
73
  - gemspec.rb
74
+ - lib/cloud_info/cli.rb
74
75
  - lib/cloud_info/instances.rb
76
+ - lib/cloud_info/version.rb
75
77
  - lib/cloud_info.rb
76
78
  - MIT-LICENSE
77
79
  - Rakefile