Esempio n. 1
0
 def get_share_group_link(share):
     if (features.is_share_groups_enabled()
             and getattr(share, 'share_group_id', None)):
         return reverse("horizon:project:share_groups:detail",
                        args=(share.share_group_id, ))
     else:
         return None
Esempio n. 2
0
 class Meta(object):
     name = "shares"
     verbose_name = _("Shares")
     status_columns = ["status"]
     row_class = shares_tables.UpdateRow
     table_actions = (
         tables.NameFilterAction,
         ManageShareAction,
         shares_tables.DeleteShare,
     )
     row_actions = (
         ManageReplicas,
         MigrationStartAction,
         MigrationCompleteAction,
         MigrationGetProgressAction,
         MigrationCancelAction,
         UnmanageShareAction,
         shares_tables.DeleteShare,
     )
     columns = [
         'tenant',
         'host',
         'name',
         'size',
         'status',
         'visibility',
         'share_type',
         'protocol',
         'share_server',
     ]
     if features.is_share_groups_enabled():
         columns.append('share_group_id')
Esempio n. 3
0
 def get_share_group_link(share):
     if (features.is_share_groups_enabled() and
             getattr(share, 'share_group_id', None)):
         return reverse(
             "horizon:project:share_groups:detail",
             args=(share.share_group_id,))
     else:
         return None
Esempio n. 4
0
    class Meta(object):
        name = "shares"
        verbose_name = _("Shares")
        status_columns = ["status"]
        row_class = UpdateRow
        table_actions = (tables.NameFilterAction, CreateShare, DeleteShare)
        row_actions = (EditShare, ResizeShare, RevertShare,
                       ss_tables.CreateShareSnapshot, ManageRules,
                       ManageReplicas, EditShareMetadata, DeleteShare)

        columns = [
            'name',
            'description',
            'metadata',
            'size',
            'status',
            'proto',
            'visibility',
            'share_network',
        ]
        if features.is_share_groups_enabled():
            columns.append('share_group_id')
Esempio n. 5
0
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from django.conf import urls

from manila_ui.dashboards.admin.share_group_snapshots import views
from manila_ui import features


if features.is_share_groups_enabled():
    urlpatterns = [
        urls.url(
            r'^$',
            views.ShareGroupSnapshotsView.as_view(),
            name='index'),
        urls.url(
            r'^(?P<share_group_snapshot_id>[^/]+)/$',
            views.ShareGroupSnapshotDetailView.as_view(),
            name='detail'),
        urls.url(
            r'^(?P<share_group_snapshot_id>[^/]+)/reset_status$',
            views.ResetShareGroupSnapshotStatusView.as_view(),
            name='reset_status'),
    ]
