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


Python utils.str_time_to_unix函数代码示例

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


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

示例1: _get_filter_args

def _get_filter_args(klass, request, custom_filters=None):
    filter_args = {}
    if 'instance' in request.GET:
        uuid = request.GET['instance']
        filter_args['instance'] = uuid
        if not utils.is_uuid_like(uuid):
            msg = "%s is not uuid-like" % uuid
            raise BadRequestException(msg)

    for (key, value) in request.GET.items():
            if not custom_filters or key not in custom_filters:
                if key.endswith('_min'):
                    k = key[0:-4]
                    _check_has_field(klass, k)
                    try:
                        filter_args['%s__gte' % k] = \
                            utils.str_time_to_unix(value)
                    except AttributeError:
                        msg = "Range filters must be dates."
                        raise BadRequestException(message=msg)
                elif key.endswith('_max'):
                    k = key[0:-4]
                    _check_has_field(klass, k)
                    try:
                        filter_args['%s__lte' % k] = \
                            utils.str_time_to_unix(value)
                    except AttributeError:
                        msg = "Range filters must be dates."
                        raise BadRequestException(message=msg)

    return filter_args
开发者ID:anujm,项目名称:stacktach,代码行数:31,代码来源:dbapi.py

示例2: test_get_instance_with_metadata

 def test_get_instance_with_metadata(self):
     launched_at = datetime.datetime.utcnow() - datetime.timedelta(minutes=5)
     launched_at = str(launched_at)
     terminated_at = str(datetime.datetime.utcnow())
     results = [self._fake_instance(launched_at=launched_at,
                                    terminated_at=terminated_at,
                                    deleted=True)]
     metadata_results = self._fake_metadata()
     self.mock_for_query('nova', nova.GET_INSTANCE_QUERY % INSTANCE_ID_1,
                         results)
     self.mock_for_query('nova',
                         nova.GET_INSTANCE_SYSTEM_METADATA % INSTANCE_ID_1,
                         metadata_results)
     self.mox.ReplayAll()
     instance = self.client.get_instance('RegionOne', INSTANCE_ID_1,
                                         get_metadata=True)
     self.assertIsNotNone(instance)
     self.assertEqual(instance['id'], INSTANCE_ID_1)
     self.assertEqual(instance['instance_flavor_id'], INSTANCE_FLAVOR_ID_1)
     launched_at_dec = stackutils.str_time_to_unix(launched_at)
     self.assertEqual(instance['launched_at'], launched_at_dec)
     terminated_at_dec = stackutils.str_time_to_unix(terminated_at)
     self.assertEqual(instance['deleted_at'], terminated_at_dec)
     self.assertTrue(instance['deleted'])
     self.mox.VerifyAll()
开发者ID:DragonDM,项目名称:stacktach,代码行数:25,代码来源:test_reconciler.py

示例3: _process_exists

def _process_exists(raw, body):
    payload = body['payload']
    instance_id = payload['instance_id']
    launched_at = utils.str_time_to_unix(payload['launched_at'])
    launched_range = (launched_at, launched_at+1)
    usage = STACKDB.get_instance_usage(instance=instance_id,
                                       launched_at__range=launched_range)
    values = {}
    values['message_id'] = body['message_id']
    values['instance'] = instance_id
    values['launched_at'] = launched_at
    beginning = utils.str_time_to_unix(payload['audit_period_beginning'])
    values['audit_period_beginning'] = beginning
    ending = utils.str_time_to_unix(payload['audit_period_ending'])
    values['audit_period_ending'] = ending
    values['instance_type_id'] = payload['instance_type_id']
    if usage:
        values['usage'] = usage
    values['raw'] = raw

    deleted_at = payload.get('deleted_at')
    if deleted_at and deleted_at != '':
        # We only want to pre-populate the 'delete' if we know this is in fact
        #     an exist event for a deleted instance. Otherwise, there is a
        #     chance we may populate it for a previous period's exist.
        delete = STACKDB.get_instance_delete(instance=instance_id,
                                             launched_at__range=launched_range)
        deleted_at = utils.str_time_to_unix(deleted_at)
        values['deleted_at'] = deleted_at
        if delete:
            values['delete'] = delete

    exists = STACKDB.create_instance_exists(**values)
    STACKDB.save(exists)
开发者ID:mendeni,项目名称:stacktach,代码行数:34,代码来源:views.py

