eaglelandsonce commited on
Commit
c94cafc
·
verified ·
1 Parent(s): 33960b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -54
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("Paste your ARM template below to simulate its deployment.")
 
 
 
215
 
216
  # Input box for ARM template
217
- template_input = st.text_area("Paste ARM Template JSON here:", height=300)
 
 
 
 
218
 
219
  # Button to simulate the evaluation
220
  if st.button("Simulate Template"):
221
- if template_input:
222
- resources_to_create, resources_to_update, resources_to_delete, resource_details, estimated_cost, dependency_graph, lint_results, system_diagram, message = simulate_deployment(template_input)
223
-
224
- st.subheader("Simulation Results:")
225
- st.write(message)
 
 
 
 
 
 
 
226
 
227
- if resources_to_create or resources_to_update or resources_to_delete:
228
- st.write("### Resources to be Created:")
229
- if resources_to_create:
230
- st.write(resources_to_create)
231
- else:
232
- st.write("No new resources will be created.")
233
 
234
- st.write("### Resources to be Updated:")
235
- if resources_to_update:
236
- st.write(resources_to_update)
237
- else:
238
- st.write("No resources will be updated.")
 
239
 
240
- st.write("### Resources to be Deleted:")
241
- if resources_to_delete:
242
- st.write(resources_to_delete)
243
- else:
244
- st.write("No resources will be deleted.")
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
- st.write("### System Diagram:")
265
- if system_diagram:
266
- st.mermaid(system_diagram)
267
- else:
268
- st.write("Unable to generate system diagram.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
 
270
- st.write("### Template Lint Results:")
271
- if lint_results:
272
- for result in lint_results:
273
- st.write(result)
274
- else:
275
- st.write("No linting issues found.")
 
 
 
 
276
  else:
277
- st.write("No changes detected in the simulation.")
278
  else:
279
- st.error("Please paste an ARM template to simulate.")
 
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.")