Esempio n. 6
0
    def __init__(self, request, *args, **kwargs):
        super(CreateForm, self).__init__(request, *args, **kwargs)
        # NOTE(vkmc): choose only those share protocols that are enabled
        # FIXME(vkmc): this should be better implemented by having a
        # capabilities endpoint on the control plane.
        manila_features = getattr(settings, 'OPENSTACK_MANILA_FEATURES', {})
        self.enabled_share_protocols = manila_features.get(
            'enabled_share_protocols',
            ['NFS', 'CIFS', 'GlusterFS', 'HDFS', 'CephFS', 'MapRFS'])
        self.enable_public_shares = manila_features.get(
            'enable_public_shares', True)
        share_networks = manila.share_network_list(request)
        share_types = manila.share_type_list(request)
        self.fields['share_type'].choices = (
            [("", "")] + [(utils.transform_dashed_name(st.name), st.name)
                          for st in share_types])

        availability_zones = manila.availability_zone_list(request)
        self.fields['availability_zone'].choices = (
            [("", "")] + [(az.name, az.name) for az in availability_zones])

        if features.is_share_groups_enabled():
            share_groups = manila.share_group_list(request)
            self.fields['sg'] = forms.ChoiceField(label=_("Share Group"),
                                                  choices=[("", "")] +
                                                  [(sg.id, sg.name or sg.id)
                                                   for sg in share_groups],
                                                  required=False)

        self.sn_field_name_prefix = 'share-network-choices-'
        for st in share_types:
            extra_specs = st.get_keys()
            dhss = extra_specs.get('driver_handles_share_servers')
            # NOTE(vponomaryov): Set and tie share-network field only for
            # share types with enabled handling of share servers.
            if (isinstance(dhss, str) and dhss.lower() in ['true', '1']):
                sn_choices = ([('', '')] + [(sn.id, sn.name or sn.id)
                                            for sn in share_networks])
                sn_field_name = (self.sn_field_name_prefix +
                                 utils.transform_dashed_name(st.name))
                sn_field = forms.ChoiceField(
                    label=_("Share Network"),
                    required=True,
                    choices=sn_choices,
                    widget=forms.Select(
                        attrs={
                            'class':
                            'switched',
                            'data-switch-on':
                            'sharetype',
                            'data-sharetype-%s' % utils.transform_dashed_name(st.name):
                            _("Share Network"),
                        }))
                self.fields[sn_field_name] = sn_field

        self.fields['share_source_type'] = forms.ChoiceField(
            label=_("Share Source"),
            required=False,
            widget=forms.Select(attrs={
                'class': 'switchable',
                'data-slug': 'source'
            }))
        self.fields['snapshot'] = forms.ChoiceField(
            label=_("Use snapshot as a source"),
            widget=forms.fields.SelectWidget(attrs={
                'class':
                'switched',
                'data-switch-on':
                'source',
                'data-source-snapshot':
                _('Snapshot')
            },
                                             data_attrs=('size', 'name'),
                                             transform=lambda x: "%s (%sGiB)" %
                                             (x.name, x.size)),
            required=False)
        self.fields['metadata'] = forms.CharField(
            label=_("Metadata"),
            required=False,
            widget=forms.Textarea(attrs={'rows': 4}))

        if self.enable_public_shares:
            self.fields['is_public'] = forms.BooleanField(
                label=_("Make visible to users from all projects"),
                required=False)

        self.fields['share_proto'].choices = [
            (sp, sp) for sp in self.enabled_share_protocols
        ]
        if ("snapshot_id" in request.GET
                or kwargs.get("data", {}).get("snapshot")):
            try:
                snapshot = self.get_snapshot(
                    request,
                    request.GET.get("snapshot_id",
                                    kwargs.get("data", {}).get("snapshot")))
                self.fields['name'].initial = snapshot.name
                self.fields['size'].initial = snapshot.size
                self.fields['snapshot'].choices = ((snapshot.id, snapshot), )
                try:
                    # Set the share type and az from the original share
                    orig_share = manila.share_get(request, snapshot.share_id)
                    self.fields['share_type'].initial = (
                        orig_share.share_type_name)
                    self.fields['availability_zone'].initial = (
                        orig_share.availability_zone)
                except Exception:
                    pass
                self.fields['size'].help_text = _(
                    'Share size must be equal to or greater than the snapshot '
                    'size (%sGiB)') % snapshot.size
                del self.fields['share_source_type']
            except Exception:
                exceptions.handle(request,
                                  _('Unable to load the specified snapshot.'))
        else:
            source_type_choices = []

            try:
                snapshot_list = manila.share_snapshot_list(request)
                snapshots = [
                    s for s in snapshot_list if s.status == 'available'
                ]
                if snapshots:
                    source_type_choices.append(("snapshot", _("Snapshot")))
                    choices = [('', _("Choose a snapshot"))] + \
                              [(s.id, s) for s in snapshots]
                    self.fields['snapshot'].choices = choices
                else:
                    del self.fields['snapshot']
            except Exception:
                exceptions.handle(request,
                                  _("Unable to retrieve "
                                    "share snapshots."))

            if source_type_choices:
                choices = ([('no_source_type', _("No source, empty share"))] +
                           source_type_choices)
                self.fields['share_source_type'].choices = choices
            else:
                del self.fields['share_source_type']
# Copyright 2017 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from manila_ui import features


PANEL_DASHBOARD = 'project'
PANEL_GROUP = 'share'
PANEL = 'share_group_snapshots'

if features.is_share_groups_enabled():
    ADD_PANEL = ('manila_ui.dashboards.project.share_group_snapshots.panel.'
                 'ShareGroupSnapshots')
else:
    REMOVE_PANEL = not features.is_share_groups_enabled()
Esempio n. 8
0
# Copyright 2017 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from manila_ui import features

PANEL_DASHBOARD = 'project'
PANEL_GROUP = 'share'
PANEL = 'share_group_snapshots'

if features.is_share_groups_enabled():
    ADD_PANEL = ('manila_ui.dashboards.project.share_group_snapshots.panel.'
                 'ShareGroupSnapshots')
else:
    REMOVE_PANEL = not features.is_share_groups_enabled()
