def generate_resource_config(resource_id, m_resource_name, queuing_system): from akrr.util.sql import cursor_execute log.info("Initiating %s at AKRR" % (m_resource_name, )) if not akrr.dry_run: os.mkdir(os.path.join(resources_dir, m_resource_name), 0o700) file_path = os.path.abspath( os.path.join(resources_dir, m_resource_name, 'resource.conf')) global resource_cfg_filename resource_cfg_filename = file_path create_resource_config(file_path, queuing_system) # add entry to mod_appkernel.resource con_ak, cur_ak = akrr.db.get_ak_db(True) cur_ak.execute('''SELECT * FROM resource WHERE nickname=%s''', (m_resource_name, )) resource_in_ak_db = cur_ak.fetchall() if len(resource_in_ak_db) == 0: cursor_execute( cur_ak, "INSERT INTO resource (resource,nickname,description,enabled,visible,xdmod_resource_id)" "VALUES(%s,%s,%s,0,0,%s);", (m_resource_name, m_resource_name, m_resource_name, resource_id), akrr.dry_run) con_ak.commit() cur_ak.execute('''SELECT * FROM resource WHERE nickname=%s''', (m_resource_name, )) if not akrr.dry_run: resource_in_ak_db = cur_ak.fetchall() resource_id_in_ak_db = resource_in_ak_db[0]['resource_id'] else: resource_id_in_ak_db = 123 # add entry to mod_akrr.resource db, cur = akrr.db.get_akrr_db(True) cur.execute('''SELECT * FROM resources WHERE name=%s''', (m_resource_name, )) resource_in_db = cur.fetchall() if len(resource_in_db) == 0: cursor_execute( cur, '''INSERT INTO resources (id,xdmod_resource_id,name,enabled) VALUES(%s,%s,%s,%s);''', (resource_id_in_ak_db, resource_id, m_resource_name, 0), akrr.dry_run) db.commit() log.info("Resource configuration is in " + file_path)
def _cursor_execute(cur, query, args=None): from akrr.util.sql import cursor_execute cursor_execute(cur, query, args=args, dry_run=akrr.dry_run)