Class: Mammoth::NodeIdentity
- Inherits:
-
Object
- Object
- Mammoth::NodeIdentity
- Defined in:
- lib/mammoth/node_identity.rb
Overview
Local Mammoth node identity used by status and future control-plane agents.
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#fleet_id ⇒ Object
readonly
Returns the value of attribute fleet_id.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#node_id ⇒ Object
readonly
Returns the value of attribute node_id.
-
#node_name ⇒ Object
readonly
Returns the value of attribute node_name.
Class Method Summary collapse
-
.from_config(config) ⇒ Mammoth::NodeIdentity
Build identity from Mammoth configuration.
Instance Method Summary collapse
-
#initialize(node_id:, node_name:, fleet_id: nil, environment: nil, labels: {}, metadata: {}) ⇒ NodeIdentity
constructor
A new instance of NodeIdentity.
-
#to_h ⇒ Hash
JSON-friendly node identity.
Constructor Details
#initialize(node_id:, node_name:, fleet_id: nil, environment: nil, labels: {}, metadata: {}) ⇒ NodeIdentity
Returns a new instance of NodeIdentity.
16 17 18 19 20 21 22 23 |
# File 'lib/mammoth/node_identity.rb', line 16 def initialize(node_id:, node_name:, fleet_id: nil, environment: nil, labels: {}, metadata: {}) @node_id = node_id @node_name = node_name @fleet_id = fleet_id @environment = environment @labels = labels || {} @metadata = || {} end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
8 9 10 |
# File 'lib/mammoth/node_identity.rb', line 8 def environment @environment end |
#fleet_id ⇒ Object (readonly)
Returns the value of attribute fleet_id.
8 9 10 |
# File 'lib/mammoth/node_identity.rb', line 8 def fleet_id @fleet_id end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
8 9 10 |
# File 'lib/mammoth/node_identity.rb', line 8 def labels @labels end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/mammoth/node_identity.rb', line 8 def @metadata end |
#node_id ⇒ Object (readonly)
Returns the value of attribute node_id.
8 9 10 |
# File 'lib/mammoth/node_identity.rb', line 8 def node_id @node_id end |
#node_name ⇒ Object (readonly)
Returns the value of attribute node_name.
8 9 10 |
# File 'lib/mammoth/node_identity.rb', line 8 def node_name @node_name end |
Class Method Details
.from_config(config) ⇒ Mammoth::NodeIdentity
Build identity from Mammoth configuration.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mammoth/node_identity.rb', line 29 def self.from_config(config) identity = config.data["node"] || {} hostname = Socket.gethostname new( node_id: identity["node_id"] || hostname, node_name: identity["node_name"] || config.dig("mammoth", "name") || hostname, fleet_id: identity["fleet_id"], environment: identity["environment"], labels: identity["labels"] || {}, metadata: identity["metadata"] || {} ) end |
Instance Method Details
#to_h ⇒ Hash
Returns JSON-friendly node identity.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mammoth/node_identity.rb', line 43 def to_h { node_id: node_id, node_name: node_name, fleet_id: fleet_id, environment: environment, labels: labels, metadata: } end |