bim 0.1.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a868333137d0ecaf6d8646b24aa0ac303b3d0ec1
4
- data.tar.gz: 9b295de401c805e2730a6907ca16fd1e9a4c3d3c
3
+ metadata.gz: c6f9989b1a73b84f166b102c06b20f48bffa922f
4
+ data.tar.gz: 485d78106d2ed26cab37cfa6cb4e1cfb9131bd23
5
5
  SHA512:
6
- metadata.gz: b840b0e83780f36af10667eb680d6582c3efdd389a33ce4b4b934e4b61b6e99050d132724b21ae3d478b7e2535835ac89f89a55b96de3d875674fd10787227ca
7
- data.tar.gz: 5757876263d0a08486a8c994343467aa1e712ccabfb59c352d2844ed111c7e328f522497267e0b1ebb4a22d1f0edf9e123924e893ae2c7264c698f61cc199700
6
+ metadata.gz: 9e378820b2071376e3a5353134c9ed16e7f6d1d0c68adb6b5b240bb6434051fea7f1ae0ca4d6e93bbbf51bd0225c62cc4b17d65f658f6fadc1f983d735c6a0d9
7
+ data.tar.gz: 0a8e22881900de573bf0969731351c25d053c431be7af6a1b836083afd2b606f715fff8c74120093cd6fcc7d98bc32baec6a4faed9275fe987dbfc0d41414fe1
data/.rubocop.yml CHANGED
@@ -2,10 +2,12 @@ AllCops:
2
2
  TargetRubyVersion: 2.4
3
3
 
4
4
  Metrics/AbcSize:
5
- Max: 25
5
+ Max: 30
6
6
 
7
7
  Metrics/LineLength:
8
8
  Max: 120
9
+ Exclude:
10
+ - 'lib/bim/subcommands/*'
9
11
 
10
12
  Metrics/ClassLength:
11
13
  Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3
4
+ - 2.4
5
+ before_install:
6
+ - gem install rubocop
7
+ script: rubocop --fail-level=W
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/littlekbt/bim.svg?branch=master)](https://travis-ci.org/littlekbt/bim)
2
+
1
3
  # Bim
2
4
 
3
5
  Bim is cli command to operate BIG-IP.
data/completions/bim.bash CHANGED
@@ -4,10 +4,10 @@ _bim() {
4
4
  _get_comp_words_by_ref -n : cur prev
5
5
 
6
6
  if [ "$COMP_CWORD" -eq 1 ]; then
7
- COMPREPLY=( $(compgen -W "$(bim help | tail -n +2 | awk '{ print $2}')" -- "$cur") )
7
+ COMPREPLY=( $(compgen -W "$(./bin/bim help | tail -n +2 | awk '{ print $2}')" -- "$cur") )
8
8
  elif [ $COMP_CWORD -eq 2 ]; then
9
9
  if [ $prev = "ssl" ] || [ $prev = "meta" ] || [ $prev = "sync" ]; then
10
- COMPREPLY=( $(compgen -W "$(bim $prev help | tail -n +2 | awk '{ print $3}')" -- $cur) )
10
+ COMPREPLY=( $(compgen -W "$(./bin/bim $prev help | tail -n +2 | awk '{ print $3}')" -- $cur) )
11
11
  fi
12
12
  fi
13
13
  }
@@ -0,0 +1,71 @@
1
+ module Bim
2
+ module Action
3
+ # Fw class uses by Bim::Subcommands::Fw
4
+ class Fw
5
+ extend Bim::Util
6
+
7
+ FW_PATH = '/mgmt/tm/security/firewall/policy'.freeze
8
+ FW_URI = URI.join(Bim::BASE_URL, Bim::Action::Fw::FW_PATH)
9
+
10
+ DETAIL_CONF = {
11
+ name: 'firewall_policy',
12
+ items: false,
13
+ attrs: %w[name fullPath],
14
+ under_key: 'rulesReference',
15
+ under_layer: {
16
+ name: 'rules_reference',
17
+ items: true,
18
+ attrs: %w[name description ipProtocol ruleList],
19
+ under_key: 'ruleListReference',
20
+ under_layer: {
21
+ name: 'rule_list_reference',
22
+ items: false,
23
+ attrs: %w[name fullPath],
24
+ under_key: 'rulesReference',
25
+ under_layer: {
26
+ name: 'rules_reference',
27
+ items: true,
28
+ attrs: %w[name description destination source]
29
+ }
30
+ }
31
+ }
32
+ }.freeze
33
+
34
+ class << self
35
+ def ls
36
+ map(FW_URI) do |item|
37
+ { 'item' => item['name'], 'fullPath' => item['fullPath'] }
38
+ end
39
+ end
40
+
41
+ def detail(name)
42
+ start_uri = URI(sub_localhost(specify_link_by_name(FW_URI, name)))
43
+ detail_depth(start_uri, DETAIL_CONF).to_json
44
+ end
45
+
46
+ def detail_depth(uri, conf)
47
+ datas = JSON.parse(get_body(uri))
48
+ if conf[:items]
49
+ datas['items'].map do |data|
50
+ detail_proc.call(data, conf, true)
51
+ end
52
+ else
53
+ detail_proc.call(datas, conf)
54
+ end
55
+ end
56
+
57
+ def detail_proc
58
+ proc do |data, conf, map = false|
59
+ d = {}
60
+ conf[:attrs].each { |attr| d[attr] = data[attr] }
61
+
62
+ (map ? (next d) : (return d)) unless data.key?(conf[:under_key])
63
+ next_uri = URI(sub_localhost(data[conf[:under_key]]['link']))
64
+ d[conf[:under_key]] = detail_depth(next_uri, conf[:under_layer])
65
+ d
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -9,27 +9,21 @@ module Bim
9
9
 
10
10
  class << self
11
11
  def actives
12
- uri = URI.join(Bim::BASE_URL, Bim::Action::Meta::DEVICE_PATH)
13
- JSON
14
- .parse(get_body(uri))['items']
15
- .select { |item| item['failoverState'] == 'active' }
16
- .inject([]) do |infos, item|
17
- infos.push(hostname: item['hostname'], ip: item['managementIp'])
18
- end.to_json
12
+ cond = proc { |item| item['failoverState'] == 'active' }
13
+ select_map(URI.join(Bim::BASE_URL, Bim::Action::Meta::DEVICE_PATH), cond) do |item|
14
+ { hostname: item['hostname'], ip: item['managementIp'] }
15
+ end
19
16
  end
20
17
 
21
18
  def device_groups
22
- uri = URI.join(Bim::BASE_URL, Bim::Action::Meta::DEVICE_GROUP_PATH)
23
- JSON
24
- .parse(get_body(uri))['items']
25
- .select { |item| item['type'] == 'sync-failover' }
26
- .inject([]) do |infos, item|
27
- m = if item&.dig('devicesReference')&.dig('link')
28
- uri_r = URI.parse(item['devicesReference']['link'].sub('localhost', BIGIP_HOST))
29
- JSON.parse(get_body(uri_r))['items'].map { |item_in| item_in['name'] }
30
- end
31
- infos.push(name: item['name'], members: m)
32
- end.to_json
19
+ cond = proc { |item| item['type'] == 'sync-failover' }
20
+ select_map(URI.join(Bim::BASE_URL, Bim::Action::Meta::DEVICE_GROUP_PATH), cond) do |item|
21
+ m = if item&.dig('devicesReference')&.dig('link')
22
+ uri_r = URI.parse(item['devicesReference']['link'].sub('localhost', BIGIP_HOST))
23
+ JSON.parse(get_body(uri_r))['items'].map { |item_in| item_in['name'] }
24
+ end
25
+ { name: item['name'], members: m }
26
+ end
33
27
  end
34
28
  end
35
29
  end
@@ -0,0 +1,41 @@
1
+ module Bim
2
+ module Action
3
+ # Node class uses by Bim::Subcommands::Node
4
+ class Node
5
+ extend Bim::Util
6
+
7
+ NODE_PATH = '/mgmt/tm/ltm/node'.freeze
8
+ NODE_URI = URI.join(Bim::BASE_URL, Bim::Action::Node::NODE_PATH)
9
+
10
+ class << self
11
+ def ls
12
+ map(NODE_URI) do |item|
13
+ { name: item['name'], address: item['address'] }
14
+ end
15
+ end
16
+
17
+ def detail(name)
18
+ specify(NODE_URI) { |d| d['name'] == name }
19
+ end
20
+
21
+ def create(name, address)
22
+ post(
23
+ NODE_URI,
24
+ { 'name' => name, 'address' => address }.to_json
25
+ )
26
+ end
27
+
28
+ def delete(name)
29
+ self_link = JSON.parse(detail(name))&.fetch('selfLink')
30
+ return "not found #{name} node" if self_link.nil?
31
+ return "cancel delete #{name} node" unless yes_or_no?("you want to delete #{name} node? [y|n]")
32
+
33
+ uri = URI(self_link.sub('localhost', Bim::BIGIP_HOST))
34
+ req = request(uri, Bim::AUTH, 'application/json', 'DELETE')
35
+ msg = http(uri).request(req).body
36
+ msg.empty? ? "success delete #{name} node" : msg
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,73 @@
1
+ module Bim
2
+ module Action
3
+ # Node class uses by Bim::Subcommands::Node
4
+ class Pool
5
+ extend Bim::Util
6
+
7
+ POOL_PATH = '/mgmt/tm/ltm/pool'.freeze
8
+ POOL_URI = URI.join(Bim::BASE_URL, Bim::Action::Pool::POOL_PATH)
9
+
10
+ class << self
11
+ def ls
12
+ map(POOL_URI) do |item|
13
+ r = { name: item['name'] }
14
+ r['members'] = JSON.parse(map(URI(sub_localhost(item['membersReference']['link']))) do |in_item|
15
+ { name: in_item['name'], address: in_item['address'] }
16
+ end)
17
+ r
18
+ end
19
+ end
20
+
21
+ def create(name, members = nil)
22
+ j = members ? { 'name' => name, 'members' => JSON.parse(members) } : { 'name' => name }
23
+ post(POOL_URI, j.to_json)
24
+ end
25
+
26
+ def members(name)
27
+ cond = proc { |item| name == item['name'] }
28
+ select_map(POOL_URI, cond) do |item|
29
+ JSON.parse(map(URI(sub_localhost(item['membersReference']['link']))) do |in_item|
30
+ { name: in_item['name'], address: in_item['address'] }
31
+ end)
32
+ end
33
+ end
34
+
35
+ def drop_members(name, members)
36
+ members_link = specify_link(POOL_URI, %w[membersReference link]) do |item|
37
+ item['name'] == name
38
+ end
39
+
40
+ drop_members = []
41
+
42
+ cond = proc { |item| members.include?(item['name']) }
43
+ JSON.parse(select_map(URI(sub_localhost(members_link)), cond) do |item|
44
+ { 'name': item['name'], 'self_link': sub_localhost(item['selfLink']) }
45
+ end).each do |item|
46
+ next unless yes_or_no?("drop #{item['name']} from #{name}? [y|n]")
47
+ uri = URI.parse(item['self_link'])
48
+ req = request(uri, Bim::AUTH, 'application/json', 'DELETE')
49
+ drop_members.push(item['name']) if http(uri).request(req).code == '200'
50
+ end
51
+
52
+ { 'drop_members': drop_members }
53
+ end
54
+
55
+ def add_members(name, members)
56
+ members_link = specify_link(POOL_URI, %w[membersReference link]) do |item|
57
+ item['name'] == name
58
+ end
59
+
60
+ add_members = []
61
+
62
+ members.each do |member|
63
+ if post(URI(sub_localhost(members_link)), { 'name': member }.to_json, false).code == '200'
64
+ add_members.push(member)
65
+ end
66
+ end
67
+
68
+ { 'add_members': add_members }
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -13,33 +13,27 @@ module Bim
13
13
  VS_PATH = '/mgmt/tm/ltm/virtual'.freeze
14
14
  CRT_FILES_PATH = '/mgmt/tm/sys/file/sslCert'.freeze
15
15
  CRT_PROFILES_PATH = '/mgmt/tm/ltm/profile/client-ssl'.freeze
16
+ CRT_FILES_URI = URI.join(Bim::BASE_URL, Bim::Action::SSL::CRT_FILES_PATH)
17
+ CRT_PROFILES_URI = URI.join(Bim::BASE_URL, Bim::Action::SSL::CRT_PROFILES_PATH)
16
18
 
17
19
  class << self
18
20
  def bundles
19
- uri = URI.join(Bim::BASE_URL, Bim::Action::SSL::CRT_FILES_PATH)
20
- JSON
21
- .parse(get_body(uri))['items']
22
- .select { |item| item['isBundle'] == 'true' }
23
- .map do |item|
24
- { 'name' => item['name'].split('.')[0...-1].join('.') }
25
- end.to_json
21
+ cond = proc { |item| item['isBundle'] == 'true' }
22
+ select_map(CRT_FILES_URI, cond) do |item|
23
+ { 'name' => item['name'].split('.')[0...-1].join('.') }
24
+ end
26
25
  end
27
26
 
28
27
  def profiles
29
- uri = URI.join(Bim::BASE_URL, Bim::Action::SSL::CRT_PROFILES_PATH)
30
- JSON.parse(get_body(uri))['items'].map do |item|
28
+ map(CRT_PROFILES_URI) do |item|
31
29
  { 'name' => item['name'], 'fullPath' => item['fullPath'], 'key' => item['key'], 'chain' => item['chain'] }
32
- end.to_json
30
+ end
33
31
  end
34
32
 
35
33
  def detail(profile_name)
36
- uri = URI.join(Bim::BASE_URL, Bim::Action::SSL::CRT_PROFILES_PATH)
37
- JSON
38
- .parse(get_body(uri))['items']
39
- .select { |item| item['name'] == profile_name || item['fullPath'] == profile_name }
40
- .map do |item|
41
- { 'name' => item['name'], 'fullPath' => item['fullPath'], 'key' => item['key'], 'chain' => item['chain'] }
42
- end.to_json
34
+ specify(CRT_PROFILES_URI) do |item|
35
+ item['name'] == profile_name || item['fullPath'] == profile_name
36
+ end
43
37
  end
44
38
 
45
39
  def upload(filepath)
@@ -117,9 +111,7 @@ module Bim
117
111
 
118
112
  def update_profiles(link, names)
119
113
  uri = URI.parse(link.sub('localhost', BIGIP_HOST))
120
- req = request(uri, Bim::AUTH, 'application/json', 'PATCH', { profiles: names }.to_json)
121
-
122
- http(uri).request(req)
114
+ post(uri, { profiles: names }.to_json)
123
115
  end
124
116
 
125
117
  def output_msg(vs_name, old_names, new_names)
@@ -14,8 +14,7 @@ module Bim
14
14
  return { 'message' => "cancel sync #{BIGIP_HOST} to #{dest}" } unless yes_or_no?(msg)
15
15
  uri = URI.join(Bim::BASE_URL, Bim::Action::Sync::SYNC_PATH)
16
16
  j = { "command": 'run', "utilCmdArgs": "config-sync #{'force-full-load-push ' if overwrite}to-group #{dest}" }
17
- req = request(uri, Bim::AUTH, 'application/json', 'POST', j.to_json)
18
- http(uri).request(req).body
17
+ post(uri, j.to_json)
19
18
  end
20
19
 
21
20
  def state
data/lib/bim/action/vs.rb CHANGED
@@ -4,26 +4,42 @@ module Bim
4
4
  class VS
5
5
  extend Bim::Util
6
6
 
7
- VIRTUALS_PATH = '/mgmt/tm/ltm/virtual'.freeze
7
+ VS_PATH = '/mgmt/tm/ltm/virtual'.freeze
8
+ VS_URI = URI.join(Bim::BASE_URL, Bim::Action::VS::VS_PATH)
8
9
 
9
10
  class << self
10
- def list
11
- JSON
12
- .parse(vs_list)['items']
13
- .map do |vs|
14
- profiles = JSON.parse(profiles(vs['profilesReference']['link']))['items'].map { |p| p['fullPath'] }
15
- { 'name' => vs['name'], 'profiles' => profiles }
16
- end.to_json
11
+ def ls
12
+ map(VS_URI) do |item|
13
+ r = { name: item['name'] }
14
+ r['profiles'] = JSON.parse(map(URI(sub_localhost(item['profilesReference']['link']))) do |in_item|
15
+ in_item['fullPath']
16
+ end)
17
+ r
18
+ end
17
19
  end
18
20
 
19
21
  def detail(name)
20
- JSON
21
- .parse(vs_list)['items']
22
- .select { |vs| vs['name'] == name }
23
- .map do |vs|
24
- profiles = JSON.parse(profiles(vs['profilesReference']['link']))['items'].map { |p| p['fullPath'] }
25
- { 'name' => vs['name'], 'profiles' => profiles }
26
- end.first.to_json
22
+ specify(VS_URI) { |d| d['name'] == name }
23
+ end
24
+
25
+ def update_dnat(name, dnat_addr, port)
26
+ j = { 'destination' => "#{dnat_addr}:#{port}" }.to_json
27
+ self_patch(name, VS_URI, j)
28
+ end
29
+
30
+ def update_snat(name, snat_addr, bitmask)
31
+ j = { 'source' => "#{snat_addr}/#{bitmask}" }.to_json
32
+ self_patch(name, VS_URI, j)
33
+ end
34
+
35
+ def change_nf(name, nf_name)
36
+ j = { 'fwEnforcedPolicy' => nf_name }.to_json
37
+ self_patch(name, VS_URI, j)
38
+ end
39
+
40
+ def change_pool(name, pool_name)
41
+ j = { 'pool' => pool_name }.to_json
42
+ self_patch(name, VS_URI, j)
27
43
  end
28
44
  end
29
45
  end
data/lib/bim/action.rb CHANGED
@@ -3,6 +3,9 @@ require 'bim/action/meta'
3
3
  require 'bim/action/sync'
4
4
  require 'bim/action/ssl'
5
5
  require 'bim/action/vs'
6
+ require 'bim/action/node'
7
+ require 'bim/action/pool'
8
+ require 'bim/action/fw'
6
9
 
7
10
  module Bim
8
11
  # Action module is namespace
data/lib/bim/cli.rb CHANGED
@@ -4,16 +4,11 @@ require 'bim/subcommands'
4
4
  module Bim
5
5
  # CLI class is import subcommands
6
6
  class CLI < Thor
7
- desc 'meta [Subcommand]', "Subcommands: #{Bim::Subcommands::Meta.instance_methods(false).join(',')}"
8
- subcommand 'meta', Bim::Subcommands::Meta
9
-
10
- desc 'sync [Subcommand]', "Subcommands: #{Bim::Subcommands::Sync.instance_methods(false).join(',')}"
11
- subcommand 'sync', Bim::Subcommands::Sync
12
-
13
- desc 'ssl [Subcommand]', "Subcommands: #{Bim::Subcommands::SSL.instance_methods(false).join(',')}"
14
- subcommand 'ssl', Bim::Subcommands::SSL
15
-
16
- desc 'vs [Subcommand]', "Subcommands: #{Bim::Subcommands::VS.instance_methods(false).join(',')}"
17
- subcommand 'vs', Bim::Subcommands::VS
7
+ # define under subcommands files as subcommands
8
+ Dir.glob(::Pathname.new(__dir__) + 'subcommands/*').map { |fp| File.basename(fp).split('.rb')[0] }.each do |cmd|
9
+ klass = Object.const_get('Bim').const_get('Subcommands').const_get(cmd.capitalize)
10
+ desc "#{cmd} [Subcommand]", "Subcommands: #{klass.instance_methods(false).join(',')}"
11
+ subcommand cmd, klass
12
+ end
18
13
  end
19
14
  end
@@ -0,0 +1,22 @@
1
+ module Bim
2
+ module Subcommands
3
+ # Fw class defines subcommands
4
+ class Fw < Thor
5
+ desc(
6
+ 'ls',
7
+ 'output firewall policy list'
8
+ )
9
+ def ls
10
+ puts Bim::Action::Fw.ls
11
+ end
12
+
13
+ desc(
14
+ 'detail [NAME]',
15
+ 'output firewall policy detail'
16
+ )
17
+ def detail(name)
18
+ puts Bim::Action::Fw.detail(name)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -4,7 +4,7 @@ module Bim
4
4
  class Meta < Thor
5
5
  desc(
6
6
  'actives',
7
- 'output active host'
7
+ 'output active hosts'
8
8
  )
9
9
  def actives
10
10
  puts Bim::Action::Meta.actives
@@ -12,7 +12,7 @@ module Bim
12
12
 
13
13
  desc(
14
14
  'device_groups',
15
- 'outpu device group'
15
+ 'output device groups'
16
16
  )
17
17
  def device_groups
18
18
  puts Bim::Action::Meta.device_groups
@@ -0,0 +1,38 @@
1
+ module Bim
2
+ module Subcommands
3
+ # Node class defines subcommands
4
+ class Node < Thor
5
+ desc(
6
+ 'ls',
7
+ 'output node list'
8
+ )
9
+ def ls
10
+ puts Bim::Action::Node.ls
11
+ end
12
+
13
+ desc(
14
+ 'detail [NAME]',
15
+ 'output node detail'
16
+ )
17
+ def detail(name)
18
+ puts Bim::Action::Node.detail(name)
19
+ end
20
+
21
+ desc(
22
+ 'create [NAME] [ADDRESS]',
23
+ 'create node'
24
+ )
25
+ def create(name, address)
26
+ puts Bim::Action::Node.create(name, address)
27
+ end
28
+
29
+ desc(
30
+ 'delete [NAME]',
31
+ 'delete node'
32
+ )
33
+ def delete(name)
34
+ puts Bim::Action::Node.delete(name)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ module Bim
2
+ module Subcommands
3
+ # Pool class defines subcommands
4
+ class Pool < Thor
5
+ desc(
6
+ 'ls',
7
+ 'output pool list'
8
+ )
9
+ def ls
10
+ puts Bim::Action::Pool.ls
11
+ end
12
+
13
+ desc(
14
+ 'create [NAME] [MEMBERS(optional: \'[{"name": "NodeName:Port", "address": "NodeAddress"}, {"name": "NodeName:Port", "address": "NodeAddress"}]\')]',
15
+ 'create pool with node members'
16
+ )
17
+ def create(name, members = nil)
18
+ puts Bim::Action::Pool.create(name, members)
19
+ end
20
+
21
+ desc(
22
+ 'members [NAME]',
23
+ 'output members belongs to pool'
24
+ )
25
+ def members(name)
26
+ puts Bim::Action::Pool.members(name)
27
+ end
28
+
29
+ desc(
30
+ 'drop [NAME] [MEMBERS(NodeName:Port)]',
31
+ 'drop node members (members are variable length)'
32
+ )
33
+ def drop(name, *members)
34
+ puts Bim::Action::Pool.drop_members(name, members)
35
+ end
36
+
37
+ desc(
38
+ 'add [NAME] [MEMBERS(NodeName:Port)]',
39
+ 'add node members (members aer variable length)'
40
+ )
41
+ def add(name, *members)
42
+ puts Bim::Action::Pool.add_members(name, members)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,7 +1,7 @@
1
1
  module Bim
2
2
  module Subcommands
3
- # SSL class defines subcommands
4
- class SSL < Thor
3
+ # Ssl class defines subcommands
4
+ class Ssl < Thor
5
5
  desc(
6
6
  'bundles',
7
7
  'output bundle certificat files info'
@@ -8,14 +8,14 @@ module Bim
8
8
  '[GROUP_NAME] [--overwrite]',
9
9
  'sync device configuration to group. if set overwrite option, sync force-full-load-push mode.'
10
10
  )
11
- option :overwrite, :type => :boolean
11
+ option :overwrite, type: :boolean
12
12
  def to_group(group)
13
13
  puts Bim::Action::Sync.sync!(group, overwrite: options.key?(:overwrite))
14
14
  end
15
15
 
16
16
  desc(
17
17
  'state',
18
- 'get sync state'
18
+ 'output sync state'
19
19
  )
20
20
  def state
21
21
  puts Bim::Action::Sync.state
@@ -23,7 +23,7 @@ module Bim
23
23
 
24
24
  desc(
25
25
  'failover_state',
26
- 'get failover state'
26
+ 'output failover state'
27
27
  )
28
28
  def failover_state
29
29
  puts Bim::Action::Sync.failover_state
@@ -1,13 +1,13 @@
1
1
  module Bim
2
2
  module Subcommands
3
- # VS class defines subcommands
4
- class VS < Thor
3
+ # Vs class defines subcommands
4
+ class Vs < Thor
5
5
  desc(
6
- 'list',
6
+ 'ls',
7
7
  'output virtual server info list'
8
8
  )
9
- def list
10
- puts Bim::Action::VS.list
9
+ def ls
10
+ puts Bim::Action::VS.ls
11
11
  end
12
12
 
13
13
  desc(
@@ -17,6 +17,38 @@ module Bim
17
17
  def detail(name)
18
18
  puts Bim::Action::VS.detail(name)
19
19
  end
20
+
21
+ desc(
22
+ 'update_dnat [NAME] [DNAT_ADDRESS] [PORT]',
23
+ 'update dnat configuration'
24
+ )
25
+ def update_dnat(name, dnat_addr, port)
26
+ puts Bim::Action::VS.update_dnat(name, dnat_addr, port)
27
+ end
28
+
29
+ desc(
30
+ 'update_snat [NAME] [SNAT_ADDRESS] [BIT_MASK]',
31
+ 'update snat configuration'
32
+ )
33
+ def update_snat(name, snat_addr, bit_mask)
34
+ puts Bim::Action::VS.update_snat(name, snat_addr, bit_mask)
35
+ end
36
+
37
+ desc(
38
+ 'change_nf [VS_NAME] [NETWORK_FIREWALL_FULLPATH]',
39
+ 'change network firewall policy'
40
+ )
41
+ def change_nf(name, nf_name)
42
+ puts Bim::Action::VS.change_nf(name, nf_name)
43
+ end
44
+
45
+ desc(
46
+ 'change_pool [NAME] [POOL_FULLPATH]',
47
+ 'change pool'
48
+ )
49
+ def change_pool(name, pool_name)
50
+ puts Bim::Action::VS.change_pool(name, pool_name)
51
+ end
20
52
  end
21
53
  end
22
54
  end
@@ -3,6 +3,9 @@ require 'bim/subcommands/meta'
3
3
  require 'bim/subcommands/sync'
4
4
  require 'bim/subcommands/ssl'
5
5
  require 'bim/subcommands/vs'
6
+ require 'bim/subcommands/node'
7
+ require 'bim/subcommands/pool'
8
+ require 'bim/subcommands/fw'
6
9
 
7
10
  module Bim
8
11
  # Subcommands module is namespace
data/lib/bim/util.rb CHANGED
@@ -36,6 +36,8 @@ module Bim
36
36
  Net::HTTP::Post.new(uri)
37
37
  when 'PATCH'
38
38
  Net::HTTP::Patch.new(uri)
39
+ when 'DELETE'
40
+ Net::HTTP::Delete.new(uri)
39
41
  end
40
42
 
41
43
  req['Content-Type'] = content_type
@@ -50,6 +52,53 @@ module Bim
50
52
  STDIN.gets.chomp.match?(/^[yY]/)
51
53
  end
52
54
 
55
+ def select_map(uri, select_block, &map_block)
56
+ JSON
57
+ .parse(get_body(uri))['items']
58
+ .select(&select_block)
59
+ .map(&map_block)
60
+ .to_json
61
+ end
62
+
63
+ def map(uri, &block)
64
+ JSON
65
+ .parse(get_body(uri))['items']
66
+ .map(&block)
67
+ .to_json
68
+ end
69
+
70
+ def specify(uri, &block)
71
+ JSON
72
+ .parse(get_body(uri))['items']
73
+ .select(&block)
74
+ .first
75
+ .to_json
76
+ end
77
+
78
+ def specify_link(uri, key = ['selfLink'], &block)
79
+ JSON
80
+ .parse(get_body(uri))['items']
81
+ .select(&block)
82
+ .first
83
+ .dig(*key)
84
+ end
85
+
86
+ def specify_link_by_name(uri, name, key = ['selfLink'])
87
+ specify_link(uri, key) { |item| item['name'] == name }
88
+ end
89
+
90
+ def post(uri, j, body = true)
91
+ req = request(uri, Bim::AUTH, 'application/json', 'POST', j)
92
+ body ? http(uri).request(req).body : http(uri).request(req)
93
+ end
94
+
95
+ def self_patch(name, list_uri, j)
96
+ self_link = sub_localhost(specify_link(list_uri) { |item| item['name'] == name })
97
+ uri = URI(self_link)
98
+ req = request(uri, Bim::AUTH, 'application/json', 'PATCH', j)
99
+ http(uri).request(req).body
100
+ end
101
+
53
102
  def vs_list
54
103
  uri = URI.join(BASE_URL, VS_PATH)
55
104
  get_body(uri)
@@ -59,5 +108,9 @@ module Bim
59
108
  uri = URI.parse(link.sub('localhost', BIGIP_HOST))
60
109
  get_body(uri)
61
110
  end
111
+
112
+ def sub_localhost(url)
113
+ url.sub('localhost', BIGIP_HOST)
114
+ end
62
115
  end
63
116
  end
data/lib/bim/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bim
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
data/lib/bim.rb CHANGED
@@ -1,7 +1,6 @@
1
- require 'bim/version'
2
- require 'bim/cli'
3
- require 'json'
4
1
  require 'base64'
2
+ require 'json'
3
+ require 'bim/version'
5
4
 
6
5
  module Bim
7
6
  BIGIP_HOST = ENV['BIGIP_HOST']
@@ -17,3 +16,5 @@ module Bim
17
16
  class UnsetPasswordEnvironmentError < UnsetEnvironmentError; end
18
17
  class UnauthorizedError < StandardError; end
19
18
  end
19
+
20
+ require 'bim/cli'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - littlekbt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2017-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
78
  - ".rubocop.yml"
79
+ - ".travis.yml"
79
80
  - Gemfile
80
81
  - LICENSE.txt
81
82
  - README.md
@@ -85,13 +86,19 @@ files:
85
86
  - completions/bim.bash
86
87
  - lib/bim.rb
87
88
  - lib/bim/action.rb
89
+ - lib/bim/action/fw.rb
88
90
  - lib/bim/action/meta.rb
91
+ - lib/bim/action/node.rb
92
+ - lib/bim/action/pool.rb
89
93
  - lib/bim/action/ssl.rb
90
94
  - lib/bim/action/sync.rb
91
95
  - lib/bim/action/vs.rb
92
96
  - lib/bim/cli.rb
93
97
  - lib/bim/subcommands.rb
98
+ - lib/bim/subcommands/fw.rb
94
99
  - lib/bim/subcommands/meta.rb
100
+ - lib/bim/subcommands/node.rb
101
+ - lib/bim/subcommands/pool.rb
95
102
  - lib/bim/subcommands/ssl.rb
96
103
  - lib/bim/subcommands/sync.rb
97
104
  - lib/bim/subcommands/vs.rb