Using OpenStack Shared File Systems

Before working with the Shared File System service, you’ll need to create a connection to your OpenStack cloud by following the Connect user guide. This will provide you with the conn variable used in the examples below.

List Availability Zones

A Shared File System service availability zone is a failure domain for your shared file systems. You may create a shared file system (referred to simply as shares) in a given availability zone, and create replicas of the share in other availability zones.

def list_availability_zones(conn):
    print("List Shared File System Availability Zones:")
    for az in conn.share.availability_zones():
        print(az)

Share Instances

Administrators can list, show information for, explicitly set the state of, and force-delete share instances.

def share_instances(conn, **query):
    print('List all share instances:')
    for si in conn.share.share_instances(**query):
        print(si)

Get Share Instance

Shows details for a single share instance.

def get_share_instance(conn, share_instance_id):
    print('Get share instance with given Id:')
    share_instance = conn.share.get_share_instance(share_instance_id)
    print(share_instance)

Reset Share Instance Status

Explicitly updates the state of a share instance.

def reset_share_instance_status(conn, share_instance_id, status):
    print(
        'Reset the status of the share instance with the given '
        'share_instance_id to the given status'
    )
    conn.share.reset_share_instance_status(share_instance_id, status)

Delete Share Instance

Force-deletes a share instance.

def delete_share_instance(conn, share_instance_id):
    print('Force-delete the share instance with the given share_instance_id')
    conn.share.delete_share_instance(share_instance_id)

Resize Share

Shared File System shares can be resized (extended or shrunk) to a given size. For details on resizing shares, refer to the Manila docs.

def resize_share(conn, share_id, share_size):
    # Be explicit about not wanting to use force if the share
    # will be extended.
    use_force = False
    print('Resize the share to the given size:')
    conn.share.resize_share(share_id, share_size, use_force)
def resize_shares_without_shrink(conn, min_size):
    # Sometimes, extending shares without shrinking
    # them (effectively setting a min size) is desirable.

    # Get list of shares from the connection.
    shares = conn.share.shares()

    # Loop over the shares:
    for share in shares:
        # Extend shares smaller than min_size to min_size,
        # but don't shrink shares larger than min_size.
        conn.share.resize_share(share.id, min_size, no_shrink=True)

List Share Group Snapshots

A share group snapshot is a point-in-time, read-only copy of the data that is contained in a share group. You can list all share group snapshots

def list_share_group_snapshots(conn, **query):
    print("List all share group snapshots:")
    share_group_snapshots = conn.share.share_group_snapshots(**query)
    for share_group_snapshot in share_group_snapshots:
        print(share_group_snapshot)

Get Share Group Snapshot

Show share group snapshot details

def get_share_group_snapshot(conn, group_snapshot_id):
    print("Show share group snapshot with given Id:")
    share_group_snapshot = conn.share.get_share_group_snapshots(
        group_snapshot_id
    )
    print(share_group_snapshot)

List Share Group Snapshot Members

Lists all share group snapshots members.

def share_group_snapshot_members(conn, group_snapshot_id):
    print("Show share group snapshot members with given Id:")
    members = conn.share.share_group_snapshot_members(group_snapshot_id)
    for member in members:
        print(member)

Create Share Group Snapshot

Creates a snapshot from a share group.

def create_share_group_snapshot(conn, share_group_id, **attrs):
    print("Creating a share group snapshot from given attributes:")
    share_group_snapshot = conn.share.create_share_group_snapshot(
        share_group_id, **attrs
    )
    print(share_group_snapshot)

Reset Share Group Snapshot

Reset share group snapshot state.

def reset_share_group_snapshot_status(conn, group_snapshot_id, status):
    print("Reseting the share group snapshot status:")
    conn.share.reset_share_group_snapshot_status(group_snapshot_id, status)

Update Share Group Snapshot

Updates a share group snapshot.

def update_share_group_snapshot(conn, group_snapshot_id, **attrs):
    print("Updating a share group snapshot with given Id:")
    share_group_snapshot = conn.share.update_share_group_snapshot(
        group_snapshot_id, **attrs
    )
    print(share_group_snapshot)

Delete Share Group Snapshot

Deletes a share group snapshot.

def delete_share_group_snapshot(conn, group_snapshot_id):
    print("Deleting a share group snapshot with given Id:")
    conn.share.delete_share_group_snapshot(group_snapshot_id)

List Share Metadata

Lists all metadata for a given share.

def list_share_metadata(conn, share_id):
    # Method returns the entire share with the metadata inside it.
    returned_share = conn.get_share_metadata(share_id)

    # Access metadata of share
    metadata = returned_share['metadata']

    print("List All Share Metadata:")
    for meta_key in metadata:
        print(f"{meta_key}={metadata[meta_key]}")

Get Share Metadata Item

Retrieves a specific metadata item from a shares metadata by its key.

def get_share_metadata_item(conn, share_id, key):
    # Method returns the entire share with the metadata inside it.
    returned_share = conn.get_share_metadata_item(share_id, key)

    # Access metadata of share
    metadata = returned_share['metadata']

    print("Get share metadata item given item key and share id:")
    print(metadata[key])

Create Share Metadata

Creates share metadata.

def create_share_metadata(conn, share_id, metadata):
    # Method returns the entire share with the metadata inside it.
    created_share = conn.create_share_metadata(share_id, metadata)

    # Access metadata of share
    metadata = created_share['metadata']

    print("Metadata created for given share:")
    print(metadata)

Update Share Metadata

Updates metadata of a given share.

def update_share_metadata(conn, share_id, metadata):
    # Method returns the entire share with the metadata inside it.
    updated_share = conn.update_share_metadata(share_id, metadata, True)

    # Access metadata of share
    metadata = updated_share['metadata']

    print("Updated metadata for given share:")
    print(metadata)

Delete Share Metadata

Deletes a specific metadata item from a shares metadata by its key. Can specify multiple keys to be deleted.

def delete_share_metadata(conn, share_id, keys):
    # Method doesn't return anything.
    conn.delete_share_metadata(share_id, keys)

Manage Share

Manage a share with Manila.

def manage_share(conn, protocol, export_path, service_host, **params):
    # Manage a share with the given protocol, export path, service host, and
    # optional additional parameters
    managed_share = conn.share.manage_share(
        protocol, export_path, service_host, **params
    )

    # Can get the ID of the share, which is now being managed with Manila
    managed_share_id = managed_share.id
    print("The ID of the share which was managed: %s", managed_share_id)

Unmanage Share

Unmanage a share from Manila.

def unmanage_share(conn, share_id):
    # Unmanage the share with the given share ID
    conn.share.unmanage_share(share_id)

    try:
        # Getting the share will raise an exception as it has been unmanaged
        conn.share.get_share(share_id)
    except Exception:
        pass