Beispiel #1
0
 def get_context_data(self, request):
     scspec_id = self.tab_group.kwargs['scspec_id']
     try:
         scspec = client.get_servicechain_spec(request, scspec_id)
         nodes = []
         gn = lambda x, y: client.get_servicechain_node(x, y)
         for node in scspec.nodes:
             n = gn(self.request, node)
             config = n.config
             config = config.strip()
             if config.startswith('{'):
                 config = yaml.load(config)
                 if 'heat_template_version' in config:
                     config = yaml.dump(
                         config, default_flow_style=False, indent=4)
                 else:
                     config = json.dumps(config, sort_keys=False, indent=4)
             else:
                 config = yaml.load(config)
                 config = yaml.dump(
                     config, default_flow_style=False, indent=4)
             setattr(n, 'config', config)
             nodes.append(n)
         setattr(scspec, 'nodes', nodes)
     except Exception:
         exceptions.handle(request, _(
             'Unable to retrieve service chain spec details.'),
             redirect=self.failure_url)
     return {'scspec': scspec}
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
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_policyaction_attributes(request, paction):
    if paction.action_type == 'redirect':
        spec = client.get_servicechain_spec(request, paction.action_value)
        url = "horizon:project:network_services:sc_spec_details"
        url = reverse(url, kwargs={'scspec_id': spec.id})
        tag_content = (url, spec.name + ":" + spec.id)
        tag = "<a href='%s'>%s</a>" % tag_content
        setattr(paction, 'action_value', mark_safe(tag))
    return paction
def update_policyaction_attributes(request, paction):
    if paction.action_type == 'redirect':
        spec = client.get_servicechain_spec(request,
                paction.action_value)
        url = "horizon:project:network_services:sc_spec_details"
        url = reverse(url, kwargs={'scspec_id': spec.id})
        tag_content = (url, spec.name + ":" + spec.id)
        tag = "<a href='%s'>%s</a>" % tag_content
        setattr(paction, 'action_value', mark_safe(tag))
    return paction
Beispiel #6
0
 def __init__(self, request, *args, **kwargs):
     super(UpdateServiceChainSpecForm, self).__init__(
         request, *args, **kwargs)
     try:
         scspec_id = self.initial['scspec_id']
         scspec = client.get_servicechain_spec(request, scspec_id)
         for attr in ['name', 'description', 'nodes']:
             self.fields[attr].initial = getattr(scspec, attr)
     except Exception:
         pass
Beispiel #7
0
 def get_context_data(self, request):
     scspec_id = self.tab_group.kwargs['scspec_id']
     try:
         scspec = client.get_servicechain_spec(request, scspec_id)
         nodes = []
         gn = lambda x, y: client.get_servicechain_node(x, y)
         for node in scspec.nodes:
             n = gn(self.request, node)
             setattr(n, 'config', json.loads(n.config))
             nodes.append(n)
         setattr(scspec, 'nodes', nodes)
     except Exception:
         exceptions.handle(request, _(
             'Unable to retrieve service chain spec details.'),
             redirect=self.failure_url)
     return {'scspec': scspec}
Beispiel #8
0
 def get_context_data(self, request):
     scspec_id = self.tab_group.kwargs['scspec_id']
     try:
         scspec = client.get_servicechain_spec(request, scspec_id)
         nodes = []
         gn = lambda x, y: client.get_servicechain_node(x, y)
         for node in scspec.nodes:
             n = gn(self.request, node)
             setattr(n, 'config', json.loads(n.config))
             nodes.append(n)
         setattr(scspec, 'nodes', nodes)
     except Exception:
         exceptions.handle(
             request,
             _('Unable to retrieve service chain spec details.'),
             redirect=self.failure_url)
     return {'scspec': scspec}
Beispiel #9
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
     }
Beispiel #10
0
 def __init__(self, request, *args, **kwargs):
     super(UpdateServiceChainSpecForm, self).__init__(
         request, *args, **kwargs)
     try:
         scspec_id = self.initial['scspec_id']
         scspec = client.get_servicechain_spec(request, scspec_id)
         for attr in ['name', 'description', 'nodes', 'shared']:
             self.fields[attr].initial = getattr(scspec, attr)
         nodes_available = dict(self.fields['nodes'].choices)
         nodes_selected = [
             (x, nodes_available[x]) for x in self.fields['nodes'].initial]
         nodes_unselected = set(self.fields['nodes'].choices) - set(
             nodes_selected)
         self.fields['nodes'].choices = nodes_selected + list(
             nodes_unselected)
     except Exception:
         msg = _("Failed to retrieve service chain spec")
         LOG.error(msg)
Beispiel #11
0
 def __init__(self, request, *args, **kwargs):
     super(UpdateServiceChainSpecForm,
           self).__init__(request, *args, **kwargs)
     try:
         scspec_id = self.initial['scspec_id']
         scspec = client.get_servicechain_spec(request, scspec_id)
         for attr in ['name', 'description', 'nodes', 'shared']:
             self.fields[attr].initial = getattr(scspec, attr)
         nodes_available = dict(self.fields['nodes'].choices)
         nodes_selected = [(x, nodes_available[x])
                           for x in self.fields['nodes'].initial]
         nodes_unselected = set(
             self.fields['nodes'].choices) - set(nodes_selected)
         self.fields['nodes'].choices = nodes_selected + list(
             nodes_unselected)
     except Exception:
         msg = _("Failed to retrieve service chain spec")
         LOG.error(msg)
Beispiel #12
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}
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