Skip to content

NT533-Q12-Distributed-Computing/lab-02-openstack-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

OpenStack Network Automation

This Python script automates the creation of a network topology in OpenStack with 3 virtual machines across 2 networks, as shown in the network diagram.

Features

The script automates all the required tasks:

  • B1: Authentication using clouds.yaml
  • B2: Create networks nhomXX_net1, nhomXX_net2
  • B3: Create subnets nhomXX_subnet1, nhomXX_subnet2
  • B4: Create ports with specific IP addresses:
    • 192.168.X.11 (pc0 on net1)
    • 192.168.X.12 (pc1 on net1)
    • 192.168.(X+1).11 (pc0 on net2)
    • 192.168.(X+1).12 (pc2 on net2)
  • B5: List available images
  • B6: List available flavors
  • B8: List available keypairs
  • B9: Create instances with base64-encoded init script
  • B10: Verify the complete setup

Network Topology

nhomXX_pc2 ---- nhomXX_net2 ---- nhomXX_pc0 ---- nhomXX_net1 ---- nhomXX_pc1
    .12             192.168.(X+1).0/24    .11/.11        192.168.X.0/24      .12

Where:

  • nhomXX_pc0 acts as a router/gateway between the two networks
  • nhomXX_pc1 is connected to net1
  • nhomXX_pc2 is connected to net2

Prerequisites

  1. OpenStack Environment: Access to an OpenStack cloud
  2. clouds.yaml: Configuration file with authentication details
  3. Python Dependencies: Install required packages

Installation

  1. Install Python dependencies:
pip install -r requirements.txt
  1. Ensure your clouds.yaml file is properly configured in the current directory or in ~/.config/openstack/clouds.yaml

Usage

Basic Usage (Group 1)

python3 openstack_automation.py

Specify Group Number

python3 openstack_automation.py 5

This will create networks with IP ranges:

  • net1: 192.168.5.0/24
  • net2: 192.168.6.0/24

Cleanup Options

Clean up by name pattern (recommended)

# Clean up group 1 resources
python3 openstack_automation.py --cleanup

# Clean up group 5 resources
python3 openstack_automation.py --cleanup 5

Clean up all resources from current session

# Clean up all resources created in current session
python3 openstack_automation.py --cleanup-all

Help

python3 openstack_automation.py --help

Make Executable

chmod +x openstack_automation.py
./openstack_automation.py

Configuration

The script uses the following naming convention:

  • Networks: Nhom{XX}_Q12_net1, Nhom{XX}_Q12_net2
  • Subnets: Nhom{XX}_Q12_subnet1, Nhom{XX}_Q12_subnet2
  • Ports: Nhom{XX}_Q12_pc0_net1, Nhom{XX}_Q12_pc1_net1, Nhom{XX}_Q12_pc0_net2, Nhom{XX}_Q12_pc2_net2
  • Instances: Nhom{XX}_Q12_pc0, Nhom{XX}_Q12_pc1, Nhom{XX}_Q12_pc2

Where XX is the group number (zero-padded to 2 digits).

For example, group 1 creates resources with prefix Nhom01_Q12.

Instance Initialization

Each instance is created with a base64-encoded initialization script that:

  • Updates the system packages
  • Installs basic networking tools
  • Configures network interfaces
  • Enables IP forwarding on the router (pc0)
  • Installs and configures nginx web server
  • Creates a test web page

Error Handling

The script includes comprehensive error handling:

  • Checks for existing resources to avoid conflicts
  • Provides detailed error messages
  • Gracefully handles authentication failures
  • Validates resource availability before creation

Output

The script provides detailed output for each step:

  • ✅ Success indicators
  • ⚠️ Warnings for existing resources
  • ❌ Error messages with details
  • 📊 Summary of created resources

Troubleshooting

  1. Authentication Issues: Verify your clouds.yaml configuration
  2. Resource Conflicts: The script handles existing resources gracefully
  3. Permission Issues: Ensure your OpenStack user has necessary permissions
  4. Network Issues: Check if the IP ranges don't conflict with existing networks

Example Output

🚀 Starting OpenStack Network Automation
Group Number: 1
Network 1: 192.168.1.0/24
Network 2: 192.168.2.0/24
==================================================

🔐 B1. Authenticating with OpenStack...
✅ Authentication successful!

🌐 B2. Creating networks...
Creating network: nhom01_net1
✅ Network nhom01_net1 created successfully!
Creating network: nhom01_net2
✅ Network nhom01_net2 created successfully!

🔗 B3. Creating subnets...
Creating subnet: nhom01_subnet1 (192.168.1.0/24)
✅ Subnet nhom01_subnet1 created successfully!
...

🎉 All tasks completed successfully!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages