-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobs2.py
executable file
·67 lines (50 loc) · 1.92 KB
/
jobs2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import logging
from nornir.core.task import Task, Result, MultiResult
from nornir_jinja2.plugins.tasks import template_file, template_string
def config_cisco_ios(task: Task, **kwargs) -> Result:
template = task.run(task=string_from_template, **kwargs)
print(type(template))
return template
def config_junos(task: Task, **kwargs) -> Result:
template = task.run(task=string_from_template, **kwargs)[1].result
#print(type(template[0].result))
step_1_result = task.run(task=step_1, **kwargs)
step_2_result = task.run(task=step_2, **kwargs)
return Result(
host=task.host,
result=f"Configured host {task.host.name} with template {template}"
)
def string_from_template(task: Task, **kwargs):
template_from_file = kwargs.pop('template', None)
template_from_string = kwargs.pop('template_str', None)
template_path = kwargs.pop('path', '')
if template_from_string:
result = task.run(task=template_string,
template=template_from_string,
task_name=task.name,
task_host=task.host,
**kwargs
)
elif template_from_file:
result = task.run(task=template_file,
template=template_from_file,
path=template_path,
task_name=task.name,
task_host=task.host,
**kwargs
)
return Result(
severity_level=logging.DEBUG,
host=task.host,
result=result
)
def step_1(task: Task, **kwargs) -> Result:
return Result(
host=task.host,
result=f"{task.host.name} performed step 1"
)
def step_2(task: Task, **kwargs) -> Result:
return Result(
host=task.host,
result=f"{task.host.name} performed step too!"
)