示例4: get_event_stats

def get_event_stats(request):
    try:
        filters = {}

        if 'when_min' in request.GET or 'when_max' in request.GET:
            if not ('when_min' in request.GET and 'when_max' in request.GET):
                msg = "When providing date range filters, " \
                      "a min and max are required."
                raise BadRequestException(message=msg)

            when_min = utils.str_time_to_unix(request.GET['when_min'])
            when_max = utils.str_time_to_unix(request.GET['when_max'])

            if when_max - when_min > HARD_WHEN_RANGE_LIMIT:
                msg = "Date ranges may be no larger than %s seconds"
                raise BadRequestException(message=msg % HARD_WHEN_RANGE_LIMIT)

            filters['when__lte'] = when_max
            filters['when__gte'] = when_min

        if 'event' in request.GET:
            filters['event'] = request.GET['event']

        service = request.GET.get("service", "nova")
        rawdata = _rawdata_factory(service)
        return {'stats': {'count': rawdata.filter(**filters).count()}}
    except (KeyError, TypeError):
        raise BadRequestException(message="Invalid/absent query parameter")
    except (ValueError, AttributeError):
        raise BadRequestException(message="Invalid format for date (Correct "
                                          "format should be %Y-%m-%d %H:%M:%S)")
开发者ID:ramielrowe,项目名称:stacktach,代码行数:31,代码来源:dbapi.py

示例5: _process_exists

def _process_exists(raw, body):
    payload = body['payload']
    instance_id = payload['instance_id']
    launched_at = utils.str_time_to_unix(payload['launched_at'])
    launched_range = (launched_at, launched_at+1)
    usage = STACKDB.get_instance_usage(instance=instance_id,
                                       launched_at__range=launched_range)
    delete = STACKDB.get_instance_delete(instance=instance_id,
                                         launched_at__range=launched_range)
    values = {}
    values['message_id'] = body['message_id']
    values['instance'] = instance_id
    values['launched_at'] = launched_at
    beginning = utils.str_time_to_unix(payload['audit_period_beginning'])
    values['audit_period_beginning'] = beginning
    ending = utils.str_time_to_unix(payload['audit_period_ending'])
    values['audit_period_ending'] = ending
    values['instance_type_id'] = payload['instance_type_id']
    if usage:
        values['usage'] = usage
    if delete:
        values['delete'] = delete
    values['raw'] = raw

    deleted_at = payload.get('deleted_at')
    if deleted_at and deleted_at != '':
        deleted_at = utils.str_time_to_unix(deleted_at)
        values['deleted_at'] = deleted_at

    exists = STACKDB.create_instance_exists(**values)
    STACKDB.save(exists)
开发者ID:pperezrubio,项目名称:stacktach,代码行数:31,代码来源:views.py

示例6: __init__

 def __init__(self, body, deployment, routing_key, json):
     super(GlanceNotification, self).__init__(body, deployment,
                                              routing_key, json)
     if isinstance(self.payload, dict):
         self.properties = self.payload.get('properties', {})
         self.image_type = image_type.get_numeric_code(self.payload)
         self.status = self.payload.get('status', None)
         self.uuid = self.payload.get('id', None)
         self.size = self.payload.get('size', None)
         created_at = self.payload.get('created_at', None)
         self.created_at = created_at and utils.str_time_to_unix(created_at)
         audit_period_beginning = self.payload.get(
             'audit_period_beginning', None)
         self.audit_period_beginning = audit_period_beginning and\
             utils.str_time_to_unix(audit_period_beginning)
         audit_period_ending = self.payload.get(
             'audit_period_ending', None)
         self.audit_period_ending = audit_period_ending and \
             utils.str_time_to_unix(audit_period_ending)
     else:
         self.properties = {}
         self.image_type = None
         self.status = None
         self.uuid = None
         self.size = None
         self.created_at = None
         self.audit_period_beginning = None
         self.audit_period_ending = None
开发者ID:anujm,项目名称:stacktach,代码行数:28,代码来源:notification.py

示例7: _process_exists

