Exemplo n.º 1
0
    def _seg_id_allocations(self):

        seg_ids = set()
        for seg_id_range in self.seg_id_ranges:
            seg_min, seg_max = seg_id_range
            seg_ids |= set(moves.range(seg_min, seg_max + 1))

        session = db.get_session()
        with session.begin(subtransactions=True):
            allocs = session.query(self.model).all()
            for alloc in allocs:
                try:
                    seg_ids.remove(alloc.segmentation_id)
                except KeyError:
                    # it's not allocatable, so check if its allocated
                    if not alloc.allocated:
                        # it's not, so remove it from table
                        LOG.info(
                            _LI("Removing seg_id %s from pool") %
                            alloc.segmentation_id)
                        session.delete(alloc)

            for seg_id in sorted(seg_ids):
                alloc = self.model(segmentation_id=seg_id)
                session.add(alloc)
Exemplo n.º 2
0
 def update_project_entry(self, pid, dci_id, result):
     session = db.get_session()
     with session.begin(subtransactions=True):
         session.query(DfaTenants).filter_by(id=pid).update({
             'result': result,
             'dci_id': dci_id
         })
Exemplo n.º 3
0
    def release_segmentation_id(self, seg_id):

        inside = any(lo <= seg_id <= hi for lo, hi in self.seg_id_ranges)
        session = db.get_session()
        with session.begin(subtransactions=True):
            query = session.query(self.model).filter_by(segmentation_id=seg_id)
            if inside:
                del_time = utils.utc_time(time.ctime())
                count = query.update({
                    "allocated": False,
                    "network_id": None,
                    "source": None,
                    "delete_time": del_time
                })
                if count:
                    LOG.info(
                        _LI("Releasing segmentation id %s to pool") % seg_id)
            else:
                count = query.delete()
                if count:
                    LOG.info(
                        _LI("Releasing segmentation_id %s outside pool") %
                        seg_id)

        if not count:
            LOG.info(_LI("segmentation_id %s not found") % seg_id)
Exemplo n.º 4
0
    def release_subnet(self, subnet_address):

        subnet_addr_int = int(netaddr.IPAddress(subnet_address))
        inside = any(lo <= subnet_addr_int <= hi
                     for lo, hi in self.subnet_ranges)
        session = db.get_session()
        with session.begin(subtransactions=True):
            query = session.query(
                self.model).filter_by(subnet_address=subnet_address)
            if inside:
                count = query.update({
                    "allocated": False,
                    "network_id": None,
                    "subnet_id": None
                })
                if count:
                    LOG.info(
                        _LI("Releasing subnet id %s to pool") % subnet_address)
            else:
                count = query.delete()
                if count:
                    LOG.info(
                        _LI("Releasing subnet %s outside pool") %
                        subnet_address)

        if not count:
            LOG.info(_LI("subnet %s not found") % subnet_address)
Exemplo n.º 5
0
    def _subnet_id_allocations(self):

        subnet_ids = sorted(
            set(moves.range(self.subnet_min, self.subnet_max, self.step)))
        # seg_ids = set()
        # for subnet_range in self.subnet_ranges:
        #    subnet_min, subnet_max = subnet_range
        #    subnet_ids |= set(moves.xrange(subnet_min, subnet_max, self.step))

        session = db.get_session()
        with session.begin(subtransactions=True):
            allocs = (session.query(self.model).all())
            for alloc in allocs:
                try:
                    ip = int(netaddr.IPAddress(alloc.subnet_address))
                    subnet_ids.remove(ip)
                except KeyError:
                    # it's not allocatable, so check if its allocated
                    if not alloc.allocated:
                        # it's not, so remove it from table
                        LOG.info(
                            _LI("Removing subnet %s from pool") %
                            alloc.subnet_address)
                        session.delete(alloc)

            for subnet_id in subnet_ids:
                subnet_add = str(netaddr.IPAddress(subnet_id))
                alloc = self.model(subnet_address=subnet_add)
                session.add(alloc)
Exemplo n.º 6
0
 def get_seg_netid_src(self, source):
     session = db.get_session()
     netid_dict = {}
     allocs = (session.query(self.model).filter_by(source=source).all())
     for alloc in allocs:
         if alloc.network_id is not None:
             netid_dict[alloc.network_id] = alloc.segmentation_id
     return netid_dict
Exemplo n.º 7
0
 def get_all_seg_netid(self):
     session = db.get_session()
     netid_dict = {}
     allocs = (session.query(self.model).all())
     for alloc in allocs:
         if alloc.network_id is not None:
             netid_dict[alloc.network_id] = alloc.segmentation_id
     return netid_dict
