Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
5
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c486bc51
authored
2 years ago
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validation ci data
parent
5c8fa224
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
15 deletions
+25
-15
circle/dashboard/forms.py
+6
-7
circle/dashboard/validators.py
+17
-0
circle/vm/models/instance.py
+2
-8
No files found.
circle/dashboard/forms.py
View file @
c486bc51
...
@@ -60,7 +60,7 @@ from vm.models import (
...
@@ -60,7 +60,7 @@ from vm.models import (
InstanceTemplate
,
Lease
,
InterfaceTemplate
,
Node
,
Trait
,
Instance
InstanceTemplate
,
Lease
,
InterfaceTemplate
,
Node
,
Trait
,
Instance
)
)
from
.models
import
Profile
,
GroupProfile
,
Message
from
.models
import
Profile
,
GroupProfile
,
Message
from
.validators
import
domain_validator
from
.validators
import
domain_validator
,
meta_data_validator
,
user_data_validator
LANGUAGES_WITH_CODE
=
((
l
[
0
],
ugettext_lazy
(
l
[
1
],
" ("
,
l
[
0
],
")"
))
LANGUAGES_WITH_CODE
=
((
l
[
0
],
ugettext_lazy
(
l
[
1
],
" ("
,
l
[
0
],
")"
))
for
l
in
LANGUAGES
)
for
l
in
LANGUAGES
)
...
@@ -569,6 +569,9 @@ class TemplateForm(forms.ModelForm):
...
@@ -569,6 +569,9 @@ class TemplateForm(forms.ModelForm):
self
.
fields
[
'raw_data'
]
.
validators
.
append
(
domain_validator
)
self
.
fields
[
'raw_data'
]
.
validators
.
append
(
domain_validator
)
self
.
fields
[
'ci_user_data'
]
.
validators
.
append
(
user_data_validator
)
self
.
fields
[
'ci_meta_data'
]
.
validators
.
append
(
meta_data_validator
)
def
clean_owner
(
self
):
def
clean_owner
(
self
):
if
self
.
instance
.
pk
is
not
None
:
if
self
.
instance
.
pk
is
not
None
:
return
User
.
objects
.
get
(
pk
=
self
.
instance
.
owner
.
pk
)
return
User
.
objects
.
get
(
pk
=
self
.
instance
.
owner
.
pk
)
...
@@ -1535,9 +1538,11 @@ class RawDataForm(forms.ModelForm):
...
@@ -1535,9 +1538,11 @@ class RawDataForm(forms.ModelForm):
class
CIDataForm
(
forms
.
ModelForm
):
class
CIDataForm
(
forms
.
ModelForm
):
ci_meta_data
=
forms
.
CharField
(
disabled
=
True
,
help_text
=
'meta-data'
,
ci_meta_data
=
forms
.
CharField
(
disabled
=
True
,
help_text
=
'meta-data'
,
validators
=
[
meta_data_validator
],
widget
=
forms
.
Textarea
(
attrs
=
{
'rows'
:
5
}),
widget
=
forms
.
Textarea
(
attrs
=
{
'rows'
:
5
}),
required
=
False
)
required
=
False
)
ci_user_data
=
forms
.
CharField
(
disabled
=
True
,
help_text
=
'user-data'
,
ci_user_data
=
forms
.
CharField
(
disabled
=
True
,
help_text
=
'user-data'
,
validators
=
[
user_data_validator
],
widget
=
forms
.
Textarea
(
attrs
=
{
'rows'
:
5
}),
widget
=
forms
.
Textarea
(
attrs
=
{
'rows'
:
5
}),
required
=
False
)
required
=
False
)
...
@@ -1551,12 +1556,6 @@ class CIDataForm(forms.ModelForm):
...
@@ -1551,12 +1556,6 @@ class CIDataForm(forms.ModelForm):
helper
.
form_show_labels
=
False
helper
.
form_show_labels
=
False
return
helper
return
helper
def
clean
(
self
):
cleaned_data
=
super
(
forms
.
ModelForm
,
self
)
.
clean
()
Instance
.
validate_meta_data
(
cleaned_data
[
'ci_meta_data'
])
Instance
.
validate_user_data
(
cleaned_data
[
'ci_user_data'
])
return
cleaned_data
class
GroupPermissionForm
(
forms
.
ModelForm
):
class
GroupPermissionForm
(
forms
.
ModelForm
):
permissions
=
forms
.
ModelMultipleChoiceField
(
permissions
=
forms
.
ModelMultipleChoiceField
(
...
...
This diff is collapsed.
Click to expand it.
circle/dashboard/validators.py
View file @
c486bc51
...
@@ -20,6 +20,9 @@ from django.utils.translation import ugettext_lazy as _
...
@@ -20,6 +20,9 @@ from django.utils.translation import ugettext_lazy as _
from
lxml
import
etree
as
ET
from
lxml
import
etree
as
ET
import
logging
import
logging
import
yaml
from
vm.models
import
Instance
rng_file
=
"/usr/share/libvirt/schemas/domain.rng"
rng_file
=
"/usr/share/libvirt/schemas/domain.rng"
...
@@ -50,6 +53,20 @@ def domain_validator(value):
...
@@ -50,6 +53,20 @@ def domain_validator(value):
raise
ValidationError
(
e
.
message
)
raise
ValidationError
(
e
.
message
)
def
meta_data_validator
(
value
):
try
:
Instance
.
validate_meta_data
(
value
)
except
yaml
.
YAMLError
as
exc
:
raise
ValidationError
(
exc
.
problem_mark
)
def
user_data_validator
(
value
):
try
:
Instance
.
validate_user_data
(
value
)
except
yaml
.
YAMLError
as
exc
:
raise
ValidationError
(
exc
.
problem_mark
)
def
connect_command_template_validator
(
value
):
def
connect_command_template_validator
(
value
):
"""Validate value as a connect command template.
"""Validate value as a connect command template.
...
...
This diff is collapsed.
Click to expand it.
circle/vm/models/instance.py
View file @
c486bc51
...
@@ -376,10 +376,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
...
@@ -376,10 +376,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
def
validate_user_data
(
cls
,
user_data
):
def
validate_user_data
(
cls
,
user_data
):
data
=
user_data
.
replace
(
'{{user}}'
,
'user'
)
data
=
user_data
.
replace
(
'{{user}}'
,
'user'
)
data
=
data
.
replace
(
'{{password}}'
,
'passwd'
)
data
=
data
.
replace
(
'{{password}}'
,
'passwd'
)
try
:
yaml
.
dump
(
yaml
.
load
(
data
,
Loader
=
yaml
.
Loader
))
yaml
.
dump
(
yaml
.
load
(
data
,
Loader
=
yaml
.
Loader
))
except
yaml
.
YAMLError
as
exc
:
raise
forms
.
ValidationError
(
exc
.
problem_mark
)
return
True
return
True
@property
@property
...
@@ -390,10 +387,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
...
@@ -390,10 +387,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
@classmethod
@classmethod
def
validate_meta_data
(
cls
,
meta_data
):
def
validate_meta_data
(
cls
,
meta_data
):
data
=
meta_data
.
replace
(
'{{hostname}}'
,
'hostname'
)
data
=
meta_data
.
replace
(
'{{hostname}}'
,
'hostname'
)
try
:
yaml
.
dump
(
yaml
.
load
(
data
,
Loader
=
yaml
.
Loader
))
yaml
.
dump
(
yaml
.
load
(
data
,
Loader
=
yaml
.
Loader
))
except
yaml
.
YAMLError
as
exc
:
raise
forms
.
ValidationError
(
exc
.
problem_mark
)
return
True
return
True
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment