Class: AMIsController

Inherits:
Object
  • Object
show all
Defined in:
lib/dew/controllers/amis_controller.rb

Instance Method Summary collapse

Instance Method Details

#create(ami_name, puppet_node_name, prototype_profile_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dew/controllers/amis_controller.rb', line 5

def create(ami_name, puppet_node_name, prototype_profile_name)
  Inform.info("Creating new AMI %{ami_name} using puppet node %{puppet} based on %{prototype_profile_name}", :ami_name => ami_name, :puppet => puppet_node_name, :prototype_profile_name => prototype_profile_name)
  environment_name = ami_name + '-prototype-' + $$.to_s

  environment = Environment.create(environment_name, Profile.read(prototype_profile_name))
  @prototype = environment.servers.first
  Inform.debug("Using server %{id} at %{ip} as our prototype.", :id => @prototype.id, :ip => @prototype.public_ip_address)

  Inform.debug("Installing puppet...")
  install_puppet_on_prototype
  Inform.debug("Copying puppet configuration... ")
  copy_puppet_to_prototype
  Inform.debug("Running puppet node %{node}... ", :node => puppet_node_name)
  run_puppet_node_on_prototype puppet_node_name

  ami_id = Inform.info "Creating new ami with name %{ami_name}", :ami_name => ami_name do
    @prototype.create_ami ami_name
  end
  Inform.info("New AMI id is %{ami_id}", :ami_id => ami_id)
  environment.destroy
end

#destroy(ami_name, opts = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dew/controllers/amis_controller.rb', line 42

def destroy ami_name, opts={}
  ami = Cloud.compute.images.all('name' => ami_name).first
  raise "AMI named #{ami_name} not found!" unless ami
  if opts[:force] || agree("<%= color('Are you sure?', YELLOW, BOLD) %> ")
    Inform.info("Destroying AMI named %{n}", :n => ami_name) do
      ami.deregister
    end
  else
    Inform.info "Aborting AMI destruction"
  end
end

#indexObject



27
28
29
30
31
32
33
# File 'lib/dew/controllers/amis_controller.rb', line 27

def index
  # Inform.info("AMIs:\n#{Cloud.compute.images.all('owner_id' => Cloud.account.aws_user_id)}")
  # /home/chris/.rvm/gems/ruby-1.9.2-p180@AWS/gems/excon-0.6.3/lib/excon/connection.rb:179:in `request': InvalidParameterValue => The filter 'owner_id' is invalid (Fog::Service::Error)
  my_amis = Cloud.compute.images.all.select { |x| x.owner_id == Cloud..aws_user_id }
  keys = %w(name id state architecture kernel_id description)
  Inform.info(View.new('My AMIs', my_amis, keys).index)
end

#show(ami_name) ⇒ Object



35
36
37
38
39
40
# File 'lib/dew/controllers/amis_controller.rb', line 35

def show ami_name
  my_amis = Cloud.compute.images.all('name' => ami_name)
  raise "AMI named #{ami_name} not found!" if my_amis.empty?
  keys = %w(id architecture block_device_mapping description location owner_id state type is_public kernel_id platform product_codes ramdisk_id root_device_type root_device_name tags name)
  Inform.info(View.new('My AMIs', my_amis, keys).show(0))
end