用于与EMC VIPR API交互的库

viperp的Python项目详细描述


用于与EMC VIPR API交互的Python库

https://travis-ci.org/chadlung/viperpy.svg?branch=master

注意:ViPR是EMC产品, 商标、版权等。

如果您正在使用ECS(弹性云存储)产品,建议您 使用ECSMinion与 管理API。

使用这个库非常简单。可以安装Viperpy 来自PyPi

$ pip install viperpy

创建viperpy类的实例需要以下内容 参数:

NameRequiredDefault ValueDescription
^{tt1}$NoNoneThe username used to fetch the ViPR token
^{tt2}$NoNoneThe password used to fetch the ViPR token
^{tt3}$NoNonePass a token to ViperPy (username/password are ignored then)
^{tt4}$YesNoneThe ViPR API endpoint, ex: ^{tt5}$
^{tt6}$YesNoneThe ViPR API endpoint, ex: ^{tt7}$
^{tt8}$NoFalseWhether 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}$No15.0Stop waiting for a response after a given number of seconds, this is a decimal value. Ex: 10.0 is ten seconds
^{tt14}$NoTrueWhether 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 更多信息。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何序列化数字?   java如何用我的Mainclass扩展ListActivity类和Fragment类?   JavaJersey、Jackson和JAXRS发布了多种JSON格式   java如何使用JavaFXKeyCombination覆盖系统默认的键盘快捷键,如Ctrl+C、Ctrl+V?   java Jersey类路径扫描示例Jersey。配置。服务器供应商。类路径   java什么样的数据结构可以作为一个数组,但在同一索引下给定多个值时会自动增长到第二维度?   java如何序列化非持久实体中的嵌套PersistentEntityResource   协议缓冲区我可以让protoc在Java中生成int数组吗?   在GregorianCalendar ArrayList Java中添加日期元素   从html模板动态生成pdf文件并用java生成目录   java Gridgain 6.5.5开源多个节点速度较慢。。?   java如何检查数组中所有整数的不相等性?   java在Eclipse中,如何多次运行JUnit测试用例   java侦听器不能处理特定的片段   java不是一个声明?(蓝色J)   找不到Attributer类型的PersonId的java定义