StoreOnce Gen3 native filtering - HewlettPackard/python-storage-clients Wiki

StoreOnce Gen3 native filtering

Class StoreOnceG3 in planned version v0.10.1 (unstable) has a filtering feature support. Be careful - this version is under development. Use this version only for testing and development.

Code example

import logging
from datetime import datetime, timedelta
from xml.etree.ElementTree import fromstring

from hpestorapi import StoreOnceG3
from hpestorapi.storeonce3 import Iterator

logging.basicConfig(level=logging.CRITICAL)

with StoreOnceG3('10.0.0.1', 'Login', 'password') as so:
    try:
        so.open()
    except Exception as error:
        print('Cannot connect to StoreOnce: ', error)
        raise error

    # ServiceSet and Catalyst Store id's
    ssid = 1
    storeid = 0

    # Generate filter for object created in last 24 hours (1 day)
    time_start = datetime.today() - timedelta(days=1)
    time_end = datetime.today()
    query = {'createdTimeStart': time_start.strftime('%Y-%m-%dT%H:%M:%SZ'),
             'createdTimeEnd': time_end.strftime('%Y-%m-%dT%H:%M:%SZ')
             }
    filter = so.filter(
        f'/cluster/servicesets/{ssid}/services/cat/stores/{storeid}/items-filter/',
        query)

    print('{:^30s} {:^30s} {:^30s} {:^30s}'.format('Item Name',
                                                   'Creation name',
                                                   'Modification date',
                                                   'Metadata modification date'))

    for item_xml in Iterator(so,
                             f'/cluster/servicesets/{ssid}/services/cat/stores/{storeid}/items/',
                             './items/item',
                             filter):
        item = fromstring(item_xml)
        name = item.find('./properties/name').text
        created = item.find('./properties/created').text
        data_modified = item.find('./properties/dataModified').text
        meta_modified = item.find('./properties/metaModified').text

        print('{:^30s} {:^30s} {:^30s} {:^30s}'.format(name, created,
                                                       data_modified,
                                                       meta_modified))
⚠️ **GitHub.com Fallback** ⚠️