Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
smartpublicbuilding
openhab-pb-stack
Commits
2b8ccb5e
Commit
2b8ccb5e
authored
6 years ago
by
Dobli
Browse files
Options
Download
Email Patches
Plain Diff
assign building labels during swarm init
parent
c2d6d9b8
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
building_manager.py
+12
-2
building_manager.py
with
12 additions
and
2 deletions
+12
-2
building_manager.py
+
12
-
2
View file @
2b8ccb5e
...
...
@@ -554,10 +554,14 @@ def generate_swarm(machines):
print
(
f
'Create initial swarm with leader
{
leader
}
'
)
if
init_swarm_machine
(
leader
):
print
(
'Swarm init successful
\n
'
)
assign_label_to_node
(
leader
,
'building'
,
leader
,
manager
=
leader
)
else
:
print
(
f
'Machine
{
machine
}
joins swarm of leader
{
leader
}
'
)
if
(
join_swarm_machine
(
machine
,
leader
)):
print
(
'Joining swarm successful
\n
'
)
assign_label_to_node
(
machine
,
'building'
,
machine
,
manager
=
leader
)
# }}}
...
...
@@ -566,19 +570,25 @@ def generate_swarm(machines):
# ******************************
# Docker client commands {{{
# ******************************
def
assign_label_to_node
(
nodeid
,
label
,
value
):
def
assign_label_to_node
(
nodeid
,
label
,
value
,
manager
=
None
):
"""Assigns a label to a node (e.g. building)
:nodeid: Id or name of the node
:label: Label you want to add
:value: The value to assign to the label
:manager: Dpcker machine to use for command, otherwise local
"""
client
=
docker
.
from_env
()
if
manager
:
building_env
=
get_machine_env
(
manager
)
client
=
docker
.
from_env
(
environment
=
building_env
)
else
:
client
=
docker
.
from_env
()
node
=
client
.
nodes
.
get
(
nodeid
)
spec
=
node
.
attrs
[
'Spec'
]
spec
[
'Labels'
][
label
]
=
value
node
.
update
(
spec
)
logging
.
info
(
f
'Assign label
{
label
}
with value
{
value
}
to
{
nodeid
}
'
)
client
.
close
()
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets