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
01bf8c3a
authored
8 years ago
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checking user agent for shutdown and reboot operations
parent
a9d62221
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
7 deletions
+26
-7
circle/occi/occi_client_example.py
+2
-3
circle/occi/occi_infrastructure.py
+24
-4
No files found.
circle/occi/occi_client_example.py
View file @
01bf8c3a
...
@@ -169,7 +169,7 @@ with requests.Session() as session:
...
@@ -169,7 +169,7 @@ with requests.Session() as session:
print
(
"status_code: "
+
str
(
req
.
status_code
))
print
(
"status_code: "
+
str
(
req
.
status_code
))
print
print
print
(
json
.
dumps
(
json
.
loads
(
req
.
text
),
sort_keys
=
True
,
print
(
json
.
dumps
(
json
.
loads
(
req
.
text
),
sort_keys
=
True
,
indent
=
4
,
separators
=
(
","
,
": "
)))
indent
=
4
,
separators
=
(
","
,
": "
)))
print
print
# vm torles
# vm torles
...
@@ -186,10 +186,9 @@ with requests.Session() as session:
...
@@ -186,10 +186,9 @@ with requests.Session() as session:
print
(
"status_code: "
+
str
(
req
.
status_code
))
print
(
"status_code: "
+
str
(
req
.
status_code
))
print
print
print
(
json
.
dumps
(
json
.
loads
(
req
.
text
),
sort_keys
=
True
,
print
(
json
.
dumps
(
json
.
loads
(
req
.
text
),
sort_keys
=
True
,
indent
=
4
,
separators
=
(
","
,
": "
)))
indent
=
4
,
separators
=
(
","
,
": "
)))
print
print
# Kijelentkezes
# Kijelentkezes
req
=
session
.
get
(
server
+
"occi/logout/"
,
headers
=
headers
,
req
=
session
.
get
(
server
+
"occi/logout/"
,
headers
=
headers
,
verify
=
False
)
verify
=
False
)
...
...
This diff is collapsed.
Click to expand it.
circle/occi/occi_infrastructure.py
View file @
01bf8c3a
...
@@ -5,6 +5,7 @@ from occi_core import Resource
...
@@ -5,6 +5,7 @@ from occi_core import Resource
from
occi_utils
import
action_list_for_resource
,
OcciActionInvocationError
from
occi_utils
import
action_list_for_resource
,
OcciActionInvocationError
from
occi_instances
import
COMPUTE_ACTIONS
from
occi_instances
import
COMPUTE_ACTIONS
from
common.models
import
HumanReadableException
from
common.models
import
HumanReadableException
from
vm.models
import
InstanceActivity
COMPUTE_STATES
=
{
COMPUTE_STATES
=
{
...
@@ -91,8 +92,23 @@ class Compute(Resource):
...
@@ -91,8 +92,23 @@ class Compute(Resource):
self
.
save
(
user
,
attributes
)
self
.
save
(
user
,
attributes
)
else
:
else
:
raise
OcciActionInvocationError
(
message
=
"Undefined action."
)
raise
OcciActionInvocationError
(
message
=
"Undefined action."
)
# to refresh Compute attribute
self
.
__init__
(
self
.
vm
)
self
.
__init__
(
self
.
vm
)
def
has_agent
(
self
):
last_boot_time
=
self
.
vm
.
activity_log
.
filter
(
succeeded
=
True
,
activity_code__in
=
(
"vm.Instance.deploy"
,
"vm.Instance.reset"
,
"vm.Instance.reboot"
))
.
latest
(
"finished"
)
.
finished
try
:
InstanceActivity
.
objects
.
filter
(
activity_code
=
"vm.Instance.agent.starting"
,
started__gt
=
last_boot_time
,
instance
=
self
.
vm
)
.
latest
(
"started"
)
except
InstanceActivity
.
DoesNotExist
:
# no agent since last boot
return
False
return
True
def
start
(
self
,
user
):
def
start
(
self
,
user
):
""" Start action on a compute instance """
""" Start action on a compute instance """
try
:
try
:
...
@@ -108,9 +124,11 @@ class Compute(Resource):
...
@@ -108,9 +124,11 @@ class Compute(Resource):
if
"method"
not
in
attributes
:
if
"method"
not
in
attributes
:
raise
OcciActionInvocationError
(
message
=
"No method given."
)
raise
OcciActionInvocationError
(
message
=
"No method given."
)
if
attributes
[
"method"
]
in
(
"graceful"
,
"acpioff"
,):
if
attributes
[
"method"
]
in
(
"graceful"
,
"acpioff"
,):
if
not
self
.
has_agent
():
raise
OcciActionInvocationError
(
message
=
"User agent is required."
)
try
:
try
:
# TODO: call shutdown properly
self
.
vm
.
shutdown
(
task
=
None
,
user
=
user
)
self
.
vm
.
shutdown
(
user
=
user
)
except
HumanReadableException
as
e
:
except
HumanReadableException
as
e
:
raise
OcciActionInvocationError
(
message
=
e
.
get_user_text
())
raise
OcciActionInvocationError
(
message
=
e
.
get_user_text
())
elif
attributes
[
"method"
]
in
(
"poweroff"
,):
elif
attributes
[
"method"
]
in
(
"poweroff"
,):
...
@@ -127,9 +145,11 @@ class Compute(Resource):
...
@@ -127,9 +145,11 @@ class Compute(Resource):
if
"method"
not
in
attributes
:
if
"method"
not
in
attributes
:
raise
OcciActionInvocationError
(
message
=
"No method given."
)
raise
OcciActionInvocationError
(
message
=
"No method given."
)
if
attributes
[
"method"
]
in
(
"graceful"
,
"warm"
,):
if
attributes
[
"method"
]
in
(
"graceful"
,
"warm"
,):
if
not
self
.
has_agent
():
raise
OcciActionInvocationError
(
message
=
"User agent is required."
)
try
:
try
:
# TODO: not working for some reason
self
.
vm
.
reboot
(
user
=
user
)
self
.
vm
.
restart
(
user
=
user
)
except
HumanReadableException
as
e
:
except
HumanReadableException
as
e
:
raise
OcciActionInvocationError
(
message
=
e
.
get_user_text
())
raise
OcciActionInvocationError
(
message
=
e
.
get_user_text
())
elif
attributes
[
"method"
]
in
(
"cold"
,):
elif
attributes
[
"method"
]
in
(
"cold"
,):
...
...
This diff is collapsed.
Click to expand it.
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