judo 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -10,6 +10,8 @@
10
10
  ### [ ] store s3 bucket in config
11
11
  ### [ ] saw a timeout on volume allocation - make sure we build in re-tries - need to allocate the server all together as much as possible
12
12
  ### [ ] round robin or specified availability_zone
13
+ ### [ ] clean up the --group stuff in the code - get it out of judo
14
+ ### [ ] want 'judo destroy :ronin ^server1'
13
15
 
14
16
  ### MAYBE
15
17
  ### [ ] store things in s3 by sha1sum
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/bin/judo CHANGED
@@ -32,7 +32,7 @@ Usage: judo launch [options] SERVER ...
32
32
 
33
33
  judo snapshot [options] SERVER SNAPSHOT ## take an ebs snapshot of a server
34
34
  judo snapshots [options] [SERVER ...] ## show current snapshots on servers
35
- judo clone [options] SNAPSHOT SERVER ## create a new server from a snapshot
35
+ judo animate [options] SNAPSHOT SERVER ## create a new server from a snapshot
36
36
  judo erase [options] SNAPSHOT ## erase an old snapshot
37
37
 
38
38
  judo swapip [options] SERVER SERVER ## swap elastic IP's on the two servers
@@ -143,14 +143,14 @@ begin
143
143
  raise JudoError, "You must specify a valid server to snapshot" if servers.empty?
144
144
  raise JudoError, "You can only snapshot one server at a time" if servers.size > 1
145
145
  servers[0].snapshot(snapshot_name)
146
- when "clone" then
146
+ when "animate" then
147
147
  snapshot_name = ARGV.shift
148
148
  raise JudoError, "You must specify a snapshot name" unless snapshot_name
149
149
  new_server = ARGV.shift
150
150
  raise JudoError, "You must specify a new server name" unless new_server
151
151
  snapshot = judo.snapshots.detect { |s| s.name == snapshot_name }
152
152
  raise JudoError, "No such snapshot #{snapshot_name}" unless snapshot
153
- snapshot.clone(new_server,options[:version])
153
+ snapshot.animate(new_server,options[:version])
154
154
  when "destroy" then
155
155
  raise JudoError, "You must specify what servers to destroy" if ARGV.empty?
156
156
  find_either(judo, ARGV) do |i|
@@ -24,9 +24,9 @@ end
24
24
 
25
25
  module Judo
26
26
  class Base
27
- attr_accessor :judo_dir, :repo, :group
27
+ attr_accessor :judo_dir, :repo, :group, :domain
28
28
 
29
- def initialize(options)
29
+ def initialize(options = Judo::Base.default_options)
30
30
  @judo_dir = options[:judo_dir]
31
31
  @repo = options[:repo]
32
32
  @group = options[:group]
@@ -81,7 +81,7 @@ module Judo
81
81
  sdb_domain("judo_config")
82
82
  end
83
83
 
84
- def self.default_options(pwd, dir = find_judo_dir(pwd))
84
+ def self.default_options(pwd = Dir.pwd, dir = find_judo_dir(pwd))
85
85
  config = YAML.load File.read("#{dir}/config.yml")
86
86
  repo_dir = config["repo"] || File.dirname(dir)
87
87
  group_config = Dir["#{repo_dir}/*/config.json"].detect { |d| File.dirname(d) == pwd }
@@ -152,7 +152,7 @@ module JudoCommandLineHelpers
152
152
  puts "[ #{server} ]"
153
153
  printf " %-24s: %s\n", "Group", server.group.name
154
154
  printf " %-24s: %s\n", "Note", server.note if server.note
155
- printf " %-24s: %s\n", "Clone Of", server.clone if server.clone
155
+ printf " %-24s: %s\n", "Animated From", server.clone if server.clone
156
156
  printf " %-24s: %s\n", "Elastic Ip", server.elastic_ip if server.elastic_ip
157
157
  sub_info("EC2", server.ec2_instance) do |i|
158
158
  [:aws_instance_id, :ssh_key_name, :aws_availability_zone, :aws_state, :aws_image_id, :dns_name, :aws_instance_type, :private_dns_name, :aws_launch_time, :aws_groups ].each do |k|
@@ -54,7 +54,7 @@ module Judo
54
54
  end
55
55
  File.open("config.json", "w") { |f| f.write(new_config.to_json) }
56
56
  Dir.chdir("..") do
57
- system "tar czf #{tar_file} #{name}"
57
+ system "tar czvf #{tar_file} #{name}"
58
58
  # puts "Uploading to s3..."
59
59
  @base.s3_put(tar_file, File.new(tar_file).read)
60
60
  @base.s3_put(version_config_file, new_config.to_json)
@@ -11,10 +11,13 @@ module Judo
11
11
  def create(options)
12
12
  raise JudoError, "no group specified" unless group_name
13
13
 
14
+ options[:virgin] = true if options[:virgin].nil?
15
+
14
16
  snapshots = options[:snapshots]
15
- note = options[:note] ## a user defined note field
16
- data = options[:data] ## instance specific data passed in JUDO_DATA
17
- ip = options[:elastic_ip] ## if the ip was allocated beforehand
17
+ note = options[:note] ## a user defined note field
18
+ data = options[:data] ## instance specific data passed in JUDO_DATA
19
+ ip = options[:elastic_ip] ## if the ip was allocated beforehand
20
+ virgin = options[:virgin] ## should the server init?
18
21
 
19
22
  version = options[:version]
20
23
  version ||= group.version
@@ -28,7 +31,7 @@ module Judo
28
31
 
29
32
  task("Creating server #{name}") do
30
33
  update "name" => name, "group" => group_name,
