Class: Bosh::CloudFoundry::Providers::AWS
- Inherits:
-
Object
- Object
- Bosh::CloudFoundry::Providers::AWS
- Defined in:
- lib/bosh-cloudfoundry/providers/aws.rb
Instance Attribute Summary collapse
-
#fog_compute ⇒ Object
readonly
Returns the value of attribute fog_compute.
Instance Method Summary collapse
-
#aws_compute_flavors ⇒ Array
Example [Hash] { :bits => 0, :cores => 2, :disk => 0, :id => ‘t1.micro’, :name => ‘Micro Instance’, :ram => 613}.
-
#create_security_group(security_group_name, ports) ⇒ Object
Creates or reuses an AWS security group and opens ports.
-
#fog_compute_flavor(server_flavor_id) ⇒ Hash
or nil if
server_flavor_id
is not a supported flavor ID. -
#initialize(fog_compute = nil) ⇒ AWS
constructor
A new instance of AWS.
- #port_open?(ip_permissions, port) ⇒ Boolean
-
#provision_public_ip_address ⇒ String
TODO nil if none available.
-
#ram_for_server_flavor(server_flavor_id) ⇒ Integer
Megabytes of RAM for requested flavor of server.
Constructor Details
#initialize(fog_compute = nil) ⇒ AWS
Returns a new instance of AWS.
7 8 9 |
# File 'lib/bosh-cloudfoundry/providers/aws.rb', line 7 def initialize(fog_compute=nil) @fog_compute = fog_compute end |
Instance Attribute Details
#fog_compute ⇒ Object (readonly)
Returns the value of attribute fog_compute.
6 7 8 |
# File 'lib/bosh-cloudfoundry/providers/aws.rb', line 6 def fog_compute @fog_compute end |
Instance Method Details
#aws_compute_flavors ⇒ Array
Example [Hash] { :bits => 0, :cores => 2, :disk => 0,
:id => 't1.micro', :name => 'Micro Instance', :ram => 613}
30 31 32 |
# File 'lib/bosh-cloudfoundry/providers/aws.rb', line 30 def aws_compute_flavors Fog::Compute::AWS::FLAVORS end |
#create_security_group(security_group_name, ports) ⇒ Object
Creates or reuses an AWS security group and opens ports.
security_group_name
is the name to be created or reused ports
is a hash of name/port for ports to open, for example:
ssh: 22,
http: 80,
https: 443
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bosh-cloudfoundry/providers/aws.rb', line 52 def create_security_group(security_group_name, ports) unless sg = fog_compute.security_groups.get(security_group_name) sg = fog_compute.security_groups.create(name: security_group_name, description: "microbosh") puts "Created security group #{security_group_name}" else puts "Reusing security group #{security_group_name}" end = sg. ports_opened = 0 ports.each do |name, port| unless port_open?(, port) sg.(port..port) puts " -> opened #{name} port #{port}" ports_opened += 1 end end puts " -> no additional ports opened" if ports_opened == 0 true end |
#fog_compute_flavor(server_flavor_id) ⇒ Hash
or nil if server_flavor_id
is not a supported flavor ID
23 24 25 |
# File 'lib/bosh-cloudfoundry/providers/aws.rb', line 23 def fog_compute_flavor(server_flavor_id) aws_compute_flavors.find { |fl| fl[:id] == server_flavor_id } end |
#port_open?(ip_permissions, port) ⇒ Boolean
72 73 74 |
# File 'lib/bosh-cloudfoundry/providers/aws.rb', line 72 def port_open?(, port) && .find {|ip| ip["fromPort"] <= port && ip["toPort"] >= port } end |
#provision_public_ip_address ⇒ String
TODO nil if none available
36 37 38 39 40 41 |
# File 'lib/bosh-cloudfoundry/providers/aws.rb', line 36 def provision_public_ip_address return unless fog_compute address = fog_compute.addresses.create address.public_ip # TODO catch error and return nil end |
#ram_for_server_flavor(server_flavor_id) ⇒ Integer
Returns megabytes of RAM for requested flavor of server.
12 13 14 15 16 17 18 |
# File 'lib/bosh-cloudfoundry/providers/aws.rb', line 12 def ram_for_server_flavor(server_flavor_id) if flavor = fog_compute_flavor(server_flavor_id) flavor[:ram] else raise "Unknown AWS flavor '#{server_flavor_id}'" end end |