def downloadFile(self, uuid, fqdn, shortname, ips, macs, netmasks, path, bwlimit): # choose a way to perform the operation ip = chooseClientIP({ 'uuid': uuid, 'fqdn': fqdn, 'shortname': shortname, 'ips': ips, 'macs': macs, 'netmasks': netmasks }) if not ip or not NetUtils.is_ipv4_format(ip): logging.getLogger().warn("Ivalid IP address format: '%s'" % str(ip)) return fail(False) client = { 'host': ip, 'chosen_ip': ip, 'uuid': uuid, 'shortname': shortname, 'ip': ips, 'macs': macs, 'protocol': 'ssh' } client['client_check'] = getClientCheck(client) client['server_check'] = getServerCheck(client) client['action'] = getAnnounceCheck('download') return self.call_method('download_file', client, path, bwlimit)
def establish_proxy(self, uuid, fqdn, shortname, ips, macs, netmasks, requestor_ip, requested_port): def _finalize(result): if type(result) == list: # got expected struct (launcher, host, port, key) = result if key == '-': # Key not provided => TCP Proxy logging.getLogger().info( 'VNC Proxy: launcher "%s" created new TCP Proxy to "%s:%s"' % (launcher, host, str(port))) else: # Key provided => Websocket Proxy logging.getLogger().info( 'VNC Proxy: launcher "%s" created new WebSocket Proxy to "%s:%s" with key "%s"' % (str(launcher), str(host), str(port), str(key))) if host == '': host = SchedulerConfig().launchers[launcher]['host'] return (host, port, key) else: return False # choose a way to perform the operation ip = chooseClientIP({ 'uuid': uuid, 'fqdn': fqdn, 'shortname': shortname, 'ips': ips, 'macs': macs, 'netmasks': netmasks }) if not ip or not NetUtils.is_ipv4_format(ip): logging.getLogger().warn("Ivalid IP address format: '%s'" % str(ip)) return fail(False) client = { 'host': ip, 'chosen_ip': ip, 'uuid': uuid, 'shortname': shortname, 'ip': ips, 'macs': macs, 'protocol': 'tcpsproxy' } client['client_check'] = getClientCheck(client) client['server_check'] = getServerCheck(client) client['action'] = getAnnounceCheck('vnc') d = self.call_method('tcp_sproxy', client, requestor_ip, requested_port) d.addCallback(_finalize) @d.addErrback def _eb(failure): logging.getLogger().warn("VNC proxy open failed: %s" % str(failure)) return d
def chooseClientInfo(target): ips = target.getIps() if len(ips) > 0: # if at least one element from list of IPs is IP format if any([NetUtils.is_ipv4_format(ip) for ip in ips]): host_dict = { "uuid": target.getUUID(), "fqdn": target.getFQDN(), "shortname": target.getShortName(), "ips": ips, "macs": target.getMacs(), "netmasks": target.getNetmasks(), } return chooseClientIP(host_dict) return None
def downloadFile(self, uuid, fqdn, shortname, ips, macs, netmasks, path, bwlimit): # choose a way to perform the operation ip = chooseClientIP({'uuid': uuid, 'fqdn': fqdn, 'shortname': shortname, 'ips': ips, 'macs': macs, 'netmasks': netmasks }) if not ip or not NetUtils.is_ipv4_format(ip): logging.getLogger().warn("Ivalid IP address format: '%s'" % str(ip)) return fail(False) client = {'host': ip, 'chosen_ip': ip, 'uuid': uuid, 'shortname': shortname, 'ip': ips, 'macs': macs, 'protocol': 'ssh' } client['client_check'] = getClientCheck(client) client['server_check'] = getServerCheck(client) client['action'] = getAnnounceCheck('download') return self.call_method('download_file', client, path, bwlimit)
def establish_proxy(self, uuid, fqdn, shortname, ips, macs, netmasks, requestor_ip, requested_port): def _finalize(result): if type(result) == list: # got expected struct (launcher, host, port, key) = result if key == '-': # Key not provided => TCP Proxy logging.getLogger().info( 'VNC Proxy: launcher "%s" created new TCP Proxy to "%s:%s"' % (launcher, host, str(port))) else: # Key provided => Websocket Proxy logging.getLogger().info( 'VNC Proxy: launcher "%s" created new WebSocket Proxy to "%s:%s" with key "%s"' % (str(launcher), str(host), str(port), str(key))) if host == '': host = SchedulerConfig().launchers[launcher]['host'] return (host, port, key) else: return False # choose a way to perform the operation ip = chooseClientIP({'uuid': uuid, 'fqdn': fqdn, 'shortname': shortname, 'ips': ips, 'macs': macs, 'netmasks': netmasks }) if not ip or not NetUtils.is_ipv4_format(ip): logging.getLogger().warn("Ivalid IP address format: '%s'" % str(ip)) return fail(False) client = {'host': ip, 'chosen_ip': ip, 'uuid': uuid, 'shortname': shortname, 'ip': ips, 'macs': macs, 'protocol': 'tcpsproxy' } client['client_check'] = getClientCheck(client) client['server_check'] = getServerCheck(client) client['action'] = getAnnounceCheck('vnc') d = self.call_method('tcp_sproxy', client, requestor_ip, requested_port) d.addCallback(_finalize) @d.addErrback def _eb(failure): logging.getLogger().warn("VNC proxy open failed: %s" % str(failure)) return d
def test08_is_not_ipv4_format(self): """ test of ipv4 format""" ip = "150.150.154.aaa" result = NetUtils.is_ipv4_format(ip) self.assertFalse(result)
def test07_is_ipv4_format(self): """ test of ipv4 format""" ip = "192.168.1.25" result = NetUtils.is_ipv4_format(ip) self.assertTrue(result)
def test08_is_not_ipv4_format(self): """ test of ipv4 format""" ip = "150.150.154.aaa" result = NetUtils.is_ipv4_format(ip) self.assertFalse(result)
def test07_is_ipv4_format(self): """ test of ipv4 format""" ip = "192.168.1.25" result = NetUtils.is_ipv4_format(ip) self.assertTrue(result)