When a VM starts it;s ports are set to active

Added network and volume details to streamlit
This commit is contained in:
2025-06-14 21:53:16 +09:30
parent 59965bdef5
commit 0bb177c1f4
4 changed files with 172 additions and 79 deletions
+91 -16
View File
@@ -285,10 +285,9 @@ def render_list():
else:
st.info("No VirtualMachine workloads found.")
def render_detail():
"""
Renders the details of a specific VM workload.
Renders the details of a specific VM workload, including attached volumes and network ports.
"""
VirtualMachine = st.session_state.client.get_virtual_machine(st.session_state.selected_resource['id'])
if not VirtualMachine:
@@ -311,15 +310,63 @@ def render_detail():
if VirtualMachine.get('updated_at'):
st.markdown(f"**Last Updated:** {format_timestamp(VirtualMachine['updated_at'])}")
st.markdown(f"**Status:** {VirtualMachine['status']}")
st.markdown(f"**Launch Parameters:** {VirtualMachine.get('launch_params', 'N/A')}")
# Edit VM Workload Form
st.markdown("**Launch Parameters:**")
launch_params = VirtualMachine.get("launch_params")
if not launch_params:
st.info("No launch parameters provided.")
else:
try:
decoded = json.loads(launch_params)
# Display known parameters
memory = decoded.pop("memory", None)
vcpu = decoded.pop("vcpu", None)
name = decoded.pop("name", None)
networks = decoded.pop("networks", [])
volumes = decoded.pop("volumes", [])
if name: st.markdown(f"- **Name:** `{name}`")
if memory: st.markdown(f"- **Memory:** `{memory} MB`")
if vcpu: st.markdown(f"- **vCPUs:** `{vcpu}`")
if networks:
st.markdown("- **Networks:**")
for net in networks:
st.markdown(f" - Network ID: `{net.get('id', 'unknown')}`")
else:
st.markdown("- **Networks:** None")
if volumes:
st.markdown("- **Volumes:**")
for vol in volumes:
st.markdown(f" - Volume: `{vol}`")
else:
st.markdown("- **Volumes:** None")
# Any other unknown keys
if decoded:
st.markdown("**Other Params:**")
for k, v in decoded.items():
st.markdown(f"- `{k}`: `{v}`")
except json.JSONDecodeError:
st.warning("Launch parameters are not valid JSON.")
# Edit VM Workload
with st.expander("Edit VM Workload"):
with st.form("edit_vm"):
new_status = st.selectbox("Status", ["running", "stopped", "pending", "failed-deleted", "pending-deleted", "pending-allocation", "failed-allocation", "pending-allocated"], index=["running", "stopped", "pending", "failed-deleted", "pending-deleted", "pending-allocation", "failed-allocation", "pending-allocated"].index(VirtualMachine['status']))
status_options = [
"running", "stopped", "pending",
"failed-deleted", "pending-deleted",
"pending-allocation", "failed-allocation",
"pending-allocated"
]
new_status = st.selectbox("Status", status_options, index=status_options.index(VirtualMachine['status']))
new_launch_params = st.text_input("Launch Parameters", value=VirtualMachine.get('launch_params', ''))
submit = st.form_submit_button("Update VM Workload")
if submit:
result = st.session_state.client.edit_virtual_machine(VirtualMachine['id'], {
"status": new_status,
@@ -327,24 +374,52 @@ def render_detail():
})
if result:
st.success("VM workload updated successfully!")
# Re-fetch the updated VM data to ensure consistency
updated_vm = st.session_state.client.get_virtual_machine(VirtualMachine['id'])
if updated_vm:
st.session_state.selected_resource = updated_vm
else: # Handle case where VM might not be found after update (unlikely but possible)
st.session_state.selected_resource = None
st.session_state.view_type = 'list' # Go back to list if VM disappears
st.session_state.selected_resource_type = 'virtual_machine' # Corrected resource type
st.session_state.selected_resource = updated_vm
else:
st.session_state.selected_resource = None
st.session_state.view_type = 'list'
st.session_state.selected_resource_type = 'virtual_machine'
st.rerun()
# Delete VM Workload Button (Now redundant with popover action, consider removing)
# Attached Volumes
st.subheader("Attached Volumes")
volumes = VirtualMachine.get("volumes", [])
if volumes:
for vol in volumes:
st.markdown(
f"- **ID:** `{vol['id']}` | **Name:** {vol.get('name', 'N/A')} | "
f"**Size:** {vol.get('size_gb', 'N/A')} GB | **Status:** {vol.get('status', 'N/A')}"
)
else:
st.info("No volumes attached to this VM.")
# Attached Network Ports
st.subheader("Network Ports")
ports = VirtualMachine.get("network_ports", [])
if ports:
for port in ports:
network = port.get("network", {})
st.markdown(f"""
- **Port ID:** `{port['id']}`
**IP:** {port.get('ip_address', 'N/A')}
**MAC:** {port.get('mac_address', 'N/A')}
**Type:** {port.get('port_type', 'N/A')}
**Network:** `{network.get('id', 'N/A')}` ({network.get('name', 'Unnamed')})
**CIDR:** {network.get('cidr', 'N/A') if network else 'N/A'}
""")
else:
st.info("No network ports attached to this VM.")
# Delete button
if st.button("Delete VM Workload"):
result = st.session_state.client.delete_virtual_machine(VirtualMachine['id'])
if result:
st.success("VM workload deleted successfully!")
st.session_state.selected_resource = None
st.session_state.view_type = 'list'
st.session_state.selected_resource_type = 'virtual_machine' # Corrected resource type
st.session_state.selected_resource_type = 'virtual_machine'
st.rerun()