def __init__(self, request, *args, **kwargs): super(UpdateGroupInstancesAction, self).__init__(request, *args, **kwargs) err_msg = _('Unable to retrieve instances list. ' 'Please try again later.') context = args[0] group_id = context.get('group_id') default_role_field_name = self.get_default_role_field_name() self.fields[default_role_field_name] = forms.CharField(required=False) self.fields[default_role_field_name].initial = 'member' field_name = self.get_member_field_name('member') self.fields[field_name] = forms.MultipleChoiceField(required=False) # Get list of available projects. all_instances = [] try: all_instances, hasmore = api.nova.server_list(self.request) except Exception: exceptions.handle(request, err_msg) groups = [] try: groups = client(request).get_groups() except Exception: exceptions.handle(request, 'Can\'t retrieve group list. Try again') except_inst_ids = [] for g in groups: if g.id == group_id: continue except_inst_ids = except_inst_ids + [ inst['instance_id'] for inst in g.instances ] instances_list = [(inst.id, inst.name) for inst in all_instances \ if inst.status == 'ACTIVE' and inst.id not in except_inst_ids] self.fields[field_name].choices = instances_list # If we have a POST from the CreateFlavor workflow, the flavor id # isn't an existing flavor. For the UpdateFlavor case, we don't care # about the access list for the current flavor anymore as we're about # to replace it. if request.method == 'POST': return # Get list of flavor projects if the flavor is not public. group_instances = [] try: if group_id: group = client(request).get_group(group_id) group_instances = group.instances except Exception: exceptions.handle(request, err_msg) self.fields[field_name].initial = group_instances
def clean(self): cleaned_data = super(AddGroupInfoAction, self).clean() name = cleaned_data.get('name') group_id = cleaned_data.get('group_id') try: groups = client(self.request).get_groups() except Exception: groups = [] msg = _('Unable to get groups list') exceptions.check_message(["Connection", "refused"], msg) raise if groups is not None and name is not None: for group in groups: if group.name.lower() == name.lower(): raise forms.ValidationError( _('The name "%s" is already used by another group.') % name) if group.id == group_id: raise forms.ValidationError( _('The ID "%s" is already used by another group.') % group_id) cleaned_data['script_data'] = normalize_newlines( cleaned_data['script_data']) # files = self.request.FILES # script = self.clean_uploaded_files('script', files) # # if script is not None: # cleaned_data['script_data'] = script return cleaned_data
def clean(self): name = self.cleaned_data.get('name') group_id = self.cleaned_data.get('group_id') try: groups = client(self.request).get_groups() except Exception: groups = [] msg = _('Unable to get groups list') exceptions.check_message(["Connection", "refused"], msg) raise # Check if there is no group with the same name if groups is not None and name is not None: for group in groups: if (group.name.lower() == name.lower() and group.group_id != group_id): raise forms.ValidationError( _('The name "%s" is already used by another ' 'group.') % name) self.cleaned_data['script_data'] = \ normalize_newlines(self.cleaned_data['script_data']) # files = self.request.FILES # script = self.clean_uploaded_files('script', files) # # if script is not None: # self.cleaned_data['script_data'] = script return self.cleaned_data
def get_data(self, request, context, *args, **kwargs): context = super(Step2View, self).get_context_data(**kwargs) # return get_group_context(self, request, context, *args, **kwargs) try: group = client(request).get_group(kwargs['id']) except Exception: pass context['group'] = { 'id': kwargs['id'], 'name': group.name if group else "" } return context
def get_data(self): try: groups = client(self.request).get_groups() print(groups) if not groups: return [] groups = get_group_view_data(self.request, groups) for group in groups: if group.instances is not None: group.instances = '\n'.join(group.instances) return groups except Exception: err_msg = _('Can\'t retrieve group list') exceptions.handle(self.request, err_msg) return []
def get_initial(self): id = self.kwargs['id'] try: # Get initial group information group = client(self.request).get_group(id) if not group: raise except Exception as e: print(e) group = None exceptions.handle(self.request, _('Unable to retrieve group details.'), redirect=reverse_lazy(INDEX_URL)) if group is not None: group = get_group_view_data(self.request, [ group, ])[0] return group.to_dict() else: return GroupData().to_dict()
def create_group(request, group): return client(request).add_group(group)
def drop_group(request, group_id): client(request).drop_group(group_id)
def get_group_log(request, id): return client(request).get_group_log(id)
def update_group(request, group, id): return client(request).update_group(group, id)