Beispiel #1
0
    def _correct_instance_id(self, id):
        '''
        Azure stores the instance ID with an incorrect byte ordering for the
        first parts. For example, the ID returned by the metadata service:

            D0DF4C54-4ECB-4A4B-9954-5BDF3ED5C3B8

        will be found as:

            544CDFD0-CB4E-4B4A-9954-5BDF3ED5C3B8

        This code corrects the byte order such that it is consistent with
        that returned by the metadata service.
        '''

        if not UUID_PATTERN.match(id):
            return id

        parts = id.split('-')
        return '-'.join([
                textutil.swap_hexstring(parts[0], width=2),
                textutil.swap_hexstring(parts[1], width=2),
                textutil.swap_hexstring(parts[2], width=2),
                parts[3],
                parts[4]
            ])
Beispiel #2
0
    def _correct_instance_id(self, id):
        '''
        Azure stores the instance ID with an incorrect byte ordering for the
        first parts. For example, the ID returned by the metadata service:

            D0DF4C54-4ECB-4A4B-9954-5BDF3ED5C3B8

        will be found as:

            544CDFD0-CB4E-4B4A-9954-5BDF3ED5C3B8

        This code corrects the byte order such that it is consistent with
        that returned by the metadata service.
        '''

        if not UUID_PATTERN.match(id):
            return id

        parts = id.split('-')
        return '-'.join([
                textutil.swap_hexstring(parts[0], width=2),
                textutil.swap_hexstring(parts[1], width=2),
                textutil.swap_hexstring(parts[2], width=2),
                parts[3],
                parts[4]
            ])
    def test_swap_hexstring(self):
        data = [
            ['12', 1, '21'],
            ['12', 2, '12'],
            ['12', 3, '012'],
            ['12', 4, '0012'],

            ['123', 1, '321'],
            ['123', 2, '2301'],
            ['123', 3, '123'],
            ['123', 4, '0123'],

            ['1234', 1, '4321'],
            ['1234', 2, '3412'],
            ['1234', 3, '234001'],
            ['1234', 4, '1234'],

            ['abcdef12', 1, '21fedcba'],
            ['abcdef12', 2, '12efcdab'],
            ['abcdef12', 3, 'f12cde0ab'],
            ['abcdef12', 4, 'ef12abcd'],

            ['aBcdEf12', 1, '21fEdcBa'],
            ['aBcdEf12', 2, '12EfcdaB'],
            ['aBcdEf12', 3, 'f12cdE0aB'],
            ['aBcdEf12', 4, 'Ef12aBcd']
        ]

        for t in data:
            self.assertEqual(t[2], textutil.swap_hexstring(t[0], width=t[1]))
Beispiel #4
0
    def test_swap_hexstring(self):
        data = [
            ['12', 1, '21'],
            ['12', 2, '12'],
            ['12', 3, '012'],
            ['12', 4, '0012'],

            ['123', 1, '321'],
            ['123', 2, '2301'],
            ['123', 3, '123'],
            ['123', 4, '0123'],

            ['1234', 1, '4321'],
            ['1234', 2, '3412'],
            ['1234', 3, '234001'],
            ['1234', 4, '1234'],

            ['abcdef12', 1, '21fedcba'],
            ['abcdef12', 2, '12efcdab'],
            ['abcdef12', 3, 'f12cde0ab'],
            ['abcdef12', 4, 'ef12abcd'],

            ['aBcdEf12', 1, '21fEdcBa'],
            ['aBcdEf12', 2, '12EfcdaB'],
            ['aBcdEf12', 3, 'f12cdE0aB'],
            ['aBcdEf12', 4, 'Ef12aBcd']
        ]

        for t in data:
            self.assertEqual(t[2], textutil.swap_hexstring(t[0], width=t[1]))