Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
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
e4964aff
authored
May 17, 2018
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement lease request creation
parent
bad98db4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
52 deletions
+77
-52
circle/dashboard/migrations/0009_auto_20180517_1630.py
+49
-0
circle/dashboard/templates/dashboard/_vm-renew.html
+1
-1
circle/dashboard/views/vm.py
+4
-1
circle/request/models.py
+14
-11
circle/request/urls.py
+1
-1
circle/request/views.py
+8
-38
No files found.
circle/dashboard/migrations/0009_auto_20180517_1630.py
0 → 100644
View file @
e4964aff
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-05-17 14:30
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'dashboard'
,
'0008_auto_20180420_1054'
),
]
operations
=
[
migrations
.
RemoveField
(
model_name
=
'profile'
,
name
=
'disk_quota'
,
),
migrations
.
RemoveField
(
model_name
=
'profile'
,
name
=
'instance_limit'
,
),
migrations
.
RemoveField
(
model_name
=
'profile'
,
name
=
'network_limit'
,
),
migrations
.
RemoveField
(
model_name
=
'profile'
,
name
=
'org_id'
,
),
migrations
.
RemoveField
(
model_name
=
'profile'
,
name
=
'smb_password'
,
),
migrations
.
RemoveField
(
model_name
=
'profile'
,
name
=
'two_factor_secret'
,
),
migrations
.
RemoveField
(
model_name
=
'profile'
,
name
=
'user'
,
),
migrations
.
AddField
(
model_name
=
'profile'
,
name
=
'user_id'
,
field
=
models
.
CharField
(
default
=
0
,
max_length
=
100
,
unique
=
True
),
preserve_default
=
False
,
),
]
circle/dashboard/templates/dashboard/_vm-renew.html
View file @
e4964aff
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
<a
class=
"btn btn-default"
href=
"{{object.get_absolute_url}}"
data-dismiss=
"modal"
>
<a
class=
"btn btn-default"
href=
"{{object.get_absolute_url}}"
data-dismiss=
"modal"
>
{% trans "Cancel" %}
{% trans "Cancel" %}
</a>
</a>
{% if
object.active and
lease_types and not request.token_user %}
{% if lease_types and not request.token_user %}
<a
class=
"btn btn-primary"
id=
"vm-renew-request-lease-button"
<a
class=
"btn btn-primary"
id=
"vm-renew-request-lease-button"
href=
"{% url "
request
.
views
.
request-lease
"
vm_pk=
object.id
%}"
>
href=
"{% url "
request
.
views
.
request-lease
"
vm_pk=
object.id
%}"
>
<i
class=
"fa fa-forward"
></i>
<i
class=
"fa fa-forward"
></i>
...
...
circle/dashboard/views/vm.py
View file @
e4964aff
...
@@ -732,7 +732,10 @@ class VmRenewView(FormOperationMixin, VmOperationView):
...
@@ -732,7 +732,10 @@ class VmRenewView(FormOperationMixin, VmOperationView):
# Lease.objects.filter(pk=default.pk).distinct())
# Lease.objects.filter(pk=default.pk).distinct())
val
=
super
(
VmRenewView
,
self
)
.
get_form_kwargs
()
val
=
super
(
VmRenewView
,
self
)
.
get_form_kwargs
()
val
.
update
({
'choices'
:
choices
,
'default'
:
default
})
val
.
update
({
'choices'
:
choices
,
'default'
:
default
,
})
return
val
return
val
def
get_response_data
(
self
,
result
,
done
,
extra
=
None
,
**
kwargs
):
def
get_response_data
(
self
,
result
,
done
,
extra
=
None
,
**
kwargs
):
...
...
circle/request/models.py
View file @
e4964aff
...
@@ -31,6 +31,7 @@ from django.utils.translation import (
...
@@ -31,6 +31,7 @@ from django.utils.translation import (
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
import
requests
import
requests
from
openstack_api.nova
import
Server
from
sizefield.models
import
FileSizeField
from
sizefield.models
import
FileSizeField
from
model_utils.models
import
TimeStampedModel
from
model_utils.models
import
TimeStampedModel
from
model_utils
import
Choices
from
model_utils
import
Choices
...
@@ -79,7 +80,7 @@ class Request(TimeStampedModel):
...
@@ -79,7 +80,7 @@ class Request(TimeStampedModel):
)
)
status
=
CharField
(
choices
=
STATUSES
,
default
=
STATUSES
.
PENDING
,
status
=
CharField
(
choices
=
STATUSES
,
default
=
STATUSES
.
PENDING
,
max_length
=
10
)
max_length
=
10
)
user
=
ForeignKey
(
User
,
related_name
=
"user"
)
user
_id
=
CharField
(
blank
=
False
,
max_length
=
100
)
closed_by
=
ForeignKey
(
User
,
related_name
=
"closed_by"
,
null
=
True
)
closed_by
=
ForeignKey
(
User
,
related_name
=
"closed_by"
,
null
=
True
)
TYPES
=
Choices
(
TYPES
=
Choices
(
(
'resource'
,
_
(
'resource request'
)),
(
'resource'
,
_
(
'resource request'
)),
...
@@ -219,22 +220,23 @@ class ResourceChangeAction(RequestAction):
...
@@ -219,22 +220,23 @@ class ResourceChangeAction(RequestAction):
class
ExtendLeaseAction
(
RequestAction
):
class
ExtendLeaseAction
(
RequestAction
):
instance
=
ForeignKey
(
Instance
)
os_server_id
=
CharField
(
blank
=
False
,
max_length
=
100
)
lease_type
=
ForeignKey
(
LeaseType
)
lease_type
=
ForeignKey
(
LeaseType
)
def
accept
(
self
,
user
):
def
accept
(
self
,
user
):
self
.
instance
.
renew
(
lease
=
self
.
lease_type
.
lease
,
save
=
True
,
force
=
True
,
pass
user
=
user
)
# self.instance.renew(lease=self.lease_type.lease, save=True, force=True,
user=user)
@property
@property
def
accept_msg
(
self
):
def
accept_msg
(
self
):
return
_
(
# return _(
'The lease of <a href="
%(url)
s">
%(name)
s</a> got extended. '
# 'The lease of <a href="%(url)s">%(name)s</a> got extended. '
'(suspend:
%(suspend)
s, remove:
%(remove)
s)'
# '(suspend: %(suspend)s, remove: %(remove)s)'
)
%
{
'name'
:
self
.
instance
.
name
,
# ) % {'name': self.instance.name,
'url'
:
self
.
instance
.
get_absolute_url
(),
# 'url': self.instance.get_absolute_url(),
'suspend'
:
self
.
lease_type
.
lease
.
get_readable_suspend_time
(),
# 'suspend': self.lease_type.lease.get_readable_suspend_time(),
'remove'
:
self
.
lease_type
.
lease
.
get_readable_delete_time
(),
}
# 'remove': self.lease_type.lease.get_readable_delete_time(), }
return
"got extended"
class
TemplateAccessAction
(
RequestAction
):
class
TemplateAccessAction
(
RequestAction
):
...
@@ -288,6 +290,7 @@ class DiskResizeAction(RequestAction):
...
@@ -288,6 +290,7 @@ class DiskResizeAction(RequestAction):
def
send_notifications
(
sender
,
instance
,
created
,
**
kwargs
):
def
send_notifications
(
sender
,
instance
,
created
,
**
kwargs
):
return
#TODO
if
not
created
:
if
not
created
:
return
return
...
...
circle/request/urls.py
View file @
e4964aff
...
@@ -29,7 +29,7 @@ from .views import (
...
@@ -29,7 +29,7 @@ from .views import (
urlpatterns
=
[
urlpatterns
=
[
url
(
r'^list/$'
,
RequestList
.
as_view
(),
url
(
r'^list/$'
,
RequestList
.
as_view
(),
name
=
"request.views.request-list"
),
name
=
"request.views.request-list"
),
url
(
r'^(?P<pk>
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
)/$'
,
RequestDetail
.
as_view
(),
url
(
r'^(?P<pk>
\d+
)/$'
,
RequestDetail
.
as_view
(),
name
=
"request.views.request-detail"
),
name
=
"request.views.request-detail"
),
url
(
r'^type/list/$'
,
RequestTypeList
.
as_view
(),
url
(
r'^type/list/$'
,
RequestTypeList
.
as_view
(),
...
...
circle/request/views.py
View file @
e4964aff
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
unicode_literals
,
absolute_import
from
__future__
import
unicode_literals
,
absolute_import
import
openstack_api
from
braces.views._access
import
AccessMixin
from
braces.views._access
import
AccessMixin
from
django.views.generic
import
(
from
django.views.generic
import
(
UpdateView
,
TemplateView
,
DetailView
,
CreateView
,
FormView
,
DeleteView
,
UpdateView
,
TemplateView
,
DetailView
,
CreateView
,
FormView
,
DeleteView
,
...
@@ -211,38 +212,7 @@ class TemplateRequestView(LoginRequiredMixin, FormView):
...
@@ -211,38 +212,7 @@ class TemplateRequestView(LoginRequiredMixin, FormView):
return
redirect
(
reverse
(
"dashboard.index"
))
return
redirect
(
reverse
(
"dashboard.index"
))
class
VmRequestMixin
(
LoginRequiredMixin
,
object
):
class
LeaseRequestView
(
LoginRequiredMixin
,
FormView
):
def
get_vm
(
self
):
return
get_object_or_404
(
Instance
,
pk
=
self
.
kwargs
[
'vm_pk'
])
def
dispatch
(
self
,
*
args
,
**
kwargs
):
vm
=
self
.
get_vm
()
user
=
self
.
request
.
user
if
not
vm
.
has_level
(
user
,
self
.
user_level
):
raise
PermissionDenied
()
if
vm
.
destroyed_at
:
message
=
_
(
"Instance
%(instance)
s has already been destroyed."
)
messages
.
error
(
self
.
request
,
message
%
{
'instance'
:
vm
.
name
})
return
redirect
(
vm
.
get_absolute_url
())
return
super
(
VmRequestMixin
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
VmRequestMixin
,
self
)
.
get_context_data
(
**
kwargs
)
context
[
'vm'
]
=
self
.
get_vm
()
return
context
def
get_form_kwargs
(
self
):
kwargs
=
super
(
VmRequestMixin
,
self
)
.
get_form_kwargs
()
kwargs
[
'request'
]
=
self
.
request
return
kwargs
def
form_valid
(
self
,
form
):
raise
NotImplementedError
class
LeaseRequestView
(
VmRequestMixin
,
FormView
):
form_class
=
LeaseRequestForm
form_class
=
LeaseRequestForm
template_name
=
"request/request-lease.html"
template_name
=
"request/request-lease.html"
user_level
=
"operator"
user_level
=
"operator"
...
@@ -251,16 +221,16 @@ class LeaseRequestView(VmRequestMixin, FormView):
...
@@ -251,16 +221,16 @@ class LeaseRequestView(VmRequestMixin, FormView):
def
form_valid
(
self
,
form
):
def
form_valid
(
self
,
form
):
data
=
form
.
cleaned_data
data
=
form
.
cleaned_data
user
=
self
.
request
.
user
user
=
self
.
request
.
user
vm
=
self
.
get_vm
()
vm
=
openstack_api
.
nova
.
server_get
(
self
.
request
,
self
.
kwargs
[
'vm_pk'
])
# to check priviliges
el
=
ExtendLeaseAction
(
el
=
ExtendLeaseAction
(
lease_type
=
data
[
'lease'
],
lease_type
=
data
[
'lease'
],
instance
=
vm
,
os_server_id
=
vm
.
id
,
)
)
el
.
save
()
el
.
save
()
req
=
Request
(
req
=
Request
(
user
=
user
,
user
_id
=
user
.
id
,
message
=
data
[
'message'
],
message
=
data
[
'message'
],
type
=
Request
.
TYPES
.
lease
,
type
=
Request
.
TYPES
.
lease
,
action
=
el
action
=
el
...
@@ -268,10 +238,10 @@ class LeaseRequestView(VmRequestMixin, FormView):
...
@@ -268,10 +238,10 @@ class LeaseRequestView(VmRequestMixin, FormView):
req
.
save
()
req
.
save
()
messages
.
success
(
self
.
request
,
self
.
success_message
)
messages
.
success
(
self
.
request
,
self
.
success_message
)
return
redirect
(
vm
.
get_absolute_url
(
))
return
redirect
(
reverse
(
'dashboard.views.detail'
,
args
=
[
self
.
kwargs
[
'vm_pk'
]]
))
class
ResourceRequestView
(
VmRequest
Mixin
,
FormView
):
class
ResourceRequestView
(
LoginRequired
Mixin
,
FormView
):
form_class
=
ResourceRequestForm
form_class
=
ResourceRequestForm
template_name
=
"request/request-resource.html"
template_name
=
"request/request-resource.html"
user_level
=
"user"
user_level
=
"user"
...
@@ -316,7 +286,7 @@ class ResourceRequestView(VmRequestMixin, FormView):
...
@@ -316,7 +286,7 @@ class ResourceRequestView(VmRequestMixin, FormView):
return
redirect
(
vm
.
get_absolute_url
())
return
redirect
(
vm
.
get_absolute_url
())
class
ResizeRequestView
(
VmRequest
Mixin
,
FormView
):
class
ResizeRequestView
(
LoginRequired
Mixin
,
FormView
):
form_class
=
ResizeRequestForm
form_class
=
ResizeRequestForm
template_name
=
"request/_request-resize-form.html"
template_name
=
"request/_request-resize-form.html"
user_level
=
"owner"
user_level
=
"owner"
...
...
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