yakumo.keystone.v2.project

Package yakumo :: Package keystone :: Package v2 :: Module project |
[hide private]
[frames] | no frames]

# Source Code for Module yakumo.keystone.v2.project

      1  # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>.
      2  # All Rights Reserved.
      3  #
      4  #    Licensed under the Apache License, Version 2.0 (the "License"); you may
      5  #    not use this file except in compliance with the License. You may obtain
      6  #    a copy of the License at
      7  #
      8  #         http://www.apache.org/licenses/LICENSE-2.0
      9  #
     10  #    Unless required by applicable law or agreed to in writing, software
     11  #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     12  #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  #    License for the specific language governing permissions and limitations
     14  #    under the License.
     15
     16  """
     17  Resource class and its manager for projects in Identity V2 API
     18  """
     19
     20  from yakumo import base
     21  from yakumo.constant import UNDEF
     22  from yakumo import mapper
     23
     24
     25  ATTRIBUTE_MAPPING = [
     26      ('id', 'id', mapper.Noop),
     27      ('name', 'name', mapper.Noop),
     28      ('description', 'description', mapper.Noop),
     29      ('is_enabled', 'enabled', mapper.Noop),
     30  ]
     31
     32
     33 -class Resource(base.Resource):
     34      """resource class for projects on Identity V2 API"""
     35
     36 -    def update(self, name=UNDEF, description=UNDEF, is_enabled=UNDEF):
     37          """
     38          Update properties of a project
     39
     40          @keyword name: Project name
     41          @type name: str
     42          @keyword description: Description
     43          @type description: str
     44          @keyword is_enabled: Whether the project is enabled or not
     45          @type is_enabled: bool
     46          @rtype: None
     47          """
     48          super(Resource, self).update(
     49              name=name,
     50              description=description,
     51              is_enabled=is_enabled)
     52
     53 -    def grant_roles(self, users=None, roles=None):
     54          """
     55          Grant roles to users for a project
     56
     57          @keyword users: List of users
     58          @type users: [keystone.user.Resource]
     59          @keyword roles: List of roles
     60          @type roles: [keystone.role.Resource]
     61          @rtype: None
     62          """
     63          if not isinstance(users, list):
     64              users = [users]
     65          if not isinstance(roles, list):
     66              roles = [roles]
     67          for role in roles:
     68              for user in users:
     69                  self._http.put(self._url_resource_path, self._id,
     70                                 "users", user.get_id(),
     71                                 "roles/OS-KSADM", role.get_id())
     72
     73 -    def revoke_roles(self, users=None, roles=None):
     74          """
     75          Revoke roles from users for a project
     76
     77          @keyword users: List of users
     78          @type users: [keystone.user.Resource]
     79          @keyword roles: List of roles
     80          @type roles: [keystone.role.Resource]
     81          @rtype: None
     82          """
     83          if not isinstance(users, list):
     84              users = [users]
     85          if not isinstance(roles, list):
     86              roles = [roles]
     87          for role in roles:
     88              for user in users:
     89                  self._http.delete(self._url_resource_path, self._id,
     90                                    "users", user.get_id(),
     91                                    "roles/OS-KSADM", role.get_id())
     92
     93
     94 -class Manager(base.Manager):
     95      """manager class for projects on Identity V2 API"""
     96
     97      resource_class = Resource
     98      service_type = 'identity'
     99      _attr_mapping = ATTRIBUTE_MAPPING
    100      _json_resource_key = 'tenant'
    101      _json_resources_key = 'tenants'
    102      _url_resource_path = '/tenants'
    103
    104 -    def create(self, name=UNDEF, description=UNDEF, is_enabled=UNDEF):
    105          """
    106          Register a project
    107
    108          @keyword name: Project name
    109          @type name: str
    110          @keyword description: Description
    111          @type description: str
    112          @keyword is_enabled: Whether the project is enabled or not
    113          @type is_enabled: bool
    114          @return: Created project
    115          @rtype: yakumo.keystone.v2.project.Resource
    116          """
    117          return super(Manager, self).create(
    118              name=name,
    119              description=description,
    120              is_enabled=is_enabled)
    121