Back to Cloud VPS Documentation

    OpenStack SDK & CLI Tutorial

    Complete guide to managing your cloud resources from the command line

    This tutorial will guide you through installing and using the OpenStack command-line interface (CLI) tools to manage your RamNode Cloud VPS instances programmatically.

    Step 1

    Prerequisites

    Before getting started, ensure you have:

    • A RamNode Cloud account with at least one project
    • Python 3.6 or higher installed on your local machine
    • Basic command-line familiarity
    Step 2

    Install the OpenStack CLI Tools

    The easiest way to install the OpenStack CLI is using pip, Python's package manager.

    Linux (Ubuntu/Debian)

    # Update package lists
    sudo apt update
    
    # Install Python pip
    sudo apt install python3-pip -y
    
    # Install OpenStack CLI
    sudo pip3 install python-openstackclient

    Linux (CentOS/Rocky/AlmaLinux)

    # Install EPEL repository (if not already installed)
    sudo yum install epel-release -y
    
    # Install Python and pip
    sudo yum install python3 python3-pip -y
    
    # Install OpenStack CLI
    sudo pip3 install python-openstackclient

    macOS

    # Install using pip (requires Python 3)
    pip3 install python-openstackclient
    
    # Or using Homebrew
    brew install openstackclient

    Windows

    # Install using pip (requires Python 3)
    pip install python-openstackclient
    Step 3

    Download Your OpenStack RC File

    The RC file contains your authentication credentials and API endpoints.

    1. Log into the Cloud Control Panel
    2. Click on your username in the top right corner
    3. Select OpenStack RC File from the dropdown menu
    4. Choose OpenStack RC File (Identity API v3) - this is the recommended version
    5. Save the file to your local machine (typically named openrc.sh)
    Step 4

    Load Your Credentials

    Source the RC file to load your credentials into your environment:

    Linux/macOS

    # Navigate to where you saved the RC file
    cd ~/Downloads
    
    # Source the file
    source openrc.sh
    
    # You'll be prompted to enter your Cloud Control Panel password
    # Type your password (it won't be visible as you type)

    Windows (PowerShell)

    # Set environment variables manually
    $env:OS_AUTH_URL="https://cloud.ramnode.com:5000/v3"
    $env:OS_PROJECT_NAME="your-project-name"
    $env:OS_USERNAME="your-email"
    $env:OS_PASSWORD="your-password"
    $env:OS_USER_DOMAIN_NAME="Default"
    $env:OS_PROJECT_DOMAIN_NAME="Default"
    $env:OS_IDENTITY_API_VERSION="3"
    Step 5

    Verify the Connection

    Test that your CLI is properly configured:

    # List your current projects
    openstack project list
    
    # List available server flavors (plans)
    openstack flavor list
    
    # List available images
    openstack image list
    
    # List your existing instances
    openstack server list
    Step 6

    Instance Management

    Manage your cloud instances with these common commands:

    Common Instance Commands
    # Create a new instance
    openstack server create \
      --flavor c1.small \
      --image "Ubuntu 22.04 LTS" \
      --key-name my-ssh-key \
      --network public \
      my-server-name
    
    # List all instances
    openstack server list
    
    # Show instance details
    openstack server show my-server-name
    
    # Stop an instance
    openstack server stop my-server-name
    
    # Start an instance
    openstack server start my-server-name
    
    # Reboot an instance
    openstack server reboot my-server-name
    
    # Delete an instance
    openstack server delete my-server-name
    Step 7

    SSH Key Management

    Manage SSH keys for secure server access:

    # List SSH keys
    openstack keypair list
    
    # Upload a new SSH key
    openstack keypair create --public-key ~/.ssh/id_rsa.pub my-key-name
    
    # Delete an SSH key
    openstack keypair delete my-key-name
    Step 8

    Network Management

    Manage floating IPs and network resources:

    # List networks
    openstack network list
    
    # Create a floating IP
    openstack floating ip create public
    
    # List floating IPs
    openstack floating ip list
    
    # Attach floating IP to instance
    openstack server add floating ip my-server-name 198.51.100.10
    
    # Remove floating IP from instance
    openstack server remove floating ip my-server-name 198.51.100.10
    Step 9

    Snapshot Management

    Create and manage instance snapshots:

    # Create a snapshot of an instance
    openstack server image create --name my-snapshot my-server-name
    
    # List all snapshots/images
    openstack image list
    
    # Delete a snapshot
    openstack image delete my-snapshot
    Step 10

    Security Group Management

    Configure firewall rules with security groups:

    # List security groups
    openstack security group list
    
    # Create a security group
    openstack security group create --description "Web Server" web-sg
    
    # Add a rule to allow HTTP
    openstack security group rule create \
      --protocol tcp \
      --dst-port 80 \
      web-sg
    
    # Add a rule to allow SSH
    openstack security group rule create \
      --protocol tcp \
      --dst-port 22 \
      web-sg
    Step 11

    Volume (Block Storage) Management

    Manage block storage volumes:

    # List volumes
    openstack volume list
    
    # Create a volume
    openstack volume create --size 100 my-volume
    
    # Attach volume to instance
    openstack server add volume my-server-name my-volume
    
    # Detach volume from instance
    openstack server remove volume my-server-name my-volume
    
    # Delete a volume
    openstack volume delete my-volume
    Step 12

    Advanced Usage

    Output Formatting

    You can format CLI output in different ways:

    # JSON output
    openstack server list -f json
    
    # YAML output
    openstack server list -f yaml
    
    # CSV output
    openstack server list -f csv
    
    # Table (default)
    openstack server list -f table

    Filtering and Querying

    # Show only specific columns
    openstack server list -c Name -c Status
    
    # Filter by status
    openstack server list --status ACTIVE
    Step 13

    Troubleshooting

    Authentication Issues

    If you encounter authentication errors:

    • Verify your password is correct
    • Check that you've sourced the RC file in your current terminal session
    • Ensure your project name is correct
    • Try downloading a fresh RC file from the control panel

    Connection Timeouts

    If commands are timing out:

    • Check your internet connection
    • Verify that your firewall isn't blocking the API endpoints
    • Try increasing the timeout: export OS_TIMEOUT=300

    Command Not Found

    If the openstack command isn't found:

    • Ensure you've installed the client correctly
    • Check that Python's bin directory is in your PATH
    • Try running: python3 -m pip install --upgrade python-openstackclient
    Step 14

    Using with Scripts

    You can use the OpenStack CLI in shell scripts for automation:

    Bash Script Example
    #!/bin/bash
    
    # Source credentials
    source ~/openrc.sh
    
    # Get list of instances
    INSTANCES=$(openstack server list -f value -c Name)
    
    # Loop through and reboot each instance
    for instance in $INSTANCES; do
        echo "Rebooting $instance..."
        openstack server reboot "$instance"
    done
    
    echo "All instances rebooted!"

    Python SDK Alternative

    For more complex automation, you can use the OpenStack Python SDK:

    Python SDK Example
    # Install the SDK
    pip install openstacksdk
    
    # Example Python script
    import openstack
    
    # Create connection
    conn = openstack.connect(cloud='openstack')
    
    # List instances
    for server in conn.compute.servers():
        print(server.name, server.status)
    
    # Create an instance
    server = conn.compute.create_server(
        name='my-server',
        image='Ubuntu 22.04',
        flavor='c1.small',
        network='public'
    )
    
    print(f"Created server: {server.name}")

    Pro Tip: For managing multiple clouds or projects, you can create a clouds.yaml file in ~/.config/openstack/ to store multiple sets of credentials. See the OpenStack CLI documentation for details.