예제 #1
0
파일: vxlan.py 프로젝트: rombie/contrail-f5
 def delete_all_fdb_entries(self, tunnel_name=None, folder='Common'):
     folder = str(folder).replace('/', '')
     request_url = self.bigip.icr_url + '/net/fdb/tunnel/'
     request_url += '~' + folder + '~' + tunnel_name
     response = self.bigip.icr_session.put(request_url,
                                           data=json.dumps(
                                               {'records': None}),
                                           timeout=const.CONNECTION_TIMEOUT)
     if response.status_code < 400:
         return True
     else:
         Log.error('VXLAN', response.text)
         raise exceptions.VXLANUpdateException(response.text)
     return False
예제 #2
0
파일: vxlan.py 프로젝트: rombie/contrail-f5
    def add_fdb_entries(self, tunnel_name=None, fdb_entries=None):
        for tunnel_name in fdb_entries:
            folder = fdb_entries[tunnel_name]['folder']
            request_url = self.bigip.icr_url + '/net/fdb/tunnel/'
            request_url += '~' + folder + '~' + tunnel_name
            existing_records = self.get_fdb_entry(tunnel_name=tunnel_name,
                                                  mac=None,
                                                  folder=folder)
            new_records = []
            new_mac_addresses = []
            new_arp_addresses = {}

            for mac in fdb_entries[tunnel_name]['records']:
                fdb_entry = dict()
                fdb_entry['name'] = mac
                fdb_entry['endpoint'] = mac['endpoint']
                new_records.append(fdb_entry)
                new_mac_addresses.append(mac)
                new_arp_addresses[mac] = mac['ip_address']

            for record in existing_records:
                if not record['name'] in new_mac_addresses:
                    new_records.append(record)
                else:
                    if record['name'] in new_arp_addresses:
                        del (new_arp_addresses[record['name']])

            payload = dict()
            payload['records'] = new_records
            response = self.bigip.icr_session.put(
                request_url,
                data=json.dumps(payload),
                timeout=const.CONNECTION_TIMEOUT)
            if response.status_code < 400:
                if const.FDB_POPULATE_STATIC_ARP:
                    for mac in new_arp_addresses:
                        try:
                            self.bigip.arp.create(
                                ip_address=new_arp_addresses[mac],
                                mac_address=mac,
                                folder=folder)
                        except Exception as e:
                            Log.error(
                                'VXLAN',
                                'could not create static arp: %s' % e.message)
            return True
        else:
            Log.error('VXLAN', response.text)
            raise exceptions.VXLANUpdateException(response.text)
        return False
예제 #3
0
    def add_fdb_entry(self,
                      tunnel_name=None,
                      mac_address=None,
                      vtep_ip_address=None,
                      arp_ip_address=None,
                      folder=None):
        """ Add vxlan fdb entry """
        folder = str(folder).replace('/', '')
        request_url = self.bigip.icr_url + '/net/fdb/tunnel/'
        request_url += '~' + folder + '~' + tunnel_name + '?ver=11.5.0'
        records = self.get_fdb_entry(tunnel_name=tunnel_name,
                                     mac=None,
                                     folder=folder)
        fdb_entry = dict()
        fdb_entry['name'] = mac_address
        fdb_entry['endpoint'] = vtep_ip_address

        for i in range(len(records)):
            if records[i]['name'] == mac_address:
                records[i] = fdb_entry
                break
        else:
            records.append(fdb_entry)

        payload = dict()
        payload['records'] = records
        response = self.bigip.icr_session.patch(
            request_url,
            data=json.dumps(payload),
            timeout=const.CONNECTION_TIMEOUT)
        if response.status_code < 400:
            if const.FDB_POPULATE_STATIC_ARP:
                if arp_ip_address:
                    try:
                        if self.bigip.arp.create(ip_address=arp_ip_address,
                                                 mac_address=mac_address,
                                                 folder=folder):
                            return True
                        else:
                            return False
                    except Exception as exc:
                        Log.error(
                            'VXLAN', 'could not create static arp: %s on %s' %
                            (exc.message, self.bigip.device_name))
                        return False
            return True
        else:
            Log.error('VXLAN', response.text)
            raise exceptions.VXLANUpdateException(response.text)
        return False
예제 #4
0
 def delete_fdb_entry(self,
                      tunnel_name=None,
                      mac_address=None,
                      arp_ip_address=None,
                      folder='Common'):
     """ Delete vxlan fdb entry """
     folder = str(folder).replace('/', '')
     if const.FDB_POPULATE_STATIC_ARP:
         if arp_ip_address:
             self.bigip.arp.delete(ip_address=arp_ip_address, folder=folder)
     request_url = self.bigip.icr_url + '/net/fdb/tunnel/'
     request_url += '~' + folder + '~' + tunnel_name + '?ver=11.5.0'
     records = self.get_fdb_entry(tunnel_name=tunnel_name,
                                  mac=None,
                                  folder=folder)
     if not records:
         return False
     original_len = len(records)
     records = [
         record for record in records if record.get('name') != mac_address
     ]
     if original_len != len(records):
         if len(records) == 0:
             records = None
         payload = dict()
         payload['records'] = records
         response = self.bigip.icr_session.patch(
             request_url,
             data=json.dumps(payload),
             timeout=const.CONNECTION_TIMEOUT)
         if response.status_code < 400:
             return True
         elif response.status_code == 404:
             return True
         else:
             Log.error('VXLAN', response.text)
             raise exceptions.VXLANUpdateException(response.text)
         return False
     return False
예제 #5
0
파일: vxlan.py 프로젝트: rombie/contrail-f5
    def delete_fdb_entries(self, tunnel_name=None, fdb_entries=None):
        for tunnel_name in fdb_entries:
            folder = fdb_entries[tunnel_name]['folder']
            request_url = self.bigip.icr_url + '/net/fdb/tunnel/'
            request_url += '~' + folder + '~' + tunnel_name
            existing_records = self.get_fdb_entry(tunnel_name=tunnel_name,
                                                  mac=None,
                                                  folder=folder)
            arps_to_delete = {}
            new_records = []

            for record in existing_records:
                for mac in fdb_entries[tunnel_name]['records']:
                    if record['name'] == mac:
                        arps_to_delete[mac] = mac['ip_address']
                        break
                else:
                    new_records.append(record)

            if len(new_records) == 0:
                new_records = None
            payload = dict()
            payload['records'] = new_records
            response = self.bigip.icr_session.put(
                request_url,
                data=json.dumps(payload),
                timeout=const.CONNECTION_TIMEOUT)
            if response.status_code < 400:
                if const.FDB_POPULATE_STATIC_ARP:
                    for mac in arps_to_delete:
                        self.bigip.arp.delete(ip_address=arps_to_delete[mac],
                                              folder='Common')
            return True
        else:
            Log.error('VXLAN', response.text)
            raise exceptions.VXLANUpdateException(response.text)
        return False