acrn-hypervisor/misc/services/life_mngr/s5_trigger_win.py
Xiangyang Wu e297839fc3 misc: life_mngr: refine lifecycle manager for windows VM
Refine lifecycle manager for windows VM since new commands
are introduced in the lifecycle manager.

v1-->v2:
	Implement socket service to receive system shutdown
	request command through local host socket.
	Add one python script to trigger system shutdown
	request in windows VM.
v2-->v3:
	Update log message.
v3-->v4:
	Support guest shutdown.
v4-->v5:
	Update command name.
v5-->v7:
	Add resend message logic.

Tracked-On: #6652

Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com>
Reviewed-by: fei1.li@intel.com
2021-11-12 11:04:23 +08:00

37 lines
839 B
Python

#!/usr/bin/env python3
#
# Copyright (C) 2021 Intel Corporation.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import socket
import sys
if __name__ == "__main__":
HOST = '127.0.0.1'
PORT = 8193
SHUTDOWN_REQ = 'req_sys_shutdown'
MSG_LEN = 32
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print(["Socket Created"])
try:
s.connect((HOST,PORT))
print("[Connection established]")
except Exception:
print('[Connection error: ' + HOST + ":" + str(PORT)+']')
s.close()
try:
s.send(SHUTDOWN_REQ.encode('utf-8'))
except Exception as _:
raise _
print(["Shutdown request sent\n"])
try:
data_input = (s.recv(MSG_LEN).decode("UTF-8"))
except Exception:
pass
print("Waiting for ACK message...: ", data_input)
s.close()