OpenStack command line clients: Difference between revisions

From Alliance Doc
Jump to navigation Jump to search
(Marked this version for translation)
No edit summary
 
(37 intermediate revisions by 8 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>
<!--T:1-->
''Parent page: [[OpenStack]]''


<!--T:2-->
<!--T:20-->
The OpenStack CLI tools perform many of the actions performed by the OpenStack dashboard GUI but on the command line. They also allow more functionality above and beyond the OpenStack dashboard.
''Parent page: [[Managing your cloud resources with OpenStack]]''
The command line clients can be used from any machine, virtual or otherwise, and only require having an internet connection and the command line clients installed. The below discussion of command line client(s), assumes that they are being used on a Linux machine. It may be possible to use them in Windows however, this has not yet been explored.


==Connecting CLI to OpenStack== <!--T:3-->
<!--T:21-->
To begin, get the openstack environment setup file: On the OpenStack dashboard go to compute->Access & Security-> API Access-> Download OpenStack RC File. This file sets environment variables so that the command line client(s) know how to connect to your OpenStack project. Then source the file (you will need to provide your OpenStack password) with something like
The [http://docs.openstack.org/developer/python-openstackclient/ OpenStack command line tool] allows you to perform many of the actions provided by the OpenStack dashboard GUI, as well as providing some functionality which the dashboard does not. The command line client can be used from any machine, virtual or otherwise, and only requires having an internet connection and the client installed. The discussion below assumes that it is being used on a Linux machine.
{{Command | source <project name>-openrc.sh}}


<!--T:4-->
==Installation== <!--T:22-->
On East-cloud there are two RC files to choose from a v2.0 and a v3 file. Unless you have a specific reason to choose the v2.0 file, choose the v3 file. If your openstack client version is version 2.5.0 or later, the East-cloud v3 file must have the line <code>export OS_IDENTITY_API_VERSION=3</code> added to it. Finally if switching between different RC files (e.g. east and west cloud RC files) you should be careful of environment variables which may still be set from the previous RC file, these may cause your OpenStack client commands to fail. You can either ensure that all environment variables set in the RC file are unset with <code>unset <variable-name></code> commands for each variable, or start a fresh new session without any of the RC environment variables set.
The OpenStack command lines tools are Python-based. You can install and run them on your personal computer or on a cloud VM. Different Linux distributions may have pre-built packages for the client, see the OpenStack [https://docs.openstack.org/user-guide/common/cli-install-openstack-command-line-clients.html installation documentation] for more details. You can quickly install both Python and the OpenStack command line tools, if you have administrative privileges on your machine.


==Combined OpenStack CLI == <!--T:5-->
<!--T:38-->
The OpenStack combined CLI replaces the various separate command line tools, such as nova, swift, glance, cider etc. (see [[OpenStack Command Line Clients#Separate Command Line Clients | Separate Command Line Clients]] for a brief overview of the older separate command line clients). See for the official OpenStack [http://docs.openstack.org/developer/python-openstackclient/ CLI documentation] for more information about the OpenStack command line clients. The rest of this section gives a very basic overview to get a user started and points out some of the commands available.
; Ubuntu
<pre>
sudo apt-get install python python-dev python-pip
sudo pip install python-openstackclient
</pre>
; CentOS 7
Run as root
<pre>
yum install epel-release
yum install gcc python python-dev python2-pip
pip install python-openstackclient
</pre>
; Fedora
<pre>
sudo dnf install python-openstackclient
</pre>
; Note: If you do not have administrative privileges and cannot use the OS package manager, then you will need to install Python and [https://pip.pypa.io/en/latest/installing/ pip] by other means. Once installed, you can get the command line tools installed into your home space like so:
<pre>
pip install --user python-openstackclient
</pre>
: The install location is probably already included in your <code>$PATH</code>, but you can double check whether <code>~/.bashrc</code> or <code>~/.bash_profile</code> contains the following line <code>PATH=$PATH:$HOME/.local/bin:$HOME/bin</code>


===Installation=== <!--T:6-->
<!--T:23-->
If you have admin access on the machine you will run these from (e.g. your desktop) you can do
; SDK
{{commands|sudo apt-get install python-dev python-pip|sudo pip install python-openstackclient}}
If you wish to explore the [http://docs.openstack.org/user-guide/sdk.html OpenStack API for Python], add <code>export PYTHONPATH=${HOME}/.local/lib/python2.7/site-packages/:${PYTHONPATH}</code> to your <code>.bashrc</code> file. Adjust the <code>python2.7</code> phrase to match the Python version you have installed.
To install on a machine without admin privileges (provided pip is already installed) use:{{command| pip install --user python-openstackclient}}
which installs to ~/.local/lib/pythonX.Y/site-packages/. By adding <code>export PYTHONPATH=${HOME}/.local/lib/python2.7/site-packages/:${PYTHONPATH}</code> to your <code>.bashrc</code> file if you are using Python major version X=2, and minor version Y=7, python can then load the OpenStack modules (see [] for information about working with the Python OpenStack API). Further adding <code>export PATH=${HOME}/.local/bin:${PATH}</code> to your .bashrc will allow you to run the OpenStack commands directly. To install a specific version of the client using pip do <code>pip install python_openstackclient==2.3.0</code>.


==Connecting CLI to OpenStack== <!--T:25-->
Your command line client must now be told how to find your OpenStack project on our clouds.
The most convenient way to do this is to download an OpenStack environment setup file. On the OpenStack dashboard go to Project-> API Access-> Download OpenStack RC File.


<!--T:7-->
<!--T:27-->
Some distributions may have pre-built packages for the client, e.g., on Fedora 23: {{commands|sudo dnf install python-openstackclient}}
Then source the file with something like {{Command |source <project name>-openrc.sh}} It will ask you for your OpenStack password, which is simply your CCDB password. Test your setup by typing {{Command |openstack image list}}


<!--T:8-->
<!--T:28-->
see the OpenStack [http://docs.openstack.org/cli-reference/common/cli_install_openstack_command_line_clients.html installation documentation] for more details.
If you switch between different RC files you should be careful of environment variables which may still be set from the previous RC file, these may cause your OpenStack client commands to fail. Either ensure that all environment variables set in the RC file are unset with <code>unset <variable-name></code>, or start a fresh new session without any of the RC environment variables set.


===Executing commands=== <!--T:9-->
==Executing commands== <!--T:29-->
The combined CLI tool can be used interactively by running
The CLI tool can be used interactively by typing
{{Command|openstack}}
{{Command|openstack}}
and then issuing commands at the prompt. Alternatively the commands can be issued as one-offs by preceding the command with <code>openstack</code>, for example
and then issuing commands at the prompt. Alternatively the commands can be issued as one-offs by preceding the command with <code>openstack</code>, for example
{{Command|openstack server list}}
{{Command|openstack server list}}
When running in interactive mode a list of available commands can be seen by typing <code>help</code> at the OpenStack prompt. The available commands are categorized by groups, many of the most commonly used groups are listed below (e.g. the <code>server</code> command group). A list of commands belonging to a command group can be obtained by typing <code>help <command group></code>. To get help on a particular command (e.g. options and arguments of the command) one can type <code>help <command group> <command></code>. Note that many of the available commands are available only to OpenStack administrators and will show some meaningless error message if a non-administrator tries using it. For this reason a list of available commands grouped by command groups is provided below to allow one to easily identify commands available to the average user.
When running in interactive mode a list of available commands can be seen by typing <code>help</code> at the OpenStack prompt. The available commands are categorized by groups; many of the most commonly used groups are listed below. A list of commands belonging to a command group can be obtained by typing <code>help <command group></code>. To get help on a particular command (e.g. options and arguments of the command) one can type <code>help <command group> <command></code>. Note that many commands are available only to OpenStack administrators and will return an error message if a non-administrator tries using it. For this reason a list of available commands grouped by command groups is provided below to allow one to easily identify commands available to the average user.


====<code>server</code> command group==== <!--T:10-->
==Command groups== <!--T:30-->
===<code>server</code> command group===
{|-
{|-
| <code>add security group</code>  || <code>migrate</code> || <code>resume</code> || <code>unlock</code>
| <code>add security group</code>  || <code>migrate</code> || <code>resume</code> || <code>unlock</code>
Line 57: Line 75:
|}
|}


====<code>volume</code> command group==== <!--T:11-->
===<code>volume</code> command group=== <!--T:31-->
{|-
{|-
|<code>create</code>||<code>set</code>
|<code>create</code>||<code>set</code>
Line 66: Line 84:
|}
|}


====<code>console</code> command group==== <!--T:12-->
===<code>console</code> command group=== <!--T:32-->
{|-
{|-
|<code>log show</code>||<code>url show</code>
|<code>log show</code>||<code>url show</code>
|}
|}
====<code>flavor</code> command group====
===<code>flavor</code> command group===
{|-
{|-
|<code>list</code>||<code>show</code>
|<code>list</code>||<code>show</code>
|}
|}
====<code>image</code> command group====
===<code>image</code> command group===
{|-
{|-
|<code>create</code>
|<code>create</code>
Line 86: Line 104:
|}
|}


====<code>ip</code> command group==== <!--T:13-->
===<code>ip</code> command group=== <!--T:33-->
{|-
{|-
|<code>fixed add</code>||<code>floating list</code>
|<code>fixed add</code>||<code>floating list</code>
Line 98: Line 116:
|<code>floating delete</code>
|<code>floating delete</code>
|}
|}
====<code>keypair</code> command group====
===<code>keypair</code> command group===
{|-
{|-
|<code>create</code>||<code>list</code>
|<code>create</code>||<code>list</code>
Line 105: Line 123:
|}
|}


====<code>network</code> command group==== <!--T:14-->
===<code>network</code> command group=== <!--T:34-->
{|-
{|-
|<code>create</code>||<code>set</code>
|<code>create</code>||<code>set</code>
Line 114: Line 132:
|}
|}


====<code>snapshot</code> command group==== <!--T:15-->
===<code>snapshot</code> command group=== <!--T:35-->
{|-
{|-
|<code>create</code>||<code>set</code>
|<code>create</code>||<code>set</code>
Line 123: Line 141:
|}
|}


====<code>security group</code> command group==== <!--T:16-->
===<code>security group</code> command group=== <!--T:36-->
{|-
{|-
|<code>create</code>||<code>rule list</code>
|<code>create</code>||<code>rule list</code>
Line 135: Line 153:
|<code>rule delete</code>||
|<code>rule delete</code>||
|}
|}
====<code>limits show</code>====
 
===<code>limits</code> command group=== <!--T:37-->
{|-
|<code>show </code>||
|}
<!--These two (container and object) are not widely publicized
<!--These two (container and object) are not widely publicized
====container====
===container===
{|-
{|-
|<code>create</code>||<code>set</code>
|<code>create</code>||<code>set</code>
Line 147: Line 169:
|<code>save</code>
|<code>save</code>
|}
|}
====object====
===object===
{|-
{|-
|<code>create</code>||<code>show</code>
|<code>create</code>||<code>show</code>
Line 161: Line 183:
-->
-->


==Separate Command Line Clients== <!--T:17-->
==Separate Command-line interfaces== <!--T:40-->
The older version of the command line clients were separated into individual clients which operated on the various aspects of OpenStack. They are mentioned here, since, as of the time of writing, not all the functionality of the older separate command line clients has been incorporated into the new combined command line clients and one may find them useful in addition to the newer combined command line client.<!--
In addition to the <code>openstack</code> command described above which incorporates much of the total functionality available into one command there are also individual commands to work with the separate components of OpenStack which often have extra functionality. These separate commands are installed at the same time as the <code>openstack</code> command, as described above, so no further installation is required to use them. A list of the commands for working with common components of OpenStack are:
 
* <code>nova</code>: for working with servers, see [https://docs.openstack.org/python-novaclient/latest/cli/nova.html OpenStack docs for nova command].
<!--T:18-->
* <code>glance</code>: for working with images, see [https://docs.openstack.org/python-glanceclient/latest/cli/glance.html OpenStack docs for glance command].
<ol>
* <code>cinder</code>: for working with volumes, see [https://docs.openstack.org/python-cinderclient/latest/user/shell.html OpenStack docs for cinder command].
<li>
* <code>heat</code>: for working with orchestration, see [https://docs.openstack.org/python-heatclient/latest/man/heat.html OpenStack docs for heat command].
Get the openstack environment setup file: On the OpenStack dashboard go to compute->Access & Security-> API Access-> Download OpenStack RC File. This file sets environment variables so that the command line clients know how to connect to your OpenStack project.</li>
<li>source the file (you will need to provide your OpenStack password)</li>
<li>install the nova client:{{Command|sudo apt-get install python-novaclient}}this client is used for managing images, instances, and flavors (i.e. the "compute" tab on horizon dashboard). (e.g. run the command {{Command|nova list}}, which lists all the instances currently setup)</li>
<li>install keystone client:{{Command|sudo apt-get install python-keystoneclient}}this client creates and manages users, tenants, roles, endpoints, and credentials. (e.g. run the command {{Command|keystone catalog}})</li>
<li>install neutron client:{{Command|sudo apt-get install python-neutronclient}} this client manages networks</li>
<li>install swift client:{{Command|sudo apt-get install python-swiftclient}} This client is used for managing the OpenStack object storage.</li>
<li>install heat client:{{Command|sudo apt-get install python-heatclient}} This client is used for automating cluster creation.</li>
</ol>-->


<!--T:19-->
<!--T:39-->
[[Category:CC-Cloud]]
[[Category: Cloud]]
</translate>
</translate>

Latest revision as of 15:31, 7 October 2024

Other languages:

Parent page: Managing your cloud resources with OpenStack

The OpenStack command line tool allows you to perform many of the actions provided by the OpenStack dashboard GUI, as well as providing some functionality which the dashboard does not. The command line client can be used from any machine, virtual or otherwise, and only requires having an internet connection and the client installed. The discussion below assumes that it is being used on a Linux machine.

Installation[edit]

The OpenStack command lines tools are Python-based. You can install and run them on your personal computer or on a cloud VM. Different Linux distributions may have pre-built packages for the client, see the OpenStack installation documentation for more details. You can quickly install both Python and the OpenStack command line tools, if you have administrative privileges on your machine.

Ubuntu
sudo apt-get install python python-dev python-pip
sudo pip install python-openstackclient
CentOS 7

Run as root

yum install epel-release
yum install gcc python python-dev python2-pip
pip install python-openstackclient
Fedora
sudo dnf install python-openstackclient
Note
If you do not have administrative privileges and cannot use the OS package manager, then you will need to install Python and pip by other means. Once installed, you can get the command line tools installed into your home space like so:
pip install --user python-openstackclient
The install location is probably already included in your $PATH, but you can double check whether ~/.bashrc or ~/.bash_profile contains the following line PATH=$PATH:$HOME/.local/bin:$HOME/bin
SDK

If you wish to explore the OpenStack API for Python, add export PYTHONPATH=${HOME}/.local/lib/python2.7/site-packages/:${PYTHONPATH} to your .bashrc file. Adjust the python2.7 phrase to match the Python version you have installed.

Connecting CLI to OpenStack[edit]

Your command line client must now be told how to find your OpenStack project on our clouds. The most convenient way to do this is to download an OpenStack environment setup file. On the OpenStack dashboard go to Project-> API Access-> Download OpenStack RC File.

Then source the file with something like

Question.png
[name@server ~]$ source <project name>-openrc.sh

It will ask you for your OpenStack password, which is simply your CCDB password. Test your setup by typing

Question.png
[name@server ~]$ openstack image list

If you switch between different RC files you should be careful of environment variables which may still be set from the previous RC file, these may cause your OpenStack client commands to fail. Either ensure that all environment variables set in the RC file are unset with unset <variable-name>, or start a fresh new session without any of the RC environment variables set.

Executing commands[edit]

The CLI tool can be used interactively by typing

Question.png
[name@server ~]$ openstack

and then issuing commands at the prompt. Alternatively the commands can be issued as one-offs by preceding the command with openstack, for example

Question.png
[name@server ~]$ openstack server list

When running in interactive mode a list of available commands can be seen by typing help at the OpenStack prompt. The available commands are categorized by groups; many of the most commonly used groups are listed below. A list of commands belonging to a command group can be obtained by typing help <command group>. To get help on a particular command (e.g. options and arguments of the command) one can type help <command group> <command>. Note that many commands are available only to OpenStack administrators and will return an error message if a non-administrator tries using it. For this reason a list of available commands grouped by command groups is provided below to allow one to easily identify commands available to the average user.

Command groups[edit]

server command group[edit]

add security group migrate resume unlock
add volume pause set unpause
create reboot shelve unrescue
delete rebuild show unset
dump create remove security group ssh unshelve
image create remove volume start
list rescue stop
lock resize suspend

volume command group[edit]

create set
delete show
list unset

console command group[edit]

log show url show

flavor command group[edit]

list show

image command group[edit]

create save
delete set
list show

ip command group[edit]

fixed add floating list
fixed remove floating pool list
floating add floating remove
floating create floating show
floating delete

keypair command group[edit]

create list
delete show

network command group[edit]

create set
delete show
list

snapshot command group[edit]

create set
delete show
list unset

security group command group[edit]

create rule list
delete rule show
list set
rule create show
rule delete

limits command group[edit]

show

Separate Command-line interfaces[edit]

In addition to the openstack command described above which incorporates much of the total functionality available into one command there are also individual commands to work with the separate components of OpenStack which often have extra functionality. These separate commands are installed at the same time as the openstack command, as described above, so no further installation is required to use them. A list of the commands for working with common components of OpenStack are: