CLI MAAS - OpenStack Guide v0

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Note: Ensure the correct permissions are preserved when restoring files and directories.

If you have additional stand-alone rack controllers and a fresh installation has regenerated the
/var/lib/maas/secret file, you'll need to make sure this secret is updated on each rack
controller to allow them to re-connect to the newly restored region controller.

Now either restart your system(s) or the stopped services. You'll find your MAAS deployment
fully restored.
MAAS CLI
The MAAS CLI can do everything that the web UI can do, and more. The CLI uses the maas
command exclusively which, in turn, connects to the API.

This page explains what is needed to get going with the CLI. Tasks are then separated into
common, image management, DHCP snippet management, and advanced.

Note that we do not provide complete coverage of the MAAS CLI. For an exhaustive treatment,
see the API documentation.

Values are represented as uppercase variables preceded with the '$' character (e.g. $PROFILE
and $EMAIL_ADDRESS). These are to be replaced with actual values.

The maas command


The maas command is obtained via the maas-cli Ubuntu package which is installed on every
region API server and rack controller. To manage MAAS at the CLI level from a remote
workstation this package will need to be installed:

sudo apt install maas-cli

Create an administrator
MAAS requires an initial administrator, sometimes called a MAAS "superuser". When the web
UI is accessed for the first time you will be prompted to create this user:

sudo maas createadmin --username=$PROFILE --email=$EMAIL_ADDRESS

Extra administrators can be created in the same way. See MAAS CLI - common tasks for
creating regular users with the CLI.

Log in (required)
To use the CLI you must first log in to the API server (region controller).

You will need the API key that was generated when your MAAS account was created. To obtain
it, run this command on the region controller (i.e. where the 'maas-region-controller' package was
installed):

sudo maas-region apikey --username=$PROFILE > $API_KEY_FILE

Note: A user's API key can also be obtained from the web interface. Click on 'username' in the
top right corner, and select 'Account'.
Log in. You will be prompted for the API key:

maas login $PROFILE $MAAS_URL

For example, to log in with the account whose username is 'admin' and where the region
controller is on the localhost:

maas login admin http://localhost:5240/MAAS/api/2.0

To log in by referring to the API key file created earlier:

maas login $PROFILE $MAAS_URL - < $API_KEY_FILE

A handy shell script, say maas-login.sh, is provided:

#!/bin/sh

# Change these 3 values as required


PROFILE=admin
API_KEY_FILE=/home/ubuntu/tmp/api_key
API_SERVER=localhost

MAAS_URL=http://$API_SERVER/MAAS/api/2.0

maas login $PROFILE $MAAS_URL - < $API_KEY_FILE

Get help
To access command help:

maas $PROFILE -h

Further examples:

maas $PROFILE tags -h


maas $PROFILE tags read -h

Log out
Once you are done with the CLI you can log out from the given profile, flushing the stored
credentials.

maas logout $PROFILE

Next steps
The following categories are now available to be explored:
 Common tasks
 Kernel management
 Image management
 Tag management
 DHCP snippet management
 Advanced tasks
 Composable hardware
Common CLI Tasks
This is a list of common tasks to perform with the MAAS CLI. See MAAS CLI on how to get
started.

List nodes
To list all nodes (and their characteristics) in the MAAS:

maas $PROFILE nodes read

Add a filter to get just their hostnames:

maas $PROFILE nodes read | grep hostname

Determine a node system ID


To determine the system ID of a node based on its MAAS hostname:

SYSTEM_ID=$(maas $PROFILE nodes read hostname=$HOSTNAME \


| grep system_id -m 1 | cut -d '"' -f 4)

Commission a node
To commission a node:

maas $PROFILE machine commission $SYSTEM_ID

Note: To commission a node it must have a status of 'New'.

To commission all nodes in the 'New' state:

maas $PROFILE machines accept-all

See Commission nodes.

Acquire a node
To acquire/allocate a random node:

maas $PROFILE machines allocate

To acquire/allocate a specific node:

maas $PROFILE machines allocate system_id=$SYSTEM_ID


