Esempio n. 1
0
def device_create(conf, values):
    session = get_session(conf)
    with session.begin():
        device_ref = models.Device()
        device_ref.update(values)
        session.add(device_ref)
        return device_ref
Esempio n. 2
0
def serverfarm_get(conf, serverfarm_id, session=None):
    session = session or get_session(conf)
    serverfarm_ref = session.query(models.ServerFarm).\
                             filter_by(id=serverfarm_id).first()
    if not serverfarm_ref:
        raise exception.ServerFarmNotFound(serverfarm_id=serverfarm_id)
    return serverfarm_ref
Esempio n. 3
0
def loadbalancer_get(conf, loadbalancer_id, session=None):
    session = session or get_session(conf)
    loadbalancer_ref = session.query(models.LoadBalancer).\
                               filter_by(id=loadbalancer_id).first()
    if not loadbalancer_ref:
        raise exception.LoadBalancerNotFound(loadbalancer_id=loadbalancer_id)
    return loadbalancer_ref
Esempio n. 4
0
def virtualserver_create(conf, values):
    session = get_session(conf)
    with session.begin():
        vserver_ref = models.VirtualServer()
        vserver_ref.update(values)
        session.add(vserver_ref)
        return vserver_ref
Esempio n. 5
0
def sticky_create(conf, values):
    session = get_session(conf)
    with session.begin():
        sticky_ref = models.Sticky()
        sticky_ref.update(values)
        session.add(sticky_ref)
        return sticky_ref
Esempio n. 6
0
def loadbalancer_create(conf, values):
    session = get_session(conf)
    with session.begin():
        lb_ref = models.LoadBalancer()
        lb_ref.update(values)
        session.add(lb_ref)
        return lb_ref
Esempio n. 7
0
def predictor_create(conf, values):
    session = get_session(conf)
    with session.begin():
        predictor_ref = models.Predictor()
        predictor_ref.update(values)
        session.add(predictor_ref)
        return predictor_ref
Esempio n. 8
0
def loadbalancer_update(conf, lb_id, values):
    session = get_session(conf)
    with session.begin():
        lb_ref = loadbalancer_get(conf, lb_id, session=session)
        lb_ref.update(values)
        lb_ref['updated_at'] = datetime.datetime.utcnow()
        return lb_ref
Esempio n. 9
0
def serverfarm_get_all_by_lb_id(conf, lb_id, tenant_id=None):
    session = get_session(conf)
    query = session.query(models.ServerFarm).filter_by(lb_id=lb_id)
    if tenant_id:
        query = query.filter(models.LoadBalancer.id == lb_id).\
                      filter(models.LoadBalancer.tenant_id == tenant_id)
    return query.all()
Esempio n. 10
0
def serverfarm_create(conf, values):
    session = get_session(conf)
    with session.begin():
        serverfarm_ref = models.ServerFarm()
        serverfarm_ref.update(values)
        session.add(serverfarm_ref)
        return serverfarm_ref
Esempio n. 11
0
def predictor_get(conf, predictor_id, session=None):
    session = session or get_session(conf)
    predictor_ref = session.query(models.Predictor).\
                            filter_by(id=predictor_id).first()
    if not predictor_ref:
        raise exception.PredictorNotFound(predictor_id=predictor_id)
    return predictor_ref
Esempio n. 12
0
def virtualserver_get(conf, vserver_id, session=None):
    session = session or get_session(conf)
    vserver_ref = session.query(models.VirtualServer).\
                          filter_by(id=vserver_id).first()
    if not vserver_ref:
        raise exception.VirtualServerNotFound(virtualserver_id=vserver_id)
    return vserver_ref
Esempio n. 13
0
def device_get(conf, device_id, session=None):
    session = session or get_session(conf)
    device_ref = session.query(models.Device).\
                         filter_by(id=device_id).first()
    if not device_ref:
        raise exception.DeviceNotFound(device_id=device_id)
    return device_ref
Esempio n. 14
0
def server_get_by_address(conf, server_address):
    session = get_session(conf)
    server_ref = session.query(models.Server).\
                         filter_by(address=server_address).\
                         filter_by(deployed='True').first()
    if not server_ref:
        raise exception.ServerNotFound(server_address=server_address)
    return server_ref
Esempio n. 15
0
def lb_count_active_by_device(conf, device_id):
    session = get_session(conf)
    with session.begin():
        lbs_count = session.query(models.LoadBalancer).\
                                  filter_by(device_id=device_id).\
                                  filter_by(status=lb_status.ACTIVE).\
                                  count()
        return lbs_count
Esempio n. 16
0
def predictor_get_by_sf_id(conf, sf_id):
    session = get_session(conf)
    predictor_ref = session.query(models.Predictor).\
                            filter_by(sf_id=sf_id).\
                            first()
    if not predictor_ref:
        raise exception.PredictorNotFound(sf_id=sf_id)
    return predictor_ref
Esempio n. 17
0
def virtualserver_get_all_by_lb_id(conf, lb_id):
    session = get_session(conf)
    vips = session.query(models.VirtualServer).\
                  filter(models.ServerFarm.lb_id == lb_id).\
                  filter_by(sf_id=models.ServerFarm.id).all()
    if not vips:
        raise exception.VirtualServerNotFound(
            "No virtual servers found for loadbalancer with id %s" % lb_id)
    return vips