Exemplo n.º 8
0
 def get_network_by_name(self, name):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             net = session.query(DfaNetwork).filter_by(name=name).all()
         return net
     except orm_exc.NoResultFound:
         LOG.info(_LI('Network %(name)s does not exist'), {'name': name})
Exemplo n.º 9
0
 def get_network_by_name(self, name):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             net = session.query(DfaNetwork).filter_by(name=name).all()
         return net
     except orm_exc.NoResultFound:
         LOG.info(_LI('Network %(name)s does not exist'), {'name': name})
Exemplo n.º 10
0
 def update_subnet(self, subnet, net_id, subnet_id):
     session = db.get_session()
     with session.begin(subtransactions=True):
         session.query(self.model).filter_by(subnet_address=subnet).update({
             "network_id":
             net_id,
             "subnet_id":
             subnet_id
         })
Exemplo n.º 11
0
 def update_fw_db_result(self, fw_id, fw_data):
     session = db.get_session()
     with session.begin(subtransactions=True):
         session.query(DfaFwInfo).filter_by(fw_id=fw_id).update({
             'openstack_provision_status':
             fw_data.get('os_status'),
             'dcnm_provision_status':
             fw_data.get('dcnm_status')
         })
Exemplo n.º 12
0
    def release_subnet_by_netid(self, netid):

        session = db.get_session()
        try:
            with session.begin(subtransactions=True):
                session.query(self.model).filter_by(allocated=True,
                                                    network_id=netid).update(
                                                        {"allocated": False})
        except orm_exc.NoResultFound:
            LOG.info("Network %(netid)s does not exist" % ({'netid': netid}))
Exemplo n.º 13
0
    def release_subnet_no_netid(self):

        net = ''
        session = db.get_session()
        try:
            with session.begin(subtransactions=True):
                (session.query(self.model).filter_by(allocated=True,
                                                     network_id=net).update(
                                                         {"allocated": False}))
        except orm_exc.NoResultFound:
            LOG.error(_LE("Query failed in release subnet no netid"))
Exemplo n.º 14
0
 def get_project_name(self, pid):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             ent = session.query(DfaTenants).filter_by(id=pid).one()
         return ent and ent.name
     except orm_exc.NoResultFound:
         LOG.info('Project %(id)s does not exist', {'id': pid})
     except orm_exc.MultipleResultsFound:
         LOG.error('More than one enty found for project %(id)s.',
                   {'id': pid})
Exemplo n.º 15
0
 def del_project_db(self, pid):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             ent = session.query(DfaTenants).filter_by(id=pid).one()
             session.delete(ent)
     except orm_exc.NoResultFound:
         LOG.info(_LI('Project %(id)s does not exist'), {'id': pid})
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE('More than one enty found for project %(id)s.'),
                   {'id': pid})
Exemplo n.º 16
0
 def get_project_id(self, name):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             ent = session.query(DfaTenants).filter_by(name=name).one()
         return ent and ent.id
     except orm_exc.NoResultFound:
         LOG.info(_LI('Project %(name)s does not exist'), {'name': name})
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE('More than one enty found for project %(name)s.'),
                   {'name': name})
Exemplo n.º 17
0
 def get_project_id(self, name):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             ent = session.query(DfaTenants).filter_by(name=name).one()
         return ent and ent.id
     except orm_exc.NoResultFound:
         LOG.info(_LI('Project %(name)s does not exist'), {'name': name})
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE('More than one enty found for project %(name)s.'),
                   {'name': name})
Exemplo n.º 18
0
 def del_project_db(self, pid):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             ent = session.query(DfaTenants).filter_by(id=pid).one()
             session.delete(ent)
     except orm_exc.NoResultFound:
         LOG.info(_LI('Project %(id)s does not exist'), {'id': pid})
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE('More than one enty found for project %(id)s.'),
                   {'id': pid})
Exemplo n.º 19
0
 def get_agent_configurations(self, host):
     session = db.get_session()
     with session.begin(subtransactions=True):
         try:
             ent = session.query(DfaAgentsDb).filter_by(host=host).one()
             return ent.configurations
         except orm_exc.NoResultFound:
             LOG.info(_LI('Agent %(host)s does not exist.'), {'host': host})
         except orm_exc.MultipleResultsFound:
             LOG.error(_LE('More than one enty found for agent %(host)s.'),
                       {'host': host})
