Exemplo n.º 1
0
 def get_data(self):
     try:
         share_group_id = self.kwargs['share_group_id']
         share_group = manila.share_group_get(self.request, share_group_id)
         members = manila.share_list(
             self.request, search_opts={"share_group_id": share_group_id})
         share_group.members = members
         share_group.share_group_type = manila.share_group_type_get(
             self.request, share_group.share_group_type_id)
         share_types = manila.share_type_list(self.request)
         share_group.share_types = [{
             "id":
             st.id,
             "name":
             st.name,
             "is_public":
             getattr(st, 'share_type_access:is_public'),
             "dhss":
             st.extra_specs.get('driver_handles_share_servers')
         } for st in share_types if st.id in share_group.share_types]
         return share_group
     except Exception:
         redirect = reverse('horizon:admin:share_groups:index')
         exceptions.handle(self.request,
                           _('Unable to retrieve share group details.'),
                           redirect=redirect)
Exemplo n.º 2
0
 def __init__(self, request, *args, **kwargs):
     super(self.__class__, self).__init__(request, *args, **kwargs)
     manila_features = getattr(settings, 'OPENSTACK_MANILA_FEATURES', {})
     self.enable_public_share_group_type_creation = manila_features.get(
         'enable_public_share_group_type_creation', True)
     if not self.enable_public_share_group_type_creation:
         self.fields.pop('is_public')
     share_type_choices = manila.share_type_list(request)
     self.fields['share_types'].choices = [
         (choice.id, choice.name) for choice in share_type_choices]
Exemplo n.º 3
0
 def get_share_types_data(self):
     try:
         share_types = manila.share_type_list(self.request)
     except Exception:
         exceptions.handle(self.request,
                           _('Unable to retrieve share types.'))
         return []
     # Convert dict with extra specs to friendly view
     for st in share_types:
         st.extra_specs = common_utils.metadata_to_str(
             st.extra_specs, 8, 45)
     return share_types
Exemplo n.º 4
0
 def __init__(self, request, *args, **kwargs):
     super(ManageShare, self).__init__(request, *args, **kwargs)
     share_types = manila.share_type_list(request)
     # NOTE(vponomaryov): choose only those share_types that have spec
     # 'driver_handles_share_servers' set to 'False' value or alias of it.
     dhss_key = 'driver_handles_share_servers'
     st_choices = [('', ''), ]
     for st in share_types:
         dhss = st.to_dict()['extra_specs'].get(dhss_key)
         if dhss and dhss.lower() in strutils.FALSE_STRINGS:
             st_choices.append((st.name, st.name))
     self.fields['share_type'].choices = st_choices
Exemplo n.º 5
0
 def __init__(self, request, *args, **kwargs):
     super(MigrationStart, self).__init__(request, *args, **kwargs)
     share_networks = manila.share_network_list(request)
     share_types = manila.share_type_list(request)
     dests = manila.pool_list(request)
     dest_choices = [('', '')] + [(d.name, d.name) for d in dests]
     st_choices = [('', '')] + [(st.id, st.name) for st in share_types]
     sn_choices = ([('', '')] + [(sn.id, sn.name or sn.id)
                                 for sn in share_networks])
     self.fields['host'].choices = dest_choices
     self.fields['new_share_type'].choices = st_choices
     self.fields['new_share_network'].choices = sn_choices
Exemplo n.º 6
0
 def get_share_types_data(self):
     try:
         share_types = manila.share_type_list(self.request)
     except Exception:
         exceptions.handle(
             self.request, _('Unable to retrieve share types.'))
         return []
     # Convert dict with extra specs to friendly view
     for st in share_types:
         st.extra_specs = common_utils.metadata_to_str(
             st.extra_specs, 8, 45)
     return share_types
Exemplo n.º 7
0
 def __init__(self, request, *args, **kwargs):
     super(MigrationStart, self).__init__(request, *args, **kwargs)
     share_networks = manila.share_network_list(request)
     share_types = manila.share_type_list(request)
     dests = manila.pool_list(request)
     dest_choices = [('', '')] + [(d.name, d.name) for d in dests]
     st_choices = [('', '')] + [(st.id, st.name) for st in share_types]
     sn_choices = (
         [('', '')] +
         [(sn.id, sn.name or sn.id) for sn in share_networks])
     self.fields['host'].choices = dest_choices
     self.fields['new_share_type'].choices = st_choices
     self.fields['new_share_network'].choices = sn_choices
