• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.get_hostname函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: delete

    def delete(self, local_only=False):
        """Delete the logical volume for the disk"""
        vm_object = self.get_virtual_machine()
        # Ensure that the user has permissions to add delete storage
        self._get_registered_object('auth').assert_permission(
            PERMISSIONS.MODIFY_HARD_DRIVE,
            vm_object
        )

        # If the storage backend is available on one to more nodes,
        # ensure that the hard drive exists. Prefer local host
        check_node = get_hostname() if get_hostname() in self.nodes else self.nodes[0]
        if self._is_cluster_master or check_node == get_hostname():
            self.ensure_exists(nodes=[check_node])

        if vm_object:
            vm_object.ensureUnlocked()
            vm_object.ensure_stopped()

            # Remove the hard drive from the MCVirt VM configuration
            self.get_attachment_object().delete(local_only=local_only)

        # Remove backing storage
        self._removeStorage(local_only=local_only)

        # Remove config
        nodes = [get_hostname()] if local_only else self._get_registered_object(
            'cluster').get_nodes(include_local=True)

        self.remove_config(nodes=nodes)
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:30,代码来源:base.py


示例2: create_id_volume

    def create_id_volume(self, nodes=None):
        """Create identification volume on the storage backend"""
        # Obtain volume object for ID volume
        volume = self.get_volume(self._id_volume_name)

        # If the storage backend is shared, then only needs to be created on
        # a single node (prefer local host if in list of nodes). If not shared,
        # ID volume will be created on all nodes
        if nodes is None:
            nodes = ([get_hostname()]
                     if get_hostname() in self.nodes else
                     [self.nodes[0]]) if self.shared else self.nodes

        try:
            # Create ID volume
            volume.create(size=2 ** 20, nodes=nodes)
        except ExternalStorageCommandErrorException:
            raise ExternalStorageCommandErrorException(
                ('An error occured whilst adding storage backend: Either the storage '
                 'backend has no free space (at least 1MB required) or '
                 'shared storage is being used, but has not been specified'))

        try:
            # Ensure that ID volume exists on all nodes
            volume.ensure_exists(nodes=self.nodes)
        except VolumeDoesNotExistError:
            raise ExternalStorageCommandErrorException(
                ('An error ocurred whilst verifying the storage backend: '
                 'A shared storage has been specified, but it is not'))
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:29,代码来源:base.py


示例3: pre_check_network

    def pre_check_network(self, name, interface):
        """Perform pre-limiary checks on node before determining
           that a network can be added"""
        self._get_registered_object('auth').assert_user_type('ConnectionUser', 'ClusterUser')
        # Ensure that the physical interface exists
        self.assert_interface_exists(interface)

        # Ensure that there are no interfaces present on the MCVirt instance
        # that match the network
        if self.check_exists(name):
            raise NetworkAlreadyExistsException('Network already exists on node: %s %s' %
                                                (name, get_hostname()))

        # Ensure that there is not already a network with the same name defined in
        # libvirt
        try:
            self._get_registered_object(
                'libvirt_connector'
            ).get_connection().networkLookupByName(name)

            # If the libvirt connect did not throw an error that
            # the network does not exist, raise an exception
            # as the network must be pressent
            # @TODO: do this more nicely. Get list of networks and
            # assert that it's not in the list
            raise NetworkAlreadyExistsException(
                'Network already defined in libvirt on node: %s %s' %
                (name, get_hostname()))
        except libvirtError:
            pass
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:30,代码来源:factory.py


示例4: undo

    def undo(self):
        """Execute the undo method for the function"""
        # If the local node is in the list of complete
        # commands, then undo it first
        if (get_hostname() in self.nodes and
                self.nodes[get_hostname()]['complete'] and
                hasattr(self.obj, self._undo_function_name)):

            # Set current node
            local_hostname = get_hostname()
            self.current_node = local_hostname

            Syslogger.logger().debug('Undo %s %s %s %s' %
                                     (get_hostname(),
                                      self._undo_function_name,
                                      str(self.nodes[get_hostname()]['args']),
                                      str(self.nodes[get_hostname()]['kwargs'])))
            getattr(self.obj, self._undo_function_name)(
                *self.nodes[get_hostname()]['args'],
                **self.nodes[get_hostname()]['kwargs'])

        # Iterate through nodes and undo
        for node in self.nodes:
            # Skip local node or if the function did not complete on the node
            if node == get_hostname() or not self.nodes[node]['complete']:
                continue

            # Run the remote undo method
            Syslogger.logger().debug('Undo %s %s %s %s' %
                                     (node,
                                      self.function.__name__,
                                      str(self.nodes[node]['args']),
                                      str(self.nodes[node]['kwargs'])))
            self._call_function_remote(node=node, undo=True)
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:34,代码来源:expose_method.py


