def gcpInstances(machine): cloud = 'GCP' machineList = [machine for machine in nc.find({"node":machine},{'_id': False})] matchingFlavor = getMatchingInstances(GC_FLAVORS, machine['cpu'], ceil(float(machine['memory']))) matchingMachines = sorted(matchingFlavor) return render_template('matching_instances.html', data=matchingMachines, cloudProvider=cloud)
def nodes(cluster): session['cluster'] = cluster machineList = [machine for machine in nc.find({"cluster_id":cluster},{'_id':False})] #my_keys = ['node','os','cpu', 'memory', 'disk'] computedAWSCost = [] computedGCPCost = [] totalAWSCost = 0 totalGCPCost = 0 for machine in machineList: #get GCP costs flavorGCP= getMatchingInstances(GC_FLAVORS, machine['cpu'], ceil(float(machine['memory']))) instanceCostGCP = gce_price(1,"regular", "us", flavorGCP[0]['name'], ceil(float(machine['disk'])), machine['os']) totalGCPCost += instanceCostGCP computedGCPCost.append(instanceCostGCP) #get aws costs flavorAWS = getMatchingInstances(AWS_FLAVORS, machine['cpu'], ceil(float(machine['memory']))) instanceCostAWS = read_EC2_ondemand_instance_prices(1, "us-east-1", flavorAWS[0]['name'], machine['os'].lower()) storageAWSCost = aws_storage_prices("us-east-1", ceil(float(machine['disk']))) monthlyCost = instanceCostAWS + storageAWSCost totalAWSCost += monthlyCost computedAWSCost.append(monthlyCost) return render_template('nodes.html', data=machineList, ceil=ceil, dataAWS=zip(machineList,computedAWSCost), totalAWS=totalAWSCost, totalGCP=totalGCPCost, dataGCP= zip(machineList,computedGCPCost), session=session)
def gcpInstances(machine): cloud = 'GCP' machineList = [ machine for machine in nc.find({"node": machine}, {'_id': False}) ] matchingFlavor = getMatchingInstances(GC_FLAVORS, machine['cpu'], ceil(float(machine['memory']))) matchingMachines = sorted(matchingFlavor) return render_template('matching_instances.html', data=matchingMachines, cloudProvider=cloud)
def get_machine_resources(machine): vcpu = 0 mem = 0 strg = 0 opsys = '' for resource in nc.find({"node":machine}, {"cpu":1,"memory":1, "disk":1, "os":1, "_id":0}): vcpu = resource['cpu'] mem = float(resource['memory']) strg = float(resource['disk']) opsys = resource['os'] return vcpu, mem, strg, opsys
def cost_variation(machine, chartID='chart_ID', chart_type='spline', chart_height=500, zoom_type='xy'): percentage_usage =[10, 25, 30, 40, 50, 60, 75, 80, 90, 100] GCP_Cost = [] AWS_Cost = [] #machineList = [machine['node'] for machine in nc.find({"cluster_id":session['cluster']},{'_id':False})] specs = [node for node in nc.find({"node":machine},{'_id': False})] flavorAWS = getMatchingInstances(AWS_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) flavorGCP = getMatchingInstances(GC_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) for percent in percentage_usage: GCP_Cost.append(get_gcp_instance_unit_cost('us', flavorGCP[0]['name'],specs[0]['os'].lower(),percent)) AWS_Cost.append(get_aws_instance_unit_cost('us-east-1', flavorAWS[0]['name'],specs[0]['os'].lower(), percent)) text_title = "Variation in instance charges on AWS and GCP" chart = {"renderTo": chartID, "type": chart_type, "height": chart_height, "zoomType": zoom_type , "backgroundColor": { "linearGradient": [0, 0, 0, 500], "stops": [ [0, 'rgb(255, 255, 255)'], [1, 'rgb(200, 200, 255)'] ] }} credits = {} if GCP_Cost and AWS_Cost: series = [ {"name": 'AWS', "type": 'spline', "data": AWS_Cost }, { "name" : 'GCP', "type": 'spline', "data" : GCP_Cost } ] title = { "text": text_title } xAxis = {"type": 'category', "categories": percentage_usage, "tickInterval": 10, "title": {"text": "Percentage of Instance Usage in a Month"} } yAxis = { "title": {"text": 'Charged Unit Cost in USD'} } return render_template('cost_variation.html', chartID=chartID, chart= chart, series=series, title=title, xAxis=xAxis, yAxis=yAxis)
def Show_On_Demand_Cost(machine, chartID='chart_ID', chart_type='spline', chart_height=500, zoom_type='xy'): percentage_usage =[10, 25, 30, 40, 50, 60, 75, 80, 90, 100] chart_data = [] AWS_Cost = [] specs = [node for node in nc.find({"node":machine},{'_id': False})] flavorAWS = getMatchingInstances(AWS_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) flavorGCP = getMatchingInstances(GC_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) for percent in percentage_usage: chart_data.append(gce_on_demand_costs(1,'us', flavorGCP[0]['name'],ceil(float(specs[0]['disk'])),specs[0]['os'].lower(), percent)) AWS_Cost.append(aws_on_demand_costs(1,'us-east-1', flavorAWS[0]['name'], ceil(float(specs[0]['disk'])) ,specs[0]['os'].lower() , percent)) GCP_Cost = chart_data #json_cpu.append(cpu_user) #json_data = json.dumps(cpu_user, default=json_util.default) text_title = "Cost of instance per usage" chart = {"renderTo": chartID, "type": chart_type, "height": chart_height, "zoomType": zoom_type , "backgroundColor": { "linearGradient": [0, 0, 0, 500], "stops": [ [0, 'rgb(255, 255, 255)'], [1, 'rgb(200, 200, 255)'] ] }} credits = {} if GCP_Cost and AWS_Cost: series = [ {"name": 'AWS', "type": 'spline', "data": AWS_Cost }, { "name" : 'GCP', "type": 'spline', "data" : GCP_Cost } ] title = {"text": text_title} xAxis = {"type": 'category', "categories": percentage_usage, "tickInterval": 10, "title": {"text": "Percentage of Instance Usage in a Month"} } yAxis = { "title": {"text": 'Cost of Instance $'} } return render_template('costs.html', chartID=chartID, chart= chart, series=series, title=title, xAxis=xAxis, yAxis=yAxis)
def show_costs(machine): if not machine: return render_template("costs.html", machine=None, awsregions='', gcpregions='', data='') regionCostAWS = [] regionCostGCP = [] awsregions = [ "us-east-1", "us-west-1", "us-west-2", "eu-west-1", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "sa-east-1", "eu-central-1", "us-gov-west-1" ] gcpregions = ['us', 'europe', 'asia'] specs = [node for node in nc.find({"node": machine}, {'_id': False})] flavorAWS = getMatchingInstances(AWS_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) flavorGCP = getMatchingInstances(GC_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) for dataCenter in awsregions: instanceCost = read_EC2_ondemand_instance_prices( 1, dataCenter, flavorAWS[0]['name'], specs[0]['os'].lower()) storageCost = aws_storage_prices(dataCenter, ceil(float(specs[0]['disk']))) monthlyCost = instanceCost + storageCost #dic.(dataCenter, monthlyCost) if instanceCost > 0: regionCostAWS.append((dataCenter, monthlyCost)) sortedRegionCostOnAWS = sorted(regionCostAWS, key=itemgetter(1)) for dataCenter in gcpregions: instanceCost = gce_price(1, "regular", dataCenter, flavorGCP[0]['name'], ceil(float(specs[0]['disk'])), specs[0]['os']) if instanceCost > 0: regionCostGCP.append((dataCenter, instanceCost)) sortedRegionCostOnGCP = sorted(regionCostGCP, key=itemgetter(1)) return render_template("costs.html", machine=machine, awsregions=sortedRegionCostOnAWS, gcpregions=sortedRegionCostOnGCP)
def show_costs(machine): if not machine: return render_template("costs.html", machine=None, awsregions= '', gcpregions='', data=''); regionCostAWS = [] regionCostGCP = [] awsregions = [ "us-east-1", "us-west-1", "us-west-2", "eu-west-1", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "sa-east-1", "eu-central-1", "us-gov-west-1" ] gcpregions = ['us', 'europe', 'asia'] specs = [node for node in nc.find({"node":machine},{'_id': False})] flavorAWS = getMatchingInstances(AWS_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) flavorGCP = getMatchingInstances(GC_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) for dataCenter in awsregions: instanceCost = read_EC2_ondemand_instance_prices(1, dataCenter, flavorAWS[0]['name'], specs[0]['os'].lower()) storageCost = aws_storage_prices(dataCenter, ceil(float(specs[0]['disk']))) monthlyCost = instanceCost + storageCost #dic.(dataCenter, monthlyCost) if instanceCost > 0: regionCostAWS.append((dataCenter, monthlyCost)) sortedRegionCostOnAWS = sorted(regionCostAWS, key= itemgetter(1)) for dataCenter in gcpregions: instanceCost = gce_price(1,"regular", dataCenter, flavorGCP[0]['name'], ceil(float(specs[0]['disk'])), specs[0]['os']) if instanceCost > 0: regionCostGCP.append((dataCenter, instanceCost)) sortedRegionCostOnGCP = sorted(regionCostGCP, key= itemgetter(1)) return render_template("costs.html", machine=machine, awsregions= sortedRegionCostOnAWS, gcpregions=sortedRegionCostOnGCP);
def nodes(cluster): session['cluster'] = cluster machineList = [ machine for machine in nc.find({"cluster_id": cluster}, {'_id': False}) ] #my_keys = ['node','os','cpu', 'memory', 'disk'] computedAWSCost = [] computedGCPCost = [] totalAWSCost = 0 totalGCPCost = 0 for machine in machineList: #get GCP costs flavorGCP = getMatchingInstances(GC_FLAVORS, machine['cpu'], ceil(float(machine['memory']))) instanceCostGCP = gce_price(1, "regular", "us", flavorGCP[0]['name'], ceil(float(machine['disk'])), machine['os']) totalGCPCost += instanceCostGCP computedGCPCost.append(instanceCostGCP) #get aws costs flavorAWS = getMatchingInstances(AWS_FLAVORS, machine['cpu'], ceil(float(machine['memory']))) instanceCostAWS = read_EC2_ondemand_instance_prices( 1, "us-east-1", flavorAWS[0]['name'], machine['os'].lower()) storageAWSCost = aws_storage_prices("us-east-1", ceil(float(machine['disk']))) monthlyCost = instanceCostAWS + storageAWSCost totalAWSCost += monthlyCost computedAWSCost.append(monthlyCost) return render_template('nodes.html', data=machineList, ceil=ceil, dataAWS=zip(machineList, computedAWSCost), totalAWS=totalAWSCost, totalGCP=totalGCPCost, dataGCP=zip(machineList, computedGCPCost), session=session)
def cost_variation(machine, chartID='chart_ID', chart_type='spline', chart_height=500, zoom_type='xy'): percentage_usage = [10, 25, 30, 40, 50, 60, 75, 80, 90, 100] GCP_Cost = [] AWS_Cost = [] #machineList = [machine['node'] for machine in nc.find({"cluster_id":session['cluster']},{'_id':False})] specs = [node for node in nc.find({"node": machine}, {'_id': False})] flavorAWS = getMatchingInstances(AWS_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) flavorGCP = getMatchingInstances(GC_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) for percent in percentage_usage: GCP_Cost.append( get_gcp_instance_unit_cost('us', flavorGCP[0]['name'], specs[0]['os'].lower(), percent)) AWS_Cost.append( get_aws_instance_unit_cost('us-east-1', flavorAWS[0]['name'], specs[0]['os'].lower(), percent)) text_title = "Variation in instance charges on AWS and GCP" chart = { "renderTo": chartID, "type": chart_type, "height": chart_height, "zoomType": zoom_type, "backgroundColor": { "linearGradient": [0, 0, 0, 500], "stops": [[0, 'rgb(255, 255, 255)'], [1, 'rgb(200, 200, 255)']] } } credits = {} if GCP_Cost and AWS_Cost: series = [{ "name": 'AWS', "type": 'spline', "data": AWS_Cost }, { "name": 'GCP', "type": 'spline', "data": GCP_Cost }] title = {"text": text_title} xAxis = { "type": 'category', "categories": percentage_usage, "tickInterval": 10, "title": { "text": "Percentage of Instance Usage in a Month" } } yAxis = {"title": {"text": 'Charged Unit Cost in USD'}} return render_template('cost_variation.html', chartID=chartID, chart=chart, series=series, title=title, xAxis=xAxis, yAxis=yAxis)
def Show_On_Demand_Cost(machine, chartID='chart_ID', chart_type='spline', chart_height=500, zoom_type='xy'): percentage_usage = [10, 25, 30, 40, 50, 60, 75, 80, 90, 100] chart_data = [] AWS_Cost = [] specs = [node for node in nc.find({"node": machine}, {'_id': False})] flavorAWS = getMatchingInstances(AWS_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) flavorGCP = getMatchingInstances(GC_FLAVORS, specs[0]['cpu'], ceil(float(specs[0]['memory']))) for percent in percentage_usage: chart_data.append( gce_on_demand_costs(1, 'us', flavorGCP[0]['name'], ceil(float(specs[0]['disk'])), specs[0]['os'].lower(), percent)) AWS_Cost.append( aws_on_demand_costs(1, 'us-east-1', flavorAWS[0]['name'], ceil(float(specs[0]['disk'])), specs[0]['os'].lower(), percent)) GCP_Cost = chart_data #json_cpu.append(cpu_user) #json_data = json.dumps(cpu_user, default=json_util.default) text_title = "Cost of instance per usage" chart = { "renderTo": chartID, "type": chart_type, "height": chart_height, "zoomType": zoom_type, "backgroundColor": { "linearGradient": [0, 0, 0, 500], "stops": [[0, 'rgb(255, 255, 255)'], [1, 'rgb(200, 200, 255)']] } } credits = {} if GCP_Cost and AWS_Cost: series = [{ "name": 'AWS', "type": 'spline', "data": AWS_Cost }, { "name": 'GCP', "type": 'spline', "data": GCP_Cost }] title = {"text": text_title} xAxis = { "type": 'category', "categories": percentage_usage, "tickInterval": 10, "title": { "text": "Percentage of Instance Usage in a Month" } } yAxis = {"title": {"text": 'Cost of Instance $'}} return render_template('costs.html', chartID=chartID, chart=chart, series=series, title=title, xAxis=xAxis, yAxis=yAxis)
def get_nodes_in_cluster(cluster): machines_in_cluster = [] #get_node_name = function(doc) { return doc.node } for machine in nc.find({"cluster_id":cluster}, {"node":1,"_id":0}): machines_in_cluster.append(machine['node']) return machines_in_cluster