Example #1
0
 def handle(self, request, context):
     ext_policy_target_id = self.initial['ext_policy_target_id']
     url = reverse("horizon:project:policytargets:ext_policy_targetdetails",
                   kwargs={'ext_policy_target_id': ext_policy_target_id})
     try:
         ext_policy_target = client.ext_policy_target_get(
             request, ext_policy_target_id)
         old_policy_rule_sets = ext_policy_target.get(
             "consumed_policy_rule_sets")
         for policy_rule_set in context['policy_rule_set']:
             old_policy_rule_sets.remove(policy_rule_set)
         consumed = dict([(item, 'string')
                          for item in old_policy_rule_sets])
         client.ext_policy_target_update(request,
                                         ext_policy_target_id,
                                         consumed_policy_rule_sets=consumed)
         msg = _('Policy Rule Set removed successfully!')
         messages.success(request, msg)
         LOG.debug(msg)
         return http.HttpResponseRedirect(url)
     except Exception:
         msg = _('Failed to remove policy_rule_set!')
         redirect = url
         LOG.error(msg)
         exceptions.handle(request, msg, redirect=redirect)
Example #2
0
 def handle(self, request, context):
     ext_policy_target_id = self.initial['ext_policy_target_id']
     ext_policy_target = client.ext_policy_target_get(
         request, ext_policy_target_id)
     url = reverse("horizon:project:policytargets:ext_policy_targetdetails",
                   kwargs={'ext_policy_target_id': ext_policy_target_id})
     try:
         for policy_rule_set in ext_policy_target.get(
                 "provided_policy_rule_sets"):
             context['policy_rule_set'].append(policy_rule_set)
         policy_rule_sets = dict([(item, 'string')
                                  for item in context['policy_rule_set']])
         client.ext_policy_target_update(
             request,
             ext_policy_target_id,
             provided_policy_rule_sets=policy_rule_sets)
         msg = _('Policy Rule Set added successfully!')
         messages.success(request, msg)
         LOG.debug(msg)
         return http.HttpResponseRedirect(url)
     except Exception:
         u = "horizon:project:policytargets:ext_policy_targetdetails"
         msg = _('Failed to add policy_rule_set!')
         redirect = reverse(
             u, kwargs={'ext_policy_target_id': ext_policy_target_id})
         LOG.error(msg)
         exceptions.handle(request, msg, redirect=redirect)
Example #3
0
 def handle(self, request, context):
     ext_policy_target_id = self.initial['ext_policy_target_id']
     url = reverse("horizon:project:policytargets:ext_policy_targetdetails",
                   kwargs={'ext_policy_target_id': ext_policy_target_id})
     try:
         ext_policy_target = client.ext_policy_target_get(request,
             ext_policy_target_id)
         old_policy_rule_sets = ext_policy_target.get(
             "consumed_policy_rule_sets")
         for policy_rule_set in context['policy_rule_set']:
             old_policy_rule_sets.remove(policy_rule_set)
         consumed = dict([(item, 'string')
                          for item in old_policy_rule_sets])
         client.ext_policy_target_update(
             request, ext_policy_target_id,
             consumed_policy_rule_sets=consumed)
         msg = _('Policy Rule Set removed successfully!')
         messages.success(request, msg)
         LOG.debug(msg)
         return http.HttpResponseRedirect(url)
     except Exception:
         msg = _('Failed to remove policy_rule_set!')
         redirect = url
         LOG.error(msg)
         exceptions.handle(request, msg, redirect=redirect)
Example #4
0
 def handle(self, request, context):
     ext_policy_target_id = self.initial['ext_policy_target_id']
     ext_policy_target = client.ext_policy_target_get(request,
         ext_policy_target_id)
     url = reverse("horizon:project:policytargets:ext_policy_targetdetails",
                   kwargs={'ext_policy_target_id': ext_policy_target_id})
     try:
         for policy_rule_set in ext_policy_target.get(
                 "provided_policy_rule_sets"):
             context['policy_rule_set'].append(policy_rule_set)
         policy_rule_sets = dict([(item, 'string')
                                  for item in context['policy_rule_set']])
         client.ext_policy_target_update(
             request, ext_policy_target_id,
             provided_policy_rule_sets=policy_rule_sets)
         msg = _('Policy Rule Set added successfully!')
         messages.success(request, msg)
         LOG.debug(msg)
         return http.HttpResponseRedirect(url)
     except Exception:
         u = "horizon:project:policytargets:ext_policy_targetdetails"
         msg = _('Failed to add policy_rule_set!')
         redirect = reverse(u, kwargs={'ext_policy_target_id':
                                       ext_policy_target_id})
         LOG.error(msg)
         exceptions.handle(request, msg, redirect=redirect)
Example #5
0
 def get_context_data(self, **kwargs):
     context = super(ExternalPTGDetailsView, self).get_context_data(
         **kwargs)
     try:
         ext_policy_target = client.ext_policy_target_get(
             self.request, context['ext_policy_target_id'])
         context['policy_target'] = ext_policy_target
     except Exception:
         pass
     return context
Example #6
0
 def get_context_data(self, **kwargs):
     context = super(ExternalPTGDetailsView, self).get_context_data(
         **kwargs)
     try:
         ext_policy_target = client.ext_policy_target_get(
             self.request, context['ext_policy_target_id'])
         context['policy_target'] = ext_policy_target
     except Exception:
         pass
     return context
Example #7
0
 def _get_object(self, *args, **kwargs):
     ext_policy_target_id = self.kwargs['ext_policy_target_id']
     try:
         ext_policy_target = client.ext_policy_target_get(
             self.request, ext_policy_target_id)
         ext_policy_target.set_id_as_name_if_empty()
         return ext_policy_target
     except Exception:
         redirect = self.success_url
         msg = _('Unable to retrieve policy_target details.')
         exceptions.handle(self.request, msg, redirect=redirect)
Example #8
0
 def _get_object(self, *args, **kwargs):
     ext_policy_target_id = self.kwargs['ext_policy_target_id']
     try:
         ext_policy_target = client.ext_policy_target_get(
             self.request, ext_policy_target_id)
         ext_policy_target.set_id_as_name_if_empty()
         return ext_policy_target
     except Exception:
         redirect = self.success_url
         msg = _('Unable to retrieve policy_target details.')
         exceptions.handle(self.request, msg, redirect=redirect)
Example #9
0
 def __init__(self, request, *args, **kwargs):
     super(ExtAddConsumedPRSForm, self).__init__(request, *args, **kwargs)
     policy_rule_sets = []
     try:
         ext_policy_target_id = kwargs['initial']['ext_policy_target_id']
         ext_policy_target = client.ext_policy_target_get(
             request, ext_policy_target_id)
         consumedpolicy_rule_sets = ext_policy_target.get(
             "consumed_policy_rule_sets")
         items = items = client.policy_rule_set_list(
             request, tenant_id=request.user.tenant_id)
         policy_rule_sets = [(p.id, p.name) for p in items
                             if p.id not in consumedpolicy_rule_sets]
     except Exception:
         pass
     self.fields['policy_rule_set'].choices = policy_rule_sets
Example #10
0
 def __init__(self, request, *args, **kwargs):
     super(ExtAddProvidedPRSForm, self).__init__(request, *args, **kwargs)
     policy_rule_sets = []
     try:
         ext_policy_target_id = kwargs['initial']['ext_policy_target_id']
         ext_policy_target = client.ext_policy_target_get(
             request, ext_policy_target_id)
         providedpolicy_rule_sets = ext_policy_target.get(
             "provided_policy_rule_sets")
         items = client.policy_rule_set_list(
             request, tenant_id=request.user.tenant_id)
         policy_rule_sets = [(p.id, p.name) for p in items
                             if p.id not in providedpolicy_rule_sets]
     except Exception as e:
         msg = _('Unable to retrieve policy rule set list.') % (str(e))
         LOG.debug(msg)
     self.fields['policy_rule_set'].choices = policy_rule_sets
Example #11
0
 def __init__(self, request, *args, **kwargs):
     super(ExtAddConsumedPRSForm, self).__init__(request, *args, **kwargs)
     policy_rule_sets = []
     try:
         ext_policy_target_id = kwargs['initial']['ext_policy_target_id']
         ext_policy_target = client.ext_policy_target_get(request,
             ext_policy_target_id)
         consumedpolicy_rule_sets = ext_policy_target.get(
             "consumed_policy_rule_sets")
         items = items = client.policy_rule_set_list(request,
             tenant_id=request.user.tenant_id)
         policy_rule_sets = [
             (p.id, p.name) for p in items
             if p.id not in consumedpolicy_rule_sets]
     except Exception:
         pass
     self.fields['policy_rule_set'].choices = policy_rule_sets
Example #12
0
 def get_consumed_policy_rule_sets_data(self):
     try:
         ext_policy_targetid = self.tab_group.kwargs['ext_policy_target_id']
         ext_policy_target = client.ext_policy_target_get(
             self.request, ext_policy_targetid)
         consumed_policy_rule_set_ids = ext_policy_target.get(
             'consumed_policy_rule_sets')
         consumed_policy_rule_sets = []
         for _id in consumed_policy_rule_set_ids:
             consumed_policy_rule_sets.append(
                 client.policy_rule_set_get(self.request, _id))
         consumed_policy_rule_sets = [gfilters.update_pruleset_attributes(
             self.request, item) for item in consumed_policy_rule_sets]
         return consumed_policy_rule_sets
     except Exception:
         error_message = _('Unable to get consumed rule sets')
         exceptions.handle(self.request, error_message)
         return []
Example #13
0
 def __init__(self, request, *args, **kwargs):
     super(ExtAddProvidedPRSForm, self).__init__(request, *args, **kwargs)
     policy_rule_sets = []
     try:
         ext_policy_target_id = kwargs['initial']['ext_policy_target_id']
         ext_policy_target = client.ext_policy_target_get(request,
             ext_policy_target_id)
         providedpolicy_rule_sets = ext_policy_target.get(
             "provided_policy_rule_sets")
         items = client.policy_rule_set_list(request,
             tenant_id=request.user.tenant_id)
         policy_rule_sets = [
             (p.id, p.name) for p in items
             if p.id not in providedpolicy_rule_sets]
     except Exception as e:
         msg = _('Unable to retrieve policy rule set list.') % (str(e))
         LOG.debug(msg)
     self.fields['policy_rule_set'].choices = policy_rule_sets
