muse-chat-api.py: unified naming, node==agent
This commit is contained in:
+10
-8
@@ -19,15 +19,15 @@ See ACCOUNTS.md for the full registry.
|
|||||||
"""
|
"""
|
||||||
import json, urllib.request, websocket, time, sys, argparse
|
import json, urllib.request, websocket, time, sys, argparse
|
||||||
|
|
||||||
# Maps agent name -> CDP URL. The agent name IS the node name.
|
# Maps agent name -> (node, CDP URL). Agent == node == profile.
|
||||||
# TODO: Rename smoke node to 'muse', phone-test to 'pip' for full unification.
|
|
||||||
# For now, map the unified names to the existing node CDP ports.
|
|
||||||
ACCOUNTS = {
|
ACCOUNTS = {
|
||||||
"muse": "http://127.0.0.1:9410/json/list", # node: smoke (TODO: rename to muse)
|
"muse": ("muse", "http://127.0.0.1:9410/json/list"),
|
||||||
"pip": "http://127.0.0.1:9420/json/list", # node: phone-test (TODO: rename to pip)
|
"pip": ("pip", "http://127.0.0.1:9420/json/list"),
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_page(cdp_url):
|
def get_page(node, cdp_url):
|
||||||
|
# Run from within the node's netns via netvm-exec
|
||||||
|
# For now, assume we're already in the netns (called via netvm-exec.sh)
|
||||||
with urllib.request.urlopen(cdp_url, timeout=5) as r:
|
with urllib.request.urlopen(cdp_url, timeout=5) as r:
|
||||||
ts = json.load(r)
|
ts = json.load(r)
|
||||||
pages = [t for t in ts if t.get('type') == 'page']
|
pages = [t for t in ts if t.get('type') == 'page']
|
||||||
@@ -84,8 +84,10 @@ def main():
|
|||||||
p.add_argument('arg', nargs='?', default=None)
|
p.add_argument('arg', nargs='?', default=None)
|
||||||
args = p.parse_args()
|
args = p.parse_args()
|
||||||
|
|
||||||
cdp_url = ACCOUNTS[args.account]
|
node, cdp_url = ACCOUNTS[args.account]
|
||||||
page = get_page(cdp_url)
|
# Note: Must be run via: netvm-exec.sh <node> -- python3 muse-chat-api.py ...
|
||||||
|
# The node name matches the account name.
|
||||||
|
page = get_page(node, cdp_url)
|
||||||
ws = websocket.create_connection(page['webSocketDebuggerUrl'], timeout=15)
|
ws = websocket.create_connection(page['webSocketDebuggerUrl'], timeout=15)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user