from osmclient.common.exceptions import NotFound
import json
import yaml
+import logging
class Role(object):
def __init__(self, http=None, client=None):
self._http = http
self._client = client
+ self._logger = logging.getLogger('osmclient')
self._apiName = '/admin'
self._apiVersion = '/v1'
self._apiResource = '/roles'
:raises ClientException: when receives an unexpected from the server.
:raises ClientException: when fails creating a role.
"""
+ self._logger.debug("")
self._client.get_token()
role = {"name": name}
:raises ClientException: when receives an unexpected response from the server.
:raises ClientException: when fails updating a role.
"""
+ self._logger.debug("")
self._client.get_token()
if new_name is None and permissions is None and add is None and remove is None:
raise ClientException('At least one option should be provided')
if not new_role_obj["permissions"]:
del new_role_obj["permissions"]
- http_code, resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase, role_obj['_id']),
+ http_code, resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase, role_obj['_id']),
postfields_dict=new_role_obj)
# print('HTTP CODE: {}'.format(http_code))
# print('RESP: {}'.format(resp))
:param force:
:raises ClientException: when fails to delete a role.
"""
+ self._logger.debug("")
self._client.get_token()
role = self.get(name)
querystring = ''
:param filter:
:returns:
"""
+ self._logger.debug("")
self._client.get_token()
filter_string = ''
if filter:
:raises NotFound: when the role is not found.
:returns: the specified role.
"""
+ self._logger.debug("")
self._client.get_token()
if utils.validate_uuid4(name):
for role in self.list():
if name == role['name']:
return role
raise NotFound("Role {} not found".format(name))
+