Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ from jsonschema import validate, ValidationError
|
|
4 |
import re
|
5 |
import networkx as nx
|
6 |
import matplotlib.pyplot as plt
|
|
|
7 |
|
8 |
# Mock existing resources (customizable)
|
9 |
existing_resources = {
|
@@ -211,69 +212,87 @@ def simulate_deployment(arm_template):
|
|
211 |
|
212 |
# Streamlit UI
|
213 |
st.title("Comprehensive ARM Template Simulator")
|
214 |
-
st.subheader("
|
|
|
|
|
|
|
215 |
|
216 |
# Input box for ARM template
|
217 |
-
template_input = st.text_area("
|
|
|
|
|
|
|
|
|
218 |
|
219 |
# Button to simulate the evaluation
|
220 |
if st.button("Simulate Template"):
|
221 |
-
if
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
st.write("No new resources will be created.")
|
233 |
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
|
|
239 |
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
st.write("### Detailed Resource Information:")
|
247 |
-
for resource in resource_details:
|
248 |
-
st.write(f"**Name:** {resource['name']}")
|
249 |
-
st.write(f"**Type:** {resource['type']}")
|
250 |
-
st.write(f"**Location:** {resource['location']}")
|
251 |
-
st.write("**Properties:**")
|
252 |
-
st.json(resource['properties'])
|
253 |
-
st.write("---")
|
254 |
-
|
255 |
-
st.write(f"### Estimated Monthly Cost: ${estimated_cost}")
|
256 |
-
|
257 |
-
st.write("### Resource Dependency Graph:")
|
258 |
-
if dependency_graph:
|
259 |
-
fig = plot_dependency_graph(dependency_graph)
|
260 |
-
st.pyplot(fig)
|
261 |
-
else:
|
262 |
-
st.write("No dependencies found between resources.")
|
263 |
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
|
|
|
|
|
|
|
|
276 |
else:
|
277 |
-
st.write("No
|
278 |
else:
|
279 |
-
st.
|
|
|
4 |
import re
|
5 |
import networkx as nx
|
6 |
import matplotlib.pyplot as plt
|
7 |
+
import io
|
8 |
|
9 |
# Mock existing resources (customizable)
|
10 |
existing_resources = {
|
|
|
212 |
|
213 |
# Streamlit UI
|
214 |
st.title("Comprehensive ARM Template Simulator")
|
215 |
+
st.subheader("Upload your ARM template or paste it below to simulate its deployment.")
|
216 |
+
|
217 |
+
# File uploader
|
218 |
+
uploaded_file = st.file_uploader("Choose an ARM template file", type=["json"])
|
219 |
|
220 |
# Input box for ARM template
|
221 |
+
template_input = st.text_area("Or paste ARM Template JSON here:", height=300)
|
222 |
+
|
223 |
+
# Function to read file contents
|
224 |
+
def read_file_contents(file):
|
225 |
+
return file.getvalue().decode("utf-8")
|
226 |
|
227 |
# Button to simulate the evaluation
|
228 |
if st.button("Simulate Template"):
|
229 |
+
# Check if a file was uploaded
|
230 |
+
if uploaded_file is not None:
|
231 |
+
# Read the contents of the uploaded file
|
232 |
+
file_contents = read_file_contents(uploaded_file)
|
233 |
+
# Use the file contents for simulation
|
234 |
+
template_to_simulate = file_contents
|
235 |
+
elif template_input:
|
236 |
+
# Use the pasted input for simulation
|
237 |
+
template_to_simulate = template_input
|
238 |
+
else:
|
239 |
+
st.error("Please either upload a file or paste an ARM template to simulate.")
|
240 |
+
st.stop()
|
241 |
|
242 |
+
# Proceed with simulation
|
243 |
+
resources_to_create, resources_to_update, resources_to_delete, resource_details, estimated_cost, dependency_graph, lint_results, system_diagram, message = simulate_deployment(template_to_simulate)
|
244 |
+
|
245 |
+
st.subheader("Simulation Results:")
|
246 |
+
st.write(message)
|
|
|
247 |
|
248 |
+
if resources_to_create or resources_to_update or resources_to_delete:
|
249 |
+
st.write("### Resources to be Created:")
|
250 |
+
if resources_to_create:
|
251 |
+
st.write(resources_to_create)
|
252 |
+
else:
|
253 |
+
st.write("No new resources will be created.")
|
254 |
|
255 |
+
st.write("### Resources to be Updated:")
|
256 |
+
if resources_to_update:
|
257 |
+
st.write(resources_to_update)
|
258 |
+
else:
|
259 |
+
st.write("No resources will be updated.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
|
261 |
+
st.write("### Resources to be Deleted:")
|
262 |
+
if resources_to_delete:
|
263 |
+
st.write(resources_to_delete)
|
264 |
+
else:
|
265 |
+
st.write("No resources will be deleted.")
|
266 |
+
|
267 |
+
st.write("### Detailed Resource Information:")
|
268 |
+
for resource in resource_details:
|
269 |
+
st.write(f"**Name:** {resource['name']}")
|
270 |
+
st.write(f"**Type:** {resource['type']}")
|
271 |
+
st.write(f"**Location:** {resource['location']}")
|
272 |
+
st.write("**Properties:**")
|
273 |
+
st.json(resource['properties'])
|
274 |
+
st.write("---")
|
275 |
+
|
276 |
+
st.write(f"### Estimated Monthly Cost: ${estimated_cost}")
|
277 |
+
|
278 |
+
st.write("### Resource Dependency Graph:")
|
279 |
+
if dependency_graph:
|
280 |
+
fig = plot_dependency_graph(dependency_graph)
|
281 |
+
st.pyplot(fig)
|
282 |
+
else:
|
283 |
+
st.write("No dependencies found between resources.")
|
284 |
|
285 |
+
st.write("### System Diagram:")
|
286 |
+
if system_diagram:
|
287 |
+
st.mermaid(system_diagram)
|
288 |
+
else:
|
289 |
+
st.write("Unable to generate system diagram.")
|
290 |
+
|
291 |
+
st.write("### Template Lint Results:")
|
292 |
+
if lint_results:
|
293 |
+
for result in lint_results:
|
294 |
+
st.write(result)
|
295 |
else:
|
296 |
+
st.write("No linting issues found.")
|
297 |
else:
|
298 |
+
st.write("No changes detected in the simulation.")
|