Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
0f34885e
authored
Jan 22, 2015
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: look for missing attributes
parent
d61fb9f3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
22 deletions
+28
-22
circle/occi/occi.py
+28
-22
No files found.
circle/occi/occi.py
View file @
0f34885e
...
...
@@ -2,12 +2,8 @@ import re
import
logging
from
django.template.loader
import
render_to_string
from
django.utils
import
timezone
from
django.utils.formats
import
date_format
from
django.utils.translation
import
ugettext_noop
from
django_sshkey.models
import
UserKey
from
firewall.models
import
Vlan
from
storage.models
import
Disk
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
,
Interface
...
...
@@ -60,6 +56,15 @@ occi_inline_attribute_regex = '.*%(attribute)s="?(?P<value>[\w/\.:#\-]+)"?.*'
occi_attribute_link_regex
=
'^/
%
s/(?P<id>
\
d+)/?'
def
check_missing_attributes
(
required
,
given
):
subset
=
set
(
required
)
-
set
(
given
.
keys
())
if
subset
:
raise
humanize_exception
(
ugettext_noop
(
"Missing attribute(s):
%
s"
%
", "
.
join
(
subset
)),
Exception
()
)
class
Category
():
"""Represents a Category object
...
...
@@ -177,12 +182,21 @@ class Compute(Resource):
params
[
'owner'
]
=
user
title
=
attributes
.
get
(
"occi.core.title"
)
if
title
:
params
[
'name'
]
=
title
params
[
'name'
]
=
title
.
decode
(
"utf-8"
)
if
template
:
inst
=
Instance
.
create_from_template
(
template
=
template
,
**
params
)
else
:
# trivial
required
=
[
"occi.compute.architecture"
,
"occi.compute.cores"
,
"occi.compute.speed"
,
"occi.compute.memory"
,
"occi.core.title"
]
check_missing_attributes
(
required
,
attributes
)
if
"x86"
in
attributes
[
'occi.compute.architecture'
]:
params
[
'arch'
]
=
X86_ARCH
else
:
...
...
@@ -206,10 +220,6 @@ class Compute(Resource):
params
[
'lease'
]
=
Lease
.
objects
.
all
()[
0
]
params
[
'access_method'
]
=
ACCESS_METHODS
[
0
][
0
]
# if no name is given
if
not
params
.
get
(
"name"
):
params
[
'name'
]
=
"Created via OCCI by
%
s"
%
user
inst
=
Instance
.
create
(
params
=
params
,
disks
=
[],
networks
=
[],
req_traits
=
[],
tags
=
[])
...
...
@@ -287,14 +297,12 @@ class Compute(Resource):
"inactive"
)
def
trigger_action
(
self
,
data
,
user
):
method
=
None
attributes
=
{}
action_term
=
None
for
d
in
data
:
m
=
occi_attribute_regex
.
match
(
d
)
if
m
:
attribute
=
m
.
group
(
"attribute"
)
if
attribute
==
"method"
:
method
=
m
.
group
(
"value"
)
attr
=
occi_attribute_regex
.
match
(
d
)
if
attr
:
attributes
[
attr
.
group
(
"attribute"
)]
=
attr
.
group
(
"value"
)
m
=
occi_action_regex
.
match
(
d
)
if
m
:
...
...
@@ -307,11 +315,8 @@ class Compute(Resource):
operation
=
"deploy"
else
:
action
=
compute_action_to_operation
.
get
(
action_term
)
if
not
method
:
raise
humanize_exception
(
ugettext_noop
(
"Missing 'method' attribute."
),
Exception
())
operation
=
action
.
get
(
method
)
check_missing_attributes
([
"method"
],
attributes
)
operation
=
action
.
get
(
attributes
[
'method'
])
getattr
(
self
.
instance
,
operation
)
.
async
(
user
=
user
)
...
...
@@ -359,13 +364,14 @@ class Storage(Resource):
if
attr
:
attributes
[
attr
.
group
(
"attribute"
)]
=
attr
.
group
(
"value"
)
check_missing_attributes
(
[
"occi.storage.size"
,
"occi.core.title"
],
attributes
)
size
=
attributes
.
get
(
"occi.storage.size"
)
if
not
(
size
and
size
.
isdigit
()):
return
None
name
=
attributes
.
get
(
"occi.core.title"
)
if
not
name
:
name
=
"disk create from OCCI at
%
s"
%
timezone
.
now
()
params
=
{
'user'
:
user
,
# not used
...
...
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