diff options
author | Thomas Duval <thomas.duval@orange.com> | 2020-06-03 10:06:52 +0200 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2020-06-03 10:06:52 +0200 |
commit | 7bb53c64da2dcf88894bfd31503accdd81498f3d (patch) | |
tree | 4310e12366818af27947b5e2c80cb162da93a4b5 /moon_manager/moon_manager/api/information | |
parent | cbea4e360e9bfaa9698cf7c61c83c96a1ba89b8c (diff) |
Update to new version 5.4HEADstable/jermamaster
Signed-off-by: Thomas Duval <thomas.duval@orange.com>
Change-Id: Idcd868133d75928a1ffd74d749ce98503e0555ea
Diffstat (limited to 'moon_manager/moon_manager/api/information')
4 files changed, 281 insertions, 0 deletions
diff --git a/moon_manager/moon_manager/api/information/__init__.py b/moon_manager/moon_manager/api/information/__init__.py new file mode 100644 index 00000000..582be686 --- /dev/null +++ b/moon_manager/moon_manager/api/information/__init__.py @@ -0,0 +1,11 @@ +# Software Name: MOON + +# Version: 5.4 + +# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors +# SPDX-License-Identifier: Apache-2.0 + +# This software is distributed under the 'Apache License 2.0', +# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt' +# or see the "LICENSE" file for more details. + diff --git a/moon_manager/moon_manager/api/information/global_attrs.py b/moon_manager/moon_manager/api/information/global_attrs.py new file mode 100644 index 00000000..21b21445 --- /dev/null +++ b/moon_manager/moon_manager/api/information/global_attrs.py @@ -0,0 +1,145 @@ +# Software Name: MOON + +# Version: 5.4 + +# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors +# SPDX-License-Identifier: Apache-2.0 + +# This software is distributed under the 'Apache License 2.0', +# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt' +# or see the "LICENSE" file for more details. + +""" +API to gather information from external component like OpenStack +""" + +from uuid import uuid4 +import logging +from moon_utilities.security_functions import enforce +from moon_manager.api.information.managers import Managers + +LOGGER = logging.getLogger("moon.manager.information.global_attrs") + + +class GlobalAttrsManager(Managers): + """ + Manager use to get information from external components + """ + + def __init__(self, connector=None): + self.driver = connector.driver + Managers.GlobalAttrsManager = self + + def set_auth(self, **kwargs): + """Set authorizations if necessary + + :param kwargs: arguments which are necessary to login to the server + :return: headers to use + """ + return self.driver.set_auth(**kwargs) + + def unset_auth(self, **kwargs): + """Unset the authorization is necessary + + :param kwargs: arguments which are necessary to logout to the server + :return: headers to use + """ + return self.driver.unset_auth(**kwargs) + + @enforce("read", "pip") + def get_users(self, user_id=None, **kwargs): + """List users in the server + + :param user_id: the user name or user ID + :param kwargs: all arguments necessary to list users + :return: a list of users + """ + return self.driver.get_users(user_id=user_id, **kwargs) + + @enforce("write", "pip") + def add_user(self, user_id=None, **kwargs): + """Add a user in the server + + :param user_id: the user name or user ID + :param kwargs: all arguments necessary to add a user + :return: the user added + """ + if not user_id: + user_id = uuid4().hex + return self.driver.add_user(user_id=user_id, **kwargs) + + @enforce(("read", "write"), "pip") + def update_user(self, user_id, **kwargs): + """Update a user in the server + + :param user_id: the user name or user ID + :param kwargs: all arguments necessary to update the user + :return: the user updated + """ + return self.driver.update_user(user_id=user_id, **kwargs) + + @enforce("write", "pip") + def delete_user(self, user_id, **kwargs): + """Delete a user in the server + + :param user_id: the user name or user ID + :param kwargs: all arguments necessary to delete the user + :return: True if the user has been deleted + """ + return self.driver.delete_user(user_id=user_id, **kwargs) + + @enforce("read", "pip") + def get_objects(self, object_id=None, object_type=None, **kwargs): + """List objects in the server + + :param object_id: the object name or user ID + :param object_type: the object type (project, vms, ...) + :param kwargs: all arguments necessary to list the object + :return: a list of objects + """ + return self.driver.get_objects(object_id=object_id, object_type=object_type, **kwargs) + + @enforce("read", "pip") + def get_object(self, object_type, **kwargs): + """List objects in the server + + :param object_type: the object type (project, vms, ...) + :param kwargs: all arguments necessary to list the object + :return: a list of objects + """ + return self.driver.get_object(object_type=object_type, **kwargs) + + @enforce("write", "pip") + def add_object(self, object_id=None, object_type=None, **kwargs): + """Add an object in the server + + :param object_id: the object name or user ID + :param object_type: the object type (project, vms, ...) + :param kwargs: all arguments necessary to add the object + :return: the object added + """ + if not object_id: + object_id = uuid4().hex + return self.driver.add_object(object_id=object_id, object_type=object_type, **kwargs) + + @enforce(("read", "write"), "pip") + def update_object(self, object_id, object_type=None, **kwargs): + """Update an object in the server + + :param object_id: the object name or user ID + :param object_type: the object type (project, vms, ...) + :param kwargs: all arguments necessary to update the object + :return: the object updated + """ + return self.driver.update_object(object_id=object_id, object_type=object_type, **kwargs) + + @enforce("write", "pip") + def delete_object(self, object_id=None, object_type=None, **kwargs): + """Delete an object in the server + + :param object_id: the object name or user ID + :param object_type: the object type (project, vms, ...) + :param kwargs: all arguments necessary to delete the object + :return: True if the object has been deleted + """ + return self.driver.delete_object(object_id=object_id, object_type=object_type, **kwargs) diff --git a/moon_manager/moon_manager/api/information/information.py b/moon_manager/moon_manager/api/information/information.py new file mode 100644 index 00000000..132b8bce --- /dev/null +++ b/moon_manager/moon_manager/api/information/information.py @@ -0,0 +1,106 @@ +# Software Name: MOON + +# Version: 5.4 + +# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors +# SPDX-License-Identifier: Apache-2.0 + +# This software is distributed under the 'Apache License 2.0', +# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt' +# or see the "LICENSE" file for more details. + +""" +API to gather information from external component like OpenStack +""" + +from uuid import uuid4 +import logging +from moon_utilities.security_functions import enforce +from moon_manager.api.information.managers import Managers + +LOGGER = logging.getLogger("moon.manager.information.api.information") + + +class InformationManager(Managers): + """ + Manager use to get information from external components + """ + + def __init__(self, connector=None): + self.driver = connector.driver + Managers.InformationManager = self + + def set_auth(self, **kwargs): + """Set authorizations if necessary + + :param kwargs: arguments which are necessary to login to the server + :return: headers to use + """ + return self.driver.set_auth(**kwargs) + + def unset_auth(self, **kwargs): + """Unset the authorization is necessary + + :param kwargs: arguments which are necessary to logout to the server + :return: headers to use + """ + return self.driver.unset_auth(**kwargs) + + @enforce("read", "pip") + def get_items(self, item_id=None, **kwargs): + """List items in the server + + :param item_id: the item name or item ID + :param kwargs: all arguments necessary to list items + :return: a list of items + """ + return self.driver.get_items(item_id=item_id, **kwargs) + + @enforce("write", "pip") + def add_item(self, item_id=None, **kwargs): + """Add a item in the server + + :param item_id: the item name or item ID + :param kwargs: all arguments necessary to add a item + :return: the item added + """ + if not item_id: + item_id = uuid4().hex + return self.driver.add_item(item_id=item_id, **kwargs) + + @enforce(("read", "write"), "pip") + def update_item(self, item_id, **kwargs): + """Update a item in the server + + :param item_id: the item name or item ID + :param kwargs: all arguments necessary to update the item + :return: the item updated + """ + return self.driver.update_item(item_id=item_id, **kwargs) + + @enforce("write", "pip") + def delete_item(self, item_id, **kwargs): + """Delete a item in the server + + :param item_id: the item name or item ID + :param kwargs: all arguments necessary to delete the item + :return: True if the item has been deleted + """ + return self.driver.delete_item(item_id=item_id, **kwargs) + + @enforce("read", "pip") + def get_projects(self): + """List projects in the server + + :return: the list of projects + """ + return self.driver.get_projects() + + @enforce("write", "pip") + def create_project(self, **tenant_dict): + """Create a project in the server + + :param tenant_dict: all arguments necessary to create a project + :return: True if the item has been deleted + """ + return self.driver.create_project(**tenant_dict) diff --git a/moon_manager/moon_manager/api/information/managers.py b/moon_manager/moon_manager/api/information/managers.py new file mode 100644 index 00000000..23aff8f5 --- /dev/null +++ b/moon_manager/moon_manager/api/information/managers.py @@ -0,0 +1,19 @@ +# Software Name: MOON + +# Version: 5.4 + +# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors +# SPDX-License-Identifier: Apache-2.0 + +# This software is distributed under the 'Apache License 2.0', +# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt' +# or see the "LICENSE" file for more details. + +""" +Group all managers for this API +""" + + +class Managers(object): + """Object that links managers together""" + InformationManager = None |