Class: Dployr::Compute::AWS
- Inherits:
-
Object
- Object
- Dployr::Compute::AWS
- Includes:
- Common
- Defined in:
- lib/dployr/compute/aws.rb
Instance Method Summary collapse
- #create_network(network_name, network_range, firewalls, routes) ⇒ Object
- #delete_network(network_name, network_range, firewalls, routes) ⇒ Object
- #destroy ⇒ Object
- #get_info ⇒ Object
- #get_ip ⇒ Object
- #halt ⇒ Object
-
#initialize(options, attrs) ⇒ AWS
constructor
A new instance of AWS.
- #start ⇒ Object
Methods included from Common
Constructor Details
#initialize(options, attrs) ⇒ AWS
Returns a new instance of AWS.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dployr/compute/aws.rb', line 10 def initialize(, attrs) = { region: [:region][0..-2], provider: 'AWS', aws_access_key_id: (attrs["aws_access_key"] or ENV["AWS_ACCESS_KEY"]), aws_secret_access_key: (attrs["aws_secret_key"] or ENV["AWS_SECRET_KEY"]), } @compute = Fog::Compute.new @attrs = attrs = end |
Instance Method Details
#create_network(network_name, network_range, firewalls, routes) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/dployr/compute/aws.rb', line 81 def create_network(network_name, network_range, firewalls, routes) # Routes not used in AWS create_vpc(network_range) # VPC + INTERNET GATEWAY create_subnet(network_range) # SUBNET + ROUTE TABLE configure_security_group(firewalls) # SECURITY GROUP end |
#delete_network(network_name, network_range, firewalls, routes) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/dployr/compute/aws.rb', line 88 def delete_network(network_name, network_range, firewalls, routes) # Network_name, firewalls and routes not used. We only need "vpc_id" if exist_vpc network_range vpcId = get_vpcId(network_range) delete_route_tables(vpcId) delete_subnets(vpcId) delete_network_acls(vpcId) delete_internet_gateways(vpcId) delete_security_groups(vpcId) delete_vpc(vpcId) else puts "\tNetwork #{network_range} not found. Nothing to delete!" end end |
#destroy ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/dployr/compute/aws.rb', line 37 def destroy instance = get_instance ["running", "stopped", "stopping"] if instance instance.destroy else raise "Instance #{@attrs["name"]} not found" end end |
#get_info ⇒ Object
33 34 35 |
# File 'lib/dployr/compute/aws.rb', line 33 def get_info get_instance ["running", "stopped", "stopping"] end |
#get_ip ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dployr/compute/aws.rb', line 22 def get_ip instance = get_instance ["running"] # TODO: add starting states if instance if [:public_ip] instance.public_ip_address else instance.private_ip_address end end end |
#halt ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/dployr/compute/aws.rb', line 46 def halt instance = get_instance ["running"] if instance instance.stop else raise "Instance #{@attrs["name"]} not found" end end |
#start ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/dployr/compute/aws.rb', line 55 def start server = get_instance ["stopped", "stopping"] if server puts "Starting stopped instance for #{@attrs["name"]} in #{@options[:region]}...".yellow server.start else puts "Creating new instance for #{@attrs["name"]} in #{@options[:region]}...".yellow = { availability_zone: [:region], flavor_id: @attrs["instance_type"], image_id: @attrs["ami"], key_name: @attrs["keypair"], subnet_id: @attrs["subnet_id"], security_group_ids: @attrs["security_groups"], tags: { Name: @attrs["name"] } } puts .to_yaml server = @compute.servers.create end print "Wait for instance to get online".yellow server.wait_for { print ".".yellow; ready? } print "\n" elastic_ip server wait_ssh @attrs, server, [:public_ip] end |