ec2manage 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,131 @@
1
+ !RBIX
2
+ 0
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 67
13
+ 26
14
+ 93
15
+ 0
16
+ 15
17
+ 29
18
+ 18
19
+ 0
20
+ 5
21
+ 7
22
+ 0
23
+ 64
24
+ 47
25
+ 49
26
+ 1
27
+ 1
28
+ 30
29
+ 8
30
+ 61
31
+ 26
32
+ 93
33
+ 1
34
+ 15
35
+ 24
36
+ 13
37
+ 45
38
+ 2
39
+ 3
40
+ 12
41
+ 49
42
+ 4
43
+ 1
44
+ 10
45
+ 35
46
+ 8
47
+ 56
48
+ 15
49
+ 5
50
+ 7
51
+ 5
52
+ 64
53
+ 47
54
+ 49
55
+ 1
56
+ 1
57
+ 15
58
+ 5
59
+ 7
60
+ 0
61
+ 64
62
+ 47
63
+ 49
64
+ 1
65
+ 1
66
+ 25
67
+ 8
68
+ 61
69
+ 15
70
+ 92
71
+ 1
72
+ 27
73
+ 34
74
+ 92
75
+ 0
76
+ 27
77
+ 15
78
+ 2
79
+ 11
80
+ I
81
+ 5
82
+ I
83
+ 0
84
+ I
85
+ 0
86
+ I
87
+ 0
88
+ n
89
+ p
90
+ 6
91
+ s
92
+ 18
93
+ ec2manage/commands
94
+ x
95
+ 7
96
+ require
97
+ x
98
+ 9
99
+ LoadError
100
+ n
101
+ x
102
+ 3
103
+ ===
104
+ s
105
+ 8
106
+ rubygems
107
+ p
108
+ 9
109
+ I
110
+ 0
111
+ I
112
+ 4
113
+ I
114
+ 17
115
+ I
116
+ 5
117
+ I
118
+ 24
119
+ I
120
+ 6
121
+ I
122
+ 2d
123
+ I
124
+ 7
125
+ I
126
+ 43
127
+ x
128
+ 39
129
+ /Users/mat/code/ec2manage/bin/ec2manage
130
+ p
131
+ 0
@@ -1,6 +1,7 @@
1
1
  require 'ec2manage'
2
2
  require 'commander/import'
3
- require 'ec2manage/commander_ext'
3
+ require 'ec2manage/ext/commander'
4
+ require 'ec2manage/ext/highline'
4
5
 
5
6
  program :name, EC2Manage.name
6
7
  program :version, EC2Manage.version
@@ -8,7 +9,11 @@ program :description, EC2Manage.summary
8
9
 
9
10
  default_command :help
10
11
 
11
- command :create do |c|
12
+ def connection
13
+ EC2Manage::Connection.new(self).connection
14
+ end
15
+
16
+ command "create-instance" do |c|
12
17
  c.syntax = '[options]'
13
18
  c.summary = 'Create an instance.'
14
19
  c.description = 'Creates an EC2 instance according to the specified options.'
@@ -25,9 +30,21 @@ command :create do |c|
25
30
  c.option '-d', '--device STRING', 'Device to attach the volume on.'
26
31
 
27
32
  c.action do |args, options|
28
- options.default :template => 'default'
29
- debugger; 1
30
- say "hello creation of template: #{options.template}"
33
+ p options.__hash__
34
+ structure = EC2Manage::Structure.new(self, options.__hash__)
35
+ say "hello creation of template: #{structure.path}"
36
+ end
37
+ end
38
+
39
+ command "create-keypair" do |c|
40
+ c.syntax = '<name>'
41
+ c.summary = 'Create a keypair.'
42
+ c.description = 'Creates a keypair with the specified name and writes it to ~/.ssh.'
43
+
44
+ c.action do |args|
45
+ name = args.shift or raise 'Please specify a name for this keypair.'
46
+ keypair = connection.create_key_pair(name)
47
+ EC2Manage::KeyManager.new.store(keypair)
31
48
  end
32
49
  end
33
50
 
@@ -36,7 +53,7 @@ command :list do |c|
36
53
  c.description = 'Lists all instances associated with the current account.'
37
54
 
38
55
  c.action do |args, options|
39
- say "hello listing"
56
+ jj EC2Manage::Lister.new(connection).list
40
57
  end
41
58
  end
42
59
 
