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


Python network.Network类代码示例

本文整理汇总了Python中app.util.network.Network的典型用法代码示例。如果您正苦于以下问题:Python Network类的具体用法?Python Network怎么用?Python Network使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: _non_registered_slaves

    def _non_registered_slaves(self, registered_slaves, slaves_to_validate):
        """
        Return list of slave hosts that have failed to register with the master service.

        :param slaves_to_validate: list of slave hostnames to check for
        :type slaves_to_validate: list[str]
        :return: list of slave hostnames that haven't registered with the master service yet
        :rtype: list[str]
        """
        registered_rsa_keys = []

        for registered_slave in registered_slaves:
            registered_rsa_keys.append(Network.rsa_key(registered_slave))

        slaves_to_validate_rsa_key_host_pairs = {}

        for slave_to_validate in slaves_to_validate:
            slaves_to_validate_rsa_key_host_pairs[Network.rsa_key(slave_to_validate)] = slave_to_validate

        non_registered_slave_hosts = []

        for rsa_key in slaves_to_validate_rsa_key_host_pairs:
            if rsa_key not in registered_rsa_keys:
                non_registered_slave_hosts.append(slaves_to_validate_rsa_key_host_pairs[rsa_key])

        return non_registered_slave_hosts
开发者ID:eltonoliveira,项目名称:ClusterRunner,代码行数:26,代码来源:deploy_subcommand.py

示例2: test_get_host_id_of_localhost

 def test_get_host_id_of_localhost(self):
     local_host_name = socket.gethostname()
     self.assertEqual(
         Network.get_host_id('localhost'),
         Network.get_host_id(local_host_name),
         'Host id of "localhost" is not the same as host id of "{}"'.format(local_host_name),
     )
开发者ID:OspreyX,项目名称:ClusterRunner,代码行数:7,代码来源:test_network.py

示例3: test_get_host_id_of_localhost

 def test_get_host_id_of_localhost(self):  # todo: this is an integration test -- move it to integration dir
     local_host_name = socket.gethostname()
     self.assertEqual(
         Network.get_host_id('localhost'),
         Network.get_host_id(local_host_name),
         'Host id of "localhost" is not the same as host id of "{}"'.format(local_host_name),
     )
开发者ID:Medium,项目名称:ClusterRunner,代码行数:7,代码来源:test_network.py

示例4: all_slaves_registered

 def all_slaves_registered():
     registered_slave_uids = set(
         [Network.get_host_id(x) for x in self._registered_slave_hostnames(slave_api_url, network)]
     )
     slaves_to_validate_uids = set(
         [Network.get_host_id(x) for x in slaves_to_validate]
     )
     return registered_slave_uids == slaves_to_validate_uids
开发者ID:Medium,项目名称:ClusterRunner,代码行数:8,代码来源:deploy_subcommand.py

示例5: _deploy_binaries_and_conf

    def _deploy_binaries_and_conf(self, host, username, current_executable, binaries_tar_path, in_use_conf_path):
        """
        Move binaries and conf to single host.

        :param host: host to deploy to
        :type host: str
        :param username: current username
        :param current_executable: path to the executable (ie: /usr/bin/python, ./clusterrunner, etc)
        :type current_executable: str
        :param binaries_tar_path: path to tar.gz file of clusterrunner binaries
        :type binaries_tar_path: str
        :param in_use_conf_path: path toe currently used conf file
        :type in_use_conf_path: str
        """
        clusterrunner_dir = join(os.path.expanduser('~'), '.clusterrunner')
        clusterrunner_executable_dir = join(clusterrunner_dir, 'dist')
        clusterrunner_executable_deploy_target = join(clusterrunner_executable_dir, 'clusterrunner')
        clusterrunner_conf_deploy_target = join(clusterrunner_dir, 'clusterrunner.conf')
        deploy_target = DeployTarget(host, username)

        if Network.are_hosts_same(host, 'localhost'):
            # Do not want to overwrite the currently running executable.
            if current_executable != clusterrunner_executable_deploy_target:
                deploy_target.deploy_binary(binaries_tar_path, clusterrunner_executable_dir)

            # Do not want to overwrite the currently used conf.
            if in_use_conf_path != clusterrunner_conf_deploy_target:
                deploy_target.deploy_conf(in_use_conf_path, clusterrunner_conf_deploy_target)
        else:
            deploy_target.deploy_binary(binaries_tar_path, clusterrunner_executable_dir)
            deploy_target.deploy_conf(in_use_conf_path, clusterrunner_conf_deploy_target)
