Files
3cloud-backend/streamlit_server/views/images.py
T

83 lines
3.3 KiB
Python

import streamlit as st
import pandas as pd
from streamlit_server.utils.helpers import format_timestamp
def render_list():
st.header("Image Management")
# Create Image Form
with st.expander("Create New Image"):
with st.form("create_image"):
name = st.text_input("Image Name")
location = st.text_input("Image Location (e.g., /images/image.img)")
location_type = st.selectbox("Location Type", ["Local", "Remote"])
size = st.number_input("Size (GB)", min_value=0.1, step=0.1)
os_family = st.text_input("OS Family (e.g., Linux)")
os_version = st.text_input("OS Version (e.g., 20.04)")
checksum = st.text_input("Checksum (optional)")
submit = st.form_submit_button("Create Image")
payload = {
"name": name,
"location": location,
"location_type": location_type,
"size": size,
"os_family": os_family,
"os_version": os_version,
"checksum": checksum
}
if submit and name and location:
result = st.session_state.client.create_image(payload)
if result:
st.success(f"Image '{name}' created successfully!")
# List Images
st.subheader("Existing Images")
images = st.session_state.client.get_images()
if images:
for image in images:
with st.container():
col1, col2, col3 = st.columns([3, 1, 1])
with col1:
st.markdown(f"### {image['name']}")
st.text(f"Location: {image['location']}")
st.text(f"Size: {image['size']} GB")
with col2:
st.text(f"ID: {image['id'][:8]}...")
with col3:
if st.button("View Details", key=f"view_{image['id']}"):
st.session_state.selected_resource = image
st.session_state.view_type = 'detail'
st.session_state.selected_resource_type = 'image'
st.rerun() # Force Streamlit to rerun the script
def render_detail():
image = st.session_state.client.get_image(st.session_state.selected_resource['id'])
st.title(f"Image: {image['name']}")
if st.button("Back to list view"):
st.session_state.view_type = 'list'
st.rerun()
st.header("Image Details")
col1, col2 = st.columns(2)
with col1:
st.markdown(f"**ID:** `{image['id']}`")
st.markdown(f"**Created:** {format_timestamp(image['created_at'])}")
st.markdown(f"**Location:** `{image['location']}`")
st.markdown(f"**Location Type:** `{image['location_type']}`")
with col2:
st.markdown(f"**Size:** `{image['size']} GB`")
st.markdown(f"**OS Family:** `{image['os_family']}`")
st.markdown(f"**OS Version:** `{image['os_version']}`")
if image.get('checksum'):
st.markdown(f"**Checksum:** `{image['checksum']}`")
if image.get('updated_at'):
st.markdown(f"**Last Updated:** {format_timestamp(image['updated_at'])}")
if st.session_state.view_type == 'detail' and st.session_state.selected_resource_type == 'image':
render_detail()
else:
render_list()