ObjPlatform consolidates all platform, virtualization, and system detection queries into a single module. All methods are static and require no instantiation, providing a clean API for environment detection across the Axion framework.
Module: factory.core/ObjPlatform.py
Test file: None (integration tested)
CLI: Includes typer CLI for platform checks
This module enables developers to:
Multi-method detection supporting:
KUBERNETES_SERVICE_HOSTResults cached where appropriate to avoid repeated system calls.
is_aws() -> boolCheck if running on an AWS EC2 instance.
Detection Methods:
Example:
if ObjPlatform.is_aws():
# Use AWS-specific configuration
region = get_aws_region()
is_kvm() -> boolCheck if running on KVM/Proxmox virtualization.
Detection Method: systemd-detect-virt
is_docker() -> intCheck if running in a Docker container.
Returns: 0 if not Docker, 1 if Docker
Caching: Result cached after first call
Detection Method: DOCKER_AXION environment variable
Example:
if ObjPlatform.is_docker():
# Docker-specific paths
config_path = "/config"
else:
# Host paths
config_path = "/home/user/.config"
is_kubernetes() -> intCheck if running inside a Kubernetes pod.
Returns: 0 if not in a pod, 1 if inside a k8s pod
Caching: Result cached after first call
Detection Method: both signals must be present —
/var/run/secrets/kubernetes.io/serviceaccount/tokenKUBERNETES_SERVICE_HOST environment variableRequiring both avoids false positives from stale volume mounts or hosts that set the env var manually.
Example:
if ObjPlatform.is_kubernetes():
# Read downward-API namespace
with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f:
namespace = f.read().strip()
is_pytest() -> boolCheck if running under pytest.
Detection Method: 'pytest' in sys.modules
get_virtualization_environment() -> strDetect the virtualization environment comprehensively.
Returns: One of: "kubernetes", "lxc", "kvm", "vmware", "aws", "wsl", "virtualbox", "physical", "unknown"
Detection Order:
Example:
env = ObjPlatform.get_virtualization_environment()
if env == "aws":
# AWS-specific initialization
setup_aws_resources()
elif env == "physical":
# Bare metal optimizations
enable_hardware_acceleration()
get_ip_address() -> strGet the local IP address.
Method: UDP socket to 8.8.8.8 (no data sent)
Caching: Result cached after first call
Fallback: Returns "127.0.0.1" on failure
Example:
ip = ObjPlatform.get_ip_address()
print(f"Local IP: {ip}")
get_mac_address(interface: str = 'ens18') -> strGet the MAC address of a network interface.
Parameters:
interface: Network interface name (default: 'ens18')Method: IOCTL to read hardware address
Platform: Linux only
Returns: MAC address in colon-separated hex format
Example:
mac = ObjPlatform.get_mac_address('eth0')
print(f"MAC: {mac}")
get_hostname() -> strGet the system hostname.
Returns: platform.node()
get_parent_name() -> strGet the name of the parent process.
Method: Uses psutil to inspect parent PID's command line
Returns: Empty string on failure
Example:
parent = ObjPlatform.get_parent_name()
if 'supervisor' in parent:
# Running under supervisor
...
is_in_multiplexer() -> boolCheck if running inside tmux, screen, or byobu.
Detection: Inspects TMUX and STY environment variables
Example:
if ObjPlatform.is_in_multiplexer():
# Terminal multiplexer features available
use_terminal_colors()
get_multiplexer_info() -> dict[str, str | bool]Gather multiplexer session details.
Returns: Dictionary with keys:
is_multiplexer: boolbackend: "tmux", "screen", or "None"session_info: Session identifier or "N/A"byobu_backend: Optional byobu backendExample:
info = ObjPlatform.get_multiplexer_info()
if info['is_multiplexer']:
print(f"Running in {info['backend']}")
print(f"Session: {info['session_info']}")
has_x_display() -> boolCheck if an X11 display server is available.
Method: Runs xset -q silently
Returns: True only when command succeeds
checkDisplay platform detection results.
python factory.core/ObjPlatform.py check
Output:
Docker: 0
K8s pod: 0
pytest: False
AWS: True
KVM: False
X11: True
Environment: aws
Hostname: web-server-01
IP: 10.0.1.5
Multiplexer: True
MAC: 00:0c:29:3a:5f:2b
from ObjPlatform import ObjPlatform
def get_data_path():
if ObjPlatform.is_docker():
return "/data"
elif ObjPlatform.is_aws():
return "/mnt/efs/data"
else:
return "/home/user/data"
from ObjPlatform import ObjPlatform
def initialize_app():
env = ObjPlatform.get_virtualization_environment()
if env == "aws":
setup_aws_logging()
enable_cloudwatch()
elif env == "docker":
setup_container_logging()
elif env == "physical":
setup_syslog()
enable_hardware_monitoring()
from ObjPlatform import ObjPlatform
def show_system_info():
print(f"Hostname: {ObjPlatform.get_hostname()}")
print(f"IP Address: {ObjPlatform.get_ip_address()}")
try:
mac = ObjPlatform.get_mac_address()
print(f"MAC Address: {mac}")
except Exception:
print("MAC Address: unavailable")
print(f"Environment: {ObjPlatform.get_virtualization_environment()}")
from ObjPlatform import ObjPlatform
# Enable GUI features only if X11 is available
if ObjPlatform.has_x_display():
launch_gui_dashboard()
else:
launch_terminal_dashboard()
# Adjust logging based on multiplexer
if ObjPlatform.is_in_multiplexer():
enable_color_logging()
else:
enable_plain_logging()
Only checks DOCKER_AXION environment variable. Does not use cgroup or other methods to avoid false positives.
Uses multiple signals:
Detects major vendors: Dell, HP, Lenovo, Supermicro, Intel
platform - System/platform identificationsocket - Network operationsfcntl / struct - MAC address IOCTLsubprocess - systemd-detect-virt, xsetos - Environment variablespsutil - Parent process detection (optional)typer - CLI interfaceObjPreflight.py - Uses ObjPlatform for environment checksConfigIni.py - May use for platform-specific configurationObjData.py - May use for platform-aware database paths