pydme package

Module contents

PyDME - Python Bindings for DME REST API

PyDME is a simplified take on providing Python bindings for Cisco DME REST API.

Submodules

pydme.core module

pydme.core

This module contains the core classes of PyDME.

class pydme.core.Api(parentApi=None)

Bases: object

DELETE(format=None)
GET(format=None, **kwargs)
POST(format=None, **kwargs)
class pydme.core.AppLoginMethod(parentApi)

Bases: pydme.core.Api

property Json
property Xml
class pydme.core.AutoRefreshThread(rootApi)

Bases: threading.Thread

CHECK_INTERVAL = 10
REFRESH_BEFORE = 60
WS_REFRESH_INT = 40
isStopped()
run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

stop()
class pydme.core.ChangeCertMethod(parentApi)

Bases: pydme.core.Api

property Json
property Xml
class pydme.core.LoginMethod(parentApi)

Bases: pydme.core.Api

property Json
POST(format=None, **kwargs)
property Xml
class pydme.core.LoginRefreshMethod(parentApi)

Bases: pydme.core.Api

property Json
property Xml
class pydme.core.LogoutMethod(parentApi)

Bases: pydme.core.Api

property Json
POST(format=None, **kwargs)
property Xml
class pydme.core.MethodApi(parentApi)

Bases: pydme.core.Api

property AppLogin
property ChangeCert
property Login
property LoginRefresh
property Logout
property RefreshSubscriptions
property ResolveClass
property UploadPackage
property Version
class pydme.core.Mo(parentApi, className, dmeClassMetas)

Bases: pydme.core.Api

property Children
property ClassName
property Dn
FromDn(dn)
GET(format=None, **kwargs)
GetXml(elementPredicate=<function Mo.<lambda>>, propertyPredicate=<function Mo.<lambda>>)
property IsConfigurable
IsConfigurableProperty(name)
property Json
property NonEmptyPropertyNames
property Parent
ParseJsonResponse(text, subscriptionIds=[])
ParseXmlResponse(xml, localOnly=False, subscriptionIds=[])
property PropertyNames
property ReadOnlyTree
property Rn
property Status
property TopRoot
Up(level=1)
property Xml
class pydme.core.MoIter(parentApi, className, objects, dmeClassMetas)

Bases: pydme.core.Api

next()
class pydme.core.Node(url, session=None, verify=False, disableWarnings=True, timeout=None, dmeMetaFilePath=None)

Bases: pydme.core.Api

hasWsMo(subscriptionId)
property methods
property mit
popWsMo(subscriptionId)
property session
startWsListener(pingInt=1800)
toggleDebugApi(shouldEnable, dme='policymgr')
toggleTestApi(shouldEnable, dme='policymgr')
useX509CertAuth(userName, certName, keyFile)
waitForWsMo(subscriptionId, timeout=None)
property webSocketUrl
class pydme.core.RefreshSubscriptionsMethod(parentApi)

Bases: pydme.core.Api

GET(format=None, **kwargs)
property Json
property Xml
class pydme.core.ResolveClassMethod(parentApi)

Bases: pydme.core.Api

GET(format=None, mit=None, autoPage=False, pageSize=10000, **kwargs)
class pydme.core.UploadPackageMethod(parentApi)

Bases: pydme.core.Api

POST(format='xml')
class pydme.core.VersionMethod(parentApi)

Bases: pydme.core.Api

property Json
property Xml
pydme.core.subLogger(name)

pydme.errors module

pydme.errors

This module contains the set of PyDME exceptions.

exception pydme.errors.Error

Bases: Exception

An ambigious error occurred.

exception pydme.errors.MetaError

Bases: pydme.errors.Error

A meta error occurred.

exception pydme.errors.MoError

Bases: pydme.errors.Error

An MO error occurred.

exception pydme.errors.ResourceError

Bases: pydme.errors.Error

A resource error occurred.

exception pydme.errors.RestError

Bases: pydme.errors.Error

A REST error occurred.

exception pydme.errors.UserError

Bases: pydme.errors.Error

A user caused error occurred.

pydme.options module

pydme.options

This module contains helpers to construct REST API options for PyDME.

class pydme.options.ApiOptions

Bases: dict

Dict like data structure capturing REST API options.

pydme.options.auditLogs = {'rsp-subtree-include': 'audit-logs,no-scoped'}

Get count.

pydme.options.childClass(className)

Query child class.

pydme.options.children = {'query-target': 'children'}

Query the entire subtree.

pydme.options.count = {'rsp-subtree-include': 'count'}

Subscribe to WebSocket notifications.

pydme.options.faults = {'rsp-subtree-include': 'faults,no-scoped'}

Query audit logs.

pydme.options.filter(filt)

Restrict to the specified filter

pydme.options.orderBy(property)

Order the query result by the given property.

pydme.options.page(value)

Results from only the given page.

pydme.options.pageSize(value)

Number of objects per page.

pydme.options.subtree = {'query-target': 'subtree'}

Include all the faults along with the entire subtree.

pydme.options.subtreeClass(className)

Query subtree class.

pydme.templating module

pydme.templating

This module contains helpers to use Jinja2 templates with PyDME.

class pydme.templating.TemplateRepository(path)

Bases: object

A Jinja2 template repository.

Parameters

path – path to a directory containing Jinja2 templates.

Usage:

>>> import pydme
>>> repo = pydme.TemplateRepository('path/to/repo')
>>> xml1 = repo.render('template1.xml', template_values={'count': 2})
>>> xml2 = repo.render('template2.xml',
                        template_values_file='values2.yml')
>>> json1 = repo.render('template1.json',
                         template_values_file='values1.yml',
                         template_values={'name': 'bar'})
render(template_path, template_values_file=None, template_values={})

Render a given template.

Template values can be specified using a YAML file, or a Python dictionary, or both. When both are specifed, the values are merged, and the value specified in the dictionary takes precedence if there is a conflict.

Parameters
  • template_path – path to the template within the repository.

  • template_values_file – path to the template values YAML file.

  • template_values – template values dictinary.

pydme.templating.mergeDict(master, other)

Merge the given two dictionaries recursively and return the result.

pydme.utils module

pydme.utils

This module contains PyDME utility functions.

pydme.utils.digestConfigExport(path, topRoot, format='xml')

Digest an APIC config export file into the given topRoot.

Parameters
  • path – path to the config export file.

  • topRoot – topRoot MO.

pydme.utils.distributeConfig(root, result=None)

Distribute configuration from the given root MO into multiple roots.

In order for an MO tree to be posted to APIC in a single operation, all MOs in that tree should belong to the same shard. APIC will reject if any of the MOs is not in the same shard. This function splits the given tree to multiple subtrees, ensuring that all the MOs in the subtre belong to the same context root. One can later post the individual subtrees without worrying about the context root implications.

Parameters
  • root – MO at the top of the tree to be processed.

  • result – optional list of subtrees to append the result to.

pydme.utils.getParentDn(dn)

Get the parent DN of the given DN string.

pydme.utils.mergeRoot(accumulator, root)

Merge the given root MO into the given acculumulator.

pydme.utils.readOnlyTree(mo)

Make the given MO tree read-only.

The MO tree (starting from topRoot) remains read-only until the enclosing with statement returns.

pydme.utils.splitIntoRns(dn)

Split the given DN string to a list of RN strings.