change description formatting. include full vm name in HYPERVISORS

This commit is contained in:
Josh Patterson
2025-02-26 14:28:31 -05:00
parent d6f527881a
commit 1a9d5f151f
3 changed files with 20 additions and 49 deletions

View File

@@ -79,7 +79,7 @@
} }
}) %} }) %}
{% endif %} {% endif %}
{% do vms.update({hostname: vm_data}) %} {% do vms.update({hostname ~ '_' ~ role: vm_data}) %}
{% else %} {% else %}
{% do salt.log.info('salt/hypervisor/map.jinja: Config file empty: ' ~ vm_file) %} {% do salt.log.info('salt/hypervisor/map.jinja: Config file empty: ' ~ vm_file) %}
{% endif %} {% endif %}
@@ -87,8 +87,8 @@
{# Find and add destroyed VMs from status files #} {# Find and add destroyed VMs from status files #}
{% set processed_vms = [] %} {% set processed_vms = [] %}
{% for vm_name, vm_data in vms.items() %} {% for vm_full_name, vm_data in vms.items() %}
{% do processed_vms.append(vm_name) %} {% do processed_vms.append(vm_full_name) %}
{% endfor %} {% endfor %}
{# Find all status files for this hypervisor #} {# Find all status files for this hypervisor #}
@@ -117,7 +117,7 @@
{% set hostname = vm_name.split('_')[0] %} {% set hostname = vm_name.split('_')[0] %}
{# Skip already processed VMs #} {# Skip already processed VMs #}
{% if hostname in processed_vms %} {% if vm_name in processed_vms %}
{% continue %} {% continue %}
{% endif %} {% endif %}
@@ -127,11 +127,11 @@
{# Only process files with "Destroyed Instance" status #} {# Only process files with "Destroyed Instance" status #}
{% if status_data and status_data.status == 'Destroyed Instance' %} {% if status_data and status_data.status == 'Destroyed Instance' %}
{% do salt.log.info('salt/hypervisor/map.jinja: Found VM with Destroyed Instance status: ' ~ hostname) %} {% do salt.log.info('salt/hypervisor/map.jinja: Found VM with Destroyed Instance status: ' ~ vm_name) %}
{# Add to vms with minimal config #} {# Add to vms with minimal config #}
{% do vms.update({ {% do vms.update({
hostname: { vm_name: {
'status': status_data, 'status': status_data,
'config': {} 'config': {}
} }

View File

@@ -390,8 +390,8 @@ def check_hardware_availability(hypervisor_path: str, vm_name: str, requested_hw
continue continue
vm_config = read_json_file(vm_file) vm_config = read_json_file(vm_file)
if 'config' not in vm_config or vm_config.get('status') != 'running': if 'config' not in vm_config:
log.debug("Skipping VM %s (not running)", basename) log.debug("Skipping VM %s (no config found)", basename)
continue continue
config = vm_config['config'] config = vm_config['config']
@@ -469,9 +469,7 @@ def create_vm_tracking_file(hypervisor_path: str, vm_name: str, config: dict) ->
set_socore_ownership(os.path.dirname(file_path)) set_socore_ownership(os.path.dirname(file_path))
data = { data = {
'config': config, 'config': config
'status': 'creating',
'timestamp': datetime.now().isoformat()
} }
# Write file and set ownership # Write file and set ownership
write_json_file(file_path, data) write_json_file(file_path, data)
@@ -648,11 +646,9 @@ def process_vm_creation(hypervisor_path: str, vm_config: dict) -> None:
# Execute command # Execute command
result = subprocess.run(cmd, capture_output=True, text=True, check=True) result = subprocess.run(cmd, capture_output=True, text=True, check=True)
# Update tracking file status with timestamp # Update tracking file if needed
tracking_file = os.path.join(hypervisor_path, vm_name) tracking_file = os.path.join(hypervisor_path, vm_name)
data = read_json_file(tracking_file) data = read_json_file(tracking_file)
data['status'] = 'running'
data['timestamp'] = datetime.now().isoformat()
write_json_file(tracking_file, data) write_json_file(tracking_file, data)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:

View File

@@ -18,55 +18,30 @@
{%- set TEMPLATE = ANNOTATION.hypervisor.hosts.pop('defaultHost') -%} {%- set TEMPLATE = ANNOTATION.hypervisor.hosts.pop('defaultHost') -%}
{%- macro update_description(description, cpu_free, mem_free, disk_free, copper_free, sfp_free, vm_list, cpu_total, mem_total, disk_total, copper_total, sfp_total) -%} {%- macro update_description(description, cpu_free, mem_free, disk_free, copper_free, sfp_free, vm_list, cpu_total, mem_total, disk_total, copper_total, sfp_total) -%}
# Hypervisor Configuration: {{ description }} #### Resource Summary
## Resource Summary
| | CPU Cores | Memory (GB) | Disk | Copper | SFP | | | CPU Cores | Memory (GB) | Disk | Copper | SFP |
|-----------|-----------|-------------|-------------|-------------|-------------| |-----------|-----------|-------------|-------------|-------------|-------------|
| Available | {{ cpu_free }} | {{ mem_free }} | {{ disk_free | replace('\n', ',') if disk_free else 'None' }} | {{ copper_free | replace('\n', ',') if copper_free else 'None' }} | {{ sfp_free | replace('\n', ',') if sfp_free else 'None' }} | | Available | {{ cpu_free }} | {{ mem_free }} | {{ disk_free | replace('\n', ',') if disk_free else 'None' }} | {{ copper_free | replace('\n', ',') if copper_free else 'None' }} | {{ sfp_free | replace('\n', ',') if sfp_free else 'None' }} |
| Total | {{ cpu_total }} | {{ mem_total }} | {{ disk_total | replace('\n', ',') }} | {{ copper_total | replace('\n', ',') }} | {{ sfp_total | replace('\n', ',') }} | | Total | {{ cpu_total }} | {{ mem_total }} | {{ disk_total | replace('\n', ',') }} | {{ copper_total | replace('\n', ',') }} | {{ sfp_total | replace('\n', ',') }} |
{%- if vm_list %} {%- if vm_list %}
## Virtual Machines #### Virtual Machines
VMs can have the following status values: {% for step in PROCESS_STEPS %}{{ step }}{% if not loop.last %}, {% endif %}{% endfor %}. The "Last Updated" timestamp shows when the VM status was last changed. After reaching "Highstate Triggered" status, additional highstate runs will not update the timestamp. Only changing to "Destroyed Instance" status will update the timestamp again. Status values: {% for step in PROCESS_STEPS %}{{ step }}{% if not loop.last %}, {% endif %}{% endfor %}. "Last Updated" shows when status changed. After "Highstate Triggered", only "Destroyed Instance" updates the timestamp.
| Name | Status | CPU Cores | Memory (GB)| Disk | Copper | SFP | Last Updated | | Name | Status | CPU Cores | Memory (GB)| Disk | Copper | SFP | Last Updated |
|--------------------|--------------------|-----------|------------|------|--------|------|---------------------| |--------------------|--------------------|-----------|------------|------|--------|------|---------------------|
{%- for hostname, vm_data in vm_list.items() %} {%- for hostname, vm_data in vm_list.items() %}
{%- set vm_status = vm_data.get('status', {}).get('status', 'Unknown') %} {%- set vm_status = vm_data.get('status', {}).get('status', 'Unknown') %}
{%- set is_destroyed = vm_status == 'Destroyed Instance' %} {%- set is_destroyed = vm_status == 'Destroyed Instance' %}
{%- set vm_role = vm_data.get('config', {}).get('role', 'unknown') %} {%- if is_destroyed %}
{%- set name = hostname ~ (('_' ~ vm_role) if not is_destroyed and vm_role != 'unknown' else '') %} | {{ hostname }} | {{ vm_status }} | - | - | - | - | - | {{ vm_data.get('status', {}).get('timestamp', 'Never') | replace('T', ' ') | regex_replace('\\.[0-9]+', '') }} |
| {{ name }} | {{ vm_status }} | {%- else %}
{%- if is_destroyed -%} | {{ hostname }} | {{ vm_status }} | {{ vm_data.get('config', {}).get('cpu', 'N/A') }} | {{ vm_data.get('config', {}).get('memory', 'N/A') }} | {{ vm_data.get('config', {}).get('disk', '-') | replace('\n', ',') if vm_data.get('config', {}).get('disk') else '-' }} | {{ vm_data.get('config', {}).get('copper', '-') | replace('\n', ',') if vm_data.get('config', {}).get('copper') else '-' }} | {{ vm_data.get('config', {}).get('sfp', '-') | replace('\n', ',') if vm_data.get('config', {}).get('sfp') else '-' }} | {{ vm_data.get('status', {}).get('timestamp', 'Never') | replace('T', ' ') | regex_replace('\\.[0-9]+', '') }} |
- {%- endif %}
{%- else -%}
{{ vm_data.get('config', {}).get('cpu', 'N/A') }}
{%- endif %} |
{%- if is_destroyed -%}
-
{%- else -%}
{{ vm_data.get('config', {}).get('memory', 'N/A') }}
{%- endif %} |
{%- if is_destroyed -%}
-
{%- else -%}
{{ vm_data.get('config', {}).get('disk', '-') | replace('\n', ',') if vm_data.get('config', {}).get('disk') else '-' }}
{%- endif %} |
{%- if is_destroyed -%}
-
{%- else -%}
{{ vm_data.get('config', {}).get('copper', '-') | replace('\n', ',') if vm_data.get('config', {}).get('copper') else '-' }}
{%- endif %} |
{%- if is_destroyed -%}
-
{%- else -%}
{{ vm_data.get('config', {}).get('sfp', '-') | replace('\n', ',') if vm_data.get('config', {}).get('sfp') else '-' }}
{%- endif %} | {{ vm_data.get('status', {}).get('timestamp', 'Never') | replace('T', ' ') | regex_replace('\\.[0-9]+', '') }} |
{%- endfor %} {%- endfor %}
{%- else %} {%- else %}
## Virtual Machines #### Virtual Machines
VMs can have the following status values: {% for step in PROCESS_STEPS %}{{ step }}{% if not loop.last %}, {% endif %}{% endfor %}. The "Last Updated" timestamp shows when the VM status was last changed. After reaching "Highstate Triggered" status, additional highstate runs will not update the timestamp. Only changing to "Destroyed Instance" status will update the timestamp again. Status values: {% for step in PROCESS_STEPS %}{{ step }}{% if not loop.last %}, {% endif %}{% endfor %}. "Last Updated" shows when status changed. After "Highstate Triggered", only "Destroyed Instance" updates the timestamp.
No Virtual Machines Found No Virtual Machines Found
{%- endif %} {%- endif %}