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
Labels
Merge Requests
16
Merge Requests
16
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
428e9dad
Commit
428e9dad
authored
Apr 30, 2013
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove ComputerPartition decorator that calls getFullComputerInformation for each method.
Solve #20130313-2E05AD.
parent
46de200d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
59 deletions
+5
-59
slapos/slap/slap.py
slapos/slap/slap.py
+5
-59
No files found.
slapos/slap/slap.py
View file @
428e9dad
...
@@ -223,6 +223,8 @@ class OpenOrder(SlapDocument):
...
@@ -223,6 +223,8 @@ class OpenOrder(SlapDocument):
software_instance
.
slap_computer_partition_id
.
encode
(
'UTF-8'
),
software_instance
.
slap_computer_partition_id
.
encode
(
'UTF-8'
),
connection_helper
=
self
.
_connection_helper
,
connection_helper
=
self
.
_connection_helper
,
)
)
# Hack to give all object attributes to the ComputerPartition instance
computer_partition
.
__dict__
=
software_instance
.
__dict__
.
copy
()
if
shared
:
if
shared
:
computer_partition
.
_synced
=
True
computer_partition
.
_synced
=
True
computer_partition
.
_connection_dict
=
software_instance
.
_connection_dict
computer_partition
.
_connection_dict
=
software_instance
.
_connection_dict
...
@@ -321,57 +323,6 @@ class Computer(SlapDocument):
...
@@ -321,57 +323,6 @@ class Computer(SlapDocument):
xml
=
self
.
_connection_helper
.
response
.
read
()
xml
=
self
.
_connection_helper
.
response
.
read
()
return
xml_marshaller
.
loads
(
xml
)
return
xml_marshaller
.
loads
(
xml
)
def
_syncComputerPartitionInformation
(
func
):
"""
Synchronize computer partition object with server information
"""
def
decorated
(
self
,
*
args
,
**
kw
):
if
getattr
(
self
,
'_synced'
,
0
):
return
func
(
self
,
*
args
,
**
kw
)
if
not
self
.
_computer_id
:
# XXX Is it only in case of requesting instance?
raise
ResourceNotReady
(
"Instance is not ready yet."
)
# XXX: This is a ugly way to keep backward compatibility,
# We should stablise slap library soon.
computer
=
self
.
_connection_helper
.
getFullComputerInformation
(
self
.
_computer_id
)
found_computer_partition
=
None
for
computer_partition
in
computer
.
_computer_partition_list
:
if
computer_partition
.
getId
()
==
self
.
getId
():
found_computer_partition
=
computer_partition
break
if
found_computer_partition
is
None
:
raise
NotFoundError
(
"No information for partition %s"
%
self
.
getId
())
else
:
for
key
,
value
in
found_computer_partition
.
__dict__
.
items
():
if
isinstance
(
value
,
unicode
):
# convert unicode to utf-8
setattr
(
self
,
key
,
value
.
encode
(
'utf-8'
))
if
isinstance
(
value
,
dict
):
new_dict
=
{}
for
ink
,
inv
in
value
.
iteritems
():
if
isinstance
(
inv
,
(
list
,
tuple
)):
new_inv
=
[]
for
elt
in
inv
:
if
isinstance
(
elt
,
(
list
,
tuple
)):
new_inv
.
append
([
x
.
encode
(
'utf-8'
)
for
x
in
elt
])
elif
isinstance
(
elt
,
dict
):
new_inv
.
append
(
dict
([(
x
.
encode
(
'utf-8'
),
y
and
y
.
encode
(
"utf-8"
))
for
x
,
y
in
elt
.
iteritems
()]))
else
:
new_inv
.
append
(
elt
.
encode
(
'utf-8'
))
new_dict
[
ink
.
encode
(
'utf-8'
)]
=
new_inv
elif
inv
is
None
:
new_dict
[
ink
.
encode
(
'utf-8'
)]
=
None
else
:
new_dict
[
ink
.
encode
(
'utf-8'
)]
=
inv
.
encode
(
'utf-8'
)
setattr
(
self
,
key
,
new_dict
)
else
:
setattr
(
self
,
key
,
value
)
setattr
(
self
,
'_synced'
,
True
)
return
func
(
self
,
*
args
,
**
kw
)
return
decorated
class
ComputerPartition
(
SlapDocument
):
class
ComputerPartition
(
SlapDocument
):
...
@@ -394,7 +345,7 @@ class ComputerPartition(SlapDocument):
...
@@ -394,7 +345,7 @@ class ComputerPartition(SlapDocument):
def
__getinitargs__
(
self
):
def
__getinitargs__
(
self
):
return
(
self
.
_computer_id
,
self
.
_partition_id
,
)
return
(
self
.
_computer_id
,
self
.
_partition_id
,
)
@
_syncComputerPartitionInformation
# 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
):
...
@@ -440,6 +391,8 @@ class ComputerPartition(SlapDocument):
...
@@ -440,6 +391,8 @@ class ComputerPartition(SlapDocument):
software_instance
.
slap_computer_partition_id
.
encode
(
'UTF-8'
),
software_instance
.
slap_computer_partition_id
.
encode
(
'UTF-8'
),
connection_helper
=
self
.
_connection_helper
,
connection_helper
=
self
.
_connection_helper
,
)
)
# Hack to give all object attributes to the ComputerPartition instance
computer_partition
.
__dict__
=
software_instance
.
__dict__
.
copy
()
if
shared
:
if
shared
:
computer_partition
.
_synced
=
True
computer_partition
.
_synced
=
True
computer_partition
.
_connection_dict
=
getattr
(
software_instance
,
computer_partition
.
_connection_dict
=
getattr
(
software_instance
,
...
@@ -507,29 +460,24 @@ class ComputerPartition(SlapDocument):
...
@@ -507,29 +460,24 @@ class ComputerPartition(SlapDocument):
raise
ResourceNotReady
()
raise
ResourceNotReady
()
return
self
.
_partition_id
return
self
.
_partition_id
@
_syncComputerPartitionInformation
def
getInstanceGuid
(
self
):
def
getInstanceGuid
(
self
):
"""Sync if not synced, then returns instance_guid"""
"""Sync if not synced, then returns instance_guid"""
if
not
getattr
(
self
,
'_instance_guid'
,
None
):
if
not
getattr
(
self
,
'_instance_guid'
,
None
):
raise
ResourceNotReady
()
raise
ResourceNotReady
()
return
self
.
_instance_guid
return
self
.
_instance_guid
@
_syncComputerPartitionInformation
def
getState
(
self
):
def
getState
(
self
):
"""Sync if not synced, then returns _requested_state."""
"""Sync if not synced, then returns _requested_state."""
if
not
getattr
(
self
,
'_requested_state'
,
None
):
if
not
getattr
(
self
,
'_requested_state'
,
None
):
raise
ResourceNotReady
()
raise
ResourceNotReady
()
return
self
.
_requested_state
return
self
.
_requested_state
@
_syncComputerPartitionInformation
def
getInstanceParameterDict
(
self
):
def
getInstanceParameterDict
(
self
):
return
getattr
(
self
,
'_parameter_dict'
,
None
)
or
{}
return
getattr
(
self
,
'_parameter_dict'
,
None
)
or
{}
@
_syncComputerPartitionInformation
def
getConnectionParameterDict
(
self
):
def
getConnectionParameterDict
(
self
):
return
getattr
(
self
,
'_connection_dict'
,
None
)
or
{}
return
getattr
(
self
,
'_connection_dict'
,
None
)
or
{}
@
_syncComputerPartitionInformation
def
getSoftwareRelease
(
self
):
def
getSoftwareRelease
(
self
):
"""
"""
Returns the software release associate to the computer partition.
Returns the software release associate to the computer partition.
...
@@ -548,7 +496,6 @@ class ComputerPartition(SlapDocument):
...
@@ -548,7 +496,6 @@ class ComputerPartition(SlapDocument):
'connection_xml'
:
xml_marshaller
.
dumps
(
connection_dict
),
'connection_xml'
:
xml_marshaller
.
dumps
(
connection_dict
),
'slave_reference'
:
slave_reference
})
'slave_reference'
:
slave_reference
})
@
_syncComputerPartitionInformation
def
getInstanceParameter
(
self
,
key
):
def
getInstanceParameter
(
self
,
key
):
parameter_dict
=
getattr
(
self
,
'_parameter_dict'
,
None
)
or
{}
parameter_dict
=
getattr
(
self
,
'_parameter_dict'
,
None
)
or
{}
if
key
in
parameter_dict
:
if
key
in
parameter_dict
:
...
@@ -556,7 +503,6 @@ class ComputerPartition(SlapDocument):
...
@@ -556,7 +503,6 @@ class ComputerPartition(SlapDocument):
else
:
else
:
raise
NotFoundError
(
"%s not found"
%
key
)
raise
NotFoundError
(
"%s not found"
%
key
)
@
_syncComputerPartitionInformation
def
getConnectionParameter
(
self
,
key
):
def
getConnectionParameter
(
self
,
key
):
connection_dict
=
getattr
(
self
,
'_connection_dict'
,
None
)
or
{}
connection_dict
=
getattr
(
self
,
'_connection_dict'
,
None
)
or
{}
if
key
in
connection_dict
:
if
key
in
connection_dict
:
...
...
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