#!/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 cluster { id name } logicalPath { fid name objectType } } } } """ # Variables: exclude relics and replicated databases variables = { "filter": [ { "texts": ["false"], "field": "IS_RELIC" }, { "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 ]) # Print tabulated output headers = ['Database Name', 'ID', 'Cluster', 'Host'] 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)