Exemple #1
0
    def test_share_group_snapshot_list(self, kwargs):
        result = api.share_group_snapshot_list(self.request, **kwargs)

        self.assertIsNotNone(result)
        self.assertEqual(
            self.manilaclient.share_group_snapshots.list.return_value, result)
        self.manilaclient.share_group_snapshots.list.assert_called_once_with(
            detailed=kwargs.get('detailed', True),
            search_opts=kwargs.get('search_opts'),
            sort_key=kwargs.get('sort_key'),
            sort_dir=kwargs.get('sort_dir'))
Exemple #2
0
    def test_share_group_snapshot_list(self, kwargs):
        result = api.share_group_snapshot_list(self.request, **kwargs)

        self.assertIsNotNone(result)
        self.assertEqual(
            self.manilaclient.share_group_snapshots.list.return_value,
            result)
        self.manilaclient.share_group_snapshots.list.assert_called_once_with(
            detailed=kwargs.get('detailed', True),
            search_opts=kwargs.get('search_opts'),
            sort_key=kwargs.get('sort_key'),
            sort_dir=kwargs.get('sort_dir'))
Exemple #3
0
 def get_share_group_snapshots_data(self):
     share_group_snapshots = []
     try:
         share_group_snapshots = manila.share_group_snapshot_list(
             self.request, search_opts={'all_tenants': True})
         share_groups = manila.share_group_list(self.request)
         sg_names = dict([(sg.id, sg.name or sg.id) for sg in share_groups])
         for snapshot in share_group_snapshots:
             snapshot.share_group = sg_names.get(snapshot.share_group_id)
     except Exception:
         msg = _("Unable to retrieve share group snapshot list.")
         exceptions.handle(self.request, msg)
     return share_group_snapshots
Exemple #4
0
    def __init__(self, request, *args, **kwargs):
        super(CreateShareGroupForm, self).__init__(request, *args, **kwargs)
        self.st_field_name_prefix = "share-type-choices-"
        self.fields["source_type"] = forms.ChoiceField(
            label=_("Source Type"),
            widget=forms.Select(attrs={
                "class": "switchable",
                "data-slug": "source",
            }),
            required=False)

        self.fields["snapshot"] = forms.ChoiceField(
            label=_("Use share group snapshot as a source"),
            widget=forms.SelectWidget(attrs={
                "class": "switched",
                "data-switch-on": "source",
                "data-source-snapshot": _("Share Group Snapshot"),
            }),
            required=True)

        if ("snapshot_id" in request.GET or
                kwargs.get("data", {}).get("snapshot")):
            try:
                snapshot = self.get_share_group_snapshot(
                    request,
                    request.GET.get(
                        "snapshot_id",
                        kwargs.get("data", {}).get("snapshot")))
                self.fields["name"].initial = snapshot.name
                self.fields["snapshot"].choices = (
                    (snapshot.id, snapshot.name or snapshot.id),
                )
                try:
                    # Set the share group type from the original share group
                    orig_sg = manila.share_group_get(
                        request, snapshot.share_group_id)
                    self.fields["sgt"].initial = orig_sg.share_group_type_id
                except Exception:
                    pass
                del self.fields["source_type"]
            except Exception:
                exceptions.handle(
                    request,
                    _("Unable to load the specified share group snapshot."))
        else:
            source_type_choices = []
            try:
                snapshot_list = manila.share_group_snapshot_list(request)
                snapshots = [s for s in snapshot_list
                             if s.status == "available"]
                if snapshots:
                    source_type_choices.append(("snapshot", _("Snapshot")))
                    self.fields["snapshot"].choices = (
                        [("", _("Choose a snapshot"))] +
                        [(s.id, s.name or s.id) for s in snapshots]
                    )
                else:
                    del self.fields["snapshot"]
            except Exception:
                exceptions.handle(
                    request,
                    _("Unable to retrieve share group snapshots."))

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

            self.fields["az"] = forms.ChoiceField(
                label=_("Availability Zone"),
                widget=forms.SelectWidget(attrs={
                    "class": "switched",
                    "data-switch-on": "source",
                    "data-source-none": _("Availability Zone"),
                }),
                required=False)

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

            share_group_types = manila.share_group_type_list(request)
            self.fields["sgt"] = forms.ChoiceField(
                label=_("Share Group Type"),
                widget=forms.fields.SelectWidget(attrs={
                    "class": "switched switchable",
                    "data-switch-on": "source",
                    "data-source-none": _("Share Group Type"),
                    "data-slug": "sgt",
                }),
                required=True)
            self.fields["sgt"].choices = (
                [("", "")] + [(sgt.id, sgt.name) for sgt in share_group_types])

            # NOTE(vponomaryov): create separate set of available share types
            # for each of share group types.
            share_types = manila.share_type_list(request)
            for sgt in share_group_types:
                st_choices = (
                    [(st.id, st.name)
                     for st in share_types if st.id in sgt.share_types])
                amount_of_choices = len(st_choices)
                st_field_name = self.st_field_name_prefix + sgt.id
                if amount_of_choices < 2:
                    st_field = forms.ChoiceField(
                        label=_("Share Types"),
                        choices=st_choices,
                        widget=forms.fields.SelectWidget(attrs={
                            "class": "switched",
                            "data-switch-on": "sgt",
                            "data-sgt-%s" % sgt.id: _(
                                "Share Types (one available)"),
                        }),
                        required=True)
                else:
                    height = min(30 * amount_of_choices, 155)
                    st_field = forms.MultipleChoiceField(
                        label=_("Share Types"),
                        choices=st_choices,
                        widget=forms.fields.widgets.SelectMultiple(attrs={
                            "style": "max-height: %spx;" % height,
                            "class": "switched",
                            "data-switch-on": "sgt",
                            "data-sgt-%s" % sgt.id: _(
                                "Share Types (multiple available)"),
                        }),
                        required=False)
                    st_field.initial = st_choices[0]
                self.fields[st_field_name] = st_field

            self.fields["share_network"] = forms.ChoiceField(
                label=_("Share Network"),
                widget=forms.fields.SelectWidget(attrs={
                    "class": "switched",
                    "data-switch-on": "source",
                    "data-source-none": _("Share Network"),
                }),
                required=False)
            share_networks = manila.share_network_list(request)
            self.fields["share_network"].choices = (
                [("", "")] +
                [(sn.id, sn.name or sn.id) for sn in share_networks])
