예제 #1
0
def host_get(host_id=None):
    if host_id:
        return utils.jsonify(host.get_host(id=host_id).dict())

    hosts = []

    for hst in host.iter_hosts():
        hosts.append(hst.dict())

    return utils.jsonify(hosts)
예제 #2
0
파일: server.py 프로젝트: aalsmile/pritunl
 def iter_hosts(self, fields=None):
     spec = {'_id': {'$in': self.hosts}}
     for hst in host.iter_hosts(spec=spec, fields=fields):
         yield hst
예제 #3
0
 def iter_hosts(self, fields=None):
     spec = {
         '_id': {'$in': self.hosts}
     }
     for hst in host.iter_hosts(spec=spec, fields=fields):
         yield hst
예제 #4
0
    def thread():
        platforms = list(DESKTOP_PLATFORMS)
        start_timestamp = datetime.datetime(2015, 12, 28, 4, 1, 0)
        hosts_collection = mongo.get_collection('hosts')
        servers_collection  = mongo.get_collection('servers')
        clients_collection = mongo.get_collection('clients')

        clients_collection.remove({})

        for hst in host.iter_hosts():
            hosts_collection.update({
                '_id': hst.id,
            }, {'$set': {
                'server_count': 0,
                'device_count': 0,
                'cpu_usage': 0,
                'mem_usage': 0,
                'thread_count': 0,
                'open_file_count': 0,
                'status': ONLINE,
                'start_timestamp': start_timestamp,
                'ping_timestamp': start_timestamp,
                'auto_public_address': None,
                'auto_public_address6': None,
                'auto_public_host': hst.name + '.pritunl.com',
                'auto_public_host6': hst.name + '.pritunl.com',
            }})

        for svr in server.iter_servers():
            prefered_hosts = host.get_prefered_hosts(
                svr.hosts, svr.replica_count)

            instances = []
            for hst in prefered_hosts:
                instances.append({
                    'instance_id': utils.ObjectId(),
                    'host_id': hst,
                    'ping_timestamp': utils.now(),
                })

            servers_collection.update({
                '_id': svr.id,
            }, {'$set': {
                'status': ONLINE,
                'pool_cursor': None,
                'start_timestamp': start_timestamp,
                'availability_group': DEFAULT,
                'instances': instances,
                'instances_count': len(instances),
            }})

            for org in svr.iter_orgs():
                for usr in org.iter_users():
                    if usr.type != CERT_CLIENT:
                        continue

                    virt_address = svr.get_ip_addr(org.id, usr.id)
                    virt_address6 = svr.ip4to6(virt_address)

                    doc = {
                        '_id': utils.ObjectId(),
                        'user_id': usr.id,
                        'server_id': svr.id,
                        'host_id': settings.local.host_id,
                        'timestamp': start_timestamp,
                        'platform': random.choice(platforms),
                        'type': CERT_CLIENT,
                        'device_name': utils.random_name(),
                        'mac_addr': utils.rand_str(16),
                        'network': svr.network,
                        'real_address': str(
                            ipaddress.IPAddress(100000000 + random.randint(
                                0, 1000000000))),
                        'virt_address': virt_address,
                        'virt_address6': virt_address6,
                        'host_address': settings.local.host.local_addr,
                        'host_address6': settings.local.host.local_addr6,
                        'dns_servers': [],
                        'dns_suffix': None,
                        'connected_since': int(start_timestamp.strftime('%s')),
                    }

                    clients_collection.insert(doc)

        for lnk in link.iter_links():
            lnk.status = ONLINE
            lnk.commit()

            for location in lnk.iter_locations():
                active = False
                for hst in location.iter_hosts():
                    if not active:
                        hst.active = True
                        active = True
                    hst.status = AVAILABLE
                    hst.commit(('active', 'status'))

        logger.info('Demo initiated', 'demo')
예제 #5
0
파일: demo.py 프로젝트: thaihust/fVPN
    def thread():
        platforms = list(DESKTOP_PLATFORMS)
        start_timestamp = datetime.datetime(2015, 12, 28, 4, 1, 0)
        hosts_collection = mongo.get_collection('hosts')
        servers_collection = mongo.get_collection('servers')
        clients_collection = mongo.get_collection('clients')

        clients_collection.remove({})

        for hst in host.iter_hosts():
            hosts_collection.update({
                '_id': hst.id,
            }, {
                '$set': {
                    'server_count': 0,
                    'device_count': 0,
                    'cpu_usage': 0,
                    'mem_usage': 0,
                    'thread_count': 0,
                    'open_file_count': 0,
                    'status': ONLINE,
                    'start_timestamp': start_timestamp,
                    'ping_timestamp': start_timestamp,
                    'auto_public_address': None,
                    'auto_public_address6': None,
                    'auto_public_host': hst.name + '.pritunl.com',
                    'auto_public_host6': hst.name + '.pritunl.com',
                }
            })

        for svr in server.iter_servers():
            prefered_hosts = host.get_prefered_hosts(svr.hosts,
                                                     svr.replica_count)

            instances = []
            for hst in prefered_hosts:
                instances.append({
                    'instance_id': utils.ObjectId(),
                    'host_id': hst,
                    'ping_timestamp': utils.now(),
                })

            servers_collection.update({
                '_id': svr.id,
            }, {
                '$set': {
                    'status': ONLINE,
                    'pool_cursor': None,
                    'start_timestamp': start_timestamp,
                    'availability_group': DEFAULT,
                    'instances': instances,
                    'instances_count': len(instances),
                }
            })

            for org in svr.iter_orgs():
                for usr in org.iter_users():
                    if usr.type != CERT_CLIENT:
                        continue

                    virt_address = svr.get_ip_addr(org.id, usr.id)
                    virt_address6 = svr.ip4to6(virt_address)

                    doc = {
                        '_id':
                        utils.ObjectId(),
                        'user_id':
                        usr.id,
                        'server_id':
                        svr.id,
                        'host_id':
                        settings.local.host_id,
                        'timestamp':
                        start_timestamp,
                        'platform':
                        random.choice(platforms),
                        'type':
                        CERT_CLIENT,
                        'device_name':
                        utils.random_name(),
                        'mac_addr':
                        utils.rand_str(16),
                        'network':
                        svr.network,
                        'real_address':
                        str(
                            ipaddress.IPAddress(
                                100000000 + random.randint(0, 1000000000))),
                        'virt_address':
                        virt_address,
                        'virt_address6':
                        virt_address6,
                        'host_address':
                        settings.local.host.local_addr,
                        'host_address6':
                        settings.local.host.local_addr6,
                        'dns_servers': [],
                        'dns_suffix':
                        None,
                        'connected_since':
                        int(start_timestamp.strftime('%s')),
                    }

                    clients_collection.insert(doc)

        for lnk in link.iter_links():
            lnk.status = ONLINE
            lnk.commit()

            for location in lnk.iter_locations():
                active = False
                for hst in location.iter_hosts():
                    if not active:
                        hst.active = True
                        active = True
                    hst.status = AVAILABLE
                    hst.commit(('active', 'status'))

        logger.info('Demo initiated', 'demo')
예제 #6
0
 def iter_hosts(self, fields=None):
     spec = {"_id": {"$in": self.hosts}}
     for hst in host.iter_hosts(spec=spec, fields=fields):
         yield hst