MAPI - Chargeback Resources

New in version 0.9.4.

This class allows to request chargback reports from HCP.

HCP needs to have MAPI enabled for the system itself as well as for every Tenant to collect from.
A system-level user can collect summed-up reports from all Tenants that have MAPI enabled; he can collect Namespace-level reports from all Tenants that have granted system-level admin access.
A Tenant-level admin can collect reports for Namespaces as well as a summed-up report for the Tenant itself.

Classes

Chargeback

class hcpsdk.mapi.Chargeback(target, timeout=600, debuglevel=0)[source]

Access to HCP chargeback reports

Parameters:
  • target – an hcpsdk.Target object pointing to an HCP FQDN starting with admin. for access from a system level account or <tenant>. for a tenant level account
  • timeout – the connection timeout; relatively high per default, as generating the report can take longer than hcpsdks default of 30 seconds on a busy system
  • debuglevel – 0..9 (used in http.client)

Class constants:

Collection periods:

CBG_DAY
CBG_HOUR
CBG_TOTAL

Output formats:

CBM_CSV
CBM_JSON
CBM_XML

Class methodes

request(tenant=None, start=None, end=None, granularity='total', fmt='application/json')[source]

Request a chargeback report for a Tenant.

Parameters:
  • tenant – the Tenant to collect from
  • start – starttime (a datetime object)
  • end – endtime (a datetime object)
  • granularity – one out of CBG_ALL
  • fmt – output format, one out of CBM_ALL
Returns:

a file-like object in text-mode containing the report

close()[source]

Close the underlying hcpsdk.Connection object.

Exceptions

exception hcpsdk.mapi.ChargebackError(reason)[source]

Base Exception used by the hcpsdk.mapi.Chargeback() class.

Parameters:reason – An error description

Sample Code

Note that the last record in this example shows the Tenants overall values, while the the record before shows statistics for a single Namespace.

>>> import hcpsdk
>>> auth = hcpsdk.NativeAuthorization('service', 'service01')
>>> tgt = hcpsdk.Target('admin.hcp73.archivas.com', auth,
                        port=hcpsdk.P_MAPI)
>>> cb = hcpsdk.mapi.Chargeback(tgt)
>>> result = cb.request(tenant='m',
                        granularity=hcpsdk.mapi.Chargeback.CBG_TOTAL,
                        fmt=hcpsdk.mapi.Chargeback.CBM_JSON)
>>> print(result.read())
{
  "chargebackData" : [ {
    "systemName" : "hcp73.archivas.com",
    "tenantName" : "m",
    "namespaceName" : "n1",
    "startTime" : "2015-11-04T15:27:29+0100",
    "endTime" : "2015-12-17T20:35:33+0100",
    "valid" : false,
    "deleted" : "false",
    "bytesOut" : 0,
    "reads" : 0,
    "writes" : 0,
    "deletes" : 0,
    "tieredObjects" : 0,
    "tieredBytes" : 0,
    "metadataOnlyObjects" : 0,
    "metadataOnlyBytes" : 0,
    "bytesIn" : 0,
    "storageCapacityUsed" : 25306468352,
    "ingestedVolume" : 25303387299,
    "objectCount" : 7219
  }, {
    "systemName" : "hcp73.archivas.com",
    "tenantName" : "m",
    "startTime" : "2015-11-04T15:27:29+0100",
    "endTime" : "2015-12-17T20:35:33+0100",
    "valid" : false,
    "deleted" : "false",
    "bytesOut" : 2156,
    "reads" : 2,
    "writes" : 1,
    "deletes" : 1,
    "tieredObjects" : 0,
    "tieredBytes" : 0,
    "metadataOnlyObjects" : 0,
    "metadataOnlyBytes" : 0,
    "bytesIn" : 5944,
    "storageCapacityUsed" : 25607081984,
    "ingestedVolume" : 25427708304,
    "objectCount" : 65607
  } ]
}
>>> cb.close()