Class: DopCommon::Infrastructure

Inherits:
Object
  • Object
show all
Includes:
HashParser, RunOptions, Validator
Defined in:
lib/dop_common/infrastructure.rb

Constant Summary collapse

VALID_PROVIDER_TYPES =
[:baremetal, :openstack, :ovirt, :vsphere]
VALID_PROVIDER_ALIASES =
{
  :rhev => :ovirt,
  :rhevm => :ovirt,
  :rhos => :openstack,
  :vmware => :vsphere
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RunOptions

#canary_host, #max_in_flight, #max_per_role, #valitdate_shared_options

Methods included from Validator

#log_validation_method, #set_not_valid, #try_validate_obj, #valid?

Methods included from HashParser

deep_symbolize_keys, hash_of_pattern_lists_valid?, is_valid_regexp?, key_aliases, load_content, load_content_valid?, parse_hash_of_pattern_lists, parse_pattern_list, pattern_list_valid?, represents_regexp?, symbolize_keys

Constructor Details

#initialize(name, hash, parent = {}) ⇒ Infrastructure

Returns a new instance of Infrastructure.



24
25
26
27
28
# File 'lib/dop_common/infrastructure.rb', line 24

def initialize(name, hash, parent={})
  @name = name
  @hash = symbolize_keys(hash)
  @parsed_credentials = parent[:parsed_credentials]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/dop_common/infrastructure.rb', line 13

def name
  @name
end

Instance Method Details

#affinity_groupsObject



66
67
68
# File 'lib/dop_common/infrastructure.rb', line 66

def affinity_groups
  @affinity_groups ||= affinity_groups_valid? ? create_affinity_groups : []
end

#credentialsObject



58
59
60
# File 'lib/dop_common/infrastructure.rb', line 58

def credentials
  @credentials ||= credentials_valid? ? create_credentials : nil
end

#default_security_groupsObject



70
71
72
# File 'lib/dop_common/infrastructure.rb', line 70

def default_security_groups
  @defalut_security_groups ||= default_security_groups_valid? ? create_default_security_groups : []
end

#endpointObject



54
55
56
# File 'lib/dop_common/infrastructure.rb', line 54

def endpoint
  @endpoint ||= endpoint_valid? ? create_endpoint : nil
end

#networksObject



62
63
64
# File 'lib/dop_common/infrastructure.rb', line 62

def networks
  @networks ||= networks_valid? ? create_networks : []
end

#providerObject Also known as: type



41
42
43
# File 'lib/dop_common/infrastructure.rb', line 41

def provider
  @provider ||= provider_valid? ? @hash[:type].downcase.to_sym : nil
end

#provides?(*t) ⇒ Boolean Also known as: type?

Returns:

  • (Boolean)


46
47
48
49
50
51
# File 'lib/dop_common/infrastructure.rb', line 46

def provides?(*t)
  t.any? do |p|
    p = p.downcase.to_sym if p.kind_of?(String)
    p == provider || p == VALID_PROVIDER_ALIASES[provider]
  end
end

#validateObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/dop_common/infrastructure.rb', line 30

def validate
  valitdate_shared_options
  log_validation_method(:provider_valid?)
  log_validation_method(:endpoint_valid?)
  log_validation_method(:networks_valid?)
  log_validation_method(:affinity_groups_valid?)
  log_validation_method(:credentials_valid?)
  try_validate_obj("Infrastructure #{name}: Can't validate the networks part because of a previous error") { networks }
  try_validate_obj("Infrastructure #{name}: Can't validate the affinity groups part because of a previous error") { affinity_groups }
end