class DopCommon::Infrastructure

Constants

VALID_PROVIDER_ALIASES
VALID_PROVIDER_TYPES

Attributes

name[R]

Public Class Methods

new(name, hash, parent={}) click to toggle source
# 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

Public Instance Methods

affinity_groups() click to toggle source
# File lib/dop_common/infrastructure.rb, line 66
def affinity_groups
  @affinity_groups ||= affinity_groups_valid? ? create_affinity_groups : []
end
credentials() click to toggle source
# File lib/dop_common/infrastructure.rb, line 58
def credentials
  @credentials ||= credentials_valid? ? create_credentials : nil
end
default_security_groups() click to toggle source
# File lib/dop_common/infrastructure.rb, line 70
def default_security_groups
  @defalut_security_groups ||= default_security_groups_valid? ? create_default_security_groups : []
end
endpoint() click to toggle source
# File lib/dop_common/infrastructure.rb, line 54
def endpoint
  @endpoint ||= endpoint_valid? ? create_endpoint : nil
end
networks() click to toggle source
# File lib/dop_common/infrastructure.rb, line 62
def networks
  @networks ||= networks_valid? ? create_networks : []
end
provider() click to toggle source
# File lib/dop_common/infrastructure.rb, line 41
def provider
  @provider ||= provider_valid? ? @hash[:type].downcase.to_sym : nil
end
Also aliased as: type
provides?(*t) click to toggle source
# 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
Also aliased as: type?
type()
Alias for: provider
type?(*t)
Alias for: provides?
validate() click to toggle source
# 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

Private Instance Methods

affinity_groups_valid?() click to toggle source
# File lib/dop_common/infrastructure.rb, line 122
def affinity_groups_valid?
  return false if @hash[:affinity_groups].nil?
  @hash[:affinity_groups].kind_of?(Hash) or
    raise PlanParsingError, "Infrastructure #{@name}: affinity_groups must be a hash"
  @hash[:affinity_groups].keys.all? { |name| name.kind_of?(String) } or
    raise PlanParsingError, "Infrastructure #{@name}: affinity group names have to be string"
  @hash[:affinity_groups].values.all? { |ag| ag.kind_of?(Hash) } or
    raise PlanParsingError, "Infrastructure #{@name}: affinity groups have to be defined as hash"
end
create_affinity_groups() click to toggle source
# File lib/dop_common/infrastructure.rb, line 152
def create_affinity_groups
  @hash[:affinity_groups].collect { |name,hash| ::DopCommon::AffinityGroup.new(name, hash) }
end
create_credentials() click to toggle source
# File lib/dop_common/infrastructure.rb, line 144
def create_credentials
  @parsed_credentials[@hash[:credentials]]
end
create_default_security_groups() click to toggle source
# File lib/dop_common/infrastructure.rb, line 156
def create_default_security_groups
  @hash[:default_security_groups]
end
create_endpoint() click to toggle source
# File lib/dop_common/infrastructure.rb, line 140
def create_endpoint
  ::URI.parse(@hash[:endpoint])
end
create_networks() click to toggle source
# File lib/dop_common/infrastructure.rb, line 148
def create_networks
  @hash[:networks].collect { |name,hash| ::DopCommon::Network.new(name, hash) }
end
credentials_valid?() click to toggle source
# File lib/dop_common/infrastructure.rb, line 100
def credentials_valid?
  return false if provides?(:baremetal) && @hash[:credentials].nil?
  raise PlanParsingError, "Infrastructure #{@name}: Credentials pointer must be a string" unless
    @hash[:credentials].kind_of?(String)
  raise PlanParsingError, "Infrastructure #{@name}: Missing definition of endpoint credentials" unless
    @parsed_credentials.has_key?(@hash[:credentials])
  true
end
default_security_groups_valid?() click to toggle source
# File lib/dop_common/infrastructure.rb, line 132
def default_security_groups_valid?
  return false if @hash[:default_security_groups].nil?
  @hash[:default_security_groups].kind_of?(Array) or
    raise PlanParsingError, "Infrastructure #{@name}: default_security_groups must be an array"
  @hash[:default_security_groups].all? { |name| name.kind_of?(String) } or
    raise PlanParsingError, "Infrastructure #{@name}: security group names have to be strings"
end
endpoint_valid?() click to toggle source
# File lib/dop_common/infrastructure.rb, line 91
def endpoint_valid?
  return false if provides?(:baremetal) && @hash[:endpoint].nil?
  raise PlanParsingError, "Infrastructure #{@name}: endpoint is a required property" if @hash[:endpoint].nil?
  ::URI.parse(@hash[:endpoint])
  true
rescue URI::InvalidURIError
  raise PlanParsingError, "Infrastructure #{@name}: the specified endpoint URL is invalid"
end
networks_valid?() click to toggle source
# File lib/dop_common/infrastructure.rb, line 109
def networks_valid?
  return false if provides?(:baremetal) && @hash[:networks].nil? # Network is optional for baremetal
  raise PlanParsingError, "Infrastructure #{@name}: network is a required property" if
    !provides?(:baremetal) && @hash[:networks].nil?
  raise PlanParsingError, "Infrastructure #{@name}: networks must be a hash" unless
    @hash[:networks].kind_of?(Hash)
  raise PlanParsingError, "Infrastructure #{@name}: network names have to be string" unless
    @hash[:networks].keys.all? { |name| name.kind_of?(String) }
  raise PlanParsingError, "Infrastructure #{@name}: each network has to be defined as hash" unless
  @hash[:networks].values.all? { |network| network.kind_of?(Hash) }
  true
end
provider_valid?() click to toggle source
# File lib/dop_common/infrastructure.rb, line 76
def provider_valid?
  case @hash[:type]
  when nil
    raise PlanParsingError, "Infrastructure #{@name}: provider type is a required property"
  when String
    p = @hash[:type].downcase.to_sym
    raise PlanParsingError, "Infrastructure #{@name}: invalid provider type" unless
      VALID_PROVIDER_TYPES.include?(p) || VALID_PROVIDER_ALIASES.keys.include?(p)
  else
    raise PlanParsingError, "Infrastructure #{@name}: provider type must be a string"
  end
  true
end
Also aliased as: type_valid?
type_valid?()
Alias for: provider_valid?