Sha256: 05ae8b9a60d104c33cb31ad64d0ae11c3626073abdaf5ac357594e4c02ccb4a2
Contents?: true
Size: 1.77 KB
Versions: 1
Compression:
Stored size: 1.77 KB
Contents
require "net/http" require 'yaml' class VcloudConfigureRequest def initialize vcloud_settings, auth_header, environment, component, rules_directory @auth_header = auth_header @config_url = vcloud_settings.edge_gateway_config_url @environment = environment @component = component @response = nil @interfaces = File.file?("#{rules_directory}/#{@environment}/interfaces.yaml") ? YAML::load_file("#{rules_directory}/#{@environment}/interfaces.yaml")['interfaces'] : {} require "#{rules_directory}/common_#{component}.rb" if File.file?("#{rules_directory}/common_#{component}.rb") require "#{rules_directory}/#{@environment}/#{component}" if File.file?("#{rules_directory}/#{@environment}/#{component}.rb") end def components { "firewall" => "Firewall", "nat" => "NAT", "lb" => "LoadBalancer" } end def submit generated_xml = Kernel.const_get("Component").const_get(components[@component]). generate_xml(@interfaces) abort "No rules found. exiting" if generated_xml.nil? url = URI(@config_url) request = Net::HTTP::Post.new url.request_uri request['Accept'] = VcloudSettings.request_headers['Accept'] request['Content-Type'] = VcloudSettings.request_headers['Content-Type'] request['x-vcloud-authorization'] = @auth_header request.body = generated_xml.to_xml puts "Reading configuration from #{@config_file}" puts "Submitting request at #{@config_url}\n" session = Net::HTTP.new(url.host, url.port) session.use_ssl = true response = session.start do |http| http.request request end puts "HTTP #{response.code}" puts response @response = response end def success? @response.code == "202" end def response_body @response.body end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vcloud-net-spinner-0.1.2 | lib/vcloud_network_configurator/vcloud_configure_request.rb |