Class: Elevage::Platform

Inherits:
Object
  • Object
show all
Defined in:
lib/elevage/platform.rb

Overview

Platform class

This represents the overall description of the platform

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeElevage::Platform

Create a new platform object



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

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

#componentsObject

Returns the value of attribute components.



16
17
18
# File 'lib/elevage/platform.rb', line 16

def components
  @components
end

#computeObject

Returns the value of attribute compute.



19
20
21
# File 'lib/elevage/platform.rb', line 19

def compute
  @compute
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/elevage/platform.rb', line 11

def description
  @description
end

#environmentsObject

Returns the value of attribute environments.



12
13
14
# File 'lib/elevage/platform.rb', line 12

def environments
  @environments
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/elevage/platform.rb', line 11

def name
  @name
end

#networkObject

Returns the value of attribute network.



18
19
20
# File 'lib/elevage/platform.rb', line 18

def network
  @network
end

#nodenameconventionObject

Returns the value of attribute nodenameconvention.



14
15
16
# File 'lib/elevage/platform.rb', line 14

def nodenameconvention
  @nodenameconvention
end

#poolsObject

Returns the value of attribute pools.



15
16
17
# File 'lib/elevage/platform.rb', line 15

def pools
  @pools
end

#tiersObject

Returns the value of attribute tiers.



13
14
15
# File 'lib/elevage/platform.rb', line 13

def tiers
  @tiers
end

#vcenterObject

Returns the value of attribute vcenter.



17
18
19
# File 'lib/elevage/platform.rb', line 17

def vcenter
  @vcenter
end

Instance Method Details

#healthy?Boolean

Determine whether the platform definition is considered correct return [Boolean]

Returns:

  • (Boolean)


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
84
85
86
87
88
89
90
91
# File 'lib/elevage/platform.rb', line 45

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] if v['datastore'].nil?
    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