From e5d484f711086fbb70b0e236fe727727831c0cd0 Mon Sep 17 00:00:00 2001 From: Nicola Peditto Date: Mon, 26 Aug 2019 10:48:57 +0200 Subject: [PATCH] Added DeviceMountFs RPC action on device Change-Id: Ia4361451fa9e46f93d78cc6641020e31fc0590df --- .../modules/device_manager.py | 66 +++++++++++++++++++ utils/docker/arm/Dockerfile | 2 +- utils/docker/arm/data/startLR | 10 +++ utils/docker/x86_64/Dockerfile | 2 +- utils/docker/x86_64/data/startLR | 10 +++ 5 files changed, 88 insertions(+), 2 deletions(-) diff --git a/iotronic_lightningrod/modules/device_manager.py b/iotronic_lightningrod/modules/device_manager.py index 4f1b7d6..dc950a9 100644 --- a/iotronic_lightningrod/modules/device_manager.py +++ b/iotronic_lightningrod/modules/device_manager.py @@ -588,6 +588,72 @@ class DeviceManager(Module.Module): return w_msg.serialize() + # SC + async def DeviceMountFs(self, req, parameters=None): + req_id = req['uuid'] + rpc_name = utils.getFuncName() + LOG.info("RPC " + rpc_name + " CALLED [req_id: " + str(req_id) + "]:") + if parameters is not None: + LOG.info(" - " + rpc_name + " parameters: " + str(parameters)) + + def MountFs(): + try: + + # mount_rw|mount_ro|mount_status + action = parameters['action_cmd'] + + if action == "mount_rw": + command = "rootrw" + elif action == "mount_ro": + command = "rootro" + elif action == "mount_status": + command = "cat /proc/mounts" + else: + command = None + + if command == None: + + out = subprocess.Popen( + command, + shell=True, + stdout=subprocess.PIPE + ) + + message = str(out.communicate()[0].decode('utf-8').strip()) + + else: + message = "Mount command '" + str(action) \ + + "' not supported!" + + w_msg = WM.WampSuccess(msg=message, req_id=req_id) + + except Exception as err: + LOG.warning("--> Error in " + rpc_name + ": " + str(err)) + w_msg = WM.WampSuccess(msg=message, req_id=req_id) + + if (req['main_request_uuid'] != None): + wampNotify(self.device_session, + self.board, w_msg.serialize(), rpc_name) + else: + return w_msg + + if (req['main_request_uuid'] != None): + + LOG.info(" - main request: " + str(req['main_request_uuid'])) + try: + threading.Thread(target=MountFs).start() + w_msg = WM.WampRunning(msg=rpc_name, req_id=req_id) + + except Exception as err: + message = "Error in thr_" + rpc_name + ": " + str(err) + LOG.error(message) + w_msg = WM.WampError(msg=message, req_id=req_id) + + else: + w_msg = MountFs() + + return w_msg.serialize() + # SC async def DeviceNetConfig(self, req, parameters=None): req_id = req['uuid'] diff --git a/utils/docker/arm/Dockerfile b/utils/docker/arm/Dockerfile index 5e4315a..98dd299 100755 --- a/utils/docker/arm/Dockerfile +++ b/utils/docker/arm/Dockerfile @@ -5,7 +5,7 @@ ENV DEBIAN_FRONTEND=noninteractive RUN chmod -R 777 /tmp/ RUN apt-get update && apt-get install -y \ - software-properties-common socat dsniff git ntpdate python build-essential vim lsof gdb screen python3 python3-setuptools python3-pip npm net-tools + software-properties-common socat dsniff git ntpdate python build-essential vim lsof gdb screen python3 python3-setuptools python3-pip npm net-tools libffi-dev RUN add-apt-repository ppa:certbot/certbot diff --git a/utils/docker/arm/data/startLR b/utils/docker/arm/data/startLR index ce0b9cb..7366bad 100755 --- a/utils/docker/arm/data/startLR +++ b/utils/docker/arm/data/startLR @@ -1,5 +1,15 @@ #!/bin/bash +# Upgrade procedures +TEST_U=`cat /etc/iotronic/iotronic.conf | grep autobahn` + +if [ "$TEST_U" = "" ]; then + cp /usr/local/lib/python3.6/dist-packages/iotronic_lightningrod/etc/iotronic/iotronic.conf /etc/iotronic/iotronic.conf + echo "iotronic configuration updated." +else + echo "Already updated." +fi + # Start the first process /usr/sbin/nginx status=$? diff --git a/utils/docker/x86_64/Dockerfile b/utils/docker/x86_64/Dockerfile index fa839d0..ad9e4c0 100644 --- a/utils/docker/x86_64/Dockerfile +++ b/utils/docker/x86_64/Dockerfile @@ -5,7 +5,7 @@ ENV DEBIAN_FRONTEND=noninteractive RUN chmod -R 777 /tmp/ RUN apt-get update && apt-get install -y \ - software-properties-common socat dsniff git ntpdate python build-essential lsof gdb screen python3 python3-setuptools python3-pip npm net-tools + software-properties-common socat dsniff git ntpdate python build-essential lsof gdb screen python3 python3-setuptools python3-pip npm net-tools libffi-dev RUN add-apt-repository ppa:certbot/certbot diff --git a/utils/docker/x86_64/data/startLR b/utils/docker/x86_64/data/startLR index ce0b9cb..7366bad 100755 --- a/utils/docker/x86_64/data/startLR +++ b/utils/docker/x86_64/data/startLR @@ -1,5 +1,15 @@ #!/bin/bash +# Upgrade procedures +TEST_U=`cat /etc/iotronic/iotronic.conf | grep autobahn` + +if [ "$TEST_U" = "" ]; then + cp /usr/local/lib/python3.6/dist-packages/iotronic_lightningrod/etc/iotronic/iotronic.conf /etc/iotronic/iotronic.conf + echo "iotronic configuration updated." +else + echo "Already updated." +fi + # Start the first process /usr/sbin/nginx status=$?