Exemplo n.º 20
0
 def get_agent_configurations(self, host):
     session = db.get_session()
     with session.begin(subtransactions=True):
         try:
             ent = session.query(DfaAgentsDb).filter_by(host=host).one()
             return ent.configurations
         except orm_exc.NoResultFound:
             LOG.info(_LI('Agent %(host)s does not exist.'), {'host': host})
         except orm_exc.MultipleResultsFound:
             LOG.error(_LE('More than one enty found for agent %(host)s.'),
                       {'host': host})
Exemplo n.º 21
0
 def add_network_db(self, net_id, net_data, source, result):
     session = db.get_session()
     with session.begin(subtransactions=True):
         net = DfaNetwork(network_id=net_id,
                          name=net_data.get('name'),
                          config_profile=net_data.get('config_profile'),
                          segmentation_id=net_data.get('segmentation_id'),
                          tenant_id=net_data.get('tenant_id'),
                          fwd_mod=net_data.get('fwd_mod'),
                          source=source,
                          result=result)
         session.add(net)
Exemplo n.º 22
0
 def get_vm(self, port_id):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             port = session.query(DfaVmInfo).filter_by(
                 port_id=port_id).one()
         return port
     except orm_exc.NoResultFound:
         LOG.info(_LI('Port %(id)s does not exist'), {'id': port_id})
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE('More than one enty found for Port %(id)s.'),
                   {'id': port_id})
Exemplo n.º 23
0
 def get_network(self, net_id):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             net = session.query(DfaNetwork).filter_by(
                 network_id=net_id).one()
         return net
     except orm_exc.NoResultFound:
         LOG.info('Network %(id)s does not exist', {'id': net_id})
     except orm_exc.MultipleResultsFound:
         LOG.error('More than one enty found for network %(id)s.',
                   {'id': net_id})
Exemplo n.º 24
0
 def get_network_by_segid(self, segid):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             net = session.query(DfaNetwork).filter_by(
                 segmentation_id=segid).one()
         return net
     except orm_exc.NoResultFound:
         LOG.info(_LI('Network %(segid)s does not exist'), {'segid': segid})
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE('More than one enty found for seg-id %(id)s.'),
                   {'id': segid})
Exemplo n.º 25
0
 def get_vm(self, port_id):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             port = session.query(DfaVmInfo).filter_by(
                 port_id=port_id).one()
         return port
     except orm_exc.NoResultFound:
         LOG.info(_LI('Port %(id)s does not exist'), {'id': port_id})
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE('More than one enty found for Port %(id)s.'),
                   {'id': port_id})
Exemplo n.º 26
0
 def add_network_db(self, net_id, net_data, source, result):
     session = db.get_session()
     with session.begin(subtransactions=True):
         net = DfaNetwork(network_id=net_id,
                          name=net_data.get('name'),
                          config_profile=net_data.get('config_profile'),
                          segmentation_id=net_data.get('segmentation_id'),
                          tenant_id=net_data.get('tenant_id'),
                          fwd_mod=net_data.get('fwd_mod'),
                          source=source,
                          result=result)
         session.add(net)
Exemplo n.º 27
0
 def get_network_by_segid(self, segid):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             net = session.query(DfaNetwork).filter_by(
                 segmentation_id=segid).one()
         return net
     except orm_exc.NoResultFound:
         LOG.info(_LI('Network %(segid)s does not exist'), {'segid': segid})
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE('More than one enty found for seg-id %(id)s.'),
                   {'id': segid})
Exemplo n.º 28
0
 def get_fw_by_rtrid(self, rtrid):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             rtr = session.query(DfaFwInfo).filter_by(router_id=rtrid)
     except orm_exc.NoResultFound:
         LOG.info(_LI('rtr %(rtrid)s does not exist') % ({'rtrid': rtrid}))
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE("More than one enty found for rtrid-id %(id)s."),
                   ({
                       'id': rtrid
                   }))
     return rtr
Exemplo n.º 29
0
 def query_topology_db(self, dict_convert=False, **req):
     """Query an entry to the topology DB. """
     session = db.get_session()
     with session.begin(subtransactions=True):
         try:
             # Check if entry exists.
             topo_disc = session.query(DfaTopologyDb).filter_by(**req).all()
         except orm_exc.NoResultFound:
             LOG.info("No Topology results found for %s", req)
             return None
     if dict_convert:
         return self._convert_topo_obj_dict(topo_disc)
     return topo_disc
Exemplo n.º 30
0
 def delete_topology_entry(self, **req):
     """Delete the entries from the topology DB. """
     session = db.get_session()
     with session.begin(subtransactions=True):
         try:
             rows = session.query(DfaTopologyDb).filter_by(**req).all()
         except orm_exc.NoResultFound:
             LOG.info("No Topology results found for %s", req)
             return
         try:
             for row in rows:
                 session.delete(row)
         except Exception as exc:
             LOG.error("Exception raised %s", str(exc))
