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


Python StorageRouterList.get_by_machine_id方法代码示例

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


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

示例1: get_my_storagerouter

# 需要导入模块: from ovs.dal.lists.storagerouterlist import StorageRouterList [as 别名]
# 或者: from ovs.dal.lists.storagerouterlist.StorageRouterList import get_by_machine_id [as 别名]
 def get_my_storagerouter():
     """
     Returns unique machine storagerouter id
     :return: Storage Router this is executed on
     :rtype: StorageRouter
     """
     from ovs.dal.lists.storagerouterlist import StorageRouterList
     storagerouter = StorageRouterList.get_by_machine_id(System.get_my_machine_id())
     if storagerouter is None:
         raise RuntimeError('Could not find the local StorageRouter')
     return storagerouter
开发者ID:grimpy,项目名称:openvstorage,代码行数:13,代码来源:system.py

示例2: new_function

# 需要导入模块: from ovs.dal.lists.storagerouterlist import StorageRouterList [as 别名]
# 或者: from ovs.dal.lists.storagerouterlist.StorageRouterList import get_by_machine_id [as 别名]
 def new_function(*args, **kwargs):
     """
     Wrapped function
     """
     request = _find_request(args)
     new_kwargs = {}
     # Find out the arguments of the decorated function
     function_info = inspect.getargspec(f)
     if function_info.defaults is None:
         mandatory_vars = function_info.args[1:]
         optional_vars = []
     else:
         mandatory_vars = function_info.args[1:-len(function_info.defaults)]
         optional_vars = function_info.args[len(mandatory_vars) + 1:]
     # Check versioning
     version = regex.match(request.META['HTTP_ACCEPT']).groupdict()['version']
     versions = (max(min_version, settings.VERSION[0]), min(max_version, settings.VERSION[-1]))
     if version == '*':  # If accepting all versions, it defaults to the highest one
         version = versions[1]
     version = int(version)
     if version < versions[0] or version > versions[1]:
         raise NotAcceptable('API version requirements: {0} <= <version> <= {1}. Got {2}'.format(versions[0], versions[1], version))
     if 'version' in mandatory_vars:
         new_kwargs['version'] = version
         mandatory_vars.remove('version')
     # Fill request parameter, if available
     if 'request' in mandatory_vars:
         new_kwargs['request'] = request
         mandatory_vars.remove('request')
     # Fill main object, if required
     if 'pk' in kwargs and object_type is not None:
         typename = object_type.__name__.lower()
         try:
             instance = object_type(kwargs['pk'])
             if typename in mandatory_vars:
                 new_kwargs[typename] = instance
                 mandatory_vars.remove(typename)
         except ObjectNotFoundException:
             raise Http404()
     # Fill local storagerouter, if requested
     if 'local_storagerouter' in mandatory_vars:
         storagerouter = StorageRouterList.get_by_machine_id(settings.UNIQUE_ID)
         new_kwargs['local_storagerouter'] = storagerouter
         mandatory_vars.remove('local_storagerouter')
     # Fill mandatory parameters
     post_data = request.DATA if hasattr(request, 'DATA') else request.POST
     get_data = request.QUERY_PARAMS if hasattr(request, 'QUERY_PARAMS') else request.GET
     for name in mandatory_vars:
         if name in kwargs:
             new_kwargs[name] = kwargs[name]
         else:
             if name not in post_data:
                 if name not in get_data:
                     raise NotAcceptable('Invalid data passed: {0} is missing'.format(name))
                 new_kwargs[name] = _try_parse(get_data[name])
             else:
                 new_kwargs[name] = _try_parse(post_data[name])
     # Try to fill optional parameters
     for name in optional_vars:
         if name in kwargs:
             new_kwargs[name] = kwargs[name]
         else:
             if name in post_data:
                 new_kwargs[name] = _try_parse(post_data[name])
             elif name in get_data:
                 new_kwargs[name] = _try_parse(get_data[name])
     # Call the function
     return f(args[0], **new_kwargs)
