- 12 Nov 2024
-
DarkLight
-
PDF
create service python-script
- Updated on 12 Nov 2024
-
DarkLight
-
PDF
iagctl create service python-script
Create a new Python script service
Synopsis
This command will create a Python script service in the gateway data store. The service can later be executed via gateway run
command. Before creating a Python script service, you will need to ensure that a repository with the actual script exists. See iagctl create repository -h
for more information.
Consider a Python script that exists in a repository called example-repo
. The repository has the following directory layout:
├── README.md
├── interface-scripts
│ ├── main.py
│ └── requirements.txt
You can specify that you want to use example-repo
via the --repository
flag.
Notice that the script exists in a directory called interface-scripts
. You can denote this using the --working-dir
flag.
Your particular script also has a requirements.txt
file that specifies the various libraries that main.py
requires. If a requirements.txt
file exists within the working-dir
, gateway will automatically pip install
the dependencies into a virtual environment and execute the script within that virtual environment when service is run
.
Environment variables that will be applied during runtime can be specified using the --env
flag.
Finally, a decorator can be specified to allow for input validation when the service is executed via run
command. For more information on decorators, run iagctl create decorator -h
.
To see how Python scripts are expected to read in arguments passed at runtime, reference iagctl run python-script -h
and view the Stub Code For Taking In Arguments
section.
iagctl create service python-script <service-name> --repository <string> --filename <string> [flags]
Examples
Create a Simple Python Service
Creates a simple Python service called my-python-service
where a Python script named main.py
is at the root of the my-repo
repository.
>_ iagctl create service python-script my-python-service \
--repository my-repo \
--filename main.py
Create a Complex Python Service
Creates a Python service that takes advantage of every available option.
>_ iagctl create service python-script interface-renamer \
--repository example-repo \
--filename main.py \
--working-dir interface-scripts \
--decorator my-decorator \
--description "A Python script to set an interface description" \
--env key1=value1 \
--env key2=value2 \
--tag interfaces
Options
--decorator string The name of the decorator to be associated with the service
--description string A brief description of the service
--env stringArray One or more environment variables set as key=value pairs
--filename string The name of the Python script file in the repository. This must exist in the working-dir (default "main.py")
-h, --help Help for python-script
--repository string The repository that contains the Python script
--tag stringArray Metadata tags to associate with the service
--working-dir string The path to the directory where the Python script exists. The path must be relative to the root of the repository
Options Inherited from Parent Commands
--config string Path to the configuration file
--raw Displays the result of the command in its raw format
--verbose Enable verbose output
CLI References
See related create
commands:
- create
- create decorator
- create repository
- create secret
- create service
- create service ansible playbook
- create service opentofu plan
- create user
For all CLI commands see → Command References Index