Esempio n. 9
0
    def __init__(self, request, *args, **kwargs):
        super(CreateForm, self).__init__(request, *args, **kwargs)
        # NOTE(vkmc): choose only those share protocols that are enabled
        # FIXME(vkmc): this should be better implemented by having a
        # capabilities endpoint on the control plane.
        manila_features = getattr(settings, 'OPENSTACK_MANILA_FEATURES', {})
        self.enabled_share_protocols = manila_features.get(
            'enabled_share_protocols',
            ['NFS', 'CIFS', 'GlusterFS', 'HDFS', 'CephFS', 'MapRFS'])
        self.enable_public_shares = manila_features.get(
            'enable_public_shares', True)
        share_networks = manila.share_network_list(request)
        share_types = manila.share_type_list(request)
        self.fields['share_type'].choices = (
            [("", "")] + [(st.name, st.name) for st in share_types])

        availability_zones = manila.availability_zone_list(request)
        self.fields['availability_zone'].choices = (
            [("", "")] + [(az.name, az.name) for az in availability_zones])

        if features.is_share_groups_enabled():
            share_groups = manila.share_group_list(request)
            self.fields['sg'] = forms.ChoiceField(
                label=_("Share Group"),
                choices=[("", "")] + [(sg.id, sg.name or sg.id)
                                      for sg in share_groups],
                required=False)

        self.sn_field_name_prefix = 'share-network-choices-'
        for st in share_types:
            extra_specs = st.get_keys()
            dhss = extra_specs.get('driver_handles_share_servers')
            # NOTE(vponomaryov): Set and tie share-network field only for
            # share types with enabled handling of share servers.
            if (isinstance(dhss, six.string_types) and
                    dhss.lower() in ['true', '1']):
                sn_choices = (
                    [('', '')] +
                    [(sn.id, sn.name or sn.id) for sn in share_networks])
                sn_field_name = self.sn_field_name_prefix + st.name
                sn_field = forms.ChoiceField(
                    label=_("Share Network"), required=True,
                    choices=sn_choices,
                    widget=forms.Select(attrs={
                        'class': 'switched',
                        'data-switch-on': 'sharetype',
                        'data-sharetype-%s' % st.name: _("Share Network"),
                    }))
                self.fields[sn_field_name] = sn_field

        self.fields['share_source_type'] = forms.ChoiceField(
            label=_("Share Source"), required=False,
            widget=forms.Select(
                attrs={'class': 'switchable', 'data-slug': 'source'}))
        self.fields['snapshot'] = forms.ChoiceField(
            label=_("Use snapshot as a source"),
            widget=forms.fields.SelectWidget(
                attrs={'class': 'switched',
                       'data-switch-on': 'source',
                       'data-source-snapshot': _('Snapshot')},
                data_attrs=('size', 'name'),
                transform=lambda x: "%s (%sGiB)" % (x.name, x.size)),
            required=False)
        self.fields['metadata'] = forms.CharField(
            label=_("Metadata"), required=False,
            widget=forms.Textarea(attrs={'rows': 4}))

        if self.enable_public_shares:
            self.fields['is_public'] = forms.BooleanField(
                label=_("Make visible for all"), required=False,
                help_text=(
                    "If set then all tenants will be able to see this share."))

        self.fields['share_proto'].choices = [(sp, sp) for sp in
                                              self.enabled_share_protocols]
        if ("snapshot_id" in request.GET or
                kwargs.get("data", {}).get("snapshot")):
            try:
                snapshot = self.get_snapshot(
                    request,
                    request.GET.get("snapshot_id",
                                    kwargs.get("data", {}).get("snapshot")))
                self.fields['name'].initial = snapshot.name
                self.fields['size'].initial = snapshot.size
                self.fields['snapshot'].choices = ((snapshot.id, snapshot),)
                try:
                    # Set the share type from the original share
                    orig_share = manila.share_get(request, snapshot.share_id)
                    # NOTE(vponomaryov): we should use share type name, not ID,
                    # because we use names in our choices above.
                    self.fields['share_type'].initial = (
                        orig_share.share_type_name)
                except Exception:
                    pass
                self.fields['size'].help_text = _(
                    'Share size must be equal to or greater than the snapshot '
                    'size (%sGiB)') % snapshot.size
                del self.fields['share_source_type']
            except Exception:
                exceptions.handle(request,
                                  _('Unable to load the specified snapshot.'))
        else:
            source_type_choices = []

            try:
                snapshot_list = manila.share_snapshot_list(request)
                snapshots = [s for s in snapshot_list
                             if s.status == 'available']
                if snapshots:
                    source_type_choices.append(("snapshot",
                                                _("Snapshot")))
                    choices = [('', _("Choose a snapshot"))] + \
                              [(s.id, s) for s in snapshots]
                    self.fields['snapshot'].choices = choices
                else:
                    del self.fields['snapshot']
            except Exception:
                exceptions.handle(request, _("Unable to retrieve "
                                             "share snapshots."))

            if source_type_choices:
                choices = ([('no_source_type',
                             _("No source, empty share"))] +
                           source_type_choices)
                self.fields['share_source_type'].choices = choices
            else:
                del self.fields['share_source_type']