开发者ID:dawnpower,项目名称:framework,代码行数:70,代码来源:decorators.py

示例3: new_function

# 需要导入模块: from ovs.dal.lists.storagerouterlist import StorageRouterList [as 别名]
# 或者: from ovs.dal.lists.storagerouterlist.StorageRouterList import get_by_machine_id [as 别名]
 def new_function(*args, **kwargs):
     """
     Wrapped function
     """
     request = _find_request(args)
     new_kwargs = {}
     validation_new_kwargs = {}
     # Find out the arguments of the decorated function
     if validator is not None:
         f_info = inspect.getargspec(validator)
         if f_info.defaults is None:
             validation_mandatory_vars = f_info.args[1:]
             validation_optional_vars = []
         else:
             validation_mandatory_vars = f_info.args[1:-len(f_info.defaults)]
             validation_optional_vars = f_info.args[len(validation_mandatory_vars) + 1:]
     else:
         validation_mandatory_vars = []
         validation_optional_vars = []
     # Check versioning
     version_match = regex.match(request.META['HTTP_ACCEPT'])
     if version_match is not None:
         version = version_match.groupdict()['version']
     else:
         version = settings.VERSION[-1]
     raw_version = version
     versions = (max(min_version, settings.VERSION[0]), min(max_version, settings.VERSION[-1]))
     if version == '*':  # If accepting all versions, it defaults to the highest one
         version = versions[1]
     version = int(version)
     if version < versions[0] or version > versions[1]:
         raise HttpNotAcceptableException(error_description='API version requirements: {0} <= <version> <= {1}. Got {2}'.format(versions[0], versions[1], version),
                                          error='invalid_version')
     # Load some information
     instance = None
     if 'pk' in kwargs and object_type is not None:
         try:
             instance = object_type(kwargs['pk'])
         except ObjectNotFoundException:
             raise HttpNotFoundException(error_description='The requested object could not be found',
                                         error='object_not_found')
     # Build new kwargs
     for _mandatory_vars, _optional_vars, _new_kwargs in [(f.ovs_metadata['load']['mandatory'][:], f.ovs_metadata['load']['optional'][:], new_kwargs),
                                                          (validation_mandatory_vars, validation_optional_vars, validation_new_kwargs)]:
         if 'version' in _mandatory_vars:
             _new_kwargs['version'] = version
             _mandatory_vars.remove('version')
         if 'raw_version' in _mandatory_vars:
             _new_kwargs['raw_version'] = raw_version
             _mandatory_vars.remove('raw_version')
         if 'request' in _mandatory_vars:
             _new_kwargs['request'] = request
             _mandatory_vars.remove('request')
         if instance is not None:
             typename = object_type.__name__.lower()
             if typename in _mandatory_vars:
                 _new_kwargs[typename] = instance
                 _mandatory_vars.remove(typename)
         if 'local_storagerouter' in _mandatory_vars:
             storagerouter = StorageRouterList.get_by_machine_id(settings.UNIQUE_ID)
             _new_kwargs['local_storagerouter'] = storagerouter
             _mandatory_vars.remove('local_storagerouter')
         # The rest of the mandatory parameters
         post_data = request.DATA if hasattr(request, 'DATA') else request.POST
         get_data = request.QUERY_PARAMS if hasattr(request, 'QUERY_PARAMS') else request.GET
         for name in _mandatory_vars:
             if name in kwargs:
                 _new_kwargs[name] = kwargs[name]
             else:
                 if name not in post_data:
                     if name not in get_data:
                         raise HttpNotAcceptableException(error_description='Invalid data passed: {0} is missing'.format(name),
                                                          error='invalid_data')
                     _new_kwargs[name] = _try_parse(get_data[name])
                 else:
                     _new_kwargs[name] = _try_parse(post_data[name])
         # Try to fill optional parameters
         for name in _optional_vars:
             if name in kwargs:
                 _new_kwargs[name] = kwargs[name]
             else:
                 if name in post_data:
                     _new_kwargs[name] = _try_parse(post_data[name])
                 elif name in get_data:
                     _new_kwargs[name] = _try_parse(get_data[name])
     # Execute validator
     if validator is not None:
         validator(args[0], **validation_new_kwargs)
     # Call the function
     return f(args[0], **new_kwargs)
