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 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 res_ajax_get_disk_table(request): """ Ajax view for fetching disk list. """ if request.method == 'GET': rest_data = prep_data({'disks': 'user/storage_image/get_list/', 'disk_controllers': 'user/storage_image/get_disk_controllers/'}, request.session) for item in rest_data['disks']: item['size'] = filesizeformatmb(item['size']) item['bus'] = get_dict_from_list(rest_data['disk_controllers'], item['disk_controller'])['name'] return messages_ajax.success(rest_data['disks'])
def acc_ajax_get_user_data(request): """ Ajax view. Returns user account data. """ if request.method == 'GET': rest_data = prep_data({'user': '******', 'cms': 'guest/cluster/list_names/' }, request.session) user_data = rest_data['user'] users_cm = get_dict_from_list(rest_data['cms'], user_data['default_cluster_id'], key='cluster_id') if users_cm is None: raise Exception('User\'s default_cluster_id=%d is not a valid CM id.' % user_data['default_cluster_id']) user_data['default_cluster_id'] = users_cm['name'] return messages_ajax.success(user_data)
def res_ajax_get_disk_table(request): """ Ajax view for fetching disk list. """ if request.method == 'GET': rest_data = prep_data( { 'disks': 'user/storage_image/get_list/', 'disk_controllers': 'user/storage_image/get_disk_controllers/' }, request.session) for item in rest_data['disks']: item['size'] = filesizeformatmb(item['size']) item['bus'] = get_dict_from_list(rest_data['disk_controllers'], item['disk_controller'])['name'] return messages_ajax.success(rest_data['disks'])
def acc_ajax_get_user_data(request): """ Ajax view. Returns user account data. """ if request.method == 'GET': rest_data = prep_data( { 'user': '******', 'cms': 'guest/cluster/list_names/' }, request.session) user_data = rest_data['user'] users_cm = get_dict_from_list(rest_data['cms'], user_data['default_cluster_id'], key='cluster_id') if users_cm is None: raise Exception( 'User\'s default_cluster_id=%d is not a valid CM id.' % user_data['default_cluster_id']) user_data['default_cluster_id'] = users_cm['name'] return messages_ajax.success(user_data)