Exemplo n.º 8
0
 def get_share_types_data(self):
     try:
         share_types = manila.share_type_list(self.request)
     except Exception:
         share_types = []
         exceptions.handle(self.request,
                           _("Unable to retrieve share types"))
     # Convert dict with extra specs to friendly view
     for st in share_types:
         es_str = ""
         for k, v in st.extra_specs.iteritems():
             es_str += "%s=%s\r\n<br />" % (k, v)
         st.extra_specs = mark_safe(es_str)
     return share_types
Exemplo n.º 9
0
 def get_share_types_data(self):
     try:
         share_types = manila.share_type_list(self.request)
     except Exception:
         share_types = []
         exceptions.handle(self.request,
                           _("Unable to retrieve share types"))
     # Convert dict with extra specs to friendly view
     for st in share_types:
         es_str = ""
         for k, v in st.extra_specs.iteritems():
             es_str += "%s=%s\r\n<br />" % (k, v)
         st.extra_specs = mark_safe(es_str)
     return share_types
Exemplo n.º 10
0
 def __init__(self, request, *args, **kwargs):
     super(ManageShare, self).__init__(request, *args, **kwargs)
     share_types = manila.share_type_list(request)
     # NOTE(vponomaryov): choose only those share_types that have spec
     # 'driver_handles_share_servers' set to 'False' value or alias of it.
     dhss_key = 'driver_handles_share_servers'
     st_choices = [
         ('', ''),
     ]
     for st in share_types:
         dhss = st.to_dict()['extra_specs'].get(dhss_key)
         if dhss and dhss.lower() in strutils.FALSE_STRINGS:
             st_choices.append((st.name, st.name))
     self.fields['share_type'].choices = st_choices
Exemplo n.º 11
0
    def get_share_group_types_data(self):
        try:
            share_group_types = manila.share_group_type_list(self.request)
        except Exception:
            exceptions.handle(
                self.request, _('Unable to retrieve share group types.'))
            return []

        share_types = manila.share_type_list(self.request)
        st_mapping = {}
        for st in share_types:
            st_mapping[st.id] = st.name
        for sgt in share_group_types:
            sgt.group_specs = common_utils.metadata_to_str(
                sgt.group_specs, 8, 45)
            sgt.share_types = ", ".join(
                [st_mapping[st] for st in sgt.share_types])
        return share_group_types
Exemplo n.º 12
0
    def get_share_group_types_data(self):
        try:
            share_group_types = manila.share_group_type_list(self.request)
        except Exception:
            exceptions.handle(
                self.request, _('Unable to retrieve share group types.'))
            return []

        share_types = manila.share_type_list(self.request)
        st_mapping = {}
        for st in share_types:
            st_mapping[st.id] = st.name
        for sgt in share_group_types:
            sgt.group_specs = common_utils.metadata_to_str(
                sgt.group_specs, 8, 45)
            sgt.share_types = ", ".join(
                [st_mapping[st] for st in sgt.share_types])
        return share_group_types
Exemplo n.º 13
0
 def get_data(self):
     try:
         share_group_id = self.kwargs['share_group_id']
         share_group = manila.share_group_get(self.request, share_group_id)
         members = manila.share_list(
             self.request, search_opts={"share_group_id": share_group_id})
         share_group.members = members
         share_types = manila.share_type_list(self.request)
         share_group.share_types = [
             {"id": st.id,
              "name": st.name,
              "is_public": getattr(st, 'share_type_access:is_public'),
              "dhss": st.extra_specs.get('driver_handles_share_servers')}
             for st in share_types if st.id in share_group.share_types
         ]
         return share_group
     except Exception:
         redirect = reverse('horizon:admin:share_groups:index')
         exceptions.handle(
             self.request,
             _('Unable to retrieve share group details.'),
             redirect=redirect)
