[lxc-users] (no subject)

alexandros giavaras a.giavaras at gmail.com
Sat Jan 18 14:53:52 UTC 2020


Hi all, (sorry for double posting the previous email was accidentally sent )

I have been using pylxd to interact LXD REST API. I create a container and
then send
the /bin/bash cmd using the raw_interactive_execute function.
Concretely here is my function call

res = container.raw_interactive_execute(['/bin/bash', ],
environment={"TERM":"xterm"})
I got back the websocket secret and the control. So far so good. I am
opening a websocket to
interact with the container as follows:

websocket.enableTrace(False)
ws = websocket.WebSocketApp(uri,
                                    on_message=on_message,
                                    on_error=on_error,
                                    on_close=on_close,
                                    on_open=on_open)

    ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}, ping_interval=0,
ping_timeout=0)
    ws.close()

Here is also the on_open

def on_open(ws):
     def run(*args):

               while True:
                      cmd = get_user_input()
                      cmd += "\r"
                      print("Sending CMD: ", cmd)
                      cmd = bytearray(cmd, encoding='utf-8')
                      ws.send(cmd, opcode=2)
                      time.sleep(1)

                   print("Closing connection...")
                   ws.close()
                    print("thread terminating...")
        thread.start_new_thread(run, ())

I then open the control as follows

uri = 'some_uri_generated'
websocket.enableTrace(False)
ws = websocket.WebSocketApp(uri,
                                                   on_message=on_message,
                                                   on_error=on_error,
                                                   on_close=on_close)

ws.on_open = on_open
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}, ping_interval=0,
ping_timeout=0)

where the on_open now is

def on_open(ws):
    def run(*args):
        print("Connected....")

        while True:

            cmd = get_user_input()
            cmd = cmd.lstrip()
            cmd = cmd.rstrip()
            if cmd == 'Exit':
                break

            width = cmd.split(',')[0]
            height = cmd.split(',')[1]

            data = "{'command':'window-resize'," \
                                "'args':'{'width': '%s', " \
                                "'height':'%s'}}'" % (width, height)

            print("control data: ", data)
            cmd = bytearray(data, encoding='utf-8')
            ws.send(data, opcode=2)
            #ws.send(data)
            time.sleep(1)

        print("Closing connection...")
        ws.close()
        print("thread terminating...")
    thread.start_new_thread(run, ())

I then fire up two terminals. One that runs the interaction with the
container and one that has the control. However when I sent the control
with some given width and height and then go on the interaction terminal
and send tput cols or tput lines nothing has changed. Am I missing sth here
or I am doing sth completely wrong and meaningless?

Thanks in advance and I am sorry for double posting.
Best
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20200118/2c812f02/attachment.html>


More information about the lxc-users mailing list