Class: OodCore::Cluster
- Inherits:
-
Object
- Object
- OodCore::Cluster
- Defined in:
- lib/ood_core/cluster.rb
Overview
An object that describes a cluster and its given features that third-party code can take advantage of.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#acls_config ⇒ Hash
readonly
The acls configuration describing the permissions for this cluster.
-
#errors ⇒ Object
readonly
The errors encountered with configuring this cluster.
-
#id ⇒ Symbol
readonly
The unique identifier for a given cluster.
-
#job_config ⇒ Hash
readonly
The job adapter configuration used for this cluster.
-
#login_config ⇒ Hash
readonly
The login configuration used for this cluster.
-
#metadata_config ⇒ Hash
readonly
Metadata configuration providing descriptive information about cluster.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
The comparison operator.
-
#acls ⇒ Array<Acl::Adapter>
Build the ACL adapters from the ACL list configuration.
-
#allow? ⇒ Boolean
Whether this cluster is allowed to be used.
-
#batch_connect_config(template = nil) ⇒ Hash
The batch connect template configuration used for this cluster.
-
#batch_connect_ssh_allow? ⇒ Boolean?
Whether this cluster supports SSH to batch connect nodes.
-
#batch_connect_template(context = {}) ⇒ BatchConnect::Template
Build a batch connect template from the respective configuration.
-
#custom_allow?(feature) ⇒ Boolean
Whether the custom feature is allowed based on the ACLs.
-
#custom_config(feature = nil) ⇒ Hash
The configuration for any custom features or resources for this cluster.
-
#initialize(cluster) ⇒ Cluster
constructor
A new instance of Cluster.
-
#job_adapter ⇒ Job::Adapter
Build a job adapter from the job configuration.
-
#job_allow? ⇒ Boolean
Whether the job feature is allowed based on the ACLs.
-
#login ⇒ OpenStruct
The login used for this cluster.
-
#login_allow? ⇒ Boolean
Whether the login feature is allowed.
-
#metadata ⇒ OpenStruct
Metadata that provides extra information about this cluster.
- #title ⇒ Object
-
#to_h ⇒ Hash
Convert object to hash.
-
#to_sym ⇒ Symbol
Convert object to symbol.
-
#valid? ⇒ Boolean
This cluster is always valid.
Constructor Details
#initialize(cluster) ⇒ Cluster
Returns a new instance of Cluster.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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 |
Instance Attribute Details
#acls_config ⇒ Hash (readonly)
The acls configuration describing the permissions for this cluster
29 30 31 |
# File 'lib/ood_core/cluster.rb', line 29 def acls_config @acls_config end |
#errors ⇒ Object (readonly)
The errors encountered with configuring this cluster
33 34 35 |
# File 'lib/ood_core/cluster.rb', line 33 def errors @errors end |
#id ⇒ Symbol (readonly)
The unique identifier for a given cluster
13 14 15 |
# File 'lib/ood_core/cluster.rb', line 13 def id @id end |
#job_config ⇒ Hash (readonly)
The job adapter configuration used for this cluster
25 26 27 |
# File 'lib/ood_core/cluster.rb', line 25 def job_config @job_config end |
#login_config ⇒ Hash (readonly)
The login configuration used for this cluster
21 22 23 |
# File 'lib/ood_core/cluster.rb', line 21 def login_config @login_config end |
#metadata_config ⇒ Hash (readonly)
Metadata configuration providing descriptive information about cluster
17 18 19 |
# File 'lib/ood_core/cluster.rb', line 17 def @metadata_config end |
Instance Method Details
#==(other) ⇒ Boolean
The comparison operator
186 187 188 |
# File 'lib/ood_core/cluster.rb', line 186 def ==(other) (other) ? id == other.to_sym : false end |
#acls ⇒ Array<Acl::Adapter>
Build the ACL adapters from the ACL list configuration
162 163 164 |
# File 'lib/ood_core/cluster.rb', line 162 def acls build_acls acls_config end |
#allow? ⇒ Boolean
Whether this cluster is allowed to be used
168 169 170 171 172 |
# File 'lib/ood_core/cluster.rb', line 168 def allow? return @allow if defined?(@allow) @allow = acls.all?(&:allow?) end |
#batch_connect_config(template = nil) ⇒ Hash
The batch connect template configuration used for this cluster
129 130 131 132 133 134 135 |
# File 'lib/ood_core/cluster.rb', line 129 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? ⇒ Boolean?
Whether this cluster supports SSH to batch connect nodes
176 177 178 179 180 181 |
# File 'lib/ood_core/cluster.rb', line 176 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 = {}) ⇒ BatchConnect::Template
Build a batch connect template from the respective configuration
140 141 142 143 |
# File 'lib/ood_core/cluster.rb', line 140 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) ⇒ Boolean
Whether the custom feature is allowed based on the ACLs
154 155 156 157 158 |
# File 'lib/ood_core/cluster.rb', line 154 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) ⇒ Hash
The configuration for any custom features or resources for this cluster
148 149 150 |
# File 'lib/ood_core/cluster.rb', line 148 def custom_config(feature = nil) feature ? @custom_config.fetch(feature.to_sym, {}).to_h.symbolize_keys : @custom_config end |
#job_adapter ⇒ Job::Adapter
Build a job adapter from the job configuration
112 113 114 |
# File 'lib/ood_core/cluster.rb', line 112 def job_adapter Job::Factory.build(job_config) end |
#job_allow? ⇒ Boolean
Whether the job feature is allowed based on the ACLs
118 119 120 121 122 123 124 |
# File 'lib/ood_core/cluster.rb', line 118 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 ⇒ OpenStruct
The login used for this cluster
98 99 100 |
# File 'lib/ood_core/cluster.rb', line 98 def login OpenStruct.new(login_config) end |
#login_allow? ⇒ Boolean
Whether the login feature is allowed
104 105 106 107 108 |
# File 'lib/ood_core/cluster.rb', line 104 def login_allow? return @login_allow if defined?(@login_allow) @login_allow = (allow? && !login_config.empty?) end |
#metadata ⇒ OpenStruct
Metadata that provides extra information about this cluster
92 93 94 |
# File 'lib/ood_core/cluster.rb', line 92 def OpenStruct.new end |
#title ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/ood_core/cluster.rb', line 80 def title if !.title.nil? .title elsif id.to_s.respond_to?(:titleize) id.to_s.titleize else id.to_s end end |
#to_h ⇒ Hash
Convert object to hash
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/ood_core/cluster.rb', line 198 def to_h { id: id, metadata: , login: login_config, job: job_config, custom: custom_config, acls: acls_config, batch_connect: batch_connect_config } end |
#to_sym ⇒ Symbol
Convert object to symbol
192 193 194 |
# File 'lib/ood_core/cluster.rb', line 192 def to_sym id end |
#valid? ⇒ Boolean
This cluster is always valid
212 213 214 |
# File 'lib/ood_core/cluster.rb', line 212 def valid? return true end |