feat: deepen ops modules and enhance sandbox coverage
This commit is contained in:
19
sandbox.py
19
sandbox.py
@@ -560,6 +560,9 @@ class LinuxSandbox:
|
||||
"kill": "signal sent (simulated)",
|
||||
"pkill": "matched processes terminated (simulated)",
|
||||
"nohup": "appending output to nohup.out",
|
||||
"systemctl": "● nginx.service - A high performance web server\n Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)\n Active: active (running) since Mon 2026-03-06 10:00:00 CST; 5 days ago\n Main PID: 1042 (nginx)\n Tasks: 3\n Memory: 12.5M",
|
||||
"service": "nginx is running",
|
||||
"journalctl": "Mar 06 10:00:00 systemd[1]: Started nginx.service\nMar 06 10:00:01 nginx[1042]: worker process started\nMar 06 10:04:12 nginx[1042]: connect() failed (111: Connection refused)",
|
||||
"ifconfig": "eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500\n inet 192.168.1.20 netmask 255.255.255.0\nlo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536\n inet 127.0.0.1 netmask 255.0.0.0",
|
||||
"ip": "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536\n inet 127.0.0.1/8 scope host lo\n2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500\n inet 192.168.1.20/24 scope global eth0",
|
||||
"ping": "PING 127.0.0.1 (127.0.0.1): 56 data bytes\n64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.025 ms\n--- 127.0.0.1 ping statistics ---\n4 packets transmitted, 4 received, 0% packet loss",
|
||||
@@ -589,12 +592,26 @@ class LinuxSandbox:
|
||||
}
|
||||
if cmd_name == "ip" and args[:1] == ["addr"]:
|
||||
return canned["ip"]
|
||||
if cmd_name == "systemctl":
|
||||
if args[:1] == ["status"]:
|
||||
target = args[1] if len(args) > 1 else 'nginx'
|
||||
return canned["systemctl"].replace('nginx', target)
|
||||
if args[:1] in (["restart"], ["start"], ["stop"], ["reload"], ["enable"]):
|
||||
target = args[1] if len(args) > 1 else 'service'
|
||||
return f"{args[0]} operation completed for {target} (simulated)"
|
||||
return canned["systemctl"]
|
||||
if cmd_name == "service":
|
||||
return canned["service"]
|
||||
if cmd_name == "journalctl":
|
||||
return canned["journalctl"]
|
||||
if cmd_name == "tail" or cmd_name == "head":
|
||||
return self._simulate_head_tail(cmd_name, args)
|
||||
if cmd_name == "which":
|
||||
return canned["which"]
|
||||
if cmd_name == "whereis":
|
||||
return canned["whereis"]
|
||||
if cmd_name == "dig":
|
||||
return canned.get("dig", ";; ANSWER SECTION:\nexample.com. 300 IN A 93.184.216.34")
|
||||
if cmd_name == "export" and args and "=" in args[0]:
|
||||
key, value = args[0].split("=", 1)
|
||||
self.env[key] = value
|
||||
@@ -681,6 +698,8 @@ class LinuxSandbox:
|
||||
output = self.user
|
||||
elif cmd_name == "history":
|
||||
output = self._simulate_history(args)
|
||||
elif cmd_name in {"systemctl", "service", "journalctl", "dig"}:
|
||||
output = self._simulate_system_text(cmd_name, args)
|
||||
else:
|
||||
output = self._simulate_system_text(cmd_name, args)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user