Command line tool (CLI)
veHaaS command line tool enables you to interact with the veHaaS services using commands in your command-line shell or from python scripts.
Deprecation notice
The v2 get-jobs subcommand is deprecated as of v1.20.0. It remains functional but will be removed in a future version. A v3 CLI subcommand is planned and will be documented when available.
Installation
The veHaaS command line tool requires Python >=3.10 to be installed. You can verify the installed Python version by running:
:
If Python is not installed, refer to the Python download page for instructions on installing Python.
Once Python is installed, use pip to install the veHaaS command line tool:
:
After installation, confirm that the veHaaS command line tool is installed correctly by running:
:
This command should display the installed version the veHaaS command line tool, indicating a successful installation. :
Syntax
The veHaaS command line tool uses a multipart structure that is specified in the following order
:
- Invocation of the command line tool: This is the initial call to the vehaas command.
- Top-level command: The primary command either use-case or API version specific.
- Subcommand: Additional commands that refine the action. Multiple levels of subcommands can be nested.
- Command options: Options that modify the behavior of the command or subcommand. These can be specified using - or -- flags.
Environment variables
This section explains how to configure environment variable settings for the veHaaS command line tool. These include the following environment variables that are supported:
| Variable | Description |
|---|---|
| VEHAAS_HOST | The URL of the veHaaS API. By default https://vehaas.vi.vector.int/ is used. |
| VEHAAS_TOKEN | The token to authenticate with the veHaaS API. Go to access-tokens for more information. |
You can set the VEHAAS_HOST and VEHAAS_TOKEN environment variables to specify the API URL and authentication token, eliminating the need to provide them with each command invocation.
Commands
The commands of the veHaaS command line tool are divided into two main categories: commands for specific use cases and commands to interact with specific versions of the veHaaS API.
Use-case-specific commands are utility functions designed to implement specific workflows, simplifying usage and providing additional convenience for the user. These include commands for session booking in the CI workflow and commands for administrative purposes.
Additionally, the veHaaS command line tool includes commands for all available API versions. These commands are autogenerated by the OpenAPI Generator, allowing users to interact with various API endpoints. They are categorized by the version of the veHaaS API, ensuring that users can easily find and use the commands relevant to the specific API version they are working with.
Assembly session commands
The assembly session commands are used for the session booking in the CI workflow.
Assembly session commands
Usage: vehaas [OPTIONS] COMMAND [ARGS]...
Command line tool to interact with the veHaaS API.
Version: 1.0.8
Environment variables:
VEHAAS_HOST: The host URL of the veHaaS API.
VEHAAS_TOKEN: The token to authenticate with the veHaaS API.
Options:
--version Show the version and exit.
-h, --help Show this message and exit.
Commands:
book-maintenance CLI command to book a maintenance window over a...
create-session-request CLI command to create a session request.
delete-maintenance Creates a session request and waits until the...
maintenance Maintenance related commands.
release-session CLI command to release an assembly session as...
v2 API v2 commands.
create-session-request
-
This command will create a new session request and waits until the session is either successfully booked or the request is rejected.
release-session
-
Release an assembly session as soon as possible. The cleanup duration needed will be automatically calculated. The updated assembly session with the calculated end time will be printed to the console.
Maintenance commands
Maintenance commands are used for administrative purposes.
Maintenance commands
Usage: vehaas [OPTIONS] COMMAND [ARGS]...
Command line tool to interact with the veHaaS API.
Version: 1.0.8
Environment variables:
VEHAAS_HOST: The host URL of the veHaaS API.
VEHAAS_TOKEN: The token to authenticate with the veHaaS API.
Options:
--version Show the version and exit.
-h, --help Show this message and exit.
Commands:
book-maintenance CLI command to book a maintenance window over a...
create-session-request CLI command to create a session request.
delete-maintenance Creates a session request and waits until the...
maintenance Maintenance related commands.
release-session CLI command to release an assembly session as...
v2 API v2 commands.
book-maintenance
-
Book a maintenance window over a fixed schedule.
delete-maintenance
-
Delete a (recurring) maintenance window.
create-vm
-
This command takes a technical-user with a defined pattern (svc-pes-hil-*) from vault of the stockpile and assigns it to the newly created VM.
maintenance create-vm
API commands
These commands are grouped by their API version tag (e.g. v2) and allow the user to interact with all available veHaaS API endpoints.
API commands
Usage: vehaas [OPTIONS] COMMAND [ARGS]...
Command line tool to interact with the veHaaS API.
Version: 1.0.8
Environment variables:
VEHAAS_HOST: The host URL of the veHaaS API.
VEHAAS_TOKEN: The token to authenticate with the veHaaS API.
Options:
--version Show the version and exit.
-h, --help Show this message and exit.
Commands:
book-maintenance CLI command to book a maintenance window over a...
create-session-request CLI command to create a session request.
delete-maintenance Creates a session request and waits until the...
maintenance Maintenance related commands.
release-session CLI command to release an assembly session as...
v2 API v2 commands.
Get help
To get more information on available commands for each API version, you can invoke the --help option on the API version tag.
:
This will display an overview of all commands for the specified API version, grouped by their resource type. These groups are organized similarly to the API endpoints in the [veHaaS API docs](https://vehaas.vi.vector.int/api/v2.0/docs), where you can interactively explore, call, and test the veHaaS API directly from your browser.
??? info "API commands grouped by resource type"
```sh hl_lines="9-27"
Usage: vehaas v2 [OPTIONS] COMMAND [ARGS]...
API v2 commands.
Options:
-h, --help Show this message and exit.
Commands:
access-tokens API access-tokens commands.
assemblies API assemblies commands.
assembly-group-relationships API assembly-group-relationships commands.
assembly-session-contexts API assembly-session-contexts commands.
assembly-session-transfers API assembly-session-transfers commands.
assembly-sessions API assembly-sessions commands.
banners API banners commands.
clusters API clusters commands.
default API default commands.
deprecation-info API deprecation-info commands.
groups API groups commands.
health API health commands.
jobs API jobs commands.
monitoring API monitoring commands.
organizations API organizations commands.
users API users commands.
virtual-machines API virtual-machines commands.
websocket-ticket API websocket-ticket commands.
```
To get an overview of all commands available for a specific resource type, you can use the --help flag and traverse through the subcommands. For example, to see all commands for assembly-sessions, run:
:
This will list all commands related to assembly-sessions.
??? info "Commands available for assembly-sessions"
```sh hl_lines="9-15"
Usage: vehaas v2 assembly-sessions [OPTIONS] COMMAND [ARGS]...
API assembly-sessions commands.
Options:
-h, --help Show this message and exit.
Commands:
create-assembly-session Create Assembly Session
delete-assembly-session Delete Assembly Session
get-assembly-session Get Assembly Session
get-assembly-sessions Get Assembly Sessions
get-session-tasks-for-assembly-session
Get Session Tasks For Assembly...
update-assembly-session Update Assembly Session
```
From there, you can run --help on the individual subcommands. For example, to see the options and syntax for create-assembly-session, run:
:
This will display the available options and the basic syntax of the command.
??? info "create-assembly-session command syntax and options"
```sh
Usage: vehaas v2 assembly-sessions create-assembly-session [OPTIONS]
Create Assembly Session
Creates and returns a new assembly session.
Options:
--assembly-session-request (AssemblySessionRequest) Allocate request.
Example:
{
"start_time" : "2000-01-23T04:56:07.000+00:00",
"assembly_ref" : "assembly_ref",
"end_time" : "2000-01-23T04:56:07.000+00:00"
}
--host (optional) The host URL of the veHaaS API. Defaults to
https://vehaas.vi.vector.int/
--token (optional) The token to authenticate with the veHaaS API.
-h, --help Show this message and exit.
```
Examples
get-assembly
-
get-assembly
$ vehaas v2 assemblies get-assembly --assembly-ref "ASSEMBLY-0" { "assembly_ref": "ASSEMBLY-0", "assembly_profile": { "assembly_ref": "ASSEMBLY-0", "assembly_name": "Spielwiese", "cluster_ref": null, ... }, "status_type": "available", "is_operational": true, "user_id": null, "user_name": null, "favorite": false, "is_public": true, "cluster_ref": "dummy-cluster", "virtual_machines": null }
create-assembly
-
create-assembly
$ vehaas v2 assemblies create-assembly \ --json-file $FILE_PATH \ --is-public "false" \ --organization-id "organization-id-1" { "assembly_ref": "assembly-1", "assembly_profile": { "assembly_ref": "assembly-1", "assembly_name": "My_Assembly-1", "cluster_ref": "CLUSTER-0", ... }, "status_type": "on stock", "is_operational": false, ... }
Python script
Since the veHaaS command line tool is written in Python, it can also be imported as a package and used directly in your Python scripts. The following example demonstrates how to interact with the veHaaS API using the veHaaS command line tool:
Python script
import json
import os
from datetime import datetime, timedelta, timezone
from pydantic.json import pydantic_encoder
from vehaas.openapi_client_v2 import ApiClient, Configuration
from vehaas.openapi_client_v2.api import AssembliesApi, AssemblySessionsApi
from vehaas.openapi_client_v2.models import AssemblySessionRequest
VEHAAS_URL = "https://vehaas.vi.vector.int" # must be without trailing slash
VEHAAS_TOKEN = os.environ.get("VEHAAS_TOKEN", "")
def main() -> None:
# Client configuration
config = Configuration(host=VEHAAS_URL)
client = ApiClient(configuration=config)
client.default_headers["private-token"] = VEHAAS_TOKEN
assembly_session_client = AssemblySessionsApi(api_client=client)
assemblies_api = AssembliesApi(api_client=client)
# Create a new assembly session
start_time = datetime.now(timezone.utc)
session_response = assembly_session_client.create_assembly_session(
assembly_session_request=AssemblySessionRequest(
assembly_ref="ASSEMBLY-101", start_time=start_time, end_time=start_time + timedelta(minutes=30)
)
)
print("Assembly Session Response:")
print(json.dumps(session_response, indent=2, default=pydantic_encoder))
# Get the assembly session
session = assembly_session_client.get_assembly_session(session_id=session_response.session_id)
print("\nAssembly Session:")
print(json.dumps(session, indent=2, default=pydantic_encoder))
# Get the assembly profile
assembly = assemblies_api.get_assembly(assembly_ref=session.assembly_ref)
print("\nAssembly Profile:")
print(json.dumps(assembly.assembly_profile, indent=2, default=pydantic_encoder))
if __name__ == "__main__":
main()