75 lines
3.2 KiB
Python
75 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Read-only feasibility report for the proposed isolated OpenWrt lab."""
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def main():
|
|
host = os.environ.get('LAB_PIMOX_HOST', '192.168.100.80')
|
|
user = os.environ.get('LAB_PIMOX_USER', 'jv')
|
|
key = os.environ.get('LAB_PIMOX_SSH_KEY_PATH', '/home/jv/.ssh/id_ed25519')
|
|
remote = '''set -eu
|
|
printf '%s\\n' '---vms---'
|
|
sudo -n qm list
|
|
printf '%s\\n' '---containers---'
|
|
sudo -n pct list
|
|
printf '%s\\n' '---bridges---'
|
|
ip -brief link show type bridge
|
|
printf '%s\\n' '---storage---'
|
|
sudo -n pvesm status --content rootdir
|
|
printf '%s\\n' '---data---'
|
|
findmnt -rn -M /data -o SOURCE,FSTYPE,OPTIONS
|
|
printf '%s\\n' '---architecture---'
|
|
uname -m
|
|
'''
|
|
try:
|
|
result = subprocess.run(['ssh', '-T', '-i', key, '-o', 'BatchMode=yes',
|
|
'-o', 'IdentitiesOnly=yes', '-o', 'ConnectTimeout=10',
|
|
'-o', 'StrictHostKeyChecking=accept-new',
|
|
f'{user}@{host}', remote],
|
|
capture_output=True, text=True, timeout=45, check=True)
|
|
sections = {}
|
|
section = None
|
|
for line in result.stdout.splitlines():
|
|
if line.startswith('---') and line.endswith('---'):
|
|
section = line.strip('-')
|
|
sections[section] = []
|
|
elif section:
|
|
sections[section].append(line)
|
|
if set(sections) != {'vms', 'containers', 'bridges', 'storage', 'data', 'architecture'}:
|
|
raise ValueError('Incomplete host report')
|
|
guests = {}
|
|
for kind in ('vms', 'containers'):
|
|
guests[kind] = [line.split()[:3] for line in sections[kind]
|
|
if line.split() and line.split()[0].isdigit()]
|
|
report = {
|
|
'mode': 'read-only planning; guests are provisioned separately and start offline',
|
|
'host_architecture': ' '.join(sections['architecture']),
|
|
'proposed_vm': {'id': 9100, 'role': 'OpenWrt router'},
|
|
'proposed_containers': [{'id': 9110, 'vlan': 10}, {'id': 9111, 'vlan': 20}],
|
|
'guest_ids_in_use': [entry for values in guests.values() for entry in values
|
|
if entry[0] in {'9100', '9110', '9111'}],
|
|
'bridge_inventory': sections['bridges'],
|
|
'container_storage': sections['storage'],
|
|
'data_mount': sections['data'],
|
|
'requirements': [
|
|
'Dedicated bridge without physical ports; preserve vmbr0 and vmbr1',
|
|
'Explicit sandbox guest identity and cluster-runtime guard changes',
|
|
'ARM64 Alpine template compatibility on this Pimox/LXC version',
|
|
'Dedicated SSD storage supporting container root filesystems',
|
|
'OpenWrt firewall blocking home, cluster, and tailnet networks',
|
|
'Guest provisioning, lifecycle, isolation and recovery validation',
|
|
],
|
|
}
|
|
print(json.dumps(report, indent=2))
|
|
except (OSError, ValueError, subprocess.SubprocessError) as exc:
|
|
print(f'Network sandbox plan failed: {exc}', file=sys.stderr)
|
|
return 1
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|