feat: redirect the output to the client terminal
This commit is contained in:
parent
c050a653d2
commit
78434e0b23
@ -46,18 +46,39 @@ class ActivationDrillClient:
|
|||||||
"""
|
"""
|
||||||
print(banner)
|
print(banner)
|
||||||
|
|
||||||
def run_command(self, cmd: str, capture_output: bool = True, as_user: str = None) -> Tuple[bool, str]:
|
def run_command(self, cmd: str, capture_output: bool = True, as_user: str = None, show_output: bool = False) -> Tuple[bool, str]:
|
||||||
"""Execute shell command and return success status and output"""
|
"""Execute shell command and return success status and output"""
|
||||||
try:
|
try:
|
||||||
if as_user:
|
if as_user:
|
||||||
cmd = f"su - {as_user} -c '{cmd}'"
|
cmd = f"su - {as_user} -c '{cmd}'"
|
||||||
|
|
||||||
if capture_output:
|
if capture_output and not show_output:
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||||
universal_newlines=True, check=False
|
universal_newlines=True, check=False
|
||||||
)
|
)
|
||||||
return result.returncode == 0, result.stdout + result.stderr
|
return result.returncode == 0, result.stdout + result.stderr
|
||||||
|
elif show_output:
|
||||||
|
# Real-time output display
|
||||||
|
print(f"{Colors.DIM} Command output:{Colors.ENDC}")
|
||||||
|
process = subprocess.Popen(
|
||||||
|
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True, bufsize=1
|
||||||
|
)
|
||||||
|
|
||||||
|
output_lines = []
|
||||||
|
while True:
|
||||||
|
line = process.stdout.readline()
|
||||||
|
if not line and process.poll() is not None:
|
||||||
|
break
|
||||||
|
if line:
|
||||||
|
line = line.rstrip()
|
||||||
|
print(f"{Colors.DIM} {line}{Colors.ENDC}")
|
||||||
|
output_lines.append(line)
|
||||||
|
|
||||||
|
return_code = process.poll()
|
||||||
|
print() # Add blank line after command output
|
||||||
|
return return_code == 0, '\n'.join(output_lines)
|
||||||
else:
|
else:
|
||||||
result = subprocess.run(cmd, shell=True, check=False)
|
result = subprocess.run(cmd, shell=True, check=False)
|
||||||
return result.returncode == 0, ""
|
return result.returncode == 0, ""
|
||||||
@ -157,7 +178,7 @@ class ActivationDrillClient:
|
|||||||
|
|
||||||
def check_hana_status(self) -> Tuple[bool, str]:
|
def check_hana_status(self) -> Tuple[bool, str]:
|
||||||
"""Check HANA database status"""
|
"""Check HANA database status"""
|
||||||
success, output = self.run_command("HDB info", as_user="prcadm")
|
success, output = self.run_command("HDB info", as_user="prcadm", show_output=True)
|
||||||
if success and "hdbnameserver" in output.lower():
|
if success and "hdbnameserver" in output.lower():
|
||||||
return True, "HANA is running"
|
return True, "HANA is running"
|
||||||
else:
|
else:
|
||||||
@ -182,23 +203,21 @@ class ActivationDrillClient:
|
|||||||
print(f"\n{Colors.YELLOW}Unregistering from system replication...{Colors.ENDC}")
|
print(f"\n{Colors.YELLOW}Unregistering from system replication...{Colors.ENDC}")
|
||||||
self.show_loading("Unregistering", 4.0)
|
self.show_loading("Unregistering", 4.0)
|
||||||
|
|
||||||
success, output = self.run_command("hdbnsutil -sr_unregister", as_user="prcadm")
|
success, output = self.run_command("hdbnsutil -sr_unregister", as_user="prcadm", show_output=True)
|
||||||
if success:
|
if success:
|
||||||
print(f"{Colors.GREEN}✓ Successfully unregistered from system replication{Colors.ENDC}")
|
print(f"{Colors.GREEN}✓ Successfully unregistered from system replication{Colors.ENDC}")
|
||||||
else:
|
else:
|
||||||
print(f"{Colors.YELLOW}⚠ Unregister command completed with warnings{Colors.ENDC}")
|
print(f"{Colors.YELLOW}⚠ Unregister command completed with warnings{Colors.ENDC}")
|
||||||
print(f"{Colors.DIM}{output[:200]}...{Colors.ENDC}")
|
|
||||||
|
|
||||||
# Start HANA database
|
# Start HANA database
|
||||||
print(f"\n{Colors.YELLOW}Starting HANA database...{Colors.ENDC}")
|
print(f"\n{Colors.YELLOW}Starting HANA database...{Colors.ENDC}")
|
||||||
self.show_loading("Starting database", 8.0)
|
self.show_loading("Starting database", 8.0)
|
||||||
|
|
||||||
success, output = self.run_command("HDB start", as_user="prcadm")
|
success, output = self.run_command("HDB start", as_user="prcadm", show_output=True)
|
||||||
if success:
|
if success:
|
||||||
print(f"{Colors.GREEN}✓ HANA database started successfully{Colors.ENDC}")
|
print(f"{Colors.GREEN}✓ HANA database started successfully{Colors.ENDC}")
|
||||||
else:
|
else:
|
||||||
print(f"{Colors.RED}✗ Failed to start HANA database{Colors.ENDC}")
|
print(f"{Colors.RED}✗ Failed to start HANA database{Colors.ENDC}")
|
||||||
print(f"{Colors.RED}{output[:300]}{Colors.ENDC}")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check database health
|
# Check database health
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user