-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refacto globalhook
- Loading branch information
Showing
37 changed files
with
636 additions
and
651 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,14 @@ | ||
from django.forms import SelectMultiple | ||
from django_filters import MultipleChoiceFilter | ||
|
||
from Squest.utils.squest_filter import SquestFilter | ||
from service_catalog.models import GlobalHook | ||
from service_catalog.models.instance import InstanceState | ||
from service_catalog.models.request import RequestState | ||
from service_catalog.models.state_hooks import HookModel | ||
from service_catalog.models import InstanceHook, RequestHook | ||
|
||
|
||
class GlobalHookFilter(SquestFilter): | ||
class InstanceHookFilter(SquestFilter): | ||
class Meta: | ||
model = GlobalHook | ||
fields = ['name', 'model'] | ||
|
||
model = MultipleChoiceFilter( | ||
choices=HookModel.choices, | ||
widget=SelectMultiple()) | ||
|
||
state_instance = MultipleChoiceFilter( | ||
label="Instance state", | ||
method='add_states_in_filter', | ||
choices=InstanceState.choices, | ||
null_value=None, | ||
widget=SelectMultiple(attrs={'data-live-search': "true"})) | ||
model = InstanceHook | ||
fields = ['name', 'state'] | ||
|
||
state_request = MultipleChoiceFilter( | ||
label="Request state", | ||
method='add_states_in_filter', | ||
choices=RequestState.choices, | ||
null_value=None, | ||
widget=SelectMultiple(attrs={'data-live-search': "true"})) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(GlobalHookFilter, self).__init__(*args, **kwargs) | ||
self.state_filter_value = list() | ||
|
||
def add_states_in_filter(self, queryset, field_name, value): | ||
self.state_filter_value += value | ||
return queryset | ||
|
||
def filter_queryset(self, queryset): | ||
queryset = super(GlobalHookFilter, self).filter_queryset(queryset) | ||
tmp = self.state_filter_value | ||
self.state_filter_value = [] | ||
return queryset.filter(state__in=tmp) | ||
class RequestHookFilter(SquestFilter): | ||
class Meta: | ||
model = RequestHook | ||
fields = ['name', 'state'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,14 @@ | ||
from django import forms | ||
from django.core.exceptions import ValidationError | ||
from django.forms import ChoiceField | ||
|
||
from Squest.utils.squest_model_form import SquestModelForm | ||
from service_catalog.models import GlobalHook | ||
from service_catalog.models.instance import InstanceState | ||
from service_catalog.models.request import RequestState | ||
|
||
from service_catalog.models import InstanceHook, RequestHook | ||
|
||
class GlobalHookForm(SquestModelForm): | ||
def __init__(self, *args, **kwargs): | ||
super(GlobalHookForm, self).__init__(*args, **kwargs) | ||
self.fields['operation'].widget.attrs['class'] = 'form-control' | ||
self.fields['state'] = ChoiceField(label="State", | ||
choices=InstanceState.choices + RequestState.choices, | ||
error_messages={'required': 'At least you must select one state'}, | ||
widget=forms.Select(attrs={'class': 'form-control'})) | ||
|
||
def clean(self): | ||
cleaned_data = super(GlobalHookForm, self).clean() | ||
model = cleaned_data.get('model') | ||
state = cleaned_data.get('state') | ||
class InstanceHookForm(SquestModelForm): | ||
class Meta: | ||
model = InstanceHook | ||
fields = ["name", "service", "state", "job_template", "extra_vars"] | ||
|
||
choices = "" | ||
if model == "Request": | ||
choices = RequestState.choices | ||
if model == "Instance": | ||
choices = InstanceState.choices | ||
if state not in (choice[0] for choice in choices): | ||
raise ValidationError({ | ||
'state': f"'{state}' is not a valid state of model '{model}'" | ||
}) | ||
return cleaned_data | ||
|
||
class RequestHookForm(SquestModelForm): | ||
class Meta: | ||
model = GlobalHook | ||
fields = ["name", "model", "service", "operation", "state", "job_template", "extra_vars"] | ||
model = RequestHook | ||
fields = ["name", "operation", "state", "job_template", "extra_vars"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Generated by Django 3.2.13 on 2023-09-12 14:52 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('service_catalog', '0023_auto_20230912_1524'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 1 WHERE state = "SUBMITTED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 2 WHERE state = "NEED_INFO";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 3 WHERE state = "REJECTED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 4 WHERE state = "ACCEPTED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 5 WHERE state = "CANCELED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 6 WHERE state = "PROCESSING";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 7 WHERE state = "COMPLETE";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 8 WHERE state = "FAILED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 9 WHERE state = "ARCHIVED";'), | ||
|
||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 1 WHERE state = "SUBMITTED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 1 WHERE state = "PENDING";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 2 WHERE state = "PROVISION_FAILED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 3 WHERE state = "PROVISIONING";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 4 WHERE state = "UPDATING";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 5 WHERE state = "UPDATE_FAILED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 6 WHERE state = "DELETING";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 7 WHERE state = "DELETED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 8 WHERE state = "DELETE_FAILED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 9 WHERE state = "ARCHIVED";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 10 WHERE state = "AVAILABLE";'), | ||
migrations.RunSQL('UPDATE service_catalog_globalhook SET state = 11 WHERE state = "ABORTED";'), | ||
|
||
migrations.AlterField( | ||
model_name='globalhook', | ||
name='state', | ||
field=models.IntegerField(), | ||
), | ||
migrations.DeleteModel( | ||
name='GlobalHook', | ||
), | ||
migrations.CreateModel( | ||
name='InstanceHook', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created', models.DateTimeField(auto_now_add=True, null=True)), | ||
('last_updated', models.DateTimeField(auto_now=True, null=True)), | ||
('name', models.CharField(max_length=100, unique=True)), | ||
('extra_vars', models.JSONField(blank=True, default=dict)), | ||
('state', models.IntegerField( | ||
choices=[(1, 'PENDING'), (2, 'PROVISION_FAILED'), (3, 'PROVISIONING'), (4, 'UPDATING'), | ||
(5, 'UPDATE_FAILED'), (6, 'DELETING'), (7, 'DELETED'), (8, 'DELETE_FAILED'), | ||
(9, 'ARCHIVED'), (10, 'AVAILABLE'), (11, 'ABORTED')])), | ||
('job_template', | ||
models.ForeignKey(on_delete=models.deletion.CASCADE, to='service_catalog.jobtemplate')), | ||
('service', | ||
models.ForeignKey(blank=True, default=None, null=True, on_delete=models.deletion.SET_NULL, | ||
to='service_catalog.service')), | ||
], | ||
options={ | ||
'abstract': False, | ||
'default_permissions': ('add', 'change', 'delete', 'view', 'list'), | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='RequestHook', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created', models.DateTimeField(auto_now_add=True, null=True)), | ||
('last_updated', models.DateTimeField(auto_now=True, null=True)), | ||
('name', models.CharField(max_length=100, unique=True)), | ||
('extra_vars', models.JSONField(blank=True, default=dict)), | ||
('state', models.IntegerField( | ||
choices=[(1, 'SUBMITTED'), (2, 'NEED_INFO'), (3, 'REJECTED'), (4, 'ACCEPTED'), (5, 'CANCELED'), | ||
(6, 'PROCESSING'), (7, 'COMPLETE'), (8, 'FAILED'), (9, 'ARCHIVED')])), | ||
('job_template', | ||
models.ForeignKey(on_delete=models.deletion.CASCADE, to='service_catalog.jobtemplate')), | ||
('operation', | ||
models.ForeignKey(blank=True, default=None, null=True, on_delete=models.deletion.SET_NULL, | ||
to='service_catalog.operation')), | ||
], | ||
options={ | ||
'abstract': False, | ||
'default_permissions': ('add', 'change', 'delete', 'view', 'list'), | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.