def from_neutron_subnet(cls, network, subnet): options = [] if subnet.gateway_ip: options.append(('routers', subnet.gateway_ip)) dns_servers = cls._normalize_dns_nameservers(network, subnet) if dns_servers: options.append(('domain-name-servers', dns_servers)) static_routes_str = cls._normalize_host_routes(network, subnet) static_routes = "" if static_routes_str: static_routes = dhcpopts.format_for_options( 'classless-static-routes', static_routes_str) if static_routes: options.append(('classless-static-routes', static_routes)) extra_options = {'dhcp-lease-time': str(cfg.CONF.dhcp_lease_duration), 'domain-name': cfg.CONF.dhcp_domain} for option in extra_options.items(): options.append(option) opt_list = [] for name, val in options: opt = dhcpopts.format_for_pnr(name, val) if opt: opt_list.append(opt) if opt_list: data = {'optionList': {'OptionItem': opt_list}} else: data = {'optionList': {'list': []}} return cls(data)
def from_neutron_subnet(cls, network, subnet): options = [] if subnet.gateway_ip: options.append(('routers', subnet.gateway_ip)) dns_servers = cls._normalize_dns_nameservers(network, subnet) if dns_servers: options.append(('domain-name-servers', dns_servers)) static_routes_str = cls._normalize_host_routes(network, subnet) static_routes = "" if static_routes_str: static_routes = dhcpopts.format_for_options( 'classless-static-routes', static_routes_str) if static_routes: options.append(('classless-static-routes', static_routes)) extra_options = { 'dhcp-lease-time': str(cfg.CONF.dhcp_lease_duration), 'domain-name': cfg.CONF.dns_domain } for option in extra_options.items(): options.append(option) opt_list = [] for name, val in options: opt = dhcpopts.format_for_pnr(name, val) if opt: opt_list.append(opt) if opt_list: data = {'optionList': {'OptionItem': opt_list}} else: data = {'optionList': {'list': []}} return cls(data)
def test_policy_from_port(self, mock_client): policy = model.Policy.from_neutron_port(fake_networks.fake_net1, fake_networks.fake_port1) opts_list = fake_networks.fake_port1.extra_dhcp_opts opt_list_pnr_format = [ dhcpopts.format_for_pnr(opts_list[i].opt_name, opts_list[i].opt_value) for i in range(len(opts_list)) ] expected = {"OptionItem": opt_list_pnr_format} self.assertEqual(expected, policy.data["optionList"])
def test_policy_from_port(self, mock_client): policy = model.Policy.from_neutron_port(fake_networks.fake_net1, fake_networks.fake_port1) opts_list = fake_networks.fake_port1.extra_dhcp_opts opt_list_pnr_format = [dhcpopts.format_for_pnr(opts_list[i].opt_name, opts_list[i].opt_value) for i in range(len(opts_list))] expected = {'OptionItem': opt_list_pnr_format} self.assertEqual(expected, policy.data['optionList'])
def from_neutron_port(cls, network, port): opt_list = [] if hasattr(port, 'extra_dhcp_opts'): for opt in port.extra_dhcp_opts: opt = dhcpopts.format_for_pnr(opt.opt_name, opt.opt_value) if opt: opt_list.append(opt) if opt_list: data = {'optionList': {'OptionItem': opt_list}} else: data = {'optionList': {'list': []}} return cls(data)
def test_policy_from_subnet(self, mock_client): fake_network = fake_networks.fake_net1 fake_subnet = fake_networks.fake_subnet1 policy = model.Policy.from_neutron_subnet(fake_network, fake_subnet) # DNS servers and static routes should correspond to values in # fake_networks.fake_subnet1 fake_policy_opts = [ ("routers", fake_subnet.gateway_ip), ("domain-name-servers", "8.8.8.8"), ("classless-static-routes", "18:28:00:01:28:00:00:02"), ("dhcp-lease-time", str(cfg.CONF.dhcp_lease_duration)), ("domain-name", cfg.CONF.dhcp_domain), ] policy_list_pnr_format = [dhcpopts.format_for_pnr(name, val) for name, val in fake_policy_opts] expected = {"OptionItem": policy_list_pnr_format} self.assertEqual(expected, policy.data["optionList"])
def test_policy_from_subnet(self, mock_client): fake_network = fake_networks.fake_net1 fake_subnet = fake_networks.fake_subnet1 policy = model.Policy.from_neutron_subnet(fake_network, fake_subnet) # DNS servers and static routes should correspond to values in # fake_networks.fake_subnet1 fake_policy_opts = [('routers', fake_subnet.gateway_ip), ('domain-name-servers', '8.8.8.8'), ('classless-static-routes', '18:28:00:01:28:00:00:02'), ('dhcp-lease-time', str(cfg.CONF.dhcp_lease_duration)), ('domain-name', cfg.CONF.dhcp_domain)] policy_list_pnr_format = [dhcpopts.format_for_pnr(name, val) for name, val in fake_policy_opts] expected = {'OptionItem': policy_list_pnr_format} self.assertEqual(expected, policy.data['optionList'])