示例5: delete_id_volume

    def delete_id_volume(self, nodes=None):
        """Delete the ID volume for the storage backend"""
        # Obtain volume object for ID volume
        volume = self.get_volume(self._id_volume_name)

        # If the storage backend is shared, then only needs to be created on
        # a single node (prefer local host if in list of nodes). If not shared,
        # ID volume will be created on all nodes
        if nodes is None:
            nodes = ([get_hostname()]
                     if get_hostname() in self.nodes else
                     [self.nodes[0]]) if self.shared else self.nodes

        # Create ID volume
        volume.delete(nodes=nodes)
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:15,代码来源:base.py


示例6: add_node_configuration

    def add_node_configuration(self, node_name, ip_address,
                               connection_user, connection_password,
                               ca_key):
        """Add MCVirt node to configuration, generates a cluster user on the remote node
        and stores credentials against node in the MCVirt configuration.
        """
        self._get_registered_object('auth').assert_permission(PERMISSIONS.MANAGE_CLUSTER)

        # Create CA file
        ssl_object = self._get_registered_object(
            'certificate_generator_factory').get_cert_generator(node_name)
        ssl_object.ca_pub_file = ca_key

        # Connect to node and obtain cluster user
        remote = Connection(username=connection_user, password=connection_password,
                            host=node_name)
        remote_user_factory = remote.get_connection('user_factory')
        connection_user = remote_user_factory.get_user_by_username(connection_user)
        remote.annotate_object(connection_user)
        username, password = connection_user.create_cluster_user(host=get_hostname())

        # Add node to configuration file
        def add_node_config(mcvirt_config):
            mcvirt_config['cluster']['nodes'][node_name] = {
                'ip_address': ip_address,
                'username': username,
                'password': password
            }
        MCVirtConfig().update_config(add_node_config)
开发者ID:Adimote,项目名称:MCVirt,代码行数:29,代码来源:cluster.py


示例7: get_remote_factory

 def get_remote_factory(self, node=None):
     if node is None or node == get_hostname():
         return self
     node = self._get_registered_object('cluster').get_remote_node(node)
     remote_factory = node.get_connection('iso_factory')
     node.annotate_object(remote_factory)
     return remote_factory
开发者ID:joesingo,项目名称:MCVirt,代码行数:7,代码来源:factory.py


示例8: gitRemove

 def gitRemove(self, message='', custom_file=None):
     """Remove and commits a configuration file"""
     if self._checkGitRepo():
         session_obj = self._get_registered_object('mcvirt_session')
         username = ''
         user = None
         if session_obj:
             try:
                 user = session_obj.get_proxy_user_object()
             except UserDoesNotExistException:
                 pass
         if user:
             username = session_obj.get_proxy_user_object().get_username()
         message += "\nUser: %s\nNode: %s" % (username, get_hostname())
         try:
             System.runCommand([self.GIT,
                                'rm',
                                '--cached',
                                self.config_file],
                               cwd=DirectoryLocation.BASE_STORAGE_DIR)
             System.runCommand([self.GIT, 'commit', '-m', message],
                               cwd=DirectoryLocation.BASE_STORAGE_DIR)
             System.runCommand([self.GIT,
                                'push'],
                               raise_exception_on_failure=False,
                               cwd=DirectoryLocation.BASE_STORAGE_DIR)
         except Exception:
             pass
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:28,代码来源:base.py


