Example #1
0
def check_shares(data):
    if not data:
        return

    paths = (share.get('path') for share in data)
    paths = [path for path in paths if path is not None]
    if len(paths) != len(set(paths)):
        raise ex.InvalidDataException(
            _('Multiple shares cannot be mounted to the same path.'))

    for path in paths:
        if not path.startswith('/') or '\x00' in path:
            raise ex.InvalidDataException(
                _('Paths must be absolute Linux paths starting with "/" '
                  'and may not contain nulls.'))

    client = manila.client()
    for share in data:
        manila_share = manila.get_share(client, share['id'])
        if not manila_share:
            raise ex.InvalidReferenceException(
                _("Requested share id %s does not exist.") % share['id'])

        share_type = manila_share.share_proto
        if share_type not in shares.SUPPORTED_SHARE_TYPES:
            raise ex.InvalidReferenceException(
                _("Requested share id %(id)s is of type %(type)s, which is "
                  "not supported by Sahara.") % {
                      "id": share['id'],
                      "type": share_type
                  })
Example #2
0
def check_shares(data):
    if not data:
        return

    paths = (share.get('path') for share in data)
    paths = [path for path in paths if path is not None]
    if len(paths) != len(set(paths)):
        raise ex.InvalidDataException(
            _('Multiple shares cannot be mounted to the same path.'))

    for path in paths:
        if not path.startswith('/') or '\x00' in path:
            raise ex.InvalidDataException(
                _('Paths must be absolute Linux paths starting with "/"'
                  'and may not contain nulls.'))

    client = manila.client()
    for share in data:
        manila_share = manila.get_share(client, share['id'])
        if not manila_share:
            raise ex.InvalidReferenceException(
                _("Requested share id %s does not exist.") % share['id'])

        share_type = manila_share.share_proto
        if share_type not in shares.SUPPORTED_SHARE_TYPES:
            raise ex.InvalidReferenceException(
                _("Requested share id %(id)s is of type %(type)s, which is "
                  "not supported by Sahara.")
                % {"id": share['id'], "type": share_type})
Example #3
0
def mount_shares(cluster):
    """Mounts all shares specified for the cluster and any of its node groups.

    - In the event that a specific share is configured for both the cluster and
      a specific node group, configuration at the node group level will be
      ignored.
    - In the event that utilities required to mount the share are not
      already installed on the node, this method may fail if the node cannot
      access the internet.
    - This method will not remove already-mounted shares.
    - This method will not remove or remount (or currently, reconfigure) shares
      already mounted to the desired local mount point.

    :param cluster: The cluster model.
    """

    node_groups = (ng for ng in cluster.node_groups if ng.shares)
    ng_mounts = [
        _mount(ng, share_config) for ng in node_groups
        for share_config in ng.shares
    ]
    c_mounts = [
        _mount(ng, share_config) for ng in cluster.node_groups
        for share_config in cluster.shares or []
    ]

    if not (ng_mounts or c_mounts):
        return

    ng_mounts_by_share_id = _group_mounts_by_share_id(ng_mounts)
    c_mounts_by_share_id = _group_mounts_by_share_id(c_mounts)

    all_share_ids = (set(ng_mounts_by_share_id.keys())
                     | set(c_mounts_by_share_id.keys()))
    mounts_by_share_id = {
        share_id: c_mounts_by_share_id.get(share_id)
        or ng_mounts_by_share_id[share_id]
        for share_id in all_share_ids
    }

    all_mounts = itertools.chain(*mounts_by_share_id.values())
    mounts_by_ng_id = _group_mounts_by_ng_id(all_mounts)

    client = manila.client()
    handlers_by_share_id = {
        id: _ShareHandler.create_from_id(id, client)
        for id in all_share_ids
    }

    for mounts in mounts_by_ng_id.values():
        node_group_shares = _NodeGroupShares(mounts[0].node_group)
        for mount in mounts:
            share_id = mount.share_config['id']
            node_group_shares.add_share(mount.share_config,
                                        handlers_by_share_id[share_id])
        node_group_shares.mount_shares_to_node_group()
Example #4
0
def unmount_shares(cluster, unmount_share_list):
    """Unmounts all shares in unmount_share_list on the given cluster

    :param cluster: The cluster model.
    :param unmount_share_list: list of shares to unmount
    """
    client = manila.client()
    unmount_share_ids = set(s["id"] for s in unmount_share_list)
    handlers_by_share_id = {id: _ShareHandler.create_from_id(id, client) for id in unmount_share_ids}
    for share in unmount_share_list:
        for ng in cluster.node_groups:
            for instance in ng.instances:
                handlers_by_share_id[share["id"]].unmount_from_instance(instance.remote(), share)
Example #5
0
def unmount_shares(cluster, unmount_share_list):
    """Unmounts all shares in unmount_share_list on the given cluster

    :param cluster: The cluster model.
    :param unmount_share_list: list of shares to unmount
    """
    client = manila.client()
    unmount_share_ids = (set(s['id'] for s in unmount_share_list))
    handlers_by_share_id = {id: _ShareHandler.create_from_id(id, client)
                            for id in unmount_share_ids}
    for share in unmount_share_list:
        for ng in cluster.node_groups:
            for instance in ng.instances:
                handlers_by_share_id[share['id']].unmount_from_instance(
                    instance.remote(), share)
Example #6
0
def mount_shares(cluster):
    """Mounts all shares specified for the cluster and any of its node groups.

    - In the event that a specific share is configured for both the cluster and
      a specific node group, configuration at the node group level will be
      ignored.
    - In the event that utilities required to mount the share are not
      already installed on the node, this method may fail if the node cannot
      access the internet.
    - This method will not remove already-mounted shares.
    - This method will not remove or remount (or currently, reconfigure) shares
      already mounted to the desired local mount point.

    :param cluster: The cluster model.
    """

    node_groups = (ng for ng in cluster.node_groups if ng.shares)
    ng_mounts = [_mount(ng, share_config) for ng in node_groups
                 for share_config in ng.shares]
    c_mounts = [_mount(ng, share_config) for ng in cluster.node_groups
                for share_config in cluster.shares or []]

    if not (ng_mounts or c_mounts):
        return

    ng_mounts_by_share_id = _group_mounts_by_share_id(ng_mounts)
    c_mounts_by_share_id = _group_mounts_by_share_id(c_mounts)

    all_share_ids = (set(ng_mounts_by_share_id.keys()) |
                     set(c_mounts_by_share_id.keys()))
    mounts_by_share_id = {
        share_id: c_mounts_by_share_id.get(share_id) or
        ng_mounts_by_share_id[share_id] for share_id in all_share_ids}

    all_mounts = itertools.chain(*mounts_by_share_id.values())
    mounts_by_ng_id = _group_mounts_by_ng_id(all_mounts)

    client = manila.client()
    handlers_by_share_id = {id: _ShareHandler.create_from_id(id, client)
                            for id in all_share_ids}

    for mounts in mounts_by_ng_id.values():
        node_group_shares = _NodeGroupShares(mounts[0].node_group)
        for mount in mounts:
            share_id = mount.share_config['id']
            node_group_shares.add_share(mount.share_config,
                                        handlers_by_share_id[share_id])
        node_group_shares.mount_shares_to_node_group()
Example #7
0
def default_mount(share_id):
    client = manila.client()
    return _ShareHandler.create_from_id(share_id, client)._default_mount()
Example #8
0
def default_mount(share_id):
    client = manila.client()
    return _ShareHandler.create_from_id(share_id, client)._default_mount()