def remover(self, id_equipment, id_environment):
        """Remove Related Equipment with Environment from by the identifier.

        :param id_equipment: Identifier of the Equipment. Integer value and greater than zero.
        :param id_environment: Identifier of the Environment. Integer value and greater than zero.

        :return: None

        :raise InvalidParameterError:  The identifier of Environment, Equipament is null and invalid.
        :raise EquipamentoNotFoundError: Equipment not registered.
        :raise EquipamentoAmbienteNaoExisteError: Environment not registered.
        :raise VipIpError: IP-related equipment is being used for a request VIP.
        :raise XMLError: Networkapi failed to generate the XML response.
        :raise DataBaseError: Networkapi failed to access the database.
        """

        if not is_valid_int_param(id_equipment):
            raise InvalidParameterError(
                'The identifier of Equipment is invalid or was not informed.')

        if not is_valid_int_param(id_environment):
            raise InvalidParameterError(
                'The identifier of Environment is invalid or was not informed.'
            )

        url = 'equipment/' + \
            str(id_equipment) + '/environment/' + str(id_environment) + '/'

        code, xml = self.submit(None, 'DELETE', url)

        return self.response(code, xml)
    def remove(self, id_equipamento, id_egrupo):
        """Remove a associacao de um grupo de equipamento com um equipamento a partir do seu identificador.

        :param id_egrupo: Identificador do grupo de equipamento.
        :param id_equipamento: Identificador do equipamento.

        :return: None

        :raise EquipamentoNaoExisteError: Equipamento não cadastrado.
        :raise GrupoEquipamentoNaoExisteError: Grupo de equipamento não cadastrado.
        :raise InvalidParameterError: O identificador do grupo é nulo ou inválido.
        :raise DataBaseError: Falha na networkapi ao acessar o banco de dados.
        :raise XMLError: Falha na networkapi ao gerar o XML de resposta.
        """

        if not is_valid_int_param(id_egrupo):
            raise InvalidParameterError(
                'O identificador do grupo de equipamento é inválido ou não foi informado.'
            )

        if not is_valid_int_param(id_equipamento):
            raise InvalidParameterError(
                'O identificador do equipamento é inválido ou não foi informado.'
            )

        url = 'egrupo/equipamento/' + \
            str(id_equipamento) + '/egrupo/' + str(id_egrupo) + '/'

        code, xml = self.submit(None, 'GET', url)

        return self.response(code, xml)
Beispiel #3
0
    def disassociate(self, id_option_vip, id_environment_vip):
        """Remove a relationship of OptionVip with EnvironmentVip.

        :param id_option_vip: Identifier of the Option VIP. Integer value and greater than zero.
        :param id_environment_vip: Identifier of the Environment VIP. Integer value and greater than zero.

        :return: Nothing

        :raise InvalidParameterError: Option VIP/Environment VIP identifier is null and/or invalid.
        :raise OptionVipNotFoundError: Option VIP not registered.
        :raise EnvironmentVipNotFoundError: Environment VIP not registered.
        :raise OptionVipError: Option vip is not associated with the environment vip
        :raise UserNotAuthorizedError: User does not have authorization to make this association.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(id_option_vip):
            raise InvalidParameterError(
                'The identifier of Option VIP is invalid or was not informed.')

        if not is_valid_int_param(id_environment_vip):
            raise InvalidParameterError(
                'The identifier of Environment VIP is invalid or was not informed.'
            )

        url = 'optionvip/' + \
            str(id_option_vip) + '/environmentvip/' + str(id_environment_vip) + '/'

        code, xml = self.submit(None, 'DELETE', url)

        return self.response(code, xml)
    def associate_ipv6(self, id_equip, id_ipv6):
        """Associates an IPv6 to a equipament.

        :param id_equip: Identifier of the equipment. Integer value and greater than zero.
        :param id_ipv6: Identifier of the ip. Integer value and greater than zero.

        :return: Dictionary with the following structure:
            {'ip_equipamento': {'id': < id_ip_do_equipamento >}}

        :raise EquipamentoNaoExisteError: Equipment is not registered.
        :raise IpNaoExisteError: IP not registered.
        :raise IpError: IP is already associated with the equipment.
        :raise InvalidParameterError:  Identifier of the equipment and/or IP is null or invalid.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(id_equip):
            raise InvalidParameterError(
                u'The identifier of equipment is invalid or was not informed.')

        if not is_valid_int_param(id_ipv6):
            raise InvalidParameterError(
                u'The identifier of ip is invalid or was not informed.')

        url = 'ipv6/' + str(id_ipv6) + '/equipment/' + str(id_equip) + '/'

        code, xml = self.submit(None, 'PUT', url)

        return self.response(code, xml)
    def remover(self, id_equipment, id_script):
        """Remove Related Equipment with Script from by the identifier.

        :param id_equipment: Identifier of the Equipment. Integer value and greater than zero.
        :param id_script: Identifier of the Script. Integer value and greater than zero.

        :return: None

        :raise InvalidParameterError: The identifier of Equipment or Script is null and invalid.
        :raise RoteiroNaoExisteError: Script not registered.
        :raise EquipamentoNaoExisteError: Equipment not registered.
        :raise EquipamentoRoteiroNaoExisteError: Equipment is not associated with the script.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response
        """
        if not is_valid_int_param(id_equipment):
            raise InvalidParameterError(
                'The identifier of Equipment is invalid or was not informed.')

        if not is_valid_int_param(id_script):
            raise InvalidParameterError(
                'The identifier of Script is invalid or was not informed.')

        url = 'equipmentscript/' + \
            str(id_equipment) + '/' + str(id_script) + '/'

        code, xml = self.submit(None, 'DELETE', url)

        return self.response(code, xml)
    def associar_ip(self, id_equipamento, id_ip):
        """Associa um IP a um equipamento.

        :param id_equipamento: Identificador do equipamento.
        :param id_ip: Identificador do IP.

        :return: Dicionário com a seguinte estrutura:
            {'ip_equipamento': {'id': < id_ip_do_equipamento >}}

        :raise EquipamentoNaoExisteError: Equipamento não cadastrado.
        :raise IpNaoExisteError: IP não cadastrado.
        :raise IpError: IP já está associado ao equipamento.
        :raise InvalidParameterError: O identificador do equipamento e/ou do IP são nulos ou inválidos.
        :raise DataBaseError: Falha na networkapi ao acessar o banco de dados.
        :raise XMLError: Falha na networkapi ao gerar o XML de resposta.
        """

        if not is_valid_int_param(id_equipamento):
            raise InvalidParameterError(
                u'O identificador do equipamento é inválido ou não foi informado.'
            )

        if not is_valid_int_param(id_ip):
            raise InvalidParameterError(
                u'O identificador do ip é inválido ou não foi informado.')

        url = 'ip/' + str(id_ip) + '/equipamento/' + str(id_equipamento) + '/'

        code, xml = self.submit(None, 'PUT', url)

        return self.response(code, xml)
    def remover(self, id_tipo_acesso, id_equipamento):
        """Removes relationship between equipment and access type.

        :param id_equipamento: Equipment identifier.
        :param id_tipo_acesso: Access type identifier.

        :return: None

        :raise EquipamentoNaoExisteError: Equipment doesn't exist.
        :raise EquipamentoAcessoNaoExisteError: Relationship between equipment and access type doesn't exist.
        :raise InvalidParameterError: Equipment and/or access type id is/are invalid.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(id_tipo_acesso):
            raise InvalidParameterError('Access type id is invalid.')

        if not is_valid_int_param(id_equipamento):
            raise InvalidParameterError('Equipment id is invalid.')

        url = 'equipamentoacesso/' + \
            str(id_equipamento) + '/' + str(id_tipo_acesso) + '/'

        code, xml = self.submit(None, 'DELETE', url)

        return self.response(code, xml)
Beispiel #8
0
    def change_password(self, id_user, user_current_password, password):
        """Change password of User from by the identifier.

        :param id_user: Identifier of the User. Integer value and greater than zero.
        :param user_current_password: Senha atual do usuário.
        :param password: Nova Senha do usuário.

        :return: None

        :raise UsuarioNaoExisteError: User not registered.
        :raise InvalidParameterError: The identifier of User is null and invalid.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.

        """
        if not is_valid_int_param(id_user):
            raise InvalidParameterError(
                u'The identifier of User is invalid or was not informed.')

        if password is None or password == "":
            raise InvalidParameterError(
                u'A nova senha do usuário é inválida ou não foi informada')

        user_map = dict()
        user_map['user_id'] = id_user
        user_map['password'] = password

        code, xml = self.submit({'user': user_map}, 'POST',
                                'user-change-pass/')

        return self.response(code, xml)
    def inserir(self, id_user, id_group):
        """Create a relationship between User and Group.

        :param id_user: Identifier of the User. Integer value and greater than zero.
        :param id_group: Identifier of the Group. Integer value and greater than zero.

        :return: Dictionary with the following structure:

        ::
            {'user_group': {'id': < id_user_group >}}

        :raise InvalidParameterError: The identifier of User or Group is null and invalid.
        :raise GrupoUsuarioNaoExisteError: UserGroup not registered.
        :raise UsuarioNaoExisteError: User not registered.
        :raise UsuarioGrupoError: User already registered in the group.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """
        if not is_valid_int_param(id_user):
            raise InvalidParameterError(
                u'The identifier of User is invalid or was not informed.')

        if not is_valid_int_param(id_group):
            raise InvalidParameterError(
                u'The identifier of Group is invalid or was not informed.')

        url = 'usergroup/user/' + \
            str(id_user) + '/ugroup/' + str(id_group) + '/associate/'

        code, xml = self.submit(None, 'PUT', url)
    def remover(self, id_user, id_group):
        """Removes relationship between User and Group.

        :param id_user: Identifier of the User. Integer value and greater than zero.
        :param id_group: Identifier of the Group. Integer value and greater than zero.

        :return: None

        :raise UsuarioGrupoNaoExisteError: Association between user and group not registered.
        :raise GrupoUsuarioNaoExisteError: UserGroup not registered.
        :raise UsuarioNaoExisteError: User not registered.
        :raise UsuarioGrupoError: User already registered in the group.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """
        if not is_valid_int_param(id_user):
            raise InvalidParameterError(
                u'The identifier of User is invalid or was not informed.')

        if not is_valid_int_param(id_group):
            raise InvalidParameterError(
                u'The identifier of Group is invalid or was not informed.')

        url = 'usergroup/user/' + \
            str(id_user) + '/ugroup/' + str(id_group) + '/dissociate/'

        code, xml = self.submit(None, 'DELETE', url)

        return self.response(code, xml)
    def edit_ipv6(self, ip6, descricao, id_ip):
        """
        Edit a IP6

        :param ip6: An IP6 available to save in format xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx.
        :param descricao: IP description.
        :param id_ip: Ipv6 identifier. Integer value and greater than zero.

        :return: None
        """

        if not is_valid_int_param(id_ip):
            raise InvalidParameterError(
                u'Ipv6 identifier is invalid or was not informed.')

        if ip6 is None or ip6 == "":
            raise InvalidParameterError(u'IP6 is invalid or was not informed.')

        ip_map = dict()
        ip_map['descricao'] = descricao
        ip_map['ip6'] = ip6
        ip_map['id_ip'] = id_ip

        url = "ipv6/edit/"

        code, xml = self.submit({'ip_map': ip_map}, 'POST', url)

        return self.response(code, xml)
    def remover_grupo(self, id_equipamento, id_grupo):
        """Remove a associação de um equipamento com um grupo de equipamento.

        :param id_equipamento: Identificador do equipamento.
        :param id_grupo: Identificador do grupo de equipamento.

        :return: None

        :raise EquipamentoGrupoNaoExisteError: Associação entre grupo e equipamento não cadastrada.
        :raise EquipamentoNaoExisteError: Equipamento não cadastrado.
        :raise EquipmentDontRemoveError: Failure to remove an association between an equipment and a group because the group is related only to a group.
        :raise InvalidParameterError: O identificador do equipamento e/ou do grupo são nulos ou inválidos.
        :raise DataBaseError: Falha na networkapi ao acessar o banco de dados.
        :raise XMLError: Falha na networkapi ao gerar o XML de resposta.
        """

        if not is_valid_int_param(id_equipamento):
            raise InvalidParameterError(
                u'O identificador do equipamento é inválido ou não foi informado.'
            )

        if not is_valid_int_param(id_grupo):
            raise InvalidParameterError(
                u'O identificador do grupo é inválido ou não foi informado.')

        url = 'equipamentogrupo/equipamento/' + \
            str(id_equipamento) + '/egrupo/' + str(id_grupo) + '/'

        code, xml = self.submit(None, 'DELETE', url)

        return self.response(code, xml)
    def dissociate(self, id_filter, id_eq_type):
        """Removes relationship between Filter and TipoEquipamento.

        :param id_filter: Identifier of Filter. Integer value and greater than zero.
        :param id_eq_type: Identifier of TipoEquipamento. Integer value, greater than zero.

        :return: None

        :raise FilterNotFoundError: Filter not registered.
        :raise TipoEquipamentoNotFoundError: TipoEquipamento not registered.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(id_filter):
            raise InvalidParameterError(
                u'The identifier of Filter is invalid or was not informed.')

        if not is_valid_int_param(id_eq_type):
            raise InvalidParameterError(
                u'The identifier of TipoEquipamento is invalid or was not informed.'
            )

        url = 'filter/' + \
            str(id_filter) + '/dissociate/' + str(id_eq_type) + '/'

        code, xml = self.submit(None, 'PUT', url)

        return self.response(code, xml)
    def buscar_por_ip_ambiente(self, ip, id_environment):
        """Get IP with an associated environment.

        :param ip: IP address in the format x1.x2.x3.x4.
        :param id_environment: Identifier of the environment. Integer value and greater than zero.

        :return: Dictionary with the following structure:

        ::

            {'ip': {'id': < id >,
            'id_vlan': < id_vlan >,
            'oct4': < oct4 >,
            'oct3': < oct3 >,
            'oct2': < oct2 >,
            'oct1': < oct1 >,
            'descricao': < descricao > }}

        :raise IpNaoExisteError: IP is not registered or not associated with environment.
        :raise InvalidParameterError: The environment identifier and/or IP is/are null or invalid.
        :raise DataBaseError: Networkapi failed to access the database.
        """

        if not is_valid_int_param(id_environment):
            raise InvalidParameterError(
                u'Environment identifier is invalid or was not informed.')

        if not is_valid_ip(ip):
            raise InvalidParameterError(u'IP is invalid or was not informed.')

        url = 'ip/' + str(ip) + '/ambiente/' + str(id_environment) + '/'

        code, xml = self.submit(None, 'GET', url)

        return self.response(code, xml)
    def associate(self, et_id, id_filter):
        """Create a relationship between Filter and TipoEquipamento.

        :param et_id: Identifier of TipoEquipamento. Integer value and greater than zero.
        :param id_filter: Identifier of Filter. Integer value and greater than zero.

        :return: Following dictionary:

        ::

            {'equiptype_filter_xref': {'id': < id_equiptype_filter_xref >} }

        :raise InvalidParameterError: TipoEquipamento/Filter identifier is null and/or invalid.
        :raise TipoEquipamentoNaoExisteError: TipoEquipamento not registered.
        :raise FilterNotFoundError: Filter not registered.
        :raise FilterEqTypeAssociationError: TipoEquipamento and Filter already associated.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(et_id):
            raise InvalidParameterError(
                u'The identifier of TipoEquipamento is invalid or was not informed.'
            )

        if not is_valid_int_param(id_filter):
            raise InvalidParameterError(
                u'The identifier of Filter is invalid or was not informed.')

        url = 'filter/' + str(id_filter) + '/equiptype/' + str(et_id) + '/'

        code, xml = self.submit(None, 'PUT', url)

        return self.response(code, xml)
    def remove_connection(self, id_interface, back_or_front):
        """
        Remove a connection between two interfaces

        :param id_interface: One side of relation
        :param back_or_front: This side of relation is back(0) or front(1)

        :return: None

        :raise InterfaceInvalidBackFrontError: Front or Back of interfaces not match to remove connection
        :raise InvalidParameterError: Interface id or back or front indicator is none or invalid.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        msg_err = 'Parameter %s is invalid. Value: %s.'

        if not is_valid_0_1(back_or_front):
            raise InvalidParameterError(msg_err %
                                        ("back_or_front", back_or_front))

        if not is_valid_int_param(id_interface):
            raise InvalidParameterError(msg_err %
                                        ("id_interface", id_interface))

        url = "interface/%s/%s/" % (str(id_interface), str(back_or_front))

        code, xml = self.submit(None, 'DELETE', url)

        return self.response(code, xml)
