Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lisa Casino
slapos.core
Commits
5ecc02c2
Commit
5ecc02c2
authored
May 08, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
directly return content from GET() and POST() - no need for self.response
parent
6144a4b3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
35 deletions
+38
-35
slapos/slap/slap.py
slapos/slap/slap.py
+38
-35
No files found.
slapos/slap/slap.py
View file @
5ecc02c2
...
...
@@ -90,13 +90,12 @@ class SlapRequester(SlapDocument):
"""
def
_requestComputerPartition
(
self
,
request_dict
):
try
:
self
.
_connection_helper
.
POST
(
'/requestComputerPartition'
,
request_dict
)
xml
=
self
.
_connection_helper
.
POST
(
'/requestComputerPartition'
,
request_dict
)
except
ResourceNotReady
:
return
ComputerPartition
(
request_dict
=
request_dict
,
connection_helper
=
self
.
_connection_helper
,
)
xml
=
self
.
_connection_helper
.
response
.
read
()
software_instance
=
xml_marshaller
.
loads
(
xml
)
computer_partition
=
ComputerPartition
(
software_instance
.
slap_computer_id
.
encode
(
'UTF-8'
),
...
...
@@ -252,9 +251,8 @@ class OpenOrder(SlapRequester):
"""
Requests a computer.
"""
self
.
_connection_helper
.
POST
(
'/requestComputer'
,
xml
=
self
.
_connection_helper
.
POST
(
'/requestComputer'
,
{
'computer_title'
:
computer_reference
})
xml
=
self
.
_connection_helper
.
response
.
read
()
computer
=
xml_marshaller
.
loads
(
xml
)
computer
.
_connection_helper
=
self
.
_connection_helper
return
computer
...
...
@@ -316,9 +314,8 @@ class Computer(SlapDocument):
'use_string'
:
computer_usage
})
def
updateConfiguration
(
self
,
xml
):
self
.
_connection_helper
.
POST
(
return
self
.
_connection_helper
.
POST
(
'/loadComputerConfigurationFromXML'
,
{
'xml'
:
xml
})
return
self
.
_connection_helper
.
response
.
read
()
def
bang
(
self
,
message
):
self
.
_connection_helper
.
POST
(
'/computerBang'
,
{
...
...
@@ -326,18 +323,17 @@ class Computer(SlapDocument):
'message'
:
message
})
def
getStatus
(
self
):
self
.
_connection_helper
.
GET
(
xml
=
self
.
_connection_helper
.
GET
(
'/getComputerStatus?computer_id=%s'
%
self
.
_computer_id
)
return
xml_marshaller
.
loads
(
self
.
_connection_helper
.
response
.
read
()
)
return
xml_marshaller
.
loads
(
xml
)
def
revokeCertificate
(
self
):
self
.
_connection_helper
.
POST
(
'/revokeComputerCertificate'
,
{
'computer_id'
:
self
.
_computer_id
})
def
generateCertificate
(
self
):
self
.
_connection_helper
.
POST
(
'/generateComputerCertificate'
,
{
xml
=
self
.
_connection_helper
.
POST
(
'/generateComputerCertificate'
,
{
'computer_id'
:
self
.
_computer_id
})
xml
=
self
.
_connection_helper
.
response
.
read
()
return
xml_marshaller
.
loads
(
xml
)
...
...
@@ -521,16 +517,16 @@ class ComputerPartition(SlapRequester):
self
.
usage
=
usage_log
def
getCertificate
(
self
):
self
.
_connection_helper
.
GET
(
xml
=
self
.
_connection_helper
.
GET
(
'/getComputerPartitionCertificate?computer_id=%s&'
'computer_partition_id=%s'
%
(
self
.
_computer_id
,
self
.
_partition_id
))
return
xml_marshaller
.
loads
(
self
.
_connection_helper
.
response
.
read
()
)
return
xml_marshaller
.
loads
(
xml
)
def
getStatus
(
self
):
self
.
_connection_helper
.
GET
(
xml
=
self
.
_connection_helper
.
GET
(
'/getComputerPartitionStatus?computer_id=%s&'
'computer_partition_id=%s'
%
(
self
.
_computer_id
,
self
.
_partition_id
))
return
xml_marshaller
.
loads
(
self
.
_connection_helper
.
response
.
read
()
)
return
xml_marshaller
.
loads
(
xml
)
class
ConnectionHelper
:
error_message_timeout
=
"
\
n
The connection timed out. Please try again later."
...
...
@@ -551,8 +547,8 @@ class ConnectionHelper:
self
.
timeout
=
timeout
def
getComputerInformation
(
self
,
computer_id
):
self
.
GET
(
'/getComputerInformation?computer_id=%s'
%
computer_id
)
return
xml_marshaller
.
loads
(
self
.
response
.
read
()
)
xml
=
self
.
GET
(
'/getComputerInformation?computer_id=%s'
%
computer_id
)
return
xml_marshaller
.
loads
(
xml
)
def
getFullComputerInformation
(
self
,
computer_id
):
"""
...
...
@@ -564,13 +560,13 @@ class ConnectionHelper:
# XXX-Cedric: should raise something smarter than "NotFound".
raise
NotFoundError
(
method
)
try
:
self
.
GET
(
method
)
xml
=
self
.
GET
(
method
)
except
NotFoundError
:
# XXX: This is a ugly way to keep backward compatibility,
# We should stablise slap library soon.
self
.
GET
(
'/getComputerInformation?computer_id=%s'
%
computer_id
)
xml
=
self
.
GET
(
'/getComputerInformation?computer_id=%s'
%
computer_id
)
return
xml_marshaller
.
loads
(
self
.
response
.
read
()
)
return
xml_marshaller
.
loads
(
xml
)
def
connect
(
self
):
connection_dict
=
dict
(
...
...
@@ -590,7 +586,7 @@ class ConnectionHelper:
try
:
self
.
connect
()
self
.
connection
.
request
(
'GET'
,
self
.
path
+
path
)
self
.
response
=
self
.
connection
.
getresponse
()
response
=
self
.
connection
.
getresponse
()
# If ssl error : may come from bad configuration
except
ssl
.
SSLError
,
e
:
if
e
.
message
==
"The read operation timed out"
:
...
...
@@ -600,22 +596,25 @@ class ConnectionHelper:
if
e
.
message
==
"timed out"
:
raise
socket
.
error
(
str
(
e
)
+
self
.
error_message_timeout
)
raise
socket
.
error
(
self
.
error_message_connect_fail
+
str
(
e
))
# check self.response.status and raise exception early
if
self
.
response
.
status
==
httplib
.
REQUEST_TIMEOUT
:
if
response
.
status
==
httplib
.
REQUEST_TIMEOUT
:
# resource is not ready
raise
ResourceNotReady
(
path
)
elif
self
.
response
.
status
==
httplib
.
NOT_FOUND
:
elif
response
.
status
==
httplib
.
NOT_FOUND
:
raise
NotFoundError
(
path
)
elif
self
.
response
.
status
==
httplib
.
FORBIDDEN
:
elif
response
.
status
==
httplib
.
FORBIDDEN
:
raise
Unauthorized
(
path
)
elif
self
.
response
.
status
!=
httplib
.
OK
:
message
=
parsed_error_message
(
self
.
response
.
status
,
self
.
response
.
read
(),
elif
response
.
status
!=
httplib
.
OK
:
message
=
parsed_error_message
(
response
.
status
,
response
.
read
(),
path
)
raise
ServerError
(
message
)
finally
:
socket
.
setdefaulttimeout
(
default_timeout
)
return
response
.
read
()
def
POST
(
self
,
path
,
parameter_dict
,
content_type
=
"application/x-www-form-urlencoded"
):
try
:
...
...
@@ -631,23 +630,27 @@ class ConnectionHelper:
raise
ssl
.
SSLError
(
self
.
ssl_error_message_connect_fail
+
str
(
e
))
except
socket
.
error
,
e
:
raise
socket
.
error
(
self
.
error_message_connect_fail
+
str
(
e
))
self
.
response
=
self
.
connection
.
getresponse
()
response
=
self
.
connection
.
getresponse
()
# check self.response.status and raise exception early
if
self
.
response
.
status
==
httplib
.
REQUEST_TIMEOUT
:
if
response
.
status
==
httplib
.
REQUEST_TIMEOUT
:
# resource is not ready
raise
ResourceNotReady
(
"%s - %s"
%
(
path
,
parameter_dict
))
elif
self
.
response
.
status
==
httplib
.
NOT_FOUND
:
elif
response
.
status
==
httplib
.
NOT_FOUND
:
raise
NotFoundError
(
"%s - %s"
%
(
path
,
parameter_dict
))
elif
self
.
response
.
status
==
httplib
.
FORBIDDEN
:
elif
response
.
status
==
httplib
.
FORBIDDEN
:
raise
Unauthorized
(
"%s - %s"
%
(
path
,
parameter_dict
))
elif
self
.
response
.
status
!=
httplib
.
OK
:
message
=
parsed_error_message
(
self
.
response
.
status
,
self
.
response
.
read
(),
elif
response
.
status
!=
httplib
.
OK
:
message
=
parsed_error_message
(
response
.
status
,
response
.
read
(),
path
)
raise
ServerError
(
message
)
finally
:
socket
.
setdefaulttimeout
(
default_timeout
)
return
response
.
read
()
class
slap
:
zope
.
interface
.
implements
(
interface
.
slap
)
...
...
@@ -699,10 +702,10 @@ class slap:
# XXX-Cedric: should raise something smarter than NotFound
raise
NotFoundError
self
.
_connection_helper
.
GET
(
'/registerComputerPartition?'
\
xml
=
self
.
_connection_helper
.
GET
(
'/registerComputerPartition?'
\
'computer_reference=%s&computer_partition_reference=%s'
%
(
computer_guid
,
partition_id
))
result
=
xml_marshaller
.
loads
(
self
.
_connection_helper
.
response
.
read
()
)
result
=
xml_marshaller
.
loads
(
xml
)
# XXX: dirty hack to make computer partition usable. xml_marshaller is too
# low-level for our needs here.
result
.
_connection_helper
=
self
.
_connection_helper
...
...
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