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
May 09, 2016
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:
print
(
"status_code: "
+
str
(
req
.
status_code
))
print
print
(
json
.
dumps
(
json
.
loads
(
req
.
text
),
sort_keys
=
True
,
indent
=
4
,
separators
=
(
","
,
": "
)))
indent
=
4
,
separators
=
(
","
,
": "
)))
print
# vm torles
...
...
@@ -186,10 +186,9 @@ with requests.Session() as session:
print
(
"status_code: "
+
str
(
req
.
status_code
))
print
print
(
json
.
dumps
(
json
.
loads
(
req
.
text
),
sort_keys
=
True
,
indent
=
4
,
separators
=
(
","
,
": "
)))
indent
=
4
,
separators
=
(
","
,
": "
)))
print
# Kijelentkezes
req
=
session
.
get
(
server
+
"occi/logout/"
,
headers
=
headers
,
verify
=
False
)
...
...
circle/occi/occi_infrastructure.py
View file @
01bf8c3a
...
...
@@ -5,6 +5,7 @@ from occi_core import Resource
from
occi_utils
import
action_list_for_resource
,
OcciActionInvocationError
from
occi_instances
import
COMPUTE_ACTIONS
from
common.models
import
HumanReadableException
from
vm.models
import
InstanceActivity
COMPUTE_STATES
=
{
...
...
@@ -91,8 +92,23 @@ class Compute(Resource):
self
.
save
(
user
,
attributes
)
else
:
raise
OcciActionInvocationError
(
message
=
"Undefined action."
)
# to refresh Compute attribute
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
):
""" Start action on a compute instance """
try
:
...
...
@@ -108,9 +124,11 @@ class Compute(Resource):
if
"method"
not
in
attributes
:
raise
OcciActionInvocationError
(
message
=
"No method given."
)
if
attributes
[
"method"
]
in
(
"graceful"
,
"acpioff"
,):
if
not
self
.
has_agent
():
raise
OcciActionInvocationError
(
message
=
"User agent is required."
)
try
:
# TODO: call shutdown properly
self
.
vm
.
shutdown
(
user
=
user
)
self
.
vm
.
shutdown
(
task
=
None
,
user
=
user
)
except
HumanReadableException
as
e
:
raise
OcciActionInvocationError
(
message
=
e
.
get_user_text
())
elif
attributes
[
"method"
]
in
(
"poweroff"
,):
...
...
@@ -127,9 +145,11 @@ class Compute(Resource):
if
"method"
not
in
attributes
:
raise
OcciActionInvocationError
(
message
=
"No method given."
)
if
attributes
[
"method"
]
in
(
"graceful"
,
"warm"
,):
if
not
self
.
has_agent
():
raise
OcciActionInvocationError
(
message
=
"User agent is required."
)
try
:
# TODO: not working for some reason
self
.
vm
.
restart
(
user
=
user
)
self
.
vm
.
reboot
(
user
=
user
)
except
HumanReadableException
as
e
:
raise
OcciActionInvocationError
(
message
=
e
.
get_user_text
())
elif
attributes
[
"method"
]
in
(
"cold"
,):
...
...
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