Beispiel #17
0
    def disassociate_environment_option_pool(self, environment_option_id):
        """Remove a relationship of optionpool with Environment.

        :param id_option_pool: Identifier of the Option Pool. Integer value and greater than zero.
        :param id_environment: Identifier of the Environment Pool. Integer value and greater than zero.

        :return: { 'id': < environment_option_id> }

        :raise InvalidParameterError: Option Pool/Environment Pool identifier is null and/or invalid.
        :raise optionpoolNotFoundError: Option Pool not registered.
        :raise EnvironmentVipNotFoundError: Environment VIP not registered.
        :raise optionpoolError: Option pool is not associated with the environment pool
        :raise UserNotAuthorizedError: User does not have authorization to make this association.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(environment_option_id):
            raise InvalidParameterError(
                u'The identifier of Option Pool is invalid or was not informed.'
            )

        if not is_valid_int_param(environment_option_id):
            raise InvalidParameterError(
                u'The identifier of Environment Pool is invalid or was not informed.'
            )

        url = 'api/pools/environment_options/' + str(
            environment_option_id) + '/'

        return self.delete(url)
    def remove_ipv6(self, id_equip, id_ipv6):
        """Remove an IPv6 to a equipament.

        :param id_equip: Identifier of the equipment. Integer value and greater than zero.
        :param id_ipv6: Identifier of the ip. Integer value and greater than zero.

        :return: None

        :raise EquipamentoNaoExisteError: Equipment is not registered.
        :raise IpNaoExisteError: IP not registered.
        :raise IpError: Dont  IP is already associated with the equipment.
        :raise InvalidParameterError:  Identifier of the equipment and/or IP is null or invalid.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(id_equip):
            raise InvalidParameterError(
                u'The identifier of equipment is invalid or was not informed.')

        if not is_valid_int_param(id_ipv6):
            raise InvalidParameterError(
                u'The identifier of ip is invalid or was not informed.')

        url = 'ipv6/' + str(id_ipv6) + '/equipment/' + \
            str(id_equip) + '/remove/'

        code, xml = self.submit(None, 'DELETE', url)

        return self.response(code, xml)
    def remover_ip(self, id_equipamento, id_ip):
        """Removes association of IP and Equipment.
        If IP has no other association with equipments, IP is also removed.

        :param id_equipamento: Equipment identifier
        :param id_ip: IP identifier.

        :return: None

        :raise VipIpError: Ip can't be removed because there is a created Vip Request.
        :raise IpEquipCantDissociateFromVip: Equipment is the last balancer for created Vip Request.
        :raise IpError: IP not associated with equipment.
        :raise InvalidParameterError: Equipment or IP identifier is none or invalid.
        :raise EquipamentoNaoExisteError: Equipment doesn't exist.
        :raise DataBaseError: Networkapi failed to access database.
        :raise XMLError: Networkapi failed to build response XML.
        """

        if not is_valid_int_param(id_equipamento):
            raise InvalidParameterError(
                u'O identificador do equipamento é inválido ou não foi informado.'
            )

        if not is_valid_int_param(id_ip):
            raise InvalidParameterError(
                u'O identificador do ip é inválido ou não foi informado.')

        url = 'ip/' + str(id_ip) + '/equipamento/' + str(id_equipamento) + '/'

        code, xml = self.submit(None, 'DELETE', url)

        return self.response(code, xml)
    def insert_vlan(self, environment_id, name, number, description, acl_file,
                    acl_file_v6, network_ipv4, network_ipv6):
        """Create new VLAN

        :param environment_id: ID for Environment.
        :param name: The name of VLAN.
        :param description: Some description to VLAN.
        :param number: Number of Vlan
        :param acl_file: Acl IPv4 File name to VLAN.
        :param acl_file_v6: Acl IPv6 File name to VLAN.
        :param network_ipv4: responsible for generating a network attribute ipv4 automatically.
        :param network_ipv6: responsible for generating a network attribute ipv6 automatically.

        :return: Following dictionary:

        ::

          {'vlan': {'id': < id_vlan >,
          'nome': < nome_vlan >,
          'num_vlan': < num_vlan >,
          'id_ambiente': < id_ambiente >,
          'descricao': < descricao >,
          'acl_file_name': < acl_file_name >,
          'acl_valida': < acl_valida >,
          'ativada': < ativada >
          'acl_file_name_v6': < acl_file_name_v6 >,
          'acl_valida_v6': < acl_valida_v6 >, } }

        :raise VlanError: VLAN name already exists, VLAN name already exists, DC division of the environment invalid or does not exist VLAN number available.
        :raise VlanNaoExisteError: VLAN not found.
        :raise AmbienteNaoExisteError: Environment not registered.
        :raise InvalidParameterError: Name of Vlan and/or the identifier of the Environment is null or invalid.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(environment_id):
            raise InvalidParameterError(u'Environment id is none or invalid.')

        if not is_valid_int_param(number):
            raise InvalidParameterError(u'Vlan number is none or invalid')

        vlan_map = dict()
        vlan_map['environment_id'] = environment_id
        vlan_map['name'] = name
        vlan_map['description'] = description
        vlan_map['acl_file'] = acl_file
        vlan_map['acl_file_v6'] = acl_file_v6
        vlan_map['number'] = number
        vlan_map['network_ipv4'] = network_ipv4
        vlan_map['network_ipv6'] = network_ipv6

        code, xml = self.submit({'vlan': vlan_map}, 'POST', 'vlan/insert/')

        return self.response(code, xml)
    def edit_vlan(
            self,
            environment_id,
            name,
            number,
            description,
            acl_file,
            acl_file_v6,
            id_vlan):
        """Edit a VLAN

        :param id_vlan: ID for Vlan
        :param environment_id: ID for Environment.
        :param name: The name of VLAN.
        :param description: Some description to VLAN.
        :param number: Number of Vlan
        :param acl_file: Acl IPv4 File name to VLAN.
        :param acl_file_v6: Acl IPv6 File name to VLAN.

        :return: None

        :raise VlanError: VLAN name already exists, DC division of the environment invalid or there is no VLAN number available.
        :raise VlanNaoExisteError: VLAN not found.
        :raise AmbienteNaoExisteError: Environment not registered.
        :raise InvalidParameterError: Name of Vlan and/or the identifier of the Environment is null or invalid.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(id_vlan):
            raise InvalidParameterError(
                u'Vlan id is invalid or was not informed.')

        if not is_valid_int_param(environment_id):
            raise InvalidParameterError(u'Environment id is none or invalid.')

        if not is_valid_int_param(number):
            raise InvalidParameterError(u'Vlan number is none or invalid')

        vlan_map = dict()
        vlan_map['vlan_id'] = id_vlan
        vlan_map['environment_id'] = environment_id
        vlan_map['name'] = name
        vlan_map['description'] = description
        vlan_map['acl_file'] = acl_file
        vlan_map['acl_file_v6'] = acl_file_v6
        vlan_map['number'] = number

        code, xml = self.submit({'vlan': vlan_map}, 'POST', 'vlan/edit/')

        return self.response(code, xml)
    def save_ipv6(self, ip6, id_equip, descricao, id_net):
        """
        Save an IP6 and associate with equipment

        :param ip6: An IP6 available to save in format xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx.
        :param id_equip: Equipment identifier. Integer value and greater than zero.
        :param descricao: IPv6 description.
        :param id_net: Network identifier. Integer value and greater than zero.

        :return: Dictionary with the following structure:

        ::

            {'ipv6': {'id': < id >,
            'block1': <block1>,
            'block2': <block2>,
            'block3': <block3>,
            'block4': <block4>,
            'block5': <block5>,
            'block6': <block6>,
            'block7': <block7>,
            'block8': <block8>,
            'descricao': < description >,
            'equipamento': [ { all name equipamentos related } ], }}
        """
        if not is_valid_int_param(id_net):
            raise InvalidParameterError(
                u'Network identifier is invalid or was not informed.')

        if not is_valid_int_param(id_equip):
            raise InvalidParameterError(
                u'Equipment identifier is invalid or was not informed.')

        if ip6 is None or ip6 == "":
            raise InvalidParameterError(
                u'IPv6 is invalid or was not informed.')

        ip_map = dict()
        ip_map['id_net'] = id_net
        ip_map['descricao'] = descricao
        ip_map['ip6'] = ip6
        ip_map['id_equip'] = id_equip

        url = "ipv6/save/"

        code, xml = self.submit({'ip_map': ip_map}, 'POST', url)

        return self.response(code, xml)
    def search(self, id_perm):
        """Search Administrative Permission from by the identifier.

        :param id_perm: Identifier of the Administrative Permission. Integer value and greater than zero.

        :return: Following dictionary:

        ::

            {'perm': {'ugrupo': < ugrupo_id >,
            'permission': < permission_id >, 'id': < id >,
            'escrita': < escrita >, 'leitura': < leitura >}}

        :raise InvalidParameterError: Group User identifier is null and invalid.
        :raise PermissaoAdministrativaNaoExisteError: Administrative Permission not registered.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(id_perm):
            raise InvalidParameterError(
                'The identifier of Administrative Permission is invalid or was not informed.'
            )

        url = 'aperms/get/' + str(id_perm) + '/'

        code, xml = self.submit(None, 'GET', url)

        return self.response(code, xml)
    def list_by_group(self, id_ugroup):
        """Search Administrative Permission by Group User by identifier.

        :param id_ugroup: Identifier of the Group User. Integer value and greater than zero.

        :return: Dictionary with the following structure:

        ::

            {'perms': [{'ugrupo': < ugrupo_id >, 'permission':  { 'function' < function >, 'id': < id > },
            'id': < id >, 'escrita': < escrita >,
            'leitura': < leitura >}, ... ] }

        :raise InvalidParameterError: Group User is null and invalid.
        :raise UGrupoNotFoundError: Group User not registered.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if id_ugroup is None:
            raise InvalidParameterError(
                'The identifier of Group User is invalid or was not informed.')

        url = 'aperms/group/' + str(id_ugroup) + '/'

        code, xml = self.submit(None, 'GET', url)

        return self.response(code, xml)
