def test_ip_netmask_to_cidr(self): self.assertEqual('10.0.0.0/8', utils.ip_netmask_to_cidr('10.0.0.1', '255.0.0.0')) self.assertEqual('10.0.0.0/9', utils.ip_netmask_to_cidr('10.0.0.1', '255.128.0.0')) self.assertEqual('10.0.0.0/16', utils.ip_netmask_to_cidr('10.0.0.1', '255.255.0.0')) self.assertEqual('10.0.0.0/20', utils.ip_netmask_to_cidr('10.0.0.1', '255.255.240.0')) self.assertEqual('10.0.0.0/30', utils.ip_netmask_to_cidr( '10.0.0.1', '255.255.255.252'))
def write_static_routes_interface_file(self, interface_file_path, interface, host_routes, template_routes, gateway, vip, netmask): # write static routes interface file mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH # TODO(johnsom): We need a way to clean out old interfaces records if CONF.amphora_agent.agent_server_network_file: flags = os.O_WRONLY | os.O_CREAT | os.O_APPEND else: flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC with os.fdopen(os.open(interface_file_path, flags, mode), 'w') as text_file: text = template_routes.render( consts=consts, interface=interface, host_routes=host_routes, gateway=gateway, network=utils.ip_netmask_to_cidr(vip, netmask), vip=vip, topology=CONF.controller_worker.loadbalancer_topology, ) text_file.write(text)
def write_vip_interface_file(self, interface_file_path, primary_interface, vip, ip, broadcast, netmask, gateway, mtu, vrrp_ip, vrrp_version, render_host_routes, template_vip): # write interface file mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH # If we are using a consolidated interfaces file, just append # otherwise clear the per interface file as we are rewriting it # TODO(johnsom): We need a way to clean out old interfaces records if CONF.amphora_agent.agent_server_network_file: flags = os.O_WRONLY | os.O_CREAT | os.O_APPEND else: flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC with os.fdopen(os.open(interface_file_path, flags, mode), 'w') as text_file: text = template_vip.render( interface=primary_interface, vip=vip, vip_ipv6=ip.version == 6, prefix=utils.netmask_to_prefix(netmask), broadcast=broadcast, netmask=netmask, gateway=gateway, network=utils.ip_netmask_to_cidr(vip, netmask), mtu=mtu, vrrp_ip=vrrp_ip, vrrp_ipv6=vrrp_version == 6, host_routes=render_host_routes, ) text_file.write(text)
def write_vip_interface_file(self, interface_file_path, interface, vip, ip, broadcast, netmask, gateway, mtu, auxiliary_ip, auxiliary_version, render_host_routes, template_vip): # write interface file mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH # If we are using a consolidated interfaces file, just append # otherwise clear the per interface file as we are rewriting it # TODO(johnsom): We need a way to clean out old interfaces records if CONF.amphora_agent.agent_server_network_file: flags = os.O_WRONLY | os.O_CREAT | os.O_APPEND else: flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC with os.fdopen(os.open(interface_file_path, flags, mode), 'w') as text_file: text = template_vip.render( consts=consts, interface=interface, vip=vip, ip=ip, vip_ipv6=ip.version == 6, # For ipv6 the netmask is already the prefix prefix=(netmask if ip.version == 6 else utils.netmask_to_prefix(netmask)), broadcast=broadcast, netmask=netmask, gateway=gateway, network=utils.ip_netmask_to_cidr(vip, netmask), mtu=mtu, auxiliary_ip=auxiliary_ip, auxiliary_ipv6=auxiliary_version == 6, host_routes=render_host_routes, topology=CONF.controller_worker.loadbalancer_topology, ) text_file.write(text)
def write_vip_interface_file(self, interface_file_path, primary_interface, vip, ip, broadcast, netmask, gateway, mtu, vrrp_ip, vrrp_version, render_host_routes, template_vip): # write interface file mode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH # If we are using a consolidated interfaces file, just append # otherwise clear the per interface file as we are rewriting it # TODO(johnsom): We need a way to clean out old interfaces records if CONF.amphora_agent.agent_server_network_file: flags = os.O_WRONLY | os.O_CREAT | os.O_APPEND else: flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC with os.fdopen(os.open(interface_file_path, flags, mode), 'w') as text_file: text = template_vip.render( consts=consts, interface=primary_interface, vip=vip, vip_ipv6=ip.version == 6, # For ipv6 the netmask is already the prefix prefix=(netmask if ip.version == 6 else utils.netmask_to_prefix(netmask)), broadcast=broadcast, netmask=netmask, gateway=gateway, network=utils.ip_netmask_to_cidr(vip, netmask), mtu=mtu, vrrp_ip=vrrp_ip, vrrp_ipv6=vrrp_version == 6, host_routes=render_host_routes, topology=CONF.controller_worker.loadbalancer_topology, ) text_file.write(text)