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 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 test_format_for_options_unknown_option(self, mock_format): expected = None value = dhcpopts.format_for_options('someoption', 'somevalue') self.assertEqual(expected, value)
def test_format_for_options_exception(self, mock_format): expected = '' mock_format.get.side_effect = Exception value = dhcpopts.format_for_options('subnet-mask', '10.10.0.1') self.assertEqual(expected, value)
def test_format_for_domain_name_options(self): expected = '65:78:61:6d:70:6c:65:2e:63:6f:6d:2e' value = dhcpopts.format_for_options('domain-name', 'example.com.') self.assertEqual(expected, value)
def test_format_for_dhcp_renewal_time_options(self): expected = '00:00:01:2c' value = dhcpopts.format_for_options('dhcp-renewal-time', 300) self.assertEqual(expected, value)
def test_format_for_ip_forwarding_options(self): expected = '01' flag = True value = dhcpopts.format_for_options('ip-forwarding', flag) self.assertEqual(expected, value)
def test_format_for_classless_static_routes_options(self): expected = '20:a9:fe:a9:fe:0a:0a:00:02' value = dhcpopts.format_for_options('classless-static-routes', '32.169.254.169.254 10.10.0.2') self.assertEqual(expected, value)