Class: Node
- Inherits:
-
Object
- Object
- Node
- Defined in:
- lib/node_layout.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cloud ⇒ Object
Returns the value of attribute cloud.
-
#id ⇒ Object
Returns the value of attribute id.
-
#roles ⇒ Object
Returns the value of attribute roles.
Instance Method Summary collapse
- #add_db_role(db_type, is_master) ⇒ Object
- #add_rabbitmq_role(is_master) ⇒ Object
- #add_role(role) ⇒ Object
- #errors ⇒ Object
- #expand_roles ⇒ Object
-
#initialize(id, cloud, roles = []) ⇒ Node
constructor
A new instance of Node.
- #valid? ⇒ Boolean
Constructor Details
#initialize(id, cloud, roles = []) ⇒ Node
Returns a new instance of Node.
556 557 558 559 560 561 562 563 564 |
# File 'lib/node_layout.rb', line 556 def initialize id, cloud, roles=[] # For Xen/KVM id is the public ip address # For clouds, id is node-X since the ip is not known @id = id @cloud = cloud @roles = roles.map { |r| r.to_sym } end |
Instance Attribute Details
#cloud ⇒ Object
Returns the value of attribute cloud.
554 555 556 |
# File 'lib/node_layout.rb', line 554 def cloud @cloud end |
#id ⇒ Object
Returns the value of attribute id.
554 555 556 |
# File 'lib/node_layout.rb', line 554 def id @id end |
#roles ⇒ Object
Returns the value of attribute roles.
554 555 556 |
# File 'lib/node_layout.rb', line 554 def roles @roles end |
Instance Method Details
#add_db_role(db_type, is_master) ⇒ Object
566 567 568 569 570 571 572 573 |
# File 'lib/node_layout.rb', line 566 def add_db_role db_type, is_master if is_master add_role :db_master add_role :zookeeper else add_role :db_slave end end |
#add_rabbitmq_role(is_master) ⇒ Object
575 576 577 578 579 580 581 |
# File 'lib/node_layout.rb', line 575 def add_rabbitmq_role is_master if is_master add_role :rabbitmq_master else add_role :rabbitmq_slave end end |
#add_role(role) ⇒ Object
583 584 585 586 |
# File 'lib/node_layout.rb', line 583 def add_role role @roles << role.to_sym end |
#errors ⇒ Object
599 600 601 |
# File 'lib/node_layout.rb', line 599 def errors @roles.map { |r| "Invalid role: #{r}" if !VALID_ROLES.include?(r) }.compact end |
#expand_roles ⇒ Object
603 604 605 606 607 |
# File 'lib/node_layout.rb', line 603 def error_msg = "Expand roles should never be called on a node type." + \ " All nodes should be either a SimpleNode or AdvancedNode" raise RuntimeError error_msg end |
#valid? ⇒ Boolean
595 596 597 |
# File 'lib/node_layout.rb', line 595 def valid? self.errors.empty? end |