Beispiel #25
0
    def alterar(self, id_groupl3, name):
        """Change Group L3 from by the identifier.

        :param id_groupl3: Identifier of the Group L3. Integer value and greater than zero.
        :param name: Group L3 name. String with a minimum 2 and maximum of 80 characters

        :return: None

        :raise InvalidParameterError: The identifier of Group L3 or name is null and invalid.
        :raise NomeGrupoL3DuplicadoError: There is already a registered Group L3 with the value of name.
        :raise GrupoL3NaoExisteError: Group L3 not registered.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(id_groupl3):
            raise InvalidParameterError(
                u'The identifier of Group L3 is invalid or was not informed.')

        url = 'groupl3/' + str(id_groupl3) + '/'

        group_l3_map = dict()
        group_l3_map['name'] = name

        code, xml = self.submit({'groupl3': group_l3_map}, 'PUT', url)

        return self.response(code, xml)
    def listar_healthcheck_expect(self, id_ambiente):
        """Lista os healthcheck_expect´s de um ambiente.

        :param id_ambiente: Identificador do ambiente.

        :return: Dicionário com a seguinte estrutura:

        ::

            {'healthcheck_expect': [{'id': < id_healthcheck_expect >,
             'expect_string': < expect_string >,
             'match_list': < match_list >,
             'id_ambiente': < id_ambiente >},
             ... demais healthcheck_expects ...]}

        :raise InvalidParameterError: O identificador do ambiente é nulo ou inválido.
        :raise DataBaseError: Falha na networkapi ao acessar o banco de dados.
        :raise XMLError: Falha na networkapi ao gerar o XML de resposta.
        """

        if not is_valid_int_param(id_ambiente):
            raise InvalidParameterError(
                'O identificador do ambiente é inválido ou não foi informado.')

        url = 'healthcheckexpect/ambiente/' + str(id_ambiente) + '/'

        code, xml = self.submit(None, 'GET', url)

        key = 'healthcheck_expect'
        return get_list_map(self.response(code, xml, [key]), key)
    def listar_por_equip(self, equip_id):
        """Lista todos os ambientes por equipamento especifico.

        :return: Dicionário com a seguinte estrutura:

        ::

            {'ambiente': {'id': < id_ambiente >,
            'link': < link >,
            'id_divisao': < id_divisao >,
            'nome_divisao': < nome_divisao >,
            'id_ambiente_logico': < id_ambiente_logico >,
            'nome_ambiente_logico': < nome_ambiente_logico >,
            'id_grupo_l3': < id_grupo_l3 >,
            'nome_grupo_l3': < nome_grupo_l3 >,
            'id_filter': < id_filter >,
            'filter_name': < filter_name >,
            'ambiente_rede': < ambiente_rede >}}

        :raise DataBaseError: Falha na networkapi ao acessar o banco de dados.
        :raise XMLError: Falha na networkapi ao gerar o XML de resposta.
        """

        if equip_id is None:
            raise InvalidParameterError(
                'O id do equipamento não foi informado.')

        url = 'ambiente/equip/' + str(equip_id) + '/'

        code, xml = self.submit(None, 'GET', url)

        return self.response(code, xml)
    def buscar_healthcheck_por_id(self, id_healthcheck):
        """Get HealthCheck by id.

        :param id_healthcheck: HealthCheck ID.

        :return: Following dictionary:

        ::

            {'healthcheck_expect': {'match_list': < match_list >,
             'expect_string': < expect_string >,
             'id': < id >,
             'ambiente': < ambiente >}}

        :raise HealthCheckNaoExisteError:  HealthCheck not registered.
        :raise InvalidParameterError: HealthCheck identifier is null and invalid.
        :raise DataBaseError: Can't connect to networkapi database.
        :raise XMLError: Failed to generate the XML response.
        """
        if not is_valid_int_param(id_healthcheck):
            raise InvalidParameterError(
                'O identificador do healthcheck é inválido ou não foi informado.'
            )

        url = 'healthcheckexpect/get/' + str(id_healthcheck) + '/'

        code, xml = self.submit(None, 'GET', url)

        return self.response(code, xml)
    def remove(self, id_vlan):
        """Remove a VLAN by your primary key.
        Execute script to remove VLAN

        :param id_vlan: ID for VLAN.

        :return: Following dictionary:

        ::

          {‘sucesso’: {‘codigo’: < codigo >,
          ‘descricao’: {'stdout':< stdout >, 'stderr':< stderr >}}}

        :raise InvalidParameterError: Identifier of the VLAN is invalid.
        :raise VlanNaoExisteError: VLAN not found.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        """

        if not is_valid_int_param(id_vlan):
            raise InvalidParameterError(
                u'Parameter id_vlan is invalid. Value: ' +
                id_vlan)

        url = 'vlan/' + str(id_vlan) + '/remove/'

        code, xml = self.submit(None, 'DELETE', url)

        return self.response(code, xml)
    def criar(self, id_vlan):
        """Create a VLAN with script 'navlan'.

        :param id_vlan: VLAN identifier.

        :return: Following dictionary:

        ::

          {‘sucesso’: {‘codigo’: < codigo >,
          ‘descricao’: {'stdout':< stdout >, 'stderr':< stderr >}}}

        :raise VlanNaoExisteError: VLAN does not exist.
        :raise EquipamentoNaoExisteError: Equipment in list does not exist.
        :raise VlanError: VLAN is active.
        :raise InvalidParameterError: VLAN identifier is none or invalid.
        :raise InvalidParameterError: Equipment list is none or empty.
        :raise DataBaseError: Networkapi failed to access the database.
        :raise XMLError: Networkapi failed to generate the XML response.
        :raise ScriptError: Failed to run the script.
        """

        if not is_valid_int_param(id_vlan):
            raise InvalidParameterError(
                u'Vlan id is invalid or was not informed.')

        url = 'vlan/' + str(id_vlan) + '/criar/'

        code, xml = self.submit({'vlan': None}, 'PUT', url)

        return self.response(code, xml)