class DocumentRESTTest(unittest.TestCase):
    """
    Test base metaclasses 
    """

    def setUp(self):
        """
        Load data from previous tests and setup test data
        :return:
        """
        #lbjson_test.TestJSON.setUp(self)

        rest_url = 'http://api.brlight.net/api'
        self.base_rest = BaseREST(rest_url)
        self.base = self.base_rest.get('expedido')
        self.doc_rest = DocumentREST(rest_url, self.base)

    def test_get_doc(self):
        document = self.doc_rest.get(1)

        document_type = self.base.metaclass()
        assert isinstance(document, document_type)

        with open('/tmp/document.json', 'w+') as f:
            f.write(document2json(self.base, document))

    def test_get_doc_colletion(self):

        collection = self.doc_rest.get_collection()
        assert isinstance(collection, Collection)
        assert isinstance(collection.results[0], self.base.metaclass())
        print (collection.results[0]._metadata)
        from liblightbase.lbutils.conv import document2json
        print(document2json(self.base, collection.results[0]))
        raise Exception('efewfv')
예제 #2
0
class UserBase():
    """
    Classe para a base de usuários
    """
    def __init__(self, rest_url=None):
        """
        Método construtor
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                base=self.lbbase, response_object=False)

    @property
    def lbbase(self):
        """
        LB Base de Users
        """
        nome = Field(**dict(
            name='nome',
            description='Nome do Usuário',
            alias='nome',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        matricula = Field(**dict(
            name='matricula',
            alias='matricula',
            description='Matricula do Usuário',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        email = Field(**dict(
            name='email',
            alias='email',
            description='E-mail do Usuário',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        telefone = Field(**dict(
            name='telefone',
            alias='telefone',
            description='Telefone do Usuário',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        orgao = Field(**dict(
            name='orgao',
            alias='orgao',
            description='Orgão do Usuário',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))


        cargo = Field(**dict(
            name='cargo',
            alias='cargo',
            description='Cargo do Usuário',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        setor = Field(**dict(
            name='setor',
            alias='setor',
            description='Setor do Usuário',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        permissao = Field(**dict(
            name='permissao',
            alias='permissao',
            description='Permissão do Usuário',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))
        
        senha = Field(**dict(
                    name='senha',
                    alias='senha',
                    description='Senha do Usuário',
                    datatype='Text',
                    indices=['Textual'],
                    multivalued=False,
                    required=True
        ))
        favoritos = Field(**dict(
                    name='favoritos',
                    alias='favoritos',
                    description='Favoritos do Usuário',
                    datatype='Text',
                    indices=['Textual'],
                    multivalued=True,
                    required=False
        ))
        home = Field(**dict(
                    name='home',
                    alias='home',
                    description='Home do Usuário',
                    datatype='Text',
                    indices=['Textual'],
                    multivalued=True,
                    required=False
        ))
        itens = Field(**dict(
                    name='itens',
                    alias='itens',
                    description='Itens do Usuário',
                    datatype='Text',
                    indices=['Textual'],
                    multivalued=True,
                    required=False
        ))

        url_hash = Field(**dict(
                    name='url_hash',
                    alias='url_hash',
                    description='hash que sera usado para para criar a url',
                    datatype='Text',
                    indices=['Textual'],
                    multivalued=True,
                    required=False
        ))

        nm_user = Field(**dict(
                    name='nm_user',
                    alias='nm_user',
                    description='Nome do usuario',
                    datatype='Text',
                    indices=['Textual'],
                    multivalued=True,
                    required=False
        ))

        HashUrl_content = Content()
        HashUrl_content.append(nm_user)
        HashUrl_content.append(url_hash)

        HashUrl_metadata = GroupMetadata(
            name='HashUrl',
            alias='HashUrl',
            description='HashUrl',
            multivalued=False
        )

        HashUrl = Group(
            metadata = HashUrl_metadata,
            content = HashUrl_content
        )

        base_metadata = BaseMetadata(
            name='users',
        )

        content_list = Content()
        content_list.append(nome)
        content_list.append(matricula)
        content_list.append(email)
        content_list.append(telefone)
        content_list.append(orgao)
        content_list.append(cargo)
        content_list.append(setor)
        content_list.append(permissao)
        content_list.append(senha)
        content_list.append(favoritos)
        content_list.append(home)
        content_list.append(itens)
        content_list.append(HashUrl)

        lbbase = Base(
            metadata=base_metadata,
            content=content_list
        )

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()
    
    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False
예제 #3
0
class DescriptionsBase(object):
    """
    Classe para a base de atividades
    """

    def __init__(self, rest_url=None):
        """
        Método construtor da base de atividades
        :param rest_url: URL do Rest
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                base=self.lbbase, response_object=False)
        here = os.path.abspath(os.path.dirname(__file__))
        data_dir = os.path.join(here, '../data/')
        self.data_dir = data_dir

    @property
    def lbbase(self):
        """
        Base no LB
        :return: LB Base object
        """
        win32_physicalmemory_memorytype_list = Content()

        win32_physicalmemory_memorytype_key = Field(**dict(
            name='win32_physicalmemory_memorytype_key',
            description='Chave do atributo MemoryType',
            alias='win32_physicalmemory_memorytype_key',
            datatype='Integer',
            indices=['Ordenado'],
            multivalued=False,
            required=False
        ))

        win32_physicalmemory_memorytype_list.append(win32_physicalmemory_memorytype_key)

        win32_physicalmemory_memorytype_value = Field(**dict(
            name='win32_physicalmemory_memorytype_value',
            description='Valro do atributo MemoryType',
            alias='win32_physicalmemory_memorytype_value',
            datatype='Text',
            indices=['Textual', 'Ordenado'],
            multivalued=False,
            required=False
        ))

        win32_physicalmemory_memorytype_list.append(win32_physicalmemory_memorytype_value)

        win32_physicalmemory_memorytype_metadata = GroupMetadata(**dict(
            name='win32_physicalmemory_memorytype',
            alias='win32_physicalmemory_memorytype',
            description='Descrição do campo win32_physicalmemory_memorytype',
            multivalued=True
        ))

        win32_physicalmemory_memorytype = Group(
            metadata=win32_physicalmemory_memorytype_metadata,
            content=win32_physicalmemory_memorytype_list
        )

        win32_processor_family_list = Content()

        win32_processor_family_key = Field(**dict(
            name='win32_processor_family_key',
            description='Chave do atributo MemoryType',
            alias='win32_processor_family_key',
            datatype='Integer',
            indices=['Ordenado'],
            multivalued=False,
            required=False
        ))

        win32_processor_family_list.append(win32_processor_family_key)

        win32_processor_family_value = Field(**dict(
            name='win32_processor_family_value',
            description='Valor do atributo Family',
            alias='win32_processor_family_value',
            datatype='Text',
            indices=['Textual', 'Ordenado'],
            multivalued=False,
            required=False
        ))

        win32_processor_family_list.append(win32_processor_family_value)

        win32_processor_family_metadata = GroupMetadata(**dict(
            name='win32_processor_family',
            alias='win32_processor_family',
            description='Descrição do campo win32_processor_family',
            multivalued=True
        ))

        win32_processor_family = Group(
            metadata=win32_processor_family_metadata,
            content=win32_processor_family_list
        )

        content_list = Content()
        content_list.append(win32_physicalmemory_memorytype)
        content_list.append(win32_processor_family)

        base_metadata = BaseMetadata(
            name='descriptions',
            description='Field descriptions'
        )

        lbbase = Base(
            metadata=base_metadata,
            content=content_list
        )

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        url = self.rest_url + '/' + self.lbbase.metadata.name
        response = requests.delete(url)

        #response = self.baserest.delete(self.lbbase)

        return response

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False

    def load_static(self):
        """
        Carrega valores dos grupos do arquivo JSON contido no Projeto
        :return:
        """
        # TODO: Coloca esses grupos e um valor definido pelo usuario
        groups_list = [
            'win32_physicalmemory_memorytype',
            'win32_processor_family'
        ]

        saida = dict()
        for group in groups_list:
            saida[group] = list()
            # Carrega valor do JSON para cada um ds grupos
            filename = self.data_dir + group + ".json"
            log.debug("Caminho completo do arquivo para carga: %s", filename)
            with open(filename, 'r', encoding='utf-8') as fd:
                value = json.loads(fd.read())
            #log.debug(value)
            for elm in value:
                #log.debug("111111111111111111111111111111")
                #log.debug(elm)
                # Faz o parsing do JSON por linha
                for key in elm.keys():
                    saida[group].append({
                        group + '_key': int(key),
                        group + '_value': elm[key]
                    })

        # Valida documento
        #log.debug(saida)
        document = conv.dict2document(self.lbbase, saida)
        document_json = conv.document2json(self.lbbase, document)
        log.debug(document_json)

        # FIXME: Verificar para que serve a remoção da base.
        # Recria base e insere um documento
        #if self.is_created():
        #    self.remove_base()
        #self.create_base()
        self.documentrest.create(document_json)
예제 #4
0
class BlacklistBase(object):
    """
    Classe para a base de órgãos
    """
    def __init__(self, rest_url=None):
        """
        Método construtor
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                base=self.lbbase, response_object=False)

    @property
    def lbbase(self):
        """
        LB Base do órgão
        """
        item = Field(**dict(
            name='item',
            description='Nome do item que será adicionado a lista.',
            alias='nome',
            datatype='Text',
            indices=['Textual', 'Unico'],
            multivalued=False,
            required=True
        ))

        base_metadata = BaseMetadata(
            name='blacklist',
        )

        content_list = Content()
        content_list.append(item)

        lbbase = Base(
            metadata=base_metadata,
            content=content_list
        )

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False
예제 #5
0
class NotifyBase():
    """
    Classe para a base de usuários
    """
    def __init__(self, rest_url=None):
        """
        Método construtor
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                                         base=self.lbbase,
                                         response_object=False)

    @property
    def lbbase(self):
        """
        LB Base de Notify
        """
        orgao = Field(**dict(name='orgao',
                             description='Órgão referente a notrificção',
                             alias='orgao',
                             datatype='Text',
                             indices=['Textual'],
                             multivalued=False,
                             required=True))

        data_coleta = Field(**dict(name='data_coleta',
                                   alias='data_coleta',
                                   description='data da coleta notificada',
                                   datatype='Text',
                                   indices=['Textual'],
                                   multivalued=False,
                                   required=True))

        notify = Field(**dict(name='notify',
                              alias='notify',
                              description='tipo de notificação',
                              datatype='Text',
                              indices=['Textual'],
                              multivalued=False,
                              required=True))

        coment = Field(**dict(name='coment',
                              alias='coment',
                              description='comentario',
                              datatype='Text',
                              indices=['Textual'],
                              multivalued=False,
                              required=True))

        status = Field(**dict(name='status',
                              alias='status',
                              description='status da notificação',
                              datatype='Text',
                              indices=['Textual'],
                              multivalued=False,
                              required=True))

        base_metadata = BaseMetadata(name='notify', )
        content_list = Content()
        content_list.append(orgao)
        content_list.append(data_coleta)
        content_list.append(notify)
        content_list.append(coment)
        content_list.append(status)

        lbbase = Base(metadata=base_metadata, content=content_list)

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False
예제 #6
0
class NotifyBase():
    """
    Classe para a base de usuários
    """
    def __init__(self, rest_url=None):
        """
        Método construtor
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                base=self.lbbase, response_object=False)

    @property
    def lbbase(self):
        """
        LB Base de Notify
        """
        orgao = Field(**dict(
            name='orgao',
            description='Órgão referente a notrificção',
            alias='orgao',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        data_coleta = Field(**dict(
            name='data_coleta',
            alias='data_coleta',
            description='data da coleta notificada',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        notify = Field(**dict(
            name='notify',
            alias='notify',
            description='tipo de notificação',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        coment = Field(**dict(
            name='coment',
            alias='coment',
            description='comentario',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        status = Field(**dict(
            name='status',
            alias='status',
            description='status da notificação',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        base_metadata = BaseMetadata(
            name='notify',
        )
        content_list = Content()
        content_list.append(orgao)
        content_list.append(data_coleta)
        content_list.append(notify)
        content_list.append(coment)
        content_list.append(status)

        lbbase = Base(
            metadata=base_metadata,
            content=content_list
        )

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False
예제 #7
0
class AtividadeBase(object):
    """
    Classe para a base de atividades
    """

    def __init__(self, rest_url=None):
        """
        Método construtor da base de atividades
        :param rest_url: URL do Rest
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                base=self.lbbase, response_object=False)

    @property
    def lbbase(self):
        """
        Base no LB
        :return: LB Base object
        """
        tipo = Field(**dict(
            name='tipo',
            description='Tipo de atividade',
            alias='tipo',
            datatype='Text',
            indices=['Textual', 'Ordenado'],
            multivalued=False,
            required=True
        ))

        usuario = Field(**dict(
            name='usuario',
            description='Usuário que realizou a atividade',
            alias='usuario',
            datatype='Text',
            indices=['Textual', 'Ordenado'],
            multivalued=False,
            required=True
        ))

        descricao = Field(**dict(
            name='descricao',
            description='Descrição da atividade',
            alias='descricao',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        data = Field(**dict(
            name='data',
            description='Data de execução da tarefa',
            alias='data',
            datatype='Date',
            indices=['Ordenado'],
            multivalued=False,
            required=True
        ))

        data_hora = Field(**dict(
            name='data_hora',
            description='Data e Hora de execução da tarefa',
            alias='data_hora',
            datatype='DateTime',
            indices=['Ordenado'],
            multivalued=False,
            required=False
        ))

        content_list = Content()
        content_list.append(tipo)
        content_list.append(usuario)
        content_list.append(descricao)
        content_list.append(data)
        content_list.append(data_hora)

        base_metadata = BaseMetadata(
            name='atividade'
        )

        lbbase = Base(
            metadata=base_metadata,
            content=content_list
        )

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False
예제 #8
0
class EmailBase(object):
    """
    Classe para a base de email
    """
    def __init__(self, rest_url=None):
        """
        Método construtor
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                                         base=self.lbbase,
                                         response_object=False)

    @property
    def lbbase(self):
        """
        LB Base de email
        """
        usuario = Field(**dict(name='usuario',
                               description='Usuario',
                               alias='Usuario',
                               datatype='Text',
                               indices=['Textual'],
                               multivalued=False,
                               required=True))

        to = Field(**dict(name='to',
                          description='Destino do email',
                          alias='to',
                          datatype='Text',
                          indices=['Textual'],
                          multivalued=True,
                          required=True))

        reply_to = Field(**dict(name='reply_to',
                                alias='reply_to',
                                description='reply_to',
                                datatype='Text',
                                indices=['Textual'],
                                multivalued=False,
                                required=True))

        subject = Field(**dict(name='subject',
                               alias='Assunto',
                               description='Assunto do e-mail',
                               datatype='Text',
                               indices=['Textual'],
                               multivalued=False,
                               required=True))

        body = Field(**dict(name='body',
                            alias='body',
                            description='Corpo do e-mail',
                            datatype='Text',
                            indices=['Textual'],
                            multivalued=False,
                            required=True))

        headers = Field(**dict(name='headers',
                               alias='headers',
                               description='headers',
                               datatype='Text',
                               indices=['Textual'],
                               multivalued=False,
                               required=True))

        data_send = Field(**dict(name='data_send',
                                 alias='data_send',
                                 description='Data de envio',
                                 datatype='DateTime',
                                 indices=['Ordenado'],
                                 multivalued=False,
                                 required=True))

        status = Field(**dict(name='status',
                              alias='status',
                              description='status',
                              datatype='Text',
                              indices=['Textual'],
                              multivalued=False,
                              required=True))

        hidden_destination = Field(**dict(name='hidden_destination',
                                          alias='hd',
                                          description='hd',
                                          datatype='Text',
                                          indices=['Textual'],
                                          multivalued=False,
                                          required=False))

        base_metadata = BaseMetadata(name='email', )

        content_list = Content()
        content_list.append(usuario)
        content_list.append(to)
        content_list.append(reply_to)
        content_list.append(subject)
        content_list.append(body)
        content_list.append(headers)
        content_list.append(data_send)
        content_list.append(status)
        content_list.append(hidden_destination)

        lbbase = Base(metadata=base_metadata, content=content_list)

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False
예제 #9
0
class ReportsBase():
    """
    Classe para a base de Reports
    """
    def __init__(self, nm_base,rest_url=None):
        """
        Método construtor
        """
        self.nm_base = nm_base
        if rest_url is None:
            self.rest_url=config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=True)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                base=self.lbbase, response_object=False)

    @property
    def lbbase(self):
        """
        LB Base do órgão
        """
        OperatingSystem_item = Field(**dict(
            name='OperatingSystem_item',
            description='Item Coletado',
            alias='Item',
            datatype='Text',
            indices=['Textual', 'Unico'],
            multivalued=False,
            required=True
        ))

        OperatingSystem_amount = Field(**dict(
            name='OperatingSystem_amount',
            alias='amount',
            description='amount',
            datatype='Integer',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        Win32_BIOS_item = Field(**dict(
            name='Win32_BIOS_item',
            description='Item Coletado',
            alias='Item',
            datatype='Text',
            indices=['Textual', 'Unico'],
            multivalued=False,
            required=True
        ))

        Win32_BIOS_amount = Field(**dict(
            name='Win32_BIOS_amount',
            alias='amount',
            description='amount',
            datatype='Integer',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        Win32_Processor_item = Field(**dict(
            name='Win32_Processor_item',
            description='Item Coletado',
            alias='Item',
            datatype='Text',
            indices=['Textual', 'Unico'],
            multivalued=False,
            required=True
        ))

        Win32_Processor_amount = Field(**dict(
            name='Win32_Processor_amount',
            alias='amount',
            description='amount',
            datatype='Integer',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        Win32_DiskDrive_item = Field(**dict(
            name='Win32_DiskDrive_item',
            description='Item Coletado',
            alias='Item',
            datatype='Text',
            indices=['Textual', 'Unico'],
            multivalued=False,
            required=True
        ))

        Win32_DiskDrive_amount = Field(**dict(
            name='Win32_DiskDrive_amount',
            alias='amount',
            description='amount',
            datatype='Integer',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        Win32_PhysicalMemory_item = Field(**dict(
            name='Win32_PhysicalMemory_item',
            description='Item Coletado',
            alias='Item',
            datatype='Text',
            indices=['Textual', 'Unico'],
            multivalued=False,
            required=True
        ))

        Win32_PhysicalMemory_amount = Field(**dict(
            name='Win32_PhysicalMemory_amount',
            alias='amount',
            description='amount',
            datatype='Integer',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        software_item = Field(**dict(
            name='SoftwareList_item',
            description='Software Coletado',
            alias='SoftwareList_item',
            datatype='Text',
            indices=['Textual', 'Unico'],
            multivalued=False,
            required=True
        ))

        software_amount = Field(**dict(
            name='SoftwareList_amount',
            alias='SoftwareList_amount',
            description='Software Amount',
            datatype='Integer',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        """
        GROUP Sistema Operacional
        """
        OperatingSystem_content = Content()
        OperatingSystem_content.append(OperatingSystem_item)
        OperatingSystem_content.append(OperatingSystem_amount)

        OperatingSystem_metadata = GroupMetadata(
            name='OperatingSystem',
            alias='OperatingSystem',
            description='OperatingSystem',
            multivalued = False
        )

        OperatingSystem = Group(
            metadata = OperatingSystem_metadata,
            content = OperatingSystem_content
        )

        """
        GROUP Bios
        """
        Win32_BIOS_content = Content()
        Win32_BIOS_content.append(Win32_BIOS_item)
        Win32_BIOS_content.append(Win32_BIOS_amount)

        Win32_BIOS_metadata = GroupMetadata(
            name='Win32_BIOS',
            alias='Win32_BIOS',
            description='Win32_BIOS',
            multivalued=False
        )

        Win32_BIOS = Group(
            metadata=Win32_BIOS_metadata,
            content=Win32_BIOS_content
        )

        """
        GROUP Processador
        """
        Win32_Processor_content = Content()
        Win32_Processor_content.append(Win32_Processor_item)
        Win32_Processor_content.append(Win32_Processor_amount)

        Win32_Processor_metadata = GroupMetadata(
            name='Win32_Processor',
            alias='Win32_Processor',
            description='Win32_Processor',
            multivalued=False
        )

        Win32_Processor = Group(
            metadata=Win32_Processor_metadata,
            content=Win32_Processor_content
        )

        """
        GROUP DiskDrive
        """
        Win32_DiskDrive_content = Content()
        Win32_DiskDrive_content.append(Win32_DiskDrive_item)
        Win32_DiskDrive_content.append(Win32_DiskDrive_amount)

        Win32_DiskDrive_metadata = GroupMetadata(
            name='Win32_DiskDrive',
            alias='Win32_DiskDrive',
            description='Win32_DiskDrive',
            multivalued = False
        )

        Win32_DiskDrive = Group(
            metadata = Win32_DiskDrive_metadata,
            content = Win32_DiskDrive_content
        )

        """
        GROUP PhysicalMemory
        """
        Win32_PhysicalMemory_content = Content()
        Win32_PhysicalMemory_content.append(Win32_PhysicalMemory_item)
        Win32_PhysicalMemory_content.append(Win32_PhysicalMemory_amount)

        Win32_PhysicalMemory_metadata = GroupMetadata(
            name='Win32_PhysicalMemory',
            alias='Win32_PhysicalMemory',
            description='Win32_PhysicalMemory',
            multivalued=False
        )

        Win32_PhysicalMemory = Group(
            metadata=Win32_PhysicalMemory_metadata,
            content=Win32_PhysicalMemory_content
        )

        """
        GROUP Software
        """
        software_content = Content()
        software_content.append(software_item)
        software_content.append(software_amount)

        software_metadata = GroupMetadata(
            name='SoftwareList',
            alias='SoftwareList',
            description='Lista de softwares',
            multivalued=False
        )

        software = Group(
            metadata=software_metadata,
            content=software_content
        )

        base_metadata = BaseMetadata(
            name = self.nm_base + "_bk",
        )

        content_list = Content()
        content_list.append(OperatingSystem)
        content_list.append(Win32_BIOS)
        content_list.append(Win32_Processor)
        content_list.append(Win32_PhysicalMemory)
        content_list.append(Win32_DiskDrive)
        content_list.append(software)

        lbbase = Base(
            metadata=base_metadata,
            content=content_list
        )

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        self.baserest.response_object = True
        response = self.baserest.create(self.lbbase)
        if response.status_code == 200:
            return self.lbbase
        else:
            return None

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        response = self.baserest.delete(self.lbbase)
        if response.status_code == 200:
            return True
        else:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            self.baserest.response_object = False
            response = self.baserest.get(self.lbbase.metadata.name)
            self.baserest.response_object = True
            return True
        except:
            return False
예제 #10
0
class EmailBase(object):
    """
    Classe para a base de email
    """
    def __init__(self, rest_url=None):
        """
        Método construtor
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                base=self.lbbase, response_object=False)

    @property
    def lbbase(self):
        """
        LB Base de email
        """
        usuario = Field(**dict(
            name='usuario',
            description='Usuario',
            alias='Usuario',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        to = Field(**dict(
            name='to',
            description='Destino do email',
            alias='to',
            datatype='Text',
            indices=['Textual'],
            multivalued=True,
            required=True
        ))

        reply_to = Field(**dict(
            name='reply_to',
            alias='reply_to',
            description='reply_to',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        subject = Field(**dict(
            name='subject',
            alias='Assunto',
            description='Assunto do e-mail',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        body = Field(**dict(
            name='body',
            alias='body',
            description='Corpo do e-mail',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        headers = Field(**dict(
            name='headers',
            alias='headers',
            description='headers',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        data_send = Field(**dict(
            name='data_send',
            alias='data_send',
            description='Data de envio',
            datatype='DateTime',
            indices=['Ordenado'],
            multivalued=False,
            required=True
        ))

        status = Field(**dict(
            name='status',
            alias='status',
            description='status',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        hidden_destination = Field(**dict(
            name='hidden_destination',
            alias='hd',
            description='hd',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        base_metadata = BaseMetadata(
            name='email',
        )

        content_list = Content()
        content_list.append(usuario)
        content_list.append(to)
        content_list.append(reply_to)
        content_list.append(subject)
        content_list.append(body)
        content_list.append(headers)
        content_list.append(data_send)
        content_list.append(status)
        content_list.append(hidden_destination)

        lbbase = Base(
            metadata=base_metadata,
            content=content_list
        )

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False
예제 #11
0
class AtividadeBase(object):
    """
    Classe para a base de atividades
    """
    def __init__(self, rest_url=None):
        """
        Método construtor da base de atividades
        :param rest_url: URL do Rest
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                                         base=self.lbbase,
                                         response_object=False)

    @property
    def lbbase(self):
        """
        Base no LB
        :return: LB Base object
        """
        tipo = Field(**dict(name='tipo',
                            description='Tipo de atividade',
                            alias='tipo',
                            datatype='Text',
                            indices=['Textual', 'Ordenado'],
                            multivalued=False,
                            required=True))

        usuario = Field(**dict(name='usuario',
                               description='Usuário que realizou a atividade',
                               alias='usuario',
                               datatype='Text',
                               indices=['Textual', 'Ordenado'],
                               multivalued=False,
                               required=True))

        descricao = Field(**dict(name='descricao',
                                 description='Descrição da atividade',
                                 alias='descricao',
                                 datatype='Text',
                                 indices=['Textual'],
                                 multivalued=False,
                                 required=True))

        data = Field(**dict(name='data',
                            description='Data de execução da tarefa',
                            alias='data',
                            datatype='Date',
                            indices=['Ordenado'],
                            multivalued=False,
                            required=True))

        data_hora = Field(
            **dict(name='data_hora',
                   description='Data e Hora de execução da tarefa',
                   alias='data_hora',
                   datatype='DateTime',
                   indices=['Ordenado'],
                   multivalued=False,
                   required=False))

        content_list = Content()
        content_list.append(tipo)
        content_list.append(usuario)
        content_list.append(descricao)
        content_list.append(data)
        content_list.append(data_hora)

        base_metadata = BaseMetadata(name='atividade')

        lbbase = Base(metadata=base_metadata, content=content_list)

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False
예제 #12
0
class BlacklistBase(object):
    """
    Classe para a base de órgãos
    """
    def __init__(self, rest_url=None):
        """
        Método construtor
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                                         base=self.lbbase,
                                         response_object=False)

    @property
    def lbbase(self):
        """
        LB Base do órgão
        """
        item = Field(
            **dict(name='item',
                   description='Nome do item que será adicionado a lista.',
                   alias='nome',
                   datatype='Text',
                   indices=['Textual', 'Unico'],
                   multivalued=False,
                   required=True))

        base_metadata = BaseMetadata(name='blacklist', )

        content_list = Content()
        content_list.append(item)

        lbbase = Base(metadata=base_metadata, content=content_list)

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False
예제 #13
0
class UserBase():
    """
    Classe para a base de usuários
    """
    def __init__(self, rest_url=None):
        """
        Método construtor
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                                         base=self.lbbase,
                                         response_object=False)

    @property
    def lbbase(self):
        """
        LB Base de Users
        """
        nome = Field(**dict(name='nome',
                            description='Nome do Usuário',
                            alias='nome',
                            datatype='Text',
                            indices=['Textual'],
                            multivalued=False,
                            required=True))

        matricula = Field(**dict(name='matricula',
                                 alias='matricula',
                                 description='Matricula do Usuário',
                                 datatype='Text',
                                 indices=['Textual'],
                                 multivalued=False,
                                 required=True))

        email = Field(**dict(name='email',
                             alias='email',
                             description='E-mail do Usuário',
                             datatype='Text',
                             indices=['Textual'],
                             multivalued=False,
                             required=True))

        telefone = Field(**dict(name='telefone',
                                alias='telefone',
                                description='Telefone do Usuário',
                                datatype='Text',
                                indices=['Textual'],
                                multivalued=False,
                                required=True))

        orgao = Field(**dict(name='orgao',
                             alias='orgao',
                             description='Orgão do Usuário',
                             datatype='Text',
                             indices=['Textual'],
                             multivalued=False,
                             required=True))

        cargo = Field(**dict(name='cargo',
                             alias='cargo',
                             description='Cargo do Usuário',
                             datatype='Text',
                             indices=['Textual'],
                             multivalued=False,
                             required=True))

        setor = Field(**dict(name='setor',
                             alias='setor',
                             description='Setor do Usuário',
                             datatype='Text',
                             indices=['Textual'],
                             multivalued=False,
                             required=True))

        permissao = Field(**dict(name='permissao',
                                 alias='permissao',
                                 description='Permissão do Usuário',
                                 datatype='Text',
                                 indices=['Textual'],
                                 multivalued=False,
                                 required=True))

        senha = Field(**dict(name='senha',
                             alias='senha',
                             description='Senha do Usuário',
                             datatype='Text',
                             indices=['Textual'],
                             multivalued=False,
                             required=True))
        favoritos = Field(**dict(name='favoritos',
                                 alias='favoritos',
                                 description='Favoritos do Usuário',
                                 datatype='Text',
                                 indices=['Textual'],
                                 multivalued=True,
                                 required=False))
        home = Field(**dict(name='home',
                            alias='home',
                            description='Home do Usuário',
                            datatype='Text',
                            indices=['Textual'],
                            multivalued=True,
                            required=False))
        itens = Field(**dict(name='itens',
                             alias='itens',
                             description='Itens do Usuário',
                             datatype='Text',
                             indices=['Textual'],
                             multivalued=True,
                             required=False))

        url_hash = Field(
            **dict(name='url_hash',
                   alias='url_hash',
                   description='hash que sera usado para para criar a url',
                   datatype='Text',
                   indices=['Textual'],
                   multivalued=True,
                   required=False))

        nm_user = Field(**dict(name='nm_user',
                               alias='nm_user',
                               description='Nome do usuario',
                               datatype='Text',
                               indices=['Textual'],
                               multivalued=True,
                               required=False))

        HashUrl_content = Content()
        HashUrl_content.append(nm_user)
        HashUrl_content.append(url_hash)

        HashUrl_metadata = GroupMetadata(name='HashUrl',
                                         alias='HashUrl',
                                         description='HashUrl',
                                         multivalued=False)

        HashUrl = Group(metadata=HashUrl_metadata, content=HashUrl_content)

        base_metadata = BaseMetadata(name='users', )

        content_list = Content()
        content_list.append(nome)
        content_list.append(matricula)
        content_list.append(email)
        content_list.append(telefone)
        content_list.append(orgao)
        content_list.append(cargo)
        content_list.append(setor)
        content_list.append(permissao)
        content_list.append(senha)
        content_list.append(favoritos)
        content_list.append(home)
        content_list.append(itens)
        content_list.append(HashUrl)

        lbbase = Base(metadata=base_metadata, content=content_list)

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False
예제 #14
0
class BaseBackup(object):
    """
    Classe para a base de usuários
    """
    def __init__(self, orgao, rest_url=None):
        """
        Método construtor
        """
        #print(rest_url)
        self.orgao = orgao
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                base=self.lbbase, response_object=False)

    @property
    def lbbase(self):

        """
        Configuração da Coleta
        """
        nome_orgao = Field(**dict(
            name='nome_orgao',
            description='Nome do Órgão',
            alias='nome_orgao',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        data_coleta = Field(**dict(
            name='data_coleta',
            description='Data da Coleta',
            alias='data_coleta',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        hash_machine = Field(**dict(
            name='hash_machine',
            description='hash para maquinas',
            alias='hash_machine',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        data_ultimo_acesso = Field(**dict(
            name='data_ultimo_acesso',
            description='data do ultimo acesso',
            alias='data acesso',
            datatype='DateTime',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        # Adições Jansen: 2015-11-26
        mac = Field(**dict(
            name='mac',
            description='MAC Address',
            alias='MAC',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        ip_computador = Field(**dict(
            name='ip_computador',
            description='IP do Computador',
            alias='Endereço IP',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        ip_rede = Field(**dict(
            name='ip_rede',
            description='IP da Rede',
            alias='IP da Rede',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        nome_rede = Field(**dict(
            name='nome_rede',
            description='Nome da Rede',
            alias='Nome da Rede',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        """
        LB Processadores
        """
        Win32_Processor_Manufacturer = Field(**dict(
            name='Win32_Processor_Manufacturer',
            description='Win32_Processor_Manufacturer',
            alias='Win32_Processor_Manufacturer',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))
        Win32_Processor_NumberOfLogicalProcessors = Field(**dict(
            name='Win32_Processor_NumberOfLogicalProcessors',
            description='Win32_Processor_NumberOfLogicalProcessors',
            alias='Win32_Processor_NumberOfLogicalProcessors',
            datatype='Integer',
            indices=[],
            multivalued=False,
            required=False
        ))

        Win32_Processor_Caption = Field(**dict(
            name='Win32_Processor_Caption',
            description='Win32_Processor_Caption',
            alias='Win32_Processor_Caption',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        Win32_Processor_MaxClockSpeed = Field(**dict(
            name='Win32_Processor_MaxClockSpeed',
            description='Win32_Processor_MaxClockSpeed',
            alias='Win32_Processor_MaxClockSpeed',
            datatype='Integer',
            indices=[],
            multivalued=False,
            required=False
        ))

        Win32_Processor_Family = Field(**dict(
            name='Win32_Processor_Family',
            description='Win32_Processor_Family',
            alias='Win32_Processor_Family',
            datatype='Integer',
            indices=[],
            multivalued=False,
            required=False
        ))

        # Adições Jansen: 2015-11-26
        win32_processor_installdate = Field(**dict(
            name='win32_processor_installdate',
            description='win32_processor_installdate',
            alias='win32_processor_installdate',
            datatype='Text',
            indices=[],
            multivalued=False,
            required=False
        ))

        """
        BaseBoard
        """
        # Adições Jansen: 2015-11-26
        win32_baseboard_installdate = Field(**dict(
            name='win32_baseboard_installdate',
            description='win32_baseboard_installdate',
            alias='win32_baseboard_installdate',
            datatype='Text',
            indices=[],
            multivalued=False,
            required=False
        ))

        """
        LB Sistema Operacional
        """
        OperatingSystem_Version = Field(**dict(
            name='OperatingSystem_Version',
            description='OperatingSystem_Version',
            alias='OperatingSystem_Version',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))
        OperatingSystem_InstallDate = Field(**dict(
            name='OperatingSystem_InstallDate',
            description='OperatingSystem_InstallDate',
            alias='OperatingSystem_InstallDate',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))
        OperatingSystem_Caption = Field(**dict(
            name='OperatingSystem_Caption',
            description='OperatingSystem_Caption',
            alias='OperatingSystem_Caption',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        """
        LB SoftwareList
        """
        SoftwareList = Field(**dict(
            name='SoftwareList',
            description='SoftwareList',
            alias='SoftwareList',
            datatype='Text',
            indices=['Textual'],
            multivalued=True,
            required=False
        ))

        """
        LB Bios
        """
        Win32_BIOS_Manufacturer = Field(**dict(
            name='Win32_BIOS_Manufacturer',
            description='Win32_BIOS_Manufacturer',
            alias='Win32_BIOS_Manufacturer',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        # Adições Jansen: 2015-11-26
        win32_bios_installdate = Field(**dict(
            name='win32_bios_installdate',
            description='win32_bios_installdate',
            alias='win32_bios_installdate',
            datatype='Text',
            indices=[],
            multivalued=False,
            required=False
        ))

        win32_bios_releasedate = Field(**dict(
            name='win32_bios_releasedate',
            description='win32_bios_releasedate',
            alias='win32_bios_releasedate',
            datatype='Text',
            indices=[],
            multivalued=False,
            required=False
        ))

        """
        LB Physical Memory
        """
        Win32_PhysicalMemory_MemoryType = Field(**dict(
            name='Win32_PhysicalMemory_MemoryType',
            description='Win32_PhysicalMemory_MemoryType',
            alias='Win32_PhysicalMemory_MemoryType',
            datatype='Integer',
            indices=[],
            multivalued=False,
            required=False
        ))

        Win32_PhysicalMemory_Capacity = Field(**dict(
            name='Win32_PhysicalMemory_Capacity',
            description='Win32_PhysicalMemory_Capacity',
            alias='Win32_PhysicalMemory_Capacity',
            datatype='Integer',
            indices=[],
            multivalued=False,
            required=False
        ))

        """
        LB Disk
        """
        Win32_DiskDrive_Caption = Field(**dict(
            name='Win32_DiskDrive_Caption',
            description='Win32_DiskDrive_Caption',
            alias='Win32_DiskDrive_Caption',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        Win32_DiskDrive_Model = Field(**dict(
            name='Win32_DiskDrive_Model',
            description='Win32_DiskDrive_Model',
            alias='Win32_DiskDrive_Model',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=False
        ))

        Win32_DiskDrive_Size = Field(**dict(
            name='Win32_DiskDrive_Size',
            description='Win32_DiskDrive_Size',
            alias='Win32_DiskDrive_Size',
            datatype='Integer',
            indices=[],
            multivalued=False,
            required=False
        ))

        """
        GROUP Sistema Operacional
        """
        OperatingSystem_content = Content()
        OperatingSystem_content.append(OperatingSystem_Version)
        OperatingSystem_content.append(OperatingSystem_InstallDate)
        OperatingSystem_content.append(OperatingSystem_Caption)

        OperatingSystem_metadata = GroupMetadata(
            name='OperatingSystem',
            alias='OperatingSystem',
            description='OperatingSystem',
            multivalued=False
        )

        OperatingSystem = Group(
            metadata=OperatingSystem_metadata,
            content=OperatingSystem_content
        )

        """
        GROUP Bios
        """
        Win32_BIOS_content = Content()
        Win32_BIOS_content.append(Win32_BIOS_Manufacturer)
        Win32_BIOS_content.append(win32_bios_installdate)
        Win32_BIOS_content.append(win32_bios_releasedate)

        Win32_BIOS_metadata = GroupMetadata(
            name='Win32_BIOS',
            alias='Win32_BIOS',
            description='Win32_BIOS',
            multivalued=False
        )

        Win32_BIOS = Group(
            metadata = Win32_BIOS_metadata,
            content = Win32_BIOS_content
        )

        """
        GROUP Processador
        """
        Win32_Processor_content = Content()
        Win32_Processor_content.append(Win32_Processor_Manufacturer)
        Win32_Processor_content.append(Win32_Processor_NumberOfLogicalProcessors)
        Win32_Processor_content.append(Win32_Processor_Caption)
        Win32_Processor_content.append(Win32_Processor_MaxClockSpeed)
        Win32_Processor_content.append(Win32_Processor_Family)
        Win32_Processor_content.append(win32_processor_installdate)

        Win32_Processor_metadata = GroupMetadata(
            name='Win32_Processor',
            alias='Win32_Processor',
            description='Win32_Processor',
            multivalued = False
        )

        Win32_Processor = Group(
            metadata = Win32_Processor_metadata,
            content = Win32_Processor_content
        )

        """
        GROUP Physical Memory
        """
        Win32_PhysicalMemory_content = Content()
        Win32_PhysicalMemory_content.append(Win32_PhysicalMemory_Capacity)
        Win32_PhysicalMemory_content.append(Win32_PhysicalMemory_MemoryType)

        Win32_PhysicalMemory_metadata = GroupMetadata(
            name='Win32_PhysicalMemory',
            alias='Win32_PhysicalMemory',
            description='Win32_PhysicalMemory',
            multivalued=False
        )

        Win32_PhysicalMemory = Group(
            metadata=Win32_PhysicalMemory_metadata,
            content=Win32_PhysicalMemory_content
        )

        """
        GROUP Logical Disk
        """
        Win32_DiskDrive_content = Content()
        Win32_DiskDrive_content.append(Win32_DiskDrive_Caption)
        Win32_DiskDrive_content.append(Win32_DiskDrive_Model)
        Win32_DiskDrive_content.append(Win32_DiskDrive_Size)

        Win32_DiskDrive_metadata = GroupMetadata(
            name='Win32_DiskDrive',
            alias='Win32_DiskDrive',
            description='Win32_DiskDrive',
            multivalued=False
        )

        Win32_DiskDrive = Group(
            metadata=Win32_DiskDrive_metadata,
            content=Win32_DiskDrive_content
        )

        """
        Group BaseBoard
        """
        Win32_BaseBoard_content = Content()
        Win32_BaseBoard_content.append(win32_baseboard_installdate)

        Win32_BaseBoard_metadata = GroupMetadata(
            name='Win32_BaseBoard',
            alias='Win32_BaseBoard',
            description='Win32_BaseBoard',
            multivalued=False
        )

        Win32_BaseBoard = Group(
            metadata=Win32_BaseBoard_metadata,
            content=Win32_BaseBoard_content
        )


        base_metadata = BaseMetadata(
            name='orgaos_bk',
        )

        content_list = Content()
        content_list.append(data_coleta)
        content_list.append(Win32_Processor)
        content_list.append(OperatingSystem)
        content_list.append(Win32_BIOS)
        content_list.append(Win32_PhysicalMemory)
        content_list.append(Win32_DiskDrive)
        content_list.append(Win32_BaseBoard)
        content_list.append(SoftwareList)
        content_list.append(hash_machine)
        content_list.append(data_ultimo_acesso)
        content_list.append(mac)
        content_list.append(ip_computador)
        content_list.append(ip_rede)
        content_list.append(nome_rede)
        content_list.append(nome_orgao)

        lbbase = Base(
            metadata=base_metadata,
            content=content_list
        )

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False

    def update_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.update(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error updating base in LB')
예제 #15
0
class ReportsBase():
    """
    Classe para a base de Reports
    """
    def __init__(self, nm_base, rest_url=None):
        """
        Método construtor
        """
        self.nm_base = nm_base
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=True)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                                         base=self.lbbase,
                                         response_object=False)

    @property
    def lbbase(self):
        """
        LB Base do órgão
        """
        OperatingSystem_item = Field(**dict(name='OperatingSystem_item',
                                            description='Item Coletado',
                                            alias='Item',
                                            datatype='Text',
                                            indices=['Textual', 'Unico'],
                                            multivalued=False,
                                            required=True))

        OperatingSystem_amount = Field(**dict(name='OperatingSystem_amount',
                                              alias='amount',
                                              description='amount',
                                              datatype='Integer',
                                              indices=['Textual'],
                                              multivalued=False,
                                              required=True))

        Win32_BIOS_item = Field(**dict(name='Win32_BIOS_item',
                                       description='Item Coletado',
                                       alias='Item',
                                       datatype='Text',
                                       indices=['Textual', 'Unico'],
                                       multivalued=False,
                                       required=True))

        Win32_BIOS_amount = Field(**dict(name='Win32_BIOS_amount',
                                         alias='amount',
                                         description='amount',
                                         datatype='Integer',
                                         indices=['Textual'],
                                         multivalued=False,
                                         required=True))

        Win32_Processor_item = Field(**dict(name='Win32_Processor_item',
                                            description='Item Coletado',
                                            alias='Item',
                                            datatype='Text',
                                            indices=['Textual', 'Unico'],
                                            multivalued=False,
                                            required=True))

        Win32_Processor_amount = Field(**dict(name='Win32_Processor_amount',
                                              alias='amount',
                                              description='amount',
                                              datatype='Integer',
                                              indices=['Textual'],
                                              multivalued=False,
                                              required=True))

        Win32_DiskDrive_item = Field(**dict(name='Win32_DiskDrive_item',
                                            description='Item Coletado',
                                            alias='Item',
                                            datatype='Text',
                                            indices=['Textual', 'Unico'],
                                            multivalued=False,
                                            required=True))

        Win32_DiskDrive_amount = Field(**dict(name='Win32_DiskDrive_amount',
                                              alias='amount',
                                              description='amount',
                                              datatype='Integer',
                                              indices=['Textual'],
                                              multivalued=False,
                                              required=True))

        Win32_PhysicalMemory_item = Field(
            **dict(name='Win32_PhysicalMemory_item',
                   description='Item Coletado',
                   alias='Item',
                   datatype='Text',
                   indices=['Textual', 'Unico'],
                   multivalued=False,
                   required=True))

        Win32_PhysicalMemory_amount = Field(
            **dict(name='Win32_PhysicalMemory_amount',
                   alias='amount',
                   description='amount',
                   datatype='Integer',
                   indices=['Textual'],
                   multivalued=False,
                   required=True))

        software_item = Field(**dict(name='SoftwareList_item',
                                     description='Software Coletado',
                                     alias='SoftwareList_item',
                                     datatype='Text',
                                     indices=['Textual', 'Unico'],
                                     multivalued=False,
                                     required=True))

        software_amount = Field(**dict(name='SoftwareList_amount',
                                       alias='SoftwareList_amount',
                                       description='Software Amount',
                                       datatype='Integer',
                                       indices=['Textual'],
                                       multivalued=False,
                                       required=True))
        """
        GROUP Sistema Operacional
        """
        OperatingSystem_content = Content()
        OperatingSystem_content.append(OperatingSystem_item)
        OperatingSystem_content.append(OperatingSystem_amount)

        OperatingSystem_metadata = GroupMetadata(name='OperatingSystem',
                                                 alias='OperatingSystem',
                                                 description='OperatingSystem',
                                                 multivalued=False)

        OperatingSystem = Group(metadata=OperatingSystem_metadata,
                                content=OperatingSystem_content)
        """
        GROUP Bios
        """
        Win32_BIOS_content = Content()
        Win32_BIOS_content.append(Win32_BIOS_item)
        Win32_BIOS_content.append(Win32_BIOS_amount)

        Win32_BIOS_metadata = GroupMetadata(name='Win32_BIOS',
                                            alias='Win32_BIOS',
                                            description='Win32_BIOS',
                                            multivalued=False)

        Win32_BIOS = Group(metadata=Win32_BIOS_metadata,
                           content=Win32_BIOS_content)
        """
        GROUP Processador
        """
        Win32_Processor_content = Content()
        Win32_Processor_content.append(Win32_Processor_item)
        Win32_Processor_content.append(Win32_Processor_amount)

        Win32_Processor_metadata = GroupMetadata(name='Win32_Processor',
                                                 alias='Win32_Processor',
                                                 description='Win32_Processor',
                                                 multivalued=False)

        Win32_Processor = Group(metadata=Win32_Processor_metadata,
                                content=Win32_Processor_content)
        """
        GROUP DiskDrive
        """
        Win32_DiskDrive_content = Content()
        Win32_DiskDrive_content.append(Win32_DiskDrive_item)
        Win32_DiskDrive_content.append(Win32_DiskDrive_amount)

        Win32_DiskDrive_metadata = GroupMetadata(name='Win32_DiskDrive',
                                                 alias='Win32_DiskDrive',
                                                 description='Win32_DiskDrive',
                                                 multivalued=False)

        Win32_DiskDrive = Group(metadata=Win32_DiskDrive_metadata,
                                content=Win32_DiskDrive_content)
        """
        GROUP PhysicalMemory
        """
        Win32_PhysicalMemory_content = Content()
        Win32_PhysicalMemory_content.append(Win32_PhysicalMemory_item)
        Win32_PhysicalMemory_content.append(Win32_PhysicalMemory_amount)

        Win32_PhysicalMemory_metadata = GroupMetadata(
            name='Win32_PhysicalMemory',
            alias='Win32_PhysicalMemory',
            description='Win32_PhysicalMemory',
            multivalued=False)

        Win32_PhysicalMemory = Group(metadata=Win32_PhysicalMemory_metadata,
                                     content=Win32_PhysicalMemory_content)
        """
        GROUP Software
        """
        software_content = Content()
        software_content.append(software_item)
        software_content.append(software_amount)

        software_metadata = GroupMetadata(name='SoftwareList',
                                          alias='SoftwareList',
                                          description='Lista de softwares',
                                          multivalued=False)

        software = Group(metadata=software_metadata, content=software_content)

        base_metadata = BaseMetadata(name=self.nm_base + "_bk", )

        content_list = Content()
        content_list.append(OperatingSystem)
        content_list.append(Win32_BIOS)
        content_list.append(Win32_Processor)
        content_list.append(Win32_PhysicalMemory)
        content_list.append(Win32_DiskDrive)
        content_list.append(software)

        lbbase = Base(metadata=base_metadata, content=content_list)

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        self.baserest.response_object = True
        response = self.baserest.create(self.lbbase)
        if response.status_code == 200:
            return self.lbbase
        else:
            return None

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        response = self.baserest.delete(self.lbbase)
        if response.status_code == 200:
            return True
        else:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            self.baserest.response_object = False
            response = self.baserest.get(self.lbbase.metadata.name)
            self.baserest.response_object = True
            return True
        except:
            return False
예제 #16
0
class OrgaoBase(object):
    """
    Classe para a base de órgãos
    """
    def __init__(self, rest_url=None):
        """
        Método construtor
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                                         base=self.lbbase,
                                         response_object=False)

    @property
    def lbbase(self):
        """
        LB Base do órgão
        """
        nome = Field(**dict(name='nome',
                            description='Nome do órgão',
                            alias='nome',
                            datatype='Text',
                            indices=['Textual', 'Unico'],
                            multivalued=False,
                            required=True))

        pretty_name = Field(**dict(name='pretty_name',
                                   description='Nome do órgão',
                                   alias='pretty_name',
                                   datatype='Text',
                                   indices=['Textual'],
                                   multivalued=False,
                                   required=True))

        sigla = Field(**dict(name='sigla',
                             alias='sigla',
                             description='Sigla do órgão',
                             datatype='Text',
                             indices=['Textual', 'Unico'],
                             multivalued=False,
                             required=True))

        gestor = Field(**dict(name='gestor',
                              alias='gestor',
                              description='Nome do gestor',
                              datatype='Text',
                              indices=['Textual'],
                              multivalued=False,
                              required=True))

        cargo = Field(**dict(name='cargo',
                             alias='cargo',
                             description='Cargo do gestor',
                             datatype='Text',
                             indices=['Textual'],
                             multivalued=False,
                             required=True))

        telefone = Field(**dict(name='telefone',
                                alias='telefone',
                                description='Telefone do órgão',
                                datatype='Text',
                                indices=['Textual'],
                                multivalued=False,
                                required=True))

        email = Field(**dict(name='email',
                             alias='email',
                             description='E-mail do órgão',
                             datatype='Text',
                             indices=['Textual', 'Unico'],
                             multivalued=False,
                             required=True))

        endereco = Field(**dict(name='endereco',
                                alias='endereco',
                                description='Endereço do orgao',
                                datatype='Text',
                                indices=['Textual'],
                                multivalued=False,
                                required=True))

        coleta = Field(**dict(name='coleta',
                              alias='coleta',
                              description='Intervalo de coleta',
                              datatype='Integer',
                              indices=[],
                              multivalued=False,
                              required=False))

        url = Field(**dict(name='url',
                           alias='url',
                           description='Url da base de dados',
                           datatype='Text',
                           indices=['Textual'],
                           multivalued=False,
                           required=False))

        siorg = Field(**dict(name='siorg',
                             alias='siorg',
                             description='Código do SIORG',
                             datatype='Text',
                             indices=['Textual', 'Unico'],
                             multivalued=False,
                             required=False))

        habilitar_bot = Field(**dict(name='habilitar_bot',
                                     alias='habilitar_bot',
                                     description='Habilitar Bot',
                                     datatype='Boolean',
                                     indices=[],
                                     multivalued=False,
                                     required=False))

        api_key = Field(**dict(name='api_key',
                               alias='api_key',
                               description='Chave de API',
                               datatype='Text',
                               indices=[],
                               multivalued=False,
                               required=True))

        base_metadata = BaseMetadata(name='orgaos', )

        content_list = Content()
        content_list.append(nome)
        content_list.append(pretty_name)
        content_list.append(sigla)
        content_list.append(gestor)
        content_list.append(cargo)
        content_list.append(telefone)
        content_list.append(email)
        content_list.append(endereco)
        content_list.append(coleta)
        content_list.append(url)
        content_list.append(habilitar_bot)
        content_list.append(api_key)
        content_list.append(siorg)

        lbbase = Base(metadata=base_metadata, content=content_list)

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        try:
            response = self.baserest.create(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error inserting base in LB')

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.delete(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error excluding base from LB')

    def update_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        try:
            response = self.baserest.update(self.lbbase)
            return True
        except HTTPError:
            raise IOError('Error updating base in LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            response = self.baserest.get(self.lbbase.metadata.name)
            return True
        except HTTPError:
            return False

    def element_exists(self, element, value, orgao=None):
        """
        Return a crime by name
        """
        orderby = OrderBy([element])
        if orgao is None:
            search = Search(
                limit=1,
                order_by=orderby,
                literal="document->>'" + element + "' = '" + value + "'",
            )
        else:
            search = Search(
                limit=1,
                order_by=orderby,
                literal="document->>'" + element + "' = '" + value +
                "' and document->>'nome' <> '" + orgao + "'",
            )
        params = {'$$': search._asjson()}

        url = self.rest_url + '/' + self.lbbase.metadata.name + '/doc'
        result = requests.get(url=url, params=params)
        results = result.json()
        print(results)
        if results['result_count'] == 0:
            return False
        else:
            return True
예제 #17
0
class AllReports():
    """
    Classe para a base de usuários
    """
    def __init__(self, rest_url=None):
        """
        Método construtor
        """
        if rest_url is None:
            self.rest_url = config.REST_URL
        else:
            self.rest_url = rest_url
        self.baserest = BaseREST(rest_url=self.rest_url, response_object=False)
        self.documentrest = DocumentREST(rest_url=self.rest_url,
                base=self.lbbase, response_object=False)


    @property
    def lbbase(self):

        """
        COnfiguração da Coleta
        """

        nome_orgao = Field(**dict(
            name='nome_orgao',
            description='Nome do Órgão',
            alias='nome_orgao',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        nome_relatorio = Field(**dict(
            name='nome_relatorio',
            description='Nome do Relatório',
            alias='nome_relatorio',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        data_coleta = Field(**dict(
            name='data_coleta',
            description='Data da Coleta',
            alias='data_coleta',
            datatype='DateTime',
            indices=['Ordenado'],
            multivalued=False,
            required=True
        ))

        total_computadores = Field(**dict(
            name='total_computadores',
            description='Total de Computadores',
            alias='total_computadores',
            datatype='Integer',
            indices=['Ordenado'],
            multivalued=False,
            required=True
        ))

        nome_item = Field(**dict(
            name='nome_item',
            description='Nome do Item',
            alias='nome_item',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))

        quantidade_item = Field(**dict(
            name='quantidade_item',
            description='Quantidades total do item',
            alias='quantidade_item',
            datatype='Integer',
            indices=['Ordenado'],
            multivalued=False,
            required=True
        ))

        descricao_item = Field(**dict(
            name='descricao_item',
            description='Descrição',
            alias='descricao_item',
            datatype='Text',
            indices=['Textual'],
            multivalued=False,
            required=True
        ))


        """
        GROUP Sistema Operacional
        """
        ItensGroup_content = Content()
        ItensGroup_content.append(nome_item)
        ItensGroup_content.append(quantidade_item)
        ItensGroup_content.append(descricao_item)

        ItensGroup_metadata = GroupMetadata(
            name='ItensGroup',
            alias='ItensGroup',
            description='Grupo de Itens',
            multivalued=True
        )

        ItensGroup = Group(
            metadata=ItensGroup_metadata,
            content=ItensGroup_content
        )

        base_metadata = BaseMetadata(
            name='all_reports'
        )

        content_list = Content()
        content_list.append(nome_orgao)
        content_list.append(nome_relatorio)
        content_list.append(data_coleta)
        content_list.append(total_computadores)
        content_list.append(ItensGroup)

        lbbase = Base(
            metadata=base_metadata,
            content=content_list
        )

        return lbbase

    @property
    def metaclass(self):
        """
        Retorna metaclass para essa base
        """
        return self.lbbase.metaclass()

    def create_base(self):
        """
        Cria base no LB
        """
        self.baserest.response_object = True
        response = self.baserest.create(self.lbbase)
        if response.status_code == 200:
            return self.lbbase
        else:
            return None

    def remove_base(self):
        """
        Remove base from Lightbase
        :param lbbase: LBBase object instance
        :return: True or Error if base was not excluded
        """
        response = self.baserest.delete(self.lbbase)
        if response.status_code == 200:
            return True
        else:
            raise IOError('Error excluding base from LB')

    def is_created(self):
        """
        Retorna se a base já existe
        """
        try:
            self.baserest.response_object = False
            response = self.baserest.get(self.lbbase.metadata.name)
            self.baserest.response_object = True
            return True
        except:
            return False