Example #1
0
 def _create_network(self, request, data):
     try:
         params = {'name': data['net_name'],
                   'admin_state_up': (data['admin_state'] == 'True'),
                   'shared': data['shared']}
         if api.neutron.is_port_profiles_supported():
             params['net_profile_id'] = data['net_profile_id']
         network = api.neutron.network_create(request, **params)
         self.context['net_id'] = network.id
         msg = (_('Network "%s" was successfully created.') %
                network.name_or_id)
         LOG.debug(msg)
         return network
     except Exception as e:
         msg = (_('Failed to create network "%(network)s": %(reason)s') %
                {"network": data['net_name'], "reason": e})
         LOG.info(msg)
         # Delete Precreated Network
         try:
             precreate_network = dict(tenant_id=request.user.project_id,
                                      nwk_name=data['net_name'],
                                      subnet=data['cidr'],
                                      cfgp=data['cfg_profile'])
             dfaclient = dfa_client.dfa_client()
             dfaclient.do_delete_precreate_network(precreate_network)
         except Exception as exc:
             LOG.error('Unable to delete precreated Network')
             exceptions.handle(self.request, exc.message)
         redirect = self.get_failure_url()
         exceptions.handle(request, msg, redirect=redirect)
         return False
Example #2
0
 def _get_cfg_profiles(self, request):
     profiles = []
     try:
         cfgplist = dfa_client.dfa_client().get_config_profiles_detail()
         profiles = [profile for cfgp in cfgplist
                     if (cfgp.get('profileSubType') == 'network:universal')
                     for profile in [cfgp.get('profileName')]]
     except Exception as exc:
         exceptions.handle(request, exc.message)
     return profiles
Example #3
0
    def handle(self, request, data):
        precreate_flag = False
        '''Pre-create network in enabler'''
        precreate_network = dict(tenant_id=request.user.project_id,
                                 nwk_name=data['net_name'],
                                 subnet=data['cidr'],
                                 cfgp=data['cfg_profile'])
        if data['cfg_profile']:
            dfaclient = dfa_client.dfa_client()
            try:
                precreate_flag = dfaclient.do_precreate_network(
                    precreate_network)
            except Exception as exc:
                LOG.error('Unable to do precreate Network')
                exceptions.handle(self.request, exc.message)
                return False

        network = self._create_network(request, data)
        if not network:
            if precreate_flag:
                # do precreate delete
                try:
                    dfaclient.do_delete_precreate_network(precreate_network)
                    precreate_flag = False
                except Exception as exc:
                    LOG.error('Unable to delete precreatedd Network')
                    exceptions.handle(self.request, exc.message)
            return False
        # If we do not need to create a subnet, return here.
        if not data['with_subnet']:
            return True
        subnet = self._create_subnet(request, data, network, no_redirect=True)
        if subnet:
            return True
        else:
            self._delete_network(request, network)
            if precreate_flag:
                # do precreate delete
                try:
                    dfaclient.do_delete_precreate_network(precreate_network)
                except Exception as exc:
                    LOG.error('Unable to delete precreated Network')
                    exceptions.handle(self.request, exc.message)
            return False