Class: Bim::Action::Pool

Inherits:
Object
  • Object
show all
Extended by:
Util
Defined in:
lib/bim/action/pool.rb

Overview

Node class uses by Bim::Subcommands::Node

Constant Summary collapse

POOL_PATH =
'/mgmt/tm/ltm/pool'.freeze
POOL_URI =
URI.join(Bim::BASE_URL, Bim::Action::Pool::POOL_PATH)

Constants included from Util

Util::VS_PATH

Class Method Summary collapse

Class Method Details

.add_members(name, members) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/bim/action/pool.rb', line 72

def add_members(name, members)
  members_link = specify_link(POOL_URI, %w[membersReference link]) do |item|
    item['name'] == name
  end

  add_members = []

  members.each do |member|
    if post(URI(sub_localhost(members_link)), { 'name': member }.to_json, false).code == '200'
      add_members.push(member)
    end
  end

  { 'add_members': add_members }
end

.create(name, monitor, slow_ramp_time, members) ⇒ Object



21
22
23
24
25
# File 'lib/bim/action/pool.rb', line 21

def create(name, monitor, slow_ramp_time, members)
  j = { 'name' => name, 'monitor' => monitor, 'slowRampTime' => slow_ramp_time }
  j['members'] = JSON.parse(members.delete('\\')) unless members.nil?
  post(POOL_URI, j.to_json)
end

.disable(name, members) ⇒ Object



48
49
50
# File 'lib/bim/action/pool.rb', line 48

def disable(name, members)
  { 'disabled_members': change_session(name, members, 'user-disabled') }
end

.drop_members(name, members) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bim/action/pool.rb', line 52

def drop_members(name, members)
  members_link = specify_link(POOL_URI, %w[membersReference link]) do |item|
    item['name'] == name
  end

  drop_members = []

  cond = proc { |item| members.include?(item['name']) }
  JSON.parse(select_map(URI(sub_localhost(members_link)), cond) do |item|
    { 'name': item['name'], 'self_link': sub_localhost(item['selfLink']) }
  end).each do |item|
    next unless yes_or_no?("drop #{item['name']} from #{name}? [y|n]")
    uri = URI.parse(item['self_link'])
    req = request(uri, Bim::AUTH, 'application/json', 'DELETE')
    drop_members.push(item['name']) if http(uri).request(req).code == '200'
  end

  { 'drop_members': drop_members }
end

.enable(name, members) ⇒ Object



44
45
46
# File 'lib/bim/action/pool.rb', line 44

def enable(name, members)
  { 'enabled_members': change_session(name, members, 'user-enabled') }
end

.lsObject



11
12
13
14
15
16
17
18
19
# File 'lib/bim/action/pool.rb', line 11

def ls
  map(POOL_URI) do |item|
    r = { name: item['name'] }
    r['members'] = JSON.parse(map(URI(sub_localhost(item['membersReference']['link']))) do |in_item|
      { name: in_item['name'], address: in_item['address'] }
    end)
    r
  end
end

.members(name) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/bim/action/pool.rb', line 35

def members(name)
  cond = proc { |item| name == item['name'] }
  select_map(POOL_URI, cond) do |item|
    JSON.parse(map(URI(sub_localhost(item['membersReference']['link']))) do |in_item|
      { name: in_item['name'], address: in_item['address'] }
    end)
  end
end

.update(name, monitor, slow_ramp_time, members) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/bim/action/pool.rb', line 27

def update(name, monitor, slow_ramp_time, members)
  uri = URI(sub_localhost(specify_link_by_name(POOL_URI, name)))
  j = { 'name' => name, 'monitor' => monitor, 'slowRampTime' => slow_ramp_time }
  j['members'] = JSON.parse(members.delete('\\')) unless members.nil?
  req = request(uri, Bim::AUTH, 'application/json', 'PATCH', j.to_json)
  http(uri).request(req).body
end