开发者ID:Medium,项目名称:ClusterRunner,代码行数:31,代码来源:deploy_subcommand.py

示例6: __init__

    def __init__(self, port, host, num_executors=10):
        """
        :param port: The port number the slave service is running on
        :type port: int
        :param host: The hostname at which the slave is reachable
        :type host: str
        :param num_executors: The number of executors this slave should operate with -- this determines how many
            concurrent subjobs the slave can execute.
        :type num_executors: int
        """
        self.port = port
        self.host = host
        self._slave_id = None
        self._num_executors = num_executors
        self._logger = log.get_logger(__name__)

        self._idle_executors = Queue(maxsize=num_executors)
        self.executors = {}
        for executor_id in range(num_executors):
            executor = SubjobExecutor(executor_id)
            self._idle_executors.put(executor)
            self.executors[executor_id] = executor

        self._setup_complete_event = Event()
        self._master_url = None
        self._network = Network(min_connection_poolsize=num_executors)
        self._master_api = None  # wait until we connect to a master first

        self._project_type = None  # this will be instantiated during build setup
        self._current_build_id = None

        UnhandledExceptionHandler.singleton().add_teardown_callback(self._async_teardown_build,
                                                                    should_disconnect_from_master=True)
开发者ID:drobertduke,项目名称:ClusterRunner,代码行数:33,代码来源:cluster_slave.py

示例7: __init__

    def __init__(self, port, host, num_executors=10):
        """
        :param port: The port number the slave service is running on
        :type port: int
        :param host: The hostname at which the slave is reachable
        :type host: str
        :param num_executors: The number of executors this slave should operate with -- this determines how many
            concurrent subjobs the slave can execute.
        :type num_executors: int
        """
        self.port = port
        self.host = host
        self.is_alive = True
        self._slave_id = None
        self._num_executors = num_executors
        self._logger = log.get_logger(__name__)

        self._idle_executors = Queue(maxsize=num_executors)
        self.executors_by_id = {}
        for executor_id in range(num_executors):
            executor = SubjobExecutor(executor_id)
            self._idle_executors.put(executor)
            self.executors_by_id[executor_id] = executor

        self._master_url = None
        self._network = Network(min_connection_poolsize=num_executors)
        self._master_api = None  # wait until we connect to a master first

        self._project_type = None  # this will be instantiated during build setup
        self._current_build_id = None
        self._build_teardown_coin = None
        self._base_executor_index = None
开发者ID:Medium,项目名称:ClusterRunner,代码行数:32,代码来源:cluster_slave.py

示例8: setUp

    def setUp(self):
        # Configure logging to go to stdout. This makes debugging easier by allowing us to see logs for failed tests.
        log.configure_logging('DEBUG')

        Secret.set('testsecret')

        self.cluster = FunctionalTestCluster(verbose=self._get_test_verbosity())
        self._network = Network()
开发者ID:Medium,项目名称:ClusterRunner,代码行数:8,代码来源:base_functional_test_case.py

示例9: is_up

    def is_up(self, service_url, timeout=0.1):
        """
        Checks if the service is up
        :type service_url: string
        :type timeout: float
        :rtype: bool
        """
        network = Network()
        timeout_time = time.time() + timeout
        while True:
            try:
                resp = network.get('http://{}'.format(service_url), timeout=timeout)
                if resp and resp.ok:
                    return True
            except (requests.RequestException, ConnectionError):
                pass
            if time.time() > timeout_time:
                break
            time.sleep(0.5)

        return False
开发者ID:drobertduke,项目名称:ClusterRunner,代码行数:21,代码来源:service_runner.py

示例10: _non_registered_slaves

    def _non_registered_slaves(self, registered_slaves, slaves_to_validate):
        """
        Return list of slave hosts that have failed to register with the master service.

        :param slaves_to_validate: list of slave hostnames to check for
        :type slaves_to_validate: list[str]
        :return: list of slave hostnames that haven't registered with the master service yet
        :rtype: list[str]
        """
        registered_host_ids = [Network.get_host_id(slave) for slave in registered_slaves]

        slaves_to_validate_host_id_pairs = {
            Network.get_host_id(slave): slave
            for slave in slaves_to_validate
        }

        non_registered_slave_hosts = [
            slaves_to_validate_host_id_pairs[host_id] for host_id in slaves_to_validate_host_id_pairs
            if host_id not in registered_host_ids
        ]

        return non_registered_slave_hosts
