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


Python messaging.MessageController类代码示例

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


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

示例1: task_postrun_handler

def task_postrun_handler(sender=None, task_id=None, task=None, args=None, kwargs=None, **kwds):
    """
    Hook for celery postrun event
    """
    _ = sender, task, args, kwargs, kwds
    try:
        MessageController.fire(MessageController.Type.TASK_COMPLETE, task_id)
    except Exception as ex:
        loghandler.error('Caught error during postrun handler: {0}'.format(ex))
开发者ID:dawnpower,项目名称:framework,代码行数:9,代码来源:celery_run.py

示例2: _wait

 def _wait(subscriber_id, message_id):
     messages = []
     last_message_id = 0
     counter = 0
     while len(messages) == 0:
         messages, last_message_id = MessageController.get_messages(subscriber_id, message_id)
         if len(messages) == 0:
             counter += 1
             if counter >= 120:  # 120 * 0.5 seconds = 60 seconds  = 1 minute
                 break
             gevent.sleep(.5)
     if len(messages) == 0:
         last_message_id = MessageController.last_message_id()
     MessageController.reset_subscriptions(subscriber_id)
     return messages, last_message_id
开发者ID:grimpy,项目名称:openvstorage,代码行数:15,代码来源:messaging.py

示例3: subscribe

 def subscribe(self, request, pk):
     """
     Subscribes a subscriber to a set of types
     """
     try:
         pk = int(pk)
         subscriptions = request.DATA
         cleaned_subscriptions = []
         if not isinstance(subscriptions, list):
             raise TypeError
         for s in subscriptions:
             if str(s) in MessageController.Type.ALL:
                 cleaned_subscriptions.append(str(s))
     except (ValueError, TypeError):
         return Response(status=status.HTTP_400_BAD_REQUEST)
     MessageController.subscribe(pk, cleaned_subscriptions)
     return Response(cleaned_subscriptions, status=status.HTTP_200_OK)
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:17,代码来源:messaging.py

示例4: last

 def last(self, pk):
     """
     Get the last messageid
     """
     try:
         _ = int(pk)
     except (ValueError, TypeError):
         return Response(status=status.HTTP_400_BAD_REQUEST)
     return Response(MessageController.last_message_id(), status=status.HTTP_200_OK)
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:9,代码来源:messaging.py

示例5: retrieve

 def retrieve(self, pk):
     """
     Retrieves the subscriptions for a given subscriber
     """
     try:
         pk = int(pk)
     except (ValueError, TypeError):
         return Response(status=status.HTTP_400_BAD_REQUEST)
     return Response(MessageController.subscriptions(pk), status=status.HTTP_200_OK)
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:9,代码来源:messaging.py

示例6: last

 def last(self, pk):
     """
     Get the last messageid
     :param pk: Primary key of subscriber
     :type pk: int
     """
     try:
         _ = int(pk)
     except (ValueError, TypeError):
         return Response(status=status.HTTP_400_BAD_REQUEST)
     return Response(MessageController.last_message_id(), status=status.HTTP_200_OK)
开发者ID:grimpy,项目名称:openvstorage,代码行数:11,代码来源:messaging.py

示例7: delete_from_voldrv

    def delete_from_voldrv(name, storagedriver_id):
        """
        This method will delete a vmachine based on the name of the vmx given
        """
        pmachine = PMachineList.get_by_storagedriver_id(storagedriver_id)
        if pmachine.hvtype not in ['VMWARE', 'KVM']:
            return

        hypervisor = Factory.get(pmachine)
        name = hypervisor.clean_vmachine_filename(name)
        if pmachine.hvtype == 'VMWARE':
            storagedriver = StorageDriverList.get_by_storagedriver_id(storagedriver_id)
            vpool = storagedriver.vpool
        else:
            vpool = None
        vm = VMachineList.get_by_devicename_and_vpool(name, vpool)
        if vm is not None:
            MessageController.fire(MessageController.Type.EVENT, {'type': 'vmachine_deleted',
                                                                  'metadata': {'name': vm.name}})
            vm.delete(abandon=['vdisks'])
开发者ID:JasperLue,项目名称:openvstorage,代码行数:20,代码来源:vmachine.py

示例8: wait

 def wait(self, pk, message_id):
     """
     Wait for messages to appear for a given subscriber
     """
     try:
         pk = int(pk)
         message_id = int(message_id)
     except (ValueError, TypeError):
         return Response(status=status.HTTP_400_BAD_REQUEST)
     thread = gevent.spawn(MessagingViewSet._wait, pk, message_id)
     gevent.joinall([thread])
     messages, last_message_id = thread.value
     return Response({'messages'       : messages,
                      'last_message_id': last_message_id,
                      'subscriptions'  : MessageController.subscriptions(pk)}, status=status.HTTP_200_OK)
