Skip to content
Snippets Groups Projects
Commit b38c0a46 authored by francisc.mendonca's avatar francisc.mendonca
Browse files

improved text

parent 427cbad0
No related branches found
No related tags found
No related merge requests found
# Lab-OS-CLI # Lab-OS-CLI: Automating Cloud Stack Deployment with OpenStack CLI
The object of this exercise is to learn how to automate the deployment of a cloud stack. In this case, it will be the same stack as deployed in the GUI tutorial. The purpose of this lab is to help you learn how to automate the deployment of a cloud stack using OpenStack's CLI. You will automate the same steps as in the GUI tutorial but through command-line interaction, scripting the process for efficiency.
Goal:
- Setup OpenStack's CLI
- Create a shell script that:
- Selects Flavour, Image, Sec. Group
- Create VM
- Select and Attach Floating IP
- Install Nginx
- Delete VM
For this we'll create two scripts - one for the creation of the VM, and a second for the deletion, although this could be only one script. ## Objectives:
- Set up OpenStack's CLI on your system.
- Create two shell scripts:
- One for creating and configuring a VM.
- Another for deleting the VM.
## Setup OpenStack's CLI In these scripts, you will:
1. Select the appropriate flavor, image, and security group.
2. Create a VM.
3. Attach a floating IP to the VM.
4. Install Nginx on the VM.
5. Delete the VM after use.
Link: https://docs.openstack.org/newton/user-guide/common/cli-install-openstack-command-line-clients.html Although it’s possible to combine both actions into a single script, separating them into "create" and "delete" scripts is a good practice for modularity.
Before starting the installation, make sure you have Python and Pip installed in your computer. ## Step 1: Setting Up OpenStack CLI
*Installation* Follow the installation guide for OpenStack CLI here: [OpenStack CLI Installation Guide](https://docs.openstack.org/newton/user-guide/common/cli-install-openstack-command-line-clients.html).
Ensure Python and Pip are installed on your machine. If not, install them before proceeding.
*Installing OpenStack Client*:
```bash ```bash
pip install python-openstackclient pip install python-openstackclient
``` ```
Then, to make sure it is correctly installed:
After the installation, verify that it's set up correctly:
```bash ```bash
$ openstack --version openstack --version
openstack 7.0.0
``` ```
If version number has been returned, then the installation is successful
You should see the version number returned, such as `openstack 7.0.0`, indicating successful installation.
### Credential File ## Step 2: Configuring OpenStack Credentials
Go to your project page, then in the menu on the left select Identity and then Application Credentials. Press 'Create Application Credentials' in the top right, and save it as `~/.config/openstack/clouds.yaml`. With SwitchEngines, the cloud name to use for this is engines. You’ll need to configure access credentials for your OpenStack project. Here's how to do it:
⚠️ App credentials might not work for some commands. 1. Go to your project’s page in the OpenStack GUI.
2. Navigate to **Identity > Application Credentials**.
3. Create a new application credential and save it as `~/.config/openstack/clouds.yaml`.
A template is also available in this repo file `conf/clouds.yaml.app_cred`. Alternatively, you can use your API credentials with explicit project name/ID -- you'll have to add your API password from your profile page's "Credentials" tab. A template is available in this repo file conf/clouds.yaml.api_cred. Ensure your `clouds.yaml` file is correctly configured for your project (e.g., SwitchEngines cloud is named `engines`). Be aware that some commands may not work with application credentials; you might need to use API credentials instead. You can find a template for both in the provided repo files: `conf/clouds.yaml.app_cred` and `conf/clouds.yaml.api_cred`.
⚠️ Avoid mixing different authentication schemes in clouds.yaml or fromthe environment (via sourcing so called OpenStack RC files). ⚠️ **Important:** Avoid mixing authentication methods (e.g., API credentials and app credentials) in the same configuration file.
Verify that your credentials are OK (⚠ it might reveal secrets! f you have just one cloud configured, you can drop the switch --os-cloud=engines, else adapt accordingly): ### Verifying Credentials
Once your credentials are configured, verify them with the following commands:
```bash ```bash
openstack --os-cloud=engines credential list openstack --os-cloud=engines credential list
openstack --os-cloud=engines application credential list openstack --os-cloud=engines application credential list
``` ```
⚠️ These commands might take a few seconds to complete. It is normal. Note: These commands may take a few seconds to execute, which is normal.
## Shell Script
To remind you again of the goal of this exercise, you are to create a shell script which: ## Step 3: Writing Your Shell Script
1. Create a VM
2. Install Nginx in the VM
3. Delete VM
To aid you with this exercise, here is the link to a few examples of how to use the OpenStack CLI commands: Your task is to write a shell script that automates the following steps:
- https://docs.openstack.org/python-openstackclient/latest/
- https://openmetal.io/docs/manuals/operators-manual/day-1/command-line/openstackclient
To list all available flavours: ### 1. Selecting a Flavor, Image, and Security Group
You'll need to select the flavor, image, and security group for your VM. Use the following commands to list available options:
- List flavors:
```bash ```bash
openstack --os-cloud=engines flavor list openstack --os-cloud=engines flavor list
``` ```
- List images:
To list all available images:
```bash ```bash
openstack --os-cloud=engines image list openstack --os-cloud=engines image list
``` ```
- List security groups:
```bash
openstack --os-cloud=engines security group list
```
To list all the availables security groups: ### 2. Creating the VM
Use the following command to create a VM:
```bash ```bash
openstack --os-cloud=engines security group list openstack server create --flavor FLAVOR_ID --image IMAGE_ID --key-name KEY_NAME \
--security-group SEC_GROUP_NAME \
INSTANCE_NAME
``` ```
To list all available key pairs: ### 3. Attaching a Floating IP
After creating the VM, you'll need to assign a floating IP. Consult the following example to attach one to your instance:
```bash ```bash
openstack --os-cloud=engines keypair list openstack floating ip create public
openstack server add floating ip INSTANCE_NAME FLOATING_IP
``` ```
The VM creation command is:
### 4. Installing Nginx on the VM
To install Nginx on the VM, you will need to log in using SSH (you will likely need to specify the floating IP you just assigned) and then run the Nginx installation command:
```bash ```bash
openstack server create --flavor FLAVOR_ID --image IMAGE_ID --key-name KEY_NAME \ ssh -i PATH_TO_KEY_PAIR.pem ubuntu@FLOATING_IP
--security-group SEC_GROUP_NAME \ sudo apt update && sudo apt install nginx -y
INSTANCE_NAME
``` ```
Then, to list the available instance: ### 5. Deleting the VM
When the VM is no longer needed, you can delete it using this command:
```bash ```bash
openstack --os-cloud=engines server list openstack server delete INSTANCE_NAME
``` ```
## Additional Resources
For more details on OpenStack CLI commands, refer to the following documentation:
- [OpenStack CLI Reference](https://docs.openstack.org/python-openstackclient/latest/)
- [OpenMetal Operator’s Manual: OpenStack CLI](https://openmetal.io/docs/manuals/operators-manual/day-1/command-line/openstackclient)
By completing this lab, you will have gained hands-on experience in automating cloud deployment tasks using OpenStack’s CLI. You should now be able to write your shell scripts to handle these tasks efficiently.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment