forked from ytti/oxidized
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nsxdfw.rb
30 lines (28 loc) · 1.18 KB
/
nsxdfw.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'net/http'
class NSXDfw < Oxidized::Model
using Refinements
cmd "/policy/api/v1/infra/domains/" do |cfg|
domains = JSON.parse(cfg.encode('UTF-8', { invalid: :replace, undef: :replace, replace: '?' }))["results"]
domain_config = {}
domains.each do |domain|
domain_config[domain['id']] = {}
policies_data = cmd "/policy/api/v1/infra/domains/#{domain['id']}/security-policies/"
policies = JSON.parse(policies_data.encode('UTF-8', { invalid: :replace, undef: :replace, replace: '?' }))["results"]
policies_config = {}
policies.each do |policy|
rules_data = cmd "/policy/api/v1/infra/domains/#{domain['id']}/security-policies/#{policy['id']}/rules"
rules = JSON.parse(rules_data.encode('UTF-8', { invalid: :replace, undef: :replace, replace: '?' }))["results"]
policies_config[policy['id']] = rules
end
domain_config[domain['id']] = policies_config
end
JSON.pretty_generate(domain_config)
end
cfg :http do
@username = @node.auth[:username]
@password = @node.auth[:password]
@headers['Content-Type'] = 'application/json'
@headers['Accept'] = 'application/json'
@secure = true
end
end