Skip to content

Commit

Permalink
Merge pull request #16 from nishubharti/version
Browse files Browse the repository at this point in the history
fix issues
  • Loading branch information
nishubharti authored Jul 28, 2021
2 parents fd31934 + 84ab5ec commit b055629
Show file tree
Hide file tree
Showing 9 changed files with 975 additions and 2,665 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ For fastest way to get up and running with blast-radius is as follows:
copy the blastradius/server/static folder to the terraform directory
```
```
easy_install blastradius-0.1.25.3-py3-none-any.whl
easy_install blastradius-0.1.25.4-py3-none-any.whl
```
* Once installed just point Blast Radius at any initialized Terraform directory:
```sh
Expand Down
3 changes: 3 additions & 0 deletions blastradius/handlers/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def __init__(self,filename=None):
temp_data = dict()
for (index, var) in data.items():
temp_data[index] = var
if (index == "Lineitem"):
if var == None:
temp_data[index] = "not available"

self.resource_cost_info.append(temp_data)

Expand Down
63 changes: 33 additions & 30 deletions blastradius/handlers/dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,29 @@ def __init__(self,flag,filename, file_contents=None):
type = sp[1].split(".")[0]
if type == "data":
#process data source:
apply_data = None
plan_data = None
plan_data = "no plan available"
policy_data = "no policy available"
cost_data = "no cost available"
time_data = "no time estimation available"
if ("not applied" in self.apply.apply_resource_info):
apply_data = "not yet applied"
plan_data = "data-source"
self.nodes.append(DotNode(d['node'], plan_data, apply_data,"no cost data available","no policy data available","no time estimation available",fmt=fmt ))
self.nodes.append(DotNode(d['node'], plan_data, apply_data,cost_data,policy_data,time_data,fmt=fmt ))
break

else:
for i in self.apply.apply_resource_info:
if i['type']+"."+i['name'] == res:
apply_data = i
plan_data = "data-source"
self.nodes.append(DotNode(d['node'], plan_data, apply_data,"no cost data available","no policy data available","no time estimation available",fmt=fmt ))
self.nodes.append(DotNode(d['node'], plan_data, apply_data,cost_data,policy_data,time_data,fmt=fmt ))
break
else:
if type == "provider":
apply_data = {}
plan_data = {}
policy_data = {}
cost_data = {}
self.nodes.append(DotNode(d['node'], plan_data, apply_data,"no cost data available","no policy data available","no time estimation available",fmt=fmt ))
if type == "provider" or type == "provisioner":
apply_data = "not yet applied"
plan_data = "no plan available"
policy_data = "no policy available"
cost_data = "no cost available"
time_data = "no time estimation available"
self.nodes.append(DotNode(d['node'], plan_data, apply_data,cost_data,policy_data,time_data,fmt=fmt ))
else:
apply_data = None
plan_data = None
Expand Down Expand Up @@ -129,20 +130,22 @@ def __init__(self,flag,filename, file_contents=None):
for i in range(len(self.cost.resource_cost_info)):
currency = self.cost.resource_cost_info[i]["currency"]
self.totalcost = str(self.cost.resource_cost_info[i]["totalcost"]) + " " +currency
for _, val in enumerate(self.cost.resource_cost_info[i]["Lineitem"]):
data = val["terraformItemId"]+"."+val["id"]
if data == res:
val["lineitemtotal"] = str(val["lineitemtotal"]) + " "+ currency
cost_data = val
break
if self.cost.resource_cost_info[i]["Lineitem"] == "not available":
cost_data = "no cost available"
else:
for _, val in enumerate(self.cost.resource_cost_info[i]["Lineitem"]):
data = val["terraformItemId"]+"."+val["id"]
if data == res:
val["lineitemtotal"] = str(val["lineitemtotal"]) + " "+ currency
cost_data = val
break

if ("not available" in self.time.resource_time_info):
time_data = "no time estimation available"

else:
for i in range(len(self.time.resource_time_info)):
self.totaltime = str(self.time.resource_time_info[i]["totalTimeEstimation"])

for _, val in enumerate(self.time.resource_time_info[i]["resources"]):
data = val["name"]
if data == res.split(".")[0]:
Expand All @@ -155,19 +158,19 @@ def __init__(self,flag,filename, file_contents=None):
# sometimes they're a side-effect of edge definitions. Capture them.
for e in self.edges:
if e.source not in [ n.label for n in self.nodes ]:
plan_data = {}
apply_data = {}
policy_data = {}
cost_data = {}
time_data = {}
apply_data = "not yet applied"
plan_data = "no plan available"
policy_data = "no policy available"
cost_data = "no cost available"
time_data = "no time estimation available"
self.nodes.append(DotNode(e.source, plan_data,apply_data,cost_data,policy_data,time_data))

