Ejemplo n.º 1
0
 def clean(self):
     cleaned_data = super(CommonData, self).clean()
     name = cleaned_data.get('name')
     try:
         if self.request.user.is_superuser:
             for attribute in bgpvpn_common.RT_FORMAT_ATTRIBUTES:
                 if not cleaned_data.get(attribute):
                     del cleaned_data[attribute]
                 else:
                     cleaned_data[attribute] = bgpvpn_common.format_rt(
                         cleaned_data[attribute])
             # if an admin user use the bgpvpn panel project
             # tenant_id field doesn't exist
             if not cleaned_data.get('tenant_id'):
                 tenant_id = self.request.user.tenant_id
             else:
                 tenant_id = cleaned_data.get('tenant_id')
             bgpvpn_api.bgpvpns_list(self.request,
                                     name=name,
                                     tenant_id=tenant_id)
         else:
             bgpvpn_api.bgpvpns_list(self.request, name=name)
     except Exception:
         msg = _('Unable to get BGPVPN with name %s') % name
         exceptions.check_message(["Connection", "refused"], msg)
         raise
     return cleaned_data
Ejemplo n.º 2
0
 def get_data(self):
     bgpvpns_list = bgpvpn_api.bgpvpns_list(self.request)
     for bgpvpn in bgpvpns_list:
         bgpvpn.networks = [api.neutron.network_get(
             self.request, id, expand_subnet=False)
             for id in bgpvpn.networks]
         bgpvpn.routers = [api.neutron.router_get(self.request, id)
                           for id in bgpvpn.routers]
         bgpvpn.tenant_name = self._get_tenant_name(bgpvpn.tenant_id)
     return bgpvpns_list
 def get_data(self):
     tenant_id = self.request.user.tenant_id
     bgpvpns_list = bgpvpn_api.bgpvpns_list(
         self.request, tenant_id=tenant_id)
     for bgpvpn in bgpvpns_list:
         bgpvpn.networks = [api.neutron.network_get(
             self.request, id, expand_subnet=False)
             for id in bgpvpn.networks]
         bgpvpn.routers = [api.neutron.router_get(self.request, id)
                           for id in bgpvpn.routers]
     return bgpvpns_list
Ejemplo n.º 4
0
 def clean(self):
     cleaned_data = super(CommonData, self).clean()
     name = cleaned_data.get('name')
     bgpvpn_id = cleaned_data.get('bgpvpn_id')
     try:
         if self.request.user.is_superuser:
             for attribute in bgpvpn_common.RT_FORMAT_ATTRIBUTES:
                 if not cleaned_data.get(attribute):
                     cleaned_data[attribute] = None
             # if an admin user use the bgpvpn panel project
             # tenant_id field doesn't exist
             if not cleaned_data.get('tenant_id'):
                 tenant_id = self.request.user.tenant_id
             else:
                 tenant_id = cleaned_data.get('tenant_id')
             bgpvpns = bgpvpn_api.bgpvpns_list(self.request,
                                               name=name,
                                               tenant_id=tenant_id)
         else:
             bgpvpns = bgpvpn_api.bgpvpns_list(self.request, name=name)
     except Exception:
         msg = _('Unable to get BGPVPN with name %s') % name
         exceptions.check_message(["Connection", "refused"], msg)
         raise
     if bgpvpns:
         if self.action == 'update':
             for bgpvpn in bgpvpns:
                 if bgpvpn.id != bgpvpn_id:
                     raise forms.ValidationError(
                         _('The name "%s" is already '
                           'used by another BGPVPN.') % name)
         else:
             raise forms.ValidationError(
                 _('The name "%s" is already '
                   'used by another BGPVPN.') % name)
     return cleaned_data
Ejemplo n.º 5
0
 def get_data(self):
     tenant_id = self.request.user.tenant_id
     bgpvpns = bgpvpn_api.bgpvpns_list(self.request, tenant_id=tenant_id)
     networks = api.neutron.network_list_for_tenant(self.request, tenant_id)
     routers = api.neutron.router_list(self.request, tenant_id=tenant_id)
     for bgpvpn in bgpvpns:
         networks_list = [
             network for network in networks
             if network.id in bgpvpn.networks
         ]
         routers_list = [
             router for router in routers if router.id in bgpvpn.routers
         ]
         bgpvpn.networks = networks_list
         bgpvpn.routers = routers_list
     return bgpvpns
Ejemplo n.º 6
0
 def clean(self):
     cleaned_data = super(CreateBgpVpn, self).clean()
     name = cleaned_data.get('name')
     tenant_id = cleaned_data.get('tenant_id')
     try:
         bgpvpns = bgpvpn_api.bgpvpns_list(self.request,
                                           name=name,
                                           tenant_id=tenant_id)
     except Exception:
         msg = _('Unable to get BGPVPN with name %s') % name
         exceptions.check_message(["Connection", "refused"], msg)
         raise
     if bgpvpns:
         raise forms.ValidationError(
             _('The name "%s" is already used by another BGPVPN.') % name)
     return cleaned_data
Ejemplo n.º 7
0
 def get_data(self):
     bgpvpns = bgpvpn_api.bgpvpns_list(self.request)
     networks = api.neutron.network_list(self.request)
     routers = api.neutron.router_list(self.request)
     tenant_dict = self._get_tenant_name()
     for bgpvpn in bgpvpns:
         networks_list = [
             network for network in networks
             if network.id in bgpvpn.networks
         ]
         routers_list = [
             router for router in routers if router.id in bgpvpn.routers
         ]
         bgpvpn.networks = networks_list
         bgpvpn.routers = routers_list
         bgpvpn.tenant_name = tenant_dict.get(bgpvpn.tenant_id, None)
     return bgpvpns