Guest User

Untitled

a guest
Jul 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Iptables returns hashes:
  2.  
  3. {"status" => false
  4. "output" => "Failed to add 1.2.3.4: <ip tables output>"}
  5.  
  6. The helper would be:
  7.  
  8. @agents["iptables"].firewall("1.2.3.4")
  9. @agents["iptables"].unfirewall("1.2.3.4")
  10. @agents["iptables"].firewalled?("1.2.3.4")
  11.  
  12. And would return lets say:
  13.  
  14. {"status" => false,
  15. "nodestatuses => [ <node 1 status as from the agent>, <node 2 status as from the agent> ]}
  16.  
  17. today without the helper it's:
  18.  
  19. req = {"command" => "isblocked", "ip" => @ips[device]}
  20.  
  21. @options[:filter]["agent"] = "iptables"
  22.  
  23. client = MCollective::Client.new(@options[:config])
  24. client.req(req, "iptables", @options, @options[:waitfor]) do |resp|
  25. unless resp[:body]["status"]
  26. raise("Not blocked on #{resp[:senderid]}")
  27. end
  28. end
  29.  
  30. It could become, and the helper would do all the above 'today' steps:
  31.  
  32. @agents.options = options
  33. ret = @agents["iptables"].firewall("1.2.3.4")
  34.  
  35. raise("Failed to firewall 1.2.3.4") unless ret["status"]
  36.  
  37. Or:
  38. raise("1.2.3.4 is not firewalled") unless @agents["iptables"].firewall("1.2.3.4")["status"]
Add Comment
Please, Sign In to add comment