MetadataAPI.get_metadata()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
1
# -*- coding: utf-8 -*-
2
#
3
# Copyright (c) 2013-2016 Online SAS and Contributors. All Rights Reserved.
4
#                         Julien Castets <[email protected]>
5
#
6
# Licensed under the BSD 2-Clause License (the "License"); you may not use this
7
# file except in compliance with the License. You may obtain a copy of the
8
# License at https://opensource.org/licenses/BSD-2-Clause
9
10
from . import API
11
12
13
class MetadataAPI(API):
14
    """ The metadata API is used to get info about a running instance.
15
16
    To authenticate the client, the API uses its IP address. The header
17
    X-Auth-Token is not needed.
18
    """
19
20
    base_url = 'http://169.254.42.42/'
21
22
    def __init__(self, **kwargs):
23
24
        assert 'auth_token' not in kwargs, \
25
            'auth_token is not required to query the metadata API'
26
27
        super(MetadataAPI, self).__init__(auth_token=None, **kwargs)
28
29
    def get_metadata(self, as_shell=False):
30
        """ Returns server metadata.
31
32
        If `as_shell` is True, return a string easily parsable by a shell. If
33
        False, return a dictionary.
34
        """
35
        if as_shell:
36
            return self.query().conf.get()
37
        return self.query().conf.get(format='json')
38