Files
DevOpsLab/scripts/delete_hosts.py
Сергей Антропов 4ed9c2e0eb
Some checks failed
Ansible Testing / lint (push) Has been cancelled
Ansible Testing / test (default) (push) Has been cancelled
Ansible Testing / test (minimal) (push) Has been cancelled
Ansible Testing / test (performance) (push) Has been cancelled
Ansible Testing / deploy-check (push) Has been cancelled
feat: добавлена поддержка создания и удаления контейнеров из пресета
- Добавлено создание контейнеров из секции hosts в create_k8s_cluster.py
- Добавлено удаление контейнеров в команде make k8s destroy
- Создан скрипт scripts/delete_hosts.py для удаления контейнеров
- Контейнеры автоматически создаются в Docker сети из пресета
- Контейнеры удаляются вместе с Kind кластером при make k8s destroy
2025-10-26 08:23:43 +03:00

45 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Скрипт для удаления контейнеров из секции hosts пресета
Автор: Сергей Антропов
Сайт: https://devops.org.ru
"""
import sys
import yaml
import subprocess
def main():
if len(sys.argv) < 2:
print("Usage: delete_hosts.py <preset_file>")
sys.exit(1)
preset_file = sys.argv[1]
print(f"📋 Читаю пресет: {preset_file}")
with open(preset_file, 'r') as f:
preset = yaml.safe_load(f)
hosts = preset.get('hosts', [])
if not hosts:
print("⚠️ В пресете нет контейнеров для удаления")
sys.exit(0)
print(f"🗑️ Удаление контейнеров (всего: {len(hosts)})")
for host in hosts:
host_name = host['name']
# Проверяем существование контейнера
result = subprocess.run(f"docker ps -a --format '{{{{.Names}}}}' | grep -x {host_name}",
shell=True, capture_output=True, text=True)
if result.stdout.strip():
print(f"🗑️ Удаление контейнера: {host_name}")
subprocess.run(f"docker rm -f {host_name}", shell=True, capture_output=True, text=True)
print(f"✅ Контейнер '{host_name}' удален")
else:
print(f"⚠️ Контейнер '{host_name}' не найден")
print("✅ Удаление завершено")
if __name__ == "__main__":
main()