@@ -0,0 +1,47 @@
1
+ require 'right_aws'
2
+ require 'right_http_connection'
3
+ require 'fileutils'
4
+
5
+ Rightscale::HttpConnection.params[:ca_file] = File.join(File.dirname(__FILE__), "cacert-root.crt")
6
+
7
+ class EC2Manage::Connection
8
+ def self.config_path
9
+ "#{ENV['HOME']}/.ec2manage"
10
+ end
11
+
12
+ def self.credentials_path
13
+ "#{config_path}/credentials"
14
+ end
15
+
16
+ def self.right_aws_logger
17
+ Logger.new("#{config_path}/right_aws.log")
18
+ end
19
+
20
+ def initialize(ui)
21
+ @ui = ui
22
+
23
+ if File.exist?(self.class.credentials_path)
24
+ config = JSON.parse(File.read(self.class.credentials_path))
25
+ @access_key_id = config["access_key_id"]
26
+ @secret_access_key = config["secret_access_key"]
27
+ else
28
+ @ui.say "<%= color('Whoops!', :bold, :red) %> I couldn't find a credentials file."
29
+ @ui.say "We'll have to create one."
30
+
31
+ @access_key_id = @ui.ask("<%= color('Please enter your Access Key ID:', :bold) %> ")
32
+ @secret_access_key = @ui.ask("<%= color('Please enter your Secret Access Key:', :bold) %> ")
33
+
34
+ @ui.say "Now I'll write this to #{@ui.color(self.class.credentials_path, :bold)} for safe keeping."
35
+
36
+ FileUtils.mkdir_p(File.dirname(self.class.credentials_path))
37
+ File.open(self.class.credentials_path, 'w') do |f|
38
+ f.print({"access_key_id" => @access_key_id, "secret_access_key" => @secret_access_key}.to_json)
39
+ end
40
+ end
41
+ end
42
+
43
+ def connection
44
+ @connection = RightAws::Ec2.new(@access_key_id, @secret_access_key,
45
+ :logger => self.class.right_aws_logger)
46
+ end
47
+ end
@@ -0,0 +1,29 @@
1
+ # Automatically include the executable and command name
2
+ # in the syntax statment
3
+ class Commander::Command
4
+ def syntax=(syntax)
5
+ @syntax = "#{EC2Manage.name} #{@name} #{syntax}"
6
+ end
7
+ end
8
+
9
+ # take back control of -t and -v
10
+ #$parser = OptionParser.new
11
+ #class OptionParser
12
+ # def self.new
13
+ # $parser
14
+ # end
15
+ #end
16
+ #
17
+ #class Commander::Runner
18
+ # alias :original_global_option :global_option
19
+ # def global_option *args, &block
20
+ # args.shift if %w(-t -v).include?(args.first)
21
+ # original_global_option(*args, &block)
22
+ # end
23
+ #
24
+ # def parse_global_options
25
+ # end
26
+ #
27
+ # def remove_global_options(*args)
28
+ # end
29
+ #end
@@ -0,0 +1,5 @@
1
+ # Also allow access to the color method, otherwise I don't
2
+ # see how we could assign a color to a local variable
3
+ module Kernel
4
+ def_delegators :$terminal, :color
5
+ end
@@ -0,0 +1,27 @@
1
+ module EC2Manage
2
+ def self.version
3
+ '0.0.3'
4
+ end
5
+
6
+ def self.name
7
+ 'ec2manage'
8
+ end
9
+
10
+ def self.summary
11
+ 'A command-line manager for EC2 instances.'
12
+ end
13
+
14
+ def self.description
15
+ <<-EOS.gsub(' ','')
16
+ ec2manage is a command line tool for managing EC2 instances.
17
+
18
+ It's main goal is to provide the same style of control as the
19
+ Amazon EC2 API Tools but with additional structure and metadata
20
+ make administrative decisions easier.
21
+ EOS
22
+ end
23
+
24
+ def self.directory
25
+ '.' + name
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ class EC2Manage::Lister
2
+ def initialize(connection)
3
+ @connection = connection
4
+ end
5
+
6
+ def list
7
+ { 'instances' => instances }
8
+ end
9
+
10
+ def instances
11
+ @connection.describe_instances.map do |i|
12
+ data = { 'zone' => i[:aws_availability_zone],
13
+ 'ami' => i[:aws_image_id],
14
+ 'keypair' => i[:ssh_key_name],
15
+ 'groups' => i[:aws_groups] }
16
+
17
+ data['volumes'] = map_volumes(i[:block_device_mappings]) if i[:block_device_mappings]
18
+
19
+ data
20
+ end
21
+ end
22
+
23
+ def map_volumes(volumes)
24
+ volumes.map do |v|
25
+ { 'device' => v[:device_name] }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,70 @@
1
+ require 'pathname'
2
+ require 'json'
3
+ require 'ostruct'
4
+
5
+ class EC2Manage::Structure
6
+ attr_reader :options
7
+
8
+ attr_reader :zone, :ami, :keypair, :groups
9
+ attr_reader :volumes
10
+
11
+ def initialize(ui, options)
12
+ @ui = ui
13
+ @options = options
14
+
15
+ load_template
16
+ override_options
17
+ end
18
+
19
+ def override_options
20
+ [:zone, :ami, :keypair, :group, :name].each do |key|
21
+ instance_variable_set("@#{key}", options[key]) if options[key]
22
+ end
23
+ end
24
+
25
+ def template_warning
26
+ if @options[:template]
27
+ here = Pathname.new(__FILE__)
28
+ example = here.dirname.join(*%w(.. .. spec fixtures default.json))
29
+ @ui.say <<-EOS
30
+ <%= color('Hey!', :bold, :red) %> I couldn't find the template file #{path}.
31
+
32
+ You might want to create it. Here's an example:
33
+
34
+ #{example.read}
35
+ EOS
36
+ end
37
+ end
38
+
39
+ def load_template
40
+ return template_warning unless File.exist?(path)
41
+
42
+ data = JSON.parse(File.read(path))
43
+ data.each do |key, value|
44
+ instance_variable_set("@#{key}", value)
45
+ end
46
+
47
+ @volumes.map! { |v| OpenStruct.new(v) }
48
+ end
49
+
50
+ def ensure_extension(template)
51
+ if template !~ /\.json$/
52
+ (template || 'default') + '.json'
53
+ else
54
+ template
55
+ end
56
+ end
57
+
58
+ def resolve(path)
59
+ if path.exist?
60
+ path.to_s
61
+ else
62
+ File.join(ENV['HOME'], EC2Manage.directory, path.basename)
63
+ end
64
+ end
65
+
66
+ def path
67
+ pathname = Pathname.new(ensure_extension(options[:template]))
68
+ resolve(pathname)
69
+ end
70
+ end
data/lib/ec2manage.rb CHANGED
@@ -1,30 +1,4 @@
1
- module EC2Manage
2
- def self.version
3
- '0.0.2'
4
- end
5
-
6
- def self.name
7
- 'ec2manage'
8
- end
9
-
10
- def self.summary
11
- 'A command-line manager for EC2 instances.'
12
- end
13
-
14
- def self.description
15
- <<-EOS.gsub(' ','')
16
- ec2manage is a command line tool for managing EC2 instances.
17
-
18
- It's main goal is to provide the same style of control as the
19
- Amazon EC2 API Tools but with additional structure and metadata
20
- make administrative decisions easier.
21
- EOS
22
- end
23
-
24
- def self.building?
25
- $0.include?("gem") && ARGV[0] == "build"
26
- end
27
- end
28
-
29
- #require 'ruby-debug'
30
- #raise 'Take out the debugger!' if EC2Manage.building?
1
+ require 'ec2manage/info'
2
+ require 'ec2manage/connection'
3
+ require 'ec2manage/structure'
4
+ require 'ec2manage/lister'
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2manage
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 2
9
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - Mat Schaffer
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-10 00:00:00 -04:00
18
+ date: 2010-09-27 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: commander
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - "="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 57
27
30
  segments:
