Class: Elevage::Environment
- Inherits:
-
Object
- Object
- Elevage::Environment
- Defined in:
- lib/elevage/environment.rb
Overview
Environment class
Instance Attribute Summary collapse
-
#components ⇒ Object
Returns the value of attribute components.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nodenameconvention ⇒ Object
Returns the value of attribute nodenameconvention.
-
#vcenter ⇒ Object
Returns the value of attribute vcenter.
Instance Method Summary collapse
-
#healthy? ⇒ Boolean
Is the environment healthy?.
-
#initialize(env) ⇒ Elevage::Environment
constructor
Construct a new environment object.
-
#list_nodes ⇒ String
List the nodes for this environment.
-
#provision(type: :all, tier: nil, component: nil, instance: nil, options: nil) ⇒ Object
Public: method to request provisioning of all or a portion of the environment.
-
#to_s ⇒ String
Override to string-ify the environment.
Constructor Details
#initialize(env) ⇒ Elevage::Environment
Construct a new environment object.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/elevage/environment.rb', line 24 def initialize(env) # Confirm environment has been defined in the platform platform = Elevage::Platform.new fail(IOError, ERR[:env_not_defined]) unless platform.environments.include?(env) # Confirm environment file exists envfile = ENV_FOLDER + env.to_s + '.yml' fail(IOError, ERR[:no_env_file]) unless env_file_exists?(envfile) # Build environment hash from environment and platform defintion files environment = build_env(env, YAML.load_file(envfile).fetch('environment'), platform) # Populate class variables @name = env @vcenter = environment['vcenter'] @components = environment['components'] @nodenameconvention = platform.nodenameconvention end |
Instance Attribute Details
#components ⇒ Object
Returns the value of attribute components.
16 17 18 |
# File 'lib/elevage/environment.rb', line 16 def components @components end |
#name ⇒ Object
Returns the value of attribute name.
14 15 16 |
# File 'lib/elevage/environment.rb', line 14 def name @name end |
#nodenameconvention ⇒ Object
Returns the value of attribute nodenameconvention.
17 18 19 |
# File 'lib/elevage/environment.rb', line 17 def nodenameconvention @nodenameconvention end |
#vcenter ⇒ Object
Returns the value of attribute vcenter.
15 16 17 |
# File 'lib/elevage/environment.rb', line 15 def vcenter @vcenter end |
Instance Method Details
#healthy? ⇒ Boolean
Is the environment healthy?
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/elevage/environment.rb', line 60 def healthy? platform = Elevage::Platform.new health = '' health += MSG[:invalid_env_vcenter] if @vcenter.nil? @components.each do |component, v| health += MSG[:invalid_env_network] if v['network'].nil? health += MSG[:invalid_env_count] unless (0..POOL_LIMIT).member?(v['count']) health += MSG[:invalid_env_compute] if v['compute'].nil? health += MSG[:invalid_env_ip] if v['count'] != v['addresses'].size if v['addresses'].nil? health += MSG[:invalid_env_ip] else v['addresses'].each { |ip| health += MSG[:invalid_env_ip] unless Resolv::IPv4::Regex.match(ip) } end health += MSG[:invalid_env_tier] unless platform.tiers.include?(v['tier']) health += MSG[:invalid_env_image] if v['image'].nil? health += MSG[:invalid_env_port] unless v['port'].is_a?(Integer) || v['port'].nil? health += MSG[:invalid_env_runlist] if v['runlist'].nil? || v['runlist'].empty? health += MSG[:invalid_env_componentrole] unless v['componentrole'].include?('#') if v['componentrole'] health += MSG[:env_component_mismatch] unless platform.components.include?(component) end health += MSG[:env_component_mismatch] unless platform.components.size == @components.size if health.length > 0 puts health + "\n#{health.lines.count} environment offense(s) detected" false else true end end |
#list_nodes ⇒ String
List the nodes for this environment. Returns multiline string = IP, fqdn, runlist
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elevage/environment.rb', line 44 def list_nodes nodes = @vcenter['destfolder'].to_s + "\n" @components.each do |component, _config| (1..@components[component]['count']).each do |i| nodes += @components[component]['addresses'][i - 1].ljust(18, ' ') + node_name(component, i) + @vcenter['domain'] + ' ' + @components[component]['runlist'].to_s + "\n" end end nodes end |
#provision(type: :all, tier: nil, component: nil, instance: nil, options: nil) ⇒ Object
Public: method to request provisioning of all or a portion of the environment
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/elevage/environment.rb', line 109 def provision(type: :all, tier: nil, component: nil, instance: nil, options: nil) # Create the ProvisionerRunQueue to batch up our tasks runner = ProvisionerRunQueue.new # Modify behavior for dry-run (no concurrency) if !['dry-run'] runner.max_concurrent = [:concurrency] else puts "Dry run requested, forcing concurrency to '1'." runner.max_concurrent = 1 end @components.each do |component_name, component_data| next unless type.eql?(:all) || component_data['tier'].match(/\A#{tier.to_s}\z/i) || component_name.match(/\A#{component.to_s}\z/i) 1.upto(component_data['addresses'].count) do |component_instance| next unless instance == component_instance || instance.nil? instance_name = node_name(component_name, component_instance) # Create the Provisioner provisioner = Elevage::Provisioner.new(instance_name, component_data, component_instance, self, ) # Add it to the queue runner.provisioners << provisioner end end runner.to_s if ['dry-run'] # Process the queue runner.run end |
#to_s ⇒ String
Override to string-ify the environment
93 94 95 96 97 98 |
# File 'lib/elevage/environment.rb', line 93 def to_s puts @name puts @vcenter.to_yaml puts @components.to_yaml puts @nodenameconvention.to_yaml end |