开发者ID:grimpy,项目名称:openvstorage,代码行数:92,代码来源:decorators.py

示例4: demote_node

# 需要导入模块: from ovs.dal.lists.storagerouterlist import StorageRouterList [as 别名]
# 或者: from ovs.dal.lists.storagerouterlist.StorageRouterList import get_by_machine_id [as 别名]
    def demote_node(cluster_ip, master_ip, ip_client_map, unique_id, unconfigure_memcached, unconfigure_rabbitmq, offline_nodes=None):
        """
        Demotes a given node
        """
        from ovs.dal.lists.storagerouterlist import StorageRouterList

        Toolbox.log(logger=NodeTypeController._logger, messages='Demoting node', title=True)
        if offline_nodes is None:
            offline_nodes = []

        if unconfigure_memcached is True and len(offline_nodes) == 0:
            if NodeTypeController._validate_local_memcache_servers(ip_client_map) is False:
                raise RuntimeError('Not all memcache nodes can be reached which is required for demoting a node.')

        # Find other (arakoon) master nodes
        arakoon_cluster_name = str(Configuration.get('/ovs/framework/arakoon_clusters|ovsdb'))
        arakoon_metadata = ArakoonInstaller.get_arakoon_metadata_by_cluster_name(cluster_name=arakoon_cluster_name)
        config = ArakoonClusterConfig(cluster_id=arakoon_cluster_name, filesystem=False)
        config.load_config()
        master_node_ips = [node.ip for node in config.nodes]
        if cluster_ip in master_node_ips:
            master_node_ips.remove(cluster_ip)
        if len(master_node_ips) == 0:
            raise RuntimeError('There should be at least one other master node')

        storagerouter = StorageRouterList.get_by_machine_id(unique_id)
        storagerouter.node_type = 'EXTRA'
        storagerouter.save()

        offline_node_ips = [node.ip for node in offline_nodes]
        if arakoon_metadata['internal'] is True:
            Toolbox.log(logger=NodeTypeController._logger, messages='Leaving Arakoon {0} cluster'.format(arakoon_cluster_name))
            ArakoonInstaller.shrink_cluster(deleted_node_ip=cluster_ip,
                                            remaining_node_ips=master_node_ips,
                                            cluster_name=arakoon_cluster_name,
                                            offline_nodes=offline_node_ips)

        try:
            external_config = Configuration.get('/ovs/framework/external_config')
            if external_config is None:
                config_store = Configuration.get_store()
                if config_store == 'arakoon':
                    Toolbox.log(logger=NodeTypeController._logger, messages='Leaving Arakoon config cluster')
                    ArakoonInstaller.shrink_cluster(deleted_node_ip=cluster_ip,
                                                    remaining_node_ips=master_node_ips,
                                                    cluster_name='config',
                                                    offline_nodes=offline_node_ips,
                                                    filesystem=True)
                else:
                    from ovs.extensions.db.etcd.installer import EtcdInstaller
                    Toolbox.log(logger=NodeTypeController._logger, messages='Leaving Etcd cluster')
                    EtcdInstaller.shrink_cluster(master_ip, cluster_ip, 'config', offline_node_ips)
        except Exception as ex:
            Toolbox.log(logger=NodeTypeController._logger, messages=['\nFailed to leave configuration cluster', ex], loglevel='exception')

        Toolbox.log(logger=NodeTypeController._logger, messages='Update configurations')
        try:
            if unconfigure_memcached is True:
                endpoints = Configuration.get('/ovs/framework/memcache|endpoints')
                endpoint = '{0}:{1}'.format(cluster_ip, 11211)
                if endpoint in endpoints:
                    endpoints.remove(endpoint)
                Configuration.set('/ovs/framework/memcache|endpoints', endpoints)
            if unconfigure_rabbitmq is True:
                endpoints = Configuration.get('/ovs/framework/messagequeue|endpoints')
                endpoint = '{0}:{1}'.format(cluster_ip, 5672)
                if endpoint in endpoints:
                    endpoints.remove(endpoint)
                Configuration.set('/ovs/framework/messagequeue|endpoints', endpoints)
        except Exception as ex:
            Toolbox.log(logger=NodeTypeController._logger, messages=['\nFailed to update configurations', ex], loglevel='exception')

        if arakoon_metadata['internal'] is True:
            Toolbox.log(logger=NodeTypeController._logger, messages='Restarting master node services')
            remaining_nodes = ip_client_map.keys()[:]
            if cluster_ip in remaining_nodes:
                remaining_nodes.remove(cluster_ip)

            PersistentFactory.store = None
            VolatileFactory.store = None

            for service in storagerouter.services:
                if service.name == 'arakoon-ovsdb':
                    service.delete()

        target_client = None
        if storagerouter in offline_nodes:
            if unconfigure_rabbitmq is True:
                Toolbox.log(logger=NodeTypeController._logger, messages='Removing/unconfiguring offline RabbitMQ node')
                client = ip_client_map[master_ip]
                try:
                    client.run(['rabbitmqctl', 'forget_cluster_node', '[email protected]{0}'.format(storagerouter.name)])
                except Exception as ex:
                    Toolbox.log(logger=NodeTypeController._logger, messages=['\nFailed to forget RabbitMQ cluster node', ex], loglevel='exception')
        else:
            target_client = ip_client_map[cluster_ip]
            if unconfigure_rabbitmq is True:
                Toolbox.log(logger=NodeTypeController._logger, messages='Removing/unconfiguring RabbitMQ')
                try:
                    if ServiceManager.has_service('rabbitmq-server', client=target_client):