Exemplo n.º 31
0
 def get_fw_by_rtr_netid(self, netid):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             net = session.query(DfaFwInfo).filter_by(
                 router_net_id=netid).one()
         return net
     except orm_exc.NoResultFound:
         LOG.info('Network %(segid)s does not exist' % ({'netid': netid}))
     except orm_exc.MultipleResultsFound:
         LOG.error("More than one enty found for netid-id %(id)s.",
                   ({
                       'id': netid
                   }))
Exemplo n.º 32
0
 def get_fw_by_tenant_id(self, tenant_id):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             fw = session.query(DfaFwInfo).filter(
                 (DfaFwInfo.tenant_id == tenant_id)).one()
             fw_dict = self.conv_db_dict(fw)
         return fw_dict
     except orm_exc.NoResultFound:
         LOG.info(_LI('FW %s does not exist') % tenant_id)
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE("More than one enty found for tenant-id %(id)s."),
                   ({
                       'id': tenant_id
                   }))
Exemplo n.º 33
0
 def get_fw(self, fw_id):
     session = db.get_session()
     fw = None
     try:
         with session.begin(subtransactions=True):
             fw = session.query(DfaFwInfo).filter_by(fw_id=fw_id).first()
             fw_dict = self.conv_db_dict(fw)
     except orm_exc.NoResultFound:
         LOG.info(_LI('fw %(fwid)s does not exist') % ({'fw_id': fw_id}))
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE("More than one enty found for fwid-id %(id)s."),
                   ({
                       'id': fw_id
                   }))
     return fw, fw_dict
Exemplo n.º 34
0
 def get_subnet(self, sub):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             net = session.query(self.model).filter_by(allocated=True,
                                                       subnet_address=sub).\
                 one()
         return net
     except orm_exc.NoResultFound:
         LOG.info('subnet %(sub)s does not exist', ({'sub': sub}))
     except orm_exc.MultipleResultsFound:
         LOG.error("More than one enty found for sub %(sub)s.", ({
             'sub': sub
         }))
     return None
Exemplo n.º 35
0
 def clear_fw_entry_by_netid(self, net_id):
     session = db.get_session()
     with session.begin(subtransactions=True):
         session.query(DfaFwInfo).filter_by(in_network_id=net_id).update({
             'in_network_id':
             '',
             'in_service_node_ip':
             ''
         })
         # We don't need to do the below if above succeeds, TODO(padkrish)
         session.query(DfaFwInfo).filter_by(out_network_id=net_id).update({
             'out_network_id':
             '',
             'out_service_node_ip':
             ''
         })
Exemplo n.º 36
0
 def add_vms_db(self, vm_data, result):
     session = db.get_session()
     with session.begin(subtransactions=True):
         vm = DfaVmInfo(instance_id=vm_data['oui'].get('vm_uuid'),
                        name=vm_data['oui'].get('vm_name'),
                        status=vm_data.get('status'),
                        network_id=vm_data.get('net_uuid'),
                        port_id=vm_data.get('port_uuid'),
                        ip=vm_data['oui'].get('ip_addr'),
                        mac=vm_data.get('vm_mac'),
                        segmentation_id=vm_data.get('segmentation_id'),
                        fwd_mod=vm_data['oui'].get('fwd_mod'),
                        gw_mac=vm_data['oui'].get('gw_mac'),
                        host=vm_data.get('host'),
                        result=result)
         session.add(vm)
Exemplo n.º 37
0
 def get_fw_by_netid(self, netid):
     session = db.get_session()
     try:
         with session.begin(subtransactions=True):
             fw = session.query(DfaFwInfo).filter(
                 (DfaFwInfo.in_network_id == netid)
                 | (DfaFwInfo.out_network_id == netid)).one()
         return fw
     except orm_exc.NoResultFound:
         LOG.info(_LI('FW %(netid)s does not exist'), ({'netid': netid}))
     except orm_exc.MultipleResultsFound:
         LOG.error(_LE("More than one enty found for netid-id %(id)s."),
                   ({
                       'id': netid
                   }))
     return None
