dew 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -59,7 +59,7 @@ Don't worry about setting permissions for the key - **dew** will manage that its
59
59
 
60
60
  And perform a basic self-test:
61
61
 
62
- $ dew environments
62
+ $ dew env
63
63
 
64
64
  ## Creating a Simple Environment
65
65
 
@@ -75,15 +75,15 @@ If your keypair isn't called 'default', you'll need to edit this file and change
75
75
 
76
76
  Now, run:
77
77
 
78
- dew -v environments create test-light my-first-environment
78
+ dew -v env create test-light my-first-environment
79
79
 
80
80
  You'll be shown a summary of the environment that you're about to create. Type 'y' to confirm its creation and watch as it's created.
81
81
 
82
82
  Once complete you can run the following commands to interact with your environment:
83
83
 
84
- dew environments ssh my-first-environment
85
- dew environments show my-first-environment
86
- dew environments destroy my-first-environment
84
+ dew env ssh my-first-environment
85
+ dew env show my-first-environment
86
+ dew env destroy my-first-environment
87
87
 
88
88
  ## Creating an AMI for a new Environment
89
89
 
data/bin/dew CHANGED
@@ -12,7 +12,7 @@ class DewCommand < DewBaseCommand
12
12
  exit(0)
13
13
  end
14
14
 
15
- subcommand "environments", "perform subcommands on the environments", EnvironmentsCommand
15
+ subcommand "env", "perform subcommands on the environments", EnvironmentsCommand
16
16
  subcommand "amis", "perform subcommands on the AMIs", AMIsCommand
17
17
  subcommand "deploy", "deploy to an environment", DeployCommand
18
18
  subcommand "console", "open an IRB session with Cloud loaded", ConsoleCommand
@@ -36,8 +36,12 @@ class DewCommand < DewBaseCommand
36
36
  rescue Clamp::HelpWanted => e
37
37
  raise
38
38
  rescue Clamp::UsageError => e
39
- Inform.error(e.message)
40
- puts e.command.help
39
+ if e.message =~ /No such sub-command 'environments'/
40
+ Inform.error("'environments' is now 'env' - please run 'dew env' instead")
41
+ else
42
+ Inform.error(e.message)
43
+ puts e.command.help
44
+ end
41
45
  exit(1)
42
46
  rescue Interrupt => e
43
47
  # If receive ^C Just exit the script...
@@ -21,7 +21,7 @@ Given /^I specify the puppet configuration "([^"]*)"$/ do |puppet_config|
21
21
  end
22
22
 
23
23
  When /^I run the create\-environment script$/ do
24
- @log = run_and_capture("./bin/dew --region #{@region} --account #{@account_name} --debug --verbose environments create -f #{@profile} #{@environment_name}", "create-environment.#{@profile}")
24
+ @log = run_and_capture("./bin/dew --region #{@region} --account #{@account_name} --debug --verbose env create -f #{@profile} #{@environment_name}", "create-environment.#{@profile}")
25
25
  end
26
26
 
27
27
  When /^I run the create\-ami script$/ do
@@ -1,7 +1,7 @@
1
1
  After("@aws") do
2
2
  if !ENV['KEEP_TEST_ARTIFACTS']
3
3
  if @environment_name
4
- run_and_capture("./bin/dew --region #{@region} --account #{@account_name} environments destroy -f #{@environment_name}", 'destroy-environment')
4
+ run_and_capture("./bin/dew --region #{@region} --account #{@account_name} env destroy -f #{@environment_name}", 'destroy-environment')
5
5
  end
6
6
  if @ami_name
7
7
  run_and_capture("./bin/dew --region #{@region} --account #{@account_name} amis destroy -f #{@ami_name}", 'destroy-ami')
@@ -92,10 +92,12 @@ class EnvironmentsCommand < Clamp::Command
92
92
  subcommand "run", "Run a script or command on each instance in the environment" do
93
93
  parameter "ENVIRONMENT_NAME", "Name of the environment"
94
94
  option ['-s', '--script'], "FILENAME", "Script to run on each instance"
95
+ option ['-a', '--args'], "ARGUMENTS", "Optional arguments to the script provided in --script", :default => ''
95
96
  option ['-c', '--command'], "COMMAND", "Command to run on each instance"
96
97
 
97
98
  def execute
98
99
  raise "Please supply either -s or -c" unless script or command
100
+ raise "--args only compatiable with --script" if command and args
99
101
 
100
102
  env = Environment.get(environment_name)
101
103
 
@@ -106,7 +108,7 @@ class EnvironmentsCommand < Clamp::Command
106
108
  if script
107
109
  ssh.upload(script, '/tmp/script')
