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
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
import
contrib
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
one
import
models
from
one
import
models
import
string
import
school.models
def
owner_person
(
obj
):
def
owner_person
(
obj
):
p
=
obj
.
owner
p
=
obj
.
owner
return
"
%
s
%
s (
%
s)"
%
(
p
.
last_name
,
p
.
first_name
,
p
.
username
)
return
"
%
s
%
s (
%
s)"
%
(
p
.
last_name
,
p
.
first_name
,
p
.
username
)
owner_person
.
short_description
=
_
(
'owner'
)
owner_person
.
short_description
=
_
(
'owner'
)
class
PersonInline
(
contrib
.
admin
.
StackedInline
):
class
PersonInline
(
contrib
.
admin
.
StackedInline
):
model
=
models
.
Person
model
=
school
.
models
.
Person
max_num
=
1
max_num
=
1
can_delete
=
False
can_delete
=
False
class
SshKeyInline
(
contrib
.
admin
.
TabularInline
):
class
SshKeyInline
(
contrib
.
admin
.
TabularInline
):
model
=
models
.
SshKey
model
=
models
.
SshKey
extra
=
2
extra
=
2
class
DetailsInline
(
contrib
.
admin
.
StackedInline
):
class
DetailsInline
(
contrib
.
admin
.
StackedInline
):
model
=
models
.
UserCloudDetails
model
=
models
.
UserCloudDetails
max_num
=
1
max_num
=
1
can_delete
=
False
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
:
class
MyUserAdmin
(
contrib
.
auth
.
admin
.
UserAdmin
):
inlines
=
inlines
+
(
PersonInline
,
SshKeyInline
,
DetailsInline
)
list_display
=
(
'username'
,
'full_name'
,
'email'
,
except
NameError
:
'date_joined'
,
'instance_count'
,
'course_groups'
)
inlines
=
(
PersonInline
,
SshKeyInline
,
DetailsInline
)
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
):
def
instance_count
(
self
,
obj
):
return
_
(
"
%(sum)
d (
%(active)
d active)"
)
%
{
'sum'
:
obj
.
instance_set
.
count
(),
return
_
(
"
%(sum)
d (
%(active)
d active)"
)
%
{
'active'
:
obj
.
instance_set
.
filter
(
state
=
'ACTIVE'
)
.
count
(),
}
'sum'
:
obj
.
instance_set
.
count
(),
'active'
:
obj
.
instance_set
.
filter
(
state
=
'ACTIVE'
)
.
count
(),
}
def
course_groups
(
self
,
obj
):
def
course_groups
(
self
,
obj
):
try
:
try
:
...
@@ -48,31 +61,35 @@ class MyUserAdmin(contrib.auth.admin.UserAdmin):
...
@@ -48,31 +61,35 @@ class MyUserAdmin(contrib.auth.admin.UserAdmin):
ordering
=
[
"-date_joined"
]
ordering
=
[
"-date_joined"
]
contrib
.
admin
.
site
.
unregister
(
contrib
.
auth
.
models
.
User
)
contrib
.
admin
.
site
.
unregister
(
contrib
.
auth
.
models
.
User
)
contrib
.
admin
.
site
.
register
(
contrib
.
auth
.
models
.
User
,
MyUserAdmin
)
contrib
.
admin
.
site
.
register
(
contrib
.
auth
.
models
.
User
,
MyUserAdmin
)
def
update_state
(
modeladmin
,
request
,
queryset
):
def
update_state
(
modeladmin
,
request
,
queryset
):
for
i
in
queryset
.
all
():
for
i
in
queryset
.
all
():
i
.
update_state
()
i
.
update_state
()
update_state
.
short_description
=
_
(
'Update status'
)
update_state
.
short_description
=
_
(
'Update status'
)
def
submit_vm
(
modeladmin
,
request
,
queryset
):
def
submit_vm
(
modeladmin
,
request
,
queryset
):
for
i
in
queryset
.
all
():
for
i
in
queryset
.
all
():
i
.
submit
(
request
.
user
)
i
.
submit
(
request
.
user
)
i
.
update_state
()
i
.
update_state
()
submit_vm
.
short_description
=
_
(
'Submit VM'
)
submit_vm
.
short_description
=
_
(
'Submit VM'
)
def
delete_vm
(
modeladmin
,
request
,
queryset
):
def
delete_vm
(
modeladmin
,
request
,
queryset
):
for
i
in
queryset
.
exclude
(
state
=
'DONE'
)
.
all
():
for
i
in
queryset
.
exclude
(
state
=
'DONE'
)
.
all
():
i
.
one_delete
()
i
.
one_delete
()
delete_vm
.
short_description
=
_
(
'Delete VM'
)
delete_vm
.
short_description
=
_
(
'Delete VM'
)
def
suspend_vm
(
modeladmin
,
request
,
queryset
):
def
suspend_vm
(
modeladmin
,
request
,
queryset
):
for
i
in
queryset
.
filter
(
state
=
'ACTIVE'
)
.
all
():
for
i
in
queryset
.
filter
(
state
=
'ACTIVE'
)
.
all
():
i
.
stop
()
i
.
stop
()
suspend_vm
.
short_description
=
_
(
'Suspend VM'
)
suspend_vm
.
short_description
=
_
(
'Suspend VM'
)
def
resume_vm
(
modeladmin
,
request
,
queryset
):
def
resume_vm
(
modeladmin
,
request
,
queryset
):
for
i
in
queryset
.
filter
(
state__in
=
(
'STOPPED'
,
'SUSPENDED'
))
.
all
():
for
i
in
queryset
.
filter
(
state__in
=
(
'STOPPED'
,
'SUSPENDED'
))
.
all
():
i
.
resume
()
i
.
resume
()
...
@@ -80,21 +97,24 @@ resume_vm.short_description = _('Resume VM')
...
@@ -80,21 +97,24 @@ resume_vm.short_description = _('Resume VM')
class
TemplateAdmin
(
contrib
.
admin
.
ModelAdmin
):
class
TemplateAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Template
model
=
models
.
Template
list_display
=
(
'name'
,
'state'
,
owner_person
,
'system'
,
'public'
)
list_display
=
(
'name'
,
'state'
,
owner_person
,
'system'
,
'public'
)
list_filter
=
(
'owner'
,
'public'
)
list_filter
=
(
'owner'
,
'public'
)
class
InstanceAdmin
(
contrib
.
admin
.
ModelAdmin
):
class
InstanceAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Instance
model
=
models
.
Instance
actions
=
[
update_state
,
submit_vm
,
delete_vm
,
suspend_vm
,
resume_vm
]
actions
=
[
update_state
,
submit_vm
,
delete_vm
,
suspend_vm
,
resume_vm
]
list_display
=
(
'id'
,
'name'
,
owner_person
,
'state'
)
list_display
=
(
'id'
,
'name'
,
owner_person
,
'state'
)
readonly_fields
=
(
'ip'
,
'active_since'
,
'pw'
,
'template'
)
readonly_fields
=
(
'ip'
,
'active_since'
,
'pw'
,
'template'
)
list_filter
=
(
'owner'
,
'template'
,
'state'
)
list_filter
=
(
'owner'
,
'template'
,
'state'
)
def
queryset
(
self
,
request
):
def
queryset
(
self
,
request
):
return
super
(
InstanceAdmin
,
self
)
.
queryset
(
request
)
return
super
(
InstanceAdmin
,
self
)
.
queryset
(
request
)
class
DiskAdmin
(
contrib
.
admin
.
ModelAdmin
):
class
DiskAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Disk
model
=
models
.
Disk
list_display
=
(
'name'
,
'used_by'
)
list_display
=
(
'name'
,
'used_by'
)
def
used_by
(
self
,
obj
):
def
used_by
(
self
,
obj
):
...
@@ -104,12 +124,14 @@ class DiskAdmin(contrib.admin.ModelAdmin):
...
@@ -104,12 +124,14 @@ class DiskAdmin(contrib.admin.ModelAdmin):
return
None
return
None
used_by
.
verbose_name
=
_
(
'used by'
)
used_by
.
verbose_name
=
_
(
'used by'
)
class
NetworkAdmin
(
contrib
.
admin
.
ModelAdmin
):
class
NetworkAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Network
model
=
models
.
Network
list_display
=
(
'name'
,
'nat'
,
'public'
,
'get_vlan'
)
list_display
=
(
'name'
,
'nat'
,
'public'
,
'get_vlan'
)
class
ShareAdmin
(
contrib
.
admin
.
ModelAdmin
):
class
ShareAdmin
(
contrib
.
admin
.
ModelAdmin
):
model
=
models
.
Network
model
=
models
.
Network
list_filter
=
(
'group'
,
'template'
,
)
list_filter
=
(
'group'
,
'template'
,
)
list_display
=
(
'name'
,
owner_person
,
'template'
,
'group'
,
)
list_display
=
(
'name'
,
owner_person
,
'template'
,
'group'
,
)
...
@@ -119,4 +141,3 @@ contrib.admin.site.register(models.Network, NetworkAdmin)
...
@@ -119,4 +141,3 @@ contrib.admin.site.register(models.Network, NetworkAdmin)
contrib
.
admin
.
site
.
register
(
models
.
Disk
,
DiskAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
Disk
,
DiskAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
Share
,
ShareAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
Share
,
ShareAdmin
)
contrib
.
admin
.
site
.
register
(
models
.
InstanceType
)
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):
...
@@ -37,27 +37,32 @@ class UpdateInstanceStateTask(Task):
# ezek csak azert vannak felveve, hogy szepen meg lehessen hivni oket
# ezek csak azert vannak felveve, hogy szepen meg lehessen hivni oket
# ezeket a fejgepen futo celery futtatja
# ezeket a fejgepen futo celery futtatja
class
CreateInstanceTask
(
Task
):
class
CreateInstanceTask
(
Task
):
def
run
(
self
,
name
,
instance_type
,
disk_id
,
network_id
,
ctx
):
def
run
(
self
,
name
,
instance_type
,
disk_id
,
network_id
,
ctx
):
pass
pass
class
DeleteInstanceTask
(
Task
):
class
DeleteInstanceTask
(
Task
):
def
run
(
self
,
one_id
):
def
run
(
self
,
one_id
):
pass
pass
class
ChangeInstanceStateTask
(
Task
):
class
ChangeInstanceStateTask
(
Task
):
def
run
(
self
,
one_id
,
new_state
):
def
run
(
self
,
one_id
,
new_state
):
pass
pass
class
SaveAsTask
(
Task
):
class
SaveAsTask
(
Task
):
def
run
(
self
,
one_id
,
new_img
):
def
run
(
self
,
one_id
,
new_img
):
pass
pass
class
UpdateDiskTask
(
Task
):
class
UpdateDiskTask
(
Task
):
def
run
(
self
):
def
run
(
self
):
pass
pass
class
UpdateNetworkTask
(
Task
):
class
UpdateNetworkTask
(
Task
):
def
run
(
self
):
def
run
(
self
):
pass
pass
one/util.py
View file @
f2577fb3
def
keygen
(
length
=
1024
):
def
keygen
(
length
=
1024
):
import
os
,
base64
import
os
import
base64
from
datetime
import
date
from
datetime
import
date
from
Crypto.PublicKey
import
RSA
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