Exemple #1
0
    def delete_fdb_entries(self, tunnel_name=None, fdb_entries=None):
        """ Delete vxlan fdb entries """
        for tunnel_name in fdb_entries:
            folder = prefixed(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
        return False
Exemple #2
0
    def delete_fdb_entries(self, tunnel_name=None, fdb_entries=None):
        """ Delete fdb entries for a tunnel """
        for tunnel_name in fdb_entries:
            folder = prefixed(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
        return False
Exemple #3
0
    def add_fdb_entries(self, fdb_entries=None):
        """ Add fdb entries for a tunnel """
        for tunnel_name in fdb_entries:
            folder = fdb_entries[tunnel_name]['folder']
            if folder != 'Common':
                folder = prefixed(folder)
            request_url = self.bigip.icr_url + '/net/fdb/tunnel/'
            request_url += '~' + folder + '~' + self.OBJ_PREFIX + \
                tunnel_name + '?ver=11.5.0'
            existing_records = self.get_fdb_entry(tunnel_name=tunnel_name,
                                                  mac=None,
                                                  folder=folder)
            new_records = []
            new_mac_addresses = []
            new_arp_addresses = {}

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

            for record in existing_records:
                if not record['name'] in new_mac_addresses:
                    new_records.append(record)
                else:
                    # This fdb entry exists and is not being updated.
                    # So, do not update the ARP record either.
                    if record['name'] in new_arp_addresses:
                        del new_arp_addresses[record['name']]

            payload = dict()
            payload['records'] = new_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:
                    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 exc:
                            Log.error(
                                'L2GRE', 'could not create static arp: %s' %
                                exc.message)
            return True
        return False
    def add_fdb_entries(self, fdb_entries=None):
        """ Add vxlan fdb entries """
        for tunnel_name in fdb_entries:
            folder = fdb_entries[tunnel_name]['folder']
            if folder != 'Common':
                folder = prefixed(folder)
            request_url = self.bigip.icr_url + '/net/fdb/tunnel/'
            request_url += '~' + folder + '~' + self.OBJ_PREFIX + \
                tunnel_name + '?ver=11.5.0'
            existing_records = self.get_fdb_entry(tunnel_name=tunnel_name,
                                                  mac=None,
                                                  folder=folder)
            new_records = []
            new_mac_addresses = []
            new_arp_addresses = {}

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

            for record in existing_records:
                if not record['name'] in new_mac_addresses:
                    new_records.append(record)
                else:
                    # This fdb entry exists and is not being updated.
                    # So, do not update the ARP record either.
                    if record['name'] in new_arp_addresses:
                        del new_arp_addresses[record['name']]

            payload = dict()
            payload['records'] = new_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:
                    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 exc:
                            Log.error('VXLAN',
                                      'could not create static arp: %s'
                                      % exc.message)
            return True
        return False
Exemple #5
0
    def _delete_vcmp_device_network(self, bigip, vlan_name):
        """For vCMP Guests, disassociate VLAN from vCMP Guest and
           delete VLAN from vCMP Host."""
        vcmp_host = self.vcmp_manager.get_vcmp_host(bigip)
        if not vcmp_host:
            return

        # Remove VLAN association from the vCMP Guest
        vcmp_guest = self.vcmp_manager.get_vcmp_guest(vcmp_host, bigip)
        try:
            vlan_seq = vcmp_host['bigip'].system.sys_vcmp.typefactory.\
                create('Common.StringSequence')
            vlan_seq.values = prefixed(vlan_name)
            vlan_seq_seq = vcmp_host['bigip'].system.sys_vcmp.typefactory.\
                create('Common.StringSequenceSequence')
            vlan_seq_seq.values = [vlan_seq]
            vcmp_host['bigip'].system.sys_vcmp.remove_vlan(
                [vcmp_guest['name']], vlan_seq_seq)
            LOG.debug(('Removed VLAN %s association from vCMP Guest %s' %
                      (vlan_name, vcmp_guest['mgmt_addr'])))
        except WebFault as webfault:
            LOG.error(('Exception removing VLAN %s association from vCMP '
                       'Guest %s:%s' %
                       (vlan_name, vcmp_guest['mgmt_addr'], webfault)))
        except Exception as exc:
            LOG.error(('Exception removing VLAN %s association from vCMP '
                       'Guest %s:%s' %
                       (vlan_name, vcmp_guest['mgmt_addr'], exc)))

        # Only delete VLAN if it is not in use by other vCMP Guests
        if self.vcmp_manager.get_vlan_use_count(vcmp_host, vlan_name):
            LOG.debug(('VLAN %s in use by other vCMP Guests on vCMP Host %s' %
                      (vlan_name, vcmp_host['bigip'].icontrol.hostname)))
            return

        # Delete VLAN from vCMP Host.  This will fail if any other vCMP Guest
        # is using this VLAN
        try:
            vcmp_host['bigip'].vlan.delete(name=vlan_name,
                                           folder='/Common')
            LOG.debug(('Deleted VLAN %s from vCMP Host %s' %
                      (vlan_name, vcmp_host['bigip'].icontrol.hostname)))
        except WebFault as webfault:
            LOG.error(('Exception deleting VLAN %s from vCMP Host %s:%s' %
                      (vlan_name, vcmp_host['bigip'].icontrol.hostname,
                       webfault)))
        except Exception as exc:
            LOG.error(('Exception deleting VLAN %s from vCMP Host %s:%s' %
                      (vlan_name, vcmp_host['bigip'].icontrol.hostname, exc)))
Exemple #6
0
 def get_vlan_use_count(self, vcmp_host, vlan_name):
     """Determine the number of vCMP guests with access to vCMP host VLAN"""
     use_count = 0
     for vcmp_guest in vcmp_host['guests']:
         vlan_list = vcmp_host['bigip'].system.sys_vcmp.get_vlan(
             [vcmp_guest['name']])
         full_path_vlan_name = '/Common/' + prefixed(vlan_name)
         if full_path_vlan_name in vlan_list[0]:
             LOG.debug(('VLAN %s associated with guest %s' %
                        (full_path_vlan_name, vcmp_guest['mgmt_addr'])))
             use_count += 1
         else:
             LOG.debug(('VLAN %s is not associated with guest %s' %
                        (full_path_vlan_name, vcmp_guest['mgmt_addr'])))
     return use_count
 def get_vlan_use_count(self, vcmp_host, vlan_name):
     """Determine the number of vCMP guests with access to vCMP host VLAN"""
     use_count = 0
     for vcmp_guest in vcmp_host['guests']:
         vlan_list = vcmp_host['bigip'].system.sys_vcmp.get_vlan(
             [vcmp_guest['name']])
         full_path_vlan_name = '/Common/' + prefixed(vlan_name)
         if full_path_vlan_name in vlan_list[0]:
             LOG.debug(('VLAN %s associated with guest %s' %
                       (full_path_vlan_name, vcmp_guest['mgmt_addr'])))
             use_count += 1
         else:
             LOG.debug(('VLAN %s is not associated with guest %s' %
                       (full_path_vlan_name, vcmp_guest['mgmt_addr'])))
     return use_count
Exemple #8
0
 def _is_vlan_assoc_with_vcmp_guest(self, bigip, vlan):
     """Is a vlan associated with a vcmp_guest?"""
     try:
         vcmp_host = self.vcmp_manager.get_vcmp_host(bigip)
         vcmp_guest = self.vcmp_manager.get_vcmp_guest(vcmp_host, bigip)
         vlan_list = vcmp_host['bigip'].system.sys_vcmp.get_vlan(
             [vcmp_guest['name']])
         full_path_vlan_name = '/Common/' + prefixed(vlan['name'])
         if full_path_vlan_name in vlan_list[0]:
             LOG.debug(('VLAN %s is associated with guest %s' %
                        (full_path_vlan_name, vcmp_guest['mgmt_addr'])))
             return True
     except WebFault as exc:
         LOG.error(('Exception checking association of VLAN %s '
                    'to vCMP Guest %s: %s ' %
                    (vlan['name'], vcmp_guest['mgmt_addr'], exc)))
         return False
     LOG.debug(('VLAN %s is not associated with guest %s' %
               (full_path_vlan_name, vcmp_guest['mgmt_addr'])))
     return False
Exemple #9
0
 def decorate_folder(self, folder='Common'):
     folder = str(folder).replace('/', '')
     return bigip_interfaces.prefixed(folder)
Exemple #10
0
    def _assure_vcmp_device_network(self, bigip, vlan):
        """For vCMP Guests, add VLAN to vCMP Host, associate VLAN with
           vCMP Guest, and remove VLAN from /Common on vCMP Guest."""
        vcmp_host = self.vcmp_manager.get_vcmp_host(bigip)
        if not vcmp_host:
            return

        # Create the VLAN on the vCMP Host
        try:
            vcmp_host['bigip'].vlan.create(
                name=vlan['name'], vlanid=vlan['id'],
                interface=vlan['interface'], folder='/Common',
                description=vlan['network']['id'],
                route_domain_id=vlan['network']['route_domain_id'])
            LOG.debug(('Created VLAN %s on vCMP Host %s' %
                      (vlan['name'], vcmp_host['bigip'].icontrol.hostname)))
        except VLANCreationException as exc:
            LOG.error(
                ('Exception creating VLAN %s on vCMP Host %s:%s' %
                 (vlan['name'], vcmp_host['bigip'].icontrol.hostname, exc)))

        # Determine if the VLAN is already associated with the vCMP Guest
        if self._is_vlan_assoc_with_vcmp_guest(bigip, vlan):
            return

        # Associate the VLAN with the vCMP Guest
        vcmp_guest = self.vcmp_manager.get_vcmp_guest(vcmp_host, bigip)
        try:
            vlan_seq = vcmp_host['bigip'].system.sys_vcmp.typefactory.\
                create('Common.StringSequence')
            vlan_seq.values = prefixed(vlan['name'])
            vlan_seq_seq = vcmp_host['bigip'].system.sys_vcmp.typefactory.\
                create('Common.StringSequenceSequence')
            vlan_seq_seq.values = [vlan_seq]
            vcmp_host['bigip'].system.sys_vcmp.add_vlan([vcmp_guest['name']],
                                                        vlan_seq_seq)
            LOG.debug(('Associated VLAN %s with vCMP Guest %s' %
                       (vlan['name'], vcmp_guest['mgmt_addr'])))
        except WebFault as exc:
            LOG.error(('Exception associating VLAN %s to vCMP Guest %s: %s '
                      % (vlan['name'], vcmp_guest['mgmt_addr'], exc)))

        # Wait for the VLAN to propagate to /Common on vCMP Guest
        full_path_vlan_name = '/Common/' + prefixed(vlan['name'])
        try:
            vlan_created = False
            for _ in range(0, 30):
                if bigip.vlan.exists(name=vlan['name'], folder='/Common'):
                    vlan_created = True
                    break
                LOG.debug(('Wait for VLAN %s to be created on vCMP Guest %s.'
                          % (full_path_vlan_name, vcmp_guest['mgmt_addr'])))
                sleep(1)

            if vlan_created:
                LOG.debug(('VLAN %s exists on vCMP Guest %s.' %
                          (full_path_vlan_name, vcmp_guest['mgmt_addr'])))
            else:
                LOG.error(('VLAN %s does not exist on vCMP Guest %s.' %
                          (full_path_vlan_name, vcmp_guest['mgmt_addr'])))
        except WebFault as exc:
            LOG.error(('Exception waiting for vCMP Host VLAN %s to '
                       'be created on vCMP Guest %s: %s' %
                      (vlan['name'], vcmp_guest['mgmt_addr'], exc)))
        except Exception as exc:
            LOG.error(('Exception waiting for vCMP Host VLAN %s to '
                       'be created on vCMP Guest %s: %s' %
                      (vlan['name'], vcmp_guest['mgmt_addr'], exc)))

        # Delete the VLAN from the /Common folder on the vCMP Guest
        try:
            bigip.vlan.delete(name=vlan['name'],
                              folder='/Common')
            LOG.debug(('Deleted VLAN %s from vCMP Guest %s' %
                      (full_path_vlan_name, vcmp_guest['mgmt_addr'])))
        except VLANDeleteException as exc:
            LOG.error(('Exception deleting VLAN %s from vCMP Guest %s: %s' %
                      (full_path_vlan_name, vcmp_guest['mgmt_addr'], exc)))
        except Exception as exc:
            LOG.error(('Exception deleting VLAN %s from vCMP Guest %s: %s' %
                      (full_path_vlan_name, vcmp_guest['mgmt_addr'], exc)))
Exemple #11
0
 def get_bigip_service_name(pool_id):
     """ Generate service name """
     return prefixed(pool_id)