|  | 
|  | 1 | +import logging | 
|  | 2 | + | 
|  | 3 | +log = logging.getLogger(__name__) | 
|  | 4 | + | 
|  | 5 | +""" | 
|  | 6 | +Tenant APIs only supported in ECS Flex | 
|  | 7 | +""" | 
|  | 8 | + | 
|  | 9 | + | 
|  | 10 | +class Tenant(object): | 
|  | 11 | +    def __init__(self, connection): | 
|  | 12 | +        """ | 
|  | 13 | +        Initialize a new instance | 
|  | 14 | +        """ | 
|  | 15 | +        self.conn = connection | 
|  | 16 | + | 
|  | 17 | +    def list(self): | 
|  | 18 | +        """ | 
|  | 19 | +        Gets the identifiers for all configured tenants. | 
|  | 20 | +
 | 
|  | 21 | +        Required role(s): | 
|  | 22 | +
 | 
|  | 23 | +        SYSTEM_ADMIN | 
|  | 24 | +        SYSTEM_MONITOR | 
|  | 25 | +
 | 
|  | 26 | +        Example JSON result from the API: | 
|  | 27 | +
 | 
|  | 28 | +        { | 
|  | 29 | +            u'tenant': [ | 
|  | 30 | +                { | 
|  | 31 | +                    u'id': u'tenant1' | 
|  | 32 | +                } | 
|  | 33 | +            ] | 
|  | 34 | +        } | 
|  | 35 | +        """ | 
|  | 36 | +        log.info("Getting all tenants") | 
|  | 37 | +        return self.conn.get(url='object/tenants') | 
|  | 38 | + | 
|  | 39 | +    def get(self, tenant): | 
|  | 40 | +        """ | 
|  | 41 | +        Gets the details for the given tenant. | 
|  | 42 | +
 | 
|  | 43 | +        Required role(s): | 
|  | 44 | +
 | 
|  | 45 | +        SYSTEM_ADMIN | 
|  | 46 | +        SYSTEM_MONITOR | 
|  | 47 | +        TENANT_ADMIN | 
|  | 48 | +
 | 
|  | 49 | +        :param tenant: Tenant identifier for which details needs to | 
|  | 50 | +        be retrieved. | 
|  | 51 | +        """ | 
|  | 52 | +        log.info("Getting info for tenant '{0}'".format(tenant)) | 
|  | 53 | + | 
|  | 54 | +        return self.conn.get( | 
|  | 55 | +            url='object/tenants/tenant/{0}'.format(tenant)) | 
|  | 56 | + | 
|  | 57 | +    def create(self, account, default_data_services_vpool=None, | 
|  | 58 | +               is_encryption_enabled=False, default_bucket_block_size=None): | 
|  | 59 | +        """ | 
|  | 60 | +        Creates a namespace with the given details | 
|  | 61 | +
 | 
|  | 62 | +       Required role(s): | 
|  | 63 | +
 | 
|  | 64 | +       SYSTEM_ADMIN | 
|  | 65 | +
 | 
|  | 66 | +       Example JSON result from the API: | 
|  | 67 | +       { | 
|  | 68 | +            'account_id':account_id, | 
|  | 69 | +            'default_data_services_vpool': default_data_services_vpool, | 
|  | 70 | +            'default_bucket_block_size': default_bucket_block_size | 
|  | 71 | +            'is_encryption_enabled': is_encryption_enabled | 
|  | 72 | +       } | 
|  | 73 | +       """ | 
|  | 74 | +        payload = { | 
|  | 75 | +            'account_id': account, | 
|  | 76 | +            'default_bucket_block_size': default_bucket_block_size, | 
|  | 77 | +            'default_data_services_vpool': default_data_services_vpool, | 
|  | 78 | +            'is_encryption_enabled': is_encryption_enabled, | 
|  | 79 | +        } | 
|  | 80 | +        log.info("Creating tenant for account '{0}'".format(account)) | 
|  | 81 | +        return self.conn.post('object/tenants/tenant', json_payload=payload) | 
|  | 82 | + | 
|  | 83 | +    # def update(self, tenant_id, default_data_services_vpool=None, vpools_added_to_allowed_vpools_list=[], | 
|  | 84 | +    #            vpools_added_to_disallowed_vpools_list=[], vpools_removed_from_allowed_vpools_list=[], | 
|  | 85 | +    #            vpools_removed_from_disallowed_vpools_list=[], tenant_admins=None, user_mapping=None, | 
|  | 86 | +    #            default_bucket_block_size=None, external_group_admins=None, is_encryption_enabled=None, | 
|  | 87 | +    #            is_stale_allowed=None): | 
|  | 88 | +    #     """ | 
|  | 89 | +    #     Updates tenant details like replication group list, tenant admins and user mappings. | 
|  | 90 | +    #     Replication group can be: | 
|  | 91 | +    #         - Added to allowed or disallowed replication group list | 
|  | 92 | +    #         - Removed from allowed or disallowed replication group list | 
|  | 93 | +    # | 
|  | 94 | +    #     Required role(s): | 
|  | 95 | +    # | 
|  | 96 | +    #     SYSTEM_ADMIN | 
|  | 97 | +    #     TENANT_ADMIN | 
|  | 98 | +    # | 
|  | 99 | +    #     There is no response body for this call | 
|  | 100 | +    # | 
|  | 101 | +    #     Expect: HTTP/1.1 200 OK | 
|  | 102 | +    # | 
|  | 103 | +    #     :param tenant_id: Tenant identifier whose details needs to be updated | 
|  | 104 | +    #     :param default_data_services_vpool: Default replication group identifier when creating buckets | 
|  | 105 | +    #     :param vpools_added_to_allowed_vpools_list: List of replication group identifier which will be added in the | 
|  | 106 | +    #     allowed List for allowing tenant access | 
|  | 107 | +    #     :param vpools_added_to_disallowed_vpools_list: List of replication group identifier which will be added in the | 
|  | 108 | +    #     disallowed list for prohibiting tenant access | 
|  | 109 | +    #     :param vpools_removed_from_allowed_vpools_list: List of replication group identifier which will be removed | 
|  | 110 | +    #     from allowed list | 
|  | 111 | +    #     :param vpools_removed_from_disallowed_vpools_list: List of replication group identifier which will be removed | 
|  | 112 | +    #     from disallowed list for removing their prohibition tenant access | 
|  | 113 | +    #     :param tenant_admins: Comma separated list of tenant admins | 
|  | 114 | +    #     :param user_mapping: List of user mapping objects | 
|  | 115 | +    #     :param default_bucket_block_size: Default bucket quota size | 
|  | 116 | +    #     :param external_group_admins: List of groups from AD Server | 
|  | 117 | +    #     :param is_encryption_enabled: Update encryption for the tenant. If null then encryption will not be updated. | 
|  | 118 | +    #     :param is_stale_allowed: Flag to allow stale data within the tenant. If null then stale allowance will not be | 
|  | 119 | +    #     updated | 
|  | 120 | +    #     """ | 
|  | 121 | +    #     payload = { | 
|  | 122 | +    #         "default_data_services_vpool": default_data_services_vpool, | 
|  | 123 | +    #         "vpools_added_to_allowed_vpools_list": vpools_added_to_allowed_vpools_list, | 
|  | 124 | +    #         "vpools_added_to_disallowed_vpools_list": vpools_added_to_disallowed_vpools_list, | 
|  | 125 | +    #         "vpools_removed_from_allowed_vpools_list": vpools_removed_from_allowed_vpools_list, | 
|  | 126 | +    #         "vpools_removed_from_disallowed_vpools_list": vpools_removed_from_disallowed_vpools_list, | 
|  | 127 | +    #         "tenant_admins": tenant_admins, | 
|  | 128 | +    #         "user_mapping": user_mapping, | 
|  | 129 | +    #         "default_bucket_block_size": default_bucket_block_size, | 
|  | 130 | +    #         "external_group_admins": external_group_admins, | 
|  | 131 | +    #         "is_encryption_enabled": is_encryption_enabled, | 
|  | 132 | +    #         "is_stale_allowed": is_stale_allowed | 
|  | 133 | +    #     } | 
|  | 134 | +    #     # FIXME: According to the API, this call should return the updated object, but it does not | 
|  | 135 | +    #     log.info("Updating tenant ID '{}'".format(tenant_id)) | 
|  | 136 | +    #     return self.conn.put('object/tenants/tenant/{}'.format(tenant_id), json_payload=payload) | 
|  | 137 | + | 
|  | 138 | +    def delete(self, tenant_id): | 
|  | 139 | +        """ | 
|  | 140 | +        Deactivates and deletes the given tenant. | 
|  | 141 | +
 | 
|  | 142 | +        Required role(s): | 
|  | 143 | +
 | 
|  | 144 | +        SYSTEM_ADMIN | 
|  | 145 | +
 | 
|  | 146 | +        There is no response body for this call | 
|  | 147 | +
 | 
|  | 148 | +        Expect: HTTP/1.1 200 OK | 
|  | 149 | +
 | 
|  | 150 | +        :param tenant_id: An active tenant identifier which needs to be deleted | 
|  | 151 | +        """ | 
|  | 152 | +        log.info("Deleting tenant ID '{}'".format(tenant_id)) | 
|  | 153 | +        # FIXME: This should be a DELETE request | 
|  | 154 | +        return self.conn.post('object/tenants/tenant/{}/delete'.format(tenant_id)) | 
0 commit comments