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
d72aa9c8
authored
Jun 01, 2018
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add template share by groups to UpdateTemplateShares view
parent
554c8261
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
12 deletions
+29
-12
circle/dashboard/views/util.py
+29
-12
No files found.
circle/dashboard/views/util.py
View file @
d72aa9c8
...
...
@@ -640,8 +640,7 @@ class UpdateSharedTemplates(View):
return
InstanceTemplate
.
objects
.
filter
(
image_id__in
=
snapshot_ids
)
def
__list_users_of_group
(
self
,
group_id
):
keystone
=
self
.
__get_keystone_admin_client
()
return
keystone
.
users
.
list
(
group
=
group_id
)
return
self
.
keystone
.
users
.
list
(
group
=
group_id
)
def
__is_member_of_groups
(
self
,
template
):
for
group
in
template
.
groups
.
all
():
...
...
@@ -660,7 +659,10 @@ class UpdateSharedTemplates(View):
if
not
self
.
__is_member_of_groups
(
template
):
snapshot_owner_glance
=
self
.
__get_glance_admin_client
(
template
.
owner_id
)
snapshot_owner_glance
.
image_members
.
delete
(
template
.
image_id
,
self
.
project_id
)
try
:
snapshot_owner_glance
.
image_members
.
delete
(
template
.
image_id
,
self
.
project_id
)
except
:
pass
# TODO: silent fail, but should log in case of some error
def
__cleanup_snapshots
(
self
):
templates_of_existing_snaps
=
self
.
__get_templates_of_snapshots
()
...
...
@@ -670,18 +672,30 @@ class UpdateSharedTemplates(View):
def
__accept_membership
(
self
,
template
):
self
.
glance
.
image_members
.
update
(
template
.
image_id
,
self
.
project_id
,
'accepted'
)
def
__share_template
(
self
,
template
):
snapshot_owner_glance
=
self
.
__get_glance_admin_client
(
template
.
owner_id
)
try
:
snapshot_owner_glance
.
image_members
.
create
(
template
.
image_id
,
self
.
project_id
)
self
.
__accept_membership
(
template
)
except
:
pass
# TODO: silent fail, but should log in case of some error
def
__share_templates
(
self
,
templates
):
for
t
in
templates
:
self
.
__share_template
(
t
)
def
__assign_by_users
(
self
):
templates
=
InstanceTemplate
.
objects
.
filter
(
users__project_id
=
self
.
project_id
)
for
t
in
templates
:
snapshot_owner_glance
=
self
.
__get_glance_admin_client
(
t
.
owner_id
)
try
:
snapshot_owner_glance
.
image_members
.
create
(
t
.
image_id
,
self
.
project_id
)
self
.
__accept_membership
(
t
)
except
:
pass
# TODO: silent fail, but should log in case of some error
self
.
__share_templates
(
templates
)
def
__get_group_ids_of_user
(
self
):
generator
=
self
.
keystone
.
groups
.
list
(
user
=
self
.
user_id
)
return
[
g
.
id
for
g
in
generator
]
def
__assign_by_groups
(
self
):
pass
group_ids
=
self
.
__get_group_ids_of_user
()
templates
=
InstanceTemplate
.
objects
.
filter
(
groups__group_id__in
=
group_ids
)
self
.
__share_templates
(
templates
)
def
__assign_snapshots
(
self
):
self
.
__assign_by_users
()
...
...
@@ -693,7 +707,8 @@ class UpdateSharedTemplates(View):
def
post
(
self
,
request
):
if
not
'secret'
in
request
.
POST
or
\
not
'project_id'
in
request
.
POST
:
not
'project_id'
in
request
.
POST
or
\
not
'user_id'
in
request
.
POST
:
return
HttpResponse
(
status
=
400
)
secret
=
request
.
POST
[
'secret'
]
...
...
@@ -701,7 +716,9 @@ class UpdateSharedTemplates(View):
return
HttpResponse
(
status
=
401
)
self
.
project_id
=
request
.
POST
[
'project_id'
]
self
.
user_id
=
request
.
POST
[
'user_id'
]
self
.
glance
=
self
.
__get_glance_admin_client
(
self
.
project_id
)
self
.
keystone
=
self
.
__get_keystone_admin_client
()
self
.
__update_shared_templates
()
return
HttpResponse
(
status
=
200
)
...
...
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