示例9: __init__

    def __init__(self):
        """Store required object member variables and create MCVirt object"""
        # Initialise Pyro4 with flag to showing that the daemon is being started
        Pyro4.current_context.STARTUP_PERIOD = True

        # Store nameserver, MCVirt instance and create daemon
        self.daemon_lock = DaemonLock()

        Pyro4.config.USE_MSG_WAITALL = False
        Pyro4.config.CREATE_SOCKET_METHOD = SSLSocket.create_ssl_socket
        Pyro4.config.CREATE_BROADCAST_SOCKET_METHOD = SSLSocket.create_broadcast_ssl_socket
        Pyro4.config.THREADPOOL_ALLOW_QUEUE = True
        Pyro4.config.THREADPOOL_SIZE = 128
        self.hostname = get_hostname()

        # Ensure that the required SSL certificates exist
        ssl_socket = CertificateGeneratorFactory().get_cert_generator('localhost')
        ssl_socket.check_certificates(check_client=False)
        ssl_socket = None

        # Wait for nameserver
        self.obtain_connection()

        RpcNSMixinDaemon.DAEMON = BaseRpcDaemon(host=self.hostname)
        self.register_factories()

        # Ensure libvirt is configured
        cert_gen_factory = RpcNSMixinDaemon.DAEMON.registered_factories[
            'certificate_generator_factory']
        cert_gen = cert_gen_factory.get_cert_generator('localhost')
        cert_gen.check_certificates()
        cert_gen = None
        cert_gen_factory = None
开发者ID:Adimote,项目名称:MCVirt,代码行数:33,代码来源:rpc_daemon.py


示例10: ensure_active

 def ensure_active(self):
     """Ensure that voljuem is active, otherwise, raise exception"""
     if not self.is_active():
         raise VolumeIsNotActiveException(
             'Volume %s is not active on %s' %
             (self.name, get_hostname())
         )
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:7,代码来源:base.py


示例11: getAllVmNames

    def getAllVmNames(self, node=None):
        """Returns a list of all VMs within the cluster or those registered on a specific node"""
        if node is not None:
            ArgumentValidator.validate_hostname(node)

        # If no node was defined, check the local configuration for all VMs
        if node is None:
            return [vm['name'] for vm in VirtualMachineConfig.get_global_config().values()]

        elif node == get_hostname():
            # @TODO - Why is this using libvirt?! Should use
            #         VM objects (i.e. config file to determine)
            #         and use a seperate function to get libvirt
            #         registered VMs
            # Obtain array of all domains from libvirt
            all_domains = self._get_registered_object(
                'libvirt_connector').get_connection().listAllDomains()
            return [vm.name() for vm in all_domains]

        else:
            # Return list of VMs registered on remote node
            cluster = self._get_registered_object('cluster')

            def remote_command(node_connection):
                """Get virtual machine names from remote node"""
                virtual_machine_factory = node_connection.get_connection('virtual_machine_factory')
                return virtual_machine_factory.getAllVmNames(node=node)
            return cluster.run_remote_command(callback_method=remote_command, nodes=[node])[node]
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:28,代码来源:factory.py


示例12: get_all

    def get_all(self, available_on_local_node=None, nodes=[], drbd=None,
                storage_type=None, shared=None, nodes_predefined=False,
                global_=None, default_location=None):
        """Return all storage backends, with optional filtering"""
        storage_objects = []

        for storage_id in self.get_config().keys():

            # Obtain storage object
            storage_object = self.get_object(storage_id)

            # Check if storage backend is global or not
            if global_ is not None and storage_object.is_global != global_:
                continue

            # Check if default location matches requested
            if (default_location is not None and
                    storage_object.get_location(return_default=True) != default_location):
                continue

            # Check storage is available on local node
            if (available_on_local_node and
                    get_hostname() not in storage_object.nodes):
                continue

            # If nodes are specified...
            if nodes:
                # Determine which nodes from the list are available
                available_nodes = []
                for node in nodes:
                    if node in storage_object.nodes:
                        available_nodes.append(node)

                # If the list of nodes is required (predefined) and not all are
                # present, skip storage backend
                if nodes_predefined and len(nodes) != len(available_nodes):
                    continue

                # Otherwise, (if the nodes are not required), ensure at least one
                # is available, otherwise, skip
                elif (not nodes_predefined) and not len(available_nodes):
                    continue

            # If drbd is specified, ensure storage object is suitable to run DRBD
            if drbd and not storage_object.is_drbd_suitable():
                continue

            # If storage_type is specified, ensure hat storage matches the object
            if storage_type and not self.get_class(storage_type) != storage_object.__class__:
                continue

            # If a shared type is defined, determine if it matches the object, otherwise skip
            if shared is not None and shared != storage_object.shared:
                continue

            # If all checks have passed, append to list of objects to return
            storage_objects.append(storage_object)

        return storage_objects
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:59,代码来源:factory.py


