Exemplo n.º 1
0
 def __init__(self, request, *args, **kwargs):
     super(CreateExternalSegmentParamForm,
           self).__init__(request, *args, **kwargs)
     ec_list = client.externalconnectivity_list(
         request, tenant_id=request.user.tenant_id)
     external_segments_options = [(ec.id, ec.name) for ec in ec_list]
     self.fields['external_segment'].choices = external_segments_options
Exemplo n.º 2
0
 def get_external_connectivity_table_data(self):
     external_segment_list = []
     try:
         external_segment_list = \
             client.externalconnectivity_list(self.request,
                 self.request.user.tenant_id)
     except Exception:
         exceptions.handle(self.tab_group.request,
                 _('Unable to retrieve network service policy list.'))
     return external_segment_list
Exemplo n.º 3
0
 def get_external_connectivity_table_data(self):
     external_segment_list = []
     try:
         external_segment_list = \
             client.externalconnectivity_list(self.request,
                 self.request.user.tenant_id)
     except Exception:
         exceptions.handle(
             self.tab_group.request,
             _('Unable to retrieve network service policy list.'))
     return external_segment_list
Exemplo n.º 4
0
 def __init__(self, request, *args, **kwargs):
     super(UpdateNATPoolForm, self).__init__(request, *args, **kwargs)
     nat_pool_id = self.initial['nat_pool_id']
     ec_list = client.externalconnectivity_list(
         request, tenant_id=request.user.tenant_id)
     external_segments_options = [(ec.id, ec.name) for ec in ec_list]
     self.fields['external_segment_id'].choices = external_segments_options
     nat_pool = client.get_natpool(request, nat_pool_id)
     attributes = [
         'name', 'description', 'ip_version', 'ip_pool',
         'external_segment_id'
     ]
     for attr in attributes:
         self.fields[attr].initial = str(nat_pool[attr])
     self.fields['shared'].initial = nat_pool['shared']
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 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
Exemplo n.º 7
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
Exemplo n.º 8
0
 def __init__(self, request, *args, **kwargs):
     super(UpdateL3PolicyForm, self).__init__(request, *args, **kwargs)
     try:
         ec_list = client.externalconnectivity_list(request, tenant_id=request.user.tenant_id)
         external_segments_options = [(ec.id, ec.name) for ec in ec_list]
         external_segments_options.insert(0, (None, "Select"))
         self.fields["external_segments"].choices = external_segments_options
         l3policy_id = self.initial["l3policy_id"]
         l3 = client.l3policy_get(request, l3policy_id)
         for item in ["name", "description", "ip_version", "ip_pool", "subnet_prefix_length"]:
             self.fields[item].initial = str(l3[item])
         self.fields["shared"].initial = l3["shared"]
         if bool(l3["external_segments"]):
             self.fields["external_segments"].initial = l3["external_segments"].keys()[0]
             self.fields["segment_ip"].initial = l3["external_segments"].values()[0][0]
         else:
             self.fields["external_segments"].initial = None
             self.fields["segment_ip"].initial = ""
     except Exception:
         msg = _("Failed to get L3 policy")
         LOG.error(msg)
         exceptions.handle(request, msg, redirect=shortcuts.redirect)
Exemplo n.º 9
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
Exemplo n.º 10
0
 def __init__(self, request, *args, **kwargs):
     super(AddL3PolicyForm, self).__init__(request, *args, **kwargs)
     ec_list = client.externalconnectivity_list(request, tenant_id=request.user.tenant_id)
     external_segments_options = [(ec.id, ec.name) for ec in ec_list]
     external_segments_options.insert(0, (None, "Select"))
     self.fields["external_segments"].choices = external_segments_options