Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
smartpublicbuilding
openhab-pb-stack
Commits
a2dd6d05
Commit
a2dd6d05
authored
Jan 09, 2019
by
dobli
Browse files
added example menu and structure comments
parent
0cdc13a3
Changes
1
Show whitespace changes
Inline
Side-by-side
building_manager.py
View file @
a2dd6d05
...
@@ -2,13 +2,17 @@
...
@@ -2,13 +2,17 @@
import
docker
import
docker
import
os
import
os
from
PyInquirer
import
prompt
# Directories for config generation
# Directories for config generation
CONFIG_DIRS
=
[
CONFIG_DIRS
=
[
'influxdb'
,
'mosquitto'
,
'nodered'
,
'ssh'
,
'treafik'
,
'volumerize'
'influxdb'
,
'mosquitto'
,
'nodered'
,
'ssh'
,
'treafik'
,
'volumerize'
]
]
# ******************************
# Config file functions
# Config file functions
# ******************************
def
generate_config_folders
(
base_path
):
def
generate_config_folders
(
base_path
):
"""Generate folders for configuration files
"""Generate folders for configuration files
...
@@ -20,7 +24,9 @@ def generate_config_folders(base_path):
...
@@ -20,7 +24,9 @@ def generate_config_folders(base_path):
os
.
makedirs
(
new_dir
)
os
.
makedirs
(
new_dir
)
# ******************************
# Docker machine functions
# Docker machine functions
# ******************************
def
get_machine_list
():
def
get_machine_list
():
"""Get a list of docker machine names using the docker-machine system command
"""Get a list of docker machine names using the docker-machine system command
...
@@ -66,7 +72,9 @@ def get_machine_env(machine_name):
...
@@ -66,7 +72,9 @@ def get_machine_env(machine_name):
return
machine_envs
return
machine_envs
# ******************************
# Docker client commands
# Docker client commands
# ******************************
def
assign_label_to_node
(
nodeid
,
label
,
value
):
def
assign_label_to_node
(
nodeid
,
label
,
value
):
"""Assigns a label to a node (e.g. building)
"""Assigns a label to a node (e.g. building)
...
@@ -120,7 +128,9 @@ def run_command_in_service(service, command, building=None):
...
@@ -120,7 +128,9 @@ def run_command_in_service(service, command, building=None):
client
.
close
()
client
.
close
()
# ******************************
# CLI base commands and main
# CLI base commands and main
# ******************************
def
init_config_dirs_command
(
args
):
def
init_config_dirs_command
(
args
):
"""Initialize config directories
"""Initialize config directories
...
@@ -180,6 +190,63 @@ def restore_command(args):
...
@@ -180,6 +190,63 @@ def restore_command(args):
get_machine_env
(
target
)
get_machine_env
(
target
)
def
interactive_command
(
args
):
"""Top level function to start the interactive mode
:args: command line arguments
"""
print
(
main_menu
())
# ******************************
# Interactive menu entries
# ******************************
def
main_menu
():
""" Display main menu
"""
questions
=
[{
'type'
:
'list'
,
'name'
:
'main'
,
'message'
:
'Public Building Manager - Main Menu'
,
'choices'
:
[
'Create initial structure'
,
'Execute command'
,
'Exit'
]
}]
answers
=
prompt
(
questions
)
if
'Create'
in
answers
[
'main'
]:
init_menu
()
return
answers
def
init_menu
():
"""Menu entry for initial setup and file generation
"""
questions
=
[
{
'type'
:
'input'
,
'name'
:
'stack_name'
,
'message'
:
'Choose a name for your setup'
},
{
'type'
:
'checkbox'
,
'name'
:
'machines'
,
'message'
:
'What docker machines will be used?'
,
'choices'
:
[{
'name'
:
m
}
for
m
in
get_machine_list
()]
},
]
answers
=
prompt
(
questions
)
print
(
answers
)
# ******************************
# Script main (entry)
# ******************************
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
import
argparse
import
argparse
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
...
@@ -188,6 +255,12 @@ if __name__ == '__main__':
...
@@ -188,6 +255,12 @@ if __name__ == '__main__':
'building configurations of openHAB with docker swarm'
)
'building configurations of openHAB with docker swarm'
)
subparsers
=
parser
.
add_subparsers
()
subparsers
=
parser
.
add_subparsers
()
# Interactive mode
parser_interactive
=
subparsers
.
add_parser
(
'interactive'
,
help
=
'Starts the interactive mode of the building manager'
)
parser_interactive
.
set_defaults
(
func
=
interactive_command
)
# Restore command
# Restore command
parser_restore
=
subparsers
.
add_parser
(
'restore'
,
help
=
'Restore backups'
)
parser_restore
=
subparsers
.
add_parser
(
'restore'
,
help
=
'Restore backups'
)
parser_restore
.
add_argument
(
parser_restore
.
add_argument
(
...
...
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