Class: Vcloud::EdgeGateway::ConfigurationGenerator::StaticRoutingService

Inherits:
Object
  • Object
show all
Defined in:
lib/vcloud/edge_gateway/configuration_generator/static_routing_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(input_config, edge_gateway_interfaces) ⇒ StaticRoutingService

Returns a new instance of StaticRoutingService.



6
7
8
9
# 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

Instance Method Details

#find_egw_interface(network_name) ⇒ Object



51
52
53
# 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_configObject



11
12
13
14
15
16
17
# 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) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# 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_sectionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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?Boolean

Returns:

  • (Boolean)


46
47
48
49
# 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