示例13: node_pre_check

 def node_pre_check(cls, cluster, libvirt_config, location):
     """Ensure volume group exists on node"""
     try:
         cls.ensure_exists(location)
     except InvalidStorageConfiguration, exc:
         raise InvalidStorageConfiguration(
             '%s on node %s' % (str(exc), get_hostname())
         )
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:8,代码来源:base.py


示例14: ensure_available

    def ensure_available(self):
        """Ensure that the storage backend is currently available on the node"""
        volume = self.get_volume(self._id_volume_name)

        if (not self.check_exists()) or not volume.check_exists():
            raise StorageBackendNotAvailableOnNode(
                'Storage backend %s is not currently avaialble on node: %s' % (
                    self.name, get_hostname()))
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:8,代码来源:base.py


示例15: insert_into_stat_db

    def insert_into_stat_db(self):
        """Add statistics to statistics database"""
        db_factory = self._get_registered_object('database_factory')
        db_rows = [
            (StatisticsDeviceType.HOST.value, get_hostname(),
             StatisticsStatType.CPU_USAGE.value, self._cpu_usage,
             "{:%s}".format(datetime.now())),

            (StatisticsDeviceType.HOST.value, get_hostname(),
             StatisticsStatType.MEMORY_USAGE.value, self._memory_usage,
             "{:%s}".format(datetime.now()))
        ]
        with db_factory.get_locking_connection() as db_inst:
            db_inst.cursor.executemany(
                """INSERT INTO stats(
                    device_type, device_id, stat_type, stat_value, stat_date
                ) VALUES(?, ?, ?, ?, ?)""",
                db_rows)
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:18,代码来源:host_statistics.py


示例16: generate_connection_info

    def generate_connection_info(self):
        """Generate required information to connect to this node from a remote node"""
        # Ensure user has required permissions
        self._get_registered_object('auth').assert_permission(
            PERMISSIONS.MANAGE_CLUSTER
        )

        # Ensure that the IP address configurations has been made correctly
        self.check_ip_configuration()

        # Create connection user
        user_factory = self._get_registered_object('user_factory')
        connection_username, connection_password = user_factory.generate_user(ConnectionUser)
        ssl_object = self._get_registered_object(
            'certificate_generator_factory').get_cert_generator(get_hostname())
        return [get_hostname(), self.get_cluster_ip_address(),
                connection_username, connection_password,
                ssl_object.get_ca_contents()]
开发者ID:Adimote,项目名称:MCVirt,代码行数:18,代码来源:cluster.py


示例17: _get_response_data

    def _get_response_data(self):
        """Determine and return response data"""
        # Return dict of node -> output, if a dict response was
        # specified
        if self.return_dict:
            return {node: self.nodes[node]['return_val']
                    for node in self.nodes.keys()}

        # Otherwise, default to returning data from local node
        elif get_hostname() in self.nodes:
            return self.nodes[get_hostname()]['return_val']

        # Otherwise, return the response from the first found node.
        elif self.nodes:
            return self.nodes[self.nodes.keys()[0]]['return_val']

        # Otherwise, if no node data, return None
        return None
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:18,代码来源:expose_method.py


示例18: __init__

    def __init__(self, server=None, remote=False):
        """Store member variables and ensure that openSSL is installed"""
        if not os.path.isfile(self.OPENSSL):
            raise OpenSSLNotFoundException('openssl not found: %s' % self.OPENSSL)

        if server == 'localhost' or server.startswith('127.') or server is None:
            self.server = get_hostname()
        else:
            self.server = server
        self.remote = remote
开发者ID:joesingo,项目名称:MCVirt,代码行数:10,代码来源:certificate_generator.py


示例19: __init__

    def __init__(self):
        """Store required object member variables and create MCVirt object"""
        # Before doing ANYTHING, ensure that the hostname that MCVirt thinks the
        # machine is (i.e. the hostname that the machine was already setup as)
        # matches the current hostname of the machine
        ensure_hostname_consistent()

        # Initialise Pyro4 with flag to showing that the daemon is being started
        Pyro4.current_context.STARTUP_PERIOD = True

        # Store nameserver, MCVirt instance and create daemon
        self.daemon_lock = DaemonLock()
        self.timer_objects = []

        Pyro4.config.USE_MSG_WAITALL = False
        Pyro4.config.CREATE_SOCKET_METHOD = SSLSocket.create_ssl_socket
        Pyro4.config.CREATE_BROADCAST_SOCKET_METHOD = SSLSocket.create_broadcast_ssl_socket
        Pyro4.config.THREADPOOL_ALLOW_QUEUE = True
        Pyro4.config.THREADPOOL_SIZE = 128
        self.hostname = get_hostname()

        # Ensure that the required SSL certificates exist
        ssl_socket = CertificateGeneratorFactory().get_cert_generator('localhost')
        ssl_socket.check_certificates(check_client=False)
        ssl_socket = None

        # Wait for nameserver
        Syslogger.logger().debug('Wait for connection to nameserver')
        self.obtain_connection()
        Syslogger.logger().debug('Obtained nameserver connection')

        RpcNSMixinDaemon.DAEMON = BaseRpcDaemon(host=self.hostname)
        self.register_factories()

        # Ensure libvirt is configured
        Syslogger.logger().debug('Start certificate check')
        cert_gen_factory = RpcNSMixinDaemon.DAEMON.registered_factories[
            'certificate_generator_factory']
        cert_gen = cert_gen_factory.get_cert_generator('localhost')
        cert_gen.check_certificates()
        cert_gen = None
        cert_gen_factory = None

        Syslogger.logger().debug('Register atexit')
        atexit.register(self.shutdown, 'atexit', '')
        for sig in (signal.SIGABRT, signal.SIGILL, signal.SIGINT,
                    signal.SIGSEGV, signal.SIGTERM):
            signal.signal(sig, self.shutdown)

        Syslogger.logger().debug('Initialising objects')
        for registered_object in RpcNSMixinDaemon.DAEMON.registered_factories:
            obj = RpcNSMixinDaemon.DAEMON.registered_factories[registered_object]
            if type(obj) is not types.TypeType:  # noqa
                Syslogger.logger().debug('Initialising object %s' % registered_object)
                obj.initialise()
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:55,代码来源:rpc_daemon.py


示例20: test_migrate_pre_migration_libvirt_failure

    def test_migrate_pre_migration_libvirt_failure(self):
        """Simulates a pre-migration libvirt failure"""
        # Set the mcvirt libvirt failure mode to simulate a pre-migration failure
        VirtualMachineLibvirtFail.LIBVIRT_FAILURE_MODE = LibvirtFailureMode.PRE_MIGRATION_FAILURE

        # Attempt to perform a migration
        with self.assertRaises(LibvirtFailureSimulationException):
            self.test_vm_object.onlineMigrate(self.local_vm_object._get_remote_nodes()[0])

        VirtualMachineLibvirtFail.LIBVIRT_FAILURE_MODE = LibvirtFailureMode.NORMAL_RUN

        # Ensure the VM is still registered on the local node and in a running state
        self.assertEqual(self.local_vm_object.getNode(), get_hostname())
        self.assertEqual(self.local_vm_object.get_power_state(), PowerStates.RUNNING.value)

        # Ensure that the VM is registered with the local libvirt instance and not on the remote
        # libvirt instance
        self.assertTrue(
            self.local_vm_object.get_name() in
            self.vm_factory.getAllVmNames(node=get_hostname())
        )
        self.assertFalse(
            self.local_vm_object.get_name() in
            self.vm_factory.getAllVmNames(node=self.local_vm_object._get_remote_nodes()[0])
        )

        # Ensure Drbd disks are in a valid state
        for disk_object in self.local_vm_object.get_hard_drive_objects():
            # Check that the disk is shown as not in-sync
            with self.assertRaises(DrbdVolumeNotInSyncException):
                disk_object._checkDrbdStatus()

            # Reset disk sync status and re-check status to ensure
            # the disk is otherwise in a valid state
            disk_object.setSyncState(True)
            disk_object._checkDrbdStatus()

            # Ensure that the local and remote disks are in the correct Drbd role
            local_role, remote_role = disk_object._drbdGetRole()
            self.assertEqual(local_role, DrbdRoleState.PRIMARY)
            self.assertEqual(remote_role, DrbdRoleState.SECONDARY)
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:41,代码来源:online_migrate_tests.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python md.get_default_access_token函数代码示例发布时间:2022-05-27
下一篇:
Python system.System类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap