Files
oracle-livemount-python/list_oracle_databases.py
2025-11-25 10:51:26 -05:00

84 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
import json
import sys
import os
from rsc import RSCAuth, RSCGraphQL
from tabulate import tabulate
def list_oracle_databases():
# Initialize auth
auth = RSCAuth()
# Initialize GraphQL client
gql = RSCGraphQL(auth)
# GraphQL query to list Oracle databases
query = """
query OracleDatabases($filter: [Filter!]) {
oracleDatabases(filter: $filter) {
nodes {
dbUniqueName
id
isRelic
cluster {
id
name
}
logicalPath {
fid
name
objectType
}
}
}
}
"""
# Variables: exclude replicated databases only
variables = {
"filter": [
{
"texts": ["false"],
"field": "IS_REPLICATED"
}
]
}
# Execute query
response = gql.query(query, variables)
# Parse and display results
databases = response['data']['oracleDatabases']['nodes']
if not databases:
print("No Oracle databases found.")
return
# Prepare data for tabulation
table_data = []
for db in databases:
cluster_name = db['cluster']['name'] if db['cluster'] else 'Unknown'
host_name = 'Unknown'
if db['logicalPath'] and len(db['logicalPath']) > 0:
# For standalone DBs, logicalPath[0] is typically the host
host_name = db['logicalPath'][0]['name']
table_data.append([
db['dbUniqueName'],
db['id'],
cluster_name,
host_name,
'Yes' if db['isRelic'] else 'No'
])
# Print tabulated output
headers = ['Database Name', 'ID', 'Cluster', 'Host', 'Relic']
print(tabulate(table_data, headers=headers, tablefmt='grid'))
if __name__ == "__main__":
try:
list_oracle_databases()
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)