Note: To acquire a node it must have a status of 'Ready'.

Deploy a node
To deploy a node:

maas $PROFILE machine deploy $SYSTEM_ID

Note: To deploy with the CLI the node must have a status of 'Allocated'. See 'Acquire a node'
above (or use the web UI).

See Deploy nodes.

Control subnet management


To enable or disable subnet management:

maas $PROFILE subnet update $SUBNET_CIDR managed=false|true

For example, to disable:

maas $PROFILE subnet update 192.168.1.0/24 managed=false

The subnet's ID can also be used in place of the CIDR address.

See Subnet management.

Create a reserved IP range


See Concepts and terms for an explanation of the two kinds of reserved IP ranges MAAS uses.

To create a range of dynamic IP addresses that will be used by MAAS for node enlistment,
commissioning, and possibly deployment:

maas $PROFILE ipranges create type=dynamic \


start_ip=$IP_DYNAMIC_RANGE_LOW end_ip=$IP_DYNAMIC_RANGE_HIGH \
comment='This is a reserved dynamic range'

To create a range of IP addresses that will not be used by MAAS:

maas $PROFILE ipranges create type=reserved \


start_ip=$IP_STATIC_RANGE_LOW end_ip=$IP_STATIC_RANGE_HIGH \
comment='This is a reserved range'

To reserve a single IP address that will not be used by MAAS:

maas $PROFILE ipaddresses reserve ip_address=$IP_STATIC_SINGLE


To remove such a single reserved IP address:

maas $PROFILE ipaddresses release ip=$IP_STATIC_SINGLE

Determine a fabric ID
To determine a fabric ID based on a subnet address:

FABRIC_ID=$(maas $PROFILE subnet read $SUBNET_CIDR \


| grep fabric | cut -d ' ' -f 10 | cut -d '"' -f 2)

Enable DHCP
To enable DHCP on a VLAN on a certain fabric:

maas $PROFILE vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True \


primary_rack=$PRIMARY_RACK_CONTROLLER

To enable DHCP HA you will need both a primary and a secondary controller:

maas $PROFILE vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True \


primary_rack=$PRIMARY_RACK_CONTROLLER \
secondary_rack=$SECONDARY_RACK_CONTROLLER

You will also need to set a default gateway (see below).

Note: DHCP for PXE booting will need to be enabled on the 'untagged' VLAN.

See DHCP for more on this subject.

Set a DNS forwarder


To set a DNS forwarder:

maas $PROFILE maas set-config name=upstream_dns value=$MY_UPSTREAM_DNS

Configure proxying
Enabling and disabling proxying in general is done via a boolean option ('true' or 'false'). This is
how proxying is disabled completely:

maas $PROFILE maas set-config name=enable_http_proxy value=false

To set an external proxy, ensure proxying is enabled (see above) and then define it:

maas $PROFILE maas set-config name=http_proxy value=$EXTERNAL_PROXY


For example,

maas $PROFILE maas set-config name=enable_http_proxy value=true


maas $PROFILE maas set-config name=http_proxy
value=http://squid.example.com:3128/

Enabling and disabling proxying per subnet is done via a boolean option ('true' or 'false'). This is
how proxying is disabled per subnet:

maas $PROFILE subnet update $SUBNET_CIDR allow_proxy=false

For example,

maas $PROFILE subnet update 192.168.0.0/22 allow_proxy=false

See Proxy for detailed information on how proxying works with MAAS.

Set a default gateway


To set the default gateway for a subnet:

maas $PROFILE subnet update $SUBNET_CIDR gateway_ip=$MY_GATEWAY

Set a DNS server


To set the DNS server for a subnet:

maas $PROFILE subnet update $SUBNET_CIDR dns_servers=$MY_NAMESERVER

Set a zone description


To set a description for a physical zone:

maas $PROFILE zone update default \


description="This zone was configured by a script."

See Zones for more information on this topic.

Add a public SSH key


To add a public SSH key to a MAAS user account:

maas $PROFILE sshkeys create "key=$SSH_KEY"

See SSH keys.

You might also like