-
Couldn't load subscription status.
- Fork 17
More
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.
Using Docker Desktop on a Mac system, you can set up a Jamf Pro "sandbox" using docker-compose, and that you can quickly set up and teardown without additional server infrastructure.
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.
If you want to test & experiement 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.
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
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
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
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
ADD PIP LIST HERE
Next, to configure you 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
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'}}}}
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)
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_packageIf you see an error that says something like SyntaxError: invalid syntax, check to see if you're using python3.
Receiving errors using different aspects of python-jamf?
Here are some common errors and how to fix them:
With Python having different locations where site-packages can be stored, it can be a 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
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.
Please see the Roadmap in the jctl wiki.
Please see the Contribute page in the jctl wiki.
- Sam Forester
- James Reynolds
- Topher Nadauld
- Tony Williams
- O'Ryan Hampton
- Richard Glaser