def lb_change_node_status(conf, lb_id, lb_node_id, lb_node_status): balancer_instance = vserver.Balancer(conf) balancer_instance.loadFromDB(lb_id) rs = db_api.server_get(conf, lb_node_id) sf = balancer_instance.sf if rs['state'] == lb_node_status: return "OK" rs['state'] = lb_node_status rsname = rs['name'] if rs['parent_id'] != "": rs['name'] = rs['parent_id'] logger.debug("Changing RServer status to: %s" % lb_node_status) device_driver = drivers.get_device_driver( balancer_instance.lb['device_id']) with device_driver.request_context() as ctx: if lb_node_status == "inservice": commands.activate_rserver(ctx, sf, rs) else: commands.suspend_rserver(ctx, sf, rs) rs['name'] = rsname db_api.server_update(conf, rs['id'], rs) return "Node %s has status %s" % (lb_node_id, rs['state'])
def update(self): db_api.loadbalancer_update(self.conf, self.lb['id'], self.lb) for st in self.sf._sticky: db_api.sticky_update(self.conf, st['id'], st) for rs in self.rs: db_api.server_update(self.conf, rs['id'], rs) for pr in self.probes: db_api.probe_update(self.conf, pr['id'], pr) for vip in self.vips: db_api.virtualserver_update(self.conf, vip['id'], vip)
def delete_rserver(ctx, rs): rss = [] LOG.debug("Got delete RS request") if rs["parent_id"] == "": rss = db_api.server_get_all_by_parent_id(ctx.conf, rs["id"]) LOG.debug("List of servers: %s", rss) ctx.device.delete_real_server(rs) if len(rss) > 0: for rs_child in rss: db_api.server_update(rs_child["id"], {"parent_id": rss[-1]["id"]}) db_api.server_update(rss[-1]["id"], {"parent_id": "", "deployed": "True"}) ctx.device.create_real_server(rss[-1])
def delete_rserver(ctx, rs): rss = [] LOG.debug("Got delete RS request") if rs['parent_id'] == "": rss = db_api.server_get_all_by_parent_id(ctx.conf, rs['id']) LOG.debug("List of servers: %s", rss) ctx.device.delete_real_server(rs) if len(rss) > 0: for rs_child in rss: db_api.server_update(ctx.conf, rs_child['id'], {'parent_id': rss[-1]['id']}) db_api.server_update(ctx.conf, rss[-1]['id'], {'parent_id': '', 'deployed': 'True'}) ctx.device.create_real_server(rss[-1])
def create_rserver(ctx, rs): try: # We can't create multiple RS with the same IP. So parent_id points to # RS which already deployed and has this IP LOG.debug("Creating rserver command execution with rserver: %s", rs) LOG.debug("RServer parent_id: %s", rs['parent_id']) if not rs['parent_id']: ctx.device.create_real_server(rs) rs['deployed'] = 'True' db_api.server_update(ctx.conf, rs['id'], rs) yield except Exception: ctx.device.delete_real_server(rs) rs['deployed'] = 'False' db_api.server_update(ctx.conf, rs['id'], rs) raise
def lb_update_node(conf, lb_id, lb_node_id, lb_node): rs = db_api.server_get(conf, lb_node_id) lb = db_api.loadbalancer_get(conf, lb_id) device_driver = drivers.get_device_driver(conf, lb['device_id']) sf = db_api.serverfarm_get(conf, rs['sf_id']) with device_driver.request_context() as ctx: commands.delete_rserver_from_server_farm(ctx, sf, rs) db_api.pack_update(rs, lb_node) new_rs = db_api.server_update(conf, rs['id'], rs) commands.add_rserver_to_server_farm(ctx, sf, new_rs) return db_api.unpack_extra(new_rs)
def lb_change_node_status(conf, lb_id, lb_node_id, lb_node_status): lb = db_api.loadbalancer_get(conf, lb_id) rs = db_api.server_get(conf, lb_node_id) sf = db_api.serverfarm_get(conf, rs['sf_id']) if rs['state'] == lb_node_status: return "OK" rs['state'] = lb_node_status rsname = rs['name'] if rs['parent_id'] != "": rs['name'] = rs['parent_id'] logger.debug("Changing RServer status to: %s" % lb_node_status) device_driver = drivers.get_device_driver(conf, lb['device_id']) with device_driver.request_context() as ctx: if lb_node_status == "inservice": commands.activate_rserver(ctx, sf, rs) else: commands.suspend_rserver(ctx, sf, rs) rs['name'] = rsname db_api.server_update(conf, rs['id'], rs) return db_api.unpack_extra(rs)
def test_server_update(self): values = get_fake_server('1', 1) server_ref = db_api.server_create(self.conf, values) update = {'name': 'test', 'extra': {'cookieName': 'testHTTPCookie', 'enableInsert': True, 'browserExpire': False, 'offset': False, 'length': 1000, 'secondaryName': 'cookie'}} server_ref = db_api.server_update(self.conf, server_ref['id'], update) server = dict(server_ref.iteritems()) values.update(update) self.assertIsNotNone(server['id']) values['id'] = server['id'] self.assertEqual(server, values)
def test_server_update(self): values = get_fake_server("1", 1) server_ref = db_api.server_create(self.conf, values) update = { "name": "test", "extra": { "cookieName": "testHTTPCookie", "enableInsert": True, "browserExpire": False, "offset": False, "length": 1000, "secondaryName": "cookie", }, } server_ref = db_api.server_update(self.conf, server_ref["id"], update) server = dict(server_ref.iteritems()) values.update(update) self.assertIsNotNone(server["id"]) values["id"] = server["id"] self.assertEqual(server, values)
def savetoDB(self): try: lb_ref = db_api.loadbalancer_update(self.conf, self.lb['id'], self.lb) except exception.LoadBalancerNotFound: lb_ref = db_api.loadbalancer_create(self.conf, self.lb) self.sf['lb_id'] = lb_ref['id'] try: sf_ref = db_api.serverfarm_update(self.conf, self.sf['id'], self.sf) except exception.ServerFarmNotFound: sf_ref = db_api.serverfarm_create(self.conf, self.sf) self.sf._predictor['sf_id'] = sf_ref['id'] try: db_api.predictor_update(self.conf, self.sf._predictor['id'], self.sf._predictor) except exception.PredictorNotFound: db_api.predictor_create(self.conf, self.sf._predictor) stickies = self.sf._sticky vips = [] self.sf = sf_ref self.sf._rservers = [] self.sf._probes = [] self.sf._sticky = [] for rs in self.rs: rs['sf_id'] = sf_ref['id'] try: rs_ref = db_api.server_update(self.conf, rs['id'], rs) except exception.ServerNotFound: rs_ref = db_api.server_create(self.conf, rs) self.sf._rservers.append(rs_ref) for pr in self.probes: pr['sf_id'] = sf_ref['id'] try: pr_ref = db_api.probe_update(self.conf, pr['id'], pr) except exception.ProbeNotFound: pr_ref = db_api.probe_create(self.conf, pr) self.sf._probes.append(pr_ref) for vip in self.vips: vip['sf_id'] = sf_ref['id'] vip['lb_id'] = lb_ref['id'] try: vip_ref = db_api.virtualserver_update(self.conf, vip['id'], vip) except exception.VirtualServerNotFound: vip_ref = db_api.virtualserver_create(self.conf, vip) vips.append(vip_ref) for st in stickies: st['sf_id'] = sf_ref['id'] try: st_ref = db_api.sticky_update(self.conf, st['id'], st) except exception.StickyNotFound: st_ref = db_api.sticky_create(self.conf, st) self.sf._sticky.append(st_ref) self.rs = self.sf._rservers self.probes = self.sf._probes self.vips = vips