Class: LinodeCluster::ClientWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/linode_cluster/client_wrapper.rb

Overview

Client Wrapper class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ClientWrapper

Returns a new instance of ClientWrapper.



6
7
8
# File 'lib/linode_cluster/client_wrapper.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/linode_cluster/client_wrapper.rb', line 4

def client
  @client
end

Instance Method Details

#find_datacenter_by_id(id) ⇒ Object



48
49
50
# File 'lib/linode_cluster/client_wrapper.rb', line 48

def find_datacenter_by_id(id)
  datacenters.find { |d| d.datacenterid == id }
end

#find_datacenter_id(region) ⇒ Object



44
45
46
# File 'lib/linode_cluster/client_wrapper.rb', line 44

def find_datacenter_id(region)
  datacenters.find { |d| d.abbr == region }.datacenterid
end

#find_default_kernelObject



64
65
66
# File 'lib/linode_cluster/client_wrapper.rb', line 64

def find_default_kernel
  kernels.find { |k| k.label.include?('Latest 64') }
end

#find_distribution_id_by_name(name) ⇒ Object



60
61
62
# File 'lib/linode_cluster/client_wrapper.rb', line 60

def find_distribution_id_by_name(name)
  distributions.find { |p| p.label == name }.distributionid
end

#find_node_by_id(id) ⇒ Object



33
34
35
36
37
# File 'lib/linode_cluster/client_wrapper.rb', line 33

def find_node_by_id(id)
  node_by_id = nodes.select { |d| d.linodeid == id }
  raise "Found multiple nodes with id #{id}" if node_by_id.count > 1
  node_by_id.first
end

#find_node_by_name(name) ⇒ Object



27
28
29
30
31
# File 'lib/linode_cluster/client_wrapper.rb', line 27

def find_node_by_name(name)
  node_by_name = nodes.select { |d| d.label == name }
  raise "Found multiple nodes with name #{name}" if node_by_name.count > 1
  node_by_name.first
end

#find_plan_by_id(id) ⇒ Object



56
57
58
# File 'lib/linode_cluster/client_wrapper.rb', line 56

def find_plan_by_id(id)
  plans.find { |p| p.planid == id }
end

#find_plan_id(size) ⇒ Object



52
53
54
# File 'lib/linode_cluster/client_wrapper.rb', line 52

def find_plan_id(size)
  plans.find { |p| p.ram.to_s == size.to_s }.planid
end

#linodeObject



10
11
12
# File 'lib/linode_cluster/client_wrapper.rb', line 10

def linode
  client.linode
end

#nodesObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/linode_cluster/client_wrapper.rb', line 14

def nodes
  @nodes ||= begin
    ip_addresses = client.linode.ip.list
    linodes = client.linode.list

    linodes.map do |l|
      node = Node.new(l, self)
      node.ip_address = ip_addresses.find { |i| i.linodeid == node.linodeid }.ipaddress
      node
    end
  end
end

#refresh_nodesObject



39
40
41
42
# File 'lib/linode_cluster/client_wrapper.rb', line 39

def refresh_nodes
  @nodes = nil
  nodes
end