Class: Bim::Action::Snat

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

Overview

Snat class uses by Bim::Subcommands::Node

Constant Summary collapse

SNAT_PATH =
'/mgmt/tm/ltm/snat'.freeze
SNAT_URI =
URI.join(Bim::BASE_URL, Bim::Action::Snat::SNAT_PATH)

Constants included from Util

Util::VS_PATH

Class Method Summary collapse

Class Method Details

.add_address(name, addresses) ⇒ Object



52
53
54
55
56
# File 'lib/bim/action/snat.rb', line 52

def add_address(name, addresses)
  origins = specify_link_by_name(SNAT_URI, name, %(origins))
  j = { 'origins': origins.push(addresses.map { |address| { 'name': address } }).flatten }
  self_patch(name, SNAT_URI, j.to_json)
end

.create(name, translation, address_list, vlans) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bim/action/snat.rb', line 26

def create(name, translation, address_list, vlans)
  j = {
    'name': name,
    'translation': translation,
    'origins': address_list.map { |address| { 'name': address } }
  }
  unless vlans.nil?
    j['vlansEnabled'] = true
    j['vlans'] = vlans.map { |vlan| "/Common/#{vlan}" }
  end
  post(SNAT_URI, j.to_json)
end

.detail(name) ⇒ Object



22
23
24
# File 'lib/bim/action/snat.rb', line 22

def detail(name)
  specify(SNAT_URI) { |d| d['name'] == name }
end

.lsObject



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

def ls
  map(SNAT_URI) do |item|
    {
      'name': item['name'],
      'translation': item['translation'],
      'address_list': item['origins'].map { |origin| origin['name'] },
      'vlans': item['vlans']
    }
  end
end

.remove_address(name, addresses) ⇒ Object



58
59
60
61
62
# File 'lib/bim/action/snat.rb', line 58

def remove_address(name, addresses)
  origins = specify_link_by_name(SNAT_URI, name, %(origins))
  j = { 'origins': (origins.map { |origin| origin['name'] } - addresses).map { |address| { 'name': address } } }
  self_patch(name, SNAT_URI, j.to_json)
end

.update(name, translation, address_list, vlans) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bim/action/snat.rb', line 39

def update(name, translation, address_list, vlans)
  j = {}
  if address_list
    j['origins'] = address_list.map { |address| { 'name': address } }
  end
  j['translation'] = translation if translation
  unless vlans.nil?
    j['vlansEnabled'] = true
    j['vlans'] = vlans.map { |vlan| "/Common/#{vlan}" }
  end
  self_patch(name, SNAT_URI, j.to_json)
end