Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f2577fb3
authored
Apr 19, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one: enforce pep8 and others
parent
1b2fb7a6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
22 deletions
+49
-22
one/admin.py
+41
-20
one/models.py
+0
-0
one/tasks.py
+6
-1
one/util.py
+2
-1
one/views.py
+0
-0
No files found.
one/admin.py
View file @
f2577fb3
from
django.contrib
import
messages
from
django.core.exceptions
import
ValidationError
from
django
import
contrib
from
django.utils.translation
import
ugettext_lazy
as
_
from
one
import
models
import
string
import
school.models
def
owner_person
(
obj
):
p
=
obj
.
owner
return
"
%
s
%
s (
%
s)"
%
(
p
.
last_name
,
p
.
first_name
,
p
.
username
)
owner_person
.
short_description
=
_
(
'owner'
)
class
PersonInline
(
contrib
.
admin
.
StackedInline
):
model
=
models
.
Person
model
=
school
.
models
.
Person
max_num
=
1
can_delete
=
False
class
SshKeyInline
(
contrib
.
admin
.
TabularInline
):
model
=
models
.
SshKey
extra
=
2
class
DetailsInline
(
contrib
.
admin
.
StackedInline
):
model
=
models
.
UserCloudDetails
max_num
=
1
can_delete
=
False
class
MyUserAdmin
(
contrib
.
auth
.
admin
.
UserAdmin
):
list_display
=
(
'username'
,
'full_name'
,
'email'
,
'date_joined'
,
'instance_count'
,
'course_groups'
)
list_filter
=
(
'is_superuser'
,
'is_active'
,
'groups'
,
'person__course_groups'
,
)
try
:
inlines
=
inlines
+
(
PersonInline
,
SshKeyInline
,
DetailsInline
)
except
NameError
:
inlines
=
(
PersonInline
,
SshKeyInline
,
DetailsInline
)
class
MyUserAdmin
(
contrib
.
auth
.
admin
.
UserAdmin
):
list_display
=
(
'username'
,
'full_name'
,
'email'
,
'date_joined'
,
'instance_count'
,
'course_groups'
)
list_filter
=
(
'is_superuser'
,
'is_active'
,
'groups'
,
'person__course_groups'
,
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
MyUserAdmin
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
add
=
[
PersonInline
,
SshKeyInline
,
DetailsInline
,
]
try
:
inlines
=
self
.
inlines
except
NameError
:
inlines
=
list
()
self
.
inlines
=
inlines
+
add
def
instance_count
(
self
,
obj
):
return
_
(
"
%(sum)
d (
%(active)
d active)"
)
%
{
'sum'
:
obj
.
instance_set
.
count
(),
'active'
:
obj
.
instance_set
.
filter
(
state
=
'ACTIVE'
)
.
count
(),
}
return
_
(
"
%(sum)
d (
%(active)
d active)"
)
%
{
'sum'
:
obj
.
instance_set
.
count
(),
'active'
:
obj
.
instance_set
.
filter
(
state
=
'ACTIVE'
)
.
count
(),
}
def
course_groups
(
self
,
obj
):
try
:
...
...
@@ -48,31 +61,35 @@ class MyUserAdmin(contrib.auth.admin.UserAdmin):
ordering
=
[
"-date_joined"
]
contrib
.
admin
.
site
.
unregister
(
contrib
.
auth
.
models
.
User
)
contrib
.
admin
.
site
.
register
(
contrib
.
auth
.
models
.
User
,
MyUserAdmin
)
def
update_state
(
modeladmin
,
request
,
queryset
):
for
i
in
queryset
.
all
():
i
.
update_state
()
update_state
.
short_description
=
_
(
'Update status'
)
def
submit_vm
(
modeladmin
,
request
,
queryset
):
for
i
in
queryset
.
all
():
i
.
submit
(
request
.
user
)
i
.
update_state
()
submit_vm
.
short_description
=
_
(
'Submit VM'
)
def
delete_vm
(
modeladmin
,
request
,
queryset
):
for
i
in
queryset
.
exclude
(
state
=
'DONE'
)
.
all
():
i
.
one_delete
()
delete_vm
.
short_description
=
_
(
'Delete VM'
)
def
suspend_vm
(
modeladmin
,
request
,
queryset
):
for
i
in
queryset
.
filter
(
state
=
'ACTIVE'
)
.
all
():
i
.
stop
()
suspend_vm
.
short_description
=
_
(
'Suspend VM'
)
def
resume_vm
(
modeladmin
,
request
,
queryset
):
for
i
in
queryset
.
filter
(
state__in
=
(
'STOPPED'
,
'SUSPENDED'
))
.
all
():
i
.
resume
()
...
...
@@ -80,21 +97,24 @@ resume_vm.short_description = _('Resume VM')
class
TemplateAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Template
model
=
models
.
Template
list_display
=
(
'name'
,
'state'
,
owner_person
,
'system'
,
'public'
)
list_filter
=
(
'owner'
,
'public'
)
class
InstanceAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Instance
model
=
models
.
Instance
actions
=
[
update_state
,
submit_vm
,
delete_vm
,
suspend_vm
,
resume_vm
]
list_display
=
(
'id'
,
'name'
,
owner_person
,
'state'
)
readonly_fields
=
(
'ip'
,
'active_since'
,
'pw'
,
'template'
)
list_filter
=
(
'owner'
,
'template'
,
'state'
)
def
queryset
(
self
,
request
):
return
super
(
InstanceAdmin
,
self
)
.
queryset
(
request
)
class
DiskAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Disk
model
=
models
.
Disk
list_display
=
(
'name'
,
'used_by'
)
def
used_by
(
self
,
obj
):
...
...
@@ -104,12 +124,14 @@ class DiskAdmin(contrib.admin.ModelAdmin):
return
None
used_by
.
verbose_name
=
_
(
'used by'
)
class
NetworkAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Network
model
=
models
.
Network
list_display
=
(
'name'
,
'nat'
,
'public'
,
'get_vlan'
)
class
ShareAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Network
model
=
models
.
Network
list_filter
=
(
'group'
,
'template'
,
)
list_display
=
(
'name'
,
owner_person
,
'template'
,
'group'
,
)
...
...
@@ -119,4 +141,3 @@ contrib.admin.site.register(models.Network, NetworkAdmin)
contrib
.
admin
.
site
.
register
(
models
.
Disk
,
DiskAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
Share
,
ShareAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
InstanceType
)
one/models.py
View file @
f2577fb3
This diff is collapsed.
Click to expand it.
one/tasks.py
View file @
f2577fb3
...
...
@@ -37,27 +37,32 @@ class UpdateInstanceStateTask(Task):
# ezek csak azert vannak felveve, hogy szepen meg lehessen hivni oket
# ezeket a fejgepen futo celery futtatja
class
CreateInstanceTask
(
Task
):
def
run
(
self
,
name
,
instance_type
,
disk_id
,
network_id
,
ctx
):
pass
class
DeleteInstanceTask
(
Task
):
def
run
(
self
,
one_id
):
pass
class
ChangeInstanceStateTask
(
Task
):
def
run
(
self
,
one_id
,
new_state
):
pass
class
SaveAsTask
(
Task
):
def
run
(
self
,
one_id
,
new_img
):
pass
class
UpdateDiskTask
(
Task
):
def
run
(
self
):
pass
class
UpdateNetworkTask
(
Task
):
def
run
(
self
):
pass
one/util.py
View file @
f2577fb3
def
keygen
(
length
=
1024
):
import
os
,
base64
import
os
import
base64
from
datetime
import
date
from
Crypto.PublicKey
import
RSA
...
...
one/views.py
View file @
f2577fb3
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