Vm scheduling and deletion works..

This commit is contained in:
2025-03-07 20:26:24 +10:30
parent 83d7427ddc
commit 4088402a23
9 changed files with 309 additions and 627 deletions
+20 -18
View File
@@ -24,6 +24,8 @@ def render():
render_detail_view_network(resource)
elif resource_type == 'container':
render_detail_view_container(resource)
elif resource_type == 'VirtualMachine':
render_detail_view_virtual_machine(resource)
def render_detail_view_container(container):
@@ -207,39 +209,39 @@ def render_detail_view_region(region):
import streamlit as st
def render_detail_view_vm(vm):
def render_detail_view_virtual_machine(vm):
"""
Renders the details of a specific VM workload.
"""
vm = st.session_state.client.get_vm(vm['id'])
VirtualMachine = st.session_state.client.get_virtual_machine(vm['id'])
if not vm:
st.error("VM workload not found.")
return
st.title(f"VM Workload: {vm['vm_name']}")
print(vm)
st.title(f"VM Workload: {VirtualMachine['name']}")
st.header("VM Workload Details")
col1, col2 = st.columns(2)
with col1:
st.markdown(f"**ID:** `{vm['id']}`")
st.markdown(f"**Created:** {format_timestamp(vm.get('created_at', 'Unknown'))}")
st.markdown(f"**VDC ID:** {vm['vdc_id']}")
st.markdown(f"**Workload Host ID:** {vm.get('workload_host_id', 'N/A')}")
st.markdown(f"**ID:** `{VirtualMachine['id']}`")
st.markdown(f"**Created:** {format_timestamp(VirtualMachine.get('created_at', 'Unknown'))}")
st.markdown(f"**VDC ID:** {VirtualMachine['vdc_id']}")
st.markdown(f"**Workload Host ID:** {VirtualMachine.get('workload_host_id', 'N/A')}")
with col2:
if vm.get('updated_at'):
st.markdown(f"**Last Updated:** {format_timestamp(vm['updated_at'])}")
st.markdown(f"**Status:** {vm['status']}")
st.markdown(f"**Launch Parameters:** {vm.get('launch_params', 'N/A')}")
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
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(vm['status']))
new_launch_params = st.text_input("Launch Parameters", value=vm.get('launch_params', ''))
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']))
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_vm(vm['id'], {
result = st.session_state.client.edit_virtual_machine(VirtualMachine['id'], {
"status": new_status,
"launch_params": new_launch_params
})
@@ -247,15 +249,15 @@ def render_detail_view_vm(vm):
st.success("VM workload updated successfully!")
st.session_state.selected_resource = vm
st.session_state.view_type = 'detail'
st.session_state.selected_resource_type = 'vm'
st.session_state.selected_resource_type = 'VirtualMachine'
st.rerun()
# Delete VM Workload Button
if st.button("Delete VM Workload"):
result = st.session_state.client.delete_vm(vm['id'])
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 = 'vm'
st.session_state.selected_resource_type = 'VirtualMachine'
st.rerun()
+48 -2
View File
@@ -74,11 +74,57 @@ def render():
result = st.session_state.client.create_virtual_machine({
"vdc": vdc_id,
"virtual-machines": [{
"vm_name": vm_name,
"vm_config": vm_config
"virtual_machine_name": vm_name,
"virtual_machine_config": vm_config
}]
})
if result:
st.success("VM workload created successfully!")
st.session_state.volumes = [] # Reset volumes after creation
st.rerun()
# List Container Workloads
st.subheader("Existing Container Workloads")
VirtualMachines = st.session_state.client.get_virtual_machines()
if VirtualMachines:
# Filter VirtualMachines based on the selected VDC
if selected_vdc_name:
selected_vdc_id = vdc_options[selected_vdc_name]
filtered_VirtualMachines = [VirtualMachine for VirtualMachine in VirtualMachines if VirtualMachine['vdc_id'] == selected_vdc_id]
else:
filtered_VirtualMachines = VirtualMachines
for VirtualMachine in filtered_VirtualMachines:
with st.container():
col1, col2, col3 = st.columns([3, 1, 1])
with col1:
# Safely handle empty or None launch_params
launch_params = VirtualMachine.get('launch_params') # Use .get() to avoid KeyError if 'launch_params' doesn't exist
if launch_params: # Check if launch_params is not empty or None
try:
VirtualMachine_name = json.loads(launch_params).get('docker_image') # Use .get() to avoid KeyError if 'docker_image' doesn't exist
except json.JSONDecodeError:
print("LP not vald json")
# Handle the case where launch_params is not valid JSON
VirtualMachine_name = None
else:
print("lp empty")
# Handle the case where launch_params is empty or None
VirtualMachine_name = None
st.markdown(f"### {VirtualMachine['name']}")
st.text(f"Status: {VirtualMachine['status']}")
st.text(f"VDC ID: {VirtualMachine['vdc_id']}")
st.text(f"Image: {VirtualMachine_name}")
with col2:
st.text(f"ID: {VirtualMachine['id']}")
with col3:
if st.button("View Details", key=f"view_{VirtualMachine['id']}"):
print("Button is pressed")
st.session_state.selected_resource = VirtualMachine
st.session_state.view_type = 'detail'
st.session_state.selected_resource_type = 'VirtualMachine'
st.rerun()
else:
st.info("No VirtualMachine workloads found.")