class SelectPolicyRuleSetAction(workflows.Action): provided_policy_rule_set = fields.DynamicMultiChoiceField( label=_("Provided Policy Rule Set"), help_text=_("Choose a policy rule set for an Group."), add_item_link=POLICY_RULE_SET_URL, required=False) consumed_policy_rule_set = fields.DynamicMultiChoiceField( label=_("Consumed Policy Rule Set"), help_text=_("Select consumed policy rule set for Group."), add_item_link=POLICY_RULE_SET_URL, required=False) class Meta(object): name = _("Application Policy") help_text = _("Select Policy Rule Set for Group.") def _policy_rule_set_list(self, request): policy_rule_sets = client.policy_rule_set_list(request, tenant_id=request.user.tenant_id) for c in policy_rule_sets: c.set_id_as_name_if_empty() policy_rule_sets = sorted(policy_rule_sets, key=lambda rule: rule.name) return [(c.id, c.name) for c in policy_rule_sets] def populate_provided_policy_rule_set_choices(self, request, context): policy_rule_set_list = [] try: rsets = self._policy_rule_set_list(request) if len(rsets) == 0: rsets.extend([('None', 'No Provided Policy Rule Sets')]) policy_rule_set_list = rsets except Exception as e: policy_rule_set_list = [] msg = _('Unable to retrieve policy rule set. %s.') % (str(e)) exceptions.handle(request, msg) return policy_rule_set_list def populate_consumed_policy_rule_set_choices(self, request, context): policy_rule_set_list = [] try: policy_rule_set_list = [('None', 'No Consumed Policy Rule Sets')] policy_rule_set_list =\ self._policy_rule_set_list(request) except Exception as e: msg = _('Unable to retrieve policy rule set. %s.') % (str(e)) exceptions.handle(request, msg) return policy_rule_set_list
class SelectPolicyActionAction(workflows.Action): actions = fields.DynamicMultiChoiceField( label=_("Policy Action"), required=False, help_text=_("Create a policy-rule with selected action."), add_item_link=ADD_POLICY_ACTION_URL) class Meta: name = _("actions") help_text = _("Select actions for your policy-rule.") 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
class SelectPolicyRuleAction(workflows.Action): policy_rules = fields.DynamicMultiChoiceField( label=_("Policy Rules"), required=False, add_item_link=ADD_POLICY_RULE_URL, help_text=_("Create a policy rule set with selected rules.")) class Meta(object): name = _("Rules") help_text = _("Select policy rules for your policy rule set.") def populate_policy_rules_choices(self, request, context): try: rules = client.policyrule_list(request, tenant_id=request.user.tenant_id) for r in rules: r.set_id_as_name_if_empty() rules = sorted(rules, key=lambda rule: rule.name) rule_list = [(rule.id, rule.name) for rule in rules] except Exception as e: rule_list = [] exceptions.handle( request, _('Unable to retrieve rules (%(error)s).') % {'error': str(e)}) return rule_list
class ExternalConnectivityAction(workflows.Action): external_segments = fields.DynamicMultiChoiceField( label=_("External Connectivity"), required=True, add_item_link=ADD_EXTERNAL_CONNECTIVITY, help_text=_("Select external segment(s) for Group.")) class Meta(object): name = _("External Connectivity") help_text = _( "Select External Connectivity for Group.") def populate_external_segments_choices(self, request, context): external_connectivities = [] try: external_connectivities = client.externalconnectivity_list( request, tenant_id=request.user.tenant_id) for p in external_connectivities: p.set_id_as_name_if_empty() ext_conn_list = sorted(external_connectivities, key=lambda segment: segment.name) ext_conn_list = \ [(p.id, p.name + ":" + p.id) for p in ext_conn_list] except Exception as e: exceptions.handle(request, _("Unable to retrieve policies (%(error)s).") % {'error': str(e)}) return ext_conn_list