def __init__(self, request, *args, **kwargs): super(UpdatePolicyActionForm, self).__init__(request, *args, **kwargs) try: policyaction_id = self.initial['policyaction_id'] pa = client.policyaction_get(request, policyaction_id) self.fields['name'].initial = pa.name self.fields['description'].initial = pa.description except Exception: pass
def get_context_data(self, request): paid = self.tab_group.kwargs['policyaction_id'] try: policyaction = client.policyaction_get(request, paid) policyaction = gfilters.update_policyaction_attributes(request, policyaction) except Exception: exceptions.handle(request, _('Unable to retrieve policyaction details.'), redirect=self.failure_url) return {'policyaction': policyaction}
def __init__(self, request, *args, **kwargs): super(UpdatePolicyActionForm, self).__init__(request, *args, **kwargs) try: policyaction_id = self.initial["policyaction_id"] pa = client.policyaction_get(request, policyaction_id) self.fields["name"].initial = pa.name self.fields["description"].initial = pa.description self.fields["shared"].initial = pa.shared except Exception: pass
def get_context_data(self, request): cid = self.tab_group.kwargs['policy_rule_set_id'] try: policy_rule_set = client.policy_rule_set_get(request, cid) rules = client.policyrule_list( request, tenant_id=request.user.tenant_id, policy_rule_set_id=policy_rule_set.id) rules = [ item for item in rules if item.id in policy_rule_set.policy_rules ] rules_with_details = [] for rule in rules: r = {} r['name'] = rule.name r['id'] = rule.id action_list = [] for aid in rule.policy_actions: action = client.policyaction_get(request, aid) a = {'id': action.id} if action.action_value: if action.action_type == 'redirect': scspec = client.get_servicechain_spec( request, action.action_value) a['name'] = "Redirect:%s" % scspec.name else: values = (str(action.action_type), str(action.action_value)) name = "%s:%s" % values a['name'] = name else: a['name'] = str(action.action_type) action_list.append(a) r['actions'] = action_list r['classifier'] = client.policyclassifier_get( request, rule.policy_classifier_id) rules_with_details.append(r) except Exception as e: msg = _('Unable to retrieve policy_rule_set details.') % (str(e)) exceptions.handle(request, msg, redirect=self.failure_url) return { 'policy_rule_set': policy_rule_set, 'rules_with_details': rules_with_details }
def get_context_data(self, request): cid = self.tab_group.kwargs['policy_rule_set_id'] try: policy_rule_set = client.policy_rule_set_get(request, cid) rules = client.policyrule_list( request, tenant_id=request.user.tenant_id, policy_rule_set_id=policy_rule_set.id) rules = [ item for item in rules if item.id in policy_rule_set.policy_rules] rules_with_details = [] for rule in rules: r = {} r['name'] = rule.name r['id'] = rule.id action_list = [] for aid in rule.policy_actions: action = client.policyaction_get(request, aid) a = {'id': action.id} if action.action_value: if action.action_type == 'redirect': scspec = client.get_servicechain_spec(request, action.action_value) a['name'] = "Redirect:%s" % scspec.name else: values = (str(action.action_type), str(action.action_value)) name = "%s:%s" % values a['name'] = name else: a['name'] = str(action.action_type) action_list.append(a) r['actions'] = action_list r['classifier'] = client.policyclassifier_get( request, rule.policy_classifier_id) rules_with_details.append(r) except Exception as e: msg = _('Unable to retrieve policy_rule_set details.') % (str(e)) exceptions.handle(request, msg, redirect=self.failure_url) return {'policy_rule_set': policy_rule_set, 'rules_with_details': rules_with_details}
def update_policyrule_attributes(request, prule): url = "horizon:project:application_policy:policyclassifierdetails" classifier_id = prule.policy_classifier_id classifier = client.policyclassifier_get(request, classifier_id) u = reverse(url, kwargs={'policyclassifier_id': classifier.id}) tag = mark_safe("<a href='" + u + "'>" + classifier.name + "</a>") setattr(prule, 'policy_classifier_id', tag) actions = prule.policy_actions action_url = "horizon:project:application_policy:policyactiondetails" ul = ["<ul>"] for a in actions: action = client.policyaction_get(request, a) u = reverse(action_url, kwargs={'policyaction_id': a}) if action.action_type == 'redirect': spec = client.get_servicechain_spec(request, action.action_value) spec_details = "%s:%s" % (spec.name, str(spec.id)) li = "<li><a href='%s'>%s</a></li>" % (u, spec_details) else: li = "<li><a href='%s'>%s</a></li>" % (u, action.name) ul.append(li) ul.append("</ul>") ultag = "".join(ul) setattr(prule, 'policy_actions', mark_safe(ultag)) return prule