William Pitcock avatar William Pitcock committed 9475a58

Add examples.

Comments (0)

Files changed (2)

examples/edia-console.py

+#!/usr/bin/env python
+#
+# A proof of concept console client running over the TortoiseLabs Cloud RPC layer.
+# We publish a Xen event-channel onto the RPC layer, and then can manipulate it by
+# reading and writing the event-channel.  This is wrapped for security reasons, to
+# restrict to just the console event-channel on the RPC server, but the same code
+# could be used for any event-channel, such as network or block i/o, allowing for
+# example, a network device that tunnels back to the customer over RPC messaging,
+# or a block i/o device that works the same way, or perhaps a file system exposed
+# via event-channel somehow.
+#
+
+import sys
+import select
+import termios
+import tty
+import re
+
+from ediarpc import rpc_client
+
+if len(sys.argv) < 4:
+    print "usage: %s hostname secret domain" % sys.argv[0]
+    exit()
+
+hostname = sys.argv[1]
+secret = sys.argv[2].encode('ascii')
+domname = sys.argv[3]
+
+print "Attempting to attach to console of VPS %s on host %s with secret %s" % (domname, hostname, secret)
+
+cli = rpc_client.ServerProxy(hostname, 5959, secret, True, iterations=15)
+
+strip_vt1_rx = re.compile('\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]')
+strip_vt2_rx = re.compile('[\x03|\x1a]')
+
+def can_read_pty(pty):
+    return select.select([pty], [], [], 0) == ([pty], [], [])
+
+def write_to_console(cli, pty):
+    data = []
+
+    while True:
+        if can_read_pty(pty) is False:
+            break
+        data.append(pty.read(1))
+
+    if len(data) > 0:
+        bytes = ''.join(data)
+        bytes = strip_vt1_rx.sub('', bytes)
+        bytes = strip_vt1_rx.sub('', bytes)
+        bytes = strip_vt2_rx.sub('', bytes)
+        cli.console_write(domname=domname, bytes=bytes)
+
+old_settings = termios.tcgetattr(sys.stdin)
+try:
+    tty.setraw(sys.stdin.fileno())
+
+    while True:
+        data = cli.console_read(domname=domname, bytes=4096)
+        csd = data['console_data']
+        csd = strip_vt1_rx.sub('', csd)
+        csd = strip_vt1_rx.sub('', csd)
+        csd = strip_vt2_rx.sub('', csd)
+        sys.stdout.write(csd)
+        write_to_console(cli, sys.stdin)
+finally:
+    termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)

examples/edia-domainlist.py

+from ediarpc import rpc_client
+from pprint import pprint
+cli = rpc_client.ServerProxy('142.4.218.16', 5959, 'moocows'.encode('ascii'), True, iterations=15)
+
+print "Calling domain_list() RPC on bhs0"
+list = cli.domain_list()
+
+for domain, stats in list.items():
+    print domain
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.