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
Gabriel Monnerat
slapos.core
Commits
05abf98d
Commit
05abf98d
authored
May 28, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8 whitespaces
parent
bd778c5f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
26 deletions
+33
-26
slapos/slap/slap.py
slapos/slap/slap.py
+33
-26
No files found.
slapos/slap/slap.py
View file @
05abf98d
...
@@ -56,6 +56,7 @@ fallback_logger.addHandler(fallback_handler)
...
@@ -56,6 +56,7 @@ fallback_logger.addHandler(fallback_handler)
DEFAULT_SOFTWARE_TYPE
=
'RootSoftwareInstance'
DEFAULT_SOFTWARE_TYPE
=
'RootSoftwareInstance'
# httplib.HTTPSConnection with key verification
# httplib.HTTPSConnection with key verification
class
HTTPSConnectionCA
(
httplib
.
HTTPSConnection
):
class
HTTPSConnectionCA
(
httplib
.
HTTPSConnection
):
"""Patched version of HTTPSConnection which verifies server certificate"""
"""Patched version of HTTPSConnection which verifies server certificate"""
...
@@ -84,6 +85,7 @@ class SlapDocument:
...
@@ -84,6 +85,7 @@ class SlapDocument:
# cause failures when accessing _connection_helper property.
# cause failures when accessing _connection_helper property.
self
.
_connection_helper
=
connection_helper
self
.
_connection_helper
=
connection_helper
class
SlapRequester
(
SlapDocument
):
class
SlapRequester
(
SlapDocument
):
"""
"""
Abstract class that allow to factor method for subclasses that use "request()"
Abstract class that allow to factor method for subclasses that use "request()"
...
@@ -119,7 +121,6 @@ class SoftwareRelease(SlapDocument):
...
@@ -119,7 +121,6 @@ class SoftwareRelease(SlapDocument):
"""
"""
Contains Software Release information
Contains Software Release information
"""
"""
zope
.
interface
.
implements
(
interface
.
ISoftwareRelease
)
zope
.
interface
.
implements
(
interface
.
ISoftwareRelease
)
def
__init__
(
self
,
software_release
=
None
,
computer_guid
=
None
,
**
kw
):
def
__init__
(
self
,
software_release
=
None
,
computer_guid
=
None
,
**
kw
):
...
@@ -155,7 +156,7 @@ class SoftwareRelease(SlapDocument):
...
@@ -155,7 +156,7 @@ class SoftwareRelease(SlapDocument):
# Does not follow interface
# Does not follow interface
self
.
_connection_helper
.
POST
(
'/softwareReleaseError'
,
{
self
.
_connection_helper
.
POST
(
'/softwareReleaseError'
,
{
'url'
:
self
.
getURI
(),
'url'
:
self
.
getURI
(),
'computer_id'
:
self
.
getComputerId
(),
'computer_id'
:
self
.
getComputerId
(),
'error_log'
:
error_log
})
'error_log'
:
error_log
})
except
Exception
:
except
Exception
:
(
logger
or
fallback_logger
).
error
(
traceback
.
format_exc
())
(
logger
or
fallback_logger
).
error
(
traceback
.
format_exc
())
...
@@ -178,6 +179,7 @@ class SoftwareRelease(SlapDocument):
...
@@ -178,6 +179,7 @@ class SoftwareRelease(SlapDocument):
def
getState
(
self
):
def
getState
(
self
):
return
getattr
(
self
,
'_requested_state'
,
'available'
)
return
getattr
(
self
,
'_requested_state'
,
'available'
)
# XXX What is this SoftwareInstance class?
# XXX What is this SoftwareInstance class?
class
SoftwareInstance
(
SlapDocument
):
class
SoftwareInstance
(
SlapDocument
):
"""
"""
...
@@ -191,22 +193,28 @@ class SoftwareInstance(SlapDocument):
...
@@ -191,22 +193,28 @@ class SoftwareInstance(SlapDocument):
for
k
,
v
in
kwargs
.
iteritems
():
for
k
,
v
in
kwargs
.
iteritems
():
setattr
(
self
,
k
,
v
)
setattr
(
self
,
k
,
v
)
"""Exposed exceptions"""
"""Exposed exceptions"""
# XXX Why do we need to expose exceptions?
# XXX Why do we need to expose exceptions?
class
ResourceNotReady
(
Exception
):
class
ResourceNotReady
(
Exception
):
zope
.
interface
.
implements
(
interface
.
IResourceNotReady
)
zope
.
interface
.
implements
(
interface
.
IResourceNotReady
)
class
ServerError
(
Exception
):
class
ServerError
(
Exception
):
zope
.
interface
.
implements
(
interface
.
IServerError
)
zope
.
interface
.
implements
(
interface
.
IServerError
)
class
NotFoundError
(
Exception
):
class
NotFoundError
(
Exception
):
zope
.
interface
.
implements
(
interface
.
INotFoundError
)
zope
.
interface
.
implements
(
interface
.
INotFoundError
)
class
Unauthorized
(
Exception
):
class
Unauthorized
(
Exception
):
zope
.
interface
.
implements
(
interface
.
IUnauthorized
)
zope
.
interface
.
implements
(
interface
.
IUnauthorized
)
class
Supply
(
SlapDocument
):
class
Supply
(
SlapDocument
):
zope
.
interface
.
implements
(
interface
.
ISupply
)
zope
.
interface
.
implements
(
interface
.
ISupply
)
def
supply
(
self
,
software_release
,
computer_guid
=
None
,
state
=
'available'
):
def
supply
(
self
,
software_release
,
computer_guid
=
None
,
state
=
'available'
):
...
@@ -219,13 +227,13 @@ class Supply(SlapDocument):
...
@@ -219,13 +227,13 @@ class Supply(SlapDocument):
raise
NotFoundError
(
"Computer %s has not been found by SlapOS Master."
raise
NotFoundError
(
"Computer %s has not been found by SlapOS Master."
%
computer_guid
)
%
computer_guid
)
class
OpenOrder
(
SlapRequester
):
class
OpenOrder
(
SlapRequester
):
zope
.
interface
.
implements
(
interface
.
IOpenOrder
)
zope
.
interface
.
implements
(
interface
.
IOpenOrder
)
def
request
(
self
,
software_release
,
partition_reference
,
def
request
(
self
,
software_release
,
partition_reference
,
partition_parameter_kw
=
None
,
software_type
=
None
,
filter_kw
=
None
,
partition_parameter_kw
=
None
,
software_type
=
None
,
state
=
None
,
shared
=
False
):
filter_kw
=
None
,
state
=
None
,
shared
=
False
):
if
partition_parameter_kw
is
None
:
if
partition_parameter_kw
is
None
:
partition_parameter_kw
=
{}
partition_parameter_kw
=
{}
if
filter_kw
is
None
:
if
filter_kw
is
None
:
...
@@ -239,7 +247,7 @@ class OpenOrder(SlapRequester):
...
@@ -239,7 +247,7 @@ class OpenOrder(SlapRequester):
# And second is a boolean.
# And second is a boolean.
'state'
:
xml_marshaller
.
dumps
(
state
),
'state'
:
xml_marshaller
.
dumps
(
state
),
'shared_xml'
:
xml_marshaller
.
dumps
(
shared
),
'shared_xml'
:
xml_marshaller
.
dumps
(
shared
),
}
}
if
software_type
is
not
None
:
if
software_type
is
not
None
:
request_dict
[
'software_type'
]
=
software_type
request_dict
[
'software_type'
]
=
software_type
else
:
else
:
...
@@ -257,6 +265,7 @@ class OpenOrder(SlapRequester):
...
@@ -257,6 +265,7 @@ class OpenOrder(SlapRequester):
computer
.
_connection_helper
=
self
.
_connection_helper
computer
.
_connection_helper
=
self
.
_connection_helper
return
computer
return
computer
def
_syncComputerInformation
(
func
):
def
_syncComputerInformation
(
func
):
"""
"""
Synchronize computer object with server information
Synchronize computer object with server information
...
@@ -277,8 +286,8 @@ def _syncComputerInformation(func):
...
@@ -277,8 +286,8 @@ def _syncComputerInformation(func):
return
func
(
self
,
*
args
,
**
kw
)
return
func
(
self
,
*
args
,
**
kw
)
return
decorated
return
decorated
class
Computer
(
SlapDocument
):
class
Computer
(
SlapDocument
):
zope
.
interface
.
implements
(
interface
.
IComputer
)
zope
.
interface
.
implements
(
interface
.
IComputer
)
def
__init__
(
self
,
computer_id
,
connection_helper
=
None
):
def
__init__
(
self
,
computer_id
,
connection_helper
=
None
):
...
@@ -304,7 +313,7 @@ class Computer(SlapDocument):
...
@@ -304,7 +313,7 @@ class Computer(SlapDocument):
def
getComputerPartitionList
(
self
):
def
getComputerPartitionList
(
self
):
for
computer_partition
in
self
.
_computer_partition_list
:
for
computer_partition
in
self
.
_computer_partition_list
:
computer_partition
.
_connection_helper
=
self
.
_connection_helper
computer_partition
.
_connection_helper
=
self
.
_connection_helper
return
[
x
for
x
in
self
.
_computer_partition_list
]
return
[
x
for
x
in
self
.
_computer_partition_list
]
def
reportUsage
(
self
,
computer_usage
):
def
reportUsage
(
self
,
computer_usage
):
if
computer_usage
==
""
:
if
computer_usage
==
""
:
...
@@ -315,7 +324,7 @@ class Computer(SlapDocument):
...
@@ -315,7 +324,7 @@ class Computer(SlapDocument):
def
updateConfiguration
(
self
,
xml
):
def
updateConfiguration
(
self
,
xml
):
return
self
.
_connection_helper
.
POST
(
return
self
.
_connection_helper
.
POST
(
'/loadComputerConfigurationFromXML'
,
{
'xml'
:
xml
})
'/loadComputerConfigurationFromXML'
,
{
'xml'
:
xml
})
def
bang
(
self
,
message
):
def
bang
(
self
,
message
):
self
.
_connection_helper
.
POST
(
'/computerBang'
,
{
self
.
_connection_helper
.
POST
(
'/computerBang'
,
{
...
@@ -351,11 +360,10 @@ def parsed_error_message(status, body, path):
...
@@ -351,11 +360,10 @@ def parsed_error_message(status, body, path):
class
ComputerPartition
(
SlapRequester
):
class
ComputerPartition
(
SlapRequester
):
zope
.
interface
.
implements
(
interface
.
IComputerPartition
)
zope
.
interface
.
implements
(
interface
.
IComputerPartition
)
def
__init__
(
self
,
computer_id
=
None
,
partition_id
=
None
,
request_dict
=
None
,
def
__init__
(
self
,
computer_id
=
None
,
partition_id
=
None
,
connection_helper
=
None
):
request_dict
=
None
,
connection_helper
=
None
):
SlapDocument
.
__init__
(
self
,
connection_helper
)
SlapDocument
.
__init__
(
self
,
connection_helper
)
if
request_dict
is
not
None
and
(
computer_id
is
not
None
or
if
request_dict
is
not
None
and
(
computer_id
is
not
None
or
partition_id
is
not
None
):
partition_id
is
not
None
):
...
@@ -377,13 +385,13 @@ class ComputerPartition(SlapRequester):
...
@@ -377,13 +385,13 @@ class ComputerPartition(SlapRequester):
if
partition_parameter_kw
is
None
:
if
partition_parameter_kw
is
None
:
partition_parameter_kw
=
{}
partition_parameter_kw
=
{}
elif
not
isinstance
(
partition_parameter_kw
,
dict
):
elif
not
isinstance
(
partition_parameter_kw
,
dict
):
raise
ValueError
(
"Unexpected type of partition_parameter_kw '%s'"
%
\
raise
ValueError
(
"Unexpected type of partition_parameter_kw '%s'"
%
partition_parameter_kw
)
partition_parameter_kw
)
if
filter_kw
is
None
:
if
filter_kw
is
None
:
filter_kw
=
{}
filter_kw
=
{}
elif
not
isinstance
(
filter_kw
,
dict
):
elif
not
isinstance
(
filter_kw
,
dict
):
raise
ValueError
(
"Unexpected type of filter_kw '%s'"
%
\
raise
ValueError
(
"Unexpected type of filter_kw '%s'"
%
filter_kw
)
filter_kw
)
# Let enforce a default software type
# Let enforce a default software type
...
@@ -528,6 +536,7 @@ class ComputerPartition(SlapRequester):
...
@@ -528,6 +536,7 @@ class ComputerPartition(SlapRequester):
'computer_partition_id=%s'
%
(
self
.
_computer_id
,
self
.
_partition_id
))
'computer_partition_id=%s'
%
(
self
.
_computer_id
,
self
.
_partition_id
))
return
xml_marshaller
.
loads
(
xml
)
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."
error_message_connect_fail
=
"Couldn't connect to the server. Please "
\
error_message_connect_fail
=
"Couldn't connect to the server. Please "
\
...
@@ -536,8 +545,9 @@ class ConnectionHelper:
...
@@ -536,8 +545,9 @@ class ConnectionHelper:
"original error was: "
"original error was: "
ssl_error_message_connect_fail
=
"
\
n
Couldn't authenticate computer. Please "
\
ssl_error_message_connect_fail
=
"
\
n
Couldn't authenticate computer. Please "
\
"check that certificate and key exist and are valid. "
"check that certificate and key exist and are valid. "
def
__init__
(
self
,
connection_wrapper
,
host
,
path
,
key_file
=
None
,
def
__init__
(
self
,
connection_wrapper
,
host
,
path
,
key_file
=
None
,
cert_file
=
None
,
master_ca_file
=
None
,
timeout
=
None
):
cert_file
=
None
,
master_ca_file
=
None
,
timeout
=
None
):
self
.
connection_wrapper
=
connection_wrapper
self
.
connection_wrapper
=
connection_wrapper
self
.
host
=
host
self
.
host
=
host
self
.
path
=
path
self
.
path
=
path
...
@@ -616,7 +626,7 @@ class ConnectionHelper:
...
@@ -616,7 +626,7 @@ class ConnectionHelper:
return
response
.
read
()
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
:
default_timeout
=
socket
.
getdefaulttimeout
()
default_timeout
=
socket
.
getdefaulttimeout
()
socket
.
setdefaulttimeout
(
self
.
timeout
)
socket
.
setdefaulttimeout
(
self
.
timeout
)
...
@@ -652,16 +662,13 @@ class ConnectionHelper:
...
@@ -652,16 +662,13 @@ class ConnectionHelper:
class
slap
:
class
slap
:
zope
.
interface
.
implements
(
interface
.
slap
)
zope
.
interface
.
implements
(
interface
.
slap
)
def
initializeConnection
(
self
,
slapgrid_uri
,
key_file
=
None
,
cert_file
=
None
,
def
initializeConnection
(
self
,
slapgrid_uri
,
key_file
=
None
,
cert_file
=
None
,
master_ca_file
=
None
,
timeout
=
60
):
master_ca_file
=
None
,
timeout
=
60
):
scheme
,
netloc
,
path
,
query
,
fragment
=
urlparse
.
urlsplit
(
scheme
,
netloc
,
path
,
query
,
fragment
=
urlparse
.
urlsplit
(
slapgrid_uri
)
slapgrid_uri
)
if
not
(
query
==
''
and
fragment
==
''
):
if
not
(
query
==
''
and
fragment
==
''
):
raise
AttributeError
(
'Passed URL %r issue: not parseable'
%
slapgrid_uri
)
raise
AttributeError
(
'Passed URL %r issue: not parseable'
%
slapgrid_uri
)
if
scheme
==
'http'
:
if
scheme
==
'http'
:
connection_wrapper
=
httplib
.
HTTPConnection
connection_wrapper
=
httplib
.
HTTPConnection
...
@@ -671,8 +678,8 @@ class slap:
...
@@ -671,8 +678,8 @@ class slap:
else
:
else
:
connection_wrapper
=
httplib
.
HTTPSConnection
connection_wrapper
=
httplib
.
HTTPSConnection
else
:
else
:
raise
AttributeError
(
'Passed URL %r issue: there is no support
for %r p
'
raise
AttributeError
(
'Passed URL %r issue: there is no support '
'
rotocol'
%
(
slapgrid_uri
,
scheme
))
'for %r p
rotocol'
%
(
slapgrid_uri
,
scheme
))
self
.
_connection_helper
=
ConnectionHelper
(
connection_wrapper
,
self
.
_connection_helper
=
ConnectionHelper
(
connection_wrapper
,
netloc
,
path
,
key_file
,
cert_file
,
master_ca_file
,
timeout
)
netloc
,
path
,
key_file
,
cert_file
,
master_ca_file
,
timeout
)
...
...
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