Skip to content

Latest commit

Β 

History

History
299 lines (236 loc) Β· 6.58 KB

File metadata and controls

299 lines (236 loc) Β· 6.58 KB

Guida Sviluppo Tower CLI 3.3.10

πŸš€ Come Usare Senza Installazione

Metodo 1: Source Environment (CONSIGLIATO) ⭐⭐⭐⭐⭐

# Attiva environment (una volta per sessione)
source env-dev.sh

# Ora usa tower-cli normalmente
tower-cli --version
tower-cli instance list
tower-cli instance health --instance 1

Vantaggi:

  • βœ… Sintassi pulita come se fosse installato
  • βœ… Modifiche al codice immediatamente attive
  • βœ… Nessuna installazione necessaria

Metodo 2: Script Wrapper

# Usa lo script diretto
./tower-cli-dev.sh --version
./tower-cli-dev.sh instance list
./tower-cli-dev.sh instance health --instance 1

Metodo 3: PYTHONPATH Inline

# Per comandi singoli
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

πŸ“ Workflow Development Tipico

# 1. Naviga nella directory
cd /myData/git/pythonVENV/ansible-tower-cli-3.3.9

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

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

# 4. Configura connessione Tower (se necessario)
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. Testa comandi esistenti
tower-cli instance list

# 6. Testa nuovi comandi gateway
tower-cli instance list --node-type hop
tower-cli instance health --instance gateway-01

# 7. Modifica codice in tower_cli/...
vim tower_cli/resources/instance.py

# 8. Testa immediatamente (nessun reinstall!)
tower-cli instance list

# 9. Debug se necessario
tower-cli --verbose instance list

πŸ”§ Struttura File Development

ansible-tower-cli-3.3.9/
β”œβ”€β”€ tower_cli/              # Codice sorgente (modifica qui)
β”‚   β”œβ”€β”€ resources/
β”‚   β”‚   └── instance.py     # ← File modificato per gateway
β”‚   β”œβ”€β”€ constants.py        # ← Versione 3.3.10
β”‚   └── ...
β”œβ”€β”€ env-dev.sh             # ← Script per environment
β”œβ”€β”€ tower-cli-dev.sh       # ← Script wrapper diretto
β”œβ”€β”€ GATEWAY_SUPPORT.md     # Documentazione gateway
β”œβ”€β”€ CHANGELOG_3.3.10.md    # Changelog modifiche
└── README_IT.md           # Quick start italiano

πŸ§ͺ Testing Durante Development

Test Base

source env-dev.sh

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

# Test help
tower-cli --help

# Test config
tower-cli config

Test Comandi Instance

# Lista istanze
tower-cli instance list

# Filtra per tipo
tower-cli instance list --node-type execution
tower-cli instance list --node-type hop
tower-cli instance list --node-type hybrid

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

Test Nuovi Comandi Gateway

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

# Jobs running
tower-cli instance jobs --instance 1
tower-cli instance jobs --instance gateway-01

πŸ› Debug

Verbose Mode

tower-cli --verbose instance list

Python Debug

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

Test Import

# Verifica import moduli
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])
"

πŸ“Š Comandi Utili

Verifica Modifiche Gateway

# Controlla se node_type Γ¨ nei campi
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 Senza Connessione Tower

# Testa help dei comandi (non richiede connessione)
tower-cli instance --help
tower-cli instance list --help
tower-cli instance health --help
tower-cli instance jobs --help

πŸ”„ Modificare e Testare

Esempio: Aggiungere un Nuovo Campo

  1. Modifica il codice:
vim tower_cli/resources/instance.py

# Aggiungi:
# new_field = models.Field(required=False, display=True)
  1. Testa IMMEDIATAMENTE (nessun reinstall):
tower-cli instance list
  1. Verifica il campo:
python -c "
import sys; sys.path.insert(0, '.')
from tower_cli.resources.instance import Resource
print([f.name for f in Resource().fields])
"

Esempio: Aggiungere un Nuovo Comando

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

⚑ Tips & Tricks

Alias Permanente

Aggiungi al tuo ~/.bashrc:

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

Poi:

tower-dev  # Attiva environment
tower-cli --version

Auto-reload con Watch

# Terminal 1: modifica codice
vim tower_cli/resources/instance.py

# Terminal 2: test automatico
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"

πŸ“š Risorse

  • Documentazione: GATEWAY_SUPPORT.md
  • Changelog: CHANGELOG_3.3.10.md
  • Quick Start: README_IT.md
  • API Docs: docs/source/api_ref/

❓ FAQ Development

Q: Le modifiche non si vedono?

A: Assicurati di aver fatto source env-dev.sh nella sessione corrente.

Q: Errore "Module not found"?

A: Verifica il PYTHONPATH: echo $PYTHONPATH dovrebbe includere la directory corrente.

Q: Come faccio il reset?

A:

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

Q: Posso usare piΓΉ versioni?

A: Sì, ogni directory ha il suo environment. Fai source env-dev.sh nella directory che vuoi usare.

🎯 Checklist Pre-Test

  • source env-dev.sh eseguito
  • tower-cli --version mostra 3.3.10
  • Connessione Tower configurata (se necessario)
  • Modifiche al codice salvate
  • Test comando eseguito

Versione: 3.3.10 Per sviluppo senza installazione