class OodCore::Cluster

An object that describes a cluster and its given features that third-party code can take advantage of.

Attributes

acls_config[R]

The acls configuration describing the permissions for this cluster @return [Hash] the acls configuration

errors[R]

The errors encountered with configuring this cluster @return Array<String> the errors

id[R]

The unique identifier for a given cluster @return [Symbol] the cluster id

job_config[R]

The job adapter configuration used for this cluster @return [Hash] the job configuration

login_config[R]

The login configuration used for this cluster @return [Hash] the login configuration

metadata_config[R]

Metadata configuration providing descriptive information about cluster @return [Hash] the metadata configuration

Public Class Methods

new(cluster) click to toggle source

@param cluster [#to_h] the cluster object @option cluster [#to_sym] :id The cluster id @option cluster [#to_h] :metadata ({}) The cluster's metadata @option cluster [#to_h] :login ({}) The cluster's SSH host @option cluster [#to_h] :job ({}) The job adapter for this cluster @option cluster [#to_h] :custom ({}) Any custom resources for this

cluster

@option cluster [Array<#to_h>] :acls ([]) List of ACLs to validate

against

@option cluster [#to_h] :batch_connect ({}) Configuration for batch

connect templates

@option cluster [#to_a] :errors ([]) List of configuration errors

# File lib/ood_core/cluster.rb, line 48
def initialize(cluster)
  c = cluster.to_h.symbolize_keys

  # Required options
  @id = c.fetch(:id) { raise ArgumentError, "No id specified. Missing argument: id" }.to_sym

  # General options
  @metadata_config = c.fetch(:metadata, {}).to_h.symbolize_keys
  @login_config    = c.fetch(:login, {})   .to_h.symbolize_keys
  @job_config      = c.fetch(:job, {})     .to_h.symbolize_keys
  @custom_config   = c.fetch(:custom, {})  .to_h.symbolize_keys
  @acls_config     = c.fetch(:acls, [])    .map(&:to_h)
  @batch_connect_config = c.fetch(:batch_connect, {}).to_h.symbolize_keys

  # side affects from object creation and validation
  @errors          = c.fetch(:errors, [])  .to_a
end

Public Instance Methods

==(other) click to toggle source

The comparison operator @param other [#to_sym] object to compare against @return [Boolean] whether objects are equivalent

# File lib/ood_core/cluster.rb, line 162
def ==(other)
  (other) ? id == other.to_sym : false
end
acls() click to toggle source

Build the ACL adapters from the ACL list configuration @return [Array<Acl::Adapter>] the acl adapter list

# File lib/ood_core/cluster.rb, line 138
def acls
  build_acls acls_config
end
allow?() click to toggle source

Whether this cluster is allowed to be used @return [Boolean] whether cluster is allowed

# File lib/ood_core/cluster.rb, line 144
def allow?
  return @allow if defined?(@allow)

  @allow = acls.all?(&:allow?)
end
batch_connect_config(template = nil) click to toggle source

The batch connect template configuration used for this cluster @param template [#to_sym, nil] the template type @return [Hash] the batch connect configuration

# File lib/ood_core/cluster.rb, line 105
def batch_connect_config(template = nil)
  if template
    @batch_connect_config.fetch(template.to_sym, {}).to_h.symbolize_keys.merge(template: template.to_sym)
  else
    @batch_connect_config
  end
end
batch_connect_ssh_allow?() click to toggle source

Whether this cluster supports SSH to batch connect nodes @return [Boolean, nil] whether cluster supports SSH to batch connect node

# File lib/ood_core/cluster.rb, line 152
def batch_connect_ssh_allow?
  return @batch_connect_ssh_allow if defined?(@batch_connect_ssh_allow)
  return @batch_connect_ssh_allow = nil if batch_connect_config.nil?

  @batch_connect_ssh_allow = batch_connect_config.fetch(:ssh_allow, nil)
end
batch_connect_template(context = {}) click to toggle source

Build a batch connect template from the respective configuration @param context [#to_h] the context used for rendering the template @return [BatchConnect::Template] the batch connect template

# File lib/ood_core/cluster.rb, line 116
def batch_connect_template(context = {})
  context = context.to_h.symbolize_keys
  BatchConnect::Factory.build batch_connect_config(context[:template] || :basic).merge(context)
end
custom_allow?(feature) click to toggle source

Whether the custom feature is allowed based on the ACLs @return [Boolean] is this custom feature allowed

# File lib/ood_core/cluster.rb, line 130
def custom_allow?(feature)
  allow? &&
    !custom_config(feature).empty? &&
    build_acls(custom_config(feature).fetch(:acls, []).map(&:to_h)).all?(&:allow?)
end
custom_config(feature = nil) click to toggle source

The configuration for any custom features or resources for this cluster @param feature [#to_sym, nil] the feature or resource @return [Hash] configuration for custom feature or resource

# File lib/ood_core/cluster.rb, line 124
def custom_config(feature = nil)
  feature ? @custom_config.fetch(feature.to_sym, {}).to_h.symbolize_keys : @custom_config
end
job_adapter() click to toggle source

Build a job adapter from the job configuration @return [Job::Adapter] the job adapter

# File lib/ood_core/cluster.rb, line 88
def job_adapter
  Job::Factory.build(job_config)
end
job_allow?() click to toggle source

Whether the job feature is allowed based on the ACLs @return [Boolean] is the job feature allowed

# File lib/ood_core/cluster.rb, line 94
def job_allow?
  return @job_allow if defined?(@job_allow)

  @job_allow = (allow? && ! job_config.empty? && build_acls(
    job_config.fetch(:acls, []).map(&:to_h)
  ).all?(&:allow?))
end
login() click to toggle source

The login used for this cluster @return [OpenStruct] the login

# File lib/ood_core/cluster.rb, line 74
def login
  OpenStruct.new(login_config)
end
login_allow?() click to toggle source

Whether the login feature is allowed @return [Boolean] is login allowed

# File lib/ood_core/cluster.rb, line 80
def login_allow?
  return @login_allow if defined?(@login_allow)

  @login_allow = (allow? && !login_config.empty?)
end
metadata() click to toggle source

Metadata that provides extra information about this cluster @return [OpenStruct] the metadata

# File lib/ood_core/cluster.rb, line 68
def metadata
  OpenStruct.new metadata_config
end
to_h() click to toggle source

Convert object to hash @return [Hash] the hash describing this object

# File lib/ood_core/cluster.rb, line 174
def to_h
  {
    id: id,
    metadata: metadata_config,
    login: login_config,
    job: job_config,
    custom: custom_config,
    acls: acls_config,
    batch_connect:  batch_connect_config
  }
end
to_sym() click to toggle source

Convert object to symbol @return [Symbol] the symbol describing this object

# File lib/ood_core/cluster.rb, line 168
def to_sym
  id
end
valid?() click to toggle source

This cluster is always valid @return true

# File lib/ood_core/cluster.rb, line 188
def valid?
  return true
end

Private Instance Methods

build_acls(ary) click to toggle source

Build acl adapter objects from array

# File lib/ood_core/cluster.rb, line 194
def build_acls(ary)
  ary.map { |a| Acl::Factory.build a }
end