108
110
  ssh.run("chmod +x /tmp/script")
109
- ssh.run("/tmp/script", :quiet => false)
111
+ ssh.run("/tmp/script #{args}", :quiet => false)
110
112
  ssh.run("rm /tmp/script")
111
113
  else
112
114
  ssh.run(command, :quiet => false)
@@ -34,7 +34,7 @@ class Environment
34
34
  environment.add_database(profile.rds_size, password) if profile.has_rds?
35
35
 
36
36
  (1..profile.count).each do
37
- environment.add_server(profile.ami, profile.size, profile.keypair, profile.security_groups)
37
+ environment.add_server(profile.ami, profile.size, profile.keypair, profile.security_groups, profile.username)
38
38
  end
39
39
 
40
40
  environment.add_elb(profile.elb_listener_ports) if profile.has_elb?
@@ -104,7 +104,7 @@ class Environment
104
104
  end
105
105
  end
106
106
 
107
- def add_server ami, size, keypair, groups
107
+ def add_server ami, size, keypair, groups, username
108
108
  Inform.info "Adding server using AMI %{ami} of size %{size}, keypair %{keypair} and security groups %{groups}",
109
109
  :ami => ami, :size => size, :keypair => keypair, :groups => groups do
110
110
  server = Server.create!( ami, size, keypair, groups )
@@ -112,6 +112,7 @@ class Environment
112
112
  server.add_tag('Creator', ENV['USER'])
113
113
  server_name = "#{name} #{servers.count + 1}"
114
114
  server.add_tag('Name', server_name)
115
+ server.add_tag('Username', username) # Needed for SSH
115
116
  Inform.debug("%{name} ID: %{id} AZ: %{az}", :name => server_name, :id =>server.id, :az => server.availability_zone)
116
117
  servers << server
117
118
  end
@@ -4,7 +4,7 @@ class Profile
4
4
 
5
5
  attr_reader :profile_name
6
6
  attr_accessor :ami, :size, :security_groups, :keypair, :count
7
- attr_accessor :rds_size, :elb_listener_ports
7
+ attr_accessor :rds_size, :elb_listener_ports, :username
8
8
 
9
9
  AWS_RESOURCES = YAML.load(File.read(File.join(File.dirname(__FILE__), '..', 'aws_resources.yaml')))
10
10
 
@@ -12,12 +12,14 @@ class Profile
12
12
  file = File.read(File.join(ENV['HOME'], '.dew', 'profiles', "#{profile_name}.yaml"))
13
13
  yaml = YAML.load(file)
14
14
  profile = new(profile_name)
15
+ profile.username = 'ubuntu'
15
16
  if yaml['instances']
16
17
  profile.ami = yaml['instances']['amis'][Cloud.region]
17
18
  profile.size = yaml['instances']['size']
18
- profile.security_groups = yaml['instances']['security-groups'] || ['default']
19
+ profile.security_groups = yaml['instances']['security-groups'] || ['default'] #XXX is this fallback tested?
19
20
  profile.keypair = yaml['instances']['keypair']
20
21
  profile.count = yaml['instances']['count'].to_i
22
+ profile.username = yaml['instances']['username'] if yaml['instances'].include?('username')
21
23
  end
22
24
  if yaml['elb']
23
25
  profile.elb_listener_ports = yaml['elb']['listener_ports']
@@ -29,7 +29,7 @@ class Server < FogModel
29
29
  end
30
30
 
31
31
  def username
32
- 'ubuntu'
32
+ tags['Username'] || 'ubuntu'
33
33
  end
34
34
 
35
35
  def ssh
data/lib/dew/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dew
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -51,7 +51,7 @@ describe Environment do
51
51
 
52
52
  describe ".create" do
53
53
  let (:security_groups) { %w(non_default) }
54
- let(:profile) { double(:profile, :keypair => 'default', :security_groups => security_groups, :ami => 'i-1234', :has_rds? => false, :has_elb? => false, :count => 2, :size => 'small' ) }
54
+ let(:profile) { double(:profile, :username => 'username', :keypair => 'default', :security_groups => security_groups, :ami => 'i-1234', :has_rds? => false, :has_elb? => false, :count => 2, :size => 'small' ) }
55
55
 
56
56
  context "when environment name is invalid" do
57
57
  it "should raise an error" do
@@ -80,7 +80,7 @@ describe Environment do
80
80
  let(:profile_count) { 2 }
81
81
 
82
82
  it "should add two instances to that environment with the chosen AMI, size and keypair" do
