当前位置: 首页>>代码示例>>Python>>正文


Python ServerInstanceCom.start方法代码示例

本文整理汇总了Python中pritunl.server.instance_com.ServerInstanceCom.start方法的典型用法代码示例。如果您正苦于以下问题:Python ServerInstanceCom.start方法的具体用法?Python ServerInstanceCom.start怎么用?Python ServerInstanceCom.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pritunl.server.instance_com.ServerInstanceCom的用法示例。


在下文中一共展示了ServerInstanceCom.start方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ServerInstance

# 需要导入模块: from pritunl.server.instance_com import ServerInstanceCom [as 别名]
# 或者: from pritunl.server.instance_com.ServerInstanceCom import start [as 别名]

#.........这里部分代码省略.........
            primary_org = organization.get_by_id(
                id=self.server.primary_organization)

        self.primary_user = primary_org.get_user(self.server.primary_user)
        if not self.primary_user:
            self.server.create_primary_user()
            primary_org = organization.get_by_id(
                id=self.server.primary_organization)
            self.primary_user = primary_org.get_user(self.server.primary_user)

        gateway = utils.get_network_gateway(self.server.network)
        gateway6 = utils.get_network_gateway(self.server.network6)

        push = ''
        for route in self.server.get_routes(include_default=False):
            if route['virtual_network']:
                continue

            network = route['network']
            if not route.get('network_link'):
                if ':' in network:
                    push += 'push "route-ipv6 %s "\n' % network
                else:
                    push += 'push "route %s %s"\n' % utils.parse_network(
                        network)
            else:
                if ':' in network:
                    push += 'route-ipv6 %s %s\n' % (network, gateway6)
                else:
                    push += 'route %s %s %s\n' % (utils.parse_network(
                        network) + (gateway,))

        for link_svr in self.server.iter_links(fields=(
                '_id', 'network', 'local_networks', 'network_start',
                'network_end', 'organizations', 'routes', 'links')):
            if self.server.id < link_svr.id:
                for route in link_svr.get_routes(include_default=False):
                    network = route['network']
                    if ':' in network:
                        push += 'route-ipv6 %s %s\n' % (
                            network, gateway6)
                    else:
                        push += 'route %s %s %s\n' % (utils.parse_network(
                            network) + (gateway,))

        if self.server.network_mode == BRIDGE:
            host_int_data = self.host_interface_data
            host_address = host_int_data['address']
            host_netmask = host_int_data['netmask']

            server_line = 'server-bridge %s %s %s %s' % (
                host_address,
                host_netmask,
                self.server.network_start,
                self.server.network_end,
            )
        else:
            server_line = 'server %s %s' % utils.parse_network(
                self.server.network)

            if self.server.ipv6:
                server_line += '\nserver-ipv6 ' + self.server.network6

        server_conf = OVPN_INLINE_SERVER_CONF % (
            self.server.port,
            self.server.protocol + ('6' if self.server.ipv6 else ''),
开发者ID:WPMedia,项目名称:pritunl,代码行数:70,代码来源:instance.py

示例2: ServerInstance

# 需要导入模块: from pritunl.server.instance_com import ServerInstanceCom [as 别名]
# 或者: from pritunl.server.instance_com.ServerInstanceCom import start [as 别名]

#.........这里部分代码省略.........
        logger.debug('Clearing iptables rules', 'server',
            server_id=self.server.id,
        )

        processes = []

        for rule in self.iptables_rules:
            process = subprocess.Popen(['iptables', '-D'] + rule,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
            )
            processes.append(process)

        for process in processes:
            process.wait()

    def stop_process(self):
        self.sock_interrupt = True

        for instance_link in self.server_links:
            instance_link.stop()

        terminated = utils.stop_process(self.process)

        if not terminated:
            logger.error('Failed to stop server process', 'server',
                server_id=self.server.id,
                instance_id=self.id,
            )
            return False

        return terminated

    def openvpn_start(self):
        try:
            return subprocess.Popen(['openvpn', self.ovpn_conf_path],
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        except OSError:
            self.server.output.push_output(traceback.format_exc())
            logger.exception('Failed to start ovpn process', 'server',
                server_id=self.server.id,
            )
            self.publish('error')

    @interrupter
    def openvpn_watch(self):
        while True:
            line = self.process.stdout.readline()
            if not line:
                if self.process.poll() is not None:
                    break
                else:
                    time.sleep(0.05)
                    continue

            yield

            try:
                self.server.output.push_output(line)
            except:
                logger.exception('Failed to push vpn output', 'server',
                    server_id=self.server.id,
                )

            yield
开发者ID:1990754123,项目名称:pritunl,代码行数:69,代码来源:instance.py

示例3: ServerInstance

# 需要导入模块: from pritunl.server.instance_com import ServerInstanceCom [as 别名]
# 或者: from pritunl.server.instance_com.ServerInstanceCom import start [as 别名]
class ServerInstance(object):
    def __init__(self, server):
        self.server = server
        self.id = utils.ObjectId()
        self.interrupt = False
        self.sock_interrupt = False
        self.startup_interrupt = False
        self.clean_exit = False
        self.interface = None
        self.bridge_interface = None
        self.primary_user = None
        self.process = None
        self.vxlan = None
        self.iptables = iptables.Iptables()
        self.iptables_lock = threading.Lock()
        self.tun_nat = False
        self.server_links = []
        self.route_advertisements = set()
        self._temp_path = utils.get_temp_path()
        self.ovpn_conf_path = os.path.join(self._temp_path, OVPN_CONF_NAME)
        self.management_socket_path = os.path.join(
            settings.conf.var_run_path,
            MANAGEMENT_SOCKET_NAME % self.id,
        )

    @cached_static_property
    def collection(cls):
        return mongo.get_collection('servers')

    @cached_static_property
    def user_collection(cls):
        return mongo.get_collection('users')

    @cached_static_property
    def routes_collection(cls):
        return mongo.get_collection('routes_reserve')

    def get_cursor_id(self):
        return messenger.get_cursor_id('servers')

    def is_interrupted(self):
        if _instances.get(self.server.id) != self:
            return True
        return self.sock_interrupt

    def publish(self, message, transaction=None, extra=None):
        extra = extra or {}
        extra.update({
            'server_id': self.server.id,
        })
        messenger.publish('servers', message,
            extra=extra, transaction=transaction)

    def subscribe(self, cursor_id=None, timeout=None):
        for msg in messenger.subscribe('servers', cursor_id=cursor_id,
                timeout=timeout):
            if msg.get('server_id') == self.server.id:
                yield msg

    def resources_acquire(self):
        if self.interface:
            raise TypeError('Server resource already acquired')

        _instances_lock.acquire()
        try:
            instance = _instances.get(self.server.id)
            if instance:
                logger.warning(
                    'Stopping duplicate instance', 'server',
                    server_id=self.server.id,
                    instance_id=instance.id,
                )

                try:
                    instance.stop_process()
                except:
                    logger.exception(
                        'Failed to stop duplicate instance', 'server',
                        server_id=self.server.id,
                        instance_id=instance.id,
                    )

                time.sleep(5)

            _instances[self.server.id] = self
        finally:
            _instances_lock.release()

        self.interface = utils.interface_acquire(self.server.adapter_type)

    def resources_release(self):
        interface = self.interface
        if interface:
            utils.interface_release(self.server.adapter_type, interface)
            self.interface = None

        _instances_lock.acquire()
        try:
            if _instances.get(self.server.id) == self:
                _instances.pop(self.server.id)
#.........这里部分代码省略.........
开发者ID:pritunl,项目名称:pritunl,代码行数:103,代码来源:instance.py


注:本文中的pritunl.server.instance_com.ServerInstanceCom.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。