ipa — IP Association Python Interface

Overview

The IPA python API provides an interface to IPA data from Python applications and scripts.

The general structure of a script using IPA is as follows:

from ipa import *

ipa = IPA()

catalogs = ipa.get_catalogs('usr.example')
for cat in catalogs:
    datasets = cat.get_datasets()
        for ds in datasets:
            print "catalog %s (%s - %s)" %(cat.name, ds.begin, ds.end)

Interface

class ipa.IPA(uri=None, pooled=False)

Represents a connection to an IPA data store.

uri should be a netsa.sql database URI.

If pooled is True, a database connection pool will be used instead of opening a new connection for each request.

add_catalog(name, type='set', desc=None, creator=None)

Add a new catalog to the IPA database. name is the full name of the catalog, in dotted notation (e.g. foo.bar.baz).

type is the catalog type, which should be one of set, bag, pmap, or mmap

Create a link between a parent and child catalog. The parent and child parameters should be the catalog IDs to link.

Remove a link between a parent and child catalog. The parent and child parameters should be the catalog IDs to unlink.

delete_catalog(catalog_id, username)

Remove a catalog from the database. This operation is destructive, unlike trash_catalog. Use with caution.

get_catalogs(expr=None)

Return a list of IPA catalogs matching expr

get_datasets(expr, begin=None, end=None, include_children=True, unique=False, sortfield='t_end', sortdir='desc')

Retrieve one or more datasets valid during a time interval.

expr is a catalog expression, which can be of any of the following formats: * numeric catalog id * catalog path name * list of numeric catalog IDs * list of path names

If expr is None, the query will be across all catalogs in the database.

The default behavior is to return each dataset for each catalog that matches expr, but tue to the fact that the catalog tree can contain multiple links to the same catalog, this can lead to duplication of dataset records. To de-dupe these, set the unique argument to True.

find_assocs(catalogs=None, datasets=None, paths=None, t_begin=None, t_end=None, range=None, label=None, limit=None, offset=None, sortfield='catalog', sortdir='asc')

Query the IPA database for associations matching the given parameters.

catalogs is a list of catalog paths to match, or None to search all catalogs.

datasets is a list of dataset IDs to match, or None to search all datasets

paths is a list of dataset paths to match, or None to search all datasets

t_begin is the beginning of a time range to query, or None if no time range is specified

t_end is the end of a time range to query, or None if no time range is specified

range is an IP address range to query

label is a textual label to query

get_range_notes(range=None, textsearch=None, comparison='overlaps', limit=None, offset=None, sortfield='ctime', sortdir='desc')

Query notes for a given time range or containing a given textual term.

add_user(username, displayname, role='User', admin_username=None)

Add a new user to the IPA database

delete_user(userid, admin_username=None)

Delete an existing user from the IPA database

check_catalog_owner(catalog_id, username)

Check if username owns the catalog with id catalog_id

check_dataset_owner(dataset_id, username)

Check if user username owns the dataset with id dataset_id

class ipa.IPACatalog(name, type='set', context=None, id=None, parent_id=None, desc=None, creator=None, creator_uid=None, depth=None, childcount=0)

A logical partition of related IPA datasets.

add_dataset(start, end, creator)

Add a new dataset to the catalog

get_dataset(date)

Retrieve a dataset for a given time from the catalog

get_datasets(begin=None, end=None)

Retrieve one or more datasets valid during a time interval from the catalog

get_labels(labels=None)

Retrieve all of the labels in the dataset

delete_dataset(date)

Deletes the dataset for a given time from the catalog

class ipa.IPADataset(id, context=None, begin=None, end=None, ctime=None, mtime=None, cat_name=None, cat_type=None, assoc_count=0, ip_count=0)

A collection of IPA associations valid during a particular time interval

add_assoc(addr, label=None, value=None, creator=None)

Add an IP association to the dataset.

class ipa.IPAAssoc(catalog=None, stime=None, etime=None, range=None, begin=None, end=None, label=None, value=None)
class ipa.IPALabel(id, name, catalog_id, conn=None)

A textual label which can be used in one or more IPA associations