83
- @env.should_receive(:add_server).with(profile.ami, profile.size, profile.keypair, profile.security_groups).twice
83
+ @env.should_receive(:add_server).with(profile.ami, profile.size, profile.keypair, profile.security_groups, profile.username).twice
84
84
  end
85
85
  end
86
86
 
@@ -223,27 +223,28 @@ EOF
223
223
 
224
224
  it "should create a Server from the provided ami, size and keypair" do
225
225
  Server.should_receive(:create!).with(*@args)
226
- @environment.add_server(*@args)
226
+ @environment.add_server(*@args, 'username')
227
227
  end
228
228
 
229
229
  it "should add the Server to its servers array" do
230
- @environment.add_server(*@args)
231
- @environment.add_server(*@args)
230
+ @environment.add_server(*@args, 'username')
231
+ @environment.add_server(*@args, 'username')
232
232
  @environment.servers.should == [server, server]
233
233
  end
234
234
 
235
- it "should tag the server with the environment name and creator" do
235
+ it "should tag the server with the environment name, creator and username" do
236
236
  server.should_receive(:add_tag).with('Environment', name)
237
237
  server.should_receive(:add_tag).with('Creator', ENV['USER'])
238
- @environment.add_server(*@args)
238
+ server.should_receive(:add_tag).with('Username', 'username')
239
+ @environment.add_server(*@args, 'username')
239
240
  end
240
241
 
241
242
  it "should tag the server with an indexed name" do
242
243
  server.should_receive(:add_tag).with('Name', "#{name} 1")
243
- @environment.add_server(*@args)
244
+ @environment.add_server(*@args, 'username')
244
245
 
245
246
  server.should_receive(:add_tag).with('Name', "#{name} 2")
246
- @environment.add_server(*@args)
247
+ @environment.add_server(*@args, 'username')
247
248
  end
248
249
  end
249
250
 
@@ -32,6 +32,7 @@ describe Profile do
32
32
  security-groups:
33
33
  - non_default
34
34
  keypair: id_revo
35
+ username: myusername
35
36
  "
36
37
  }
37
38
 
@@ -40,6 +41,7 @@ describe Profile do
40
41
  it { subject.size.should == 'c1.medium' }
41
42
  it { subject.security_groups.should == %w{non_default} }
42
43
  it { subject.keypair.should == 'id_revo' }
44
+ it { subject.username.should == 'myusername' }
43
45
 
44
46
  it "should have a to_s" do
45
47
  subject.to_s.should == <<EOF
@@ -53,6 +55,10 @@ EOF
53
55
  end
54
56
  end
55
57
 
58
+ it "should default to 'ubuntu' as the username" do
59
+ subject.username.should == 'ubuntu'
60
+ end
61
+
56
62
  describe "without an elb or RDS section" do
57
63
  it { subject.has_elb?.should be_false }
58
64
  it { subject.has_rds?.should be_false }
@@ -51,7 +51,17 @@ describe Server do
51
51
  end
52
52
 
53
53
  describe :username do
54
- it "should always be 'ubuntu'" do
54
+ context "with a username tag" do
55
+ before :each do
56
+ fog_server.should_receive(:tags).and_return({'Username' => 'bob'})
57
+ end
58
+
59
+ it "should use the username in the tag" do
60
+ @server.username.should == 'bob'
61
+ end
62
+ end
63
+
64
+ it "should default to 'ubuntu' if no Username tag is present" do
55
65
  @server.username.should == 'ubuntu'
56
66
  end
57
67
  end
@@ -98,7 +108,7 @@ describe Server do
98
108
  File.should_receive(:stat).with(@path).and_raise(Errno::ENOENT)
99
109
  end
100
110
 
101
- it { lambda { @server.credentials }.should raise_error /Can't find keyfile/ }
111
+ it { lambda { @server.credentials }.should raise_error %r{Can't find keyfile} }
102
112
  end
103
113
  end
104
114
  end
@@ -147,7 +157,7 @@ describe Server do
147
157
  it "should open a new Gofer::Host connection using the hostname, default username and key data" do
148
158
  Cloud.should_receive(:keyfile_path).with(key_name).and_return('/key/path')
149
159
  File.should_receive(:read).with('/key/path').and_return('key data')
150
- Gofer::Host.should_receive(:new).with(endpoint, 'ubuntu', hash_including(:key_data => ['key data'])).and_return 'ssh'
160
+ Gofer::Host.should_receive(:new).with(endpoint, @server.username, hash_including(:key_data => ['key data'])).and_return 'ssh'
151
161
  @server.ssh.should == 'ssh'
152
162
  end
153
163
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dew
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.6
5
+ version: 0.1.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - PlayUp Devops
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-13 00:00:00 Z
13
+ date: 2011-07-18 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: inform