Class: Mccloud::Config
- Inherits:
-
Object
- Object
- Mccloud::Config
- Defined in:
- lib/mccloud/config.rb,
lib/mccloud/config/keypair.rb,
lib/mccloud/config/mccloud.rb,
lib/mccloud/config/provider.rb,
lib/mccloud/config/template.rb,
lib/mccloud/config/component.rb,
lib/mccloud/config/collection.rb,
lib/mccloud/config/definition.rb
Defined Under Namespace
Classes: Collection, Component, Definition, Keypair, Mccloud, Provider, Template
Instance Attribute Summary collapse
-
#definitions ⇒ Object
Returns the value of attribute definitions.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#ips ⇒ Object
Returns the value of attribute ips.
-
#keypairs ⇒ Object
Returns the value of attribute keypairs.
-
#keystores ⇒ Object
Returns the value of attribute keystores.
-
#lbs ⇒ Object
Returns the value of attribute lbs.
-
#mccloud ⇒ Object
include ::Mccloud::Logger.
-
#providers ⇒ Object
Returns the value of attribute providers.
-
#stacks ⇒ Object
Returns the value of attribute stacks.
-
#templates ⇒ Object
Returns the value of attribute templates.
-
#vms ⇒ Object
Returns the value of attribute vms.
Instance Method Summary collapse
- #define {|config| ... } ⇒ Object
- #filter ⇒ Object
-
#initialize(options) ⇒ Config
constructor
A new instance of Config.
-
#load_mccloud_config ⇒ Object
We put a long name to not clash with any function in the Mccloud file itself.
- #stackfilter ⇒ Object
Constructor Details
#initialize(options) ⇒ Config
Returns a new instance of Config.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mccloud/config.rb', line 29 def initialize() @env=[:env] env.logger.info("config") { "Initializing empty list of vms,lbs,stacks, ips in config" } @lbs=Hash.new;@stacks=Hash.new;@ips=Hash.new; @keystores=Hash.new; @keypairs=Hash.new; @providers=Hash.new; @templates=::Mccloud::Templates.new(env) @definitions=::Mccloud::Definitions.new(env) @vms=::Mccloud::Vms.new(env) end |
Instance Attribute Details
#definitions ⇒ Object
Returns the value of attribute definitions.
27 28 29 |
# File 'lib/mccloud/config.rb', line 27 def definitions @definitions end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
22 23 24 |
# File 'lib/mccloud/config.rb', line 22 def env @env end |
#ips ⇒ Object
Returns the value of attribute ips.
24 25 26 |
# File 'lib/mccloud/config.rb', line 24 def ips @ips end |
#keypairs ⇒ Object
Returns the value of attribute keypairs.
24 25 26 |
# File 'lib/mccloud/config.rb', line 24 def keypairs @keypairs end |
#keystores ⇒ Object
Returns the value of attribute keystores.
24 25 26 |
# File 'lib/mccloud/config.rb', line 24 def keystores @keystores end |
#lbs ⇒ Object
Returns the value of attribute lbs.
24 25 26 |
# File 'lib/mccloud/config.rb', line 24 def lbs @lbs end |
#mccloud ⇒ Object
include ::Mccloud::Logger
20 21 22 |
# File 'lib/mccloud/config.rb', line 20 def mccloud @mccloud end |
#providers ⇒ Object
Returns the value of attribute providers.
25 26 27 |
# File 'lib/mccloud/config.rb', line 25 def providers @providers end |
#stacks ⇒ Object
Returns the value of attribute stacks.
24 25 26 |
# File 'lib/mccloud/config.rb', line 24 def stacks @stacks end |
#templates ⇒ Object
Returns the value of attribute templates.
27 28 29 |
# File 'lib/mccloud/config.rb', line 27 def templates @templates end |
#vms ⇒ Object
Returns the value of attribute vms.
24 25 26 |
# File 'lib/mccloud/config.rb', line 24 def vms @vms end |
Instance Method Details
#define {|config| ... } ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mccloud/config.rb', line 41 def define() config=OpenStruct.new # These don't depend on a provider config.mccloud=::Mccloud::Config::Mccloud.new(self) @mccloud=config.mccloud # Assign templates config.template=::Mccloud::Config::Template.new(self) config.template.components=@templates # Assign definitions config.definition=::Mccloud::Config::Definition.new(self) config.definition.components=@definitions # Assign keypairs config.keypair=::Mccloud::Config::Keypair.new(self) config.keypair.components=@keypairs # Assign providers config.provider=::Mccloud::Config::Provider.new(self) config.provider.components=@providers # These components depend on a provider, so we try to guess it frst # This will access self's variables like : # vms,lbs, ips, etc by simply putting an 's' after the type config.vm=::Mccloud::Config::Collection.new("vm",self) config.lb=::Mccloud::Config::Collection.new("lb",self) config.ip=::Mccloud::Config::Collection.new("ip",self) config.stack=::Mccloud::Config::Collection.new("stack",self) config.keystore=::Mccloud::Config::Collection.new("keystore",self) # Process config file yield config end |
#filter ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/mccloud/config.rb', line 109 def filter() mcfilter=Array.new if !@prefix.nil? mcfilter << @prefix end if @environment!="" mcfilter << @environment end if @identity!="" mcfilter << @identity end full_filter=mcfilter.join(@delimiter) if full_filter.length>0 full_filter=full_filter+@delimiter end return full_filter end |
#load_mccloud_config ⇒ Object
We put a long name to not clash with any function in the Mccloud file itself
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mccloud/config.rb', line 79 def load_mccloud_config() mccloud_configurator=self begin mccloud_file=File.read(File.join(env.root_path,env.mccloud_file)) env.logger.info("Reading #{mccloud_file}") mccloud_file.gsub!("Mccloud::Config.run","mccloud_configurator.define") # http://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation instance_eval(mccloud_file) rescue LoadError => e raise ::Mccloud::Error, "Error loading configfile - Sorry: #{e.}" rescue NoMethodError => e raise ::Mccloud::Error, "Some method got an error in the configfile - Sorry\n#{$!}\n#{e.}" rescue Errno::ENOENT => e raise ::Mccloud::Error, "You need a Mccloudfile to be able to run mccloud, run mccloud init to create one, #{e}" rescue ::Mccloud::Error => e raise ::Mccloud::Error, "#{e}" rescue Error => e raise ::Mccloud::Error, "Error processing configfile - Sorry" end return self end |
#stackfilter ⇒ Object
103 104 105 106 107 |
# File 'lib/mccloud/config.rb', line 103 def stackfilter vmfilter=self.filter filter=vmfilter.gsub!(/[^[:alnum:]]/, '') return filter end |