imporved the DNS capabilities
Linked the logs and console to streamlit
This commit is contained in:
@@ -334,6 +334,7 @@ def add_container_workload():
|
||||
db.session.add(new_cloudflare_tunnel)
|
||||
db.session.flush()
|
||||
|
||||
logger.debug(dns_records_to_create)
|
||||
# Create DNS records for each hostname
|
||||
for dns_record in dns_records_to_create:
|
||||
# Create DNS record in Cloudflare
|
||||
@@ -345,22 +346,33 @@ def add_container_workload():
|
||||
# The commented code above is not required becuase the DNS records are created with the tunnel, so we need to query
|
||||
# the setup_tunnel reponse for the DNs info...maybe?
|
||||
# Create DNS record in our database
|
||||
|
||||
for _createdDNSRecord in cloudflare_response['dns_records_created']:
|
||||
logger.debug(_createdDNSRecord)
|
||||
if _createdDNSRecord['hostname']==dns_record['hostname']:
|
||||
logger.debug(f"Match {_createdDNSRecord['hostname']}")
|
||||
dns_record_id=_createdDNSRecord['response']['id']
|
||||
|
||||
new_dns_record = CloudflareDNSRecord(
|
||||
name="dns",
|
||||
zone_id=zone_id,
|
||||
dns_record_id="11", #dns_response['id'],
|
||||
dns_record_id=dns_record_id,
|
||||
hostname=dns_record['hostname'],
|
||||
record_type="CNAME",
|
||||
content=f"{cloudflare_response['tunnel_id']}.cfargotunnel.com",
|
||||
tunnel_id=new_cloudflare_tunnel.id
|
||||
)
|
||||
db.session.add(new_dns_record)
|
||||
|
||||
db.session.flush()
|
||||
logger.debug(f"Created DNS Record - {hostname}")
|
||||
# Link the port forwarding to the DNS record
|
||||
port_forward = PortForwarding.query.get(dns_record['forward_id'])
|
||||
port_forward = PortForwarding.query.filter_by(id=dns_record['forward_id']).first()
|
||||
|
||||
if port_forward:
|
||||
logger.debug("Found the associated PortForwarding in the DB")
|
||||
port_forward.dns_record_id = new_dns_record.id
|
||||
db.session.add(port_forward)
|
||||
logger.debug(f"Linked DNS record to PortForwarding {dns_record['forward_id']}")
|
||||
|
||||
# Create cloudflared sidecar container
|
||||
sidecar_container_name = f"cloudflared-sidecar-{new_pod.id}"
|
||||
@@ -611,7 +623,7 @@ def update_container_workload(system_container_id):
|
||||
zone_id = "e2cafdd8929869d5db885d8824f514b5"
|
||||
logger.info("Deleting Cloudflare Tunnel")
|
||||
cloudflare_manager = CloudflareTunnelManager(api_token, account_id, zone_id, logger)
|
||||
cloudflare_manager.delete_tunnel(tunnel.tunnel_id)
|
||||
cloudflare_manager.cleanup_tunnel(tunnel.name,delete_tunnel=True)
|
||||
|
||||
tunnel.soft_delete()
|
||||
db.session.add(tunnel)
|
||||
@@ -688,7 +700,9 @@ def get_pods():
|
||||
"internal_port": pf.internal_port,
|
||||
"external_port": pf.external_port,
|
||||
"protocol": pf.protocol,
|
||||
"ip_address": pf.ip_address
|
||||
"ip_address": pf.ip_address,
|
||||
"dns_record_id": pf.dns_record_id,
|
||||
"dns_record_hostname": pf.dns_record.hostname if pf.dns_record else None
|
||||
}
|
||||
for pf in pod.port_forwardings
|
||||
],
|
||||
|
||||
@@ -43,12 +43,18 @@ def regions():
|
||||
|
||||
@ui_bp.route("/container_logs")
|
||||
def container_logs():
|
||||
containers = Workload.query.filter(or_(Workload.workload_type == "Container", Workload.workload_type == "NSController"), Workload.deleted==False).all()
|
||||
containers = Workload.query.filter(or_(Workload.workload_type == "Container", Workload.workload_type == "NSController"), Workload._status=="running").all()
|
||||
return render_template("container_logs.html", containers=containers)
|
||||
|
||||
|
||||
@ui_bp.route("/vnc/<vm_id>")
|
||||
def console(vm_id):
|
||||
@ui_bp.route("/container_logs/<container_id>")
|
||||
def container_logs_specific(container_id):
|
||||
containers = Workload.query.filter(or_(Workload.workload_type == "Container", Workload.workload_type == "NSController"), Workload._status=="running", Workload.id==container_id).all()
|
||||
return render_template("container_logs.html", containers=containers)
|
||||
|
||||
|
||||
@ui_bp.route("/vnc.html")
|
||||
def console():
|
||||
"""Render the noVNC client page for a specific VM"""
|
||||
# Fetch the WebSocket URL from the API
|
||||
API_SERVER_URL = "http://localhost:5000" # API to get VNC session token
|
||||
|
||||
@@ -216,8 +216,8 @@ def render_list():
|
||||
with cols[2]:
|
||||
st.text(dns_status)
|
||||
|
||||
if pf.get('dns_hostname'):
|
||||
st.page_link(f"http://{pf['dns_hostname']}", label=f"http://{pf['dns_hostname']}")
|
||||
if pf.get('dns_record_hostname'):
|
||||
st.page_link(f"http://{pf['dns_record_hostname']}", label=f"http://{pf['dns_record_hostname']}")
|
||||
else:
|
||||
st.page_link(f"http://{pf['ip_address']}:{pf['external_port']}", label=f"http://{pf['ip_address']}:{pf['external_port']}")
|
||||
|
||||
@@ -240,6 +240,11 @@ def render_list():
|
||||
st.session_state.view_type = 'detail'
|
||||
st.session_state.selected_resource_type = 'container'
|
||||
st.rerun()
|
||||
st.page_link(
|
||||
f"http://127.0.0.5:5000/ui/container_logs/{container['container_id']}",
|
||||
label="Console & Logs",
|
||||
icon="🖥️"
|
||||
)
|
||||
st.markdown("---")
|
||||
|
||||
# Delete pod button
|
||||
|
||||
Reference in New Issue
Block a user