def _process_exists(raw):
    notif = json.loads(raw.json)
    payload = notif[1]['payload']
    instance_id = payload['instance_id']
    launched_at = utils.str_time_to_unix(payload['launched_at'])
    launched_range = (launched_at, launched_at+1)
    usage = STACKDB.get_instance_usage(instance=instance_id,
                                       launched_at__range=launched_range)
    delete = STACKDB.get_instance_delete(instance=instance_id,
                                         launched_at__range=launched_range)
    values = {}
    values['message_id'] = notif[1]['message_id']
    values['instance'] = instance_id
    values['launched_at'] = launched_at
    values['instance_type_id'] = payload['instance_type_id']
    if usage:
        values['usage'] = usage
    if delete:
        values['delete'] = delete
    values['raw'] = raw

    deleted_at = payload.get('deleted_at')
    if deleted_at and deleted_at != '':
        deleted_at = utils.str_time_to_unix(deleted_at)
        values['deleted_at'] = deleted_at

    exists = STACKDB.create_instance_exists(**values)
    STACKDB.save(exists)
开发者ID:AsherBond,项目名称:stacktach,代码行数:28,代码来源:views.py

示例8: test_save_image_exists_with_delete_not_none

    def test_save_image_exists_with_delete_not_none(self):
        raw = self.mox.CreateMockAnything()
        delete = self.mox.CreateMockAnything()
        audit_period_beginning = "2013-05-20 17:31:57.939614"
        audit_period_ending = "2013-06-20 17:31:57.939614"
        size = 123
        uuid = "2df2ccf6-bc1b-4853-aab0-25fda346b3bb"
        deleted_at = "2013-06-20 14:31:57.939614"
        body = {
            "event_type": "image.upload",
            "timestamp": "2013-06-20 18:31:57.939614",
            "publisher_id": "glance-api01-r2961.global.preprod-ord.ohthree.com",
            "payload": {
                "created_at": str(DUMMY_TIME),
                "status": "saving",
                "audit_period_beginning": audit_period_beginning,
                "audit_period_ending": audit_period_ending,
                "properties": {
                    "image_type": "snapshot",
                    "instance_uuid": INSTANCE_ID_1,
                    },
                "deleted_at": deleted_at,
                "size": size,
                "owner": TENANT_ID_1,
                "id": "2df2ccf6-bc1b-4853-aab0-25fda346b3bb",
                }
        }
        deployment = "1"
        routing_key = "glance_monitor.info"
        json = '{["routing_key", {%s}]}' % body

        self.mox.StubOutWithMock(db, 'create_image_exists')
        self.mox.StubOutWithMock(db, 'get_image_usage')
        self.mox.StubOutWithMock(db, 'get_image_delete')

        created_at_range = (DECIMAL_DUMMY_TIME, DECIMAL_DUMMY_TIME+1)
        db.get_image_usage(created_at__range=created_at_range,
                           uuid=uuid).AndReturn(None)
        db.get_image_delete(created_at__range=created_at_range,
                            uuid=uuid).AndReturn(delete)
        db.create_image_exists(
            created_at=utils.str_time_to_unix(str(DUMMY_TIME)),
            owner=TENANT_ID_1,
            raw=raw,
            audit_period_beginning=utils.str_time_to_unix(audit_period_beginning),
            audit_period_ending=utils.str_time_to_unix(audit_period_ending),
            size=size,
            uuid=uuid,
            usage=None,
            delete=delete,
            deleted_at=utils.str_time_to_unix(str(deleted_at))).AndReturn(raw)

        self.mox.ReplayAll()

        notification = GlanceNotification(body, deployment, routing_key,
                                          json)
        notification.save_exists(raw)
        self.mox.VerifyAll()
开发者ID:RallySoftware,项目名称:stacktach,代码行数:58,代码来源:test_notification.py

示例9: test_str_time_to_unix

    def test_str_time_to_unix(self):
        self.assertEqual(
            stacktach_utils.str_time_to_unix("2013-05-15T11:51:11Z"),
            decimal.Decimal('1368618671'))

        self.assertEqual(
            stacktach_utils.str_time_to_unix("2013-05-15T11:51:11.123Z"),
            decimal.Decimal('1368618671.123'))

        self.assertEqual(
            stacktach_utils.str_time_to_unix("2013-05-15T11:51:11"),
            decimal.Decimal('1368618671'))

        self.assertEqual(
            stacktach_utils.str_time_to_unix("2013-05-15T11:51:11.123"),
            decimal.Decimal('1368618671.123'))

        self.assertEqual(
            stacktach_utils.str_time_to_unix("2013-05-15 11:51:11"),
            decimal.Decimal('1368618671'))

        self.assertEqual(
            stacktach_utils.str_time_to_unix("2013-05-15 11:51:11.123"),
            decimal.Decimal('1368618671.123'))

        with self.assertRaises(Exception):
            stacktach_utils.str_time_to_unix("invalid date"),
            decimal.Decimal('1368618671')
