rudy 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -4,8 +4,7 @@ RUDY, CHANGES
4
4
 
5
5
  NOTE: This is a complete re-write from 0.1
6
6
 
7
- * UPGRADE: drydock 0.3.3
8
- * NEW: Commands: myaddress, addresses, images, instances, disks, connect release
7
+ * NEW: Commands: myaddress, addresses, images, instances, disks, connect, copy release
9
8
  * NEW: Metadata storage to SimpleDB
10
9
  * NEW: Creates EBS volumes based on startup from metadata
11
10
  * NEW: Automated release process
@@ -14,6 +13,7 @@ NOTE: This is a complete re-write from 0.1
14
13
  * NEW: Manage system based on security groups.
15
14
  * NEW: "rudy groups" overhaul. Display, creates, destroys groups.
16
15
  * CHANGE: Added Environment variables
16
+ * UPGRADE: drydock 0.3.3
17
17
 
18
18
 
19
19
  #### 0.1 (2009-02-06) ###############################
data/bin/rudy CHANGED
@@ -113,6 +113,17 @@ command :connect => Rudy::Command::Environment do |obj|
113
113
  end
114
114
  end
115
115
 
116
+ debug :on
117
+ option :r, :remote, "Copy FROM the remote machine to the local machine"
118
+ option :p, :print, "Only print the SSH command, don't connect"
119
+ usage "rudy [-e env] [-u user] copy [-p] -r [from path] [to path]"
120
+ command :copy => Rudy::Command::Environment do |obj, argv|
121
+ capture(:stderr) do
122
+ obj.print_header
123
+ raise "No path specified (rudy copy FROM-PATH [FROM-PATH ...] TO-PATH)" unless argv.size >= 2
124
+ obj.copy(argv)
125
+ end
126
+ end
116
127
 
117
128
 
118
129
  option :all, "Display all disk definitions"
@@ -124,7 +135,7 @@ option :D, :destroy, "Destroy a disk definition"
124
135
  option :A, :attach, "Attach a disk"
125
136
  usage "rudy [global options] disks [-C -p path -d device -s size] [-A] [-D] [disk name]"
126
137
  command :disks => Rudy::Command::Disks do |obj, argv|
127
- #capture(:stderr) do
138
+ capture(:stderr) do
128
139
  obj.print_header
129
140
  if obj.create
130
141
  raise "No filesystem path specified" unless obj.path
@@ -141,7 +152,7 @@ command :disks => Rudy::Command::Disks do |obj, argv|
141
152
  obj.print_disks
142
153
  end
143
154
  obj.print_footer
144
- #end
155
+ end
145
156
  end
146
157
 
147
158
  #command :volumes => Rudy::Command::Volumes do |obj|
@@ -188,6 +199,7 @@ option :b, :bucket_name, String, "The name of the bucket that will store the ima
188
199
  option :C, :create, "Create an image"
189
200
  usage "rudy images [-C -i image -b bucket -a account]"
190
201
  command :images => Rudy::Command::Images do |obj|
202
+ capture(:stderr) do
191
203
  obj.print_header
192
204
 
193
205
  if obj.create
@@ -198,18 +210,22 @@ command :images => Rudy::Command::Images do |obj|
198
210
  obj.print_images
199
211
  end
200
212
  end
213
+ end
201
214
 
202
215
  command :stage => Rudy::Command::Stage do |obj|
216
+ capture(:stderr) do
203
217
  obj.print_header
204
218
 
205
219
  raise "No SCM defined. Set RUDY_SVN_BASE or RUDY_GIT_BASE." unless obj.scm
206
220
 
207
221
  exit unless you_are_sure?
208
222
  obj.push_to_stage
209
-
223
+ end
210
224
  end
211
225
 
212
226
 
227
+
228
+
213
229
  option :all, "Display all security groups"
214
230
  option :r, :protocols, Array, "Comma-separated list of protocols. One of: tcp (default), udp, icmp"
215
231
  option :p, :ports, Array, "List of comma-separated ports to authorize (default: 22,80,443)"
