@@ -13,6 +13,11 @@ created
13
13
from ansible.module_utils.network.common.cfg.base import ConfigBase
14
14
from ansible.module_utils.network.common.utils import to_list
15
15
from {{ import_path }}.{{ network_os }}.facts.facts import Facts
16
+ {% if transport .netconf %}
17
+ from ansible.module_utils.network.netconf.netconf import locked_config
18
+ from ansible.module_utils.network.common.netconf import (build_root_xml_node,
19
+ build_child_xml_node)
20
+ {% endif %}
16
21
17
22
18
23
class {{ resource|capitalize }}(ConfigBase):
@@ -51,8 +56,29 @@ class {{ resource|capitalize }}(ConfigBase):
51
56
:returns: The result from module execution
52
57
"""
53
58
result = {'changed': False}
54
- commands = list()
59
+ {% if transport .netconf %}
60
+ existing_{{ resource }}_facts = self.get_{{ resource }}_facts()
61
+ config_xmls = self.set_config(existing_{{ resource }}_facts)
62
+
63
+ with locked_config(self._module):
64
+ for config_xml in to_list(config_xmls):
65
+ diff = self._module._connectionload_config(self._module, config_xml, [])
66
+
67
+ commit = not self._module.check_mode
68
+ if diff:
69
+ if commit:
70
+ self._module._connection.commit_configuration(self._module)
71
+ else:
72
+ self._module._connection.discard_changes(self._module)
73
+ result['changed'] = True
74
+
75
+ if self._module._diff:
76
+ result['diff'] = {'prepared': diff}
77
+
78
+ result['xml'] = config_xmls
79
+ {% else %}
55
80
warnings = list()
81
+ commands = list()
56
82
57
83
existing_{{ resource }}_facts = self.get_{{ resource }}_facts()
58
84
commands.extend(self.set_config(existing_{{ resource }}_facts))
@@ -62,6 +88,7 @@ class {{ resource|capitalize }}(ConfigBase):
62
88
result['changed'] = True
63
89
result['commands'] = commands
64
90
91
+ {% endif %}
65
92
changed_{{ resource }}_facts = self.get_{{ resource }}_facts()
66
93
67
94
result['before'] = existing_{{ resource }}_facts
@@ -93,6 +120,23 @@ class {{ resource|capitalize }}(ConfigBase):
93
120
:returns: the commands necessary to migrate the current configuration
94
121
to the desired configuration
95
122
"""
123
+ {% if transport .netconf %}
124
+ root = build_root_xml_node('{{ resource }}')
125
+ state = self._module.params['state']
126
+ if state == 'overridden':
127
+ config_xmls = self._state_overridden(want, have)
128
+ elif state == 'deleted':
129
+ config_xmls = self._state_deleted(want, have)
130
+ elif state == 'merged':
131
+ config_xmls = self._state_merged(want, have)
132
+ elif state == 'replaced':
133
+ config_xmls = self._state_replaced(want, have)
134
+
135
+ for xml in config_xmls:
136
+ root.append(xml)
137
+
138
+ return self._module._connection.tostring(root)
139
+ {% else %}
96
140
state = self._module.params['state']
97
141
if state == 'overridden':
98
142
kwargs = {}
@@ -107,7 +151,47 @@ class {{ resource|capitalize }}(ConfigBase):
107
151
kwargs = {}
108
152
commands = self._state_replaced(**kwargs)
109
153
return commands
154
+ {% endif %}
155
+ {% if transport .netconf %}
156
+ def _state_replaced(self, want, have):
157
+ """ The command generator when state is replaced
110
158
159
+ :rtype: A list
160
+ :returns: the xml necessary to migrate the current configuration
161
+ to the desired configuration
162
+ """
163
+ intf_xml = []
164
+ return intf_xml
165
+
166
+ def _state_overridden(self, want, have):
167
+ """ The command generator when state is overridden
168
+
169
+ :rtype: A list
170
+ :returns: the xml necessary to migrate the current configuration
171
+ to the desired configuration
172
+ """
173
+ intf_xml = []
174
+ return intf_xml
175
+ def _state_deleted(self, want, have):
176
+ """ The command generator when state is deleted
177
+
178
+ :rtype: A list
179
+ :returns: the xml necessary to migrate the current configuration
180
+ to the desired configuration
181
+ """
182
+ intf_xml = []
183
+ return intf_xml
184
+
185
+ def _state_merged(self, want, have):
186
+ """ The command generator when state is merged
187
+
188
+ :rtype: A list
189
+ :returns: the xml necessary to migrate the current configuration
190
+ to the desired configuration
191
+ """
192
+ intf_xml = []
193
+ return intf_xml
194
+ {% else %}
111
195
@staticmethod
112
196
def _state_replaced(**kwargs):
113
197
""" The command generator when state is replaced
@@ -151,3 +235,4 @@ class {{ resource|capitalize }}(ConfigBase):
151
235
"""
152
236
commands = []
153
237
return commands
238
+ {% endif %}
0 commit comments