def handle(self, request, data): try: source_type = data.get('source_type') if (data.get("snapshot") and source_type in (None, 'snapshot')): snapshot = self.get_share_group_snapshot( request, data["snapshot"]) snapshot_id = snapshot.id source_sg = manila.share_group_get( request, snapshot.share_group_id) data['sgt'] = source_sg.share_group_type_id else: snapshot_id = None share_group = manila.share_group_create( request, name=data['name'], description=data['description'], share_group_type=data['sgt'], share_types=None if snapshot_id else data.get('share_types'), share_network=( None if snapshot_id else data.get('share_network')), source_share_group_snapshot=snapshot_id, availability_zone=None if snapshot_id else data['az']) message = _('Creating share group "%s"') % data['name'] messages.success(request, message) return share_group except ValidationError as e: self.api_error(e.messages[0]) return False except Exception: exceptions.handle(request, ignore=True) self.api_error(_("Unable to create share group.")) return False
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)
def handle(self, request, data): try: source_type = data.get('source_type') if (data.get("snapshot") and source_type in (None, 'snapshot')): snapshot = self.get_share_group_snapshot( request, data["snapshot"]) snapshot_id = snapshot.id source_sg = manila.share_group_get(request, snapshot.share_group_id) data['sgt'] = source_sg.share_group_type_id else: snapshot_id = None share_group = manila.share_group_create( request, name=data['name'], description=data['description'], share_group_type=utils.transform_dashed_name(data['sgt']), share_types=None if snapshot_id else data.get('share_types'), share_network=(None if snapshot_id else data.get('share_network')), source_share_group_snapshot=snapshot_id, availability_zone=None if snapshot_id else data['az']) message = _('Creating share group "%s"') % data['name'] messages.success(request, message) return share_group except ValidationError as e: self.api_error(e.messages[0]) return False except Exception: exceptions.handle(request, ignore=True) self.api_error(_("Unable to create share group.")) return False
def test_share_group_get(self): sg = "fake_share_group" result = api.share_group_get(self.request, sg) self.assertEqual(self.manilaclient.share_groups.get.return_value, result) self.manilaclient.share_groups.get.assert_called_once_with(sg)
def test_share_group_get(self): sg = "fake_share_group" result = api.share_group_get(self.request, sg) self.assertEqual( self.manilaclient.share_groups.get.return_value, result) self.manilaclient.share_groups.get.assert_called_once_with(sg)
def get_object(self): if not hasattr(self, "_object"): sg_id = self.kwargs["share_group_id"] try: self._object = manila.share_group_get(self.request, sg_id) except Exception: msg = _("Unable to retrieve share group '%s'.") % sg_id url = reverse('horizon:admin:share_groups:index') exceptions.handle(self.request, msg, redirect=url) return self._object
def get_object(self): if not hasattr(self, "_object"): sg_id = self.kwargs['share_group_id'] try: self._object = manila.share_group_get(self.request, sg_id) except Exception: msg = _('Unable to retrieve share group.') url = reverse('horizon:project:share_groups:index') exceptions.handle(self.request, msg, redirect=url) return self._object
def get_object(self): if not hasattr(self, "_object"): sg_id = self.kwargs["share_group_id"] try: self._object = manila.share_group_get(self.request, sg_id) except Exception: msg = _("Unable to retrieve share group '%s'.") % sg_id url = reverse('horizon:admin:share_groups:index') exceptions.handle(self.request, msg, redirect=url) return self._object
def get_object(self): if not hasattr(self, "_object"): sg_id = self.kwargs['share_group_id'] try: self._object = manila.share_group_get(self.request, sg_id) except Exception: msg = _('Unable to retrieve share group.') url = reverse('horizon:project:share_groups:index') exceptions.handle(self.request, msg, redirect=url) return self._object
def get_data(self): try: share_group_snapshot = manila.share_group_snapshot_get( self.request, self.kwargs['share_group_snapshot_id']) sg = manila.share_group_get( self.request, share_group_snapshot.share_group_id) share_group_snapshot.sg_name_or_id = sg.name or sg.id except Exception: exceptions.handle( self.request, _('Unable to retrieve share group snapshot details.'), redirect=self.redirect_url) return share_group_snapshot
def get_context_data(self, **kwargs): context = super(self.__class__, self).get_context_data(**kwargs) sg_id = self.kwargs['share_group_id'] try: sg = manila.share_group_get(self.request, sg_id) context['share_group_name'] = sg.name or sg_id except Exception: exceptions.handle( self.request, _("Unable to get the specified share group '%s' for " "snapshot creation.") % sg_id) context['share_group_name'] = sg_id context['share_group_id'] = sg_id # TODO(vponomaryov): add support of quotas when it is implemented # for share group snapshots on server side. return context
def get_context_data(self, **kwargs): context = super(self.__class__, self).get_context_data(**kwargs) sg_id = self.kwargs['share_group_id'] try: sg = manila.share_group_get(self.request, sg_id) context['share_group_name'] = sg.name or sg_id except Exception: exceptions.handle( self.request, _("Unable to get the specified share group '%s' for " "snapshot creation.") % sg_id) context['share_group_name'] = sg_id context['share_group_id'] = sg_id # TODO(vponomaryov): add support of quotas when it is implemented # for share group snapshots on server side. return context
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)
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])
def get_data(self, request, sg_id): sg = manila.share_group_get(request, sg_id) return sg
def get_data(self, request, sg_id): sg = manila.share_group_get(request, sg_id) return sg
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])