manilaclient Python API¶
用法¶
为了直接使用 Python API,您首先需要获取一个认证令牌并确定要与之通信的端点。 完成这些操作后,您可以像这样使用 API
>>> from manilaclient import client
>>> manila = client.Client('1', $OS_USER_NAME, $OS_PASSWORD, $OS_TENANT_NAME, $OS_AUTH_URL)
>>> manila.shares.list()
[]
>>> share = manila.shares.create(share_proto="nfs", size=1, share_network_id="some_share_network_id")
>>> share.id
ce06d0a8-5c1b-4e2c-81d2-39eca6bbfb70
>>> manila.shares.list()
[<Share: ce06d0a8-5c1b-4e2c-81d2-39eca6bbfb70>]
>>> share.delete
除了创建和删除共享之外,manilaclient 还可以管理共享类型、访问控制等! 以使用 CephFS 和 Ganesha 提供 NFS 支持为例(假设此操作从上面的初始化继续进行)
>>> share_type = client.share_types.create(
>>> name="cephfsnfstype", spec_driver_handles_share_servers=False,
>>> extra_specs={
>>> 'vendor_name': 'Ceph',
>>> 'storage_protocol': 'NFS',
>>> 'snapshot_support': False,
>>> })
>>> share_type
<ShareType: cephfsnfstype>
>>> share = client.shares.create(
>>> share_type='cephfsnfstype', name='cephnfsshare1',
>>> share_proto="nfs", size=1)
>>> share.allow(access_type='ip', access="192.168.0.0/24", access_level='rw')
{'id': '29bc4b66-d55d-424d-8107-aee96d1c562b', 'share_id': '0ac95dd2-afba-4ba3-8934-721b29492f04', 'access_level': 'rw', 'access_to': '192.168.0.0/24', 'access_type': 'ip', 'state': 'new'}
>>> share.export_locations
['10.5.0.22:/volumes/_nogroup/cf0451b6-0a95-4982-a801-2e212e9c9b96']
在上面的示例中,Manila 将使用 NFS 共享类型设置,该共享类型由 CephFS 支持。 然后创建一个共享,并添加访问控制,授予 192.168.0/24 子网对共享的读/写访问权限。