Class: Chef::Knife::SlFirewallList

Inherits:
Chef::Knife show all
Includes:
SlBase
Defined in:
lib/chef/knife/sl_firewall_list.rb

Instance Method Summary collapse

Methods included from SlBase

#connection, #current_domain, included, #list_firewalls, #list_vlans, #locate_config_value

Instance Method Details

#format_rules(rules) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/chef/knife/sl_firewall_list.rb', line 56

def format_rules(rules)
  
  if rules == []
    puts "Empty"
    
    return
  end
  
  rule_list = ["Order", "ID", "Action", "Proto", "SRC IP", "SRC Mask", "DST IP", "DST Mask", "DST Ports", "Notes"]
  
  rule_list.map!{ |f| ui.color(f, :bold) }
  
  rules = rules.first['rules'].sort_by { |rule| rule['orderValue'] }
  
  rules.each do |rule|
    rule_list << rule['orderValue'].to_s
    rule_list << rule['id'].to_s
    rule_list << rule['action'].to_s
    rule_list << rule['protocol'].to_s
    rule_list << rule['sourceIpAddress'].to_s
    rule_list << rule['sourceIpSubnetMask'].to_s
    rule_list << rule['destinationIpAddress'].to_s
    rule_list << rule['destinationIpSubnetMask']
    rule_list << [rule['destinationPortRangeStart'].to_s, rule['destinationPortRangeEnd'].to_s].join("-")
    rule_list << rule['notes'].to_s
  end
  
  puts ui.list(rule_list, :uneven_columns_across, 10)
end

#list_firewall_rules_by_id(id) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/knife/sl_firewall_list.rb', line 44

def list_firewall_rules_by_id(id)
  mask = {
    "rules" => ""
  }
  
  host_ref = connection("SoftLayer_Network_Firewall_Interface").object_with_id(id)
  
  host_objs = host_ref.object_mask(mask).getFirewallContextAccessControlLists.find_all.to_a
  
  return host_objs
end

#runObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chef/knife/sl_firewall_list.rb', line 30

def run
  $stdout.sync = true
  
  firewalls = list_firewalls
  
  firewalls.each do |firewall|
    firewall['firewallInterfaces'].each do |fw_interface|
      puts "Interface: #{fw_interface['name']}"
      rules = list_firewall_rules_by_id(fw_interface['id'])
      format_rules(rules)
    end
  end
end