Class: Bosh::Consul::Models::Cluster
- Inherits:
-
Object
- Object
- Bosh::Consul::Models::Cluster
- Defined in:
- lib/bosh/consul/models/cluster.rb
Instance Attribute Summary collapse
-
#director_client ⇒ Object
readonly
Returns the value of attribute director_client.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#leader ⇒ Object
readonly
Returns the value of attribute leader.
-
#peers ⇒ Object
readonly
Returns the value of attribute peers.
Instance Method Summary collapse
-
#discover_from_ips(ips) ⇒ Object
Discover the consul cluster from the IPs of servers or clients to the cluster Setups up @leader & @peers IP addresses.
-
#initialize(director_client) ⇒ Cluster
constructor
A new instance of Cluster.
- #load_from_agent(leader_ip) ⇒ Object
-
#load_from_deployment_name(deployment_name) ⇒ Object
A [re-]initialization method to get IPs for a cluster.
- #valid? ⇒ Boolean
Constructor Details
#initialize(director_client) ⇒ Cluster
Returns a new instance of Cluster.
5 6 7 8 9 10 |
# File 'lib/bosh/consul/models/cluster.rb', line 5 def initialize(director_client) @director_client = director_client # FIXME: waiting on an API endpoint to discover the domain @domain = "consul" end |
Instance Attribute Details
#director_client ⇒ Object (readonly)
Returns the value of attribute director_client.
2 3 4 |
# File 'lib/bosh/consul/models/cluster.rb', line 2 def director_client @director_client end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
3 4 5 |
# File 'lib/bosh/consul/models/cluster.rb', line 3 def domain @domain end |
#leader ⇒ Object (readonly)
Returns the value of attribute leader.
3 4 5 |
# File 'lib/bosh/consul/models/cluster.rb', line 3 def leader @leader end |
#peers ⇒ Object (readonly)
Returns the value of attribute peers.
3 4 5 |
# File 'lib/bosh/consul/models/cluster.rb', line 3 def peers @peers end |
Instance Method Details
#discover_from_ips(ips) ⇒ Object
Discover the consul cluster from the IPs of servers or clients to the cluster Setups up @leader & @peers IP addresses
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bosh/consul/models/cluster.rb', line 29 def discover_from_ips(ips) ip = ips.first if @leader = get(ip, "/v1/status/leader") @leader =~ /"(.*):(\d+)"/ @leader, @cluster_port = $1, $2 @peers = JSON.parse(get(ip, "/v1/status/peers")) @peers.map! do |peer| peer =~ /(.*):(\d+)/ $1 end end end |
#load_from_agent(leader_ip) ⇒ Object
22 23 24 25 |
# File 'lib/bosh/consul/models/cluster.rb', line 22 def load_from_agent(leader_ip) @leader = @peers = nil discover_from_ips([leader_ip]) end |
#load_from_deployment_name(deployment_name) ⇒ Object
A [re-]initialization method to get IPs for a cluster
13 14 15 16 17 18 19 20 |
# File 'lib/bosh/consul/models/cluster.rb', line 13 def load_from_deployment_name(deployment_name) @leader = @peers = nil # fetch_vm_state raises error if name invalid vms = director_client.fetch_vm_state(deployment_name) deployment_ips = vms.map {|vm| vm["ips"].first } discover_from_ips(deployment_ips) end |
#valid? ⇒ Boolean
42 43 44 |
# File 'lib/bosh/consul/models/cluster.rb', line 42 def valid? @leader end |