Skip to content
No description, website, or topics provided.
Go Other
  1. Go 98.8%
  2. Other 1.2%
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Godeps
auth
autocomplete
base
cmd
cmd_runner
command_loader
commands
config
connection
errors
formatter_provider
formatters
help
integration_tests
model_adjuster
model_loader
model_validator
models
options
parser
proxy
scripts
state
vendor
.gitignore
CONTRIBUTING.md
Design.md
LICENSE
README.md
dev
init.go
run_integraion_tests
run_integraion_tests.cmd
run_tests
run_tests.cmd

README.md

CenturyLink Cloud CLI

This is the Command Line Interface (CLI) for the CenturyLink Cloud. It runs on MacOS, Linux and Windows.

Getting Started

Download the tool

The latest version of the CLI can be downloaded from the releases page.

Install it

On Linux:

Extract the archive. Its contents look like:

clc-$VERSION-linux-amd64
|
 -- clc
 -- install_autocompletion
 -- autocomplete
   |
    -- bash_autocomplete

You can immediately start using the clc binary, or put it somewhere on your PATH for convenience. In order to turn on bash autocomplete you have to source the bash_autocomplete script. install_autocompletion copies this script to ~/.bash_completion/clc and puts a line sourcing it to the ~/.bashrc file so that autocomplete is turned on automatically in every terminal session.

On MacOS:

There are 2 options of installing the tool: a tar archive and a pkg file.

The tar archive is pretty much the same as the one for Linux. The only difference is that install_autocompletion alters ~/.bash_profile, not ~/.bashrc.

The pkg file is an easy way to set up things. It installs everything for you. The binary is placed at /usr/local/bin. The ~/.bash_completion/clc script is created and a line sourcing this script is added to ~/.bash_profile to enable bash autocomplete.

On Windows:

Extract the archive. Its contents look like:

clc-$VERSION-windows-x64
|
 -- clc.exe
 -- autocomplete
   |
    -- powershell3_autocomplete.ps1

You can start using the binary right away, or put it somewhere on your PATH for convenience. To turn on PowerShell autocomplete execute the powershell3_autocomplete.ps1 script.

Note that autocomplete only works with PowerShell version >= 3. PowerShell v3 is distributed as a part of Windows Management Framework 3.0, which can be downloaded from here. You can check the version by typing $PSVersionTable.PSVersion.

Log in to your CenturyLink Cloud account

You need to be authenticated with a username and password in order to execute CLI commands. There are plenty of ways to set the credentials:

  • A config (see the Config section for more details).

  • A login command:

    clc login --user bob --password passw0rd.

    This puts the passed credentials into the config.

  • CLC_USER and CLC_PASSWORD environment variables:

    CLC_USER=bob CLC_PASSWORD=passw0rd clc server list

    or on Windows in PowerShell:

    $env:CLC_USER="bob"; $env:CLC_PASSWORD="passw0rd"; clc.exe server list.

    Note: If specified, these values take precedence over the values from the configuration file and environment variables (if any).

  • --user and --password command options:

    clc server list --user bob --password passw0rd.

    Note: If specified, these values take precedence over the values from the configuration file and environment variables (if any).

Set up the configuration file

The program uses a configuration file located at $HOME/.clc/config.yml on Linux/Unix/Mac and C:\Users\%username%\clc\config.yml on Windows. A config file is created automatically on the first execution of any command. The file is in YAML format. The following fields count:

  • user and password: the credentials used for authentication.
  • defaultformat: a default output format, either json, table or text.
  • profiles: a hash of alternative credentials. See Profiles.
  • defaultdatacenter: a short code for a default data center. See the corresponding section.

An example of a configuration file:

user: bob
password: passw0rd
defaultformat: "table"
defaultdatacenter: "CA1"
profiles:
  alice:
    user: alice
    password: pa33w0rd

Profiles

Each profile is a pair of alternative credentials to use. Profiles are specified in the configuration file.

To choose a profile for a single command invokation use either a --profile option or CLC_PROFILE environment variable: clc server list --profile alice.

Also, you can set up your default credentials from a profile via the login command: clc login --profile alice. Be careful, though, because your previous defaults will be overriden this way. Therefore it is a grood idea to have a profile for every of your users.

Specify a default data center

A number of commands require a default data center variable (via the --data-center option) in order to ensure that the command only operates on the entities (groups, servers, policies, etc) belonging to the specific data center.

There is an option to set a default data center so that you do not need to specify it with every command.

You can either set a data center in the config using the defaultdatacenter field or execute a command:

clc data-center set-default --data-center <a-short-code-for-a-data-center>

You can query the current default with:

clc data-center show-default

Or unset it using:

clc data-center unset-default

Switch accounts

Your account is determined automatically for you upon authentication. But you might also have sub accounts that have to be dealt with. Thus, the tool allows you to specify a custom account via an --account-alias option: clc server list --account-alias MYSUBACC.

Identify entities by ID or by name

There are many commands that depend on the identification of specific entities such as server, group or network. A common pattern for specifying the entity ID in the command line is --<entity>-id, like --server-id or --load-balancer-id.

Alternatively, the name of an entity can be specified instead of the ID (the common pattern is --<entity>-name). This approach has some important subtleties to mention:

  • You can't specify both an ID and a name for the same entity.
  • If there is more than one entity with the specified name, an error occurs.
  • Autocomplete, if turned on, works for names and does not work for IDs. See the Autocomplete section for details.

List of CLI commands

Below is a list of CLI commands to help bring you up-to-speed on using the tool.

####Explore the list of data centers:

clc data-center list

####Find server template IDs that contain the word "UBUNTU" in some data center <data-center>:

clc data-center get-deployment-capabilities --data-center <data-center> --query templates.name --output text | grep UBUNTU

####Search for the root group ID of the data center under consideration:

clc group list --all --filter location-id=<data-center> --query id --output text

Or, the same thing can be accomplished by issuing:

clc group list --data-center <data-center> --query id --output text

####Get the list of subgroups. Use a "SubGroup" alias for subgroups IDs in the output:

clc group get --group-id <root-group-id> --query 'groups.{SubGroup:id}'

####Create your own group inside the one queried:

clc group create --name "my group" --description "A group of mine" --parent-group-id <group-id> --custom-fields "id=<some-field>,value=<some-value>" "id=<another-field>,value=<another-value>"

Note: Pay attention to how we set custom fields. According to the command help, the --custom-fields argument accepts an array of objects with 2 keys each: id and value. The tool interprets multiple space-separated values as an array and each object can be specified using the key1=value1,key2=value2,..-notation, which is described in more detail further in the document.

####Open multiple ports to a public IP address:

clc server update-public-ip-address --server-name MyServerName --public-ip xxx.xxx.xxx.xxx --ports "port=80,protocol=tcp" "port=443,protocol=tcp"

Note: Pay attention to how we set custom fields. According to the command help, the --custom-fields argument accepts an array of objects with 2 keys each: id and value. The tool interprets multiple space-separated values as an array and each object can be specified using the key1=value1,key2=value2,..-notation, which is described in more detail further in the document.

####Create a server:

clc server create --name myserv --source-server-id <template-id> --group-id <group-id> --cpu 1 --memory-gb 1

The same can be accomplished with a piece of JSON:

clc server create '{"name":"myserv","source-server-id":"<template-id>","group-id":"<group-id>","cpu":1,"memory-gb":1}'

Be careful with JSON. Keys and string values have to be enclosed in double quotes. Also, an expression may fail to be parsed unless it is enclosed in quotes, mainly because commas and spaces usually have special meanings in shells.

There is another notation for describing objects:

clc server create "name=myserv,source-server-id='<template-id>',group-id='<group-id>',cpu=1,memory-gb=1"

In this case you can use both ' and " for both values and the whole expression, but be sure to escape special characters, as it has been partly described for JSON.

Note: this notation does not support nested objects and arrays.

You can also mix both options:

clc server create '{"name":"myserv"}' source-server-id='<template-id>' --group-id <group-id> --cpu 1 --memory-gb 1

Note: Be sure to put all the data not bound to any command key first, otherwise it will be interpreted as a value or an item of an array for the preceding command key.

####Wait until the server has been created:

clc wait

####Query only servers with status "active" and see the output as a table:

clc server list --all --filter status=active --output table

####Increase the server's CPUs count and log the HTTP request/response data:

clc server update --server-id <server_id> --cpu 2 --trace

####Show billing details of the servers of the group as a table:

clc group get-billing-details --group-id <group-id> --query groups.<group-id>.servers --output table

####Make a skeleton of a command for getting groups with servers inside:

clc group list --filter 'servers-count>0' --generate-cli-skeleton > groups_with_servers.json

####Apply the skeleton:

clc group list --from-file groups_with_servers.json

Autocomplete

Autocomplete currently works for:

  • Resources (server, data-center, group, etc)
  • Commands
  • Command options and arguments
  • The --output values
  • The --profile values
  • Values of the arguments that have a limited set of possible values (like server create --type standard|hyperscale|bareMetal)
  • Values of the arguments that are actually entity names

Autocomplete for entity names

'Entity names' is a special item in the autocomplete list because options are fetched from the server. This kind of autocomplete only works under certain circumstances and the process may take a relatively long time. Things you should note:

  • The functionality does not work until the user has been authenticated. Authentication is needed to perform API requests.
  • Since options are generated on the fly as the user enters a command, an entity name lookup for the data-center-dependent commands is only made within the default data center. If there is no default set, no options will appear.
  • In bash, a waiting indicator in the form of dot rotation is shown for the time options that are fetched after the Tab has been pressed. Windows PowerShell does not support this kind of interaction - the input is simply blocked until the options have arrived.
  • A cache is implemented to avoid making long subsequent requests to the server. The cache entry lifetime is 30 seconds.

Getting Help

Explore the available resources, commands, options and other useful guidance using the --help option: clc --help, clc <resource> --help and clc <resouce> <command> --help are all at your service.

The documentation of the underlying HTTP API can be found here.

Security

The CenturyLink Cloud Go CLI leverages our public API that serves all requests over HTTPS. Therefore credentials are encrypted when being transfered. Credentials stored on the local machine in the config.yml are not encrypted during installation and you are encouraged to use industry standard encryption tools in order to provide additional protection for them.

License

The project is licensed under the Apache License v2.0.

You can’t perform that action at this time.