Class: Cloud

Inherits:
Object
  • Object
show all
Defined in:
lib/sproutr/cloud.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCloud

Returns a new instance of Cloud.



10
11
12
# File 'lib/sproutr/cloud.rb', line 10

def initialize
  @ec2 ||= Swirl::AWS.new :ec2, load_config
end

Class Attribute Details

.imagesObject

Returns the value of attribute images.



7
8
9
# File 'lib/sproutr/cloud.rb', line 7

def images
  @images
end

.instancesObject

Returns the value of attribute instances.



7
8
9
# File 'lib/sproutr/cloud.rb', line 7

def instances
  @instances
end

Instance Method Details

#describe_image(ami) ⇒ Object



29
30
31
# File 'lib/sproutr/cloud.rb', line 29

def describe_image(ami)
  @ec2.call "DescribeImages", "ImageId" => ami
end

#get_imagesObject



21
22
23
24
25
26
27
# File 'lib/sproutr/cloud.rb', line 21

def get_images
  aws_images = @ec2.call "DescribeImages", "Owner" => "self"
  images = aws_images["imagesSet"].select { |img| img["name"] } rescue nil
  @images = Array.new
  images.each { |image| @images << Ami.new(image) }
  @images
end

#get_instancesObject



14
15
16
17
18
19
# File 'lib/sproutr/cloud.rb', line 14

def get_instances
  aws_instances = @ec2.call "DescribeInstances"
  @instances = Array.new
  aws_instances["reservationSet"].each { |reservation| @instances << Instance.new(reservation["instancesSet"][0]) }
  @instances
end