Example #14
0
 def get_consumed_policy_rule_sets_data(self):
     try:
         ext_policy_targetid = self.tab_group.kwargs['ext_policy_target_id']
         ext_policy_target = client.ext_policy_target_get(
             self.request, ext_policy_targetid)
         consumed_policy_rule_set_ids = ext_policy_target.get(
             'consumed_policy_rule_sets')
         consumed_policy_rule_sets = []
         for _id in consumed_policy_rule_set_ids:
             consumed_policy_rule_sets.append(
                 client.policy_rule_set_get(self.request, _id))
         consumed_policy_rule_sets = [
             gfilters.update_pruleset_attributes(self.request, item)
             for item in consumed_policy_rule_sets
         ]
         return consumed_policy_rule_sets
     except Exception:
         error_message = _('Unable to get consumed rule sets')
         exceptions.handle(self.request, error_message)
         return []
Example #15
0
 def __init__(self, request, *args, **kwargs):
     super(UpdateExternalPolicyTargetForm, self).__init__(request,
         *args, **kwargs)
     try:
         ext_policy_target_id = self.initial['ext_policy_target_id']
         ext_policy_target = client.ext_policy_target_get(request,
             ext_policy_target_id)
         policy_rule_sets = client.policy_rule_set_list(
             request, tenant_id=request.user.tenant_id)
         external_connectivities = client.externalconnectivity_list(
             request, tenant_id=request.user.tenant_id)
         for c in policy_rule_sets:
             c.set_id_as_name_if_empty()
         ext_conn_list = [(e.id, e.name)for e in external_connectivities]
         policy_rule_sets = sorted(
             policy_rule_sets, key=lambda rule: rule.name)
         policy_rule_set_list = [(c.id, c.name) for c in policy_rule_sets]
         self.fields[
             'provided_policy_rule_sets'].choices = policy_rule_set_list
         self.fields[
             'consumed_policy_rule_sets'].choices = policy_rule_set_list
         self.fields[
             'external_segments'].choices = ext_conn_list
         provided_init = []
         consumed_init = []
         for item in policy_rule_set_list:
             if item[0] in ext_policy_target.provided_policy_rule_sets:
                 provided_init.append(item[0])
             if item[0] in ext_policy_target.consumed_policy_rule_sets:
                 consumed_init.append(item[0])
         self.fields['provided_policy_rule_sets'].initial = provided_init
         self.fields['consumed_policy_rule_sets'].initial = consumed_init
         for attr in ['name', 'description', 'shared']:
             self.fields[attr].initial = getattr(ext_policy_target, attr)
         self.fields['external_segments'].initial = \
             ext_policy_target.external_segments[0]
     except Exception as e:
         msg = _('Unable to retrieve policy_rule_set details. %s') % (
             str(e))
         exceptions.handle(request, msg)
         pass
Example #16
0
 def __init__(self, request, *args, **kwargs):
     super(UpdateExternalPolicyTargetForm,
           self).__init__(request, *args, **kwargs)
     try:
         ext_policy_target_id = self.initial['ext_policy_target_id']
         ext_policy_target = client.ext_policy_target_get(
             request, ext_policy_target_id)
         policy_rule_sets = client.policy_rule_set_list(
             request, tenant_id=request.user.tenant_id)
         external_connectivities = client.externalconnectivity_list(
             request, tenant_id=request.user.tenant_id)
         for c in policy_rule_sets:
             c.set_id_as_name_if_empty()
         ext_conn_list = [(e.id, e.name) for e in external_connectivities]
         policy_rule_sets = sorted(policy_rule_sets,
                                   key=lambda rule: rule.name)
         policy_rule_set_list = [(c.id, c.name) for c in policy_rule_sets]
         self.fields[
             'provided_policy_rule_sets'].choices = policy_rule_set_list
         self.fields[
             'consumed_policy_rule_sets'].choices = policy_rule_set_list
         self.fields['external_segments'].choices = ext_conn_list
         provided_init = []
         consumed_init = []
         for item in policy_rule_set_list:
             if item[0] in ext_policy_target.provided_policy_rule_sets:
                 provided_init.append(item[0])
             if item[0] in ext_policy_target.consumed_policy_rule_sets:
                 consumed_init.append(item[0])
         self.fields['provided_policy_rule_sets'].initial = provided_init
         self.fields['consumed_policy_rule_sets'].initial = consumed_init
         for attr in ['name', 'description', 'shared', 'external_segments']:
             self.fields[attr].initial = getattr(ext_policy_target, attr)
     except Exception as e:
         msg = _('Unable to retrieve policy_rule_set details. %s') % (
             str(e))
         exceptions.handle(request, msg)
         pass