@@ -111,84 +111,6 @@ def delete_xpaths(self, xpaths, prefix=None):
111
111
paths .append (self .parse_xpath_to_gnmi_path (xpath ))
112
112
return self .set (deletes = paths )
113
113
114
- def check_configs (self , configs ):
115
- if isinstance (configs , string_types ):
116
- logger .debug ("Handling as JSON string." )
117
- try :
118
- configs = json .loads (configs )
119
- except :
120
- raise Exception ("{0}\n is invalid JSON!" .format (configs ))
121
- configs = [configs ]
122
- elif isinstance (configs , dict ):
123
- logger .debug ("Handling already serialized JSON object." )
124
- configs = [configs ]
125
- elif not isinstance (configs , (list , set )):
126
- raise Exception (
127
- "{0} must be an iterable of configs!" .format (str (configs ))
128
- )
129
- return configs
130
-
131
- def create_updates (self , configs , origin , json_ietf = True ):
132
- """Check configs, and construct "Update" messages.
133
-
134
- Parameters
135
- ----------
136
- configs: dict of <xpath>: <dict val for JSON>
137
- origin: None or 'openconfig'
138
- json_ietf: bool encoding type for Update val (default True)
139
-
140
- Returns
141
- -------
142
- List of Update messages with val populated.
143
-
144
- If a set of configs contain a common Xpath, the Update must contain
145
- a consolidation of xpath/values for 2 reasons:
146
-
147
- 1. Devices may have a restriction on how many Update messages it will
148
- accept at once.
149
- 2. Some xpath/values are required to be set in same Update because of
150
- dependencies like leafrefs, mandatory settings, and if/when/musts.
151
- """
152
- if not configs :
153
- return None
154
- configs = self .check_configs (configs )
155
-
156
- xpaths = []
157
- updates = []
158
- for config in configs :
159
- xpath = next (iter (config .keys ()))
160
- xpaths .append (xpath )
161
- common_xpath = os .path .commonprefix (xpaths )
162
-
163
- if common_xpath :
164
- update_configs = self .get_payload (configs )
165
- for update_cfg in update_configs :
166
- xpath , payload = update_cfg
167
- update = proto .gnmi_pb2 .Update ()
168
- update .path .CopyFrom (
169
- self .parse_xpath_to_gnmi_path (
170
- xpath , origin = origin
171
- )
172
- )
173
- if json_ietf :
174
- update .val .json_ietf_val = payload
175
- else :
176
- update .val .json_val = payload
177
- updates .append (update )
178
- return updates
179
- else :
180
- for config in configs :
181
- top_element = next (iter (config .keys ()))
182
- update = proto .gnmi_pb2 .Update ()
183
- update .path .CopyFrom (self .parse_xpath_to_gnmi_path (top_element ))
184
- config = config .pop (top_element )
185
- if json_ietf :
186
- update .val .json_ietf_val = json .dumps (config ).encode ("utf-8" )
187
- else :
188
- update .val .json_val = json .dumps (config ).encode ("utf-8" )
189
- updates .append (update )
190
- return updates
191
-
192
114
def set_json (self , update_json_configs = None , replace_json_configs = None ,
193
115
origin = 'device' , json_ietf = True ):
194
116
"""A convenience wrapper for set() which assumes JSON payloads and constructs desired messages.
0 commit comments