diff --git a/README.md b/README.md index fd1986e1a06a73346b025dbb62fc708db9797a34..01be48cc68c77d2a788ba121074208621cbc89f2 100644 --- a/README.md +++ b/README.md @@ -1,101 +1,121 @@ -# 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. -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 +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. -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. + +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. -## Setup OpenStack's CLI +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. -Link: https://docs.openstack.org/newton/user-guide/common/cli-install-openstack-command-line-clients.html +## Step 1: Setting Up OpenStack CLI -Before starting the installation, make sure you have Python and Pip installed in your computer. +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). -*Installation* +Ensure Python and Pip are installed on your machine. If not, install them before proceeding. + +*Installing OpenStack Client*: ```bash pip install python-openstackclient ``` -Then, to make sure it is correctly installed: + +After the installation, verify that it's set up correctly: ```bash -$ openstack --version -openstack 7.0.0 +openstack --version ``` -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. + +## Step 2: Configuring OpenStack Credentials -### Credential File +You’ll need to configure access credentials for your OpenStack project. Here's how to do it: -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. +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`. -⚠️ App credentials might not work for some commands. +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`. -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. +⚠️ **Important:** Avoid mixing authentication methods (e.g., API credentials and app credentials) in the same configuration file. -⚠️ Avoid mixing different authentication schemes in clouds.yaml or fromthe environment (via sourcing so called OpenStack RC files). +### Verifying Credentials -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): +Once your credentials are configured, verify them with the following commands: ```bash openstack --os-cloud=engines 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 +## Step 3: Writing Your Shell Script -To remind you again of the goal of this exercise, you are to create a shell script which: -1. Create a VM -2. Install Nginx in the VM -3. Delete VM +Your task is to write a shell script that automates the following steps: -To aid you with this exercise, here is the link to a few examples of how to use the OpenStack CLI commands: -- https://docs.openstack.org/python-openstackclient/latest/ -- https://openmetal.io/docs/manuals/operators-manual/day-1/command-line/openstackclient +### 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: -To list all available flavours: - -```bash -openstack --os-cloud=engines flavor list -``` +- List flavors: + ```bash + openstack --os-cloud=engines flavor list + ``` +- List images: + ```bash + openstack --os-cloud=engines image list + ``` +- List security groups: + ```bash + openstack --os-cloud=engines security group list + ``` -To list all available images: +### 2. Creating the VM +Use the following command to create a VM: ```bash -openstack --os-cloud=engines image list +openstack server create --flavor FLAVOR_ID --image IMAGE_ID --key-name KEY_NAME \ +--security-group SEC_GROUP_NAME \ +INSTANCE_NAME ``` -To list all the availables security groups: +### 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 -openstack --os-cloud=engines security group list +openstack floating ip create public +openstack server add floating ip INSTANCE_NAME FLOATING_IP ``` -To list all available key pairs: +### 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 -openstack --os-cloud=engines keypair list +ssh -i PATH_TO_KEY_PAIR.pem ubuntu@FLOATING_IP +sudo apt update && sudo apt install nginx -y ``` -The VM creation command is: + +### 5. Deleting the VM +When the VM is no longer needed, you can delete it using this command: ```bash -openstack server create --flavor FLAVOR_ID --image IMAGE_ID --key-name KEY_NAME \ - --security-group SEC_GROUP_NAME \ - INSTANCE_NAME +openstack server delete INSTANCE_NAME ``` -Then, to list the available instance: +## Additional Resources -```bash -openstack --os-cloud=engines server list -``` +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