Class: Profile
- Inherits:
-
Object
- Object
- Profile
- Defined in:
- lib/dew/models/profile.rb
Constant Summary collapse
- AWS_RESOURCES =
YAML.load(File.read(File.join(File.dirname(__FILE__), '..', 'aws_resources.yaml')))
Instance Attribute Summary collapse
-
#ami ⇒ Object
Returns the value of attribute ami.
-
#count ⇒ Object
Returns the value of attribute count.
-
#elb_listener_ports ⇒ Object
Returns the value of attribute elb_listener_ports.
-
#keypair ⇒ Object
Returns the value of attribute keypair.
-
#profile_name ⇒ Object
readonly
Returns the value of attribute profile_name.
-
#rds_size ⇒ Object
Returns the value of attribute rds_size.
-
#security_groups ⇒ Object
Returns the value of attribute security_groups.
-
#size ⇒ Object
Returns the value of attribute size.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #has_elb? ⇒ Boolean
- #has_rds? ⇒ Boolean
-
#initialize(profile_name) ⇒ Profile
constructor
A new instance of Profile.
- #to_s ⇒ Object
Constructor Details
#initialize(profile_name) ⇒ Profile
Returns a new instance of Profile.
41 42 43 44 45 |
# File 'lib/dew/models/profile.rb', line 41 def initialize(profile_name) @profile_name = profile_name # :ami, :size, :security_groups, :keypair, :count # :rds_size, :elb_listener_ports end |
Instance Attribute Details
#ami ⇒ Object
Returns the value of attribute ami.
6 7 8 |
# File 'lib/dew/models/profile.rb', line 6 def ami @ami end |
#count ⇒ Object
Returns the value of attribute count.
6 7 8 |
# File 'lib/dew/models/profile.rb', line 6 def count @count end |
#elb_listener_ports ⇒ Object
Returns the value of attribute elb_listener_ports.
7 8 9 |
# File 'lib/dew/models/profile.rb', line 7 def elb_listener_ports @elb_listener_ports end |
#keypair ⇒ Object
Returns the value of attribute keypair.
6 7 8 |
# File 'lib/dew/models/profile.rb', line 6 def keypair @keypair end |
#profile_name ⇒ Object (readonly)
Returns the value of attribute profile_name.
5 6 7 |
# File 'lib/dew/models/profile.rb', line 5 def profile_name @profile_name end |
#rds_size ⇒ Object
Returns the value of attribute rds_size.
7 8 9 |
# File 'lib/dew/models/profile.rb', line 7 def rds_size @rds_size end |
#security_groups ⇒ Object
Returns the value of attribute security_groups.
6 7 8 |
# File 'lib/dew/models/profile.rb', line 6 def security_groups @security_groups end |
#size ⇒ Object
Returns the value of attribute size.
6 7 8 |
# File 'lib/dew/models/profile.rb', line 6 def size @size end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/dew/models/profile.rb', line 7 def username @username end |
Class Method Details
.read(profile_name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dew/models/profile.rb', line 11 def self.read(profile_name) file = File.read(File.join(ENV['HOME'], '.dew', 'profiles', "#{profile_name}.yaml")) yaml = YAML.load(file) profile = new(profile_name) profile.username = 'ubuntu' if yaml['instances'] profile.ami = yaml['instances']['amis'][Cloud.region] profile.size = yaml['instances']['size'] profile.security_groups = yaml['instances']['security-groups'] || ['default'] #XXX is this fallback tested? profile.keypair = yaml['instances']['keypair'] profile.count = yaml['instances']['count'].to_i profile.username = yaml['instances']['username'] if yaml['instances'].include?('username') end if yaml['elb'] profile.elb_listener_ports = yaml['elb']['listener_ports'] end if yaml['rds'] profile.rds_size = yaml['rds']['size'] end profile end |
.size_to_s(size) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/dew/models/profile.rb', line 47 def self.size_to_s(size) #instance_str = "%{memory} memory, %{processor} processor, %{storage} storage, %{platform} platform, %{io_performance} I/O performance" instance_str = "%{memory} GB memory, %{processor} ECUs processor, %{storage} GB storage, %{platform}-bit platform, %{io_performance} I/O performance" flavor = Cloud.compute.flavors.detect { |f| f.id == size } instance_hash = { :memory => flavor.ram.to_s, :processor => flavor.cores.to_s, :storage => flavor.disk.to_s, :platform => flavor.bits.to_s, :io_performance => '??' } instance_hash.inject(instance_str) { |res,(k,v)| res.gsub(/%\{#{k}\}/, v) } end |
Instance Method Details
#has_elb? ⇒ Boolean
33 34 35 |
# File 'lib/dew/models/profile.rb', line 33 def has_elb? elb_listener_ports != nil end |
#has_rds? ⇒ Boolean
37 38 39 |
# File 'lib/dew/models/profile.rb', line 37 def has_rds? rds_size != nil end |
#to_s ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dew/models/profile.rb', line 55 def to_s db_instance_str = "%{memory} memory, %{processor} processor, %{platform} platform, %{io_performance} I/O performance" table { |t| t << [ "#{count} instance#{'s' if count > 1}", "#{size.inspect} (#{self.class.size_to_s(size)})"] t << ['disk image', ami.inspect] t << ['load balancer', "listener ports: #{elb_listener_ports.inspect}"] if has_elb? t << ['database', "#{rds_size.inspect} (#{AWS_RESOURCES['db_instance_types'][rds_size].inject(db_instance_str) { |res,(k,v)| res.gsub(/%\{#{k}\}/, v) } })"] if has_rds? t << ['security groups', security_groups.inspect] t << ['keypair', keypair.inspect] }.to_s end |