示例#1
0
def serialize_swift_object(sobject):
    metadocument = {k: sobject.get(k, None) for k, v in sobject.items()
                    if k.lower().startswith("x-object-meta")}
    object_fields = ('id',
                     'name',
                     'account',
                     'account_id',
                     'container',
                     'container_id',
                     'etag'
                     )
    document = {f: sobject.get(f, None) for f in object_fields}
    document['content_type'] = sobject.get('content-type', None)
    document['content_length'] = sobject.get('content-length', None)

    if sobject.get('x-timestamp'):
        timestamp = float(sobject.get('x-timestamp'))
        document['created_at'] = \
            utils.isotime(datetime.datetime.fromtimestamp(timestamp))
    if sobject.get('last-modified'):
        updated_dt = datetime.datetime.strptime(
            sobject['last-modified'], dateformat)
        document['updated_at'] = utils.isotime(updated_dt)
    document.update(metadocument)
    return document
示例#2
0
def timestamp_to_isotime(timestamp):
    """Take a rabbitmq-style timestamp (2016-03-14 16:49:23.749458) and convert
    to an ISO8601 timestamp.
    """
    fmt = '%Y-%m-%d %H:%M:%S.%f'
    parsed_time = datetime.datetime.strptime(timestamp, fmt)
    return utils.isotime(parsed_time)
示例#3
0
def timestamp_to_isotime(timestamp):
    """Take a rabbitmq-style timestamp (2016-03-14 16:49:23.749458) and convert
    to an ISO8601 timestamp.
    """
    fmt = '%Y-%m-%d %H:%M:%S.%f'
    parsed_time = datetime.datetime.strptime(timestamp, fmt)
    return utils.isotime(parsed_time)
示例#4
0
def serialize_swift_container(container):
    metadocument = {k: container.get(k, None) for k, v in
                    container.items()
                    if k.lower().startswith("x-container-meta")}
    container_fields = ('id',
                        'name',
                        'account',
                        'account_id',
                        'x-container-read'
                        )
    document = {f: container.get(f, None) for f in container_fields}
    if container.get('x-timestamp'):
        timestamp = float(container.get('x-timestamp'))
        document['created_at'] = \
            utils.isotime(datetime.datetime.fromtimestamp(timestamp))

    # (laskhmiS) get_container doesn't include last_modified field even
    # though the swift api documentation says it returns it. Include it
    # when it starts sending it.

    # Notifications for container sends this field as 'updated_at' instead
    # of 'last_modified'.
    if container.get('updated_at'):
        document['updated_at'] = container['updated_at']

    document.update(metadocument)
    return document
def serialize_swift_container(container):
    metadocument = {
        k: container.get(k, None)
        for k, v in container.items()
        if k.lower().startswith("x-container-meta")
    }
    container_fields = ('id', 'name', 'account', 'account_id',
                        'x-container-read')
    document = {f: container.get(f, None) for f in container_fields}
    if container.get('x-timestamp'):
        timestamp = float(container.get('x-timestamp'))
        document['created_at'] = \
            utils.isotime(datetime.datetime.fromtimestamp(timestamp))

    # (laskhmiS) get_container doesn't include last_modified field even
    # though the swift api documentation says it returns it. Include it
    # when it starts sending it.

    # Notifications for container sends this field as 'updated_at' instead
    # of 'last_modified'.
    if container.get('updated_at'):
        document['updated_at'] = container['updated_at']

    document.update(metadocument)
    return document
示例#6
0
    def to_wsme_model(model, db_entity, self_link=None, schema=None):
        # Return the wsme_attributes names:values as a dict
        names = []
        for attribute in model._wsme_attributes:
            names.append(attribute.name)

        values = {}
        for name in names:
            value = getattr(db_entity, name, None)
            if value is not None:
                if type(value) == datetime:
                    iso_datetime_value = utils.isotime(value)
                    values.update({name: iso_datetime_value})
                else:
                    values.update({name: value})

        if schema:
            values['schema'] = schema

        model_object = model(**values)

        # 'self' kwarg is used in wsme.types.Base.__init__(self, ..) and
        # conflicts during initialization. self_link is a proxy field to self.
        if self_link:
            model_object.self = self_link

        return model_object
    def to_wsme_model(model, db_entity, self_link=None, schema=None):
        # Return the wsme_attributes names:values as a dict
        names = []
        for attribute in model._wsme_attributes:
            names.append(attribute.name)

        values = {}
        for name in names:
            value = getattr(db_entity, name, None)
            if value is not None:
                if type(value) == datetime:
                    iso_datetime_value = utils.isotime(value)
                    values.update({name: iso_datetime_value})
                else:
                    values.update({name: value})

        if schema:
            values['schema'] = schema

        model_object = model(**values)

        # 'self' kwarg is used in wsme.types.Base.__init__(self, ..) and
        # conflicts during initialization. self_link is a proxy field to self.
        if self_link:
            model_object.self = self_link

        return model_object
def serialize_swift_object(sobject):
    metadocument = {
        k: sobject.get(k, None)
        for k, v in sobject.items() if k.lower().startswith("x-object-meta")
    }
    object_fields = ('id', 'name', 'account', 'account_id', 'container',
                     'container_id', 'etag')
    document = {f: sobject.get(f, None) for f in object_fields}
    document['content_type'] = sobject.get('content-type', None)
    document['content_length'] = sobject.get('content-length', None)

    if sobject.get('x-timestamp'):
        timestamp = float(sobject.get('x-timestamp'))
        document['created_at'] = \
            utils.isotime(datetime.datetime.fromtimestamp(timestamp))
    if sobject.get('last-modified'):
        updated_dt = datetime.datetime.strptime(sobject['last-modified'],
                                                dateformat)
        document['updated_at'] = utils.isotime(updated_dt)
    document.update(metadocument)
    return document
示例#9
0
def serialize_swift_account(account):
    metadocument = {k: account.get(k, None) for k, v in account.items()
                    if k.lower().startswith("x-account-meta")}
    account_fields = ('id', 'name')
    document = {f: account.get(f, None) for f in account_fields}

    document['domain_id'] = account.get('x-account-project-domain-id', None)
    if account.get('x-timestamp'):
        timestamp = float(account.get('x-timestamp'))
        document['created_at'] = \
            utils.isotime(datetime.datetime.fromtimestamp(timestamp))

    # lakshmiS: swift get_account() doesn't include update datetime field(?)
    if account.get('updated_at'):
        document['updated_at'] = account.get('updated_at')

    document.update(metadocument)
    return document
示例#10
0
def serialize_swift_account(account):
    metadocument = {
        k: account.get(k, None)
        for k, v in account.items() if k.lower().startswith("x-account-meta")
    }
    account_fields = ('id', 'name')
    document = {f: account.get(f, None) for f in account_fields}

    document['domain_id'] = account.get('x-account-project-domain-id', None)
    if account.get('x-timestamp'):
        timestamp = float(account.get('x-timestamp'))
        document['created_at'] = \
            utils.isotime(datetime.datetime.fromtimestamp(timestamp))

    # lakshmiS: swift get_account() doesn't include update datetime field(?)
    if account.get('updated_at'):
        document['updated_at'] = account.get('updated_at')

    document.update(metadocument)
    return document
示例#11
0
def get_now_str():
    """Wrapping this to make testing easier (mocking utcnow's troublesome)
    and keep it in one place in case oslo changes
    """
    return utils.isotime(oslo_utils.timeutils.utcnow())
示例#12
0
def get_now_str():
    """Wrapping this to make testing easier (mocking utcnow's troublesome)
    and keep it in one place in case oslo changes
    """
    return utils.isotime(oslo_utils.timeutils.utcnow())
import copy
import datetime
import mock

import glanceclient.exc

from searchlight.common import utils
from searchlight.elasticsearch.plugins.base import NotificationBase
from searchlight.elasticsearch.plugins.glance import images as images_plugin
from searchlight.elasticsearch import ROLE_USER_FIELD
import searchlight.tests.unit.utils as unit_test_utils
import searchlight.tests.utils as test_utils


DATETIME = datetime.datetime(2012, 5, 16, 15, 27, 36, 325355)
DATE1 = utils.isotime(DATETIME)

# General
USER1 = '54492ba0-f4df-4e4e-be62-27f4d76b29cf'

TENANT1 = '6838eb7b-6ded-434a-882c-b344c77fe8df'
TENANT2 = '2c014f32-55eb-467d-8fcb-4bd706012f81'
TENANT3 = '5a3e60e8-cfa9-4a9e-a90a-62b42cea92b8'
TENANT4 = 'c6c87f25-8a94-47ed-8c83-053c25f42df4'

# Images
UUID1 = 'c80a1a6c-bd1f-41c5-90ee-81afedb1d58d'
UUID2 = 'a85abd86-55b3-4d5b-b0b4-5d0a6e6042fc'
UUID3 = '971ec09a-8067-4bc8-a91f-ae3557f1c4c7'
UUID4 = '6bbe7cc2-eae7-4c0f-b50d-a7160b0c6a86'
UUID5 = 'KERNEL-eae7-4c0f-b50d-RAMDISK'
示例#14
0
import mock
from oslo_utils import uuidutils

from searchlight.common import utils
from searchlight.elasticsearch.plugins.neutron import\
    ports as port_plugin
import searchlight.tests.unit.utils as unit_test_utils
import searchlight.tests.utils as test_utils


USER1 = u'27f4d76b-be62-4e4e-aa33bb11cc55'
ID1 = u'813dd936-663e-4e5b-877c-986021b73e2c'
TENANT1 = u'8eaac046b2c44ab99246cb0850c7f06d'
NETWORK1 = u'bc0adf22-3aef-4e7b-8b99-12670b5a76b5'
UUID_PORT_ID = uuidutils.generate_uuid()
_now_str = utils.isotime(datetime.datetime.utcnow())


def _create_port_fixture(port_id, tenant_id, network_id, **kwargs):
    port = {
        u'admin_state_up': True,
        u'allowed_address_pairs': [],
        u'binding:host_id': u'devstack',
        u'binding:profile': {},
        u'binding:vif_details': {u'ovs_hybrid_plug': True,
                                 u'port_filter': True},
        u'binding:vif_type': u'ovs',
        u'binding:vnic_type': u'normal',
        u'device_id': None,
        u'device_owner': 'compute:None',
        u'dns_assignment': [{
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime

from searchlight.common import utils
from searchlight.elasticsearch.plugins.neutron import\
    subnets as subnets_plugin
import searchlight.tests.unit.utils as unit_test_utils
import searchlight.tests.utils as test_utils


_now_str = utils.isotime(datetime.datetime.utcnow())
USER1 = u'27f4d76b-be62-4e4e-aa33bb11cc55'
ID1 = "813dd936-663e-4e5b-877c-986021b73e2c"
NETID1 = "98dcb60c-59b9-4b3c-bf6a-b8504112e978"
TENANT1 = "8eaac046b2c44ab99246cb0850c7f06d"


def _subnet_fixture(network_id, tenant_id, subnet_id, name, **kwargs):
    fixture = {
        "id": subnet_id,
        "network_id": network_id,
        "name": name,
        "tenant_id": tenant_id,
        "ip_version": kwargs.pop("ip_version", 4),
        "cidr": kwargs.pop("cidr", "192.0.0.1/24")
    }
ID2 = "AUTH_7554da43-6443-acdf-deac-3425223cdada"
ID3 = "AUTH_30754354-ca43-124b-12b5-789234bcdefa'"

AUTH_PREFIX = "AUTH_"

X_ACCOUNT_META_KEY1 = 'x-account-meta-key1'
X_ACCOUNT_META_VALUE1 = 'x-account-meta-value1'

X_ACCOUNT_META_KEY2 = 'x-account-meta-key2'
X_ACCOUNT_META_VALUE2 = 'x-account-meta-value2'

TENANT1 = "15b9a454cee34dbe9933ad575a0a6930"
DOMAIN_ID = "default"

DATETIME = datetime.datetime(2016, 2, 20, 1, 13, 24, 215337)
DATE1 = utils.isotime(DATETIME)


def _account_fixture(account_id, domain_id, name, **kwargs):
    fixture = {
        "id": account_id,
        "name": name,
        "x-account-project-domain-id": domain_id,
        'x-timestamp': now_epoch_time
    }
    fixture.update(kwargs)
    return fixture


def _notification_account_fixture(account_id, **kwargs):
    metadata = kwargs.pop('meta', {})