def clm_ajax_set_password(request, id1, template_name='admin_clm/ajax/set_password.html', form_class=PasswordForm): """ Ajax view for setting user's password. """ id1 = int(id1) if request.method == 'POST': form = form_class(request.POST) if form.is_valid(): new_password = form.cleaned_data['new_password'] prep_data(('admin_clm/user/set_password/', { 'user_id': id1, 'new_password': new_password }), request.session) if id1 == request.session['user'].user_id: request.session['user'].set_password(new_password) request.session.modified = True return messages_ajax.success( _('You have successfully set password for user <b>%(desc)s</b>.' ) % {'desc': (force_escape(request.POST.get('desc')))}) else: form = form_class() return messages_ajax.success(render_to_string( template_name, { 'form': form, 'text': _('Setting password for user <b>%(desc)s</b>:') % { 'desc': (force_escape(request.REQUEST.get('desc'))) } }, context_instance=RequestContext(request)), status=1)
def cma_ajax_change_quota(request, template_name='generic/form.html', form_class=MultipleChangeQuotaForm): """ Ajax view for changing users quota. """ if request.method == 'POST': form = form_class(data=request.POST) user_list = request.POST.getlist('userids[]') if form.is_valid(): dictionary = {'user_ids': [int(a) for a in user_list]} for value, key in form.cleaned_data.items(): if key is not None: dictionary[value] = key prep_data(('admin_cm/user/multiple_change_quota/', dictionary), request.session) return messages_ajax.success( _('You have successfully changed quota.')) else: form = form_class() return messages_ajax.success( render_to_string(template_name, { 'form': form, 'confirmation': _('Change'), 'text': '' }, context_instance=RequestContext(request)))
def img_ajax_add_image_http(request, template_name='generic/form.html', form_class=AddImageHttp): """ Ajax view for handling adding image from http link. """ rest_data = prep_data( { 'disk_controllers': 'user/system_image/get_disk_controllers/', 'video_devices': 'user/system_image/get_video_devices/', 'network_devices': 'user/system_image/get_network_devices/' }, request.session) if request.method == 'POST': form = form_class(data=request.POST, files=request.FILES, rest_data=rest_data) if form.is_valid(): dictionary = form.cleaned_data prep_data(('user/system_image/download/', dictionary), request.session) return messages_ajax.success(_('Image upload started.')) else: form = form_class(rest_data=rest_data) return messages_ajax.success(render_to_string( template_name, { 'form': form, 'confirmation': _('Add image'), 'text': _('Please specify image parameters:') }, context_instance=RequestContext(request)), status=1)
def acc_password_reset(request, template_name='account/password_reset_form.html', password_reset_form=PasswordResetForm): """ <b>Password reset</b> form handling (email is sent). @parameter{request} @parameter{template_name} optional @parameter{password_reset_form} optional """ if request.method == "POST": form = password_reset_form(request.POST) if form.is_valid(): try: dictionary = {'email': form.cleaned_data['email'], 'wi_data': settings.WI_DATA} prep_data(('guest/user/reset_password_mail/', dictionary), request.session) except Exception: return redirect('acc_password_reset_error') return redirect('acc_password_reset_done') else: form = password_reset_form() rest_data = prep_data('guest/user/is_mailer_active/', request.session) return render_to_response(template_name, dict({'form': form}.items() + rest_data.items()), context_instance=RequestContext(request))
def acc_password_change(request, template_name='account/password_change_form.html', password_change_form=PasswordChangeForm): """ View for password changing (for logged users). """ if request.method == "POST": form = password_change_form(user=request.session['user'], data=request.POST) if form.is_valid(): new_password = form.cleaned_data['new_password1'] try: prep_data(('user/user/set_password/', { 'new_password': new_password }), request.session) except RestErrorException as ex: messages.error(request, ex.value) request.session['user'].set_password(new_password) request.session.modified = True return redirect('acc_password_change_done') else: form = password_change_form(user=request.session['user']) return render_to_response(template_name, {'form': form}, context_instance=RequestContext(request))
def hlp_form(request, form_class=HelpForm, template_name='help/form.html'): """ View handling help form. """ if request.method == 'POST': form = form_class(data=request.POST) if form.is_valid(): topic, issue, email = form.cleaned_data[ 'topic'], form.cleaned_data['issue'], form.cleaned_data[ 'email'] name = str( request.session.get('user', form.cleaned_data['firstlast'])) topic += _(' from user:'******', email: ' + email dictionary = {'issue': issue, 'topic': topic} try: prep_data(('user/user/send_issue/', dictionary), request.session) except Exception: return redirect('hlp_issue_error') return redirect('hlp_issue_sent') else: form = form_class() rest_data = prep_data('guest/user/is_mailer_active/', request.session) return render_to_response(template_name, dict({'form': form}.items() + rest_data.items()), context_instance=RequestContext(request))
def acc_ajax_account_data_edit(request, template_name='generic/form.html', form_class=AccountDataEdit): """ Ajax view for user account data editing. """ rest_data = prep_data({'cms': 'guest/cluster/list_names/'}, request.session) if request.method == 'POST': form = form_class(data=request.POST, rest_data=rest_data) if form.is_valid(): prep_data({'user': ('user/user/edit/', form.cleaned_data)}, request.session) request.session['user'].email = form.cleaned_data['email'] request.session['user'].default_cluster_id = form.cleaned_data['default_cluster_id'] request.session.modified = True return messages_ajax.success(_('Account data edited.')) else: form = form_class(data={'email': request.session['user'].email, 'default_cluster_id': request.session['user'].default_cluster_id}, rest_data=rest_data) return messages_ajax.success(render_to_string(template_name, {'form': form, 'text': '', 'confirmation': _('Save')}, context_instance=RequestContext(request)), status=1)
def cma_ajax_copy_iso(request, id1, template_name='generic/form.html', form_class=CopyToUserForm): """ Ajax view for changing the image owner. """ rest_data = prep_data({'users': 'admin_cm/user/get_list/'}, request.session) if request.method == 'POST': form = form_class(data=request.POST, files=request.FILES, rest_data=rest_data) if form.is_valid(): dictionary = form.cleaned_data dictionary['src_image_id'] = int(id1) dictionary['dest_user_id'] = int(dictionary['dest_user_id']) prep_data(('admin_cm/iso_image/copy/', dictionary), request.session) return messages_ajax.success( _("<b>%(desc)s</b> copied.") % {'desc': force_escape(request.REQUEST.get('desc'))}) else: form = form_class(rest_data=rest_data) return messages_ajax.success(render_to_string( template_name, { 'form': form, 'confirmation': _('Copy'), 'text': _('Select user:') }, context_instance=RequestContext(request)), status=1)
def res_ajax_add_disk(request, template_name='resources/ajax/add_disk.html', form_class=AddDiskForm): """ Ajax view for adding new disk. """ rest_data = prep_data( { 'quota': 'user/user/check_quota/', 'supported_filesystems': 'user/storage_image/get_filesystems/', 'disk_controllers': 'user/storage_image/get_disk_controllers/' }, request.session) quota = rest_data['quota'] if request.method == 'POST': form = form_class(request.POST, rest_data=rest_data) if form.is_valid(): dictionary = form.cleaned_data prep_data({'key': ('user/storage_image/create/', dictionary)}, request.session) return messages_ajax.success(_("Disk is being created.")) else: form = form_class(rest_data=rest_data) return messages_ajax.success(render_to_string( template_name, { 'form': form, 'free': quota['storage'] - quota['used_storage'] }, context_instance=RequestContext(request)), status=1)
def hlp_form(request, form_class=HelpForm, template_name='help/form.html'): """ View handling help form. """ if request.method == 'POST': form = form_class(data=request.POST) if form.is_valid(): topic, issue, email = form.cleaned_data['topic'], form.cleaned_data['issue'], form.cleaned_data['email'] name = str(request.session.get('user', form.cleaned_data['firstlast'])) topic += _(' from user:'******', email: ' + email dictionary = {'issue': issue, 'topic': topic} try: prep_data(('user/user/send_issue/', dictionary), request.session) except Exception: return redirect('hlp_issue_error') return redirect('hlp_issue_sent') else: form = form_class() rest_data = prep_data('guest/user/is_mailer_active/', request.session) return render_to_response(template_name, dict({'form': form}.items() + rest_data.items()), context_instance=RequestContext(request))
def res_ajax_upload_iso_http(request, template_name='generic/form.html', form_class=UploadISOForm): """ Ajax view for uploading iso image from a http link. """ rest_data = prep_data( {'disk_controllers': 'user/iso_image/get_disk_controllers/'}, request.session) if request.method == 'POST': form = form_class(data=request.POST, rest_data=rest_data) if form.is_valid(): dictionary = form.cleaned_data prep_data({'images': ('user/iso_image/download/', dictionary)}, request.session) return messages_ajax.success(_("ISO image upload started.")) else: form = form_class(rest_data=rest_data) return messages_ajax.success(render_to_string( template_name, { 'form': form, 'confirmation': _('Upload ISO image'), 'text': _('Please specify ISO image parameters:') }, context_instance=RequestContext(request)), status=1)
def mai_ajax_edit_news(request, id1, template_name='generic/form.html', form_class=NewsForm): """ Ajax view for editing a news entry. """ if request.method == 'POST': form = form_class(data=request.POST) if form.is_valid(): dictionary = form.cleaned_data dictionary.update({'news_id': id1}) prep_data(('admin_clm/news/edit/', dictionary), request.session) return messages_ajax.success(_('News entry edited.')) else: rest_data = prep_data(('admin_clm/news/get_by_id/', { 'news_id': id1 }), request.session) rest_data['sticky'] = rest_data['sticky'] != 0 form = form_class(rest_data) return messages_ajax.success(render_to_string( template_name, { 'form': form, 'text': _('Edit news data:'), 'confirmation': _('Save'), 'id': id1 }, context_instance=RequestContext(request)), status=1)
def cma_ajax_change_cm_password( request, template_name='admin_cm/ajax/change_password.html', form_class=PasswordForm): """ Ajax view for changing logged CM admin password. """ if request.method == 'POST': form = form_class(request.POST) if form.is_valid(): prep_data(('admin_cm/user/change_password/', { 'new_password': form.cleaned_data['new_password'] }), request.session) request.session['user'].cm_password = form.cleaned_data[ 'new_password'] request.session.modified = True return messages_ajax.success( _('You have successfully changed your CM password.')) else: form = form_class() return messages_ajax.success(render_to_string( template_name, {'form': form}, context_instance=RequestContext(request)), status=1)
def img_ajax_add_image_http(request, template_name="generic/form.html", form_class=AddImageHttp): """ Ajax view for handling adding image from http link. """ rest_data = prep_data( { "disk_controllers": "user/system_image/get_disk_controllers/", "video_devices": "user/system_image/get_video_devices/", "network_devices": "user/system_image/get_network_devices/", }, request.session, ) if request.method == "POST": form = form_class(data=request.POST, files=request.FILES, rest_data=rest_data) if form.is_valid(): dictionary = form.cleaned_data prep_data(("user/system_image/download/", dictionary), request.session) return messages_ajax.success(_("Image upload started.")) else: form = form_class(rest_data=rest_data) return messages_ajax.success( render_to_string( template_name, {"form": form, "confirmation": _("Add image"), "text": _("Please specify image parameters:")}, context_instance=RequestContext(request), ), status=1, )
def cma_vms_ajax_vm_details(request, vm_id, template_name='admin_cm/ajax/vm_details.html'): """ Ajax view for fetching VM details. """ if request.method == 'POST': vm = prep_data(('admin_cm/vm/get_by_id/', { 'vm_id': vm_id }), request.session) rest_data2 = prep_data( {'user': ('admin_cm/user/get_by_id/', { 'user_id': vm['user_id'] })}, request.session) owner = parse_user(rest_data2['user']) if vm['state'] == vm_states['closed']: return messages_ajax.success('', status=1) vm['uptime'] = time_from_sec(vm['uptime']) return messages_ajax.success( render_to_string(template_name, { 'vm_id': vm_id, 'item': vm, 'states_reversed': vm_states_reversed, 'states': vm_states, 'owner': owner }, context_instance=RequestContext(request)))
def vms_ajax_assign_disk(request, vm_id, template_name='vms/ajax/assign_disk.html', form_class=AssignDiskForm): """ Ajax view for assigning Disk to a virtual machine. """ rest_data = prep_data({'disks': 'user/storage_image/get_list/', 'disk_controllers': 'user/storage_image/get_disk_controllers/' }, request.session) live_attach = [] for item in rest_data['disk_controllers']: if item['live_attach'] == True: live_attach.append(item['id']) disks_list = [] for item in rest_data['disks']: if item['disk_controller'] in live_attach: disks_list.append(item) rest_data['disks'] = disks_list if request.method == 'POST': form = form_class(data=request.POST, rest_data=rest_data) if form.is_valid(): dictionary = form.cleaned_data dictionary.update({'vm_id': vm_id}) prep_data(('user/storage_image/attach/', dictionary), request.session) return messages_ajax.success(_('Disk has been assigned.')) else: form = form_class(rest_data=rest_data) return messages_ajax.success(render_to_string(template_name, {'form': form, 'confirmation': _('Assign')}, context_instance=RequestContext(request)), status=1)
def get_context_data(self, form, **kwargs): context = super(CreateFarmWizard, self).get_context_data(form=form, **kwargs) context.update({'steps_desc': [_('Image'), _('Hardware'), _('Optional resources'), _('Summary')]}) if self.steps.current == '0': rest_data = prep_data({'groups': 'user/group/list_groups/'}, self.request.session) categories = [ ['all', _('All images')], ['private', _('My images')], ['public', _('Public images')], ] for item in parsing.parse_groups(rest_data): categories.append([item[0], _('Group images: ') + item[1]]) context.update({'image_categories': categories}) elif self.steps.current == '1': form_cleaned_data = self.get_all_cleaned_data() rest_data = prep_data({'image': ('user/system_image/get_by_id/', {'system_image_id': form_cleaned_data['image_id']}), }, self.request.session) context.update({'steps_desc': [rest_data['image']['name'] if len(rest_data['image']['name']) <= 15 else rest_data['image']['name'][:15] + '...', _('Hardware'), _('Optional resources'), _('Summary')]}) elif self.steps.current == '2': form_cleaned_data = self.get_all_cleaned_data() rest_data = prep_data({'image': ('user/system_image/get_by_id/', {'system_image_id': form_cleaned_data['image_id']}), 'templates': 'user/template/get_list/', }, self.request.session) template = utils.get_dict_from_list(rest_data['templates'], form_cleaned_data['worker_template_id'], key='template_id') context.update({'steps_desc': [rest_data['image']['name'] if len(rest_data['image']['name']) <= 15 else rest_data['image']['name'][:15] + '...', str(form_cleaned_data['count']) + ' * ' + str(template['cpu']) + '/' + str(template['memory']), _('Optional resources'), _('Summary')]}) elif self.steps.current == '3': form_cleaned_data = self.get_all_cleaned_data() rest_data = prep_data({'image': ('user/system_image/get_by_id/', {'system_image_id': form_cleaned_data['image_id']}), 'templates': 'user/template/get_list/', 'ips': 'user/public_ip/get_list/', 'disks': 'user/storage_image/get_list/', 'iso': 'user/iso_image/get_list/', }, self.request.session) summary_data = {'summary_image': rest_data['image'], 'summary_head_template': utils.get_dict_from_list(rest_data['templates'], form_cleaned_data['head_template_id'], key='template_id'), 'summary_template': utils.get_dict_from_list(rest_data['templates'], form_cleaned_data['worker_template_id'], key='template_id'), 'summary_count': form_cleaned_data['count'], 'summary_ip': utils.get_dict_from_list(rest_data['ips'], form_cleaned_data['public_ip_id'], key='public_ip_id'), 'summary_disks': utils.get_dicts_from_list(rest_data['disks'], form_cleaned_data['disk_list'], key='storage_image_id'), 'summary_iso': utils.get_dicts_from_list(rest_data['iso'], form_cleaned_data['iso_list'], key='iso_image_id'), 'summary_vnc': form_cleaned_data['vnc'], } template = utils.get_dict_from_list(rest_data['templates'], form_cleaned_data['worker_template_id'], key='template_id') context.update({'steps_desc': [rest_data['image']['name'] if len(rest_data['image']['name']) <= 15 else rest_data['image']['name'][:15] + '...', str(form_cleaned_data['count']) + ' * ' + str(template['cpu']) + '/' + str(template['memory']), _('Optional resources'), _('Summary')]}) context.update(summary_data) return context
def done(self, form_list, **kwargs): form_data = self.get_all_cleaned_data() try: prep_data(('user/vm/create/', form_data), self.request.session) except RestErrorException as ex: messages.error(self.request, ex.value) else: messages.success(self.request, _('Virtual machine is being created.')) return redirect(self.url_done)
def get_context_data(self, form, **kwargs): context = super(CreateVMWizard, self).get_context_data(form=form, **kwargs) context.update({'steps_desc': [_('Image'), _('Hardware'), _('Optional resources'), _('Summary')]}) if self.steps.current == '0': rest_data = prep_data({'groups': 'user/group/list_groups/'}, self.request.session) categories = [ ['all', _('All images')], ['private', _('My images')], ['public', _('Public images')], ] for item in parsing.parse_groups(rest_data): categories.append([item[0], _('Group images: ') + item[1]]) context.update({'image_categories': categories}) elif self.steps.current == '1': form_cleaned_data = self.get_all_cleaned_data() rest_data = prep_data({'image': ('user/system_image/get_by_id/', {'system_image_id': form_cleaned_data['image_id']}), }, self.request.session) context.update({'steps_desc': [rest_data['image']['name'] if len(rest_data['image']['name']) <= 15 else rest_data['image']['name'][:15] + '...', _('Hardware'), _('Optional resources'), _('Summary')]}) elif self.steps.current == '2': form_cleaned_data = self.get_all_cleaned_data() rest_data = prep_data({'image': ('user/system_image/get_by_id/', {'system_image_id': form_cleaned_data['image_id']}), 'templates': 'user/template/get_list/', }, self.request.session) template = utils.get_dict_from_list(rest_data['templates'], form_cleaned_data['template_id'], key='template_id') context.update({'steps_desc': [rest_data['image']['name'] if len(rest_data['image']['name']) <= 15 else rest_data['image']['name'][:15] + '...', str(template['cpu']) + '/' + str(template['memory']), _('Optional resources'), _('Summary')]}) elif self.steps.current == '3': form_cleaned_data = self.get_all_cleaned_data() rest_data = prep_data({'image': ('user/system_image/get_by_id/', {'system_image_id': form_cleaned_data['image_id']}), 'templates': 'user/template/get_list/', 'ips': 'user/public_ip/get_list/', 'disks': 'user/storage_image/get_list/', 'iso': 'user/iso_image/get_list/', }, self.request.session) summary_data = {'summary_image': rest_data['image'], 'summary_template': utils.get_dict_from_list(rest_data['templates'], form_cleaned_data['template_id'], key='template_id'), 'summary_ip': utils.get_dict_from_list(rest_data['ips'], form_cleaned_data['public_ip_id'], key='public_ip_id'), 'summary_disks': utils.get_dicts_from_list(rest_data['disks'], form_cleaned_data['disk_list'], key='storage_image_id'), 'summary_iso': utils.get_dicts_from_list(rest_data['iso'], form_cleaned_data['iso_list'], key='iso_image_id'), 'summary_vnc': form_cleaned_data['vnc'], } template = utils.get_dict_from_list(rest_data['templates'], form_cleaned_data['template_id'], key='template_id') context.update({'steps_desc': [rest_data['image']['name'] if len(rest_data['image']['name']) <= 15 else rest_data['image']['name'][:15] + '...', str(template['cpu']) + '/' + str(template['memory']), _('Optional resources'), _('Summary')]}) context.update(summary_data) return context
def done(self, form_list, **kwargs): """ Action executed on last step submition. """ form_data = self.get_all_cleaned_data() try: prep_data({'farm': ('user/farm/create/', form_data)}, self.request.session) except RestErrorException as ex: messages.error(self.request, ex.value) else: messages.success(self.request, _('Farm is being created.')) return redirect(self.url_done)
def grp_ajax_send_request(request, group_id, template_name='generic/simple.html'): """ Ajax view for sending group request membership. """ if request.method == 'POST': prep_data(('user/group/join_request/', {'group_id': group_id}), request.session) return messages_ajax.success(_('You have successfully sent a request.')) else: return messages_ajax.success(render_to_string(template_name, {'confirmation': _('Yes'), 'text': _('Do you want to send a request?')}, context_instance=RequestContext(request)))
def cma_ajax_get_cm_data(request): """ Ajax view for fetching CM data (quotas etc.). """ if request.method == "GET": rest_data = prep_data( {"cm_data": "admin_cm/cluster/get_data/", "nodes": "admin_cm/node/get_list/"}, request.session ) data = rest_data["cm_data"] total_cpu = 0 total_mem = 0 free_cpu = 0 free_mem = 0 for node in rest_data["nodes"]: node["stateName"] = unicode(node_states[node["state"]]) if node["state"] == 1: free_cpu += node["cpu_free"] free_mem += node["memory_free"] total_cpu += node["cpu_total"] total_mem += node["memory_total"] data["free_cpu"] = free_cpu data["free_mem"] = filesizeformatmb(free_mem) data["total_cpu"] = total_cpu data["total_mem"] = filesizeformatmb(total_mem) data["stateName"] = unicode(cm_states[data["state"]]) return messages_ajax.success(data)
def far_ajax_get_table(request): """ Ajax view for fetching farm list. """ if request.method == 'GET': rest_data = prep_data('user/farm/get_list/', request.session) for item in rest_data: item['uptime'] = time_from_sec(item['uptime']) item['stateName'] = unicode(farm_states[item['state']]) item['stateTooltip'] = unicode(farm_states_help[item['state']]) for vm in item['vms']: vm['stateName'] = unicode(vm_states_reversed[vm['state']]) vm['pub_ip'] = [] for i in vm['leases']: if i['public_ip'] != "": vm['pub_ip'].append(i['public_ip']['address']) vm['priv_ip'] = [] for i in vm['leases']: vm['priv_ip'].append(i['address']) vm['cpuLoadPercent'] = int( min(float(vm['cpu_load'].get('60') or 0) * 100, 100)) vm['cpuLoadColor'] = "#%02x%02x%02x" % tuple( i * 255 for i in hsv_to_rgb( float(vm['cpuLoadPercent']) / 300, 1.0, 0.8)) return messages_ajax.success(rest_data)
def cma_networks(request, template_name='admin_cm/networks.html'): """ View rendering network list. """ rest_data = prep_data('admin_cm/user/get_list/', request.session) return render_to_response(template_name, {'all_users': rest_data}, context_instance=RequestContext(request))
def grp_ajax_grp_details_table(request, group_id): """ Ajax view for fetching group details. """ if request.method == 'GET': user = request.session['user'] rest_data = prep_data({'group_data': ('user/group/get_by_id/', {'group_id': group_id}), 'members': ('user/group/list_members/', {'group_id': group_id}), 'requests': ('user/group/list_requests/', {'group_id': group_id}) }, request.session) leader_id = rest_data['group_data'].get('leader_id') leader = True if leader_id == '': leader = False else: if int(user.user_id) != int(leader_id): leader = False for item in rest_data['members']: item['request'] = False item['leader'] = leader item['self'] = True if int(item['user_id']) == int(user.user_id) else False item['group_id'] = group_id for item in rest_data['requests']: item['request'] = True item['leader'] = leader item['self'] = True if int(item['user_id']) == int(user.user_id) else False item['group_id'] = group_id return messages_ajax.success([{'name':_('Members:'), 'items': rest_data['members']}, {'name':_('Requests:'), 'items': rest_data['requests']}])
def cma_ajax_get_table_images(request): """ Ajax view for fetching images list. """ if request.method == 'GET': rest_data = prep_data({'images_public': ('admin_cm/system_image/get_list/', {'access': image_access['public']}), 'images_private': ('admin_cm/system_image/get_list/', {'access': image_access['private']}), 'images_group': ('admin_cm/system_image/get_list/', {'access': image_access['group']})}, request.session) for item in rest_data['images_public']: item['size'] = unicode(filesizeformatmb(item['size'])) item['type'] = 'public' item['stateName'] = image_states_reversed[item['state']] list_images = [{'name': unicode(_('Public:')), 'items': rest_data['images_public']}] for item in rest_data['images_private']: item['size'] = unicode(filesizeformatmb(item['size'])) item['type'] = 'private' item['stateName'] = image_states_reversed[item['state']] list_images.append({'name': unicode(_('Private:')), 'items': rest_data['images_private']}) for group in rest_data['images_group']: for item in group['images']: item['size'] = unicode(filesizeformatmb(item['size'])) item['type'] = 'group' item['stateName'] = image_states_reversed[item['state']] list_images.append({'name': unicode(_('Group:')) + ' ' + group['name'], 'items': group['images']}) return messages_ajax.success(list_images)
def img_ajax_get_group_table(request): """ Ajax view for fetching group images list. """ if request.method == 'GET': rest_data = prep_data( { 'own_groups': 'user/group/list_own_groups/', 'group_images': ('user/system_image/get_list/', { 'access': image_access['group'] }), }, request.session) leader = parsing.parse_own_groups(rest_data) group_list = [] for group in rest_data['group_images']: group_images_list = [] for item in group['images']: item['stateName'] = unicode( image_states_reversed[item['state']]) item['size'] = filesizeformatmb(item['size']) item['mine'] = True if item['user_id'] == request.session[ 'user'].user_id else False item['myGroup'] = True if item['group_id'] in leader else False group_images_list.append(item) group_list.append({ 'name': group['name'], 'items': group_images_list, 'group_id': group['group_id'] }) return messages_ajax.success(group_list)
def mai_ajax_get_news_table(request): """ Ajax view for fetching news list (whole). """ if request.method == 'GET': response = prep_data('guest/news/get_list/', request.session) return messages_ajax.success(response)
def far_ajax_get_table(request): """ Ajax view for fetching farm list. """ if request.method == 'GET': rest_data = prep_data('user/farm/get_list/', request.session) for item in rest_data: item['uptime'] = time_from_sec(item['uptime']) item['stateName'] = unicode(farm_states[item['state']]) item['stateTooltip'] = unicode(farm_states_help[item['state']]) for vm in item['vms']: vm['stateName'] = unicode(vm_states_reversed[vm['state']]) vm['pub_ip'] = [] for i in vm['leases']: if i['public_ip'] != "": vm['pub_ip'].append(i['public_ip']['address']) vm['priv_ip'] = [] for i in vm['leases']: vm['priv_ip'].append(i['address']) vm['cpuLoadPercent'] = int(min(float(vm['cpu_load'].get('60') or 0) * 100, 100)) vm['cpuLoadColor'] = "#%02x%02x%02x" % tuple(i * 255 for i in hsv_to_rgb(float(vm['cpuLoadPercent']) / 300, 1.0, 0.8)) return messages_ajax.success(rest_data)
def cma_ajax_get_cm_data(request): """ Ajax view for fetching CM data (quotas etc.). """ if request.method == 'GET': rest_data = prep_data( { 'cm_data': 'admin_cm/cluster/get_data/', 'nodes': 'admin_cm/node/get_list/' }, request.session) data = rest_data['cm_data'] total_cpu = 0 total_mem = 0 free_cpu = 0 free_mem = 0 for node in rest_data['nodes']: node['stateName'] = unicode(node_states[node['state']]) if node['state'] == 1: free_cpu += node['cpu_free'] free_mem += node['memory_free'] total_cpu += node['cpu_total'] total_mem += node['memory_total'] data['free_cpu'] = free_cpu data['free_mem'] = filesizeformatmb(free_mem) data['total_cpu'] = total_cpu data['total_mem'] = filesizeformatmb(total_mem) data['stateName'] = unicode(cm_states[data['state']]) return messages_ajax.success(data)
def cma_vms(request, template_name='admin_cm/show_vm.html'): """ View handling the page embeding the VM list. """ users = prep_data('admin_cm/user/get_list/', request.session) return render_to_response(template_name, {'all_users': users}, context_instance=RequestContext(request))
def cma_networks_ajax_get_table(request, user_id): """ Ajax view returning network list. """ if request.method == 'GET': networks = prep_data(('admin_cm/network/list_user_networks/', {'user_id': int(user_id)}), request.session) return messages_ajax.success(networks)
def res_ajax_generate_key(request, template_name='generic/form.html', form_class=GenerateKeyForm): """ Ajax view for ssh key generation. """ if request.method == 'POST': form = form_class(request.POST) if form.is_valid(): rest_data = prep_data( { 'key': ('user/key/generate/', { 'name': form.cleaned_data['name'] }) }, request.session) return messages_ajax.success_with_key( _("You have successfully generated a key"), rest_data['key'], form.cleaned_data['name']) else: form = form_class() return messages_ajax.success(render_to_string(template_name, { 'form': form, 'confirmation': _('Generate'), 'text': _('2048-bit RSA key<br /><b>Note!</b> We don\'t keep a copy of your private key. We can\'t recreate it if your key is lost.' ) }, context_instance= RequestContext(request)), status=1)
def img_ajax_get_group_table(request): """ Ajax view for fetching group images list. """ if request.method == "GET": rest_data = prep_data( { "own_groups": "user/group/list_own_groups/", "group_images": ("user/system_image/get_list/", {"access": image_access["group"]}), }, request.session, ) leader = parsing.parse_own_groups(rest_data) group_list = [] for group in rest_data["group_images"]: group_images_list = [] for item in group["images"]: item["stateName"] = unicode(image_states_reversed[item["state"]]) item["size"] = filesizeformatmb(item["size"]) item["mine"] = True if item["user_id"] == request.session["user"].user_id else False item["myGroup"] = True if item["group_id"] in leader else False group_images_list.append(item) group_list.append({"name": group["name"], "items": group_images_list, "group_id": group["group_id"]}) return messages_ajax.success(group_list)
def add_variables(request): """ Context processor for attaching CM list and other data to every request. """ if request.session.get('user') == None: return {} try: rest_data = prep_data('guest/cluster/list_names/', request.session) except RestErrorException as ex: messages.error(request, ex.value) wi_logger = logging.getLogger('wi_logger') wi_logger.error('%s' % ex.value) return {} cm_list = rest_data none_available = True for item in cm_list: if item['state'] == cluster_states['ok']: none_available = False break if none_available: messages.error(request, _('No CM available.')) admin_cm_name = None for item in cm_list: if request.session['user'].is_logged_admin_cm and request.session['user'].cm_id == item['cluster_id']: admin_cm_name = item['name'] return {'cm_list': cm_list, 'cluster_states': cluster_states, 'admin_cm_name': admin_cm_name, 'VERSION': settings.VERSION}
def cma_farms_ajax_get_table(request, user_id): """ Ajax view for fetching farms list. """ if request.method == 'GET': farms = prep_data(('admin_cm/farm/get_list/', {'user_id': int(user_id)}), request.session) for farm in farms: farm['stateName'] = unicode(farm_states_reversed[farm['state']]) for vm in farm['vms']: vm['pub_ip'] = [] for i in vm['leases']: if i['public_ip'] != "": vm['pub_ip'].append(i['public_ip']['address']) vm['priv_ip'] = [] for i in vm['leases']: vm['priv_ip'].append(i['address']) farm['stringIP'] = ', '.join(farm['vms'][0]['priv_ip']) farm['stringPubIP'] = ', '.join(farm['vms'][0]['pub_ip']) farm['stringDisk'] = ', '.join([disk['name'] for disk in farm['vms'][0]['storage_images']]) farm['stringISO'] = ', '.join([iso['name'] for iso in farm['vms'][0]['iso_images']]) return messages_ajax.success(farms)
def cma_ajax_get_cm_data(request): """ Ajax view for fetching CM data (quotas etc.). """ if request.method == 'GET': rest_data = prep_data({'cm_data': 'admin_cm/cluster/get_data/', 'nodes': 'admin_cm/node/get_list/' }, request.session) data = rest_data['cm_data'] total_cpu = 0 total_mem = 0 free_cpu = 0 free_mem = 0 for node in rest_data['nodes']: node['stateName'] = unicode(node_states[node['state']]) if node['state'] == 1: free_cpu += node['cpu_free'] free_mem += node['memory_free'] total_cpu += node['cpu_total'] total_mem += node['memory_total'] data['free_cpu'] = free_cpu data['free_mem'] = filesizeformatmb(free_mem) data['total_cpu'] = total_cpu data['total_mem'] = filesizeformatmb(total_mem) data['stateName'] = unicode(cm_states[data['state']]) return messages_ajax.success(data)
def get_form_kwargs(self, step=None): step = int(step) initial_data = {} if step == 1: rest_data = prep_data({'templates': 'user/template/get_list/'}, self.request.session) initial_data = {'rest_data': rest_data, 'session': self.request.session} if step == 2: rest_data = prep_data({'ips': 'user/public_ip/get_list/', 'disks': 'user/storage_image/get_list/', 'iso': 'user/iso_image/get_list/', }, self.request.session) initial_data = {'rest_data': rest_data} return initial_data
def cma_ajax_change_cm_password(request, template_name='admin_cm/ajax/change_password.html', form_class=PasswordForm): """ Ajax view for changing logged CM admin password. """ if request.method == 'POST': form = form_class(request.POST) if form.is_valid(): prep_data(('admin_cm/user/change_password/', {'new_password': form.cleaned_data['new_password']}), request.session) request.session['user'].cm_password = form.cleaned_data['new_password'] request.session.modified = True return messages_ajax.success(_('You have successfully changed your CM password.')) else: form = form_class() return messages_ajax.success(render_to_string(template_name, {'form': form}, context_instance=RequestContext(request)), status=1)
def cma_networks_ajax_get_table(request, user_id): """ Ajax view returning network list. """ if request.method == 'GET': networks = prep_data(('admin_cm/network/list_user_networks/', { 'user_id': int(user_id) }), request.session) return messages_ajax.success(networks)
def mai_ajax_get_main_news_table(request): """ Ajax view for fetching news list (first 3). """ if request.method == 'GET': response = prep_data('guest/news/get_list/', request.session) sticky_news = [x for x in response if x['sticky'] == 1][:3] return messages_ajax.success(sticky_news)
def acc_password_reset_confirm(request, uidb36=None, token=None, template_name='account/password_reset_confirm.html', form_class=SetPasswordForm): """ Check whether given address hash is correct. Displayes <b>password edition</b> form. @code acc_password_reset_confirm(request, uidb36=None, token=None, template_name='account/password_reset_confirm.html', form_class=SetPasswordForm) @endcode @parameter{request} @parameter{uidb36} optional @parameter{token} optional @parameter{template_name} optional @parameter{form_class} optional """ assert uidb36 is not None and token is not None # checked by URLconf try: uid_int = base36_to_int(uidb36) except ValueError: raise Http404 if request.method == 'POST': form = form_class(request.POST) if form.is_valid(): dictionary = {'user_id': uid_int, 'token': token, 'new_password': form.cleaned_data['new_password1']} try: prep_data(('guest/user/set_password_token/', dictionary), request.session) except Exception: return redirect('acc_password_reset_error_token') return redirect('acc_password_reset_complete') else: try: prep_data(('guest/user/check_token/', {'user_id': uid_int, 'token': token}), request.session) except Exception: return redirect('acc_password_reset_error_token') form = form_class() return render_to_response(template_name, {'form': form}, context_instance=RequestContext(request))
def res_ajax_get_iso_table(request): """ Ajax view returning iso images list. """ if request.method == 'GET': rest_data = prep_data('user/iso_image/get_list/', request.session) for item in rest_data: item['size'] = filesizeformatmb(item['size']) return messages_ajax.success(rest_data)
def cma_networks_ajax_network_details(request, network_id, template_name='admin_cm/ajax/network_details.html'): """ Ajax view fetching network details. """ if request.method == 'POST': net = prep_data(('admin_cm/network/list_leases/', {'network_id': network_id}), request.session) return messages_ajax.success(render_to_string(template_name, {'id': int(network_id), 'item': net}, context_instance=RequestContext(request)))
def acc_password_change(request, template_name='account/password_change_form.html', password_change_form=PasswordChangeForm): """ View for password changing (for logged users). """ if request.method == "POST": form = password_change_form(user=request.session['user'], data=request.POST) if form.is_valid(): new_password = form.cleaned_data['new_password1'] try: prep_data(('user/user/set_password/', {'new_password': new_password}), request.session) except RestErrorException as ex: messages.error(request, ex.value) request.session['user'].set_password(new_password) request.session.modified = True return redirect('acc_password_change_done') else: form = password_change_form(user=request.session['user']) return render_to_response(template_name, {'form': form}, context_instance=RequestContext(request))
def clm_ajax_get_table_users(request): """ Ajax view for fetching users list. """ if request.method == 'GET': users = prep_data('admin_clm/user/get_list/', request.session) for item in users: item['is_activeName'] = unicode(user_states[item['is_active']]) return messages_ajax.success(users)
def get_messages(request): """ Ajax view fetching user messages. """ if request.method == 'POST': response = prep_data('user/message/get_list/', request.session) for item in response: item['text'] = get_message(item['code'], item['params']) item['level'] = message_levels_reversed[item['level']] return messages_ajax.success(response)
def clm_ajax_get_table_cms(request): """ Ajax view for fetching Cluster Manager list. """ if request.method == 'GET': cms = prep_data('admin_clm/cluster/get_list/', request.session) for item in cms: item['is_activeName'] = unicode(cm_states[item['state']]) return messages_ajax.success(cms)
def cma_ajax_get_table_iso(request): """ Ajax view for fetching ISO images list. """ if request.method == 'GET': iso = prep_data('admin_cm/iso_image/get_list/', request.session) for item in iso: item['size'] = filesizeformatmb(item['size']) return messages_ajax.success(iso)
def cma_ajax_node_details(request, node_id, template_name='admin_cm/ajax/node_details.html'): """ Ajax view fetching node details. """ if request.method == 'POST': node = prep_data(('admin_cm/node/get_by_id_details/', {'node_id': node_id}), request.session) return messages_ajax.success(render_to_string(template_name, {'node_id': node_id, 'node': node, 'node_states': node_states }, context_instance=RequestContext(request)))
def cma_ajax_get_table_disks(request): """ Ajax view for fetching disks list. """ if request.method == 'GET': disks = prep_data('admin_cm/storage_image/get_list/', request.session) for item in disks: item['size'] = filesizeformatmb(item['size']) return messages_ajax.success(disks)