Getting there
This commit is contained in:
61
rsc.py
61
rsc.py
@@ -2,6 +2,7 @@ import json
|
||||
import os
|
||||
import time
|
||||
import requests
|
||||
import socket
|
||||
|
||||
class RSCAuth:
|
||||
def __init__(self, config_file='rsc.json'):
|
||||
@@ -102,6 +103,66 @@ class RSCGraphQL:
|
||||
|
||||
return data
|
||||
|
||||
def get_local_database_id(self):
|
||||
"""Get the ID of the local database on this host, preferring one protected by SLA"""
|
||||
hostname = socket.gethostname()
|
||||
|
||||
query = """
|
||||
query OracleDatabases($filter: [Filter!]) {
|
||||
oracleDatabases(filter: $filter) {
|
||||
nodes {
|
||||
id
|
||||
dbUniqueName
|
||||
isRelic
|
||||
effectiveSlaDomain {
|
||||
id
|
||||
name
|
||||
}
|
||||
cluster {
|
||||
id
|
||||
name
|
||||
}
|
||||
logicalPath {
|
||||
fid
|
||||
name
|
||||
objectType
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
variables = {
|
||||
"filter": [
|
||||
{"texts": ["false"], "field": "IS_REPLICATED"}
|
||||
]
|
||||
}
|
||||
|
||||
response = self.query(query, variables)
|
||||
all_dbs = response['data']['oracleDatabases']['nodes']
|
||||
|
||||
# Filter databases on this host
|
||||
dbs = [db for db in all_dbs if db['logicalPath'] and db['logicalPath'][0]['name'] == hostname]
|
||||
|
||||
if not dbs:
|
||||
raise ValueError(f"No databases found on host {hostname}")
|
||||
|
||||
# Filter databases with SLA protection
|
||||
protected_dbs = [db for db in dbs if db.get('effectiveSlaDomain')]
|
||||
|
||||
if protected_dbs:
|
||||
if len(protected_dbs) == 1:
|
||||
return protected_dbs[0]['id']
|
||||
else:
|
||||
# Multiple protected, use the first one with a warning
|
||||
print(f"WARN: Multiple protected databases on {hostname}, using {protected_dbs[0]['dbUniqueName']}")
|
||||
return protected_dbs[0]['id']
|
||||
else:
|
||||
if len(dbs) == 1:
|
||||
return dbs[0]['id']
|
||||
else:
|
||||
raise ValueError(f"Multiple databases on {hostname}, none protected by SLA")
|
||||
|
||||
def introspect_schema(self):
|
||||
"""Introspect the GraphQL schema to get type information"""
|
||||
introspection_query = """
|
||||
|
||||
Reference in New Issue
Block a user