Files
wif2ansible/wif2ansible/models.py
Kris Forbes fc1c4bfaa8
All checks were successful
Build and Release / Build Windows Exe (push) Successful in 10s
Support multiple IPs per server and robust mapping
2026-02-06 16:19:05 -05:00

52 lines
1.7 KiB
Python

from dataclasses import dataclass, field
from typing import List, Dict, Optional, Any
@dataclass
class Server:
reference: str
hostname: str # This might be same as reference
# Support multiple IPs per field (lists)
ip_addresses: List[str] = field(default_factory=list)
production_ips: List[str] = field(default_factory=list)
# helper for compatibility/primary IP
@property
def primary_ip(self) -> Optional[str]:
return self.ip_addresses[0] if self.ip_addresses else None
@property
def primary_prod_ip(self) -> Optional[str]:
return self.production_ips[0] if self.production_ips else None
platform: str = 'unknown' # e.g. 'Windows', 'Linux'
def get_ansible_vars(self) -> Dict[str, Any]:
"""Returns ansible variables based on platform."""
vars = {}
# Basic mapping - can be expanded
p = self.platform.lower()
if 'win' in p:
vars['ansible_connection'] = 'winrm'
vars['ansible_winrm_transport'] = 'ntlm'
vars['ansible_winrm_port'] = 5985
vars['ansible_winrm_server_cert_validation'] = 'ignore' # Common default, maybe safer to omit
elif 'lin' in p or 'rhel' in p or 'ubuntu' in p:
# Default ssh is usually fine, but being explicit doesn't hurt
pass
if self.primary_ip:
vars['ansible_host'] = self.primary_ip
return vars
@dataclass
class Flow:
flow_id: str
source_ip: str
destination_ip: str
ports: List[int]
protocol: str = 'tcp'
def __hash__(self):
return hash((self.flow_id, self.source_ip, self.destination_ip, tuple(sorted(self.ports)), self.protocol))