Class: Inception::Providers::Clients::AwsProviderClient
- Inherits:
-
FogProviderClient
- Object
- FogProviderClient
- Inception::Providers::Clients::AwsProviderClient
- Defined in:
- lib/inception/providers/clients/aws_provider_client.rb
Instance Attribute Summary
Attributes inherited from FogProviderClient
Instance Method Summary collapse
- #associate_ip_address_with_server(ip_address, server) ⇒ Object
- #aws_compute_flavor_ids ⇒ Object
-
#aws_compute_flavors ⇒ Array
Example [Hash] { :bits => 0, :cores => 2, :disk => 0, :id => ‘t1.micro’, :name => ‘Micro Instance’, :ram => 613}.
- #create_and_attach_volume(name, disk_size, server, device) ⇒ Object
- #create_internet_gateway(vpc_id) ⇒ Object
-
#create_subnet(vpc_id, cidr_block) ⇒ String
Creates a VPC subnet.
- #create_vpc(name, cidr_block) ⇒ Object
- #find_server_device(server, device) ⇒ Object
- #fog_attributes(inception_server) ⇒ Object
-
#fog_compute_flavor(server_flavor_id) ⇒ Hash
or nil if
server_flavor_id
is not a supported flavor ID. -
#image_id ⇒ Object
Ubuntu 13.04.
-
#provision_public_ip_address(options = {}) ⇒ String
Provision an EC2 or VPC elastic IP addess.
-
#ram_for_server_flavor(server_flavor_id) ⇒ Integer
Megabytes of RAM for requested flavor of server.
-
#setup_fog_connection ⇒ Object
Construct a Fog::Compute object Uses
attributes
which normally originates fromsettings.provider
.
Methods included from Inception::Providers::Constants::AwsConstants
#default_region_code, #region_labels
Methods inherited from FogProviderClient
#authorize_port_range, #bootstrap, #cleanup_unused_ip_addresses, #create_key_pair, #create_security_group, #delete_key_pair_if_exists, #delete_servers_with_name, #delete_volumes_with_name, #extract_port_definition, #find_unused_public_ip_address, #flavor_id, #initialize, #ip_permissions, #port_open?, #provision_or_reuse_public_ip_address, #set_resource_name
Constructor Details
This class inherits a constructor from Inception::Providers::Clients::FogProviderClient
Instance Method Details
#associate_ip_address_with_server(ip_address, server) ⇒ Object
54 55 56 57 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 54 def associate_ip_address_with_server(ip_address, server) address = fog_compute.addresses.get(ip_address) address.server = server end |
#aws_compute_flavor_ids ⇒ Object
34 35 36 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 34 def aws_compute_flavor_ids aws_compute_flavors.map { |fl| fl[:id] } end |
#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/inception/providers/clients/aws_provider_client.rb', line 30 def aws_compute_flavors Fog::Compute::AWS::FLAVORS end |
#create_and_attach_volume(name, disk_size, server, device) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 80 def create_and_attach_volume(name, disk_size, server, device) volume = fog_compute.volumes.create( size: disk_size, name: name, description: '', device: device, availability_zone: server.availability_zone) # TODO: the following works in fog 1.9.0+ (but which has a bug in bootstrap) # https://github.com/fog/fog/issues/1516 # # volume.wait_for { volume.status == 'available' } # volume.attach(server.id, "/dev/vdc") # volume.wait_for { volume.status == 'in-use' } # # Instead, using: volume.server = server end |
#create_internet_gateway(vpc_id) ⇒ Object
71 72 73 74 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 71 def create_internet_gateway(vpc_id) gateway = fog_compute.internet_gateways.create(vpc_id: vpc_id) gateway.id end |
#create_subnet(vpc_id, cidr_block) ⇒ String
Creates a VPC subnet
66 67 68 69 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 66 def create_subnet(vpc_id, cidr_block) subnet = fog_compute.subnets.create(vpc_id: vpc_id, cidr_block: cidr_block) subnet.subnet_id end |
#create_vpc(name, cidr_block) ⇒ Object
59 60 61 62 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 59 def create_vpc(name, cidr_block) vpc = fog_compute.vpcs.create(name: name, cidr_block: cidr_block) vpc.id end |
#find_server_device(server, device) ⇒ Object
76 77 78 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 76 def find_server_device(server, device) server.volumes.all.find {|v| v.device == device} end |
#fog_attributes(inception_server) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 132 def fog_attributes(inception_server) { image_id: inception_server.image_id, groups: inception_server.security_groups, key_name: inception_server.key_name, private_key_path: inception_server.private_key_path, flavor_id: inception_server.flavor, public_ip_address: inception_server.ip_address, bits: 64, username: "ubuntu", } 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/inception/providers/clients/aws_provider_client.rb', line 23 def fog_compute_flavor(server_flavor_id) aws_compute_flavors.find { |fl| fl[:id] == server_flavor_id } end |
#image_id ⇒ Object
Ubuntu 13.04
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 99 def image_id region = fog_compute.region # http://cloud-images.ubuntu.com/locator/ec2/ image_id = case region.to_s when "ap-northeast-1" "ami-6b26ab6a" when "ap-southeast-1" "ami-2b511e79" when "eu-west-1" "ami-3d160149" when "sa-east-1" "ami-28e43e35" when "us-east-1" "ami-c30360aa" when "us-west-1" "ami-d383af96" when "ap-southeast-2" "ami-84a333be" when "us-west-2" "ami-bf1d8a8f" end image_id || raise("Please add Ubuntu 13.04 64bit (EBS) AMI image id to aws.rb#raring_image_id method for region '#{region}'") end |
#provision_public_ip_address(options = {}) ⇒ String
Provision an EC2 or VPC elastic IP addess.
-
VPC - provision_public_ip_address(vpc: true)
-
EC2 - provision_public_ip_address
TODO nil if none available
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 43 def provision_public_ip_address(={}) if .delete(:vpc) [:domain] = "vpc" else [:domain] = .delete(:domain) || "standard" end 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/inception/providers/clients/aws_provider_client.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 |
#setup_fog_connection ⇒ Object
Construct a Fog::Compute object Uses attributes
which normally originates from settings.provider
125 126 127 128 129 130 |
# File 'lib/inception/providers/clients/aws_provider_client.rb', line 125 def setup_fog_connection configuration = Fog.symbolize_credentials(attributes.credentials) configuration[:provider] = "AWS" configuration[:region] = attributes.region @fog_compute = Fog::Compute.new(configuration) end |