Exemplo n.º 1
0
    def parseParams(self, params):
        obj_dict = params.copy()
        nodes_list = obj_dict.pop('nodes', [])
        probes_list = obj_dict.get('healthMonitor', [])
        vips_list = obj_dict.get('virtualIps', [])
        stic = obj_dict.get('sessionPersistence', [])

        try:
            lb = obj_dict.pop('lb')
        except KeyError:
            lb_ref = db_api.loadbalancer_pack_extra(obj_dict)
        else:
            lb_ref = db_api.loadbalancer_pack_extra(obj_dict)
            lb_ref['id'] = lb['id']
            lb_ref['tenant_id'] = lb['tenant_id']
            lb_ref['created_at'] = lb['created_at']
            lb_ref['updated_at'] = lb['updated_at']

        lb_ref['status'] = lb_status.BUILD
        self.lb = lb_ref

        sf_ref = db_api.serverfarm_pack_extra({})
        self.sf = sf_ref
        self.sf._rservers = []
        self.sf._probes = []
        self.sf._sticky = []

        predictor_ref = db_api.predictor_pack_extra({})
        self.sf._predictor = predictor_ref

        """ Parse RServer nodes and attach them to SF """
        for node in nodes_list:
            rs_ref = db_api.server_pack_extra(node)
            # We need to check if there is already real server with the
            # same IP deployed
            try:
                parent_ref = db_api.server_get_by_address_on_device(self.conf,
                                                        rs_ref['address'],
                                                        lb_ref['device_id'])
            except exception.ServerNotFound:
                pass
            else:
                if parent_ref.get('address') != '':
                    rs_ref['parent_id'] = parent_ref['id']

            self.rs.append(rs_ref)
            self.sf._rservers.append(rs_ref)

        for pr in probes_list:
            probe_ref = db_api.probe_pack_extra(pr)
            self.probes.append(probe_ref)
            self.sf._probes.append(probe_ref)

        for vip in vips_list:
            vs_ref = db_api.virtualserver_pack_extra(vip)
            vs_ref['transport'] = lb_ref['extra'].get('transport')
            vs_ref['appProto'] = lb_ref['protocol']
            vs_ref['name'] = vs_ref['id']
            self.vips.append(vs_ref)
            self.vips.append(vs_ref)
Exemplo n.º 2
0
def create_lb(conf, params):
    nodes = params.pop('nodes', [])
    probes = params.pop('healthMonitor', [])
    vips = params.pop('virtualIps', [])
    values = db_api.loadbalancer_pack_extra(params)
    lb_ref = db_api.loadbalancer_create(conf, values)
    device = scheduler.schedule_loadbalancer(conf, lb_ref)
    device_driver = drivers.get_device_driver(conf, device['id'])
    lb = db_api.unpack_extra(lb_ref)
    lb['device_id'] = device['id']
    lb_ref = db_api.loadbalancer_pack_extra(lb)
    try:
        with device_driver.request_context() as ctx:
            commands.create_loadbalancer(ctx, lb_ref, nodes, probes, vips)

    except (exception.Error, exception.Invalid):
        lb_ref.status = lb_status.ERROR
        lb_ref.deployed = 'False'
    else:
        lb_ref.status = lb_status.ACTIVE
        lb_ref.deployed = 'True'
    db_api.loadbalancer_update(conf, lb['id'], lb_ref)
    return lb_ref['id']
Exemplo n.º 3
0
def create_lb(conf, params):
    node_values = params.pop('nodes', [])
    probe_values = params.pop('healthMonitor', [])
    vip_values = params.pop('virtualIps', [])
    lb_values = db_api.loadbalancer_pack_extra(params)

    lb_ref = db_api.loadbalancer_create(conf, lb_values)
    sf_ref = db_api.serverfarm_create(conf, {'lb_id': lb_ref['id']})
    db_api.predictor_create(conf, {'sf_id': sf_ref['id'],
                                   'type': lb_ref['algorithm']})
    vip_update_values = {'protocol': lb_ref['protocol']}

    vips = []
    for vip in vip_values:
        vip = db_api.virtualserver_pack_extra(vip)
        db_api.pack_update(vip, vip_update_values)
        vip['lb_id'] = lb_ref['id']
        vip['sf_id'] = sf_ref['id']
        vips.append(db_api.virtualserver_create(conf, vip))

    servers = []
    for server in node_values:
        server = db_api.server_pack_extra(server)
        server['sf_id'] = sf_ref['id']
        servers.append(db_api.server_create(conf, server))

    probes = []
    for probe in probe_values:
        probe = db_api.probe_pack_extra(probe)
        probe['lb_id'] = lb_ref['id']
        probe['sf_id'] = sf_ref['id']
        probes.append(db_api.probe_create(conf, probe))

    device_ref = scheduler.schedule(conf, lb_ref)
    db_api.loadbalancer_update(conf, lb_ref['id'],
                               {'device_id': device_ref['id']})
    device_driver = drivers.get_device_driver(conf, device_ref['id'])
    with device_driver.request_context() as ctx:
        try:
            commands.create_loadbalancer(ctx, sf_ref, vips, servers, probes,
                                         [])
        except Exception:
            with utils.save_and_reraise_exception():
                db_api.loadbalancer_update(conf, lb_ref['id'],
                                           {'status': lb_status.ERROR,
                                            'deployed': False})
    db_api.loadbalancer_update(conf, lb_ref['id'],
                               {'status': lb_status.ACTIVE,
                                'deployed': True})
    return lb_ref['id']