Total Complexity | 4 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | # -*- coding: utf-8 -*- |
||
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 |