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
Thomas Gambier
slapos.core
Commits
4fcc16cb
Commit
4fcc16cb
authored
Apr 11, 2016
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_slap_tool: migrate business template to new format
parent
8df0d28d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
90 deletions
+86
-90
master/bt5/slapos_slap_tool/SkinTemplateItem/portal_skins/slapos_slap_tool/Computer_updateFromDict.py
.../portal_skins/slapos_slap_tool/Computer_updateFromDict.py
+86
-0
master/bt5/slapos_slap_tool/SkinTemplateItem/portal_skins/slapos_slap_tool/Computer_updateFromDict.xml
...portal_skins/slapos_slap_tool/Computer_updateFromDict.xml
+0
-90
No files found.
master/bt5/slapos_slap_tool/SkinTemplateItem/portal_skins/slapos_slap_tool/Computer_updateFromDict.py
0 → 100644
View file @
4fcc16cb
def
compareAndUpdateAddressList
(
document
,
address_list
,
additional_dict
=
None
):
if
additional_dict
is
None
:
additional_dict
=
{}
to_delete_ip_id_list
=
[]
to_add_ip_dict_list
=
address_list
[:]
existing_address_list
=
document
.
contentValues
(
portal_type
=
'Internet Protocol Address'
)
existing_address_list
.
sort
(
key
=
lambda
x
:
{
0
:
1
,
1
:
2
}[
int
(
x
.
id
==
'default_network_interface'
)])
for
address
in
existing_address_list
:
current_dict
=
{
'addr'
:
address
.
getIpAddress
(),
'netmask'
:
address
.
getNetmask
()
}
if
current_dict
in
to_add_ip_dict_list
:
to_add_ip_dict_list
.
remove
(
current_dict
)
else
:
# XXX - Only delete if Network interface are supposed to be the same
if
additional_dict
.
has_key
(
'network_interface'
):
if
address
.
getNetworkInterface
(
''
)
and
additional_dict
[
'network_interface'
]
!=
address
.
getNetworkInterface
():
continue
to_delete_ip_id_list
.
append
(
address
.
getId
())
for
address
in
to_add_ip_dict_list
:
if
to_delete_ip_id_list
:
id
=
to_delete_ip_id_list
.
pop
()
address_document
=
document
.
restrictedTraverse
(
id
)
else
:
kw
=
{
'portal_type'
:
'Internet Protocol Address'
}
if
not
len
(
document
.
objectIds
(
portal_type
=
'Internet Protocol Address'
)):
kw
.
update
(
id
=
'default_network_address'
)
address_document
=
document
.
newContent
(
**
kw
)
address_document
.
edit
(
ip_address
=
address
[
'addr'
],
netmask
=
address
[
'netmask'
],
**
additional_dict
)
if
to_delete_ip_id_list
:
document
.
deleteContent
(
to_delete_ip_id_list
)
# Getting existing partitions
existing_partition_dict
=
{}
for
c
in
context
.
contentValues
(
portal_type
=
"Computer Partition"
):
existing_partition_dict
[
c
.
getReference
()]
=
c
# update computer data
quantity
=
len
(
computer_dict
[
'partition_list'
])
if
context
.
getQuantity
()
!=
quantity
:
context
.
edit
(
quantity
=
quantity
)
compareAndUpdateAddressList
(
context
,
[{
'addr'
:
computer_dict
[
'address'
],
'netmask'
:
computer_dict
[
'netmask'
]}])
expected_partition_dict
=
{}
for
send_partition
in
computer_dict
[
'partition_list'
]:
partition
=
existing_partition_dict
.
get
(
send_partition
[
'reference'
],
None
)
expected_partition_dict
[
send_partition
[
'reference'
]]
=
True
if
partition
is
None
:
partition
=
context
.
newContent
(
portal_type
=
'Computer Partition'
)
partition
.
validate
()
partition
.
markFree
()
elif
partition
.
getSlapState
()
==
'inactive'
:
# Reactivate partition
partition
.
markFree
(
comment
=
"Reactivated by slapformat"
)
if
partition
.
getValidationState
()
==
"invalidated"
:
partition
.
validate
(
comment
=
"Reactivated by slapformat"
)
if
partition
.
getReference
()
!=
send_partition
[
'reference'
]:
partition
.
edit
(
reference
=
send_partition
[
'reference'
])
network_interface
=
send_partition
[
'tap'
][
'name'
]
compareAndUpdateAddressList
(
partition
,
send_partition
[
'address_list'
],
{
'network_interface'
:
network_interface
})
tap_addr_list
=
[]
additional_dict
=
{
'network_interface'
:
'route_'
+
network_interface
}
if
send_partition
[
'tap'
].
has_key
(
'ipv4_addr'
)
and
send_partition
[
'tap'
][
'ipv4_addr'
]:
tap_addr_list
.
append
({
'addr'
:
send_partition
[
'tap'
][
'ipv4_addr'
],
'netmask'
:
send_partition
[
'tap'
][
'ipv4_netmask'
]
})
additional_dict
[
'gateway_ip_address'
]
=
send_partition
[
'tap'
][
'ipv4_gateway'
]
additional_dict
[
'network_address'
]
=
send_partition
[
'tap'
][
'ipv4_network'
]
compareAndUpdateAddressList
(
partition
,
tap_addr_list
,
additional_dict
)
# Desactivate all other partitions
for
key
,
value
in
existing_partition_dict
.
items
():
if
key
not
in
expected_partition_dict
:
if
value
.
getSlapState
()
==
"free"
:
value
.
markInactive
(
comment
=
"Desactivated by slapformat"
)
if
value
.
getValidationState
()
==
"validated"
:
value
.
invalidate
(
comment
=
"Desactivated by slapformat"
)
master/bt5/slapos_slap_tool/SkinTemplateItem/portal_skins/slapos_slap_tool/Computer_updateFromDict.xml
View file @
4fcc16cb
...
...
@@ -48,96 +48,6 @@
</object>
</value>
</item>
<item>
<key>
<string>
_body
</string>
</key>
<value>
<string>
def compareAndUpdateAddressList(document, address_list, additional_dict=None):\n
if additional_dict is None:\n
additional_dict = {}\n
to_delete_ip_id_list = []\n
to_add_ip_dict_list = address_list[:]\n
existing_address_list = document.contentValues(portal_type=\'Internet Protocol Address\')\n
existing_address_list.sort(key=lambda x: {0: 1, 1: 2}[int(x.id == \'default_network_interface\')])\n
for address in existing_address_list:\n
current_dict = {\n
\'addr\': address.getIpAddress(),\n
\'netmask\': address.getNetmask()\n
}\n
if current_dict in to_add_ip_dict_list:\n
to_add_ip_dict_list.remove(current_dict)\n
else:\n
# XXX - Only delete if Network interface are supposed to be the same\n
if additional_dict.has_key(\'network_interface\'):\n
if address.getNetworkInterface(\'\') and additional_dict[\'network_interface\'] != address.getNetworkInterface():\n
continue\n
to_delete_ip_id_list.append(address.getId())\n
\n
for address in to_add_ip_dict_list:\n
if to_delete_ip_id_list:\n
id = to_delete_ip_id_list.pop()\n
address_document = document.restrictedTraverse(id)\n
else:\n
kw = {\'portal_type\': \'Internet Protocol Address\'}\n
if not len(document.objectIds(portal_type=\'Internet Protocol Address\')):\n
kw.update(id=\'default_network_address\')\n
address_document = document.newContent(**kw)\n
address_document.edit(\n
ip_address=address[\'addr\'],\n
netmask=address[\'netmask\'],\n
**additional_dict\n
)\n
if to_delete_ip_id_list:\n
document.deleteContent(to_delete_ip_id_list)\n
\n
\n
# Getting existing partitions\n
existing_partition_dict = {}\n
for c in context.contentValues(portal_type="Computer Partition"):\n
existing_partition_dict[c.getReference()] = c\n
\n
# update computer data\n
quantity = len(computer_dict[\'partition_list\'])\n
if context.getQuantity() != quantity:\n
context.edit(quantity=quantity)\n
\n
compareAndUpdateAddressList(context, [{\'addr\': computer_dict[\'address\'], \'netmask\': computer_dict[\'netmask\']}])\n
expected_partition_dict = {}\n
for send_partition in computer_dict[\'partition_list\']:\n
partition = existing_partition_dict.get(send_partition[\'reference\'], None)\n
expected_partition_dict[send_partition[\'reference\']] = True\n
if partition is None:\n
partition = context.newContent(portal_type=\'Computer Partition\')\n
partition.validate()\n
partition.markFree()\n
elif partition.getSlapState() == \'inactive\':\n
# Reactivate partition\n
partition.markFree(comment="Reactivated by slapformat")\n
\n
if partition.getValidationState() == "invalidated":\n
partition.validate(comment="Reactivated by slapformat")\n
if partition.getReference() != send_partition[\'reference\']:\n
partition.edit(reference=send_partition[\'reference\'])\n
network_interface = send_partition[\'tap\'][\'name\']\n
compareAndUpdateAddressList(partition, send_partition[\'address_list\'], {\'network_interface\': network_interface})\n
tap_addr_list = []\n
additional_dict = {\'network_interface\': \'route_\' + network_interface}\n
if send_partition[\'tap\'].has_key(\'ipv4_addr\') and send_partition[\'tap\'][\'ipv4_addr\']:\n
tap_addr_list.append({\n
\'addr\': send_partition[\'tap\'][\'ipv4_addr\'],\n
\'netmask\': send_partition[\'tap\'][\'ipv4_netmask\']\n
})\n
additional_dict[\'gateway_ip_address\'] = send_partition[\'tap\'][\'ipv4_gateway\']\n
additional_dict[\'network_address\'] = send_partition[\'tap\'][\'ipv4_network\']\n
compareAndUpdateAddressList(partition, tap_addr_list, additional_dict)\n
\n
# Desactivate all other partitions\n
for key, value in existing_partition_dict.items():\n
if key not in expected_partition_dict:\n
if value.getSlapState() == "free":\n
value.markInactive(comment="Desactivated by slapformat")\n
if value.getValidationState() == "validated":\n
value.invalidate(comment="Desactivated by slapformat")\n
</string>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
computer_dict
</string>
</value>
...
...
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