Example #1
0
    def isAvailableFor(self, userService, ip):
        '''
        Checks if the transport is available for the requested destination ip
        '''
        ready = self.cache.get(ip)
        if ready is None:
            userServiceInstance = userService.getInstance()
            con = userServiceInstance.getConsoleConnection()

            logger.debug('Connection data: {}'.format(con))

            if con is None:
                return False

            port, secure_port = con['port'], con['secure_port']
            port = -1 if port is None else port
            secure_port = -1 if secure_port is None else secure_port

            # test ANY of the ports
            port_to_test = port if port != -1 else secure_port
            if port_to_test == -1:
                self.cache.put('cachedMsg', 'Could not find the PORT for connection', 120)  # Write a message, that will be used from getCustom
                logger.info('SPICE didn\'t find has any port: {}'.format(con))
                return False

            self.cache.put('cachedMsg',
                           'Could not reach server "{}" on port "{}" from broker (prob. causes are name resolution & firewall rules)'.format(con['address'], port_to_test),
                           120)

            if connection.testServer(con['address'], port_to_test) is True:
                self.cache.put(ip, 'Y', READY_CACHE_TIMEOUT)
                ready = 'Y'

        return ready == 'Y'
Example #2
0
 def testServer(self,
                host: str,
                port: typing.Union[str, int],
                timeout: int = 4) -> bool:
     if self.proxy is not None:
         return self.proxy.doTestServer(host, port, timeout)
     return connection.testServer(host, port, timeout)
Example #3
0
 def testServer(self,
                userService: 'models.UserService',
                ip: str,
                port: typing.Union[str, int],
                timeout: int = 4) -> bool:
     proxy: typing.Optional[
         'models.Proxy'] = userService.deployed_service.service.proxy
     if proxy:
         return proxy.doTestServer(ip, port, timeout)
     return connection.testServer(ip, str(port), timeout)
Example #4
0
 def getUnassignedMachine(self) -> typing.Optional[str]:
     # Search first unassigned machine
     try:
         now = getSqlDatetimeAsUnix()
         consideredFreeTime = now - config.GlobalConfig.SESSION_EXPIRE_TIME.getInt(
             force=False) * 3600
         for ip in self._ips:
             theIP = IPServiceBase.getIp(ip)
             theMAC = IPServiceBase.getMac(ip)
             locked = self.storage.getPickle(theIP)
             if not locked or locked < consideredFreeTime:
                 if self._port > 0 and self._skipTimeOnFailure > 0 and self.cache.get(
                         'port{}'.format(theIP)):
                     continue  # The check failed not so long ago, skip it...
                 self.storage.putPickle(theIP, now)
                 # Is WOL enabled?
                 wolENABLED = bool(self.parent().wolURL(theIP, theMAC))
                 # Now, check if it is available on port, if required...
                 if self._port > 0 and not wolENABLED:  # If configured WOL, check is a nonsense
                     if (connection.testServer(
                             theIP, self._port, timeOut=0.5) is False):
                         # Log into logs of provider, so it can be "shown" on services logs
                         self.parent().doLog(
                             log.WARN,
                             'Host {} not accesible on port {}'.format(
                                 theIP, self._port),
                         )
                         logger.warning(
                             'Static Machine check on %s:%s failed. Will be ignored for %s minutes.',
                             theIP,
                             self._port,
                             self._skipTimeOnFailure,
                         )
                         self.storage.remove(
                             theIP)  # Return Machine to pool
                         if self._skipTimeOnFailure > 0:
                             self.cache.put(
                                 'port{}'.format(theIP),
                                 '1',
                                 validity=self._skipTimeOnFailure * 60,
                             )
                         continue
                 if theMAC:
                     return theIP + ';' + theMAC
                 return theIP
         return None
     except Exception:
         logger.exception("Exception at getUnassignedMachine")
         return None
Example #5
0
 def isAvailableFor(self, ip):
     '''
     Checks if the transport is available for the requested destination ip
     Override this in yours transports
     '''
     logger.debug('Checking availability for {0}'.format(ip))
     ready = self.cache().get(ip)
     if ready is None:
         # Check again for ready
         if connection.testServer(ip, '3389') is True:
             self.cache().put(ip, 'Y', READY_CACHE_TIMEOUT)
             return True
         else:
             self.cache().put(ip, 'N', READY_CACHE_TIMEOUT)
     return ready == 'Y'
Example #6
0
 def isAvailableFor(self, ip):
     '''
     Checks if the transport is available for the requested destination ip
     Override this in yours transports
     '''
     logger.debug('Checking availability for {0}'.format(ip))
     ready = self.cache().get(ip)
     if ready is None:
         # Check again for readyness
         if connection.testServer(ip, self._listenPort) is True:
             self.cache().put(ip, 'Y', READY_CACHE_TIMEOUT)
             return True
         else:
             self.cache().put(ip, 'N', READY_CACHE_TIMEOUT)
     return ready == 'Y'
Example #7
0
 def isAvailableFor(self, userService: 'models.UserService',
                    ip: str) -> bool:
     """
     Checks if the transport is available for the requested destination ip
     Override this in yours transports
     """
     logger.debug('Checking availability for %s', ip)
     ready = self.cache.get(ip)
     if ready is None:
         # Check again for ready
         if connection.testServer(ip, 22):
             self.cache.put(ip, 'Y', READY_CACHE_TIMEOUT)
             return True
         self.cache.put(ip, 'N', READY_CACHE_TIMEOUT)
     return ready == 'Y'
Example #8
0
 def getUnassignedMachine(self) -> typing.Optional[str]:
     # Search first unassigned machine
     try:
         for ip in self._ips:
             theIP = ip.split('~')[0]
             if self.storage.readData(theIP) is None:
                 self.storage.saveData(theIP, theIP)
                 # Now, check if it is available on port, if required...
                 if self._port > 0:
                     if connection.testServer(theIP, self._port, timeOut=0.5) is False:
                         # Log into logs of provider, so it can be "shown" on services logs
                         self.parent().doLog(log.WARN, 'Host {} not accesible on port {}'.format(theIP, self._port))
                         self.storage.remove(theIP)  # Return Machine to pool
                         continue
                 return theIP
         return None
     except Exception:
         logger.exception("Exception at getUnassignedMachine")
         return None
Example #9
0
 def testServer(self, host, port, timeout=4):
     if self.proxy is not None:
         return self.proxy.doTestServer(host, port, timeout)
     return connection.testServer(host, six.text_type(port), timeout)
Example #10
0
 def testServer(self, host, port, timeout=4):
     if self.proxy is not None:
         return self.proxy.doTestServer(host, port, timeout)
     return connection.testServer(host, str(port), timeout)
Example #11
0
 def testServer(self, userService, ip, port, timeout=4):
     proxy = userService.deployed_service.service.proxy
     if proxy is not None:
         return proxy.doTestServer(ip, port, timeout)
     return connection.testServer(ip, six.text_type(port), timeout)
Example #12
0
 def testServer(self, userService, ip, port, timeout=4):
     proxy = userService.deployed_service.service.proxy
     if proxy is not None:
         return proxy.doTestServer(ip, port, timeout)
     return connection.testServer(ip, str(port), timeout)