class Vcloud::EdgeGateway::ConfigurationGenerator::StaticRoutingService

Public Class Methods

new(input_config, edge_gateway_interfaces) click to toggle source
# File lib/vcloud/edge_gateway/configuration_generator/static_routing_service.rb, line 6
def initialize input_config, edge_gateway_interfaces
  @input_config = input_config
  @edge_gateway_interfaces = edge_gateway_interfaces
end

Public Instance Methods

find_egw_interface(network_name) click to toggle source
# File lib/vcloud/edge_gateway/configuration_generator/static_routing_service.rb, line 51
def find_egw_interface(network_name)
  @edge_gateway_interfaces.find{|i| i.network_name == network_name}
end
generate_fog_config() click to toggle source
# File lib/vcloud/edge_gateway/configuration_generator/static_routing_service.rb, line 11
def generate_fog_config
  return nil unless @input_config
  {
    IsEnabled:   routing_enabled?,
    StaticRoute: generate_static_route_section
  }
end
generate_gateway_interface_section(network_name) click to toggle source
# File lib/vcloud/edge_gateway/configuration_generator/static_routing_service.rb, line 35
def generate_gateway_interface_section(network_name)
  egw_interface = find_egw_interface(network_name)
  raise "unable to find gateway network interface with id #{network_id}" unless egw_interface

  {
    type: "application/vnd.vmware.vcloud.orgVdcNetwork+xml",
    name: egw_interface.network_name,
    href: egw_interface.network_href
  }
end
generate_static_route_section() click to toggle source
# File lib/vcloud/edge_gateway/configuration_generator/static_routing_service.rb, line 19
def generate_static_route_section
  routes = @input_config[:static_routes]
  return [] if routes.nil?
  routes.collect do |route|
    route[:enabled] ||= 'true'
    {
      Name:             route[:name],
      Network:          route[:network],
      NextHopIp:        route[:next_hop],
      IsEnabled:        route[:enabled],
      GatewayInterface: generate_gateway_interface_section(route[:apply_on])

    }
  end
end
routing_enabled?() click to toggle source
# File lib/vcloud/edge_gateway/configuration_generator/static_routing_service.rb, line 46
def routing_enabled?
    return 'false' unless @input_config
    @input_config.key?(:enabled) ? @input_config[:enabled].to_s : 'true'
end