コード例 #1
0
    def __init__(self,
                 sub_options: Iterable[NTPSubOption],
                 always_send: bool = False):
        option = NTPServersOption(options=sub_options)
        option.validate()

        super().__init__(option, always_send=always_send)
コード例 #2
0
 def setUp(self):
     self.option_bytes = bytes.fromhex('0038004b'
                                       '0001001020010db8000000000000000000000001'
                                       '00020010ff12000000000000000000000000abcd'
                                       '00030011') + b'\x03ntp\x08steffann\x02nl\x00' + \
                         bytes.fromhex('ffff000a') + b'RandomData'
     self.option_object = NTPServersOption(options=[
         NTPServerAddressSubOption(IPv6Address('2001:db8::1')),
         NTPMulticastAddressSubOption(IPv6Address('ff12::abcd')),
         NTPServerFQDNSubOption('ntp.steffann.nl.'),
         UnknownNTPSubOption(65535, b'RandomData'),
     ])
     self.parse_option()
コード例 #3
0
    def combine(
            self,
            existing_options: Iterable[NTPServersOption]) -> NTPServersOption:
        """
        Combine multiple options into one.

        :param existing_options: The existing options to include NTP servers from
        :return: The combined option
        """
        sub_options = []

        # Add from existing options first
        for option in existing_options:
            for sub_option in option.options:
                if sub_option not in sub_options:
                    sub_options.append(sub_option)

        # Then add our own
        for sub_option in self.option.dns_servers:
            if sub_option not in sub_options:
                sub_options.append(sub_option)

        # And return a new option with the combined addresses
        return NTPServersOption(options=sub_options)
コード例 #4
0
ファイル: __init__.py プロジェクト: corinnepritchard/dhcpkit
    def __init__(self, sub_options: Iterable[NTPSubOption], always_send: bool = False):
        option = NTPServersOption(options=sub_options)
        option.validate()

        super().__init__(option, always_send=always_send)
コード例 #5
0
 def test_bad_option_length(self):
     with self.assertRaisesRegex(ValueError, 'does not match the combined length'):
         NTPServersOption.parse(bytes.fromhex('003800130001001020010db8000000000000000000000001'))
コード例 #6
0
ファイル: test_ntp.py プロジェクト: sjm-steffann/dhcpkit
 def test_bad_option_length(self):
     with self.assertRaisesRegex(ValueError, 'does not match the combined length'):
         NTPServersOption.parse(bytes.fromhex('003800130001001020010db8000000000000000000000001'))
コード例 #7
0
ファイル: ntp.py プロジェクト: mndfcked/dhcpkit
    def __init__(self, sub_options: [NTPSubOption]):
        option = NTPServersOption(options=sub_options)
        option.validate()

        super().__init__(option)