# -*- coding: utf-8 -*- module Fog module Vcloud class Compute class Real def generate_outbound_rule() outbound_rule = < true OUTGOING allow true -1 Any -1 Any out false EOF outbound_rule end def generate_tcp_rules(tcp_ports) firewall_rules = "" tcp_ports.each do |port| firewall_rules << < true #{port} allow true #{port} Any -1 Any in false EOF end firewall_rules end def generate_udp_rules(udp_ports) firewall_rules = "" udp_ports.each do |port| firewall_rules << < true #{port} allow true #{port} Any -1 Any in false EOF end firewall_rules end def generate_configure_org_network_request(vapp_id, vapp_network, vapp_network_uri, org_network, org_network_uri, enable_firewall=false, portmap=nil) firewall_body = "" if not enable_firewall firewall_body = "false" else firewall_rules = generate_outbound_rule + generate_tcp_rules(portmap["TCP"]) + generate_udp_rules(portmap["UDP"]) firewall_body = <true drop false #{firewall_rules} EOF end body = < The configuration parameters for logical networks natRouted true #{firewall_body} true ipTranslation allowTraffic false bridged true EOF end def configure_org_network(vapp_id, vapp_network, vapp_network_uri, org_network, org_network_uri, enable_firewall=false, port_map=nil) body = generate_configure_org_network_request(vapp_id, vapp_network, vapp_network_uri, org_network, org_network_uri, enable_firewall, port_map) #puts ("Body: #{body}") request( :body => body, :expects => 202, :headers => {'Content-Type' => 'Application/vnd.vmware.vcloud.networkConfigSection+xml' }, :method => 'PUT', :uri => "#{vapp_id}/networkConfigSection", :parse => true ) end end end end end