31
- "note" => note, "virgin" => true,
34
+ "note" => note, "virgin" => virgin,
32
35
  "secret" => new_secret, "version" => version,
33
36
  "data" => data, "elastic_ip" => ip
34
37
  @base.sdb.put_attributes(@base.base_domain, "groups", group_name => name)
@@ -90,11 +93,7 @@ module Judo
90
93
 
91
94
  def kuzushi_action
92
95
  if virgin?
93
- if cloned?
94
- "start"
95
- else
96
- "init"
97
- end
96
+ "init"
98
97
  else
99
98
  "start"
100
99
  end
@@ -328,6 +327,7 @@ module Judo
328
327
  force_detach_volumes if force
329
328
  wait_for_volumes_detached if volumes.size > 0
330
329
  remove "instance_id"
330
+ update "stopped_at" => Time.now.to_i
331
331
  end
332
332
 
333
333
  def launch_ec2(boot = nil)
@@ -342,7 +342,7 @@ module Judo
342
342
  :key_name => config["key_name"],
343
343
  :group_ids => security_groups,
344
344
  :user_data => ud).first
345
- update "instance_id" => result[:aws_instance_id], "virgin" => false
345
+ update "instance_id" => result[:aws_instance_id], "virgin" => false, "started_at" => Time.now.to_i
346
346
  end
347
347
 
348
348
  def debug(str)
@@ -498,6 +498,7 @@ module Judo
498
498
  export DEBIAN_FRONTEND="noninteractive"
499
499
  export DEBIAN_PRIORITY="critical"
500
500
  export JUDO_ID='#{name}'
501
+ export JUDO_DOMAIN='#{@base.domain}'
501
502
  export JUDO_BOOT='#{judo_boot}'
502
503
  export JUDO_DATA='#{data}'
503
504
  export SECRET='#{secret}'
@@ -1,11 +1,17 @@
1
1
  module Judo
2
+ ### sdb
3
+ ### name {
4
+ ### "version" => [ server.version ],
5
+ ### "devs" => [ "/dev/sde1:snap-abc123", "/dev/sde2:snap-abc456" ],
6
+ ### "server" => server.name
7
+ ### "group" => server.group.name
8
+ ### "virgin" => server.virgin
9
+ ### "note" => server.note
10
+ ### "data" => server.data
11
+ ### "created_at" => unixtime
2
12
  class Snapshot
3
13
  attr_accessor :name, :server_name
4
14
 
5
- def self.domain
6
- "judo_snapshots"
7
- end
8
-
9
15
  def initialize(base, name, server_name)
10
16
  @base = base
11
17
  @name = name
@@ -28,10 +34,26 @@ module Judo
28
34
  get("group")
29
35
  end
30
36
 
37
+ def created_at
38
+ Time.at(get("time").to_i)
39
+ end
40
+
31
41
  def version
32
42
  get("version").to_i
33
43
  end
34
44
 
45
+ def note
46
+ get("note")
47
+ end
48
+
49
+ def data
50
+ get("data")
51
+ end
52
+
53
+ def virgin
54
+ get("virgin").to_s == "true"
55
+ end
56
+
35
57
  def devs
36
58
  Hash[ (state["devs"] || []).map { |a| a.split(":") } ]
37
59
  end
@@ -43,16 +65,26 @@ module Judo
43
65
  devs = server.volumes.map do |dev,vol|
44
66
  "#{dev}:#{@base.ec2.create_snapshot(vol)[:aws_id]}"
45
67
  end
46
- @base.sdb.put_attributes(@base.snapshot_domain, name, { "version" => server.version, "devs" => devs, "server" => server.name, "group" => server.group.name }, :replace)
68
+ @base.sdb.put_attributes(@base.snapshot_domain, name, {
69
+ "version" => server.version,
70
+ "virgin" => server.virgin?,
71
+ "note" => server.note,
72
+ "data" => server.data,
73
+ "devs" => devs,
74
+ "server" => server.name,
75
+ "group" => server.group.name,
76
+ "created_at" => Time.now.to_i.to_s
77
+ }, :replace)
47
78
  server.add "snapshots", name
48
79
  end
49
80
  end
50
81
 
51
- def clone(new_server, version = self.version)
52
- raise JudoError, "cannot clone, snapshotting not complete" unless completed?
82
+ def animate(new_server, version = self.version)
83
+ raise JudoError, "cannot animate, snapshotting not complete" unless completed?
53
84
  server = @base.new_server(new_server, group_name)
54
- server.create( :version => version, :snapshots => devs)
85
+ server.create( :version => version, :snapshots => devs, :virgin => virgin, :note => note, :data => data )
55
86
  server.update "clone" => name ##, "secret" => rand(2 ** 128).to_s(36) ## cant change this till kuzushi knows about a post-clone operation
87
+ server
56
88
  end
57
89
 
58
90
  def delete
@@ -81,8 +113,16 @@ module Judo
81
113
  devs.values
82
114
  end
83
115
 
116
+ def ec2_data
117
+ @base.ec2_snapshots.select { |s| ec2_ids.include? s[:aws_id] }
118
+ end
119
+
84
120
  def completed?
85
- not @base.ec2_snapshots.select { |s| ec2_ids.include? s[:aws_id] }.detect { |s| s[:aws_status] != "completed" }
121
+ not ec2_data.detect { |s| s[:aws_status] != "completed" }
122
+ end
123
+
124
+ def progress
125
+ "#{(ec2_data.inject(0) { |sum,a| sum + a[:aws_progress].to_i } / ec2_data.size).to_i}%"
86
126
  end
87
127
 
88
128
  def size(snap_id)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Orion Henry
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-18 00:00:00 -04:00
17
+ date: 2010-05-20 00:00:00 -04:00
18
18
  default_executable: judo
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency