Skip to content

Latest commit

Β 

History

History
301 lines (238 loc) Β· 6.49 KB

File metadata and controls

301 lines (238 loc) Β· 6.49 KB

Tower CLI 3.3.10 Development Guide

πŸš€ How to Use Without Installation

Method 1: Source Environment (RECOMMENDED) ⭐⭐⭐⭐⭐

# Activate environment (once per session)
source env-dev.sh

# Now use tower-cli normally
tower-cli --version
tower-cli instance list
tower-cli instance health --instance 1

Advantages:

  • βœ… Clean syntax as if installed
  • βœ… Code changes immediately active
  • βœ… No installation required

Method 2: Wrapper Script

# Use direct script
./tower-cli-dev.sh --version
./tower-cli-dev.sh instance list
./tower-cli-dev.sh instance health --instance 1

Method 3: Inline PYTHONPATH

# For single commands
PYTHONPATH=. python -c "from tower_cli.cli.run import cli; cli()" --version
PYTHONPATH=. python -c "from tower_cli.cli.run import cli; cli()" instance list

πŸ“ Typical Development Workflow

# 1. Navigate to directory
cd /myData/git/pythonVENV/ansible-tower-cli-3.3.9

# 2. Activate environment
source env-dev.sh
# Output: βœ… Tower CLI Development Environment activated!

# 3. Verify version
tower-cli --version
# Output: Tower CLI 3.3.10

# 4. Configure Tower connection (if needed)
tower-cli config host https://tower.example.com
tower-cli config username admin
tower-cli config password mypass
tower-cli config verify_ssl false

# 5. Test existing commands
tower-cli instance list

# 6. Test new gateway commands
tower-cli instance list --node-type hop
tower-cli instance health --instance gateway-01

# 7. Modify code in tower_cli/...
vim tower_cli/resources/instance.py

# 8. Test immediately (no reinstall!)
tower-cli instance list

# 9. Debug if needed
tower-cli --verbose instance list

πŸ”§ Development File Structure

ansible-tower-cli-3.3.9/
β”œβ”€β”€ tower_cli/              # Source code (modify here)
β”‚   β”œβ”€β”€ resources/
β”‚   β”‚   └── instance.py     # ← Modified file for gateway
β”‚   β”œβ”€β”€ constants.py        # ← Version 3.3.10
β”‚   └── ...
β”œβ”€β”€ env-dev.sh             # ← Script for environment
β”œβ”€β”€ tower-cli-dev.sh       # ← Direct wrapper script
β”œβ”€β”€ GATEWAY_SUPPORT_EN.md  # Gateway documentation
β”œβ”€β”€ CHANGELOG_3.3.10_EN.md # Changes changelog
└── README_EN.md           # English quick start

πŸ§ͺ Testing During Development

Base Tests

source env-dev.sh

# Verify import
python -c "from tower_cli import __version__; print(__version__)"
# Output: 3.3.10

# Test help
tower-cli --help

# Test config
tower-cli config

Instance Command Tests

# List instances
tower-cli instance list

# Filter by type
tower-cli instance list --node-type execution
tower-cli instance list --node-type hop
tower-cli instance list --node-type hybrid

# Get specific
tower-cli instance get --id 1
tower-cli instance get --hostname gateway-01

New Gateway Command Tests

# Health check (requires Tower 3.6+)
tower-cli instance health --instance 1
tower-cli instance health --instance gateway-01 --format json

# Running jobs
tower-cli instance jobs --instance 1
tower-cli instance jobs --instance gateway-01

πŸ› Debug

Verbose Mode

tower-cli --verbose instance list

Python Debug

# Run with Python debug
python -u -c "
import sys
sys.path.insert(0, '.')
from tower_cli.cli.run import cli
cli()
" instance list

Test Import

# Verify module imports
python -c "
import sys
sys.path.insert(0, '.')
from tower_cli.resources import instance
print('Instance resource:', instance.Resource)
print('Endpoint:', instance.Resource.endpoint)
print('Fields:', [f.name for f in instance.Resource.fields])
"

πŸ“Š Useful Commands

Verify Gateway Changes

# Check if node_type is in fields
python -c "
import sys
sys.path.insert(0, '.')
from tower_cli.resources.instance import Resource
r = Resource()
fields = [f.name for f in r.fields]
print('node_type in fields:', 'node_type' in fields)
print('All fields:', fields)
"

Test Without Tower Connection

# Test command help (doesn't require connection)
tower-cli instance --help
tower-cli instance list --help
tower-cli instance health --help
tower-cli instance jobs --help

πŸ”„ Modify and Test

Example: Add a New Field

  1. Modify the code:
vim tower_cli/resources/instance.py

# Add:
# new_field = models.Field(required=False, display=True)
  1. Test IMMEDIATELY (no reinstall):
tower-cli instance list
  1. Verify the field:
python -c "
import sys; sys.path.insert(0, '.')
from tower_cli.resources.instance import Resource
print([f.name for f in Resource().fields])
"

Example: Add a New Command

  1. Modify instance.py:
@resources.command
def my_new_command(self, **kwargs):
    """My new command"""
    return {"status": "ok"}
  1. Test:
tower-cli instance my-new-command

⚑ Tips & Tricks

Permanent Alias

Add to your ~/.bashrc:

alias tower-dev='source /myData/git/pythonVENV/ansible-tower-cli-3.3.9/env-dev.sh'

Then:

tower-dev  # Activate environment
tower-cli --version

Auto-reload with Watch

# Terminal 1: modify code
vim tower_cli/resources/instance.py

# Terminal 2: automatic test
watch -n 2 'PYTHONPATH=. python -c "from tower_cli.resources.instance import Resource; print([f.name for f in Resource().fields])"'

Quick Test Script

#!/bin/bash
source env-dev.sh
tower-cli instance list --node-type hop || echo "No gateways found"
tower-cli instance health --instance 1 || echo "Health check failed"

πŸ“š Resources

  • Documentation: GATEWAY_SUPPORT_EN.md
  • Changelog: CHANGELOG_3.3.10_EN.md
  • Quick Start: README_EN.md
  • API Docs: docs/source/api_ref/

❓ Development FAQ

Q: Changes not showing?

A: Make sure you've done source env-dev.sh in the current session.

Q: "Module not found" error?

A: Verify PYTHONPATH: echo $PYTHONPATH should include current directory.

Q: How do I reset?

A:

unset PYTHONPATH
unalias tower-cli awx-cli
source env-dev.sh  # Reactivate

Q: Can I use multiple versions?

A: Yes, each directory has its own environment. Do source env-dev.sh in the directory you want to use.

🎯 Pre-Test Checklist

  • source env-dev.sh executed
  • tower-cli --version shows 3.3.10
  • Tower connection configured (if needed)
  • Code changes saved
  • Test command executed

Version: 3.3.10 For development without installation Author: rUser75 Project: https://github.com/rUser75/tower-cli