-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd: add export-db as a flux account command
Problem: The "export-db" command is located in a separate file in the src/cmd/ directory and thus requires a different method of calling it than the other flux-accounting commands, i.e you need to write "flux account-export-db" instead of "flux account export-db". Move this file to the directory containing the other Python bindings for flux-accounting and add it as a regular command like the other bindings so that you can just call it like "flux account export-db". Remove the methods and command line argument that deal with establishing a connection to the flux-accounting DB since the systemd service will handle establishing that connection. Adjust the calls in the sharness test and top-level README for export-db to account for the change.
- Loading branch information
Showing
8 changed files
with
117 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/bindings/python/fluxacct/accounting/db_info_subcommands.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python3 | ||
|
||
############################################################### | ||
# Copyright 2024 Lawrence Livermore National Security, LLC | ||
# (c.f. AUTHORS, NOTICE.LLNS, COPYING) | ||
# | ||
# This file is part of the Flux resource manager framework. | ||
# For details, see https://github.com/flux-framework. | ||
# | ||
# SPDX-License-Identifier: LGPL-3.0 | ||
############################################################### | ||
import csv | ||
|
||
|
||
def export_db_info(conn, users=None, banks=None): | ||
try: | ||
cur = conn.cursor() | ||
select_users_stmt = """ | ||
SELECT username, userid, bank, shares, max_running_jobs, max_active_jobs, | ||
max_nodes, queues FROM association_table | ||
""" | ||
cur.execute(select_users_stmt) | ||
table = cur.fetchall() | ||
|
||
# open a .csv file for writing | ||
users_filepath = users if users else "users.csv" | ||
users_file = open(users_filepath, "w") | ||
with users_file: | ||
writer = csv.writer(users_file) | ||
|
||
for row in table: | ||
writer.writerow(row) | ||
|
||
select_banks_stmt = """ | ||
SELECT bank, parent_bank, shares FROM bank_table | ||
""" | ||
cur.execute(select_banks_stmt) | ||
table = cur.fetchall() | ||
|
||
banks_filepath = banks if banks else "banks.csv" | ||
banks_file = open(banks_filepath, "w") | ||
with banks_file: | ||
writer = csv.writer(banks_file) | ||
|
||
for row in table: | ||
writer.writerow(row) | ||
except IOError as err: | ||
print(err) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters