Skip to content
Richard Glaser edited this page Feb 24, 2022 · 21 revisions

Development Server

We "highly" recommend that you set up a Jamf Pro development server testing python-jamf module or anything experimental or major changes on a development server before implementing it on your production server. In case something unexpected happens it only happens development server and NOT your production server.

For example, if you are a Jamf Cloud customer you can get a "sandbox" server that you can experiment and test things before moving to production. Or for on-premise instances, you get a "sandbox" license that you can set up in your server infrastructure.

Docker

Using Docker Desktop on a Mac system, you can set up a Jamf Pro "sandbox" using docker-compose, and you can quickly set up and teardown without additional server infrastructure.

Docker for Mac Jamf Pro Sandbox Server

See the following GitHub repository here for instructions on this process.

Or here is an in-depth presentation, Docker for Beginners by James Reynolds at the University of Utah, MacAdmins meeting.

Virtual Environments

If you want to test & experiment with python-jamf before promoting it to be installed into your system site directories, a virtual environment provides one option.

The venv module provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories. Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.

Navigate to Virtual Environments Directory

If you store your virtual environments in a specific location, navigate to that directory:

cd /path/to/virtual_environments

If not, you might consider creating a directory to manage & store virtual environments:

mkdir /path/to/virtual_environments

Then change to the directory noted above.

Create python-jamf Virtual Environment

To create a virtual environment for python-jamf enter the following command:

% python3 -m venv python-jamf-env

This will create a virtual environment for you with the following files in the virtual environment directory python-jamf-env:

  • bin
  • include
  • lib
  • pyvenv.cfg

Activate python-jamf Virtual Environment

To activate the virtual environment, enter the following command:

% source python-jamf-env/bin/activate
(python-jamf-env)

To verify your virtual environment is activated, you can enter the following command:

% which python
/path/to/virtual_environments/python-jamf-env/bin/python

And you should get output that the python is within the python-jamf-env virtual environment directory.

And if you enter the following command you can get a list of packages installed in the virtual environment.

% pip list
Package     Version
----------- --------
pip         21.3.1
setuptools  28.8.0

Install python-jamf

Next, to install python-jamf in your virtual environment, enter the following command:

% pip3 install python-jamf

To verify its installed properly, enter the following command:

% pip list
Package            Version
------------------ ----------------
certifi            2021.10.8
chardet            3.0.4
idna               2.10
importlib-metadata 4.11.1
keyring            23.5.0
pip                21.2.4
python-jamf        0.7.3-2-gd517792
requests           2.24.0
setuptools         58.1.0
urllib3            1.25.11
zipp               3.7.0

Configure Jamf Pro Credentials

Next, to configure your Jamf Pro server credentials, enter the following command:

% conf-python-jamf

Hostname (don't forget https:// and :8443): https://jamf.example.edu:8443
Username: [MyAPIUser]
Password: [hidden]
2021-11-19 21:11:15,100:     INFO: jamf.config.Config - save(): saving: /Users/[UserAccountName]/Library/Preferences/edu.utah.mlib.jamfutil.plist

Test the Connection

Next, to test the setup of python-jamf and your Jamf Pro server credentals & settings, enter the following command:

% conf-python-jamf -t
{'accounts': {'groups': None, 'users': {'user': {'id': '1', 'name': 'richard'}}}}

For more details on usage, please see Testing Installation with Python

Exit Virtual Environment

After you are done testing the python-jamf virtual environment, you can exit with the following command:

% deactivate

If you want to start the python-jamf virtual environment in the future, enter the command:

% source python-jamf-env/bin/activate
(python-jamf-env)

Running Tests

The following doesn't work as of 2020/12.

cd python-jamf

# runs all tests
python3 -m unittest discover -v

# run tests individually
python3 -m python-jamf.tests.test_api
python3 -m jamf.tests.test_config
python3 -m jamf.tests.test_convert
python3 -m jamf.tests.test_package

If you see an error that says something like SyntaxError: invalid syntax, check to see if you're using python3.

Troubleshooting

Errors

Receiving errors using different aspects of python-jamf?

Here are some common errors and how to fix them:

Which python-jamf is Python using?

With Python having different locations where site-packages can be stored, it can be difficult to make sure that it is using the correct version. python-jamf is located in one of the site-package directories. To find the location we have to look at how Python uses site-packages. Python has a hierarchical list of directories it checks for the library.

The list can be found by using Python's site command.

python3 -m site
List Site-Package Directories

This produces the list of site-package directories Python checks.

% python3 -m site
sys.path = [
   '/Users/topher/Documents/GitHub/jctl',
   '/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
   '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
   '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload',
   '/Users/topher/Library/Python/3.8/lib/python/site-packages',
   '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages',
]
USER_BASE: '/Users/topher/Library/Python/3.8' (exists)
USER_SITE: '/Users/topher/Library/Python/3.8/lib/python/site-packages' (exists)
ENABLE_USER_SITE: True

The top directory in the list is the first place that Python tries to find the particular site-package. Perform a list on the directory and see if you find jamf or python-jamf there. "jamf" was the old name that was installed pre-0.4.0. Continue down the list until you have reached where pip has installed python-jamf for you.

To figure out where pip has installed python-jamf for you, use this command:

pip show python-jamf

In location it will display where PIP has installed python-jamf.

% pip show python-jamf
Name: python-jamf
Version: 0.4.7
Summary: Python wrapper for Jamf Pro API
Home-page: https://github.com/univ-of-utah-marriott-library-apple/python-jamf
Author: The University of Utah
Author-email: [email protected]
License: UNKNOWN
Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
Requires: requests
Required-by:

By the time that you have reached the pip installed directory, the other python-jamf should have been discovered.

Roadmap

Please see the Roadmap in the jctl wiki.

Contributing

Please see the Contribute page in the jctl wiki.

Contributors

  • Sam Forester
  • James Reynolds
  • Topher Nadauld
  • Richard Glaser
  • Tony Williams
  • O'Ryan Hampton
Clone this wiki locally