Class: Mccloud::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/mccloud/generator.rb

Overview

This takes care of initializing a new Mccloud project

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Generator

Returns a new instance of Generator.



11
12
13
14
# File 'lib/mccloud/generator.rb', line 11

def initialize(env)
  @env=env
  @generators=[:aws,:kvm,:host]
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



9
10
11
# File 'lib/mccloud/generator.rb', line 9

def env
  @env
end

Instance Method Details

#generate(options = {}) ⇒ Object

Raises:



16
17
18
19
20
21
22
23
# File 'lib/mccloud/generator.rb', line 16

def generate(options={})
  defaults={ :provider => :aws, :force => false}
  options=defaults.merge(options)
  provider=options[:provider].to_sym
  raise ::Mccloud::Error, "Unsupported provider #{provider}" unless @generators.include?(provider)
  generate_mccloudfile(options)
  generate_mccloud_sshkey(options)
end

#generate_mccloud_sshkey(options) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/mccloud/generator.rb', line 39

def generate_mccloud_sshkey(options)
  k=Mccloud::Keypair.new("mccloud",env)
  if k.exists?
      env.ui.info "Re-using existing mccloud RSA key in #{k.public_key_path}"
  else
    k.generate(options)
  end
end

#generate_mccloudfile(options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mccloud/generator.rb', line 25

def generate_mccloudfile(options)
  begin
    f=Mccloud::Mccloudfile.new(File.join(env.root_path,"Mccloudfile"))
    if f.exists?
      env.ui.error "Mccloudfile already exists"
    else
      env.ui.info "Creating a new Mccloudfile"
      f.generate(options)
    end
  rescue Error => ex
    raise ::Mccloud::Error, "Error creating Mccloudfile.\n#{ex}"
  end
end