From 804c389b8fddf23c58287dc7fd7181756ab4fa5d Mon Sep 17 00:00:00 2001 From: ramon Date: Mon, 20 Mar 2017 13:30:47 +0000 Subject: [PATCH] =?UTF-8?q?#718:=20OGAgent=20realiza=20varios=20intentos?= =?UTF-8?q?=20de=20activaci=C3=B3n=20hasta=20que=20la=20interfaz=20de=20re?= =?UTF-8?q?d=20est=C3=A9=20activa=20o=20pasen=2030=20s.;=20mejorar=20proce?= =?UTF-8?q?so=20de=20creaci=C3=B3n=20de=20OGAgent=20en=20Windows=20y=20mac?= =?UTF-8?q?OS.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://opengnsys.es/svn/branches/version1.1@5238 a21b9725-9963-47de-94b9-378ad31fedc9 --- macos/build-pkg.sh | 8 +++++--- src/opengnsys/macos/operations.py | 2 +- .../modules/server/OpenGnSys/__init__.py | 19 ++++++++++++++++--- windows/build-windows.sh | 1 + 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/macos/build-pkg.sh b/macos/build-pkg.sh index 02cf165..500da58 100755 --- a/macos/build-pkg.sh +++ b/macos/build-pkg.sh @@ -5,14 +5,16 @@ VERSION=1.1.0 AUTHOR="OpenGnsys Project" -# Create directories. +# Create empty directories. +cd $(dirname $0) +rm -fr build mkdir -p build && cd build mkdir -p flat/base.pkg flat/Resources/en.lproj mkdir -p root/Applications # Copy application and script files. -cp -r ../../src root/Applications/OGAgent.app -cp -r ../scripts . +cp -a ../../src root/Applications/OGAgent.app +cp -a ../scripts . # Create plist file. cat << EOT > root/Applications/OGAgent.app/OGAgent.plist diff --git a/src/opengnsys/macos/operations.py b/src/opengnsys/macos/operations.py index 2995de9..458f5a5 100644 --- a/src/opengnsys/macos/operations.py +++ b/src/opengnsys/macos/operations.py @@ -104,7 +104,7 @@ def getNetworkInfo(): ''' for ifname in _getInterfaces(): ip, mac = _getIpAndMac(ifname) - if mac != None: # Skips local interfaces + if mac != None and ip != None: # Skips local interfaces yield utils.Bunch(name=ifname, mac=mac, ip=ip) diff --git a/src/opengnsys/modules/server/OpenGnSys/__init__.py b/src/opengnsys/modules/server/OpenGnSys/__init__.py index 9bb95be..f939eb6 100644 --- a/src/opengnsys/modules/server/OpenGnSys/__init__.py +++ b/src/opengnsys/modules/server/OpenGnSys/__init__.py @@ -83,11 +83,24 @@ class OpenGnSysWorker(ServerWorker): self.cmd = None # Ensure cfg has required configuration variables or an exception will be thrown self.REST = REST(self.service.config.get('opengnsys', 'remote')) - # Get network interfaces - self.interface = list(operations.getNetworkInfo())[0] # Get first network interface + # Get network interfaces until they are active or timeout (30 sec) + for t in range(0,30): + try: + self.interface = list(operations.getNetworkInfo())[0] # Get first network interface + except Exception as e: + # Wait 1 sec. and retry + sleep(1) + finally: + # Exit loop if interface is active + if self.interface: + if t > 0: + logger.debug("Fetch connection data after {} tries".format(t)) + break + # Raise error after timeout + if not self.interface: + raise e # Generate random secret to send on activation self.random = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(self.length)) - # Send initalization message self.REST.sendMessage('ogagent/started', {'mac': self.interface.mac, 'ip': self.interface.ip, 'secret': self.random, 'ostype': operations.osType, 'osversion': operations.osVersion}) diff --git a/windows/build-windows.sh b/windows/build-windows.sh index a861b09..d7248ab 100755 --- a/windows/build-windows.sh +++ b/windows/build-windows.sh @@ -2,3 +2,4 @@ export WINEARCH=win32 export WINEPREFIX=$(realpath $(dirname $0)/wine) wine cmd /c c:\\ogagent\\build.bat +chmod -x $(dirname $0)/../OGAgentSetup*.exe