Class: Component::NAT
- Inherits:
-
Object
- Object
- Component::NAT
- Defined in:
- lib/component/nat.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
Instance Method Summary collapse
- #dnat(options) ⇒ Object
-
#initialize ⇒ NAT
constructor
A new instance of NAT.
- #rule(options) ⇒ Object
- #snat(options) ⇒ Object
Constructor Details
#initialize ⇒ NAT
Returns a new instance of NAT.
8 9 10 11 |
# File 'lib/component/nat.rb', line 8 def initialize @rules = [] @count = 65537 end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
6 7 8 |
# File 'lib/component/nat.rb', line 6 def rules @rules end |
Class Method Details
.generate_xml(interfaces) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/component/nat.rb', line 36 def self.generate_xml interfaces return if NAT.instance.rules.nil? or NAT.instance.rules.empty? Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.EdgeGatewayServiceConfiguration('xmlns' => "http://www.vmware.com/vcloud/v1.5", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xsi:schemaLocation' => "http://www.vmware.com/vcloud/v1.5 http://vendor-api-url.net/v1.5/schema/master.xsd") { xml.NatService { xml.IsEnabled "true" NAT.instance.rules.each do |rule| xml.NatRule { xml.RuleType rule[:type] xml.IsEnabled rule[:enabled] xml.Id rule[:id] xml.GatewayNatRule { xml.Interface('type' => "application/vnd.vmware.admin.network+xml", 'name' => rule[:interface], 'href' => interfaces[rule[:interface]]) xml.OriginalIp rule[:original][:ip] if rule[:original][:port] xml.OriginalPort rule[:original][:port] end xml.TranslatedIp rule[:translated][:ip] if rule[:translated][:port] xml.TranslatedPort rule[:translated][:port] end if rule[:type] == "DNAT" xml.Protocol rule[:protocol] end } } end } } end end |
.instance ⇒ Object
32 33 34 |
# File 'lib/component/nat.rb', line 32 def self.instance @nat ||= NAT.new end |
.reset ⇒ Object
28 29 30 |
# File 'lib/component/nat.rb', line 28 def self.reset @nat = nil end |
Instance Method Details
#dnat(options) ⇒ Object
13 14 15 |
# File 'lib/component/nat.rb', line 13 def dnat() rule(.merge(:type => 'DNAT')) end |
#rule(options) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/component/nat.rb', line 21 def rule() @count += 1; defaults = { :enabled => true, :protocol => 'tcp', :id=>@count} = defaults.merge() rules << end |
#snat(options) ⇒ Object
17 18 19 |
# File 'lib/component/nat.rb', line 17 def snat() rule(.merge(:type => 'SNAT')) end |