开发者ID:Medium,项目名称:ClusterRunner,代码行数:22,代码来源:deploy_subcommand.py

示例11: __init__

 def __init__(self, slave_url, num_executors):
     """
     :type slave_url: str
     :type num_executors: int
     """
     self.url = slave_url
     self.num_executors = num_executors
     self.id = self._slave_id_counter.increment()
     self._num_executors_in_use = Counter()
     self._network = Network(min_connection_poolsize=num_executors)
     self.current_build_id = None
     self.is_alive = True
     self._slave_api = UrlBuilder(slave_url, app.master.cluster_master.ClusterMaster.API_VERSION)
开发者ID:drobertduke,项目名称:ClusterRunner,代码行数:13,代码来源:slave.py

示例12: run

    def run(self, log_level, master_url, remote_file=None, build_type=None, **request_params):
        """
        Execute a build and wait for it to complete.

        :param log_level: the log level at which to do application logging (or None for default log level)
        :type log_level: str | None
        :param master_url: the url (specified by the user) of the master to which we should send the build
        :type master_url: str | None
        :param remote_file: a list of remote files where each element contains the output file name and the resource URL
        :type remote_file: list[list[str]] | None
        :param build_type: the build type of the request to be sent (e.g., "git", "directory"). If not specified
            will default to the "directory" project type.
        :type build_type: str | None
        :param request_params: key-value pairs to be provided as build parameters in the build request
        :type request_params: dict
        """
        log_level = log_level or Configuration['log_level']
        log.configure_logging(log_level=log_level, simplified_console_logs=True)
        request_params['type'] = build_type or request_params.get('type') or 'directory'

        if remote_file:
            request_params['remote_files'] = {name: url for name, url in remote_file}

        operational_master_url = master_url or '{}:{}'.format(Configuration['hostname'], Configuration['port'])

        # If running a single master, single slave--both on localhost--we need to launch services locally.
        if master_url is None and Network.are_hosts_same(Configuration['master_hostname'], 'localhost') \
                and len(Configuration['slaves']) == 1 \
                and Network.are_hosts_same(Configuration['slaves'][0], 'localhost'):
            self._start_local_services_if_needed(operational_master_url)

        if request_params['type'] == 'directory':
            request_params['project_directory'] = request_params.get('project_directory') or os.getcwd()

        runner = BuildRunner(master_url=operational_master_url, request_params=request_params, secret=Secret.get())

        if not runner.run():
            sys.exit(1)
开发者ID:Medium,项目名称:ClusterRunner,代码行数:38,代码来源:build_subcommand.py

示例13: test_are_hosts_same

    def test_are_hosts_same(
            self,
            host_to_id,
            expect_hosts_are_same,
    ):
        def side_effect(host):
            host_id = host_to_id[host]
            if host_id is None:
                raise socket.gaierror
            else:
                return host_id

        self._patch_socket_gethostbyname(side_effect=side_effect)
        self.assertEqual(Network.are_hosts_same(*host_to_id), expect_hosts_are_same)
开发者ID:Medium,项目名称:ClusterRunner,代码行数:14,代码来源:test_network.py

示例14: __init__

 def __init__(self, slave_url, num_executors):
     """
     :type slave_url: str
     :type num_executors: int
     """
     self.url = slave_url
     self.num_executors = num_executors
     self.id = self._slave_id_counter.increment()
     self._num_executors_in_use = Counter()
     self._network = Network(min_connection_poolsize=num_executors)
     self.current_build_id = None
     self._is_alive = True
     self._slave_api = UrlBuilder(slave_url, self.API_VERSION)
     self._logger = log.get_logger(__name__)
开发者ID:OspreyX,项目名称:ClusterRunner,代码行数:14,代码来源:slave.py

示例15: __init__

 def __init__(self, master_url, request_params, secret):
     """
     :param master_url: The url of the master which the build will be executed on
     :type master_url: str
     :param request_params: A dict of request params that will be json-encoded and sent in the build request
     :type request_params: dict
     :type secret: str
     """
     self._master_url = self._ensure_url_has_scheme(master_url)
     self._request_params = request_params
     self._secret = secret
     self._build_id = None
     self._network = Network()
     self._logger = get_logger(__name__)
     self._last_build_status_details = None
     self._master_api = UrlBuilder(master_url, self.API_VERSION)
     self._cluster_master_api_client = ClusterMasterAPIClient(master_url)
开发者ID:OspreyX,项目名称:ClusterRunner,代码行数:17,代码来源:build_runner.py


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