Class: Dployr::Compute::AWS
- Inherits:
-
Object
- Object
- Dployr::Compute::AWS
- Includes:
- Common
- Defined in:
- lib/dployr/compute/aws.rb
Instance Method Summary collapse
- #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: ENV["AWS_ACCESS_KEY"], aws_secret_access_key: ENV["AWS_SECRET_KEY"], } @compute = Fog::Compute.new @attrs = attrs = end |
Instance Method Details
#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] return instance.public_ip_address else return 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 |