#.........这里部分代码省略.........
开发者ID:openvstorage,项目名称:framework,代码行数:103,代码来源:nodetype.py

示例5: promote_node

# 需要导入模块: from ovs.dal.lists.storagerouterlist import StorageRouterList [as 别名]
# 或者: from ovs.dal.lists.storagerouterlist.StorageRouterList import get_by_machine_id [as 别名]
    def promote_node(cluster_ip, master_ip, ip_client_map, unique_id, configure_memcached, configure_rabbitmq):
        """
        Promotes a given node
        """
        from ovs.dal.lists.storagerouterlist import StorageRouterList
        from ovs.dal.lists.servicetypelist import ServiceTypeList
        from ovs.dal.lists.servicelist import ServiceList
        from ovs.dal.hybrids.service import Service

        Toolbox.log(logger=NodeTypeController._logger, messages='Promoting node', title=True)
        if configure_memcached is True:
            if NodeTypeController._validate_local_memcache_servers(ip_client_map) is False:
                raise RuntimeError('Not all memcache nodes can be reached which is required for promoting a node.')

        target_client = ip_client_map[cluster_ip]
        machine_id = System.get_my_machine_id(target_client)
        node_name, _ = target_client.get_hostname()
        master_client = ip_client_map[master_ip]

        storagerouter = StorageRouterList.get_by_machine_id(unique_id)
        storagerouter.node_type = 'MASTER'
        storagerouter.save()

        external_config = Configuration.get('/ovs/framework/external_config')
        if external_config is None:
            config_store = Configuration.get_store()
            if config_store == 'arakoon':
                Toolbox.log(logger=NodeTypeController._logger, messages='Joining Arakoon configuration cluster')
                metadata = ArakoonInstaller.extend_cluster(master_ip=master_ip,
                                                           new_ip=cluster_ip,
                                                           cluster_name='config',
                                                           base_dir=Configuration.get('/ovs/framework/paths|ovsdb'),
                                                           ports=[26400, 26401],
                                                           filesystem=True)
                ArakoonInstaller.restart_cluster_add(cluster_name='config',
                                                     current_ips=metadata['ips'],
                                                     new_ip=cluster_ip,
                                                     filesystem=True)
                ServiceManager.register_service(node_name=machine_id,
                                                service_metadata=metadata['service_metadata'])
            else:
                from ovs.extensions.db.etcd.installer import EtcdInstaller
                Toolbox.log(logger=NodeTypeController._logger, messages='Joining Etcd cluster')
                EtcdInstaller.extend_cluster(master_ip, cluster_ip, 'config')

        # Find other (arakoon) master nodes
        arakoon_cluster_name = str(Configuration.get('/ovs/framework/arakoon_clusters|ovsdb'))
        arakoon_metadata = ArakoonInstaller.get_arakoon_metadata_by_cluster_name(cluster_name=arakoon_cluster_name)
        config = ArakoonClusterConfig(cluster_id=arakoon_cluster_name, filesystem=False)
        config.load_config()
        master_node_ips = [node.ip for node in config.nodes]
        if cluster_ip in master_node_ips:
            master_node_ips.remove(cluster_ip)
        if len(master_node_ips) == 0:
            raise RuntimeError('There should be at least one other master node')

        arakoon_ports = []
        if arakoon_metadata['internal'] is True:
            Toolbox.log(logger=NodeTypeController._logger, messages='Joining Arakoon OVS DB cluster')
            result = ArakoonInstaller.extend_cluster(master_ip=master_ip,
                                                     new_ip=cluster_ip,
                                                     cluster_name=arakoon_cluster_name,
                                                     base_dir=Configuration.get('/ovs/framework/paths|ovsdb'))
            ArakoonInstaller.restart_cluster_add(cluster_name=arakoon_cluster_name,
                                                 current_ips=result['ips'],
                                                 new_ip=cluster_ip, filesystem=False)
            arakoon_ports = [result['client_port'], result['messaging_port']]

        if configure_memcached is True:
            NodeTypeController.configure_memcached(client=target_client, logger=NodeTypeController._logger)
        NodeTypeController.add_services(client=target_client, node_type='master', logger=NodeTypeController._logger)

        Toolbox.log(logger=NodeTypeController._logger, messages='Update configurations')
        if configure_memcached is True:
            endpoints = Configuration.get('/ovs/framework/memcache|endpoints')
            endpoint = '{0}:11211'.format(cluster_ip)
            if endpoint not in endpoints:
                endpoints.append(endpoint)
                Configuration.set('/ovs/framework/memcache|endpoints', endpoints)
        if configure_rabbitmq is True:
            endpoints = Configuration.get('/ovs/framework/messagequeue|endpoints')
            endpoint = '{0}:5672'.format(cluster_ip)
            if endpoint not in endpoints:
                endpoints.append(endpoint)
                Configuration.set('/ovs/framework/messagequeue|endpoints', endpoints)

        if arakoon_metadata['internal'] is True:
            Toolbox.log(logger=NodeTypeController._logger, messages='Restarting master node services')
            ArakoonInstaller.restart_cluster_add(cluster_name=arakoon_cluster_name,
                                                 current_ips=master_node_ips,
                                                 new_ip=cluster_ip,
                                                 filesystem=False)
            PersistentFactory.store = None
            VolatileFactory.store = None

            if 'arakoon-ovsdb' not in [s.name for s in ServiceList.get_services() if s.is_internal is False or s.storagerouter.ip == cluster_ip]:
                service = Service()
                service.name = 'arakoon-ovsdb'
                service.type = ServiceTypeList.get_by_name(ServiceType.SERVICE_TYPES.ARAKOON)
                service.ports = arakoon_ports
#.........这里部分代码省略.........
开发者ID:openvstorage,项目名称:framework,代码行数:103,代码来源:nodetype.py


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