def edit_quota(): # Get quota details from the first student in the course students = list( keystone.get_projects(current_user.course)['students'].values()) if not students: flash('No students registered!') return redirect(url_for('index')) #student_quota = nova.get_project_quota(list(keystone.get_projects(current_user.course)['students'].values())[0]) student_quota = nova.get_project_quota(students[0]) form = forms.QuotaForm() form.instances_quota.choices = [ (i, i) for i in range(1, int(app.config['QUOTA_INSTANCES_MAX']) + 1) ] form.cores_quota.choices = [ (i, i) for i in range(1, int(app.config['QUOTA_CORES_MAX']) + 1) ] ram_values = [] for i in range(1024, int(app.config['QUOTA_RAM_MAX']) + 1, 1024): if i <= 8192 and i % 1024 == 0: ram_values.append((i, str(i) + ' MB')) elif i % 2048 == 0: ram_values.append((i, str(i) + ' MB')) form.ram_quota.choices = ram_values form.networks_quota.choices = [ (i, i) for i in range(1, int(app.config['QUOTA_NETWORKS_MAX']) + 1) ] if form.validate_on_submit(): for pid in keystone.get_projects( current_user.course)['students'].values(): nova.update_project_quota.delay( pid, form.instances_quota.data, form.cores_quota.data, form.ram_quota.data, form.networks_quota.data, form.networks_quota.data, int(form.networks_quota.data) * 10, form.instances_quota.data, form.networks_quota.data) flash('Quota updated') return redirect(url_for('index')) # Make default value equal to whatever's currently set form.instances_quota.default = student_quota['instances'] form.cores_quota.default = student_quota['cores'] form.ram_quota.default = student_quota['ram'] form.networks_quota.default = student_quota['network'] form.process() return render_template('edit_quota.html', title='Edit Quota', form=form, navbar_text='Quota: ' + current_user.course)
def index(): #jobs = inspect() #print(jobs.active()) #return render_template('index.html', title='Home', projects=keystone.get_projects(current_user.course), active_jobs=jobs.active(), scheduled_jobs=jobs.scheduled()) return render_template( 'index.html', title='Home', projects=keystone.get_projects(current_user.course), project_info=keystone.get_project_info(current_user.course), navbar_text='Course Overview: ' + current_user.course)
def router_create_wrapper(project, course, network_name, network): nt = setup_neutronclient() projects = get_projects(course) all_projects = {**projects['instructors'], **projects['students']} all_networks = merge_network_dicts(project, network) external_network_id = nt.list_networks(name='HRL')['networks'][0]['id'] for project in all_projects: router_name = project + '-' + network_name + '-Router' async_router_create.delay(all_projects[project], all_networks[project]['subnets']['id'], router_name, external_network_id)
def network_create_wrapper(project, course, network_name, cidr): import netaddr nt = setup_neutronclient() projects = get_projects(course) all_projects = {**projects['instructors'], **projects['students']} external_network_id = nt.list_networks(name='HRL')['networks'][0]['id'] cidr = netaddr.IPNetwork(cidr + '/24') gateway = netaddr.IPNetwork(cidr)[1] for project in all_projects: network_name_template = project + '-' + network_name async_network_create.delay(all_projects[project], \ network_name_template + '-Network', \ network_name_template + '-Subnet', \ network_name_template + '-Router', \ str(cidr), str(gateway), external_network_id)
def verify_network_integrity(course, network): nt = setup_neutronclient() projects = get_projects(course) networks = [] if network: for name in network: networks.append(name) else: return problem_children = {} for n in networks: problem_children[n] = {} subnet_ip = network[n]['subnets']['cidr'] gateway_ip = network[n]['subnets']['gateway_ip'] for project in projects['students']: problem_children[n][project] = {} problem_list = [] if not network[n]['children'].get(project): problem_list.append('NETWORK_NOT_FOUND') else: if not network[n]['children'][project].get('subnets'): problem_list.append('SUBNET_NOT_FOUND') else: if not 'cidr' in network[n]['children'][project]['subnets']: problem_list.append('NO_CIDR_SET') else: if not network[n]['children'][project]['subnets'][ 'cidr'] == subnet_ip: problem_list.append('CIDR_IP_WRONG') if not 'gateway_ip' in network[n]['children'][project][ 'subnets']: problem_list.append('NO_GATEWAY_IP_SET') else: if not network[n]['children'][project]['subnets'][ 'gateway_ip'] == gateway_ip: problem_list.append('GATEWAY_IP_WRONG') if 'router' not in network[n]['children'][ project] and network[n]['router']: problem_list.append('ROUTER_NOT_FOUND') if not problem_list: del problem_children[n][project] else: problem_children[n][project] = problem_list return problem_children