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
Paul Graydon
slapos.core
Commits
14a63810
Commit
14a63810
authored
Apr 30, 2013
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor request methods.
parent
428e9dad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
50 deletions
+36
-50
slapos/slap/slap.py
slapos/slap/slap.py
+36
-50
No files found.
slapos/slap/slap.py
View file @
14a63810
...
@@ -77,6 +77,36 @@ class SlapDocument:
...
@@ -77,6 +77,36 @@ 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
):
"""
Abstract class that allow to factor method for subclasses that use "request()"
"""
def
_requestComputerPartition
(
self
,
request_dict
):
try
:
self
.
_connection_helper
.
POST
(
'/requestComputerPartition'
,
request_dict
)
except
ResourceNotReady
:
return
ComputerPartition
(
request_dict
=
request_dict
,
connection_helper
=
self
.
_connection_helper
,
)
else
:
xml
=
self
.
_connection_helper
.
response
.
read
()
software_instance
=
xml_marshaller
.
loads
(
xml
)
computer_partition
=
ComputerPartition
(
software_instance
.
slap_computer_id
.
encode
(
'UTF-8'
),
software_instance
.
slap_computer_partition_id
.
encode
(
'UTF-8'
),
connection_helper
=
self
.
_connection_helper
,
)
# Hack to give all object attributes to the ComputerPartition instance
computer_partition
.
__dict__
=
software_instance
.
__dict__
.
copy
()
# XXX not generic enough.
if
xml_marshaller
.
loads
(
request_dict
[
'shared_xml'
]):
computer_partition
.
_synced
=
True
computer_partition
.
_connection_dict
=
software_instance
.
_connection_dict
computer_partition
.
_parameter_dict
=
software_instance
.
_parameter_dict
return
computer_partition
class
SoftwareRelease
(
SlapDocument
):
class
SoftwareRelease
(
SlapDocument
):
"""
"""
Contains Software Release information
Contains Software Release information
...
@@ -182,7 +212,7 @@ class Supply(SlapDocument):
...
@@ -182,7 +212,7 @@ 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
(
Slap
Document
):
class
OpenOrder
(
Slap
Requester
):
zope
.
interface
.
implements
(
interface
.
IOpenOrder
)
zope
.
interface
.
implements
(
interface
.
IOpenOrder
)
...
@@ -208,28 +238,7 @@ class OpenOrder(SlapDocument):
...
@@ -208,28 +238,7 @@ class OpenOrder(SlapDocument):
else
:
else
:
# Let's enforce a default software type
# Let's enforce a default software type
request_dict
[
'software_type'
]
=
DEFAULT_SOFTWARE_TYPE
request_dict
[
'software_type'
]
=
DEFAULT_SOFTWARE_TYPE
try
:
return
self
.
_requestComputerPartition
(
request_dict
)
self
.
_connection_helper
.
POST
(
'/requestComputerPartition'
,
request_dict
)
except
ResourceNotReady
:
return
ComputerPartition
(
request_dict
=
request_dict
,
connection_helper
=
self
.
_connection_helper
,
)
else
:
xml
=
self
.
_connection_helper
.
response
.
read
()
software_instance
=
xml_marshaller
.
loads
(
xml
)
computer_partition
=
ComputerPartition
(
software_instance
.
slap_computer_id
.
encode
(
'UTF-8'
),
software_instance
.
slap_computer_partition_id
.
encode
(
'UTF-8'
),
connection_helper
=
self
.
_connection_helper
,
)
# Hack to give all object attributes to the ComputerPartition instance
computer_partition
.
__dict__
=
software_instance
.
__dict__
.
copy
()
if
shared
:
computer_partition
.
_synced
=
True
computer_partition
.
_connection_dict
=
software_instance
.
_connection_dict
computer_partition
.
_parameter_dict
=
software_instance
.
_parameter_dict
return
computer_partition
def
requestComputer
(
self
,
computer_reference
):
def
requestComputer
(
self
,
computer_reference
):
"""
"""
...
@@ -345,7 +354,6 @@ class ComputerPartition(SlapDocument):
...
@@ -345,7 +354,6 @@ class ComputerPartition(SlapDocument):
def
__getinitargs__
(
self
):
def
__getinitargs__
(
self
):
return
(
self
.
_computer_id
,
self
.
_partition_id
,
)
return
(
self
.
_computer_id
,
self
.
_partition_id
,
)
# XXX-Cedric: Factor me with OpenOrder.request()
def
request
(
self
,
software_release
,
software_type
,
partition_reference
,
def
request
(
self
,
software_release
,
software_type
,
partition_reference
,
shared
=
False
,
partition_parameter_kw
=
None
,
filter_kw
=
None
,
shared
=
False
,
partition_parameter_kw
=
None
,
filter_kw
=
None
,
state
=
None
):
state
=
None
):
...
@@ -365,7 +373,8 @@ class ComputerPartition(SlapDocument):
...
@@ -365,7 +373,8 @@ class ComputerPartition(SlapDocument):
if
software_type
is
None
:
if
software_type
is
None
:
software_type
=
DEFAULT_SOFTWARE_TYPE
software_type
=
DEFAULT_SOFTWARE_TYPE
request_dict
=
{
'computer_id'
:
self
.
_computer_id
,
request_dict
=
{
'computer_id'
:
self
.
_computer_id
,
'computer_partition_id'
:
self
.
_partition_id
,
'computer_partition_id'
:
self
.
_partition_id
,
'software_release'
:
software_release
,
'software_release'
:
software_release
,
'software_type'
:
software_type
,
'software_type'
:
software_type
,
...
@@ -375,31 +384,8 @@ class ComputerPartition(SlapDocument):
...
@@ -375,31 +384,8 @@ class ComputerPartition(SlapDocument):
partition_parameter_kw
),
partition_parameter_kw
),
'filter_xml'
:
xml_marshaller
.
dumps
(
filter_kw
),
'filter_xml'
:
xml_marshaller
.
dumps
(
filter_kw
),
'state'
:
xml_marshaller
.
dumps
(
state
),
'state'
:
xml_marshaller
.
dumps
(
state
),
}
}
try
:
return
self
.
_requestComputerPartition
(
request_dict
)
self
.
_connection_helper
.
POST
(
'/requestComputerPartition'
,
request_dict
)
except
ResourceNotReady
:
return
ComputerPartition
(
request_dict
=
request_dict
,
connection_helper
=
self
.
_connection_helper
,
)
else
:
xml
=
self
.
_connection_helper
.
response
.
read
()
software_instance
=
xml_marshaller
.
loads
(
xml
)
computer_partition
=
ComputerPartition
(
software_instance
.
slap_computer_id
.
encode
(
'UTF-8'
),
software_instance
.
slap_computer_partition_id
.
encode
(
'UTF-8'
),
connection_helper
=
self
.
_connection_helper
,
)
# Hack to give all object attributes to the ComputerPartition instance
computer_partition
.
__dict__
=
software_instance
.
__dict__
.
copy
()
if
shared
:
computer_partition
.
_synced
=
True
computer_partition
.
_connection_dict
=
getattr
(
software_instance
,
'_connection_dict'
,
None
)
computer_partition
.
_parameter_dict
=
getattr
(
software_instance
,
'_parameter_dict'
,
None
)
return
computer_partition
def
building
(
self
):
def
building
(
self
):
self
.
_connection_helper
.
POST
(
'/buildingComputerPartition'
,
{
self
.
_connection_helper
.
POST
(
'/buildingComputerPartition'
,
{
...
...
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