summaryrefslogtreecommitdiff
path: root/python-cisco-sdwan.spec
blob: 19e2d5a3453ea3da21876df475f45c233834ec0d (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
%global _empty_manifest_terminate_build 0
Name:		python-cisco-sdwan
Version:	1.21.2
Release:	1
Summary:	Cisco-SDWAN Automation Toolset
License:	MIT License  Copyright (c) 2019 Cisco Systems, Inc. and/or its affiliates  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
URL:		https://github.com/CiscoDevNet/sastre
Source0:	https://mirrors.aliyun.com/pypi/web/packages/c5/12/7950d3b53eb4c8106a7531729500f8c0da8b76abe173ac548340bccd7c0e/cisco_sdwan-1.21.2.tar.gz
BuildArch:	noarch

Requires:	python3-pydantic
Requires:	python3-pyyaml
Requires:	python3-requests

%description
tag: template_feature
name_template:
  regex: "^All-"
  name_regex: "{name ^All-(.+)}"
name_map:
  DC1-VPN10-Interface-Template: DC-VPN10-Interface_v01
  DC1-VPN20-Interface-Template: DC-VPN20-Interface_v01
% sdwan --verbose transform recipe --from-file recipe.yaml test-transform
INFO: Transform task: vManage URL: "https://198.18.1.10" -> Local output dir: "test-transform"
<< snip >>
INFO: Matched feature template All-VPN0-TEMPLATE_cEdge
INFO: Replacing feature template: All-VPN0-TEMPLATE_cEdge -> VPN0-TEMPLATE_cEdge
INFO: Inspecting template_device items
INFO: Task completed successfully
```
Push changes to vManage using the restore task:
```
% sdwan --verbose restore all --workdir test-transform --update             
INFO: Restore task: Local workdir: "test-transform" -> vManage URL: "https://198.18.1.10"
<< snip >>
INFO: Task completed successfully
```
## Notes
### Regular Expressions
It is recommended to always use single quotes when specifying a regular expression to --regex option:
```
sdwan --verbose restore all --regex 'VPN1'
```
This is to prevent the shell from interpreting special characters that could be part of the pattern provided.
Matching done by --regex is un-anchored. That is, unless anchor marks are provided (e.g. ^ or $), the specified pattern matches if present anywhere in the string. In other words, this is a search function.
The regular expression syntax supported is described in https://docs.python.org/3/library/re.html
#### Behavior of --regex and --not-regex:
- --regex is used to select items to include (i.e. perform task operation)
- --not-regex is used to define items not to include. That is, select all items, except the ones matching --not-regex.
- When --regex match on multiple fields (e.g. item name, item ID), an item is selected if the item name OR item ID match the regular expression provided.
- With --not-regex, when it matches on multiple fields (e.g. item name, item ID), all items are selected, except the ones where item name OR item ID match the regular expression.
### Template name manipulation via name-regex
Multiple Sastre tasks utilize name-regex for name manipulation:
- Migrate task --name option accepts a name-regex.
- Transform copy/rename tasks have a `<name-regex>` mandatory parameter. 
- Transform recipe task allow `name_regex` under `name_template` section of the recipe YAML file. 
- The 'list transform' task also take a `<name-regex>` parameter. This task was designed to facilitate testing of those expressions.
A name-regex is a template for creating a new name based on segments of an original name.
The following rules apply:
- Occurrences of {name} are replaced with the original item name.
- Sections of the original item name can be captured by providing a regular expression in the format: {name &lt;regex&gt;}. This regular expression must contain one or more capturing groups, which define segments of the original name to "copy". Segments matching each capturing group are concatenated and "pasted" to the {name} position.
- If the regular expression does not match, {name &lt;regex&gt;} is replaced with an empty string.
Example:
```
Consider the template name "G_Branch_184_Single_cE4451-X_2xWAN_DHCP_L2_v01". 
In order to get the migrated name as "G_Branch_201_Single_cE4451-X_2xWAN_DHCP_L2_v01", one can use --name '{name (G_.+)_184_.+}_201_{name G.+_184_(.+)}'.
% sdwan list transform template_device --regex 'G_Branch_184_Single_cE4451' --workdir sastre_cx_golden_repo '{name (G_.+)_184_.+}_201_{name G.+_184_(.+)}'
+===================================================================================================================================================================+
| Name                                                          | Transformed                                                   | Tag             | Type            |
+===================================================================================================================================================================+
| G_Branch_184_Single_cE4451-X_2xWAN_Static_2xSLAN_Trunk_L2_v01 | G_Branch_201_Single_cE4451-X_2xWAN_Static_2xSLAN_Trunk_L2_v01 | template_device | device template |
| G_Branch_184_Single_cE4451-X_2xWAN_DHCP_L2_v01                | G_Branch_201_Single_cE4451-X_2xWAN_DHCP_L2_v01                | template_device | device template |
+---------------------------------------------------------------+---------------------------------------------------------------+-----------------+-----------------+
```
### Logs
Sastre logs messages to the terminal and to log files (under the logs/ directory).
Debug-level and higher severity messages are always saved to the log files.
The --verbose flag controls the severity of messages printed to the terminal. If --verbose is not specified, only warning-level and higher messages are logged. When --verbose is specified, informational-level and higher messages are printed. 
### Restore behavior
By default, restore will skip items with the same name. If an existing item on vManage has the same name as an item in the backup this item is skipped from restore.
Any references/dependencies on that item are properly updated. For instance, if a feature template is not pushed to vManage because an item with the same name is already present, device templates being pushed will now point to the feature template which is already on vManage.
**Restore with --update:**
Adding the --update option to restore modifies this behavior. In this case, Sastre will update existing items containing the same name as in the backup, but only if their content is different.
When an existing vManage item is modified, device templates may need to be reattached or vSmart policies may need to be re-activated. This is handled as follows:
- Updating items associated with an active vSmart policy may require this policy to be re-activated. In this case, Sastre will request the policy reactivate automatically.
- On updates to master templates (e.g. device template) containing attached devices, Sastre will re-attach the device templates.
- On Updates to child templates (e.g. feature template) associated with master templates containing attached devices, Sastre will re-attach the affected master template(s).
- In all re-attach cases, Sastre will use the existing attachment values on vManage to feed the attach request.
The implication is that if modified templates define new variables re-attach will fail, because not all variables would have values assigned. In this case, the recommended procedure is to detach the master template (e.g. using detach task), re-run "restore --update", then re-attach the device-template from vManage, where one would be able to supply any missing variable values.
**Factory default items:**
If a factory-default item in the backup is a dependency (referenced by other items) that is missing on the target vManage, it is converted to a non-default item and pushed to vManage. 
A WARNING message is displayed when this condition happens. The user may want to review the corresponding templates/policies and update them to reference newer versions or equivalent factory-defaults that may be available on vManage. 
## Installing
Sastre requires Python 3.8 or newer. This can be verified by pasting the following to a terminal window:
```
% python3 -c "import sys;assert sys.version_info>(3,8)" && echo "ALL GOOD"
```
If 'ALL GOOD' is printed it means Python requirements are met. If not, download and install the latest 3.x version at Python.org (https://www.python.org/downloads/).
The recommended way to install Sastre is via pip. For development purposes, Sastre can be installed from the GitHub repository. Both methods are described in this section.
### PIP install in a virtual environment (recommended)
Create a directory to store the virtual environment and runtime files:
```
% mkdir sastre
% cd sastre
```
Create virtual environment:
```
% python3 -m venv venv
```
Activate virtual environment:
```
% source venv/bin/activate
(venv) %
```
- Note that the prompt is updated with the virtual environment name (venv), indicating that the virtual environment is active.
Upgrade initial virtual environment packages:
```
(venv) % pip install --upgrade pip setuptools
```
Install Sastre:
```
(venv) % pip install --upgrade cisco-sdwan
```
Verify that Sastre can run:
```
(venv) % sdwan --version
```
Notes:
- The virtual environment is deactivated by typing 'deactivate' at the command prompt.
- Before running Sastre, make sure to activate the virtual environment back again (source venv/bin/activate).
### PIP install
With this option you will likely need to run the pip commands as sudo.
Install Sastre:
```
% python3 -m pip install --upgrade cisco-sdwan
```
Verify that Sastre can run:
```
% sdwan --version
```
### GitHub install
Clone from the GitHub repository:
```
% git clone https://github.com/CiscoDevNet/sastre
```
Move to the clone directory:
```
% cd sastre
```
Create virtual environment:
```
% python3 -m venv venv
```
Activate virtual environment:
```
% source venv/bin/activate
(venv) %
```
- Note that the prompt is updated with the virtual environment name (venv), indicating that the virtual environment is active.
Upgrade initial virtual environment packages:
```
(venv) % pip install --upgrade pip setuptools
```
Install required Python packages:
```
(venv) % pip install -r requirements.txt
```
Verify that Sastre can run:
```
(venv) % python3 sdwan.py --version
```
### Docker install
First, proceed with the [GitHub install](#GitHub-install) outlined above.
Ensure you are within the directory cloned from GitHub:
```
% cd sastre
```
Then proceed as follows to build the docker container:
```
% docker build -t sastre .
Sending build context to Docker daemon    220MB
Step 1/12 : ARG http_proxy
Step 2/12 : ARG https_proxy
Step 3/12 : ARG no_proxy

%package -n python3-cisco-sdwan
Summary:	Cisco-SDWAN Automation Toolset
Provides:	python-cisco-sdwan
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-cisco-sdwan
tag: template_feature
name_template:
  regex: "^All-"
  name_regex: "{name ^All-(.+)}"
name_map:
  DC1-VPN10-Interface-Template: DC-VPN10-Interface_v01
  DC1-VPN20-Interface-Template: DC-VPN20-Interface_v01
% sdwan --verbose transform recipe --from-file recipe.yaml test-transform
INFO: Transform task: vManage URL: "https://198.18.1.10" -> Local output dir: "test-transform"
<< snip >>
INFO: Matched feature template All-VPN0-TEMPLATE_cEdge
INFO: Replacing feature template: All-VPN0-TEMPLATE_cEdge -> VPN0-TEMPLATE_cEdge
INFO: Inspecting template_device items
INFO: Task completed successfully
```
Push changes to vManage using the restore task:
```
% sdwan --verbose restore all --workdir test-transform --update             
INFO: Restore task: Local workdir: "test-transform" -> vManage URL: "https://198.18.1.10"
<< snip >>
INFO: Task completed successfully
```
## Notes
### Regular Expressions
It is recommended to always use single quotes when specifying a regular expression to --regex option:
```
sdwan --verbose restore all --regex 'VPN1'
```
This is to prevent the shell from interpreting special characters that could be part of the pattern provided.
Matching done by --regex is un-anchored. That is, unless anchor marks are provided (e.g. ^ or $), the specified pattern matches if present anywhere in the string. In other words, this is a search function.
The regular expression syntax supported is described in https://docs.python.org/3/library/re.html
#### Behavior of --regex and --not-regex:
- --regex is used to select items to include (i.e. perform task operation)
- --not-regex is used to define items not to include. That is, select all items, except the ones matching --not-regex.
- When --regex match on multiple fields (e.g. item name, item ID), an item is selected if the item name OR item ID match the regular expression provided.
- With --not-regex, when it matches on multiple fields (e.g. item name, item ID), all items are selected, except the ones where item name OR item ID match the regular expression.
### Template name manipulation via name-regex
Multiple Sastre tasks utilize name-regex for name manipulation:
- Migrate task --name option accepts a name-regex.
- Transform copy/rename tasks have a `<name-regex>` mandatory parameter. 
- Transform recipe task allow `name_regex` under `name_template` section of the recipe YAML file. 
- The 'list transform' task also take a `<name-regex>` parameter. This task was designed to facilitate testing of those expressions.
A name-regex is a template for creating a new name based on segments of an original name.
The following rules apply:
- Occurrences of {name} are replaced with the original item name.
- Sections of the original item name can be captured by providing a regular expression in the format: {name &lt;regex&gt;}. This regular expression must contain one or more capturing groups, which define segments of the original name to "copy". Segments matching each capturing group are concatenated and "pasted" to the {name} position.
- If the regular expression does not match, {name &lt;regex&gt;} is replaced with an empty string.
Example:
```
Consider the template name "G_Branch_184_Single_cE4451-X_2xWAN_DHCP_L2_v01". 
In order to get the migrated name as "G_Branch_201_Single_cE4451-X_2xWAN_DHCP_L2_v01", one can use --name '{name (G_.+)_184_.+}_201_{name G.+_184_(.+)}'.
% sdwan list transform template_device --regex 'G_Branch_184_Single_cE4451' --workdir sastre_cx_golden_repo '{name (G_.+)_184_.+}_201_{name G.+_184_(.+)}'
+===================================================================================================================================================================+
| Name                                                          | Transformed                                                   | Tag             | Type            |
+===================================================================================================================================================================+
| G_Branch_184_Single_cE4451-X_2xWAN_Static_2xSLAN_Trunk_L2_v01 | G_Branch_201_Single_cE4451-X_2xWAN_Static_2xSLAN_Trunk_L2_v01 | template_device | device template |
| G_Branch_184_Single_cE4451-X_2xWAN_DHCP_L2_v01                | G_Branch_201_Single_cE4451-X_2xWAN_DHCP_L2_v01                | template_device | device template |
+---------------------------------------------------------------+---------------------------------------------------------------+-----------------+-----------------+
```
### Logs
Sastre logs messages to the terminal and to log files (under the logs/ directory).
Debug-level and higher severity messages are always saved to the log files.
The --verbose flag controls the severity of messages printed to the terminal. If --verbose is not specified, only warning-level and higher messages are logged. When --verbose is specified, informational-level and higher messages are printed. 
### Restore behavior
By default, restore will skip items with the same name. If an existing item on vManage has the same name as an item in the backup this item is skipped from restore.
Any references/dependencies on that item are properly updated. For instance, if a feature template is not pushed to vManage because an item with the same name is already present, device templates being pushed will now point to the feature template which is already on vManage.
**Restore with --update:**
Adding the --update option to restore modifies this behavior. In this case, Sastre will update existing items containing the same name as in the backup, but only if their content is different.
When an existing vManage item is modified, device templates may need to be reattached or vSmart policies may need to be re-activated. This is handled as follows:
- Updating items associated with an active vSmart policy may require this policy to be re-activated. In this case, Sastre will request the policy reactivate automatically.
- On updates to master templates (e.g. device template) containing attached devices, Sastre will re-attach the device templates.
- On Updates to child templates (e.g. feature template) associated with master templates containing attached devices, Sastre will re-attach the affected master template(s).
- In all re-attach cases, Sastre will use the existing attachment values on vManage to feed the attach request.
The implication is that if modified templates define new variables re-attach will fail, because not all variables would have values assigned. In this case, the recommended procedure is to detach the master template (e.g. using detach task), re-run "restore --update", then re-attach the device-template from vManage, where one would be able to supply any missing variable values.
**Factory default items:**
If a factory-default item in the backup is a dependency (referenced by other items) that is missing on the target vManage, it is converted to a non-default item and pushed to vManage. 
A WARNING message is displayed when this condition happens. The user may want to review the corresponding templates/policies and update them to reference newer versions or equivalent factory-defaults that may be available on vManage. 
## Installing
Sastre requires Python 3.8 or newer. This can be verified by pasting the following to a terminal window:
```
% python3 -c "import sys;assert sys.version_info>(3,8)" && echo "ALL GOOD"
```
If 'ALL GOOD' is printed it means Python requirements are met. If not, download and install the latest 3.x version at Python.org (https://www.python.org/downloads/).
The recommended way to install Sastre is via pip. For development purposes, Sastre can be installed from the GitHub repository. Both methods are described in this section.
### PIP install in a virtual environment (recommended)
Create a directory to store the virtual environment and runtime files:
```
% mkdir sastre
% cd sastre
```
Create virtual environment:
```
% python3 -m venv venv
```
Activate virtual environment:
```
% source venv/bin/activate
(venv) %
```
- Note that the prompt is updated with the virtual environment name (venv), indicating that the virtual environment is active.
Upgrade initial virtual environment packages:
```
(venv) % pip install --upgrade pip setuptools
```
Install Sastre:
```
(venv) % pip install --upgrade cisco-sdwan
```
Verify that Sastre can run:
```
(venv) % sdwan --version
```
Notes:
- The virtual environment is deactivated by typing 'deactivate' at the command prompt.
- Before running Sastre, make sure to activate the virtual environment back again (source venv/bin/activate).
### PIP install
With this option you will likely need to run the pip commands as sudo.
Install Sastre:
```
% python3 -m pip install --upgrade cisco-sdwan
```
Verify that Sastre can run:
```
% sdwan --version
```
### GitHub install
Clone from the GitHub repository:
```
% git clone https://github.com/CiscoDevNet/sastre
```
Move to the clone directory:
```
% cd sastre
```
Create virtual environment:
```
% python3 -m venv venv
```
Activate virtual environment:
```
% source venv/bin/activate
(venv) %
```
- Note that the prompt is updated with the virtual environment name (venv), indicating that the virtual environment is active.
Upgrade initial virtual environment packages:
```
(venv) % pip install --upgrade pip setuptools
```
Install required Python packages:
```
(venv) % pip install -r requirements.txt
```
Verify that Sastre can run:
```
(venv) % python3 sdwan.py --version
```
### Docker install
First, proceed with the [GitHub install](#GitHub-install) outlined above.
Ensure you are within the directory cloned from GitHub:
```
% cd sastre
```
Then proceed as follows to build the docker container:
```
% docker build -t sastre .
Sending build context to Docker daemon    220MB
Step 1/12 : ARG http_proxy
Step 2/12 : ARG https_proxy
Step 3/12 : ARG no_proxy

%package help
Summary:	Development documents and examples for cisco-sdwan
Provides:	python3-cisco-sdwan-doc
%description help
tag: template_feature
name_template:
  regex: "^All-"
  name_regex: "{name ^All-(.+)}"
name_map:
  DC1-VPN10-Interface-Template: DC-VPN10-Interface_v01
  DC1-VPN20-Interface-Template: DC-VPN20-Interface_v01
% sdwan --verbose transform recipe --from-file recipe.yaml test-transform
INFO: Transform task: vManage URL: "https://198.18.1.10" -> Local output dir: "test-transform"
<< snip >>
INFO: Matched feature template All-VPN0-TEMPLATE_cEdge
INFO: Replacing feature template: All-VPN0-TEMPLATE_cEdge -> VPN0-TEMPLATE_cEdge
INFO: Inspecting template_device items
INFO: Task completed successfully
```
Push changes to vManage using the restore task:
```
% sdwan --verbose restore all --workdir test-transform --update             
INFO: Restore task: Local workdir: "test-transform" -> vManage URL: "https://198.18.1.10"
<< snip >>
INFO: Task completed successfully
```
## Notes
### Regular Expressions
It is recommended to always use single quotes when specifying a regular expression to --regex option:
```
sdwan --verbose restore all --regex 'VPN1'
```
This is to prevent the shell from interpreting special characters that could be part of the pattern provided.
Matching done by --regex is un-anchored. That is, unless anchor marks are provided (e.g. ^ or $), the specified pattern matches if present anywhere in the string. In other words, this is a search function.
The regular expression syntax supported is described in https://docs.python.org/3/library/re.html
#### Behavior of --regex and --not-regex:
- --regex is used to select items to include (i.e. perform task operation)
- --not-regex is used to define items not to include. That is, select all items, except the ones matching --not-regex.
- When --regex match on multiple fields (e.g. item name, item ID), an item is selected if the item name OR item ID match the regular expression provided.
- With --not-regex, when it matches on multiple fields (e.g. item name, item ID), all items are selected, except the ones where item name OR item ID match the regular expression.
### Template name manipulation via name-regex
Multiple Sastre tasks utilize name-regex for name manipulation:
- Migrate task --name option accepts a name-regex.
- Transform copy/rename tasks have a `<name-regex>` mandatory parameter. 
- Transform recipe task allow `name_regex` under `name_template` section of the recipe YAML file. 
- The 'list transform' task also take a `<name-regex>` parameter. This task was designed to facilitate testing of those expressions.
A name-regex is a template for creating a new name based on segments of an original name.
The following rules apply:
- Occurrences of {name} are replaced with the original item name.
- Sections of the original item name can be captured by providing a regular expression in the format: {name &lt;regex&gt;}. This regular expression must contain one or more capturing groups, which define segments of the original name to "copy". Segments matching each capturing group are concatenated and "pasted" to the {name} position.
- If the regular expression does not match, {name &lt;regex&gt;} is replaced with an empty string.
Example:
```
Consider the template name "G_Branch_184_Single_cE4451-X_2xWAN_DHCP_L2_v01". 
In order to get the migrated name as "G_Branch_201_Single_cE4451-X_2xWAN_DHCP_L2_v01", one can use --name '{name (G_.+)_184_.+}_201_{name G.+_184_(.+)}'.
% sdwan list transform template_device --regex 'G_Branch_184_Single_cE4451' --workdir sastre_cx_golden_repo '{name (G_.+)_184_.+}_201_{name G.+_184_(.+)}'
+===================================================================================================================================================================+
| Name                                                          | Transformed                                                   | Tag             | Type            |
+===================================================================================================================================================================+
| G_Branch_184_Single_cE4451-X_2xWAN_Static_2xSLAN_Trunk_L2_v01 | G_Branch_201_Single_cE4451-X_2xWAN_Static_2xSLAN_Trunk_L2_v01 | template_device | device template |
| G_Branch_184_Single_cE4451-X_2xWAN_DHCP_L2_v01                | G_Branch_201_Single_cE4451-X_2xWAN_DHCP_L2_v01                | template_device | device template |
+---------------------------------------------------------------+---------------------------------------------------------------+-----------------+-----------------+
```
### Logs
Sastre logs messages to the terminal and to log files (under the logs/ directory).
Debug-level and higher severity messages are always saved to the log files.
The --verbose flag controls the severity of messages printed to the terminal. If --verbose is not specified, only warning-level and higher messages are logged. When --verbose is specified, informational-level and higher messages are printed. 
### Restore behavior
By default, restore will skip items with the same name. If an existing item on vManage has the same name as an item in the backup this item is skipped from restore.
Any references/dependencies on that item are properly updated. For instance, if a feature template is not pushed to vManage because an item with the same name is already present, device templates being pushed will now point to the feature template which is already on vManage.
**Restore with --update:**
Adding the --update option to restore modifies this behavior. In this case, Sastre will update existing items containing the same name as in the backup, but only if their content is different.
When an existing vManage item is modified, device templates may need to be reattached or vSmart policies may need to be re-activated. This is handled as follows:
- Updating items associated with an active vSmart policy may require this policy to be re-activated. In this case, Sastre will request the policy reactivate automatically.
- On updates to master templates (e.g. device template) containing attached devices, Sastre will re-attach the device templates.
- On Updates to child templates (e.g. feature template) associated with master templates containing attached devices, Sastre will re-attach the affected master template(s).
- In all re-attach cases, Sastre will use the existing attachment values on vManage to feed the attach request.
The implication is that if modified templates define new variables re-attach will fail, because not all variables would have values assigned. In this case, the recommended procedure is to detach the master template (e.g. using detach task), re-run "restore --update", then re-attach the device-template from vManage, where one would be able to supply any missing variable values.
**Factory default items:**
If a factory-default item in the backup is a dependency (referenced by other items) that is missing on the target vManage, it is converted to a non-default item and pushed to vManage. 
A WARNING message is displayed when this condition happens. The user may want to review the corresponding templates/policies and update them to reference newer versions or equivalent factory-defaults that may be available on vManage. 
## Installing
Sastre requires Python 3.8 or newer. This can be verified by pasting the following to a terminal window:
```
% python3 -c "import sys;assert sys.version_info>(3,8)" && echo "ALL GOOD"
```
If 'ALL GOOD' is printed it means Python requirements are met. If not, download and install the latest 3.x version at Python.org (https://www.python.org/downloads/).
The recommended way to install Sastre is via pip. For development purposes, Sastre can be installed from the GitHub repository. Both methods are described in this section.
### PIP install in a virtual environment (recommended)
Create a directory to store the virtual environment and runtime files:
```
% mkdir sastre
% cd sastre
```
Create virtual environment:
```
% python3 -m venv venv
```
Activate virtual environment:
```
% source venv/bin/activate
(venv) %
```
- Note that the prompt is updated with the virtual environment name (venv), indicating that the virtual environment is active.
Upgrade initial virtual environment packages:
```
(venv) % pip install --upgrade pip setuptools
```
Install Sastre:
```
(venv) % pip install --upgrade cisco-sdwan
```
Verify that Sastre can run:
```
(venv) % sdwan --version
```
Notes:
- The virtual environment is deactivated by typing 'deactivate' at the command prompt.
- Before running Sastre, make sure to activate the virtual environment back again (source venv/bin/activate).
### PIP install
With this option you will likely need to run the pip commands as sudo.
Install Sastre:
```
% python3 -m pip install --upgrade cisco-sdwan
```
Verify that Sastre can run:
```
% sdwan --version
```
### GitHub install
Clone from the GitHub repository:
```
% git clone https://github.com/CiscoDevNet/sastre
```
Move to the clone directory:
```
% cd sastre
```
Create virtual environment:
```
% python3 -m venv venv
```
Activate virtual environment:
```
% source venv/bin/activate
(venv) %
```
- Note that the prompt is updated with the virtual environment name (venv), indicating that the virtual environment is active.
Upgrade initial virtual environment packages:
```
(venv) % pip install --upgrade pip setuptools
```
Install required Python packages:
```
(venv) % pip install -r requirements.txt
```
Verify that Sastre can run:
```
(venv) % python3 sdwan.py --version
```
### Docker install
First, proceed with the [GitHub install](#GitHub-install) outlined above.
Ensure you are within the directory cloned from GitHub:
```
% cd sastre
```
Then proceed as follows to build the docker container:
```
% docker build -t sastre .
Sending build context to Docker daemon    220MB
Step 1/12 : ARG http_proxy
Step 2/12 : ARG https_proxy
Step 3/12 : ARG no_proxy

%prep
%autosetup -n cisco_sdwan-1.21.2

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-cisco-sdwan -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Fri Jun 09 2023 Python_Bot <Python_Bot@openeuler.org> - 1.21.2-1
- Package Spec generated