Exemplo n.º 14
0
 def __init__(self, request, *args, **kwargs):
     super(ManageShare, self).__init__(request, *args, **kwargs)
     share_types = manila.share_type_list(request)
     # NOTE(vponomaryov): choose only those share_types that have spec
     # 'driver_handles_share_servers' set to 'False' value or alias of it.
     dhss_key = 'driver_handles_share_servers'
     st_choices = [('', ''), ]
     for st in share_types:
         dhss = st.to_dict()['extra_specs'].get(dhss_key)
         if dhss and dhss.lower() in strutils.FALSE_STRINGS:
             st_choices.append((st.name, st.name))
     self.fields['share_type'].choices = st_choices
     # 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.fields['protocol'].choices = ([(' ', ' ')] +
                                        [(enabled_proto, enabled_proto)
                                        for enabled_proto in
                                        self.enabled_share_protocols])
Exemplo n.º 15
0
 def __init__(self, request, *args, **kwargs):
     super(ManageShare, self).__init__(request, *args, **kwargs)
     share_types = manila.share_type_list(request)
     # NOTE(vponomaryov): choose only those share_types that have spec
     # 'driver_handles_share_servers' set to 'False' value or alias of it.
     dhss_key = 'driver_handles_share_servers'
     st_choices = [('', ''), ]
     for st in share_types:
         dhss = st.to_dict()['extra_specs'].get(dhss_key)
         if dhss and dhss.lower() in strutils.FALSE_STRINGS:
             st_choices.append((st.name, st.name))
     self.fields['share_type'].choices = st_choices
     # 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.fields['protocol'].choices = ([(' ', ' ')] +
                                        [(enabled_proto, enabled_proto)
                                        for enabled_proto in
                                        self.enabled_share_protocols])
Exemplo n.º 16
0
    def __init__(self, request, *args, **kwargs):
        super(CreateForm, self).__init__(request, *args, **kwargs)
        share_protos = ('NFS', 'CIFS', 'GlusterFS', 'HDFS', )
        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])
        self.fields['share_proto'].choices = [(sp, sp) for sp in share_protos]
        if "snapshot_id" in request.GET:
            try:
                snapshot = self.get_snapshot(request,
                                             request.GET["snapshot_id"])
                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)
                    self.fields['share_type'].initial = orig_share.share_type
                except Exception:
                    pass
                self.fields['size'].help_text = _(
                    'Share size must be equal to or greater than the snapshot '
                    'size (%sGB)') % 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']

        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.insert(5, sn_field_name, sn_field)
Exemplo n.º 17
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])
Exemplo n.º 18
0
    def __init__(self, request, *args, **kwargs):
        super(CreateForm, self).__init__(request, *args, **kwargs)
        share_protos = ('NFS', 'CIFS', 'GlusterFS', 'HDFS', 'CephFS')
        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 = nova.availability_zone_list(request)
        self.fields['availability_zone'].choices = (
            [("", "")] +
            [(az.zoneName, az.zoneName) for az in availability_zones])

        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}))
        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 share_protos]
        if "snapshot_id" in request.GET:
            try:
                snapshot = self.get_snapshot(request,
                                             request.GET["snapshot_id"])
                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)
                    self.fields['share_type'].initial = orig_share.share_type
                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']
Exemplo n.º 19
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])
Exemplo n.º 20
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']
Exemplo n.º 21
0
    def test_share_type_list(self):
        api.share_type_list(self.request)

        self.manilaclient.share_types.list.assert_called_once_with()
Exemplo n.º 22
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']
Exemplo n.º 23
0
    def __init__(self, request, *args, **kwargs):
        super(CreateForm, self).__init__(request, *args, **kwargs)
        share_protos = ('NFS', 'CIFS', 'GlusterFS', 'HDFS', 'CephFS')
        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 = nova.availability_zone_list(request)
        self.fields['availability_zone'].choices = (
            [("", "")] + [(az.zoneName, az.zoneName)
                          for az in availability_zones])

        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}))
        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 share_protos]
        if "snapshot_id" in request.GET:
            try:
                snapshot = self.get_snapshot(request,
                                             request.GET["snapshot_id"])
                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)
                    self.fields['share_type'].initial = orig_share.share_type
                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']