code: def purge_existing_ovb(nova_api, neutron):
      LOG.info('Cleaning up OVB environment from the tenant.')
      for server in nova_api.servers.list():
          if server.name in ('bmc', 'undercloud'):
              server.delete()
          if server.name.startswith('baremetal_'):
              server.delete()
      for router in neutron.list_routers().get('routers'):
          if router['name'] not in ('router', 'bmc_router'):
              continue
          for subnet in neutron.list_subnets().get('subnets'):
              if not (subnet['name'].startswith('bmc_eth') or subnet['name'] == 'rdo-m-subnet'):
                  continue
              try:
                  neutron.remove_interface_router(router['id'], {'subnet_id': subnet['id']})
              except neutronclient.common.exceptions.NotFound:
                  pass
      try:
          bmc_router = neutron.list_routers(name='bmc_router').get('routers')[0]
          for port in neutron.list_ports(device_id=bmc_router['id'])['ports']:
              if port.get('device_owner') == 'network:router_gateway':
                  continue
              info = {'id': router['id'],
                      'port_id': port['id'],
                      'tenant_id': bmc_router.get('tenant_id'),
                      }
              neutron.remove_interface_router(bmc_router['id'], info)
          neutron.delete_router(bmc_router['id'])
      except IndexError:
          pass
      for _ in range(0, 5):
          try:
              for port in neutron.list_ports()['ports']:
                  if port['name'].endswith('_provision'):
                      neutron.delete_port(port['id'])
              for net in neutron.list_networks().get('networks'):
                  if not net['name'].startswith('provision_'):
                      continue
                  for port in neutron.list_ports(network_id=net['id'])['ports']:
                      if port.get('device_owner') == 'network:router_interface':
                          continue
                      try:
                          neutron.delete_port(port['id'])
                      except neutronclient.common.exceptions.PortNotFoundClient:
                              pass
                      for subnet in neutron.list_subnets(network_id=net['id'])['subnets']:
                          neutron.delete_subnet(subnet['id'])
                  neutron.delete_network(net['id'])
          except neutronclient.common.exceptions.Conflict:
              LOG.debug('waiting for all the ports to be freed...')
              time.sleep(5)
          else:
              return