Exemplo n.º 38
0
 def add_vms_db(self, vm_data, result):
     session = db.get_session()
     with session.begin(subtransactions=True):
         vm = DfaVmInfo(instance_id=vm_data['oui'].get('vm_uuid'),
                        name=vm_data['oui'].get('vm_name'),
                        status=vm_data.get('status'),
                        network_id=vm_data.get('net_uuid'),
                        port_id=vm_data.get('port_uuid'),
                        ip=vm_data['oui'].get('ip_addr'),
                        mac=vm_data.get('vm_mac'),
                        segmentation_id=vm_data.get('segmentation_id'),
                        fwd_mod=vm_data['oui'].get('fwd_mod'),
                        gw_mac=vm_data['oui'].get('gw_mac'),
                        host=vm_data.get('host'),
                        result=result)
         session.add(vm)
Exemplo n.º 39
0
    def update_agent_db(self, agent_info):
        session = db.get_session()
        host = agent_info.get('host')
        with session.begin(subtransactions=True):
            try:
                # Check if entry exists.
                session.query(DfaAgentsDb).filter_by(host=host).one()

                # Entry exist, only update the heartbeat and configurations.
                session.query(DfaAgentsDb).filter_by(host=host).update(
                    {'heartbeat': agent_info.get('timestamp')})
            except orm_exc.NoResultFound:
                LOG.info(_LI('Creating new entry for agent on %(host)s.'),
                         {'host': host})
                agent = DfaAgentsDb(host=host,
                                    created=agent_info.get('timestamp'),
                                    heartbeat=agent_info.get('timestamp'),
                                    configurations=agent_info.get('config'))
                session.add(agent)
            except orm_exc.MultipleResultsFound:
                LOG.error(_LE('More than one enty found for agent %(host)s.'),
                          {'host': host})
Exemplo n.º 40
0
 def get_all_projects(self):
     session = db.get_session()
     with session.begin(subtransactions=True):
         projs = session.query(DfaTenants).all()
     return projs
Exemplo n.º 41
0
 def update_project_entry(self, pid, dci_id, result):
     session = db.get_session()
     with session.begin(subtransactions=True):
         session.query(DfaTenants).filter_by(id=pid).update(
             {'result': result, 'dci_id': dci_id})
Exemplo n.º 42
0
 def get_all_networks(self):
     session = db.get_session()
     with session.begin(subtransactions=True):
         nets = session.query(DfaNetwork).all()
     return nets
Exemplo n.º 43
0
 def update_network_db(self, net_id, result):
     session = db.get_session()
     with session.begin(subtransactions=True):
         session.query(DfaNetwork).filter_by(
             network_id=net_id).update({"result": result})
Exemplo n.º 44
0
 def update_network(self, net_id, **params):
     session = db.get_session()
     with session.begin(subtransactions=True):
         session.query(DfaNetwork).filter_by(
             network_id=net_id).update(params.get('columns'))
Exemplo n.º 45
0
 def add_project_db(self, pid, name, dci_id, result):
     proj = DfaTenants(id=pid, name=name, dci_id=dci_id, result=result)
     session = db.get_session()
     with session.begin(subtransactions=True):
         session.add(proj)
Exemplo n.º 46
0
 def update_agent_configurations(self, host, configs):
     session = db.get_session()
     with session.begin(subtransactions=True):
         # Update the configurations.
         return session.query(DfaAgentsDb).filter_by(host=host).update(
             {'configurations': configs})
Exemplo n.º 47
0
 def update_vm_db(self, vm_port_id, **params):
     session = db.get_session()
     with session.begin(subtransactions=True):
         session.query(DfaVmInfo).filter_by(
             port_id=vm_port_id).update(params.get('columns'))
Exemplo n.º 48
0
 def get_fialed_projects_entries(self, fail_res):
     session = db.get_session()
     with session.begin(subtransactions=True):
         ent = session.query(DfaTenants).filter_by(result=fail_res).all()
     return ent
Exemplo n.º 49
0
 def get_vms_for_this_req(self, **req):
     session = db.get_session()
     with session.begin(subtransactions=True):
         vms = session.query(DfaVmInfo).filter_by(**req).all()
     return vms
Exemplo n.º 50
0
 def get_vms(self):
     session = db.get_session()
     with session.begin(subtransactions=True):
         vms = session.query(DfaVmInfo).all()
     return vms
Exemplo n.º 51
0
 def delete_network_db(self, net_id):
     session = db.get_session()
     with session.begin(subtransactions=True):
         net = session.query(DfaNetwork).filter_by(
             network_id=net_id).first()
         session.delete(net)
Exemplo n.º 52
0
 def delete_vm_db(self, vm_uuid):
     session = db.get_session()
     with session.begin(subtransactions=True):
         vm = session.query(DfaVmInfo).filter_by(
             instance_id=vm_uuid).first()
         session.delete(vm)