开发者ID:BillTheBest,项目名称:openvstorage,代码行数:15,代码来源:messaging.py

示例9: wait

 def wait(self, pk, message_id):
     """
     Wait for messages to appear for a given subscriber
     :param pk: Primary key of subscriber
     :type pk: int
     :param message_id: The last message_id that was already received
     :type message_id: str
     """
     try:
         pk = int(pk)
         message_id = int(message_id)
     except (ValueError, TypeError):
         return Response(status=status.HTTP_400_BAD_REQUEST)
     thread = gevent.spawn(MessagingViewSet._wait, pk, message_id)
     gevent.joinall([thread])
     result = thread.value
     if result is None:
         messages = []
         last_message_id = message_id
     else:
         messages, last_message_id = thread.value
     return Response({'messages': messages,
                      'last_message_id': last_message_id,
                      'subscriptions': MessageController.subscriptions(pk)}, status=status.HTTP_200_OK)
开发者ID:grimpy,项目名称:openvstorage,代码行数:24,代码来源:messaging.py

示例10: list

 def list(self):
     """
     Provides a list of subscriptions
     """
     return Response(MessageController.all_subscriptions(), status=status.HTTP_200_OK)
开发者ID:grimpy,项目名称:openvstorage,代码行数:5,代码来源:messaging.py

示例11: update_vmachine_config

    def update_vmachine_config(vmachine, vm_object, pmachine=None):
        """
        Update a vMachine configuration with a given vMachine configuration
        :param vmachine: Virtual Machine to update
        :param vm_object: New virtual machine info
        :param pmachine: Physical machine of the virtual machine
        """
        try:
            vdisks_synced = 0
            if vmachine.name is None:
                MessageController.fire(MessageController.Type.EVENT,
                                       {'type': 'vmachine_created',
                                        'metadata': {'name': vm_object['name']}})
            elif vmachine.name != vm_object['name']:
                MessageController.fire(MessageController.Type.EVENT,
                                       {'type': 'vmachine_renamed',
                                        'metadata': {'old_name': vmachine.name,
                                                     'new_name': vm_object['name']}})
            if pmachine is not None:
                vmachine.pmachine = pmachine
            vmachine.name = vm_object['name']
            vmachine.hypervisor_id = vm_object['id']
            vmachine.devicename = vm_object['backing']['filename']
            vmachine.save()
            # Updating and linking disks
            storagedrivers = StorageDriverList.get_storagedrivers()
            datastores = dict([('{0}:{1}'.format(storagedriver.storage_ip, storagedriver.mountpoint), storagedriver) for storagedriver in storagedrivers])
            vdisk_guids = []
            mutex = volatile_mutex('{0}_{1}'.format(vmachine.name, vmachine.devicename))
            for disk in vm_object['disks']:
                ensure_safety = False
                if disk['datastore'] in vm_object['datastores']:
                    datastore = vm_object['datastores'][disk['datastore']]
                    if datastore in datastores:
                        try:
                            mutex.acquire(wait=10)
                            vdisk = VDiskList.get_by_devicename_and_vpool(disk['filename'], datastores[datastore].vpool)
                            if vdisk is None:
                                # The disk couldn't be located, but is in our datastore. We might be in a recovery scenario
                                vdisk = VDisk()
                                vdisk.vpool = datastores[datastore].vpool
                                vdisk.reload_client()
                                vdisk.devicename = disk['filename']
                                vdisk.volume_id = vdisk.storagedriver_client.get_volume_id(str(disk['backingfilename']))
                                vdisk.size = vdisk.info['volume_size']
                                vdisk.metadata = {'lba_size': vdisk.info['lba_size'],
                                                  'cluster_multiplier': vdisk.info['cluster_multiplier']}
                                # Create the disk in a locked context, but don't execute long running-task in same context
                                vdisk.save()
                                ensure_safety = True
                        finally:
                            mutex.release()
                        if ensure_safety:
                            MDSServiceController.ensure_safety(vdisk)
                            VDiskController.dtl_checkup(vdisk_guid=vdisk.guid)

                        # Update the disk with information from the hypervisor
                        if vdisk.vmachine is None:
                            MessageController.fire(MessageController.Type.EVENT,
                                                   {'type': 'vdisk_attached',
                                                    'metadata': {'vmachine_name': vmachine.name,
                                                                 'vdisk_name': disk['name']}})
                        vdisk.vmachine = vmachine
                        vdisk.name = disk['name']
                        vdisk.order = disk['order']
                        vdisk.save()
                        vdisk_guids.append(vdisk.guid)
                        vdisks_synced += 1

            for vdisk in vmachine.vdisks:
                if vdisk.guid not in vdisk_guids:
                    MessageController.fire(MessageController.Type.EVENT,
                                           {'type': 'vdisk_detached',
                                            'metadata': {'vmachine_name': vmachine.name,
                                                         'vdisk_name': vdisk.name}})
                    vdisk.vmachine = None
                    vdisk.save()

            VMachineController._logger.info('Updating vMachine finished (name {0}, {1} vdisks (re)linked)'.format(
                vmachine.name, vdisks_synced
            ))
        except Exception as ex:
            VMachineController._logger.info('Error during vMachine update: {0}'.format(str(ex)))
            raise
