Class: Judo::Group
- Inherits:
-
Object
- Object
- Judo::Group
- Defined in:
- lib/judo/group.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #check_conf(conf) ⇒ Object
- #commit ⇒ Object
- #config(version) ⇒ Object
- #destroy ⇒ Object
- #displayname ⇒ Object
-
#initialize(base, name) ⇒ Group
constructor
A new instance of Group.
- #load_config(version) ⇒ Object
- #load_userdata(version) ⇒ Object
- #s3_url(version) ⇒ Object
- #servers ⇒ Object
- #set_version ⇒ Object
- #tar_file(version) ⇒ Object
- #to_s ⇒ Object
- #userdata(version) ⇒ Object
- #version_config_file(version) ⇒ Object
- #version_desc(v) ⇒ Object
- #version_userdata_file(version) ⇒ Object
Constructor Details
#initialize(base, name) ⇒ Group
Returns a new instance of Group.
5 6 7 8 |
# File 'lib/judo/group.rb', line 5 def initialize(base, name) @base = base @name = name end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/judo/group.rb', line 3 def name @name end |
#version ⇒ Object
Returns the value of attribute version.
3 4 5 |
# File 'lib/judo/group.rb', line 3 def version @version end |
Instance Method Details
#check_conf(conf) ⇒ Object
43 44 45 46 47 |
# File 'lib/judo/group.rb', line 43 def check_conf(conf) if conf["import"] raise JudoError, "config option 'import' no longer supported" end end |
#commit ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/judo/group.rb', line 49 def commit raise JudoError, "Group name all is reserved" if name == "all" @base.task("Compiling #{self} version #{version + 1}") do @version = version + 1 conf = JSON.parse(File.read("#{name}/config.json")) userdata = File.read("#{name}/userdata.erb") tar = tar_file(@version) puts "" Util.system_confirmed "tar czvf #{tar} #{name}" puts "Uploading config to s3..." @base.s3_put(version_config_file(@version), conf.to_json) puts "Uploading userdata.erb to s3..." @base.s3_put(version_userdata_file(@version), userdata) puts "Uploading tar file to s3..." @base.s3_put(tar, File.new(tar).read(File.stat(tar).size)) File.delete(tar) set_version end end |
#config(version) ⇒ Object
18 19 20 |
# File 'lib/judo/group.rb', line 18 def config(version) (@config ||= {})[version] ||= load_config(version) end |
#destroy ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/judo/group.rb', line 85 def destroy @base.task("Destroying servers in group #{self}") do servers.each { |s| s.destroy } end @base.task("Destroying group #{self}") do @base.groups.delete(self) @base.sdb.delete_attributes(@base.base_domain, "group_versions", [ name ]) end end |
#displayname ⇒ Object
95 96 97 |
# File 'lib/judo/group.rb', line 95 def displayname ":#{name}" end |
#load_config(version) ⇒ Object
32 33 34 35 36 |
# File 'lib/judo/group.rb', line 32 def load_config(version) JSON.load @base.s3_get(version_config_file(version)) rescue Aws::AwsError raise JudoError, "No config stored: try 'judo commit #{to_s}'" end |
#load_userdata(version) ⇒ Object
26 27 28 29 30 |
# File 'lib/judo/group.rb', line 26 def load_userdata(version) @base.s3_get(version_userdata_file(version)) rescue Aws::AwsError raise JudoError, "No userdata stored: try 'judo commit #{to_s}'" end |
#s3_url(version) ⇒ Object
81 82 83 |
# File 'lib/judo/group.rb', line 81 def s3_url(version) @url = @base.s3_url(tar_file(version)) end |
#servers ⇒ Object
22 23 24 |
# File 'lib/judo/group.rb', line 22 def servers @base.servers.select { |s| s.group_name == name } end |
#set_version ⇒ Object
38 39 40 41 |
# File 'lib/judo/group.rb', line 38 def set_version @base.sdb.put_attributes(@base.base_domain, "group_versions", {name => version}, :replace) end |
#tar_file(version) ⇒ Object
77 78 79 |
# File 'lib/judo/group.rb', line 77 def tar_file(version) "#{name}.#{version}.tar.gz" end |
#to_s ⇒ Object
99 100 101 |
# File 'lib/judo/group.rb', line 99 def to_s displayname end |
#userdata(version) ⇒ Object
14 15 16 |
# File 'lib/judo/group.rb', line 14 def userdata(version) (@userdata ||= {})[version] ||= load_userdata(version) end |
#version_config_file(version) ⇒ Object
69 70 71 |
# File 'lib/judo/group.rb', line 69 def version_config_file(version) "#{name}.#{version}.json" end |
#version_desc(v) ⇒ Object
103 104 105 |
# File 'lib/judo/group.rb', line 103 def version_desc(v) v == version ? "v#{v}" : "v#{v}/#{version}" end |
#version_userdata_file(version) ⇒ Object
73 74 75 |
# File 'lib/judo/group.rb', line 73 def version_userdata_file(version) "#{name}.#{version}.erb" end |