-
Notifications
You must be signed in to change notification settings - Fork 17
Working with Record Classes
Currently, the python-jamf
module supports about 50 Jamf records like Buildings, Categories, Computers, OSXConfigurationProfiles, and Policies for example. Each record is a Python object, but they are generic, so all of the data in the supported records are accessible. The record classes do not have member variables for Jamf data. All Jamf Pro data is stored as a Python dictionary that is accessed with the data property.
There are record classes that represent lists of records, and there are record classes that represent individual records. All class names that are plural are lists, and all class names that are singular represent a single record. Example: computers
is a list of computers, but computer
is a single computer record.
We realize that we made this too complex and it needs to be simplified. We are working on it right now.
Here is an example of working with the Categories record. Because this is plural, it is a list of record.
from jamf.records import Categories
allcategories = Categories()
for item in allcategories:
repr(item)
The following methods return a list of records. These are regular list classes, not Categories classes.
names = allcategories.names()
ids = allcategories.ids()
type(ids) # <class 'list'>
cat_util = allcategories.recordsWithName("Utilities")
cat_macos = allcategories.recordsWithRegex("[Mm]ac ?OS")
type(cat_macos) # <class 'list'>
type(allcategories) # <class 'jamf.records.Categories'>
Starting where we left off above, we can get an individual record.
category = allcategories.recordWithId(141)
category = Categories().find("Utilities")
repr(category)
category = Categories().find(141)
repr(category)
type(category) # <class 'jamf.records.Category'>
The detailed data is not retrieved from the Jamf server until it is accessed.
category.data
To edit the data, just set it and save.
category.data['name'] = "Bla"
category.save()
Data in record classes are cached. If it changes on the server, it must be updated.
allcategories.refresh()
Most of the real work of jctl
and pkgctl
is in the Records class file. The purpose of that was so that it can be available to others, but it is in a rough state and needs some serious improvements. For example, the Computers and Computer classes have code that can print applications on the computers. But, like I said, it's seriously flawed and needs to be fixed.