-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from openvstorage/develop
Promote
- Loading branch information
Showing
23 changed files
with
969 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,6 @@ | |
"source_contents": "--transform 's,^,{0}-{1}/,' src *.txt", | ||
"version": { | ||
"major": 0, | ||
"minor": 4 | ||
"minor": 5 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (C) 2018 iNuron NV | ||
# | ||
# This file is part of Open vStorage Open Source Edition (OSE), | ||
# as available from | ||
# | ||
# http://www.openvstorage.org and | ||
# http://www.openvstorage.com. | ||
# | ||
# This file is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Affero General Public License v3 (GNU AGPLv3) | ||
# as published by the Free Software Foundation, in version 3 as it comes | ||
# in the LICENSE.txt file of the Open vStorage OSE distribution. | ||
# | ||
# Open vStorage is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY of any kind. | ||
|
||
# Backwards compatibility & easier importing | ||
from .baseclient import BaseClient | ||
from .ovsclient import OVSClient | ||
from .simpleclient import SimpleClient | ||
|
||
__all__ = ["BaseClient", "OVSClient", "SimpleClient"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (C) 2018 iNuron NV | ||
# | ||
# This file is part of Open vStorage Open Source Edition (OSE), | ||
# as available from | ||
# | ||
# http://www.openvstorage.org and | ||
# http://www.openvstorage.com. | ||
# | ||
# This file is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Affero General Public License v3 (GNU AGPLv3) | ||
# as published by the Free Software Foundation, in version 3 as it comes | ||
# in the LICENSE.txt file of the Open vStorage OSE distribution. | ||
# | ||
# Open vStorage is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY of any kind. | ||
import time | ||
from .baseclient import BaseClient | ||
|
||
|
||
class OVSClient(BaseClient): | ||
|
||
def wait_for_task(self, task_id, timeout=None): | ||
""" | ||
Waits for a task to complete | ||
:param task_id: Task to wait for | ||
:param timeout: Time to wait for task before raising | ||
""" | ||
start = time.time() | ||
finished = False | ||
previous_metadata = None | ||
while finished is False: | ||
if timeout is not None and timeout < (time.time() - start): | ||
raise RuntimeError('Waiting for task {0} has timed out.'.format(task_id)) | ||
task_metadata = self.get('/tasks/{0}/'.format(task_id)) | ||
finished = task_metadata['status'] in ('FAILURE', 'SUCCESS') | ||
if finished is False: | ||
if task_metadata != previous_metadata: | ||
self._logger.debug('Waiting for task {0}, got: {1}'.format(task_id, task_metadata)) | ||
previous_metadata = task_metadata | ||
else: | ||
self._logger.debug('Still waiting for task {0}...'.format(task_id)) | ||
time.sleep(1) | ||
else: | ||
self._logger.debug('Task {0} finished, got: {1}'.format(task_id, task_metadata)) | ||
return task_metadata['successful'], task_metadata['result'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright (C) 2018 iNuron NV | ||
# | ||
# This file is part of Open vStorage Open Source Edition (OSE), | ||
# as available from | ||
# | ||
# http://www.openvstorage.org and | ||
# http://www.openvstorage.com. | ||
# | ||
# This file is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Affero General Public License v3 (GNU AGPLv3) | ||
# as published by the Free Software Foundation, in version 3 as it comes | ||
# in the LICENSE.txt file of the Open vStorage OSE distribution. | ||
# | ||
# Open vStorage is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY of any kind. | ||
import base64 | ||
from .baseclient import BaseClient | ||
|
||
|
||
class SimpleClient(BaseClient): | ||
""" | ||
Simple API client | ||
- No JWT | ||
- No caching | ||
- No versioning | ||
- No verification | ||
- Authorization with username/password | ||
""" | ||
def __init__(self, ip, port, credentials=None): | ||
""" | ||
Initializes the object with credentials and connection information | ||
:param ip: IP to which to connect | ||
:type ip: str | ||
:param port: Port on which to connect | ||
:type port: int | ||
:param credentials: Credentials to connect | ||
:type credentials: tuple | ||
:return: None | ||
:rtype: NoneType | ||
""" | ||
super(SimpleClient, self).__init__(ip, port, credentials) | ||
self._url = 'https://{0}:{1}/'.format(ip, port) | ||
|
||
def _build_headers(self): | ||
""" | ||
Builds the request headers | ||
:return: The request headers | ||
:rtype: dict | ||
""" | ||
headers = {'Accept': 'application/json; version={0}'.format(self._version), | ||
'Content-Type': 'application/json'} | ||
if self._token is not None: | ||
headers['Authorization'] = 'Basic {0}'.format(base64.b64encode('{0}:{1}'.format(self.client_id, self.client_secret)).strip()) | ||
return headers |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright (C) 2017 iNuron NV | ||
# | ||
# This file is part of Open vStorage Open Source Edition (OSE), | ||
# as available from | ||
# | ||
# http://www.openvstorage.org and | ||
# http://www.openvstorage.com. | ||
# | ||
# This file is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Affero General Public License v3 (GNU AGPLv3) | ||
# as published by the Free Software Foundation, in version 3 as it comes | ||
# in the LICENSE.txt file of the Open vStorage OSE distribution. | ||
# | ||
# Open vStorage is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY of any kind. | ||
|
||
""" | ||
API decorators | ||
""" | ||
|
||
from functools import wraps | ||
|
||
|
||
class HTTPRequestGenericDecorators(object): | ||
|
||
@classmethod | ||
def wrap_data(cls, data_type='data'): | ||
""" | ||
Wrap the API data in a dict with given_key | ||
Eg. | ||
def xyz: return <Data> | ||
@wrap_data('data_type') | ||
def xyz: return {'data_type': <Data>} | ||
""" | ||
|
||
def wrapper(f): | ||
""" | ||
Wrapper function | ||
""" | ||
|
||
@wraps(f) | ||
def new_function(*args, **kwargs): | ||
""" | ||
Return the | ||
""" | ||
results = f(*args, **kwargs) | ||
d = {data_type: results} | ||
if data_type != 'data': # no data key present yet | ||
d['data'] = results | ||
return d | ||
return new_function | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.