Newer
Older
cortex-hub / ai-hub / app / core / templates / provisioning / provision.py.j2
# Cortex Agent One-Liner Provisioner
import os
import sys
import urllib.request
import subprocess

print("🚀 Starting Cortex Agent Provisioning for node: {{ node_id }}")

# 1. Create .cortex/agent-node directory
install_dir = os.path.expanduser("~/.cortex/agent-node")
os.makedirs(install_dir, exist_ok=True)
os.chdir(install_dir)

# 2. Write agent_config.yaml
print("[*] Writing configuration...")
with open("agent_config.yaml", "w") as f:
    f.write("""{{ config_yaml }}""")

# 3. Download bootstrap_installer.py
print("[*] Downloading installer...")
installer_url = "{{ base_url }}/api/v1/agent/installer"
urllib.request.urlretrieve(installer_url, "bootstrap_installer.py")

# 4. Run installer with --daemon (or --non-interactive)
print("[*] Bootstrapping agent...")
cmd = [
    sys.executable, "bootstrap_installer.py", 
    "--daemon", 
    "--hub", "{{ base_url }}", 
    "--token", "{{ invite_token }}",
    "--node-id", "{{ node_id }}"
]
subprocess.run(cmd)

print("✅ Provisioning complete! Node should be online in the Mesh Dashboard shortly.")