if e.target not in [ n.label for n in self.nodes ]:
plan_data = {}
apply_data = {}
policy_data = {}
cost_data = {}
time_data = {}
apply_data = "not yet applied"
plan_data = "no plan available"
policy_data = "no policy available"
cost_data = "no cost available"
time_data = "no time estimation available"
self.nodes.append(DotNode(e.target, plan_data,apply_data,cost_data,policy_data,time_data))

self.stack('var')
Expand Down Expand Up @@ -471,7 +474,7 @@ def focus(self, node):
{% if node.cost == "no cost available" %}
<TR><TD fixedsize="true" width="20" height="20"><IMG SRC= "static/images/cost.png"/></TD><TD>{{ "%-30s"|format("&#62;_estimate cost") }}</TD><TD fixedsize="true" width="50" height="20">{{ "%-10s"|format("N/A") }}</TD></TR>
{% else %}
<TR><TD fixedsize="true" width="20" height="20"><IMG SRC= "static/images/cost.png"/></TD><TD>{{ "%-30s"|format("&#62;_estimate cost") }}</TD><TD fixedsize="true" width="50" height="20">{{ "%-10s"|format(node.cost.lineitemtotal) }}</TD></TR>
<TR><TD fixedsize="true" width="20" height="20"><IMG SRC= "static/images/cost.png"/></TD><TD>{{ "%-30s"|format("&#62;_estimate cost") }}</TD><TD fixedsize="true" width="50" height="20">{{ "%-10s"|format(node.cost.currlineitemtotal) }}</TD></TR>
{% endif %}
{% if node.time == "no time estimation available" %}
<TR><TD fixedsize="true" width="20" height="20"><IMG SRC= "static/images/time.png"/></TD><TD>{{ "%-30s"|format("&#62;_estimate time") }}</TD><TD fixedsize="true" width="50" height="20"><IMG SRC= "static/images/hourglass.png"/></TD></TR>
Expand Down
9 changes: 6 additions & 3 deletions blastradius/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import jinja2


# 1st-party libraries
from blastradius.handlers.dot import DotGraph, Format, DotNode
from blastradius.handlers.terraform import Terraform
Expand Down Expand Up @@ -78,14 +77,18 @@ def simple_graph():
file_contents=run_tf_graph()
new_file_content = ''
for line in file_contents.splitlines():
if re.search("var",line) or re.search("provider",line) or re.search("meta.count-boundary",line) or re.search("output",line):
if re.search("var",line) or re.search("provider",line) or re.search("meta.count-boundary",line) or re.search("output",line) :
if re.search("meta.count-boundary",line) and not (re.search("output",line) or re.search("var",line) or re.search('\[root\] root',line)):
new_line = line.replace("meta.count-boundary (EachMode fixup)","root")
new_file_content+=new_line +'\n'
if re.search("provider.template",line):
x = line.split('->')
if x[0].find("[root] provider.template (close)") != -1 :
new_line = line.replace("[root] provider.template (close)","[root] root")
new_file_content+=new_line +'\n'
else:
new_file_content+=line +'\n'


return new_file_content


Expand Down
6 changes: 5 additions & 1 deletion blastradius/server/static/js/blast-radius-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,14 @@ blastradiusnew = function (selector, svg_url, json_url,br_state) {

var render_plan = function(d) {
var plan_title = "plan info"
var yamlplan = json2yaml(d.plan)
var ttip = '';
ttip += title_html(d);
if (d.plan == "no plan available"){
ttip += '<hr style="background-color:black"/><br><span class="title" style="background:' + color("#ffbf00") + ';">' + plan_title + '</span><br><br>'+(d.plan.length == 0 ? '' : "<p class='explain'>" + JSON.stringify(d.plan, replacer, 2) + "</p><br>"+ '<hr style="background-color:black"/>') ;
} else {
var yamlplan = json2yaml(d.plan)
ttip += '<hr style="background-color:black"/><br><span class="title" style="background:' + color("#ffbf00") + ';">' + plan_title + '</span><br><br>'+(d.plan.length == 0 ? '' : "<p class='explain'>" + yamlplan + "</p><br>"+ '<hr style="background-color:black"/>') ;
}
ttip += child_html(d);
return ttip;
}
Expand Down
Loading

0 comments on commit b055629

Please sign in to comment.