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
4baa3506
authored
Nov 11, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: handle storagelink errors
detect if the target storage and source vm exists
parent
a2911611
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
12 deletions
+29
-12
circle/occi/occi.py
+11
-5
circle/occi/views.py
+12
-7
circle/vm/operations.py
+6
-0
No files found.
circle/occi/occi.py
View file @
4baa3506
import
re
import
re
from
django.shortcuts
import
get_object_or_404
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
from
django.utils
import
timezone
from
django.utils
import
timezone
...
@@ -428,17 +427,24 @@ class StorageLink(Link):
...
@@ -428,17 +427,24 @@ class StorageLink(Link):
g
=
re
.
match
(
occi_attribute_link_regex
%
"vm"
,
source
)
g
=
re
.
match
(
occi_attribute_link_regex
%
"vm"
,
source
)
vm_pk
=
g
.
group
(
"id"
)
vm_pk
=
g
.
group
(
"id"
)
disk
=
get_object_or_404
(
Disk
,
pk
=
disk_pk
)
try
:
vm
=
get_object_or_404
(
Instance
,
pk
=
vm_pk
)
vm
=
Instance
.
objects
.
filter
(
destroyed_at
=
None
)
.
get
(
pk
=
vm_pk
)
disk
=
Disk
.
objects
.
filter
(
destroyed
=
None
)
.
get
(
pk
=
disk_pk
)
except
(
Instance
.
DoesNotExist
,
Disk
.
DoesNotExist
):
return
None
try
:
vm
.
attach_disk
(
user
=
user
,
disk
=
disk
)
vm
.
attach_disk
(
user
=
user
,
disk
=
disk
)
except
:
pass
cls
.
location
=
"
%
sstoragelink/
%
svm_
%
sdisk"
%
(
OCCI_ADDR
,
vm_pk
,
cls
.
location
=
"
%
sstoragelink/
%
svm_
%
sdisk"
%
(
OCCI_ADDR
,
vm_pk
,
disk_pk
)
disk_pk
)
return
cls
return
cls
def
render_location
(
self
):
def
render_location
(
self
):
return
"/link/storagelink/vm
%
d_disk
%
d"
%
(
instance
.
pk
,
disk
.
pk
)
return
"/link/storagelink/vm
%
d_disk
%
d"
%
(
self
.
instance
.
pk
,
self
.
disk
.
pk
)
def
render_as_link
(
self
):
def
render_as_link
(
self
):
kind
=
STORAGE_LINK_KIND
kind
=
STORAGE_LINK_KIND
...
...
circle/occi/views.py
View file @
4baa3506
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
,
Http404
from
django.shortcuts
import
get_object_or_404
from
django.utils.decorators
import
method_decorator
from
django.utils.decorators
import
method_decorator
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.generic
import
View
,
DetailView
from
django.views.generic
import
View
,
DetailView
...
@@ -191,9 +190,14 @@ class DiskInterface(DetailView):
...
@@ -191,9 +190,14 @@ class DiskInterface(DetailView):
class
StorageLinkInterface
(
View
):
class
StorageLinkInterface
(
View
):
def
get_vm_and_disk
(
self
):
def
get_vm_and_disk
(
self
):
vm
=
get_object_or_404
(
Instance
,
pk
=
self
.
kwargs
[
'vm_pk'
])
try
:
disk
=
get_object_or_404
(
Disk
,
pk
=
self
.
kwargs
[
'disk_pk'
])
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
return
vm
,
disk
except
(
Instance
.
DoesNotExist
,
Disk
.
DoesNotExist
):
raise
Http404
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
vm
,
disk
=
self
.
get_vm_and_disk
()
vm
,
disk
=
self
.
get_vm_and_disk
()
...
@@ -208,17 +212,18 @@ class StorageLinkInterface(View):
...
@@ -208,17 +212,18 @@ class StorageLinkInterface(View):
# (they don't even exist in the model)
# (they don't even exist in the model)
if
request
.
GET
.
get
(
"action"
):
if
request
.
GET
.
get
(
"action"
):
return
HttpResponse
(
""
,
status
=
500
)
return
HttpResponse
(
""
,
status
=
500
)
else
:
data
=
get_post_data_from_request
(
request
)
data
=
get_post_data_from_request
(
request
)
sl
=
StorageLink
.
create_object
(
data
=
data
)
sl
=
StorageLink
.
create_object
(
data
=
data
)
if
sl
:
response
=
HttpResponse
(
response
=
HttpResponse
(
"X-OCCI-Location:
%
s"
%
sl
.
location
,
"X-OCCI-Location:
%
s"
%
sl
.
location
,
status
=
201
,
status
=
201
,
content_type
=
"text/plain"
,
content_type
=
"text/plain"
,
)
)
return
response
return
response
else
:
return
HttpResponse
(
)
return
HttpResponse
(
"VM or Storage does not exist."
,
status
=
500
)
@method_decorator
(
csrf_exempt
)
@method_decorator
(
csrf_exempt
)
def
dispatch
(
self
,
*
args
,
**
kwargs
):
def
dispatch
(
self
,
*
args
,
**
kwargs
):
...
...
circle/vm/operations.py
View file @
4baa3506
...
@@ -1295,6 +1295,12 @@ class AttachDiskOperation(InstanceOperation):
...
@@ -1295,6 +1295,12 @@ class AttachDiskOperation(InstanceOperation):
accept_states
=
(
'STOPPED'
,
'PENDING'
,
'RUNNING'
)
accept_states
=
(
'STOPPED'
,
'PENDING'
,
'RUNNING'
)
def
_operation
(
self
,
user
,
activity
,
disk
):
def
_operation
(
self
,
user
,
activity
,
disk
):
if
disk
in
self
.
instance
.
disks
.
all
():
raise
humanize_exception
(
ugettext_noop
(
"Disk (#
%
d) is already attached to this virtual machine."
)
%
disk
.
pk
,
Exception
())
devnums
=
list
(
ascii_lowercase
)
devnums
=
list
(
ascii_lowercase
)
for
d
in
self
.
instance
.
disks
.
all
():
for
d
in
self
.
instance
.
disks
.
all
():
devnums
.
remove
(
d
.
dev_num
)
devnums
.
remove
(
d
.
dev_num
)
...
...
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