2020-01-21 20:04:22 +00:00
|
|
|
from core.config import Configuration
|
2020-01-18 00:57:49 +00:00
|
|
|
from core.configservice.base import ConfigService, ConfigServiceMode
|
2020-01-21 20:04:22 +00:00
|
|
|
from core.emulator.enumerations import ConfigDataTypes
|
2020-01-18 00:57:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SimpleService(ConfigService):
|
|
|
|
name = "Simple"
|
|
|
|
group = "SimpleGroup"
|
2020-01-21 18:35:46 +00:00
|
|
|
directories = ["/etc/quagga", "/usr/local/lib"]
|
|
|
|
files = ["test1.sh", "test2.sh"]
|
2020-01-18 00:57:49 +00:00
|
|
|
executables = []
|
|
|
|
dependencies = []
|
|
|
|
startup = []
|
|
|
|
validate = []
|
|
|
|
shutdown = []
|
|
|
|
validation_mode = ConfigServiceMode.BLOCKING
|
2020-01-21 20:04:22 +00:00
|
|
|
default_configs = [
|
2020-01-24 18:59:47 +00:00
|
|
|
Configuration(_id="value1", _type=ConfigDataTypes.STRING, label="Text"),
|
|
|
|
Configuration(_id="value2", _type=ConfigDataTypes.BOOL, label="Boolean"),
|
|
|
|
Configuration(
|
|
|
|
_id="value3",
|
|
|
|
_type=ConfigDataTypes.STRING,
|
|
|
|
label="Multiple Choice",
|
|
|
|
options=["value1", "value2", "value3"],
|
|
|
|
),
|
2020-01-21 20:04:22 +00:00
|
|
|
]
|
2020-01-21 22:00:55 +00:00
|
|
|
modes = {
|
2020-01-24 18:59:47 +00:00
|
|
|
"mode1": {"value1": "value1", "value2": "0", "value3": "value2"},
|
|
|
|
"mode2": {"value1": "value2", "value2": "1", "value3": "value3"},
|
|
|
|
"mode3": {"value1": "value3", "value2": "0", "value3": "value1"},
|
2020-01-21 22:00:55 +00:00
|
|
|
}
|
2020-01-18 00:57:49 +00:00
|
|
|
|
2020-01-23 19:06:09 +00:00
|
|
|
def get_text_template(self, name: str) -> str:
|
2020-01-20 23:02:04 +00:00
|
|
|
if name == "test1.sh":
|
|
|
|
return """
|
2020-01-21 18:35:46 +00:00
|
|
|
# sample script 1
|
2020-01-20 23:02:04 +00:00
|
|
|
# node id(${node.id}) name(${node.name})
|
2020-01-21 20:04:22 +00:00
|
|
|
# config: ${config}
|
2020-01-20 23:02:04 +00:00
|
|
|
echo hello
|
|
|
|
"""
|
2020-01-21 18:35:46 +00:00
|
|
|
elif name == "test2.sh":
|
|
|
|
return """
|
|
|
|
# sample script 2
|
|
|
|
# node id(${node.id}) name(${node.name})
|
2020-01-21 20:04:22 +00:00
|
|
|
# config: ${config}
|
2020-01-21 18:35:46 +00:00
|
|
|
echo hello2
|
|
|
|
"""
|