def init_db_data(host: str, port: int, root_password: str, db_name: str, xml_files: Optional[List[str]] = None, client: OrientDB = None) -> pyorient.OrientDB: if xml_files is not None: for filepath in xml_files: load_xml_into_db(host, port, root_password, filepath, db_name) if client is None: client = pyorient.OrientDB(host, port) client.connect('root', root_password) if client.db_exists(db_name): client.db_open(db_name, 'admin', 'admin') else: client.db_create(db_name, pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_MEMORY) client.db_open(db_name, 'admin', 'admin') client.command('CREATE CLASS BBNEvaluationInput EXTENDS V') client.command('CREATE PROPERTY BBNEvaluationInput.jsonData STRING') client.command('CREATE CLASS BBNEvaluationOutput EXTENDS V') client.command('CREATE PROPERTY BBNEvaluationOutput.jsonData STRING') client.command('CREATE PROPERTY BBNEvaluationOutput.finalState STRING') client.command('CREATE PROPERTY BBNEvaluationOutput.finalStateInfo STRING') # client.coommand('CREATE CLASS DAUInventory EXTENDS V') return client
def _init_db_data(self, db_name: str, xml_files: Optional[List[str]] = None, client: pyorient.OrientDB = None) -> pyorient.OrientDB: if xml_files is not None: for filepath in xml_files: json.dump(self.config, open(SWRI_CONFIG_FILE, 'w'), indent=4) importer = OrientDBXMLImporter(databaseName=db_name, configFile=SWRI_CONFIG_FILE, mdlFile=filepath) importer.import_xml() importer.orientDB_helper.close_database() if client is None: client = pyorient.OrientDB(self.host, self.port) client.connect('root', self.root_password) if client.db_exists(db_name): client.db_open(db_name, 'admin', 'admin') else: client.db_create(db_name, pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_MEMORY) client.db_open(db_name, 'admin', 'admin') client.command('CREATE CLASS BBNEvaluationData EXTENDS V') client.command( 'CREATE PROPERTY BBNEvaluationData.inputJsonData STRING') client.command( 'CREATE PROPERTY BBNEvaluationData.outputJsonData STRING') client.command('CREATE PROPERTY BBNEvaluationData.currentState STRING') client.command( 'CREATE PROPERTY BBNEvaluationData.currentStateInfo STRING') return client
def main(): argument_spec = dict( host=dict(required=True), port=dict(type=int, default=2424), user=dict(default="root"), password=dict(default="root", no_log=True), database=dict(), storage_type=dict(choices=["plocal", "memory"]), db_list=dict(type=bool), db_size=dict(type=bool), db_exists=dict(type=bool), db_count_records=dict(type=bool), check_default_credentials=dict(type=bool), ) module = AnsibleModule( argument_spec=argument_spec, required_if=( ("db_size", True, ["database"]), ("db_exists", True, ["database", "storage_type"]), ("db_count_records", True, ["database"]), ), mutually_exclusive=[( "db_list", "db_size", "db_exists", "db_count_records", "check_default_credentials", )], ) client = OrientDB(host=module.params["host"], port=module.params["port"]) try: client.connect(user=module.params["user"], password=module.params["password"]) if module.params["db_list"]: module.exit_json( databases=client.db_list().__getattr__("databases")) elif module.params["db_size"]: client.db_open( module.params["database"], module.params["user"], module.params["password"], ) module.exit_json(size=client.db_size()) elif module.params["db_exists"]: module.exit_json(exist=client.db_exists( module.params["database"], type=module.params["storage_type"])) elif module.params["db_count_records"]: client.db_open( module.params["database"], module.params["user"], module.params["password"], ) module.exit_json(count=client.db_count_records()) elif module.params["check_default_credentials"]: _db_list = [] # Check for Default Login for i in client.db_list().__getattr__("databases"): try: client.db_open(i, "admin", "admin") _db_list.append(i) client.db_close() except: # nopep8 #nosec pass module.exit_json(default_credential_dbs=_db_list) else: module.fail_json(msg="unknown options are passed") except Exception as e: module.fail_json(msg=str(e)) finally: client.db_close()
try: print("here") socket.connect() client = OrientDB(socket) session_id = client.connect("root", "password") #get session id client.db_open("test", "root", "password") #open db for item in db_atributes.orient_classes( ): #create a classes and atributes of new class if not exists based on db atributes file client.command("CREATE CLASS " + item['name'] + " IF NOT EXISTS EXTENDS " + item['classType']) for prop in item['atributes']: client.command("CREATE PROPERTY " + item['name'] + "." + prop['name'] + " IF NOT EXISTS " + prop['types']) except Exception as e: print(e) socket.connect() client = OrientDB(socket) session_id = client.connect("root", "password") #get session id if not client.db_exists( "test" ): #if exeption is for non created db lets create the db and classes with atributes based on db_atributes file client.db_create("test", pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_PLOCAL) client.db_open("test", "root", "password") for item in db_atributes.orient_classes(): client.command("CREATE CLASS " + item['name'] + " IF NOT EXISTS EXTENDS " + item['classType']) for prop in item['atributes']: client.command("CREATE PROPERTY " + item['name'] + "." + prop['name'] + " IF NOT EXISTS " + prop['types'])