开发者ID:DarumasLegs,项目名称:framework,代码行数:84,代码来源:vmachine.py

示例12: update_vmachine_config

    def update_vmachine_config(vmachine, vm_object, pmachine=None):
        """
        Update a vMachine configuration with a given vMachine configuration
        """
        try:
            vdisks_synced = 0
            if vmachine.name is None:
                MessageController.fire(MessageController.Type.EVENT,
                                       {'type': 'vmachine_created',
                                        'metadata': {'name': vm_object['name']}})
            elif vmachine.name != vm_object['name']:
                MessageController.fire(MessageController.Type.EVENT,
                                       {'type': 'vmachine_renamed',
                                        'metadata': {'old_name': vmachine.name,
                                                     'new_name': vm_object['name']}})
            if pmachine is not None:
                vmachine.pmachine = pmachine
            vmachine.name = vm_object['name']
            vmachine.hypervisor_id = vm_object['id']
            vmachine.devicename = vm_object['backing']['filename']
            vmachine.save()
            # Updating and linking disks
            storagedrivers = StorageDriverList.get_storagedrivers()
            datastores = dict([('{}:{}'.format(storagedriver.storage_ip, storagedriver.mountpoint), storagedriver) for storagedriver in storagedrivers])
            vdisk_guids = []
            for disk in vm_object['disks']:
                if disk['datastore'] in vm_object['datastores']:
                    datastore = vm_object['datastores'][disk['datastore']]
                    if datastore in datastores:
                        vdisk = VDiskList.get_by_devicename_and_vpool(disk['filename'], datastores[datastore].vpool)
                        if vdisk is None:
                            # The disk couldn't be located, but is in our datastore. We might be in a recovery scenario
                            vdisk = VDisk()
                            vdisk.vpool = datastores[datastore].vpool
                            vdisk.reload_client()
                            vdisk.devicename = disk['filename']
                            vdisk.volume_id = vdisk.storagedriver_client.get_volume_id(str(disk['backingfilename']))
                            vdisk.size = vdisk.info['volume_size']
                        # Update the disk with information from the hypervisor
                        if vdisk.vmachine is None:
                            MessageController.fire(MessageController.Type.EVENT,
                                                   {'type': 'vdisk_attached',
                                                    'metadata': {'vmachine_name': vmachine.name,
                                                                 'vdisk_name': disk['name']}})
                        vdisk.vmachine = vmachine
                        vdisk.name = disk['name']
                        vdisk.order = disk['order']
                        vdisk.save()
                        vdisk_guids.append(vdisk.guid)
                        vdisks_synced += 1

            for vdisk in vmachine.vdisks:
                if vdisk.guid not in vdisk_guids:
                    MessageController.fire(MessageController.Type.EVENT,
                                           {'type': 'vdisk_detached',
                                            'metadata': {'vmachine_name': vmachine.name,
                                                         'vdisk_name': vdisk.name}})
                    vdisk.vmachine = None
                    vdisk.save()

            logger.info('Updating vMachine finished (name {}, {} vdisks (re)linked)'.format(
                vmachine.name, vdisks_synced
            ))
        except Exception as ex:
            logger.info('Error during vMachine update: {0}'.format(str(ex)))
            raise
开发者ID:mflu,项目名称:openvstorage_centos,代码行数:66,代码来源:vmachine.py

示例13: task_postrun_handler

def task_postrun_handler(sender=None, task_id=None, task=None, args=None, kwargs=None, **kwds):
    """
    Hook for celery postrun event
    """
    _ = sender, task, args, kwargs, kwds
    MessageController.fire(MessageController.Type.TASK_COMPLETE, task_id)
开发者ID:jianyongchen,项目名称:openvstorage,代码行数:6,代码来源:celery_run.py


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