@@ -219,6 +235,9 @@ option :D, :destroy, "Destroy a security group"
219
235
  option :M, :modify, "Modify a security group"
220
236
  usage "rudy [global options] groups [-C] [-a IP addresses] [-p ports] [group name]"
221
237
  command :groups => Rudy::Command::Groups do |obj, argv|
238
+ capture(:stderr) do
239
+ obj.print_header
240
+
222
241
  if obj.create
223
242
  obj.create_group(argv.first)
224
243
 
@@ -232,6 +251,7 @@ command :groups => Rudy::Command::Groups do |obj, argv|
232
251
  else
233
252
  obj.print_groups(argv.first)
234
253
  end
254
+ end
235
255
  end
236
256
 
237
257
 
data/lib/drydock.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  require 'optparse'
2
2
  require 'ostruct'
3
3
 
4
- #
5
- #
4
+
6
5
  module Drydock
7
6
  # The base class for all command objects. There is an instance of this class
8
7
  # for every command defined. Global and command-specific options are added
data/lib/rudy.rb CHANGED
@@ -33,7 +33,7 @@ module Rudy #:nodoc:
33
33
  module VERSION #:nodoc:
34
34
  MAJOR = 0.freeze unless defined? MAJOR
35
35
  MINOR = 2.freeze unless defined? MINOR
36
- TINY = 3.freeze unless defined? TINY
36
+ TINY = 4.freeze unless defined? TINY
37
37
  def self.to_s
38
38
  [MAJOR, MINOR, TINY].join('.')
39
39
  end
@@ -81,19 +81,33 @@ def sh(command, chdir=false)
81
81
  end
82
82
 
83
83
  # TODO: Net::SSH
84
- def ssh(host, keypair, user, command, chdir=false, verbose=false)
85
- cmd = "ssh -q -i #{keypair} #{user}@#{host} '"
86
- cmd += "cd #{chdir} && " if chdir
87
- cmd += " #{command}'"
84
+ def ssh(host, keypair, user, command=false, chdir=false, verbose=false, printonly=false)
85
+ puts "CONNECTING TO #{host}..."
86
+ cmd = "ssh -q -i #{keypair} #{user}@#{host} "
87
+ command = "cd #{chdir} && #{command}" if chdir
88
+ cmd += " '#{command}'" if command
88
89
  puts cmd if verbose
89
- system(cmd)
90
+ printonly ? (puts cmd) : system(cmd)
90
91
  end
91
92
 
92
93
 
93
- def scp(host, keypair, user, local_path, remote_path, verbose=false)
94
- cmd = "scp -i #{keypair} #{local_path} #{user}@#{host}:#{remote_path}"
94
+ def scp(host, keypair, user, paths, to_path, to_local=false, verbose=false, printonly=false)
95
+ puts "CONNECTING TO #{host}..."
96
+ paths = [paths] unless paths.is_a?(Array)
97
+ from_paths = ""
98
+ if to_local
99
+ paths.each do |path|
100
+ from_paths << "#{user}@#{host}:#{path} "
101
+ end
102
+ else
103
+ to_path = "#{user}@#{host}:#{to_path}"
104
+ from_paths = paths.join(' ')
105
+ end
106
+
107
+ cmd = "scp -i #{keypair} #{from_paths} #{to_path}"
108
+
95
109
  puts cmd if verbose
96
- system(cmd)
110
+ printonly ? (puts cmd) : system(cmd)
97
111
  end
98
112
 
99
113
 
@@ -86,6 +86,13 @@ module Rudy
86
86
  #@s3 = Rudy::AWS::SimpleDB.new(@access_key, @secret_key)
87
87
  end
88
88
 
89
+ # Raises exceptions if the requested user does
90
+ # not have a valid keypair configured. (See: EC2_KEYPAIR_*)
91
+ def check_keys
92
+ raise "No SSH key provided for #{keypairname}!" unless has_keypair?(keypairname)
93
+ raise "SSH key provided but cannot be found! (#{keypairpath})" unless File.exists?(keypairpath)
94
+ end
95
+
89
96
  def has_pem_keys?
90
97
  (@ec2_cert && File.exists?(@ec2_cert) &&
91
98
  @ec2_private_key && File.exists?(@ec2_private_key))
@@ -185,26 +192,27 @@ module Rudy
185
192
  # Print a default header to the screen for every command.
186
193
  # +cmd+ is the name of the command current running.
187
194
  def print_header(cmd=nil)
188
- print "RUDY v#{Rudy::VERSION}"
189
- print " -- #{@alias}" if @alias
190
- puts
191
-
192
- criteria = []
193
- [:zone, :environment, :role, :position].each do |n|
194
- val = instance_variable_get("@#{n}")
195
- criteria << "[#{n} = #{val}]"
196
- end
197
- puts criteria.join(" and ")
198
-
195
+ title = "RUDY v#{Rudy::VERSION}"
196
+ title << " -- #{@alias}" if @alias
197
+ puts title, $/
198
+
199
199
  if (@environment == "prod")
200
- puts %q(
201
- =======================================================
200
+ puts %q(=======================================================
202
201
  =======================================================
203
202
  !!!!!!!!! YOU ARE PLAYING WITH PRODUCTION !!!!!!!!!
204
203
  =======================================================
205
204
  =======================================================
206
- )
205
+
206
+ )
207
+ end
208
+
209
+ criteria = []
210
+ [:zone, :environment, :role, :position].each do |n|
211
+ val = instance_variable_get("@#{n}")
212
+ criteria << "[#{n} = #{val}]"
207
213
  end
214
+ puts criteria.join(" and ")
215
+ puts
208
216
 
209
217
  end
210
218
 
@@ -13,20 +13,34 @@
13
13
  module Rudy
14
14
  module Command
15
15
  class Environment < Rudy::Command::Base
16
-
17
- def connect
18
- raise "No SSH key provided for #{keypairname}!" unless has_keypair?(keypairname)
19
- raise "SSH key provided but cannot be found! (#{keypairpath})" unless File.exists?(keypairpath)
16
+
17
+ # Returns a hash of info for the requested machine. If the requested machine
18
+ # is not running, it will raise an exception.
19
+ def find_requested_machine
20
20
  machine_list = @ec2.instances.list(machine_group)
21
21
  machine = machine_list.values.first # NOTE: Only one machine per group, for now...
22
-
23
22
  raise "There's no machine running in #{machine_group}" unless machine
24
23
  raise "The primary machine in #{machine_group} is not in a running state" unless machine[:aws_state] == 'running'
25
- cmd = "ssh -i #{keypairpath} #{user}@#{machine[:dns_name]}"
26
- puts cmd
27
- system(cmd) unless @print
24
+
25
+ machine
28
26
  end
29
27
 
28
+ def connect
29
+ check_keys
30
+ machine = find_requested_machine
31
+ ssh machine[:dns_name], keypairpath, user, false, false, false, @print
32
+ end
33
+
34
+ # +paths+ an array of paths to copy. The last element is the "to" path.
35
+ def copy(paths)
36
+ check_keys
37
+ machine = find_requested_machine
38
+ paths = paths.flatten
39
+ to_path = paths.pop
40
+ scp machine[:dns_name], keypairpath, user, paths, to_path, @remote, false, @print
41
+ end
42
+
43
+
30
44
  # Start EC2 instances to run the stage.
31
45
  # Returns a hash in the same format as +instances+
32
46
  def build_stage
data/rudy.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "rudy"
3
- s.version = "0.2.3"
3
+ s.version = "0.2.4"
4
4
  s.summary = "Rudy is a handy staging and deployment tool for Amazon EC2."
5
5
  s.description = "Rudy is a handy staging and deployment tool for Amazon EC2."
6
6
  s.author = "Delano Mandelbaum"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rudy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-23 00:00:00 -05:00
12
+ date: 2009-02-24 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15