예제 #1
0
 def get_context_data(self, request):
     ruleid = self.tab_group.kwargs['policyrule_id']
     actions = []
     classifiers = []
     try:
         policyrule = client.policyrule_get(request, ruleid)
         actions = client.policyaction_list(
             request,
             tenant_id=request.user.tenant_id,
             policyrule_id=ruleid)
         actions = [
             item for item in actions
             if item.id in policyrule.policy_actions
         ]
         classifiers = client.policyclassifier_list(
             request,
             tenant_id=request.user.tenant_id,
             policyrule_id=ruleid)
         classifiers = [
             item for item in classifiers
             if item.id == policyrule.policy_classifier_id
         ]
     except Exception:
         exceptions.handle(request,
                           _('Unable to retrieve policyrule details.'),
                           redirect=self.failure_url)
     return {
         'policyrule': policyrule,
         'classifiers': classifiers,
         'actions': actions
     }
예제 #2
0
    def __init__(self, request, *args, **kwargs):
        super(UpdatePolicyRuleForm, self).__init__(request, *args, **kwargs)
        try:
            policyrule_id = self.initial['policyrule_id']
            rule = client.policyrule_get(request, policyrule_id)

            for item in ['name', 'description',
                         'policy_classifier_id', 'policy_actions', 'shared']:
                self.fields[item].initial = getattr(rule, item)

            actions = client.policyaction_list(request,
                tenant_id=request.user.tenant_id)
            for action in actions:
                action.set_id_as_name_if_empty()
            actions = sorted(actions, key=lambda action: action.name)
            action_list = [(a.id, a.name) for a in actions]
            self.fields['policy_actions'].choices = action_list

            classifiers = client.policyclassifier_list(request,
                tenant_id=request.user.tenant_id)
            classifier_list = [(c.id, c.name) for c in classifiers]
            self.fields['policy_classifier_id'].choices = classifier_list
        except Exception:
            exceptions.handle(
                request, _("Unable to retrive policy rule details."))
예제 #3
0
 def get_policyactionstable_data(self):
     actions = []
     try:
         actions = client.policyaction_list(self.tab_group.request)
         a = lambda x, y: gfilters.update_policyaction_attributes(x, y)
         actions = [a(self.request, item) for item in actions]
     except Exception as e:
         msg = _('Unable to retrieve actions list. %s') % (str(e))
         exceptions.handle(self.tab_group.request, msg)
     return actions
 def populate_actions_choices(self, request, context):
     try:
         actions = client.policyaction_list(request)
         action_list = [a.id for a in actions]
         for action in actions:
             action.set_id_as_name_if_empty()
         actions = sorted(actions,
                          key=lambda action: action.name)
         action_list = [(a.id, a.name) for a in actions]
         if len(action_list) > 0:
             self.fields['actions'].initial = action_list[0]
     except Exception as e:
         action_list = []
         exceptions.handle(request,
                           _('Unable to retrieve actions (%(error)s).')
                           % {'error': str(e)})
     return action_list
예제 #5
0
 def populate_actions_choices(self, request, context):
     try:
         actions = client.policyaction_list(request)
         action_list = [a.id for a in actions]
         for action in actions:
             action.set_id_as_name_if_empty()
         actions = sorted(actions, key=lambda action: action.name)
         action_list = [(a.id, a.name) for a in actions]
         if len(action_list) > 0:
             self.fields['actions'].initial = action_list[0]
     except Exception as e:
         action_list = []
         exceptions.handle(
             request,
             _('Unable to retrieve actions (%(error)s).') %
             {'error': str(e)})
     return action_list
예제 #6
0
 def get_context_data(self, request):
     ruleid = self.tab_group.kwargs['policyrule_id']
     actions = []
     classifiers = []
     try:
         policyrule = client.policyrule_get(request, ruleid)
         actions = client.policyaction_list(request, policyrule_id=ruleid)
         actions = [
             item for item in actions if item.id in
             policyrule.policy_actions]
         classifiers = client.policyclassifier_list(
             request, policyrule_id=ruleid)
         classifiers = [
             item for item in classifiers if
             item.id == policyrule.policy_classifier_id]
     except Exception:
         exceptions.handle(request,
                           _('Unable to retrieve policyrule details.'),
                           redirect=self.failure_url)
     return {'policyrule': policyrule,
             'classifiers': classifiers,
             'actions': actions}