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
Nicolas Wavrant
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
Hide 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):
...
@@ -90,13 +90,12 @@ class SlapRequester(SlapDocument):
"""
"""
def
_requestComputerPartition
(
self
,
request_dict
):
def
_requestComputerPartition
(
self
,
request_dict
):
try
:
try
:
self
.
_connection_helper
.
POST
(
'/requestComputerPartition'
,
request_dict
)
xml
=
self
.
_connection_helper
.
POST
(
'/requestComputerPartition'
,
request_dict
)
except
ResourceNotReady
:
except
ResourceNotReady
:
return
ComputerPartition
(
return
ComputerPartition
(
request_dict
=
request_dict
,
request_dict
=
request_dict
,
connection_helper
=
self
.
_connection_helper
,
connection_helper
=
self
.
_connection_helper
,
)
)
xml
=
self
.
_connection_helper
.
response
.
read
()
software_instance
=
xml_marshaller
.
loads
(
xml
)
software_instance
=
xml_marshaller
.
loads
(
xml
)
computer_partition
=
ComputerPartition
(
computer_partition
=
ComputerPartition
(
software_instance
.
slap_computer_id
.
encode
(
'UTF-8'
),
software_instance
.
slap_computer_id
.
encode
(
'UTF-8'
),
...
@@ -252,9 +251,8 @@ class OpenOrder(SlapRequester):
...
@@ -252,9 +251,8 @@ class OpenOrder(SlapRequester):
"""
"""
Requests a computer.
Requests a computer.
"""
"""
self
.
_connection_helper
.
POST
(
'/requestComputer'
,
xml
=
self
.
_connection_helper
.
POST
(
'/requestComputer'
,
{
'computer_title'
:
computer_reference
})
{
'computer_title'
:
computer_reference
})
xml
=
self
.
_connection_helper
.
response
.
read
()
computer
=
xml_marshaller
.
loads
(
xml
)
computer
=
xml_marshaller
.
loads
(
xml
)
computer
.
_connection_helper
=
self
.
_connection_helper
computer
.
_connection_helper
=
self
.
_connection_helper
return
computer
return
computer
...
@@ -316,9 +314,8 @@ class Computer(SlapDocument):
...
@@ -316,9 +314,8 @@ class Computer(SlapDocument):
'use_string'
:
computer_usage
})
'use_string'
:
computer_usage
})
def
updateConfiguration
(
self
,
xml
):
def
updateConfiguration
(
self
,
xml
):
self
.
_connection_helper
.
POST
(
return
self
.
_connection_helper
.
POST
(
'/loadComputerConfigurationFromXML'
,
{
'xml'
:
xml
})
'/loadComputerConfigurationFromXML'
,
{
'xml'
:
xml
})
return
self
.
_connection_helper
.
response
.
read
()
def
bang
(
self
,
message
):
def
bang
(
self
,
message
):
self
.
_connection_helper
.
POST
(
'/computerBang'
,
{
self
.
_connection_helper
.
POST
(
'/computerBang'
,
{
...
@@ -326,18 +323,17 @@ class Computer(SlapDocument):
...
@@ -326,18 +323,17 @@ class Computer(SlapDocument):
'message'
:
message
})
'message'
:
message
})
def
getStatus
(
self
):
def
getStatus
(
self
):
self
.
_connection_helper
.
GET
(
xml
=
self
.
_connection_helper
.
GET
(
'/getComputerStatus?computer_id=%s'
%
self
.
_computer_id
)
'/getComputerStatus?computer_id=%s'
%
self
.
_computer_id
)
return
xml_marshaller
.
loads
(
self
.
_connection_helper
.
response
.
read
()
)
return
xml_marshaller
.
loads
(
xml
)
def
revokeCertificate
(
self
):
def
revokeCertificate
(
self
):
self
.
_connection_helper
.
POST
(
'/revokeComputerCertificate'
,
{
self
.
_connection_helper
.
POST
(
'/revokeComputerCertificate'
,
{
'computer_id'
:
self
.
_computer_id
})
'computer_id'
:
self
.
_computer_id
})
def
generateCertificate
(
self
):
def
generateCertificate
(
self
):
self
.
_connection_helper
.
POST
(
'/generateComputerCertificate'
,
{
xml
=
self
.
_connection_helper
.
POST
(
'/generateComputerCertificate'
,
{
'computer_id'
:
self
.
_computer_id
})
'computer_id'
:
self
.
_computer_id
})
xml
=
self
.
_connection_helper
.
response
.
read
()
return
xml_marshaller
.
loads
(
xml
)
return
xml_marshaller
.
loads
(
xml
)
...
@@ -521,16 +517,16 @@ class ComputerPartition(SlapRequester):
...
@@ -521,16 +517,16 @@ class ComputerPartition(SlapRequester):
self
.
usage
=
usage_log
self
.
usage
=
usage_log
def
getCertificate
(
self
):
def
getCertificate
(
self
):
self
.
_connection_helper
.
GET
(
xml
=
self
.
_connection_helper
.
GET
(
'/getComputerPartitionCertificate?computer_id=%s&'
'/getComputerPartitionCertificate?computer_id=%s&'
'computer_partition_id=%s'
%
(
self
.
_computer_id
,
self
.
_partition_id
))
'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
):
def
getStatus
(
self
):
self
.
_connection_helper
.
GET
(
xml
=
self
.
_connection_helper
.
GET
(
'/getComputerPartitionStatus?computer_id=%s&'
'/getComputerPartitionStatus?computer_id=%s&'
'computer_partition_id=%s'
%
(
self
.
_computer_id
,
self
.
_partition_id
))
'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
:
class
ConnectionHelper
:
error_message_timeout
=
"
\
n
The connection timed out. Please try again later."
error_message_timeout
=
"
\
n
The connection timed out. Please try again later."
...
@@ -551,8 +547,8 @@ class ConnectionHelper:
...
@@ -551,8 +547,8 @@ class ConnectionHelper:
self
.
timeout
=
timeout
self
.
timeout
=
timeout
def
getComputerInformation
(
self
,
computer_id
):
def
getComputerInformation
(
self
,
computer_id
):
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
getFullComputerInformation
(
self
,
computer_id
):
def
getFullComputerInformation
(
self
,
computer_id
):
"""
"""
...
@@ -564,13 +560,13 @@ class ConnectionHelper:
...
@@ -564,13 +560,13 @@ class ConnectionHelper:
# XXX-Cedric: should raise something smarter than "NotFound".
# XXX-Cedric: should raise something smarter than "NotFound".
raise
NotFoundError
(
method
)
raise
NotFoundError
(
method
)
try
:
try
:
self
.
GET
(
method
)
xml
=
self
.
GET
(
method
)
except
NotFoundError
:
except
NotFoundError
:
# XXX: This is a ugly way to keep backward compatibility,
# XXX: This is a ugly way to keep backward compatibility,
# We should stablise slap library soon.
# 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
):
def
connect
(
self
):
connection_dict
=
dict
(
connection_dict
=
dict
(
...
@@ -590,7 +586,7 @@ class ConnectionHelper:
...
@@ -590,7 +586,7 @@ class ConnectionHelper:
try
:
try
:
self
.
connect
()
self
.
connect
()
self
.
connection
.
request
(
'GET'
,
self
.
path
+
path
)
self
.
connection
.
request
(
'GET'
,
self
.
path
+
path
)
self
.
response
=
self
.
connection
.
getresponse
()
response
=
self
.
connection
.
getresponse
()
# If ssl error : may come from bad configuration
# If ssl error : may come from bad configuration
except
ssl
.
SSLError
,
e
:
except
ssl
.
SSLError
,
e
:
if
e
.
message
==
"The read operation timed out"
:
if
e
.
message
==
"The read operation timed out"
:
...
@@ -600,22 +596,25 @@ class ConnectionHelper:
...
@@ -600,22 +596,25 @@ class ConnectionHelper:
if
e
.
message
==
"timed out"
:
if
e
.
message
==
"timed out"
:
raise
socket
.
error
(
str
(
e
)
+
self
.
error_message_timeout
)
raise
socket
.
error
(
str
(
e
)
+
self
.
error_message_timeout
)
raise
socket
.
error
(
self
.
error_message_connect_fail
+
str
(
e
))
raise
socket
.
error
(
self
.
error_message_connect_fail
+
str
(
e
))
# check self.response.status and raise exception early
# 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
# resource is not ready
raise
ResourceNotReady
(
path
)
raise
ResourceNotReady
(
path
)
elif
self
.
response
.
status
==
httplib
.
NOT_FOUND
:
elif
response
.
status
==
httplib
.
NOT_FOUND
:
raise
NotFoundError
(
path
)
raise
NotFoundError
(
path
)
elif
self
.
response
.
status
==
httplib
.
FORBIDDEN
:
elif
response
.
status
==
httplib
.
FORBIDDEN
:
raise
Unauthorized
(
path
)
raise
Unauthorized
(
path
)
elif
self
.
response
.
status
!=
httplib
.
OK
:
elif
response
.
status
!=
httplib
.
OK
:
message
=
parsed_error_message
(
self
.
response
.
status
,
message
=
parsed_error_message
(
response
.
status
,
self
.
response
.
read
(),
response
.
read
(),
path
)
path
)
raise
ServerError
(
message
)
raise
ServerError
(
message
)
finally
:
finally
:
socket
.
setdefaulttimeout
(
default_timeout
)
socket
.
setdefaulttimeout
(
default_timeout
)
return
response
.
read
()
def
POST
(
self
,
path
,
parameter_dict
,
def
POST
(
self
,
path
,
parameter_dict
,
content_type
=
"application/x-www-form-urlencoded"
):
content_type
=
"application/x-www-form-urlencoded"
):
try
:
try
:
...
@@ -631,23 +630,27 @@ class ConnectionHelper:
...
@@ -631,23 +630,27 @@ class ConnectionHelper:
raise
ssl
.
SSLError
(
self
.
ssl_error_message_connect_fail
+
str
(
e
))
raise
ssl
.
SSLError
(
self
.
ssl_error_message_connect_fail
+
str
(
e
))
except
socket
.
error
,
e
:
except
socket
.
error
,
e
:
raise
socket
.
error
(
self
.
error_message_connect_fail
+
str
(
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
# 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
# resource is not ready
raise
ResourceNotReady
(
"%s - %s"
%
(
path
,
parameter_dict
))
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
))
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
))
raise
Unauthorized
(
"%s - %s"
%
(
path
,
parameter_dict
))
elif
self
.
response
.
status
!=
httplib
.
OK
:
elif
response
.
status
!=
httplib
.
OK
:
message
=
parsed_error_message
(
self
.
response
.
status
,
message
=
parsed_error_message
(
response
.
status
,
self
.
response
.
read
(),
response
.
read
(),
path
)
path
)
raise
ServerError
(
message
)
raise
ServerError
(
message
)
finally
:
finally
:
socket
.
setdefaulttimeout
(
default_timeout
)
socket
.
setdefaulttimeout
(
default_timeout
)
return
response
.
read
()
class
slap
:
class
slap
:
zope
.
interface
.
implements
(
interface
.
slap
)
zope
.
interface
.
implements
(
interface
.
slap
)
...
@@ -699,10 +702,10 @@ class slap:
...
@@ -699,10 +702,10 @@ class slap:
# XXX-Cedric: should raise something smarter than NotFound
# XXX-Cedric: should raise something smarter than NotFound
raise
NotFoundError
raise
NotFoundError
self
.
_connection_helper
.
GET
(
'/registerComputerPartition?'
\
xml
=
self
.
_connection_helper
.
GET
(
'/registerComputerPartition?'
\
'computer_reference=%s&computer_partition_reference=%s'
%
(
'computer_reference=%s&computer_partition_reference=%s'
%
(
computer_guid
,
partition_id
))
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
# XXX: dirty hack to make computer partition usable. xml_marshaller is too
# low-level for our needs here.
# low-level for our needs here.
result
.
_connection_helper
=
self
.
_connection_helper
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