Debian Codegraph @

doc/source/user/api.rst

raw
1 The :program:`manilaclient` Python API
2 ======================================
3
4 .. module:: manilaclient
5 :synopsis: A client for the OpenStack Manila API.
6
7 .. currentmodule:: manilaclient
8
9 Usage
10 -----
11
12 In order to use the Python API directly, you must first obtain an auth
13 token and identify which endpoint you wish to speak to. Once you have
14 done so, you can use the API like so::
15
16 >>> from manilaclient import client
17 >>> manila = client.Client('1', $OS_USER_NAME, $OS_PASSWORD, $OS_TENANT_NAME, $OS_AUTH_URL)
18 >>> manila.shares.list()
19 []
20 >>> share = manila.shares.create(share_proto="nfs", size=1, share_network_id="some_share_network_id")
21 >>> share.id
22 ce06d0a8-5c1b-4e2c-81d2-39eca6bbfb70
23 >>> manila.shares.list()
24 [<Share: ce06d0a8-5c1b-4e2c-81d2-39eca6bbfb70>]
25 >>> share.delete
26
27 In addition to creating and deleting shares, the manilaclient can manage
28 share-types, access controls, and more! Using CephFS with Ganesha for NFS
29 support as an example (assuumes this continues from the above initialization)::
30
31 >>> share_type = client.share_types.create(
32 >>> name="cephfsnfstype", spec_driver_handles_share_servers=False,
33 >>> extra_specs={
34 >>> 'vendor_name': 'Ceph',
35 >>> 'storage_protocol': 'NFS',
36 >>> 'snapshot_support': False,
37 >>> })
38 >>> share_type
39 <ShareType: cephfsnfstype>
40 >>> share = client.shares.create(
41 >>> share_type='cephfsnfstype', name='cephnfsshare1',
42 >>> share_proto="nfs", size=1)
43 >>> share.allow(access_type='ip', access="192.168.0.0/24", access_level='rw')
44 {'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'}
45 >>> share.export_locations
46 ['10.5.0.22:/volumes/_nogroup/cf0451b6-0a95-4982-a801-2e212e9c9b96']
47
48 In the above example, Manila will be setup with an NFS share type, backed
49 by CephFS. A share is then created, and then access controls are added giving
50 the 192.168.0/24 subnet read/write access to the share.