def middleware_clean(self, data): targetobj = self.cleaned_data.get('iscsi_target') with client as c: target = c.call('iscsi.target.query', [('id', '=', targetobj.id)], {'get': True}) data['auth'] = data.pop('authgroup') or None data['authmethod'] = AUTHMETHOD_LEGACY_MAP.get(data.pop('authtype')) data['initiator'] = data.pop('initiatorgroup') data['portal'] = data.pop('portalgroup') if self.instance.id: orig = models.iSCSITargetGroups.objects.get(pk=self.instance.id).__dict__ old = { 'authmethod': AUTHMETHOD_LEGACY_MAP.get(orig['iscsi_target_authtype']), 'portal': orig['iscsi_target_portalgroup_id'], 'initiator': orig['iscsi_target_initiatorgroup_id'], 'auth': orig['iscsi_target_authgroup'], } for idx, i in enumerate(target['groups']): if ( i['portal'] == old['portal'] and i['initiator'] == old['initiator'] and i['auth'] == old['auth'] and i['authmethod'] == old['authmethod'] ): break else: raise forms.ValidationError('Target group not found') target['groups'][idx] = data else: target['groups'].append(data) self.instance.id = targetobj.id target.pop('id') return target
def middleware_clean(self, data): targetobj = self.cleaned_data.get('iscsi_target') with client as c: target = c.call('iscsi.target.query', [('id', '=', targetobj.id)], {'get': True}) data['auth'] = data.pop('authgroup') or None data['authmethod'] = AUTHMETHOD_LEGACY_MAP.get(data.pop('authtype')) data['initiator'] = data.pop('initiatorgroup') data['portal'] = data.pop('portalgroup') if self.instance.id: orig = models.iSCSITargetGroups.objects.get(pk=self.instance.id).__dict__ old = { 'authmethod': AUTHMETHOD_LEGACY_MAP.get(orig['iscsi_target_authtype']), 'portal': orig['iscsi_target_portalgroup_id'], 'initiator': orig['iscsi_target_initiatorgroup_id'], 'auth': orig['iscsi_target_authgroup'], } for idx, i in enumerate(target['groups']): if ( i['portal'] == old['portal'] and i['initiator'] == old['initiator'] and i['auth'] == old['auth'] and i['authmethod'] == old['authmethod'] ): break else: raise forms.ValidationError('Target group not found') target['groups'][idx] = data else: target['groups'].append(data) self.instance.id = targetobj.id target.pop('id') return target
def middleware_clean(self, data): data['listen'] = self._listen data['discovery_authmethod'] = AUTHMETHOD_LEGACY_MAP.get( data.pop('discoveryauthmethod')) data['discovery_authgroup'] = data.pop('discoveryauthgroup') or None data.pop('tag', None) return data
def cleanformset_iscsitargetgroups(self, fs, forms): for form in forms: if not hasattr(form, 'cleaned_data'): continue if form.cleaned_data.get('DELETE'): continue data = { 'authmethod': AUTHMETHOD_LEGACY_MAP.get( form.cleaned_data.get('iscsi_target_authtype') ), } for i in ('portal', 'auth', 'initiator'): group = form.cleaned_data.get(f'iscsi_target_{i}group') if group == '-1': group = None if group: if hasattr(group, 'id'): data[i] = group.id else: data[i] = int(group) else: data[i] = None self._groups.append(data) return True
def cleanformset_iscsitargetgroups(self, fs, forms): for form in forms: if not hasattr(form, 'cleaned_data'): continue if form.cleaned_data.get('DELETE'): continue data = { 'authmethod': AUTHMETHOD_LEGACY_MAP.get( form.cleaned_data.get('iscsi_target_authtype')), } for i in ('portal', 'auth', 'initiator'): group = form.cleaned_data.get(f'iscsi_target_{i}group') if group == '-1': group = None if group: if hasattr(group, 'id'): data[i] = group.id else: data[i] = int(group) else: data[i] = None self._groups.append(data) return True
def middleware_clean(self, data): data['listen'] = self._listen data['discovery_authmethod'] = AUTHMETHOD_LEGACY_MAP.get(data.pop('discoveryauthmethod')) data['discovery_authgroup'] = data.pop('discoveryauthgroup') or None data.pop('tag', None) return data