Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
d263bf24
authored
Nov 12, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: delete storagelink
remove disk from instance, but don't destroy it
parent
c3dd4099
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
9 deletions
+43
-9
circle/occi/occi.py
+7
-0
circle/occi/urls.py
+1
-1
circle/occi/views.py
+15
-7
circle/vm/models/instance.py
+2
-1
circle/vm/operations.py
+18
-0
No files found.
circle/occi/occi.py
View file @
d263bf24
...
...
@@ -505,6 +505,13 @@ class StorageLink(Link):
'attrs'
:
self
.
attrs
,
})
def
delete
(
self
):
# TODO
user
=
User
.
objects
.
get
(
username
=
"test"
)
if
self
.
disk
in
self
.
instance
.
disks
.
all
():
self
.
instance
.
detach_disk
(
user
=
user
,
disk
=
self
.
disk
)
"""predefined stuffs
...
...
circle/occi/urls.py
View file @
d263bf24
...
...
@@ -33,6 +33,6 @@ urlpatterns = patterns(
url
(
r'^disk/(?P<pk>\d+)/$'
,
DiskInterface
.
as_view
(),
name
=
"occi.disk"
),
url
(
r'^link/storagelink/$'
,
StorageLinkInterface
.
as_view
()),
url
(
r'^link/storagelink/vm(?P<vm_pk>\d+)_disk(?P<disk_pk>\d+)/$'
,
url
(
r'^link/storagelink/vm(?P<vm_pk>\d+)_disk(?P<disk_pk>\d+)/
?
$'
,
StorageLinkInterface
.
as_view
(),
name
=
"occi.storagelink"
),
)
circle/occi/views.py
View file @
d263bf24
...
...
@@ -201,15 +201,16 @@ class DiskInterface(DetailView):
class
StorageLinkInterface
(
View
):
def
get_vm_and_disk
(
self
):
try
:
vm
=
Instance
.
objects
.
filter
(
destroyed
=
None
)
.
get
(
pk
=
self
.
kwargs
[
'vm_pk'
])
disk
=
Disk
.
objects
.
filter
(
destroyed
=
None
)
.
get
(
pk
=
self
.
kwargs
[
'disk_pk'
])
return
vm
,
disk
except
(
Instance
.
DoesNotExist
,
Disk
.
DoesNotExist
):
vm
=
get_object_or_404
(
Instance
.
objects
.
filter
(
destroyed_at
=
None
),
pk
=
self
.
kwargs
[
'vm_pk'
])
disk
=
get_object_or_404
(
Disk
.
objects
.
filter
(
destroyed
=
None
),
pk
=
self
.
kwargs
[
'disk_pk'
])
if
disk
not
in
vm
.
disks
.
all
():
raise
Http404
return
vm
,
disk
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
vm
,
disk
=
self
.
get_vm_and_disk
()
sl
=
StorageLink
(
instance
=
vm
,
disk
=
disk
)
...
...
@@ -236,6 +237,13 @@ class StorageLinkInterface(View):
else
:
return
HttpResponse
(
"VM or Storage does not exist."
,
status
=
500
)
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
vm
,
disk
=
self
.
get_vm_and_disk
()
sl
=
StorageLink
(
instance
=
vm
,
disk
=
disk
)
sl
.
delete
()
return
HttpResponse
(
""
)
@method_decorator
(
csrf_exempt
)
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
StorageLinkInterface
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
circle/vm/models/instance.py
View file @
d263bf24
...
...
@@ -817,7 +817,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
return
acts
def
get_merged_activities
(
self
,
user
=
None
):
whitelist
=
(
"create_disk"
,
"download_disk"
,
"attach_disk"
)
whitelist
=
(
"create_disk"
,
"download_disk"
,
"attach_disk"
,
"detach_disk"
,
)
acts
=
self
.
get_activities
(
user
)
merged_acts
=
[]
latest
=
None
...
...
circle/vm/operations.py
View file @
d263bf24
...
...
@@ -1326,3 +1326,21 @@ class AttachDiskOperation(InstanceOperation):
return
create_readable
(
ugettext_noop
(
"attach disk
%(name)
s"
),
name
=
kwargs
[
'disk'
]
.
name
)
@register_operation
class
DetachDiskOperation
(
InstanceOperation
):
id
=
'detach_disk'
name
=
_
(
"detach disk"
)
description
=
_
(
"Detach the specified disk from the virtual machine."
)
required_perms
=
()
accept_states
=
(
'STOPPED'
,
'PENDING'
,
'RUNNING'
)
def
_operation
(
self
,
activity
,
user
,
disk
):
if
self
.
instance
.
is_running
and
disk
.
type
not
in
[
"iso"
]:
self
.
instance
.
_detach_disk
(
disk
=
disk
,
parent_activity
=
activity
)
return
self
.
instance
.
disks
.
remove
(
disk
)
def
get_activity_name
(
self
,
kwargs
):
return
create_readable
(
ugettext_noop
(
'deatch disk
%(name)
s'
),
name
=
kwargs
[
"disk"
]
.
name
)
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