Class: Profile

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile_name) ⇒ Profile

Returns a new instance of Profile.



40
41
42
43
44
# File 'lib/dew/models/profile.rb', line 40

def initialize(profile_name)
  @profile_name = profile_name
  # :ami, :size, :security_groups, :keypair, :count
  # :rds_size, :elb_listener_ports
end

Instance Attribute Details

#amiObject

Returns the value of attribute ami.



6
7
8
# File 'lib/dew/models/profile.rb', line 6

def ami
  @ami
end

#countObject

Returns the value of attribute count.



6
7
8
# File 'lib/dew/models/profile.rb', line 6

def count
  @count
end

#elb_listener_portsObject

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

#keypairObject

Returns the value of attribute keypair.



6
7
8
# File 'lib/dew/models/profile.rb', line 6

def keypair
  @keypair
end

#profile_nameObject (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_sizeObject

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_groupsObject

Returns the value of attribute security_groups.



6
7
8
# File 'lib/dew/models/profile.rb', line 6

def security_groups
  @security_groups
end

#sizeObject

Returns the value of attribute size.



6
7
8
# File 'lib/dew/models/profile.rb', line 6

def size
  @size
end

#usernameObject

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
# File 'lib/dew/models/profile.rb', line 11

def self.read(profile_name)
  yaml = YAML.load_file(File.join(ENV['HOME'], '.dew', 'profiles', "#{profile_name}.yaml"))
  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



46
47
48
49
50
51
52
# File 'lib/dew/models/profile.rb', line 46

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/dew/models/profile.rb', line 32

def has_elb?
  elb_listener_ports != nil
end

#has_rds?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/dew/models/profile.rb', line 36

def has_rds?
  rds_size != nil
end

#to_sObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dew/models/profile.rb', line 54

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