Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
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
Pipeline
#104
failed with stage
in 0 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
circle/occi/occi_client_example.py
+0
-1
circle/occi/occi_infrastructure.py
+24
-4
No files found.
circle/occi/occi_client_example.py
View file @
01bf8c3a
...
...
@@ -189,7 +189,6 @@ with requests.Session() as session:
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