Skip to content

Using the CLI

This tool allows the manipulation of all Metal Cloud elements via the command line.

metalcloud-cli

To install on Mac OS X:

brew tap metalsoft-io/homebrew-repo
brew install metalcloud-cli

To install on any CentOS/Redhat Linux distribution, use the latest release for your platform: https://github.com/metalsoft-io/metalcloud-cli/releases/latest

$ sudo rpm -i https://github.com/metalsoft-io/metalcloud-cli/releases/download/v2.5.13/metalcloud-cli_2.5.13_linux_amd64.rpm

To install on any Debian/Ubuntu distributions:

curl -sLO https://github.com/metalsoft-io/metalcloud-cli/releases/download/v2.5.13/metalcloud-cli_2.5.13_linux_amd64.deb && sudo dpkg -i metalcloud-cli_2.5.13_linux_amd64.deb

To install on Windows: Binaries are available here: Download and unzip the executable, and execute it.

To install using go get:

Terminal window
go get github.com/metalsoft-io/metalcloud-cli

In the Metalsoft Web UI, click the user icon at the top right corner. Then go to API credentials > API key.

Copy the API key. Its format is <number>:<letters>.

Copy the endpoint. Its format is https://api.environment.hostname.

Configure credentials as environment variables:

Terminal window
export METALCLOUD_API_KEY="<your key>" # example value: "1:e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e"
export METALCLOUD_ENDPOINT="<your api endpoint>" # example value: "https://api.demo.metalsoft.io"
export METALCLOUD_USER_EMAIL="<your email>" # example value: "user@metalsoft.io"
export METALCLOUD_INSECURE_SKIP_VERIFY=false #defaults to false
export METALCLOUD_TIMEOUT_SECONDS=300 #defaults to 300 if not set

Use metalcloud-cli help for a list of supported commands.

To create an infrastructure in the default site (configured via the METALCLOUD_SITE environment variable):

Terminal window
metalcloud-cli infrastructure create --label test --return-id
Terminal window
metalcloud-cli infrastructure list
+-------+-----------------------------------------+-------------------------------+-----------+-----------+---------------------+---------------------+
| ID | LABEL | OWNER | REL. | STATUS | CREATED | UPDATED |
+-------+-----------------------------------------+-------------------------------+-----------+-----------+---------------------+---------------------+
| 12345 | complex-demo | d.d@sdd.com | OWNER | active | 2019-03-28T15:23:08Z| 2019-03-28T15:23:08Z|
+-------+-----------------------------------------+-------------------------------+-----------+-----------+---------------------+---------------------+

To create an instance array in that infrastructure, get the ID of the infrastructure from above (12345):

Terminal window
metalcloud-cli instance-array create --infra 12345 --label master --proc 1 --proc-core-count 8 --ram 16

To view the ID of the previously created drive array:

Terminal window
metalcloud-cli instance-array list --infra 12345
+-------+---------------------+---------------------+-----------+
| ID | LABEL | STATUS | INST_CNT |
+-------+---------------------+---------------------+-----------+
| 54321 | master | ordered | 1 |
+-------+---------------------+---------------------+-----------+
Total: 1 Instance Arrays

To create a drive array and attach it to the previous instance array:

Terminal window
metalcloud-cli drive-array create --infra 12345 --label master-da --ia 54321

To view the current status of the infrastructure:

Terminal window
metalcloud-cli infrastructure get --id 12345
Infrastructures I have access to (as test@test.com)
+-------+----------------+-------------------------------+-----------------------------------------------------------------------+-----------+
| ID | OBJECT_TYPE | LABEL | DETAILS | STATUS |
+-------+----------------+-------------------------------+-----------------------------------------------------------------------+-----------+
| 36791 | InstanceArray | master | 1 instances (16 RAM, 8 cores, 1 disks) | ordered |
| 47398 | DriveArray | master-da | 1 drives - 40.0 GB iscsi_ssd (volume_template:0) attached to: 36791 | ordered |
+-------+----------------+-------------------------------+-----------------------------------------------------------------------+-----------+
Total: 2 elements

Apply creates or updates a resource from a file. The supported format is yaml.

Terminal window
metalcloud-cli apply -f resources.yaml

Specify the type of the requested resource using the field kind.

cat resources.yaml
kind: InstanceArray
apiVersion: 1.0
label: my-instance-array
---
kind: Secret
apiVersion: 1.0
name: my-secret

You can find the objects and their fields in the SDK documentation. The fields will be in the format specified in the yaml tag. For example, the SubnetPool object has a field named subnet_pool_prefix_human_readable in JSON format. In the YAML file used as input for this command, the field is called prefix.

The CLI also provides a “condensed format” for most of its commands:

  • instance-array = ia
  • drive-array = da
  • infrastructure = infra
  • list = ls
  • delete = rm …

This allows commands such as:

Terminal window
metalcloud-cli infra ls

Most commands also take a label instead of an id as a parameter. For example:

Terminal window
metalcloud-cli infra show --id complex-demo

Some commands depend on various permissions. For instance, you cannot access another user’s infrastructure unless you are a delegate of it.