def _reals_can_associate_server_pool_by_environment_vip_on_request_vip(server_pool, server_pool_member_list, environment_vip): try: environment_list_related = EnvironmentEnvironmentVip.get_environment_list_by_environment_vip( environment_vip) ipv4_list, ipv6_list = [], [] for server_pool_member in server_pool_member_list: if server_pool_member.ip: ipv4_list.append(server_pool_member.ip) else: ipv6_list.append(server_pool_member.ipv6) for ipv4 in ipv4_list: environment = Ambiente.objects.filter( vlan__networkipv4__ip=ipv4).uniqueResult() if environment not in environment_list_related: raise api_exceptions.EnvironmentEnvironmentVipNotBoundedException( error_messages.get(396) % ( environment.name, ipv4.ip_formated, environment_vip.name) ) for ipv6 in ipv6_list: environment = Ambiente.objects.filter( vlan__networkipv6__ipv6=ipv6).uniqueResult() if environment not in environment_list_related: raise api_exceptions.EnvironmentEnvironmentVipNotBoundedException( error_messages.get(396) % ( server_pool.environment.name, ipv6.ip_formated, environment_vip.name) ) except Exception, error: log.error(error) raise error
def _reals_can_associate_server_pool_by_environment_vip_on_request_vip(server_pool, server_pool_member_list, environment_vip): try: environment_list_related = EnvironmentEnvironmentVip.get_environment_list_by_environment_vip(environment_vip) ipv4_list, ipv6_list = [], [] for server_pool_member in server_pool_member_list: if server_pool_member.ip: ipv4_list.append(server_pool_member.ip) else: ipv6_list.append(server_pool_member.ipv6) for ipv4 in ipv4_list: environment = Ambiente.objects.filter(vlan__networkipv4__ip=ipv4).uniqueResult() if environment not in environment_list_related: raise api_exceptions.EnvironmentEnvironmentVipNotBoundedException( error_messages.get(396) % (environment.name, ipv4.ip_formated, environment_vip.name) ) for ipv6 in ipv6_list: environment = Ambiente.objects.filter(vlan__networkipv6__ipv6=ipv6).uniqueResult() if environment not in environment_list_related: raise api_exceptions.EnvironmentEnvironmentVipNotBoundedException( error_messages.get(396) % (server_pool.environment.name, ipv6.ip_formated, environment_vip.name) ) except Exception, error: log.error(error) raise error
def deactivate_network(self, user, id): id_network, network_type = self.get_id_and_net_type(id) if not is_valid_int_greater_zero_param(id_network): self.log.error( u'The id network parameter is invalid. Value: %s.', id_network) raise InvalidValueError(None, 'id_network', id_network) if not is_valid_version_ip(network_type, IP_VERSION): self.log.error( u'The type network parameter is invalid value: %s.', network_type) raise InvalidValueError(None, 'network_type', network_type) if network_type == self.NETWORK_TYPE_V4: net = NetworkIPv4.get_by_pk(id_network) if not self.is_active_netwok(net): raise NetworkInactiveError( message=error_messages.get(self.CODE_MESSAGE_INACTIVE_NETWORK)) command = NETWORKIPV4_REMOVE % int(id_network) code, stdout, stderr = exec_script(command) if code == 0: net = NetworkIPv4.get_by_pk(id_network) net.deactivate(user) else: net = NetworkIPv6.get_by_pk(id_network) if not self.is_active_netwok(net): raise NetworkInactiveError( message=error_messages.get(self.CODE_MESSAGE_INACTIVE_NETWORK)) command = NETWORKIPV6_REMOVE % int(id_network) code, stdout, stderr = exec_script(command) if code == 0: net.deactivate(user) return code, stdout, stderr
def valid_to_save_reals_v2(pools): """ Valid values of pool member """ for pool in pools: ids = [p['id'] for p in pool['server_pool_members'] if p['id']] db_members = ServerPoolMember.objects.filter(id__in=ids) db_members_id = [str(s.id) for s in db_members] # verify if member is invalid for member in pool['server_pool_members']: if member['id']: if str(member['id']) not in db_members_id: raise exceptions.InvalidRealPoolException() # verify if port is invalid invalid_ports_real = [member['port_real'] for member in pool['server_pool_members'] if int(member['port_real']) > 65535 or int(member['port_real']) < 1] # verify if priority is invalid invalid_priority = [member['priority'] for member in pool['server_pool_members'] if int(member['priority']) > 4294967295 or int(member['priority']) < 0] # verify if pool member is duplicate ips_ports = [(member['port_real'], member['ip']['id'] if member['ip'] else member['ipv6']['id']) for member in pool['server_pool_members']] environment_vip_list = EnvironmentVip.get_environment_vips_by_environment_id(pool['server_pool']['environment']['id']) environment_vip_list_name = ', '.join([envvip.name for envvip in environment_vip_list]) environment_list_related = EnvironmentEnvironmentVip.get_environment_list_by_environment_vip_list(environment_vip_list) for members in pool['server_pool_members']: if members['ip']: environment = Ambiente.objects.filter(vlan__networkipv4__ip=members['ip']['id']).uniqueResult() if environment not in environment_list_related: raise api_exceptions.EnvironmentEnvironmentVipNotBoundedException( error_messages.get(396) % (environment.name, members['ip']['ip_formated'], environment_vip_list_name) ) for members in pool['server_pool_members']: if members['ipv6']: environment = Ambiente.objects.filter(vlan__networkipv6__ipv6=members['ipv6']['id']).uniqueResult() if environment not in environment_list_related: raise api_exceptions.EnvironmentEnvironmentVipNotBoundedException( error_messages.get(396) % (environment.name, members['ipv6']['ip_formated'], environment_vip_list_name) ) if invalid_ports_real: raise exceptions.InvalidRealPoolException( 'O nĂºmero da porta deve estar entre 1 e 65535.') if invalid_priority: raise exceptions.InvalidRealPoolException( 'O valor da Prioridade deve estar entre 0 e 4294967295.') if len(ips_ports) != len(set(ips_ports)): raise exceptions.InvalidRealPoolException( 'Ips com portas iguais.') # if len(id_equips) != len(id_pool_member): # raise exceptions.InvalidRealPoolException( # 'Quantidade de portas e equipamento difere.') # load data in variables for compare db with json pls = ServerPool.objects.filter(id__in=[pool['server_pool']['id'] for pool in pools]) ps = {} for p in pools: ps[str(p['server_pool']['id'])] = p sp = {} for p in pls: sp[str(p.id)] = p # q_filters = list() # for members in pool['server_pool_members']: # if members['id']: # q_filters.append({ # 'port_real': members['port_real'], # 'id': members['id'] # }) # if len(q_filters)>0: # members_par = ServerPoolMember.objects.filter( # reduce(lambda x, y: x | y, [Q(**q_filter) for q_filter in q_filters])) # else: # members_par = list() # members_all = ServerPoolMember.objects.filter(server_pool__id=p.id) # if len(members_par) != len(members_all) and p.pool_created: # raise exceptions.PoolMemberChange(p.identifier) # return error when change names in pool created change_name = [sp[p].identifier for idx, p in enumerate(ps) if sp[p].identifier != ps[str(p)]['server_pool']['identifier'] and sp[p].pool_created] if len(change_name) > 0: raise exceptions.PoolNameChange(','.join(change_name)) # return error when change environments in pool created change_env = [sp[p].identifier for idx, p in enumerate(ps) if str(sp[p].environment.id) != str(ps[str(p)]['server_pool']['environment']['id']) and sp[p].pool_created] change_env_all = [sp[p].id for idx, p in enumerate(ps) if str(sp[p].environment.id) != str(ps[str(p)]['server_pool']['environment']['id'])] change_real = ServerPoolMember.objects.filter(server_pool_id__in=change_env_all) if len(change_env) > 0 or len(change_real) > 0: raise exceptions.PoolEnvironmentChange(','.join(change_env)) return ps, sp