Esempio n. 18
0
def loadbalancer_get(conf, loadbalancer_id, tenant_id=None, session=None):
    session = session or get_session(conf)
    query = session.query(models.LoadBalancer).filter_by(id=loadbalancer_id)
    if tenant_id:
        query = query.filter_by(tenant_id=tenant_id)
    loadbalancer_ref = query.first()
    if not loadbalancer_ref:
        raise exception.LoadBalancerNotFound(loadbalancer_id=loadbalancer_id)
    return loadbalancer_ref
Esempio n. 19
0
def loadbalancer_get_all_by_device_id(conf, device_id):
    session = get_session(conf)
    query = session.query(models.LoadBalancer).filter_by(device_id=device_id)
    lb_refs = query.all()
    if not lb_refs:
        raise exception.LoadBalancerNotFound('No loadbalancer '
                                             'for the device %s found'
                                             % device_id)
    return lb_refs
Esempio n. 20
0
def loadbalancer_get_all_by_vm_id(conf, tenant_id, vm_id):
    session = get_session(conf)
    query = session.query(models.LoadBalancer).distinct().\
                    filter_by(tenant_id=tenant_id).\
                    filter(models.LoadBalancer.id ==
                           models.ServerFarm.lb_id).\
                    filter(models.Server.sf_id ==
                           models.ServerFarm.id).\
                    filter(models.Server.vm_id == vm_id)
    return query.all()
Esempio n. 21
0
def server_get(conf, server_id, lb_id=None, session=None):
    session = session or get_session(conf)
    query = session.query(models.Server).filter_by(id=server_id)
    if lb_id:
        query = query.filter(models.ServerFarm.lb_id == lb_id).\
                        filter(models.Server.sf_id == models.ServerFarm.id)
    server_ref = query.first()
    if not server_ref:
        raise exception.ServerNotFound(server_id=server_id)
    return server_ref
Esempio n. 22
0
def sticky_get(conf, sticky_id, tenant_id=None, session=None):
    session = session or get_session(conf)
    query = session.query(models.Sticky).filter_by(id=sticky_id)
    if tenant_id:
        query = query.filter(models.Sticky.sf_id == models.ServerFarm.id).\
                  filter(models.LoadBalancer.id == models.ServerFarm.lb_id).\
                  filter(models.LoadBalancer.tenant_id == tenant_id)
    sticky_ref = query.first()
    if not sticky_ref:
        raise exception.StickyNotFound(sticky_id=sticky_id)
    return sticky_ref
Esempio n. 23
0
def probe_get(conf, probe_id, tenant_id=None, session=None):
    session = session or get_session(conf)
    query = session.query(models.Probe).filter_by(id=probe_id)
    if tenant_id:
        query = query.filter(models.Probe.sf_id == models.ServerFarm.id).\
                  filter(models.LoadBalancer.id == models.ServerFarm.lb_id).\
                  filter(models.LoadBalancer.tenant_id == tenant_id)
    probe_ref = query.first()
    if not probe_ref:
        raise exception.ProbeNotFound(probe_id=probe_id)
    return probe_ref
Esempio n. 24
0
def virtualserver_get_all_by_lb_id(conf, lb_id, tenant_id=None):
    session = get_session(conf)
    query = session.query(models.VirtualServer).\
                  filter(models.ServerFarm.lb_id == lb_id).\
                  filter_by(sf_id=models.ServerFarm.id)
    if tenant_id:
        query = query.\
                  filter(models.LoadBalancer.id == models.ServerFarm.lb_id).\
                  filter(models.LoadBalancer.tenant_id == tenant_id)
    vips = query.all()
    return vips
Esempio n. 25
0
def server_get_by_address_on_device(conf, server_address, device_id):
    session = get_session(conf)
    server_refs = session.query(models.Server).\
                         filter_by(address=server_address).\
                         filter_by(deployed='True')
    for server_ref in server_refs:
        sf = serverfarm_get(conf, server_ref['sf_id'], session=session)
        lb = loadbalancer_get(conf, sf['lb_id'])
        if device_id == lb['device_id']:
            return server_ref
    raise exception.ServerNotFound(server_address=server_address,
                                   device_id=device_id)
Esempio n. 26
0
def virtualserver_get(conf, vserver_id, tenant_id=None, session=None):
    session = session or get_session(conf)
    query = session.query(models.VirtualServer).filter_by(id=vserver_id)
    if tenant_id:
        query = query.\
                  filter(models.VirtualServer.sf_id == models.ServerFarm.id).\
                  filter(models.LoadBalancer.id == models.ServerFarm.lb_id).\
                  filter(models.LoadBalancer.tenant_id == tenant_id)
    vserver_ref = query.first()
    if not vserver_ref:
        raise exception.VirtualServerNotFound(virtualserver_id=vserver_id)
    return vserver_ref
Esempio n. 27
0
def device_destroy(conf, device_id):
    session = get_session(conf)
    with session.begin():
        device_ref = device_get(conf, device_id, session=session)
        session.delete(device_ref)
Esempio n. 28
0
def device_update(conf, device_id, values):
    session = get_session(conf)
    with session.begin():
        device_ref = device_get(conf, device_id, session=session)
        device_ref.update(values)
        return device_ref
Esempio n. 29
0
def device_get_all(conf):
    session = get_session(conf)
    query = session.query(models.Device)
    return query.all()
Esempio n. 30
0
def virtualserver_destroy_by_sf_id(conf, sf_id, session=None):
    session = session or get_session(conf)
    with session.begin():
        session.query(models.VirtualServer).filter_by(sf_id=sf_id).delete()