Module: CloudProviders::Ec2Helpers

Included in:
Ec2
Defined in:
lib/cloud_providers/ec2/ec2_helpers.rb

Instance Method Summary collapse

Instance Method Details

#associate_address(instance_id) ⇒ Object

Associate an address with the instance using ec2 Get the next_unused_elastic_ip and if there is one, associate the instance to the public ip



46
47
48
49
50
51
52
53
54
55
# File 'lib/cloud_providers/ec2/ec2_helpers.rb', line 46

def associate_address(instance_id)
  new_ip = next_unused_elastic_ip
  ec2.associate_address(instance_id, new_ip)
  loop do
    if describe_instance(:instance_id => instance_id).public_ip == new_ip
      return new_ip
    end
    sleep 1
  end
end

#attach_volume(instance_id, volume_id = next_unused_volume, device = "/dev/sdh") ⇒ Object

VOLUMES



5
6
7
# File 'lib/cloud_providers/ec2/ec2_helpers.rb', line 5

def attach_volume(instance_id, volume_id=next_unused_volume, device="/dev/sdh")
  ec2.attach_volume(volume_id, instance_id, device)
end

#next_unused_elastic_ipObject

Get the next usable elastic ip First, get the list of addresses from ec2 that the client has access to, then select only the ones that are not associated with an instance. If the cloud has set elastic_ips to use, then, using the intersection of the unused ips and those, find the first one available and return that.



64
65
66
67
68
69
70
# File 'lib/cloud_providers/ec2/ec2_helpers.rb', line 64

def next_unused_elastic_ip
  if unusued_elastic_ips.empty?
    nil
  else
    unusued_elastic_ips.first
  end
end

#next_unused_volumeObject



9
10
11
12
13
14
15
# File 'lib/cloud_providers/ec2/ec2_helpers.rb', line 9

def next_unused_volume
  if all_volumes.empty?
    nil
  else
    available_volumes.first
  end
end

#security_groups(list = []) ⇒ Object

SECURITY GROUPS



34
35
36
# File 'lib/cloud_providers/ec2/ec2_helpers.rb', line 34

def security_groups(list=[])
  ec2.describe_security_groups(list)
end