Added Cloud Service Manager
Change-Id: Ica5ecd82517e4f6c24a324f0ba1d42fce4ea70fb
This commit is contained in:
parent
1fd573e3b2
commit
b817d23bd5
|
@ -43,6 +43,7 @@ class Board(object):
|
||||||
self.mobile = None
|
self.mobile = None
|
||||||
self.session = None
|
self.session = None
|
||||||
self.session_id = None
|
self.session_id = None
|
||||||
|
self.agent_url = None
|
||||||
|
|
||||||
self.location = {}
|
self.location = {}
|
||||||
|
|
||||||
|
@ -141,6 +142,7 @@ class Board(object):
|
||||||
)
|
)
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
|
||||||
|
# self.agent_url = str(self.wamp_config['url'])
|
||||||
LOG.info(' - agent: ' + str(self.agent))
|
LOG.info(' - agent: ' + str(self.agent))
|
||||||
LOG.info(' - url: ' + str(self.wamp_config['url']))
|
LOG.info(' - url: ' + str(self.wamp_config['url']))
|
||||||
LOG.info(' - realm: ' + str(self.wamp_config['realm']))
|
LOG.info(' - realm: ' + str(self.wamp_config['realm']))
|
||||||
|
|
|
@ -601,6 +601,24 @@ class WampManager(object):
|
||||||
component.start(loop)
|
component.start(loop)
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
|
|
||||||
|
"""
|
||||||
|
# TEMPORARY ------------------------------------------------------
|
||||||
|
from subprocess import call
|
||||||
|
LOG.debug("Unmounting...")
|
||||||
|
|
||||||
|
try:
|
||||||
|
mountPoint = "/opt/BBB"
|
||||||
|
# errorCode = self.libc.umount(mountPoint, None)
|
||||||
|
errorCode = call(["umount", "-l", mountPoint])
|
||||||
|
|
||||||
|
LOG.debug("Unmount " + mountPoint + " result: " + str(errorCode))
|
||||||
|
|
||||||
|
except Exception as msg:
|
||||||
|
result = "Unmounting error:", msg
|
||||||
|
LOG.debug(result)
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
"""
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
LOG.info("Stopping WAMP agent server...")
|
LOG.info("Stopping WAMP agent server...")
|
||||||
# Canceling pending tasks and stopping the loop
|
# Canceling pending tasks and stopping the loop
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
# Copyright 2017 MDSLAB - University of Messina
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
__author__ = "Nicola Peditto <npeditto@unime.it"
|
||||||
|
|
||||||
|
import inspect
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
|
import subprocess
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from iotronic_lightningrod.modules import Module
|
||||||
|
from iotronic_lightningrod.modules import utils
|
||||||
|
|
||||||
|
import iotronic_lightningrod.wampmessage as WM
|
||||||
|
|
||||||
|
|
||||||
|
from oslo_log import log as logging
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceManager(Module.Module):
|
||||||
|
|
||||||
|
def __init__(self, board, session):
|
||||||
|
super(ServiceManager, self).__init__("ServiceManager", board)
|
||||||
|
|
||||||
|
def finalize(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def ServiceEnable(self, name, public_port, local_port):
|
||||||
|
|
||||||
|
LOG.info("RPC " + utils.getFuncName()
|
||||||
|
+ " CALLED for " + name + " service:")
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
url_ip = urlparse(self.board.wamp_config["url"])[1].split(':')[0]
|
||||||
|
|
||||||
|
# "wstun -r6030:127.0.0.1:22 ws://192.168.17.103:8080"
|
||||||
|
opt_reverse = "-r" + str(public_port) + ":127.0.0.1:" \
|
||||||
|
+ str(local_port)
|
||||||
|
wagent_url = "ws://" + url_ip + ":8080"
|
||||||
|
|
||||||
|
wstun = subprocess.Popen(
|
||||||
|
['/usr/bin/wstun', opt_reverse, wagent_url],
|
||||||
|
stdout=subprocess.PIPE
|
||||||
|
)
|
||||||
|
|
||||||
|
LOG.debug(" - WSTUN stdout: " + str(wstun.stdout))
|
||||||
|
|
||||||
|
message = "Cloud service " + str(name) + " exposed on port " \
|
||||||
|
+ str(public_port) + " on " + url_ip
|
||||||
|
|
||||||
|
LOG.info(" - " + message + " with PID " + str(wstun.pid))
|
||||||
|
|
||||||
|
w_msg = WM.WampSuccess([wstun.pid, message])
|
||||||
|
|
||||||
|
except Exception as err:
|
||||||
|
message = "Error exposing " + str(name) + " service: " + str(err)
|
||||||
|
LOG.error(" - " + message)
|
||||||
|
w_msg = WM.WampError(message)
|
||||||
|
|
||||||
|
return w_msg.serialize()
|
||||||
|
|
||||||
|
async def ServiceDisable(self, name, pid):
|
||||||
|
|
||||||
|
LOG.info("RPC " + utils.getFuncName() + " CALLED for "
|
||||||
|
+ name + " service:")
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
os.kill(pid, signal.SIGKILL)
|
||||||
|
|
||||||
|
message = "Cloud service " + str(name) + " disabled."
|
||||||
|
|
||||||
|
LOG.info(" - " + message)
|
||||||
|
w_msg = WM.WampSuccess(message)
|
||||||
|
|
||||||
|
except Exception as err:
|
||||||
|
message = "Error disabling " + str(name) + " service: " + str(err)
|
||||||
|
LOG.error(" - " + message)
|
||||||
|
w_msg = WM.WampError(message)
|
||||||
|
|
||||||
|
return w_msg.serialize()
|
||||||
|
|
||||||
|
async def ServiceRestore(self, name, public_port, local_port, pid):
|
||||||
|
|
||||||
|
LOG.info("RPC " + utils.getFuncName() + " CALLED for "
|
||||||
|
+ name + " service:")
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
# 1. Kill wstun process (if exists)
|
||||||
|
try:
|
||||||
|
os.kill(pid, signal.SIGKILL)
|
||||||
|
LOG.info(" - service " + name + " with PID " + str(pid)
|
||||||
|
+ " killed.")
|
||||||
|
except OSError:
|
||||||
|
LOG.warning(" - WSTUN process already killed: "
|
||||||
|
"creating new one...")
|
||||||
|
|
||||||
|
# 2. Create the reverse tunnel
|
||||||
|
url_ip = urlparse(self.board.wamp_config["url"])[1].split(':')[0]
|
||||||
|
opt_reverse = "-r" + str(public_port) + ":127.0.0.1:" + str(
|
||||||
|
local_port)
|
||||||
|
wagent_url = "ws://" + url_ip + ":8080"
|
||||||
|
wstun = subprocess.Popen(
|
||||||
|
['/usr/bin/wstun', opt_reverse, wagent_url],
|
||||||
|
stdout=subprocess.PIPE
|
||||||
|
)
|
||||||
|
|
||||||
|
message = "service " + str(name) + " restored on port " \
|
||||||
|
+ str(public_port) + " on " + url_ip
|
||||||
|
LOG.info(" - " + message + " with PID " + str(wstun.pid))
|
||||||
|
w_msg = WM.WampSuccess([wstun.pid, message])
|
||||||
|
|
||||||
|
except Exception as err:
|
||||||
|
message = "Error restoring " + str(name) + " service: " + str(err)
|
||||||
|
LOG.error(" - " + message)
|
||||||
|
w_msg = WM.WampError(message)
|
||||||
|
|
||||||
|
return w_msg.serialize()
|
|
@ -16,6 +16,7 @@
|
||||||
__author__ = "Nicola Peditto <npeditto@unime.it"
|
__author__ = "Nicola Peditto <npeditto@unime.it"
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import inspect
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
from six import moves
|
from six import moves
|
||||||
from stevedore import extension
|
from stevedore import extension
|
||||||
|
@ -25,10 +26,15 @@ from iotronic_lightningrod.config import entry_points_name
|
||||||
from iotronic_lightningrod.lightningrod import SESSION
|
from iotronic_lightningrod.lightningrod import SESSION
|
||||||
from iotronic_lightningrod.modules import Module
|
from iotronic_lightningrod.modules import Module
|
||||||
|
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def getFuncName():
|
||||||
|
return inspect.stack()[1][3]
|
||||||
|
|
||||||
|
|
||||||
def refresh_stevedore(namespace=None):
|
def refresh_stevedore(namespace=None):
|
||||||
"""Trigger reload of entry points.
|
"""Trigger reload of entry points.
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,8 @@ s4t.modules =
|
||||||
utility = iotronic_lightningrod.modules.utils:Utility
|
utility = iotronic_lightningrod.modules.utils:Utility
|
||||||
plugin = iotronic_lightningrod.modules.plugin_manager:PluginManager
|
plugin = iotronic_lightningrod.modules.plugin_manager:PluginManager
|
||||||
device = iotronic_lightningrod.modules.device_manager:DeviceManager
|
device = iotronic_lightningrod.modules.device_manager:DeviceManager
|
||||||
|
service = iotronic_lightningrod.modules.service_manager:ServiceManager
|
||||||
|
# vfs = iotronic_lightningrod.modules.vfs_manager:VfsManager
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
build_scripts =
|
build_scripts =
|
||||||
|
|
Loading…
Reference in New Issue