Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4701cfb4
authored
Sep 02, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add validator conn command
parent
db31f971
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
70 additions
and
16 deletions
+70
-16
circle/dashboard/forms.py
+3
-8
circle/dashboard/models.py
+3
-4
circle/dashboard/templates/dashboard/connect-command-create.html
+22
-1
circle/dashboard/templates/dashboard/connect-command-edit.html
+22
-2
circle/dashboard/templates/dashboard/vm-detail.html
+1
-1
circle/dashboard/validators.py
+14
-0
circle/dashboard/views.py
+5
-0
No files found.
circle/dashboard/forms.py
View file @
4701cfb4
...
...
@@ -54,7 +54,7 @@ from .models import Profile, GroupProfile
from
circle.settings.base
import
LANGUAGES
,
MAX_NODE_RAM
from
django.utils.translation
import
string_concat
from
.v
irtvalidator
import
domain_validator
from
.v
alidators
import
domain_validator
from
dashboard.models
import
ConnectCommand
...
...
@@ -1064,19 +1064,14 @@ class ConnectCommandForm(forms.ModelForm):
fields
=
(
'name'
,
'access_method'
,
'template'
)
model
=
ConnectCommand
@property
def
helper
(
self
):
helper
=
FormHelper
()
helper
.
add_input
(
Submit
(
"submit"
,
_
(
"Save"
)))
return
helper
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
user
=
kwargs
.
pop
(
"user"
,
None
)
self
.
user
=
kwargs
.
pop
(
"user"
)
super
(
ConnectCommandForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
clean
(
self
):
if
self
.
user
:
self
.
instance
.
user
=
self
.
user
return
super
(
ConnectCommandForm
,
self
)
.
clean
()
...
...
circle/dashboard/models.py
View file @
4701cfb4
...
...
@@ -49,6 +49,7 @@ from vm.tasks.agent_tasks import add_keys, del_keys
from
vm.models.instance
import
ACCESS_METHODS
from
.store_api
import
Store
,
NoStoreException
,
NotOkException
from
.validators
import
connect_command_template_validator
logger
=
getLogger
(
__name__
)
...
...
@@ -113,10 +114,8 @@ class ConnectCommand(Model):
help_text
=
_
(
'Template for connection command string. '
'Available parameters are: '
'username, password, '
'host, port, app. Example: sshpass '
'-p
%(password)
s ssh -o '
'StrictHostKeyChecking=no
%(username)
s@'
'
%(host)
s -p
%(port)
s'
))
'host, port.'
),
validators
=
[
connect_command_template_validator
])
def
__unicode__
(
self
):
return
self
.
template
...
...
circle/dashboard/templates/dashboard/connect-command-create.html
View file @
4701cfb4
...
...
@@ -14,7 +14,28 @@
<h3
class=
"no-margin"
><i
class=
"fa fa-code"
></i>
{% trans "Create new command template" %}
</h3>
</div>
<div
class=
"panel-body"
>
{% crispy form %}
<form
method=
"POST"
>
{% csrf_token %}
{{ form.name|as_crispy_field }}
{{ form.access_method|as_crispy_field }}
{{ form.template|as_crispy_field }}
<p
class=
"text-muted"
>
{% trans "Examples" %}
</p>
<p>
<strong>
SSH:
</strong>
<span
class=
"text-muted"
>
sshpass -p %(password)s ssh -o StrictHostKeyChecking=no cloud@%(host)s -p %(port)d
</span>
</p>
<p>
<strong>
RDP:
</strong>
<span
class=
"text-muted"
>
rdesktop %(host)s:%(port)d -u cloud -p %(password)s
</span>
</p>
<input
type=
"submit"
class=
"btn btn-primary"
value=
"{% trans "
Save
"
%}"
>
</form>
</div>
</div>
</div>
...
...
circle/dashboard/templates/dashboard/connect-command-edit.html
View file @
4701cfb4
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load sizefieldtags %}
{% load crispy_forms_tags %}
{% block title-page %}{% trans "Edit command template" %}{% endblock %}
...
...
@@ -15,7 +14,28 @@
<h3
class=
"no-margin"
><i
class=
"fa fa-code"
></i>
{% trans "Edit command template" %}
</h3>
</div>
<div
class=
"panel-body"
>
{% crispy form %}
<form
method=
"POST"
>
{% csrf_token %}
{{ form.name|as_crispy_field }}
{{ form.access_method|as_crispy_field }}
{{ form.template|as_crispy_field }}
<p
class=
"text-muted"
>
{% trans "Examples" %}
</p>
<p>
<strong>
SSH:
</strong>
<span
class=
"text-muted"
>
sshpass -p %(password)s ssh -o StrictHostKeyChecking=no cloud@%(host)s -p %(port)d
</span>
</p>
<p>
<strong>
RDP:
</strong>
<span
class=
"text-muted"
>
rdesktop %(host)s:%(port)d -u cloud -p %(password)s
</span>
</p>
<input
type=
"submit"
class=
"btn btn-primary"
value=
"{% trans "
Save
"
%}"
>
</form>
</div>
</div>
</div>
...
...
circle/dashboard/templates/dashboard/vm-detail.html
View file @
4701cfb4
...
...
@@ -125,7 +125,7 @@
</div>
{% empty %}
<div
class=
"input-group
"
id=
"
dashboard-vm-details-connect-command"
>
<div
class=
"input-group
dashboard-vm-details-connect-command"
>
<span
class=
"input-group-addon input-tags"
>
{% trans "Command" %}
</span>
<input
type=
"text"
spellcheck=
"false"
value=
"{% trans "
Connection
is
not
possible
."
%}"
id=
"vm-details-connection-string"
class=
"form-control input-tags"
/>
...
...
circle/dashboard/v
irtvalidator
.py
→
circle/dashboard/v
alidators
.py
View file @
4701cfb4
from
django.core.exceptions
import
ValidationError
from
django.utils.translation
import
ugettext_lazy
as
_
from
lxml
import
etree
as
ET
import
logging
...
...
@@ -29,3 +31,15 @@ def domain_validator(value):
relaxng
.
assertValid
(
parsed_xml
)
except
Exception
as
e
:
raise
ValidationError
(
e
.
message
)
def
connect_command_template_validator
(
value
):
try
:
value
%
{
'username'
:
"uname"
,
'password'
:
"pw"
,
'host'
:
"111.111.111.111"
,
'port'
:
12345
,
}
except
(
KeyError
,
TypeError
,
ValueError
):
raise
ValidationError
(
_
(
"Invalid template string."
))
circle/dashboard/views.py
View file @
4701cfb4
...
...
@@ -3341,6 +3341,11 @@ class ConnectCommandDetail(LoginRequiredMixin, SuccessMessageMixin,
raise
PermissionDenied
()
return
super
(
ConnectCommandDetail
,
self
)
.
post
(
request
,
args
,
kwargs
)
def
get_form_kwargs
(
self
):
kwargs
=
super
(
ConnectCommandDetail
,
self
)
.
get_form_kwargs
()
kwargs
[
'user'
]
=
self
.
request
.
user
return
kwargs
class
ConnectCommandDelete
(
LoginRequiredMixin
,
DeleteView
):
model
=
ConnectCommand
...
...
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