def test_share_group_type_list(self, show_all): result = api.share_group_type_list(self.request, show_all) self.assertIsNotNone(result) self.assertEqual(self.manilaclient.share_group_types.list.return_value, result) self.manilaclient.share_group_types.list.assert_called_once_with( show_all=show_all)
def test_share_group_type_list(self, show_all): result = api.share_group_type_list(self.request, show_all) self.assertIsNotNone(result) self.assertEqual( self.manilaclient.share_group_types.list.return_value, result) self.manilaclient.share_group_types.list.assert_called_once_with( show_all=show_all)
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
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
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])
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])