def handle(self, request, context): ext_policy_target_id = self.initial['ext_policy_target_id'] url = reverse("horizon:project:policytargets:ext_policy_targetdetails", kwargs={'ext_policy_target_id': ext_policy_target_id}) try: ext_policy_target = client.ext_policy_target_get( request, ext_policy_target_id) old_policy_rule_sets = ext_policy_target.get( "consumed_policy_rule_sets") for policy_rule_set in context['policy_rule_set']: old_policy_rule_sets.remove(policy_rule_set) consumed = dict([(item, 'string') for item in old_policy_rule_sets]) client.ext_policy_target_update(request, ext_policy_target_id, consumed_policy_rule_sets=consumed) msg = _('Policy Rule Set removed successfully!') messages.success(request, msg) LOG.debug(msg) return http.HttpResponseRedirect(url) except Exception: msg = _('Failed to remove policy_rule_set!') redirect = url LOG.error(msg) exceptions.handle(request, msg, redirect=redirect)
def handle(self, request, context): ext_policy_target_id = self.initial['ext_policy_target_id'] ext_policy_target = client.ext_policy_target_get( request, ext_policy_target_id) url = reverse("horizon:project:policytargets:ext_policy_targetdetails", kwargs={'ext_policy_target_id': ext_policy_target_id}) try: for policy_rule_set in ext_policy_target.get( "provided_policy_rule_sets"): context['policy_rule_set'].append(policy_rule_set) policy_rule_sets = dict([(item, 'string') for item in context['policy_rule_set']]) client.ext_policy_target_update( request, ext_policy_target_id, provided_policy_rule_sets=policy_rule_sets) msg = _('Policy Rule Set added successfully!') messages.success(request, msg) LOG.debug(msg) return http.HttpResponseRedirect(url) except Exception: u = "horizon:project:policytargets:ext_policy_targetdetails" msg = _('Failed to add policy_rule_set!') redirect = reverse( u, kwargs={'ext_policy_target_id': ext_policy_target_id}) LOG.error(msg) exceptions.handle(request, msg, redirect=redirect)
def handle(self, request, context): ext_policy_target_id = self.initial['ext_policy_target_id'] url = reverse("horizon:project:policytargets:ext_policy_targetdetails", kwargs={'ext_policy_target_id': ext_policy_target_id}) try: ext_policy_target = client.ext_policy_target_get(request, ext_policy_target_id) old_policy_rule_sets = ext_policy_target.get( "consumed_policy_rule_sets") for policy_rule_set in context['policy_rule_set']: old_policy_rule_sets.remove(policy_rule_set) consumed = dict([(item, 'string') for item in old_policy_rule_sets]) client.ext_policy_target_update( request, ext_policy_target_id, consumed_policy_rule_sets=consumed) msg = _('Policy Rule Set removed successfully!') messages.success(request, msg) LOG.debug(msg) return http.HttpResponseRedirect(url) except Exception: msg = _('Failed to remove policy_rule_set!') redirect = url LOG.error(msg) exceptions.handle(request, msg, redirect=redirect)
def handle(self, request, context): ext_policy_target_id = self.initial['ext_policy_target_id'] ext_policy_target = client.ext_policy_target_get(request, ext_policy_target_id) url = reverse("horizon:project:policytargets:ext_policy_targetdetails", kwargs={'ext_policy_target_id': ext_policy_target_id}) try: for policy_rule_set in ext_policy_target.get( "provided_policy_rule_sets"): context['policy_rule_set'].append(policy_rule_set) policy_rule_sets = dict([(item, 'string') for item in context['policy_rule_set']]) client.ext_policy_target_update( request, ext_policy_target_id, provided_policy_rule_sets=policy_rule_sets) msg = _('Policy Rule Set added successfully!') messages.success(request, msg) LOG.debug(msg) return http.HttpResponseRedirect(url) except Exception: u = "horizon:project:policytargets:ext_policy_targetdetails" msg = _('Failed to add policy_rule_set!') redirect = reverse(u, kwargs={'ext_policy_target_id': ext_policy_target_id}) LOG.error(msg) exceptions.handle(request, msg, redirect=redirect)
def handle(self, request, context): ext_policy_target_id = self.initial['ext_policy_target_id'] name_or_id = context.get('name') or ext_policy_target_id try: if 'provided_policy_rule_sets' in context: if context.get('provided_policy_rule_sets'): context['provided_policy_rule_sets'] = dict( [(i, 'string') for i in context['provided_policy_rule_sets']]) else: context['provided_policy_rule_sets'] = None if 'consumed_policy_rule_sets' in context: if context.get('consumed_policy_rule_sets'): context['consumed_policy_rule_sets'] = dict( [(i, 'string') for i in context['consumed_policy_rule_sets']]) else: context['consumed_policy_rule_sets'] = None if context.get('name'): context['name'] = html.escape(context['name']) if context.get('description'): context['description'] = html.escape(context['description']) ext_policy_target = client.ext_policy_target_update( request, ext_policy_target_id, **context) msg = _('External Group %s was successfully updated.') % name_or_id LOG.debug(msg) messages.success(request, msg) return ext_policy_target except Exception as e: msg = _('Failed to update Group %(name)s. %(reason)s') % {'name': name_or_id, 'reason': str(e)} LOG.error(msg) redirect = reverse(self.failure_url) exceptions.handle(request, msg, redirect=redirect)
def handle(self, request, context): ext_policy_target_id = self.initial['ext_policy_target_id'] name_or_id = context.get('name') or ext_policy_target_id try: if 'provided_policy_rule_sets' in context: if context.get('provided_policy_rule_sets'): context['provided_policy_rule_sets'] = dict([ (i, 'string') for i in context['provided_policy_rule_sets'] ]) else: context['provided_policy_rule_sets'] = None if 'consumed_policy_rule_sets' in context: if context.get('consumed_policy_rule_sets'): context['consumed_policy_rule_sets'] = dict([ (i, 'string') for i in context['consumed_policy_rule_sets'] ]) else: context['consumed_policy_rule_sets'] = None if context.get('name'): context['name'] = html.escape(context['name']) if context.get('description'): context['description'] = html.escape(context['description']) ext_policy_target = client.ext_policy_target_update( request, ext_policy_target_id, **context) msg = _('External Group %s was successfully updated.') % name_or_id LOG.debug(msg) messages.success(request, msg) return ext_policy_target except Exception as e: msg = _('Failed to update Group %(name)s. %(reason)s') % { 'name': name_or_id, 'reason': str(e) } LOG.error(msg) redirect = reverse(self.failure_url) exceptions.handle(request, msg, redirect=redirect)