def update_vip(self, vips): pools_ins = list() pools_del = list() tratado = util.trata_param_vip(vips) vts = virtualserver.VirtualServer(self._lb) dict_create_vip = { 'vips_cache': tratado.get('vips_cache_filter_to_insert'), 'vips': tratado.get('vips_filter_to_insert'), 'pool': tratado.get('pool_filter_to_insert') } dict_delete_vip = { 'vips_cache': tratado.get('vips_cache_filter_to_delete'), 'vips': tratado.get('vips_filter_to_delete'), 'pool_created': list() } # delete ports try: log.info('try delete ports') pools_del = self._delete_vip(dict_delete_vip) vts = virtualserver.VirtualServer(self._lb) except Exception, e: # rollback delete of ports log.info('rollback delete of ports') pools_del = self._delete_vip(dict_create_vip) log.error('error to delete ports') log.error(e) raise base_exceptions.CommandErrorException(e)
def _delete_vip(self, tratado): pools_del = list() vts = virtualserver.VirtualServer(self._lb) try: self._lb._channel.System.Session.start_transaction() if tratado.get('vips'): vps_names = [vp['name'] for vp in tratado.get('vips')] vts.delete(vps_names=vps_names) rule_l7 = [ '{}_RULE_L7'.format(vp['name']) for vp in tratado.get('vips') if vp.get('pool_l7') ] if rule_l7: rl = rule.Rule(self._lb) rl.delete(rule_names=rule_l7) # CACHE if tratado.get('vips_cache'): vps_names = [vp['name'] for vp in tratado.get('vips_cache')] vts.delete(vps_names=vps_names) except Exception, e: self._lb._channel.System.Session.rollback_transaction() log.error(e) raise e
def partial_update_vip(self, vips): tratado = util.trata_param_vip(vips) vts = virtualserver.VirtualServer(self._lb) try: log.info('try update vips') if tratado.get('vips_filter'): vts.partial_update(vips=tratado.get('vips_filter')) except Exception, e: log.info('error update vips') log.error(e) raise base_exceptions.CommandErrorException(e)
def _create_vip(self, tratado): pools_ins = list() vts = virtualserver.VirtualServer(self._lb) # vip create if tratado.get('pool'): self.__create_pool({'pools': tratado.get('pool')}) pools_ins = [ server_pool.get('id') for server_pool in tratado.get('pool') ] try: if tratado.get('vips'): vts.create(vips=tratado.get('vips')) except Exception, e: if tratado.get('pool'): self._delete_pool({'pools': tratado.get('pool')}) log.error(e) raise base_exceptions.CommandErrorException(e)
def _cleanup_vip(self, tratado): pools_del = list() vts = virtualserver.VirtualServer(self._lb) if tratado.get('vips'): for vip in tratado.get('vips'): try: vts.delete(vps_names=[vip['name']]) except: pass try: if vip.get('pool_l7'): rl = rule.Rule(self._lb) rl.delete(rule_names='{}_RULE_L7'.format(vip['name'])) except: pass # CACHE if tratado.get('vips_cache'): for vip in tratado.get('vips_cache'): vts.delete(vps_names=[vip['name']])