def update_sc_instance_attributes(request, scinstance):
    ptg_url = "horizon:project:policytargets:policy_targetdetails"
    clsurl = "horizon:project:application_policy:policyclassifierdetails"
    scspec_url = "horizon:project:network_services:sc_spec_details"
    consumer_ptg = scinstance.consumer_ptg_id
    provider_ptg = scinstance.provider_ptg_id
    scspec = scinstance.servicechain_specs
    classifier = scinstance.classifier_id
    if consumer_ptg is not None and consumer_ptg != "N/A":
        ptg = client.policy_target_get(request, consumer_ptg)
        u = reverse(ptg_url, kwargs={'policy_target_id': ptg.id})
        atag = "<a href='%s'>%s</a>" % (u, ptg.name)
        setattr(scinstance, 'consumer_ptg', mark_safe(atag))
    if provider_ptg is not None:
        ptg = client.policy_target_get(request, provider_ptg)
        u = reverse(ptg_url, kwargs={'policy_target_id': ptg.id})
        atag = "<a href='%s'>%s</a>" % (u, ptg.name)
        setattr(scinstance, 'provider_ptg', mark_safe(atag))
    if classifier is not None:
        cls = client.policyclassifier_get(request, classifier)
        u = reverse(clsurl, kwargs={'policyclassifier_id': cls.id})
        atag = "<a href='%s'>%s</a>" % (u, cls.name)
        setattr(scinstance, 'classifier', mark_safe(atag))
    if scspec is not None:
        scs = client.get_servicechain_spec(request, scspec[0])
        url = reverse(scspec_url, kwargs={'scspec_id': scs.id})
        atag = "<a href='%s'>%s</a>" % (url, scs.name)
        setattr(scinstance, 'servicechain_spec', mark_safe(atag))
        scni = update_scn_instance_attributes(request, scs)
        setattr(scinstance, 'servicechain', scni.chain)
    return scinstance
def update_sc_instance_attributes(request, scinstance):
    ptg_url = "horizon:project:policytargets:policy_targetdetails"
    clsurl = "horizon:project:application_policy:policyclassifierdetails"
    scspec_url = "horizon:project:network_services:sc_spec_details"
    consumer_ptg = scinstance.consumer_ptg
    provider_ptg = scinstance.provider_ptg
    scspec = scinstance.servicechain_spec
    classifier = scinstance.classifier
    if consumer_ptg is not None:
        ptg = client.policy_target_get(request, consumer_ptg)
        u = reverse(ptg_url, kwargs={'policy_target_id': ptg.id})
        atag = "<a href='%s'>%s</a>" % (u, ptg.name)
        setattr(scinstance, 'consumer_ptg', mark_safe(atag))
    if provider_ptg is not None:
        ptg = client.policy_target_get(request, consumer_ptg)
        u = reverse(ptg_url, kwargs={'policy_target_id': ptg.id})
        atag = "<a href='%s'>%s</a>" % (u, ptg.name)
        setattr(scinstance, 'provider_ptg', mark_safe(atag))
    if classifier is not None:
        cls = client.policyclassifier_get(request, classifier)
        u = reverse(clsurl, kwargs={'policyclassifier_id': cls.id})
        atag = "<a href='%s'>%s</a>" % (u, cls.name)
        setattr(scinstance, 'classifier', mark_safe(atag))
    if scspec is not None:
        sc = client.get_servicechain_spec(request, scspec)
        u = reverse(scspec_url, kwargs={'scspec_id': sc.id})
        atag = "<a href='%s'>%s</a>" % (u, sc.name)
        setattr(scinstance, 'servicechain_spec', mark_safe(atag))
    return scinstance
Exemplo n.º 3
0
 def get_context_data(self, request):
     pcid = self.tab_group.kwargs['policyclassifier_id']
     try:
         policyclassifier = client.policyclassifier_get(request, pcid)
     except Exception:
         exceptions.handle(request,
                           _('Unable to retrieve policy_rule_set details.'),
                           redirect=self.failure_url)
     return {'policyclassifier': policyclassifier}
Exemplo n.º 4
0
 def __init__(self, request, *args, **kwargs):
     super(UpdatePolicyClassifierForm, self).__init__(request, *args, **kwargs)
     try:
         policyclassifier_id = self.initial["policyclassifier_id"]
         classifier = client.policyclassifier_get(request, policyclassifier_id)
         for item in ["name", "description", "protocol", "port_range", "direction", "shared"]:
             self.fields[item].initial = getattr(classifier, item)
     except Exception:
         exceptions.handle(request, _("Unable to retrive policy classifier details."))
Exemplo n.º 5
0
 def __init__(self, request, *args, **kwargs):
     super(UpdatePolicyClassifierForm, self).__init__(
         request, *args, **kwargs)
     try:
         policyclassifier_id = self.initial['policyclassifier_id']
         classifier = client.policyclassifier_get(
             request, policyclassifier_id)
         for item in ['name', 'description',
                      'protocol', 'port_range', 'direction']:
             self.fields[item].initial = getattr(classifier, item)
     except Exception:
         exceptions.handle(
             request, _("Unable to retrive policy classifier details."))
Exemplo n.º 6
0
 def __init__(self, request, *args, **kwargs):
     super(UpdatePolicyClassifierForm, self).__init__(
         request, *args, **kwargs)
     try:
         policyclassifier_id = self.initial['policyclassifier_id']
         classifier = client.policyclassifier_get(
             request, policyclassifier_id)
         classifier = gfilters.update_classifier_attributes(classifier)
         for item in ['name', 'description',
                      'protocol', 'port_range', 'direction', 'shared']:
             self.fields[item].initial = getattr(classifier, item)
     except Exception:
         exceptions.handle(
             request, _("Unable to retrive policy classifier details."))
Exemplo n.º 7
0
 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
     }
Exemplo n.º 8
0
 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}
Exemplo n.º 9
0
 def __init__(self, request, *args, **kwargs):
     super(UpdatePolicyClassifierForm, self).__init__(
         request, *args, **kwargs)
     self.fields['protocol'].widget = fields.DropdownEditWidget(
         data_list=PROTOCOLS, name='list')
     try:
         policyclassifier_id = self.initial['policyclassifier_id']
         classifier = client.policyclassifier_get(
             request, policyclassifier_id)
         classifier = gfilters.update_classifier_attributes(classifier)
         for item in ['name', 'description',
                      'port_range', 'direction', 'shared']:
             self.fields[item].initial = getattr(classifier, item)
         protocol = getattr(classifier, "protocol")
         if protocol is not None:
             self.fields['protocol'].initial = protocol
         else:
             self.fields['protocol'].initial = "any"
     except Exception:
         exceptions.handle(
             request, _("Unable to retrive policy classifier 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
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