Exemple #5
0
    def __init__(self, request, *args, **kwargs):
        super(CreateShareGroupForm, self).__init__(request, *args, **kwargs)
        self.st_field_name_prefix = "share-type-choices-"
        self.fields["source_type"] = forms.ChoiceField(
            label=_("Source Type"),
            widget=forms.Select(attrs={
                "class": "switchable",
                "data-slug": "source",
            }),
            required=False)

        self.fields["snapshot"] = forms.ChoiceField(
            label=_("Use share group snapshot as a source"),
            widget=forms.SelectWidget(
                attrs={
                    "class": "switched",
                    "data-switch-on": "source",
                    "data-source-snapshot": _("Share Group Snapshot"),
                }),
            required=True)

        if ("snapshot_id" in request.GET
                or kwargs.get("data", {}).get("snapshot")):
            try:
                snapshot = self.get_share_group_snapshot(
                    request,
                    request.GET.get("snapshot_id",
                                    kwargs.get("data", {}).get("snapshot")))
                self.fields["name"].initial = snapshot.name
                self.fields["snapshot"].choices = ((snapshot.id, snapshot.name
                                                    or snapshot.id), )
                try:
                    # Set the share group type from the original share group
                    orig_sg = manila.share_group_get(request,
                                                     snapshot.share_group_id)
                    self.fields["sgt"].initial = orig_sg.share_group_type_id
                except Exception:
                    pass
                del self.fields["source_type"]
            except Exception:
                exceptions.handle(
                    request,
                    _("Unable to load the specified share group snapshot."))
        else:
            source_type_choices = []
            try:
                snapshot_list = manila.share_group_snapshot_list(request)
                snapshots = [
                    s for s in snapshot_list if s.status == "available"
                ]
                if snapshots:
                    source_type_choices.append(("snapshot", _("Snapshot")))
                    self.fields["snapshot"].choices = (
                        [("", _("Choose a snapshot"))] +
                        [(s.id, s.name or s.id) for s in snapshots])
                else:
                    del self.fields["snapshot"]
            except Exception:
                exceptions.handle(
                    request, _("Unable to retrieve share group snapshots."))

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

            self.fields["az"] = forms.ChoiceField(
                label=_("Availability Zone"),
                widget=forms.SelectWidget(
                    attrs={
                        "class": "switched",
                        "data-switch-on": "source",
                        "data-source-none": _("Availability Zone"),
                    }),
                required=False)

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

            share_group_types = manila.share_group_type_list(request)
            self.fields["sgt"] = forms.ChoiceField(
                label=_("Share Group Type"),
                widget=forms.fields.SelectWidget(
                    attrs={
                        "class": "switched switchable",
                        "data-switch-on": "source",
                        "data-source-none": _("Share Group Type"),
                        "data-slug": "sgt",
                    }),
                required=True)
            self.fields["sgt"].choices = (
                [("", "")] + [(utils.transform_dashed_name(sgt.id), sgt.name)
                              for sgt in share_group_types])

            # NOTE(vponomaryov): create separate set of available share types
            # for each of share group types.
            share_types = manila.share_type_list(request)
            for sgt in share_group_types:
                st_choices = ([(st.id, st.name) for st in share_types
                               if st.id in sgt.share_types])
                amount_of_choices = len(st_choices)
                st_field_name = (self.st_field_name_prefix +
                                 utils.transform_dashed_name(sgt.id))
                if amount_of_choices < 2:
                    st_field = forms.ChoiceField(
                        label=_("Share Types"),
                        choices=st_choices,
                        widget=forms.fields.SelectWidget(
                            attrs={
                                "class":
                                "switched",
                                "data-switch-on":
                                "sgt",
                                "data-sgt-%s" % utils.transform_dashed_name(sgt.id):
                                _("Share Types (one available)"),
                            }),
                        required=True)
                else:
                    height = min(30 * amount_of_choices, 155)
                    st_field = forms.MultipleChoiceField(
                        label=_("Share Types"),
                        choices=st_choices,
                        widget=forms.fields.widgets.SelectMultiple(
                            attrs={
                                "style":
                                "max-height: %spx;" % height,
                                "class":
                                "switched",
                                "data-switch-on":
                                "sgt",
                                "data-sgt-%s" % utils.transform_dashed_name(sgt.id):
                                _("Share Types (multiple available)"),
                            }),
                        required=False)
                    st_field.initial = st_choices[0]
                self.fields[st_field_name] = st_field

            self.fields["share_network"] = forms.ChoiceField(
                label=_("Share Network"),
                widget=forms.fields.SelectWidget(
                    attrs={
                        "class": "switched",
                        "data-switch-on": "source",
                        "data-source-none": _("Share Network"),
                    }),
                required=False)
            share_networks = manila.share_network_list(request)
            self.fields["share_network"].choices = ([("", "")] +
                                                    [(sn.id, sn.name or sn.id)
                                                     for sn in share_networks])