用于与EMC VIPR API交互的库
viperp的Python项目详细描述
用于与EMC VIPR API交互的Python库
注意:ViPR是EMC产品, 商标、版权等。
如果您正在使用ECS(弹性云存储)产品,建议您 使用ECSMinion与 管理API。
使用这个库非常简单。可以安装Viperpy 来自PyPi:
$ pip install viperpy
创建viperpy类的实例需要以下内容 参数:
Name | Required | Default Value | Description |
---|---|---|---|
^{tt1}$ | No | None | The username used to fetch the ViPR token |
^{tt2}$ | No | None | The password used to fetch the ViPR token |
^{tt3}$ | No | None | Pass a token to ViperPy (username/password are ignored then) |
^{tt4}$ | Yes | None | The ViPR API endpoint, ex: ^{tt5}$ |
^{tt6}$ | Yes | None | The ViPR API endpoint, ex: ^{tt7}$ |
^{tt8}$ | No | False | Whether to check a host’s SSL certificate |
^{tt9}$ | No | ^{tt10}$ | The filename of the temporary token |
^{tt11}$ | No | ^{tt12}$ | The location to store the temporary token file |
^{tt13}$ | No | 15.0 | Stop waiting for a response after a given number of seconds, this is a decimal value. Ex: 10.0 is ten seconds |
^{tt14}$ | No | True | Whether to cache the token, by default this is true you should only switch this to false when you want to directly fetch a token for a user |
下面是一个经过大部分API调用的示例请注意 有些电话比其他电话要长。有时你可以 需要将request_timeout设置为60.0
from viperpy import Viperpy, ViperpyException from viperpy.util.common import get_formatted_time_string try: client = Viperpy(username='someone', password='password', token_endpoint='https://192.168.1.146:4443/login', vipr_endpoint='https://192.168.1.146:4443', request_timeout=15.0) print(client.user_info.whoami()) print(client.user_info.get_tenant(username=None)) audit_time_bucket = get_formatted_time_string(2014, 12, 4, 0, None) print(client.audit.get_audit_log(audit_time_bucket)) print(client.fabric_capacity.get_capacity()) print(client.disk.get_disks(maximum=-3, index=1)) single_disk_info = client.disk.get_disk_by_urn( urn='urn:fabric:disk:00b0b99b-a395-4179-8838-f121b99061fb') print(single_disk_info) single_disk_capacity_info = client.disk.get_disk_capacity( urn='urn:fabric:disk:00b0b99b-a395-4179-8838-f121b99061fb') print(single_disk_capacity_info) print(client.health.get_health()) print(client.node.get_nodes(maximum=-5, index=0)) print(client.services.get_services()) print(client.bucket.get_buckets('namespace1')) print(client.bucket.get_bucket_retention('bucket1')) print(client.object_data_control_capacity.get_capacity()) print(client.namespace.get_namespaces()) print(client.namespace.get_namespace_info('namespace1')) print(client.user_management.get_objectusers()) print(client.user_management.get_objectusers('namespace1')) print(client.user_management.lock_objectuser('myuser1', is_locked=True, namespace='namespace1')) print(client.user_management.get_objectuser_info('myuser1')) print(client.user_management.lock_objectuser('myuser1', is_locked=False, namespace='namespace1')) print(client.user_management.get_objectuser_info('myuser1')) print(client.user_secret_key.get_user_secret_keys(uid='user1@test')) print(client.configuration.get_config_properties()) print(client.health_monitor.get_stats()) health_info = client.health_monitor.get_health(0) print(health_info) health_info = client.health_monitor.get_stats( node_id=['urn:fabric:node:0fedcf91-5086-11e3-a7f8-001e6769f9a1:', 'urn:fabric:node:14115e71-4fbe-11e3-b044-001e6769e808:']) print(health_info) print(client.health_monitor.get_diagnostics(node_id='nilea01-r05-05')) print(client.health_monitor.get_storage_stats()) print(client.upgrade.get_target_version()) print(client.upgrade.get_cluster_state(True)) print(client.upgrade.get_download_progress()) tenants_list = client.tenants.get_tenants_bulk() for tenant_id in tenants_list: tenant_info = client.tenants.get_tenant(tenant_id) print(tenant_info) print(tenant_info['name']) try: subtenant = client.tenants.get_subtenants(tenant_id) if subtenant: print(subtenant) except: pass # Beta Billing API: print(client.billing.get_bucket_billing_info('namespace1', 'bucket1')) except ViperpyException as viperpy_ex: print('Message: {0}'.format(viperpy_ex.message)) print('Status Code Returned: {0}\n'.format(viperpy_ex.http_status_code)) print('ViPR API Message: {0}'.format(viperpy_ex.vipr_message)) except Exception as ex: print(ex.message)
示例:使用有效的令牌而不是提供用户名和密码
您直接将身份验证令牌传递给viperpy,这意味着您 不需要提供用户名/密码。下面是一个例子(令牌 已被缩短):
client = Viperpy(token='DLAcbGZtbjh6eVB3eUF1TzFEZWNmc0M2VVl2QjBVPQM', token_endpoint='https://192.168.1.146:4443/login', vipr_endpoint='https://192.168.1.146:4443', request_timeout=15.0)
示例:创建、列出和删除对象用户
from viperpy import Viperpy, ViperpyException if __name__ == "__main__": try: client = Viperpy(username='someone', password='password', token=None, token_endpoint='https://192.168.1.146:4443/login', vipr_endpoint='https://192.168.1.146:4443', request_timeout=15.0) print(client.user_management.add_objectuser(user='mytest1', namespace='namespace1')) print(client.user_management.get_objectusers()) # This next line won't print anything useful as the body is empty # If an HTTP 200 is not returned an error with raise, otherwise you can # assume that the call was successful client.user_management.deactivate_objectuser(user='mytest1') print(client.user_management.get_objectusers()) except ViperpyException as viperpy_ex: print('Message: {0}'.format(viperpy_ex.message)) print('Status Code Returned: {0}\n'.format(viperpy_ex.http_status_code)) print('ViPR API Message: {0}'.format(viperpy_ex.vipr_message)) except Exception as ex: print(ex.message)
示例:获取令牌
通过设置 cache_token参数设置为false,然后调用get_token:
from viperpy import Viperpy, ViperpyException if __name__ == "__main__": try: client = Viperpy(username='someone', password='password', token=None, token_endpoint='https://192.168.1.146:4443/login', vipr_endpoint='https://192.168.1.146:4443', request_timeout=15.0, cache_token=False) print(client.get_token()) except ViperpyException as viperpy_ex: print('Message: {0}'.format(viperpy_ex.message)) print('Status Code Returned: {0}\n'.format(viperpy_ex.http_status_code)) print('ViPR API Message: {0}'.format(viperpy_ex.vipr_message)) except Exception as ex: print(ex.message)
示例:删除缓存的令牌
from viperpy import Viperpy, ViperpyException if __name__ == "__main__": try: client = Viperpy(username='someone', password='password', token=None, token_endpoint='https://192.168.1.146:4443/login', vipr_endpoint='https://192.168.1.146:4443', request_timeout=15.0, cache_token=False) print(client.remove_cached_token()) except ViperpyException as viperpy_ex: print('Message: {0}'.format(viperpy_ex.message)) print('Status Code Returned: {0}\n'.format(viperpy_ex.http_status_code)) print('ViPR API Message: {0}'.format(viperpy_ex.vipr_message)) except Exception as ex: print(ex.message)
viprβapi
已经为新版本的vipr 2.1.1(beta)版本添加了支持 计费和软配额API。
运行PEP8
源代码中有一些示例json注释已经结束 允许的PEP8长度。您可以通过运行以下命令来忽略它们:
$ pep8 --ignore=E501 .
许可证
此软件库是在EMC免费软件下发布给您的 许可协议。见 LICENSE 更多信息。