开发者ID:Lupul,项目名称:stacktach,代码行数:28,代码来源:test_stacktach_utils.py

示例10: _process_delete

def _process_delete(raw, notification):
    if notification.launched_at and notification.launched_at != '':
        instance_id = notification.instance
        deleted_at = utils.str_time_to_unix(notification.deleted_at)
        launched_at = utils.str_time_to_unix(notification.launched_at)
        values = {
            'instance': instance_id,
            'deleted_at': deleted_at,
            'launched_at': launched_at
        }
        (delete, new) = STACKDB.get_or_create_instance_delete(**values)
        delete.raw = raw

        STACKDB.save(delete)
开发者ID:souvikbasu,项目名称:stacktach,代码行数:14,代码来源:views.py

示例11: save_exists

    def save_exists(self, raw):
        if isinstance(self.payload, dict):
            audit_period_beginning = self.payload.get(
                'audit_period_beginning', None)
            audit_period_beginning = audit_period_beginning and\
                utils.str_time_to_unix(audit_period_beginning)
            audit_period_ending = self.payload.get(
                'audit_period_ending', None)
            audit_period_ending = audit_period_ending and \
                utils.str_time_to_unix(audit_period_ending)
            message_id = self.message_id
            images = self.payload.get('images', [])
        else:
            stacklog.warn("Received exists with invalid payload "
                          "GlanceRawData(%s)" % raw.id)
            audit_period_beginning = None
            audit_period_ending = None
            images = []

        for image in images:
            created_at = image['created_at']
            created_at = created_at and utils.str_time_to_unix(created_at)
            uuid = image['id']
            deleted_at = image['deleted_at']
            deleted_at = deleted_at and utils.str_time_to_unix(deleted_at)

            if created_at:
                values = {
                    'uuid': uuid,
                    'audit_period_beginning': audit_period_beginning,
                    'audit_period_ending': audit_period_ending,
                    'owner': self.owner,
                    'size': image['size'],
                    'raw': raw,
                    'message_id': message_id
                }
                usage = db.get_image_usage(uuid=uuid)
                values['usage'] = usage
                values['created_at'] = created_at
                if deleted_at:
                    delete = db.get_image_delete(uuid=uuid)
                    values['delete'] = delete
                    values['deleted_at'] = deleted_at

                db.create_image_exists(**values)
            else:
                stacklog.warn("Ignoring exists without created_at. GlanceRawData(%s)"
                              % raw.id)
开发者ID:DragonDM,项目名称:stacktach,代码行数:48,代码来源:notification.py

示例12: test_save_delete_should_persist_image_delete

    def test_save_delete_should_persist_image_delete(self):
        raw = self.mox.CreateMockAnything()
        uuid = "2df2ccf6-bc1b-4853-aab0-25fda346b3bb"
        deleted_at = "2013-06-20 14:31:57.939614"
        body = {
            "event_type": "image.delete",
            "publisher_id": "glance-api01-r2961.global.preprod-ord.ohthree.com",
            "payload": {
                "id": "2df2ccf6-bc1b-4853-aab0-25fda346b3bb",
                "deleted_at": deleted_at
            }
        }
        deployment = "1"
        routing_key = "glance_monitor.info"
        json = '{["routing_key", {%s}]}' % body

        self.mox.StubOutWithMock(db, 'create_image_delete')
        db.create_image_delete(
            raw=raw,
            uuid=uuid,
            deleted_at=utils.str_time_to_unix(deleted_at)).AndReturn(raw)
        self.mox.ReplayAll()

        notification = GlanceNotification(body, deployment, routing_key, json)
        notification.save_delete(raw)
        self.mox.VerifyAll()
开发者ID:RallySoftware,项目名称:stacktach,代码行数:26,代码来源:test_notification.py

示例13: _process_usage_for_updates

def _process_usage_for_updates(raw, body):
    payload = body['payload']

    if raw.event == INSTANCE_EVENT['create_end']:
        if 'message' in payload and payload['message'] != 'Success':
            return

    instance_id = payload['instance_id']
    request_id = body['_context_request_id']
    (usage, new) = STACKDB.get_or_create_instance_usage(instance=instance_id,
                                                        request_id=request_id)

    if raw.event in [INSTANCE_EVENT['create_end'],
                     INSTANCE_EVENT['rebuild_end'],
                     INSTANCE_EVENT['resize_finish_end'],
                     INSTANCE_EVENT['resize_revert_end']]:
        usage.launched_at = utils.str_time_to_unix(payload['launched_at'])

    if raw.event == INSTANCE_EVENT['resize_revert_end']:
        usage.instance_type_id = payload['instance_type_id']
    elif raw.event == INSTANCE_EVENT['resize_prep_end']:
        usage.instance_type_id = payload['new_instance_type_id']

    usage.tenant = payload['tenant_id']
    image_meta = payload.get('image_meta', {})
    usage.rax_options = image_meta.get('com.rackspace__1__options', '')
    usage.os_architecture = image_meta.get('org.openstack__1__architecture',
                                           '')
    usage.os_version = image_meta.get('org.openstack__1__os_version', '')
    usage.os_distro = image_meta.get('org.openstack__1__os_distro', '')

    STACKDB.save(usage)
开发者ID:huangshunping,项目名称:stacktach,代码行数:32,代码来源:views.py

示例14: _process_usage_for_updates

def _process_usage_for_updates(raw, notification):
    if raw.event == INSTANCE_EVENT['create_end']:
        if notification.message and notification.message != 'Success':
            return

    instance_id = notification.instance
    request_id = notification.request_id
    (usage, new) = STACKDB.get_or_create_instance_usage(instance=instance_id,
                                                        request_id=request_id)

    if raw.event in [INSTANCE_EVENT['create_end'],
                     INSTANCE_EVENT['rebuild_end'],
                     INSTANCE_EVENT['resize_finish_end'],
                     INSTANCE_EVENT['resize_revert_end'],
                     INSTANCE_EVENT['rescue_end']]:
        usage.launched_at = utils.str_time_to_unix(notification.launched_at)

    if raw.event in [INSTANCE_EVENT['resize_revert_end'],
                     INSTANCE_EVENT['resize_finish_start'],
                     INSTANCE_EVENT['resize_finish_end']]:
        usage.instance_type_id = notification.instance_type_id
        usage.instance_flavor_id = notification.instance_flavor_id

    usage.tenant = notification.tenant
    usage.rax_options = notification.rax_options
    usage.os_architecture = notification.os_architecture
    usage.os_version = notification.os_version
    usage.os_distro = notification.os_distro

    STACKDB.save(usage)
开发者ID:jtopjian,项目名称:stacktach,代码行数:30,代码来源:views.py

示例15: _process_usage_for_new_launch

def _process_usage_for_new_launch(raw, body):
    payload = body['payload']
    values = {}
    values['instance'] = payload['instance_id']
    values['request_id'] = body['_context_request_id']

    (usage, new) = STACKDB.get_or_create_instance_usage(**values)

    if raw.event in [INSTANCE_EVENT['create_start'],
                     INSTANCE_EVENT['rebuild_start']]:
        usage.instance_type_id = payload['instance_type_id']

    if raw.event in [INSTANCE_EVENT['rebuild_start'],
                     INSTANCE_EVENT['resize_prep_start'],
                     INSTANCE_EVENT['resize_revert_start']] and\
            usage.launched_at is None:
        # Grab the launched_at so if this action spans the audit period,
        #     we will have a launch record corresponding to the exists.
        #     We don't want to override a launched_at if it is already set
        #     though, because we may have already received the end event
        usage.launched_at = utils.str_time_to_unix(payload['launched_at'])

    usage.tenant = payload['tenant_id']
    image_meta = payload.get('image_meta', {})
    usage.rax_options = image_meta.get('com.rackspace__1__options', '')
    usage.os_architecture = image_meta.get('org.openstack__1__architecture',
                                           '')
    usage.os_version = image_meta.get('org.openstack__1__os_version', '')
    usage.os_distro = image_meta.get('org.openstack__1__os_distro', '')
    STACKDB.save(usage)
开发者ID:huangshunping,项目名称:stacktach,代码行数:30,代码来源:views.py


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