def build_config(config): """ Determines the configuration of the metadata service. :type config: akanda.router.models.Configuration :param config: :rtype: akanda.router.models.Configuration """ config_data = {} for net in config.networks: if not net.is_tenant_network: continue ip_instance_map = {} for a in net.address_allocations: for ip in a.ip_addresses: ip_instance_map[ip] = a.device_id config_data[net.id] = { 'listen_port': internal_metadata_port(net.interface.ifname), 'ip_instance_map': ip_instance_map } config_data['tenant_id'] = config.tenant_id return config_data
def _build_v4_nat(self, config): rules = [] for network in self.get_internal_networks(config): if network.interface.first_v4: # Forward metadata requests on the management interface rules.append(Rule( '-A PREROUTING -i %s -d %s -p tcp -m tcp ' '--dport %s -j DNAT --to-destination %s:%s' % ( network.interface.ifname, defaults.METADATA_DEST_ADDRESS, defaults.HTTP, network.interface.first_v4, defaults.internal_metadata_port( network.interface.ifname ) ), ip_version=4 )) # Add a masquerade catch-all for VMs without floating IPs ext_if = self.get_external_network(config).interface rules.append(Rule( '-A POSTROUTING -o %s -j MASQUERADE' % ( ext_if.ifname ), ip_version=4 )) return rules
def _format_metadata_rule(int_if): args = { 'ifname': int_if, 'dest_addr': defaults.METADATA_DEST_ADDRESS, 'local_port': defaults.internal_metadata_port(int_if) } return ('pass in quick on %(ifname)s proto tcp to %(dest_addr)s port http ' 'rdr-to 127.0.0.1 port %(local_port)d') % args
def _format_metadata_rule(int_if): args = { "ifname": int_if, "dest_addr": defaults.METADATA_DEST_ADDRESS, "local_port": defaults.internal_metadata_port(int_if), } return ( "pass in quick on %(ifname)s proto tcp to %(dest_addr)s port http " "rdr-to 127.0.0.1 port %(local_port)d" ) % args
def build_config(config): config_data = {} for net in config.networks: if not net.is_tenant_network: continue ip_instance_map = {} for a in net.address_allocations: for ip in a.ip_addresses: ip_instance_map[ip] = a.device_id config_data[net.id] = { 'listen_port': internal_metadata_port(net.interface.ifname), 'ip_instance_map': ip_instance_map } return config_data
def _build_v4_nat(self, config): rules = [] for network in self.get_internal_networks(config): if network.interface.first_v4: # Forward metadata requests on the management interface rules.append( Rule('-A PREROUTING -i %s -d %s -p tcp -m tcp ' '--dport %s -j DNAT --to-destination %s:%s' % (network.interface.ifname, defaults.METADATA_DEST_ADDRESS, defaults.HTTP, network.interface.first_v4, defaults.internal_metadata_port( network.interface.ifname)), ip_version=4)) # Add a masquerade catch-all for VMs without floating IPs ext_if = self.get_external_network(config).interface rules.append( Rule('-A POSTROUTING -o %s -j MASQUERADE' % (ext_if.ifname), ip_version=4)) return rules