28
31
  - 4
29
32
  - 0
@@ -32,12 +35,14 @@ dependencies:
32
35
  type: :runtime
33
36
  version_requirements: *id001
34
37
  - !ruby/object:Gem::Dependency
35
- name: json
38
+ name: json_pure
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - "="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 1
41
46
  segments:
42
47
  - 1
43
48
  - 4
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: right_aws
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - "="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 15
55
62
  segments:
56
63
  - 2
57
64
  - 0
@@ -63,14 +70,30 @@ dependencies:
63
70
  name: rspec
64
71
  prerelease: false
65
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
66
74
  requirements:
67
75
  - - ">="
68
76
  - !ruby/object:Gem::Version
77
+ hash: 3
69
78
  segments:
70
79
  - 0
71
80
  version: "0"
72
81
  type: :development
73
82
  version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ type: :development
96
+ version_requirements: *id005
74
97
  description: |
75
98
  ec2manage is a command line tool for managing EC2 instances.
76
99
 
@@ -88,10 +111,16 @@ extra_rdoc_files: []
88
111
  files:
89
112
  - README.md
90
113
  - bin/ec2manage
91
- - lib/ec2manage/commander_ext.rb
114
+ - bin/ec2manage.compiled.rbc
92
115
  - lib/ec2manage/commands.rb
116
+ - lib/ec2manage/connection.rb
117
+ - lib/ec2manage/ext/commander.rb
118
+ - lib/ec2manage/ext/highline.rb
119
+ - lib/ec2manage/info.rb
120
+ - lib/ec2manage/lister.rb
121
+ - lib/ec2manage/structure.rb
93
122
  - lib/ec2manage.rb
94
- has_rdoc: false
123
+ has_rdoc: true
95
124
  homepage: http://github.com/matschaffer/ec2manage
96
125
  licenses: []
97
126
 
@@ -101,23 +130,27 @@ rdoc_options: []
101
130
  require_paths:
102
131
  - lib
103
132
  required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
104
134
  requirements:
105
135
  - - ">="
106
136
  - !ruby/object:Gem::Version
137
+ hash: 3
107
138
  segments:
108
139
  - 0
109
140
  version: "0"
110
141
  required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
111
143
  requirements:
112
144
  - - ">="
113
145
  - !ruby/object:Gem::Version
146
+ hash: 3
114
147
  segments:
115
148
  - 0
116
149
  version: "0"
117
150
  requirements: []
118
151
 
119
152
  rubyforge_project: nowarning
120
- rubygems_version: 1.3.6
153
+ rubygems_version: 1.3.7
121
154
  signing_key:
122
155
  specification_version: 3
123
156
  summary: A command-line manager for EC2 instances.
@@ -1,6 +0,0 @@
1
- # Automatically include the executable and command name in the syntax statment
2
- class Commander::Command
3
- def syntax=(syntax)
4
- @syntax = "#{EC2Manage.name} #{@name} #{syntax}"
5
- end
6
- end