Class: Mccloud::Generator
- Inherits:
-
Object
- Object
- Mccloud::Generator
- Defined in:
- lib/mccloud/generator.rb
Overview
This takes care of initializing a new Mccloud project
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
Instance Method Summary collapse
- #generate(options = {}) ⇒ Object
- #generate_mccloud_sshkey(options) ⇒ Object
- #generate_mccloudfile(options) ⇒ Object
-
#initialize(env) ⇒ Generator
constructor
A new instance of Generator.
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
#env ⇒ Object
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
16 17 18 19 20 21 22 23 |
# File 'lib/mccloud/generator.rb', line 16 def generate(={}) defaults={ :provider => :aws, :force => false} =defaults.merge() provider=[:provider].to_sym raise ::Mccloud::Error, "Unsupported provider #{provider}" unless @generators.include?(provider) generate_mccloudfile() generate_mccloud_sshkey() 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() 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() 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() 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() end rescue Error => ex raise ::Mccloud::Error, "Error creating Mccloudfile.\n#{ex}" end end |