Class: Elevage::Platform
- Inherits:
-
Object
- Object
- Elevage::Platform
- Defined in:
- lib/elevage/platform.rb
Overview
Platform class
Instance Attribute Summary collapse
-
#components ⇒ Object
Returns the value of attribute components.
-
#compute ⇒ Object
Returns the value of attribute compute.
-
#description ⇒ Object
Returns the value of attribute description.
-
#environments ⇒ Object
Returns the value of attribute environments.
-
#name ⇒ Object
Returns the value of attribute name.
-
#network ⇒ Object
Returns the value of attribute network.
-
#nodenameconvention ⇒ Object
Returns the value of attribute nodenameconvention.
-
#pools ⇒ Object
Returns the value of attribute pools.
-
#tiers ⇒ Object
Returns the value of attribute tiers.
-
#vcenter ⇒ Object
Returns the value of attribute vcenter.
Instance Method Summary collapse
-
#healthy? ⇒ Boolean
rubocop:disable MethodLength, LineLength, CyclomaticComplexity, PerceivedComplexity, AmbiguousOperator.
-
#initialize ⇒ Platform
constructor
rubocop:disable MethodLength.
Constructor Details
#initialize ⇒ Platform
rubocop:disable MethodLength
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/elevage/platform.rb', line 20 def initialize fail unless platform_files_exists? platform = YAML.load_file(YML_PLATFORM).fetch('platform') @name = platform['name'] @description = platform['description'] @environments = platform['environments'] @tiers = platform['tiers'] @nodenameconvention = platform['nodenameconvention'] @pools = platform['pools'] @components = platform['components'] @vcenter = YAML.load_file(YML_VCENTER).fetch('vcenter') @network = YAML.load_file(YML_NETWORK).fetch('network') @compute = YAML.load_file(YML_COMPUTE).fetch('compute') end |
Instance Attribute Details
#components ⇒ Object
Returns the value of attribute components.
14 15 16 |
# File 'lib/elevage/platform.rb', line 14 def components @components end |
#compute ⇒ Object
Returns the value of attribute compute.
17 18 19 |
# File 'lib/elevage/platform.rb', line 17 def compute @compute end |
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/elevage/platform.rb', line 9 def description @description end |
#environments ⇒ Object
Returns the value of attribute environments.
10 11 12 |
# File 'lib/elevage/platform.rb', line 10 def environments @environments end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/elevage/platform.rb', line 9 def name @name end |
#network ⇒ Object
Returns the value of attribute network.
16 17 18 |
# File 'lib/elevage/platform.rb', line 16 def network @network end |
#nodenameconvention ⇒ Object
Returns the value of attribute nodenameconvention.
12 13 14 |
# File 'lib/elevage/platform.rb', line 12 def nodenameconvention @nodenameconvention end |
#pools ⇒ Object
Returns the value of attribute pools.
13 14 15 |
# File 'lib/elevage/platform.rb', line 13 def pools @pools end |
#tiers ⇒ Object
Returns the value of attribute tiers.
11 12 13 |
# File 'lib/elevage/platform.rb', line 11 def tiers @tiers end |
#vcenter ⇒ Object
Returns the value of attribute vcenter.
15 16 17 |
# File 'lib/elevage/platform.rb', line 15 def vcenter @vcenter end |
Instance Method Details
#healthy? ⇒ Boolean
rubocop:disable MethodLength, LineLength, CyclomaticComplexity, PerceivedComplexity, AmbiguousOperator
37 38 39 40 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 77 78 79 80 81 82 83 |
# File 'lib/elevage/platform.rb', line 37 def healthy? health = '' # Array of string checked for empty values health += MSG[:empty_environments] unless @environments.all? health += MSG[:empty_tiers] unless @tiers.all? health += MSG[:empty_nodenameconvention] unless @nodenameconvention.all? # Loop through all pool definitions, check for valid settings @pools.each do |_pool, v| health += MSG[:pool_count_size] unless (0..POOL_LIMIT).member?(v['count']) health += MSG[:invalid_tiers] unless @tiers.include?(v['tier']) health += MSG[:no_image_ref] if v['image'].nil? health += MSG[:invalid_compute] unless @compute.key?(v['compute']) health += MSG[:invalid_port] if v['port'].nil? health += MSG[:invalid_runlist] unless v['runlist'].all? health += MSG[:invalid_componentrole] unless v['componentrole'].include?('#') if v['componentrole'] end # Loop through all vcenter definitions, check for valid settings @vcenter.each do |_vcenter, v| health += MSG[:invalid_geo] if v['geo'].nil? health += MSG[:invalid_timezone] unless (0..TIMEZONE_LIMIT).member?(v['timezone'].to_i) health += MSG[:invalid_host] if v['host'].nil? health += MSG[:invalid_datacenter] if v['datacenter'].nil? health += MSG[:invalid_imagefolder] if v['imagefolder'].nil? health += MSG[:invalid_destfolder] if v['destfolder'].nil? health += MSG[:invalid_appendenv] unless v['appendenv'] == true || v['appendenv'] == false health += MSG[:invalid_appenddomain] unless v['appenddomain'] == true || v['appenddomain'] == false health += MSG[:empty_datastores] unless v['datastores'].all? health += MSG[:invalid_domain] if v['domain'].nil? v['dnsips'].each { |ip| health += MSG[:invalid_ip] unless Resolv::IPv4::Regex.match(ip) } end # Loop through all network definitions, check for valid settings @network.each do |_network, v| health += MSG[:empty_network] if v.values.any? &:nil? health += MSG[:invalid_gateway] unless Resolv::IPv4::Regex.match(v['gateway']) end # Loop through all compute definitions, check for valid settings @compute.each do |_compute, v| health += MSG[:invalid_cpu] unless (0..CPU_LIMIT).member?(v['cpu']) health += MSG[:invalid_ram] unless (0..RAM_LIMIT).member?(v['ram']) end if health.length > 0 puts health + "\n#{health.lines.count} platform offense(s) detected" false else true end end |