leostream-admin-cli

command module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 8 Imported by: 0

README

Leostream-admin-cli

This repository contains a command line interface (CLI) for the Leostream Connection Broker REST API. The CLI is written in Go and is compiled to a single binary that can be run on any platform that supports Go. Currently it can fetch and update the following Leostream resources:

Additionally, it can create the following resources:

  • pool assignments
  • centers

It is also possible to query information about individual desktops with the leostream-admin-cli vm command. This command can be used to get the desktop ID, the desktop name, the desktop state, the desktop type, the desktop user, and the desktop pool. It will show if a desktop is assigned to a user through a policy or hard assignment.

For more info see

leostream-admin-cli also can backup and restore the Leostream database:

This is a work in progress

TODO

  • add create command for - pools - gateways
  • add delete command - pools - gateways
  • Add support for other Centers than AWS
  • add more tests
  • add more error handling
  • add more documentation how to use the CLI
  • add more examples
  • add more output formats

Installation

To install the CLI, you must have Go installed on your system. Please see the Go installation instructions for more information.

You can install the CLI by running the following command:

go install gitlab.com/hocmodo/leostream-admin-cli@latest

The binary will then be installed in your GOPATH/bin/ directory. You can add this directory to your PATH to make the CLI available from anywhere.

In my case, I have the following in my ~/.bash_profile:

export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

Building the source yourself

Install go-task (MacOS)
% brew install go-task/tap/go-task
Build the binary using task
% task build
task: [build] GOFLAGS=-mod=mod go build -o $GOPATH/bin/leostream-admin-cli main.go

Usage

Step 1: Add environment variables

Your user in Leostream needs permission to access the REST API. You can create a user with the appropriate permissions in the Leostream Connection Broker web interface. Once you have created a user, you can set the following environment variables:

export LEOSTREAM_API_USERNAME=<username>
export LEOSTREAM_API_PASSWORD=<password>
export LEOSTREAM_API_API_URL=https://<api host>
export LEOSTREAM_API_SSL_INSECURE=True (if you are using a self-signed certificate)

Note: the url should be the full url including the protocol and port number if different than 443.

Step 2: Execute a command

To execute a command, you must specify the resource type and the command like so:

leostream-admin-cli <resource type> <command> <options>
Backup command

See backup for more information.

Pool command

The pool commands are used to get and update pools in the Leostream Connection Broker. The following commands are available:

  • list
  • get
  • update
pool get
% leostream-admin-cli pool get -h
Get Leostream pool by ID. For example:
		leostream-admin-cli pool get --pool_id 1

Usage:
  leostream-admin-cli pool get [flags]

Flags:
  -h, --help   help for get

Global Flags:
  -j, --json             Output in JSON
      --pool_id string   Pool_id to get pool for

% leostream-admin-cli pool get --pool_id 5
{
        "id": 5,
        "name": "AWS desktop pool",
        "display_name": "AWS desktop pool",
        "pool_definition": {
                "restrict_by": "A",
                "pool_attribute_join": "A",
                "never_rogue": 0,
                "use_vmotion": 0,
                "attributes": [
                        {
                                "vm_table_field": "server_id",
                                "ad_attribute_field": "",
                                "vm_gpu_field": "",
                                "text_to_match": "13",
                                "condition_type": "eq"
                        }
                ]
        },
        "provision": {
                "provision_on_off": 1,
                "provision_tenant_id": 0,
                "provision_threshold": 1,
                "provision_vm_id": 15,
                "provision_vm_name": "desktop-{SEQUENCE}",
                "provision_vm_name_next_value": 4,
                "provision_vm_display_name": "",
                "provision_url": "",
                "provision_server_id": 13,
                "provision_max": 1,
                "provision_limits_enforce": 0,
                "mark_deletable": 1,
                "mark_unavailable": 0,
                "time_limits": [],
                "center": {
                        "id": 13,
                        "name": "aws-center-us-east-1",
                        "type": "amazon",
                        "aws_size": "t3a.micro",
                        "aws_t2_unlimited": 1,
                        "aws_sub_net": "subnet-09bd8643/vpc-9c880fe6/us-east-1d/,subnet-df11aee1/vpc-9c880fe6/us-east-1e/,subnet-c4b5dea3/vpc-9c880fe6/us-east-1b/,subnet-41f3856f/vpc-9c880fe6/us-east-1c/,subnet-1b8ffb47/vpc-9c880fe6/us-east-1a/,subnet-15daf71a/vpc-9c880fe6/us-east-1f/",
                        "aws_sec_group": "sg-b1c127f6",
                        "aws_vpc_id": "vpc-9c880fe6"
                }
        },
        "pool_stats": {
                "counts_updated": "2024-04-19 17:13:39",
                "total_vm": 1,
                "total_vm_stopped": 1,
                "available_vm": 1
        },
        "vms_list": [
                {
                        "display_name": "Desktop 3",
                        "id": 19,
                        "name": "desktop-3",
                        "status": 2
                }
        ]
}

pool list

Not all commands have flags. For example, to list all pools, you would run the following command:

% leostream-admin-cli pool list
+---------+-------------------------------------+
| POOL ID | POOL NAME                           |
+---------+-------------------------------------+
|       1 | All Desktops                        |
|       4 | All Linux Desktops                  |
|       3 | All Windows Desktops                |
|      11 | Linux Advanced Desktop Pool         |
|     103 | My Pool2                            |
+---------+-------------------------------------+
pool update

Updating a pool is similar to getting a pool, except you must add the appropriate flags. The help function can be used to see what flags are available for each command. For example, to get help for the pool update command, you would run the following command:

% leostream-admin-cli pool update --help
Update Leostream pool by ID. For example:
		leostream-admin-cli pool update --pool_id 1 --name "My Pool" --display_name "My Pool" --provision_onoff 1 --provision_threshold 1 --provision_vm_name test1 --provision_vm_id 1 --provision_name_next_value 1 --provision_max 1 --center_id 1 --center_type "vmware"

Usage:
  leostream-admin-cli pool update [flags]

Flags:
      --center_id string                   ID of center to which this pool belongs
      --center_type string                 Type of center to which this pool belongs (amazon, azure, vmware, etc.
      --display_name string                Pool display name in the UI
  -h, --help                               help for update
      --name string                        Pool name
      --provision_max string               Maximum number of provisioned desktops (default "1")
      --provision_name_next_value string   Next value to use for naming provisioned desktops (default "1")
      --provision_onoff string             Desktop provisioning enabled or not
      --provision_threshold string         Threshold at which to provision desktops
      --provision_vm_id string             ID of the desktop image to use for provisioning
      --provision_vm_name string           Name of the desktop instance to be provisioned (default "1")

Global Flags:
      --pool_id string   Pool_id to get pool for

To update a pool for instance to change the display name, you would run the following command:

%  leostream-admin-cli pool update --pool_id 103 --name "My Pool" --display_name "My new Pool" --provision_onoff 0 --provision_threshold 1 --provision_vm_name test1 --provision_vm_id 1 --provision_name_next_value 1 --provision_max 1
{
	"stored_data": {
		"id": 103,
		"name": "My Pool",
		"display_name": "My new Pool",
		"pool_definition": {
			"restrict_by": "C",
			"never_rogue": 0,
			"server_ids": [
				1
			],
			"use_vmotion": 0
		},
		"provision": {
			"provision_on_off": 0,
			"provision_threshold": 1,
			"provision_max": 1,
			"center": {}
		}
	}
}

The response contains the updated pool exactly as it is stored in the Leostream Connection Broker database.

Output of commands

Can be formatted as JSON or plain. To format output as JSON, add --json to the command. This way you can pipe the output to other commands or scripts like jq.

For example:

E.g.

% leostream-admin-cli pool list --json
[
	{
		"id": 1,
		"name": "All Desktops"
	},
	{
		"id": 4,
		"name": "All Linux Desktops"
	},
	{
		"id": 3,
		"name": "All Windows Desktops"
	},
	{
		"id": 11,
		"name": "Linux Advanced Desktop Pool"
	},
	{
		"id": 103,
		"name": "My Pool2"
	}
]

Documentation

Overview

Copyright © 2023 NAME HERE <EMAIL ADDRESS>

Directories

Path Synopsis
cmd
vm

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL