Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@app.route('/vmware/clusters')
@cortex.core.login_required
def vmware_clusters():
curd = g.db.cursor(mysql.cursors.DictCursor)
curd.execute('SELECT `a`.`cluster`, `a`.`vcenter`, `b`.`hosts`, `a`.`vm_count`, (`b`.`ram_usage` * 1048576) AS `ram_usage`, (`a`.`assigned_ram` * 1048576) AS `assigned_ram`, `b`.`ram` AS `total_ram`, `a`.`assigned_cores`, `b`.`cores` AS `total_cores`, `b`.`cpu_usage` AS `cpu_usage_mhz`, ROUND(`b`.`cpuhz` / 1000) AS `total_mhz` FROM (SELECT `cluster`, `vcenter`, COUNT(*) AS `vm_count`, SUM(`numCPU`) AS `assigned_cores`, SUM(`memoryMB`) AS `assigned_ram` FROM `vmware_cache_vm` WHERE `cluster` != "None" group by `cluster`) `a` JOIN `vmware_cache_clusters` `b` ON `a`.`cluster` = `b`.`name`;')
# Take the above query and group it by vCenter
vcenters = {}
row = curd.fetchone()
while row is not None:
# If this is the first time we've seen a vCenter, create a new array
if row['vcenter'] not in vcenters:
vcenters[row['vcenter']] = []
# Add a row to the array
vcenters[row['vcenter']].append(row)
# Extract information from DataTables
(draw, start, length, order_column, order_asc, search) = _sysrequests_extract_datatables()
# Validate and convert the ordering column number to the name of the
# column as it is in the database
if order_column == 0:
order_column = 'status'
elif order_column == 1:
order_column = 'requested_who'
elif order_column == 2:
order_column = 'purpose'
elif order_column == 3:
order_column = 'request_date'
else:
app.logger.warn('Invalid ordering column parameter in DataTables request')
abort(400)
# Validate the system class filter group. This is the name of the
# currently selected tab on the page that narrows down by system
# class, e.g .srv, vhost, etc.
filter_group = None
if request.form.get('filter_group', None) in ["0", "1", "2"]:
filter_group = int(request.form['filter_group'])
# Get results of query
# get all the requests if the user has the permission
if does_user_have_permission("sysrequests.all.view"):
system_count = cortex.lib.sysrequests.get_request_count(filter_group)
filtered_count = cortex.lib.sysrequests.get_request_count(filter_group, None, search)
results = cortex.lib.sysrequests.get_requests(filter_group, None, search, order_column, order_asc, start, length)
@app.disable_csrf_check
def root():
# If the user is already logged in, just redirect them to their dashboard
if cortex.lib.user.is_logged_in():
return redirect(url_for('dashboard'))
else:
if app.config['DEFAULT_USER_AUTH'] == 'cas':
return cas()
else:
return login()
def fatalerr(title="Totes not an error ;)", message="While processing your request an unexpected error occured which the application could not recover from", debug=None):
# Should we show a traceback?
if debug is None:
if app.debug:
debug = traceback.format_exc()
else:
debug = "Please ask your administrator to consult the error log for more information."
# Build the response. Not using a template here to prevent any Jinja
# issues from causing this to fail.
html = """
<title>Fatal Error</title>
<style type="text/css">
body {</style>
@app.route('/help/puppet')
@cortex.lib.user.login_required
def puppet_help():
"""Displays the Puppet ENC help page."""
return render_template('puppet/help.html', active='puppet', title="Puppet Help")
'search_domain': '',
'net': {
'routes': [],
'networks': [],
},
}
# get the VM
try:
vm = cortex.lib.systems.get_vm_by_system_id(id)
except ValueError:
abort(404)
except Exception as e:
# If we want to handle vCenter being unavailable gracefully.
if not app.config.get('HANDLE_UNAVAILABLE_VCENTER_GRACEFULLY', False):
raise e
else:
vm = None
# Add an error field to the data we return,
# so we can display a message on the template.
data['error'] = 'Unable to retrieve system information, please check vCenter availability.'
if vm is not None and vm.guest is not None:
if vm.guest.ipStack is not None and len(vm.guest.ipStack) > 0:
if vm.guest.ipStack[0].dnsConfig is not None:
if vm.guest.ipStack[0].dnsConfig.hostName is not None:
data['hostname'] = vm.guest.ipStack[0].dnsConfig.hostName
if vm.guest.ipStack[0].dnsConfig.ipAddress is not None:
data['dns_resolvers'] = vm.guest.ipStack[0].dnsConfig.ipAddress
if vm.guest.ipStack[0].dnsConfig.domainName is not None:
data['search_domain'] = vm.guest.ipStack[0].dnsConfig.domainName
@app.route('/systems/withperms')
@cortex.lib.user.login_required
def systems_withperms():
"""Shows the list of systems which have permissions"""
# Check user permissions
if not does_user_have_permission("systems.all.view"):
abort(403)
# Get the list of active classes (used to populate the tab bar)
classes = cortex.lib.classes.get_list()
# Render
return render_template('systems/list.html', classes=classes, active='perms', title="Systems with permissions", perms_only=True)
@app.route('/task/status//log', methods=['GET'])
@cortex.lib.user.login_required
def task_status_log(id):
"""Much like task_status, but only returns the event log. This is used by
an AJAX routine on the page to refresh the log every 10 seconds."""
## Get the task details
task = cortex.lib.core.task_get(id)
# Return a 404 if we've not found the task
if not task:
abort(404)
# Check the user has the permission to view this task
if not task['username'] == session['username']:
if not does_user_have_permission("tasks.view"):
abort(403)