|
13 | 13 | # under the License. |
14 | 14 | # |
15 | 15 | from cloudkittyclient.common import base |
| 16 | +from cloudkittyclient import exc |
16 | 17 |
|
17 | 18 |
|
18 | 19 | class ScopeManager(base.BaseManager): |
@@ -48,3 +49,54 @@ def get_scope_state(self, **kwargs): |
48 | 49 | 'offset', 'limit', 'collector', 'fetcher', 'scope_id', 'scope_key'] |
49 | 50 | url = self.get_url(None, kwargs, authorized_args=authorized_args) |
50 | 51 | return self.api_client.get(url).json() |
| 52 | + |
| 53 | + def reset_scope_state(self, **kwargs): |
| 54 | + """Returns nothing. |
| 55 | +
|
| 56 | + Some optional filters can be provided. |
| 57 | + The all_scopes and the scope_id options are mutually exclusive and one |
| 58 | + must be provided. |
| 59 | +
|
| 60 | + :param state: datetime object from which the state will be reset |
| 61 | + :type state: datetime.datetime |
| 62 | + :param all_scopes: Whether all scopes must be reset |
| 63 | + :type all_scopes: bool |
| 64 | + :param collector: Optional collector to filter on. |
| 65 | + :type collector: str or list of str |
| 66 | + :param fetcher: Optional fetcher to filter on. |
| 67 | + :type fetcher: str or list of str |
| 68 | + :param scope_id: Optional scope_id to filter on. |
| 69 | + :type scope_id: str or list of str |
| 70 | + :param scope_key: Optional scope_key to filter on. |
| 71 | + :type scope_key: str or list of str |
| 72 | + """ |
| 73 | + |
| 74 | + if not kwargs.get('state'): |
| 75 | + raise exc.ArgumentRequired("'state' argument is required") |
| 76 | + |
| 77 | + if not kwargs.get('all_scopes') and not kwargs.get('scope_id'): |
| 78 | + raise exc.ArgumentRequired( |
| 79 | + "You must specify either 'scope_id' or 'all_scopes'") |
| 80 | + |
| 81 | + if kwargs.get('all_scopes') and kwargs.get('scope_id'): |
| 82 | + raise exc.InvalidArgumentError( |
| 83 | + "You can't specify both 'scope_id' and 'all_scopes'") |
| 84 | + |
| 85 | + for key in ('collector', 'fetcher', 'scope_id', 'scope_key'): |
| 86 | + if key in kwargs.keys(): |
| 87 | + if isinstance(kwargs[key], list): |
| 88 | + kwargs[key] = ','.join(kwargs[key]) |
| 89 | + |
| 90 | + body = dict( |
| 91 | + state=kwargs.get('state'), |
| 92 | + scope_id=kwargs.get('scope_id'), |
| 93 | + scope_key=kwargs.get('scope_key'), |
| 94 | + collector=kwargs.get('collector'), |
| 95 | + fetcher=kwargs.get('fetcher'), |
| 96 | + all_scopes=kwargs.get('all_scopes'), |
| 97 | + ) |
| 98 | + # Stripping None and False values |
| 99 | + body = dict(filter(lambda elem: bool(elem[1]), body.items())) |
| 100 | + |
| 101 | + url = self.get_url(None, kwargs) |
| 102 | + return self.api_client.put(url, json=body) |
0 commit comments