-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlispapi.py
1706 lines (1433 loc) · 59.1 KB
/
lispapi.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
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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -----------------------------------------------------------------------------
#
# Copyright 2013-2019 lispers.net - Dino Farinacci <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -----------------------------------------------------------------------------
#
# lispapi.py
#
# This file containse API definitions that users call in their python programs.
#
# When this file is changed, remote file lispapi.html and click the "API
# Documentation" button on the landing page to build a pydoc lispapi.txt
# file.
#
# If you modify this file, please run:
#
# pydoc lispapi.py > lispapi.txt
#
# So the API documentation stays up to date. Then commit lispapi.txt to the
# repo.
#
# -----------------------------------------------------------------------------
from __future__ import print_function
from builtins import str
from builtins import range
from builtins import object
"""
This python module is called by client network applications that want to
interface with the lispers.net implementation of LISP. For questions, bug
reports, or feature requests, contact [email protected].
Here is a program calling sequence:
>>> import lispapi
>>> att = lispapi.api_init("att.net", "root")
>>> vz = lispapi.api_init("verizon.net", "root")
>>>
>>> att_rtr = att.is_rtr_enabled()
>>> vz_ms = vz.is_ms_enabled()
>>>
>>> print "AT&T has RTR:, att_rtr
AT&T has RTR: True
>>> print "VZ has MS:", vz_ms
VZ has MS: False
>>>
>>> vz.enable_ms()
>>> print "VZ has MS:", vz.is_ms_enabled()
VZ has MS: True
>>>
"""
#------------------------------------------------------------------------------
import requests
import json
import os
#
# Supress cert verfication warnings from requests library.
#
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
REQ_TIMEOUT = 3
#------------------------------------------------------------------------------
class api_init(object):
def __init__(self, host, user, pw=None, port=8080, api_debug=False,
do_get=True):
""" Required to be first call by API user. Returns instance that must
be stored by caller. If 'pw' is None, then the password will be
obtained from the environment variable LISPAPI_PW. If you want the
LISP API to return debug information, pass argument api_debug=True.
If 'port' is negative, use http versus https.
"""
self.host = host
self.user = user
if (pw == None): pw = os.getenv("LISPAPI_PW_" + host)
if (pw == None): pw = os.getenv("LISPAPI_PW")
self.pw = pw
http = "https://"
if (port < 0):
port = -port
http = http.replace("s", "")
#endif
self.url = http + self.host + ":{}/lisp/api/".format(str(port))
self.enable_status = None
self.debug_status = None
self.api_debug = api_debug
self.enable_status = None
self.debug_status = None
self.xtr_parameters = None
#
# Test username/password by getting LISP component status. Store it
# locally so we can do quick gets later or put individual entries.
#
if (do_get):
self.get_enable()
self.get_debug()
self.get_xtr_parameters()
#endif
#enddef
def api_print(self):
""" Print contents of lispapi class. Returns a string. """
print("url: {}@{}, enable-status: {}, debug-status: {}".format( \
self.user, self.url, self.enable_status, self.debug_status))
#enddef
def api_enable_debug(self):
""" Enable debug output for this LISP API. """
self.api_debug = True
#enddef
def api_disable_debug(self):
""" Disable debug output for this LISP API. """
self.api_debug = False
#enddef
def get_enable(self, force_query=False):
""" Returns "lisp enable" status for system. Returns a dictionary
array.
"""
if (force_query == False and self.enable_status != None):
return(self.enable_status)
#endif
data = self.__get("lisp enable")
self.enable_status = data
return(data)
#enddef
def get_debug(self):
""" Returns "lisp debug" status for system. Returns a dictionary
array.
"""
if (self.debug_status != None): return(self.debug_status)
data = self.__get("lisp debug")
self.debug_status = data
return(data)
#enddef
def get_xtr_parameters(self):
""" Returns the "lisp xtr-parameters" settings for the system. Returns
a dictionary array.
"""
if (self.xtr_parameters != None): return(self.xtr_parameters)
data = self.__get("lisp xtr-parameters")
self.xtr_parameters = data
return(data)
#enddef
def is_itr_enabled(self):
""" Return True if ITR is enabled on system. """
return(self.enable_status and self.enable_status["itr"] == "yes")
#enddef
def is_etr_enabled(self):
""" Return True if ETR is enabled on system. """
return(self.enable_status and self.enable_status["etr"] == "yes")
#enddef
def is_rtr_enabled(self):
""" Return True if RTR is enabled on system. """
return(self.enable_status and self.enable_status["rtr"] == "yes")
#enddef
def is_mr_enabled(self):
""" Return True if MR is enabled on system. """
return(self.enable_status and
self.enable_status["map-resolver"] == "yes")
#enddef
def is_ms_enabled(self):
""" Return True if Map-Server is enabled on system. """
return(self.enable_status and
self.enable_status["map-server"] == "yes")
#enddef
def is_ddt_enabled(self):
""" Return True if DDT-node is enabled on system. """
return(self.enable_status and self.enable_status["ddt-node"] == "yes")
#enddef
def is_itr_debug_enabled(self):
""" Return True if ITR debug looging is enabled on system. """
return(self.debug_status and self.debug_status["itr"] == "yes")
#enddef
def is_etr_debug_enabled(self):
""" Return True if ETR debug looging is enabled on system. """
return(self.debug_status and self.debug_status["etr"] == "yes")
#enddef
def is_rtr_debug_enabled(self):
""" Return True if RTR debug looging is enabled on system. """
return(self.debug_status and self.debug_status["rtr"] == "yes")
#enddef
def is_mr_debug_enabled(self):
""" Return True if Map-Resolver debug looging is enabled on system. """
return(self.debug_status and
self.debug_status["map-resolver"] == "yes")
#enddef
def is_ms_debug_enabled(self):
""" Return True if Map-Server debug looging is enabled on system. """
return(self.debug_status and self.debug_status["map-server"] == "yes")
#enddef
def is_ddt_debug_enabled(self):
""" Return True if DDT-node debug looging is enabled on system. """
return(self.debug_status and self.debug_status["ddt-node"] == "yes")
#enddef
def enable_itr(self):
""" Activate ITR functionality on system. """
if (self.enable_status == None): return
self.enable_status["itr"] = "yes"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def enable_etr(self):
""" Activate ETR functionality on system. """
if (self.enable_status == None): return
self.enable_status["etr"] = "yes"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def enable_rtr(self):
""" Activate RTR functionality on system. """
if (self.enable_status == None): return
self.enable_status["rtr"] = "yes"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def enable_mr(self):
""" Activate Map-Resolver functionality on system. """
if (self.enable_status == None): return
self.enable_status["map-resolver"] = "yes"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def enable_ms(self):
""" Activate Map-Server functionality on system. """
if (self.enable_status == None): return
self.enable_status["map-server"] = "yes"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def enable_ddt(self):
""" Activate DDT-node functionality on system. """
if (self.enable_status == None): return
self.enable_status["ddt-node"] = "yes"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def disable_itr(self):
""" Deactivate ITR functionality on system. """
if (self.enable_status == None): return
self.enable_status["itr"] = "no"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def disable_etr(self):
""" Deactivate ETR functionality on system. """
if (self.enable_status == None): return
self.enable_status["etr"] = "no"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def disable_rtr(self):
""" Deactivate RTR functionality on system. """
if (self.enable_status == None): return
self.enable_status["rtr"] = "no"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def disable_mr(self):
""" Deactivate Map-Resolver functionality on system. """
if (self.enable_status == None): return
self.enable_status["map-resolver"] = "no"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def disable_ms(self):
""" Deactivate Map-Server functionality on system. """
if (self.enable_status == None): return
self.enable_status["map-server"] = "no"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def disable_ddt(self):
""" Deactivate DDT-node functionality on system. """
if (self.enable_status == None): return
self.enable_status["ddt-node"] = "no"
data = self.__put("lisp enable", self.enable_status)
return(self.__error(data) == False)
#enddef
def enable_core_debug(self):
""" Activate the LISP core process debug logging. """
if (self.debug_status == None): return
self.debug_status["core"] = "yes"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def enable_itr_debug(self):
""" Activate ITR debug logging. """
if (self.debug_status == None): return
self.debug_status["itr"] = "yes"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def enable_etr_debug(self):
""" Activate ETR debug logging. """
if (self.debug_status == None): return
self.debug_status["etr"] = "yes"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def enable_rtr_debug(self):
""" Activate RTR debug logging. """
if (self.debug_status == None): return
self.debug_status["rtr"] = "yes"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def enable_mr_debug(self):
""" Activate Map-Resolver debug logging. """
if (self.debug_status == None): return
self.debug_status["map-resolver"] = "yes"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def enable_ms_debug(self):
""" Activate Map-Server debug logging. """
if (self.debug_status == None): return
self.debug_status["map-server"] = "yes"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def enable_ddt_debug(self):
""" Activate DDT-node debug logging. """
if (self.debug_status == None): return
self.debug_status["ddt-node"] = "yes"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def disable_core_debug(self):
""" Deactivate the LISP core process debug logging. """
if (self.debug_status == None): return
self.debug_status["core"] = "no"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def disable_itr_debug(self):
""" Deactivate ITR debug logging. """
if (self.debug_status == None): return
self.debug_status["itr"] = "no"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def disable_etr_debug(self):
""" Deactivate ETR debug logging. """
if (self.debug_status == None): return
self.debug_status["etr"] = "no"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def disable_rtr_debug(self):
""" Deactivate RTR debug logging. """
if (self.debug_status == None): return
self.debug_status["rtr"] = "no"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def disable_mr_debug(self):
""" Deactivate Map-Resolver debug logging. """
if (self.debug_status == None): return
self.debug_status["map-resolver"] = "no"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def disable_ms_debug(self):
""" Deactivate Map-Server debug logging. """
if (self.debug_status == None): return
self.debug_status["map-server"] = "no"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def disable_ddt_debug(self):
""" Deactivate DDT-node debug logging. """
if (self.debug_status == None): return
self.debug_status["ddt-node"] = "no"
data = self.__put("lisp debug", self.debug_status)
return(self.__error(data) == False)
#enddef
def add_user_account(self, username, password):
""" Configures a user-account command. Returns True if successful. """
if (self.enable_status == None): return
data = self.__put("lisp user-account",
{ "username" : username, "password" : password})
return(self.__error(data) == False)
#enddef
def delete_user_account(self, username):
""" Removes a user-account command. Returns True if successful. """
if (self.enable_status == None): return
data = self.__delete("lisp user-account", { "username" : username })
return(self.__error(data) == False)
#enddef
def enable_itr_security(self):
""" Enable AES encryption for packets ITRs or RTRs encapsulate. """
if (self.enable_status == None): return
self.xtr_parameters["data-plane-security"] = "yes"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def disable_itr_security(self):
""" Disable AES encryption for packets ITRs or RTRs encapsulate. """
if (self.enable_status == None): return
self.xtr_parameters["data-plane-security"] = "no"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def enable_xtr_nat_traversal(self):
""" Enable NAT-traversal functionality on ITR and ETR. Make sure
your database-mapping configuration contains an interface
(versus an address) for an RLOC."""
if (self.enable_status == None): return
self.xtr_parameters["nat-traversal"] = "yes"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def disable_xtr_nat_traversal(self):
""" Disable NAT-traversal functionality in an ITR and ETR."""
if (self.enable_status == None): return
self.xtr_parameters["nat-traversal"] = "no"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def enable_xtr_rloc_probing(self):
""" Enable RLOC-probing functionality on an ITR or RTR."""
if (self.enable_status == None): return
self.xtr_parameters["rloc-probing"] = "yes"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def disable_xtr_rloc_probing(self):
""" Disable RLOC-probing functionality on an ITR and RTR."""
if (self.enable_status == None): return
self.xtr_parameters["rloc-probing"] = "no"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def enable_xtr_nonce_echoing(self):
""" Enable Nonce-Echoing functionality on an ITR or RTR."""
if (self.enable_status == None): return
self.xtr_parameters["nonce-echoing"] = "yes"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def disable_xtr_nonce_echoing(self):
""" Disable Nonce-Echoing functionality on an ITR and RTR."""
if (self.enable_status == None): return
self.xtr_parameters["nonce-echoing"] = "no"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def enable_xtr_data_plane_logging(self):
""" Enable data-plane logging functionality on an xTR."""
if (self.enable_status == None): return
self.xtr_parameters["data-plane-logging"] = "yes"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def disable_xtr_data_plane_logging(self):
""" Disable data-plane logging functionality on an xTR."""
if (self.enable_status == None): return
self.xtr_parameters["data-plane-logging"] = "no"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def enable_xtr_flow_logging(self):
""" Enable packet flow logging functionality on an xTR."""
if (self.enable_status == None): return
self.xtr_parameters["flow-logging"] = "yes"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def disable_xtr_flow_logging(self):
""" Disable packet flow logging functionality on an xTR."""
if (self.enable_status == None): return
self.xtr_parameters["flow-logging"] = "no"
data = self.__put("lisp xtr-parameters", self.xtr_parameters)
if (self.__error(data)): return("put error")
return("good")
#enddef
def add_mr_ddt_root(self, address=""):
""" Configure the address of a LISP-DDT root node. Variable 'address'
is an IPv4 or IPv6 address string. Returns error string or "good"
when successful.
"""
if (address == ""): return("no address supplied")
if (self.__check_address_syntax(address) == False):
return("bad address syntax")
#endif
if (self.enable_status == None): return
data = self.__put("lisp ddt-root", { "address" : address })
if (self.__error(data)): return("put error")
return("good")
#enddef
def delete_mr_ddt_root(self, address=""):
""" Deconfigure the address of a LISP-DDT root node. Variable 'address'
is an IPv4 or IPv6 address string. Returns error string or "good"
when successful.
"""
if (address == ""): return("no address supplied")
if (self.__check_address_syntax(address) == False):
return("bad address syntax")
#endif
if (self.enable_status == None): return
data = self.__delete("lisp ddt-root", { "address" : address })
if (self.__error(data)): return("delete error")
return("good")
#enddef
def add_mr_referral(self, iid="0", prefix="", group="", referral_set=[]):
""" Configure a referral EID-prefix. First argument is an instance-ID
value in string format. the second argument is an IPv4, IPv6
or MAC address prefix string. The third argument is an optional
group address when an (S,G) entry is being passed where 'prefix'
is S and 'group" is G. The fourth argument is an array
of DDT-node IPv4 or IPv6 address strings. Returns error string or
"good" when successful.
"""
if (prefix == ""): return("no prefix supplied")
if (referral_set == ""): return("no referral-set supplied")
if (self.__check_prefix_syntax(prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.__check_address_set_syntax(referral_set, False) == False):
return("bad address syntax in referral-set")
#endif
if (self.enable_status == None): return
data = self.__build_prefix_tuple(iid, prefix, group)
data = [ data ]
for ref in referral_set:
data.append({"referral" : {"address" : ref}})
#endfor
data = self.__put("lisp referral-cache", data)
if (self.__error(data)): return("put error")
return("good")
#enddef
def delete_mr_referral(self, iid="0", prefix="", group=""):
""" Deconfigure a referral EID-prefix. The 'prefix' and 'group'
arguments are IPv4, IPv6 or MAC address prefix strings. The 'iid'
argument is the value of an instance-ID in string format.
Returns error string or "good" when successful.
"""
if (prefix == ""): return("no prefix supplied")
if (self.__check_prefix_syntax(prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.enable_status == None): return
data = self.__build_prefix_tuple(iid, prefix, group)
data = self.__delete("lisp referral-cache", data)
if (self.__error(data)): return("delete error")
return("good")
#enddef
def add_ddt_delegation(self, iid="0", prefix="", group="",
referral_set=[]):
""" Configure a LISP-DDT delegation EID-prefix with a referral-set.
First argument is an instance-ID value in string format. the
second argument is an IPv4, IPv6 or MAC address prefix string.
The third argument is an optional group address when an (S,G)
entry is being passed where 'prefix' is S and 'group" is G.
The fourth argument is an array of child DDT-node IPv4 or IPv6
address strings. Returns error string or "good" when successful.
"""
if (prefix == ""): return("no prefix supplied")
if (referral_set == ""): return("no referral-set supplied")
if (self.__check_prefix_syntax(prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.__check_address_set_syntax(referral_set, False) == False):
return("bad address syntax in referral-set")
#endif
if (self.enable_status == None): return
data = self.__build_prefix_tuple(iid, prefix, group)
data = [ data ]
for ref in referral_set:
data.append({"delegate" : {"address" : ref}})
#endfor
data = self.__put("lisp delegation", data)
if (self.__error(data)): return("put error")
return("good")
#enddef
def delete_ddt_delegation(self, iid="0", prefix="", group=""):
""" Deconfigure a LISP-DDT delegation EID-prefix. The 'prefix'
argument is an IPv4, IPv6 or MAC address prefix string.
The second argument is an array of child DDT-node IPv4 or IPv6
address strings. Returns error string or "good" when successful.
"""
if (prefix == ""): return("no prefix supplied")
if (self.__check_prefix_syntax(prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.enable_status == None): return
data = self.__build_prefix_tuple(iid, prefix, group)
data = self.__delete("lisp delegation", data)
if (self.__error(data)): return("delete error")
return("good")
#enddef
def add_ddt_auth_prefix(self, iid="0", auth_prefix="", group=""):
""" Configure a LISP-DDT authoritative-prefix for a DDT-node.
The 'auth_prefix' argument is an IPv4, IPv6 or MAC address prefix
string. Returns error string or "good" when successful.
"""
if (auth_prefix == ""): return("no prefix supplied")
if (self.__check_prefix_syntax(auth_prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.enable_status == None): return
data = self.__build_prefix_tuple(iid, auth_prefix, group)
data = [ data["prefix"] ]
data = self.__put("lisp ddt-authoritative-prefix", data)
if (self.__error(data)): return("put error")
return("good")
#enddef
def delete_ddt_auth_prefix(self, iid="0", auth_prefix="", group=""):
""" Deconfigure a LISP-DDT authoritative-prefix for a DDT-node.
The 'auth_prefix' argument is an IPv4, IPv6 or MAC address prefix
string. Returns error string or "good" when successful.
"""
if (auth_prefix == ""): return("no auth-prefix supplied")
if (self.__check_prefix_syntax(auth_prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.enable_status == None): return
data = self.__build_prefix_tuple(iid, auth_prefix, group)
data = self.__delete("lisp ddt-authoritative-prefix", data)
if (self.__error(data)): return("delete error")
return("good")
#enddef
def add_ms_map_server_peer(self, iid="0", prefix="", group="",
peer_set=[]):
""" Configure a Map-Server peer for a given EID-prefix. This allows
a Map-Server to return all otther Map-Servers in a Map-Referral
message for this given EID-prefix. First argument is an
instance-ID value in string format. the second argument is an
IPv4, IPv6 or MAC address prefix string. The third argument is an
optional group address when an (S,G) entry is being passed where
'prefix' is S and 'group" is G. The fourth argument is an array of
of all Map-Servers serving this EID-prefix. It should include
this local Map-Server the API call is to. Each element of the
array are address strings. Returns error string or "good" when
successful.
"""
if (prefix == ""): return("no prefix supplied")
if (peer_set == ""): return("no peer-set supplied")
if (self.__check_prefix_syntax(prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.__check_address_set_syntax(peer_set, False) == False):
return("bad address syntax in referral-set")
#endif
if (self.enable_status == None): return
data = self.__build_prefix_tuple(iid, prefix, group)
data = [ data ]
for peer in peer_set:
data.append({"peer" : {"address" : peer}})
#endfor
data = self.__put("lisp map-server-peer", data)
if (self.__error(data)): return("put error")
return("good")
#enddef
def delete_ms_map_server_peer(self, iid="0", prefix="", group=""):
""" Deconfigure a Map-Server peer EID-prefix in a Map-Server. The
'prefix' argument is an IPv4, IPv6 or MAC address prefix string.
The second argument is an array of child DDT-node IPv4 or IPv6
address strings. Returns error string or "good" when successful.
"""
if (prefix == ""): return("no prefix supplied")
if (self.__check_prefix_syntax(prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.enable_status == None): return
data = self.__build_prefix_tuple(iid, prefix, group)
data = self.__delete("lisp map-server-peer", data)
if (self.__error(data)): return("delete error")
return("good")
#enddef
def add_ms_site(self, site_name, auth_key, prefix_list, description=""):
""" Add LISP site with allowed EID-prefix list. Array prefix_list
must be built by build_ms_site_allowed_prefix() before using this
call."""
if (site_name == ""): return("no site-name supplied")
if (auth_key == ""): return("no auth_key supplied")
status = self.__check_prefix_list(prefix_list)
if (status != True): return(status)
if (self.enable_status == None): return
data = []
data.append({ "site-name" : site_name })
data.append({ "description" : description })
data.append({ "authentication-key" : auth_key })
data.append(prefix_list)
data = self.__put("lisp site", data)
if (self.__error(data)): return("put error")
return("good")
#enddef
def build_ms_site_allowed_prefix(self, prefix_list, iid="0", prefix="",
group="", ams=False, fpr=False, fnpr=False, pprd=False, pra=""):
""" Add EID-prefix and attributes to a prefix-list array to be supplied
with site information when calling add_ms_site(). Caller needs to
intialize prefix_list to [] for the first call and needs to pass
the same variable on each subsequent call.
"""
if (prefix == ""): return("no prefix supplied")
if (self.__check_prefix_syntax(prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.enable_status == None): return
#
# The prefix-list is an array of dictionary arrays.
#
data = self.__build_prefix_tuple(iid, prefix, group,
kw="allowed-prefix")
ap = data["allowed-prefix"]
if (ams): ap["accept-more-specifics"] = "yes"
if (fpr): ap["force-proxy-reply"] = "yes"
if (fnpr): ap["force-nat-proxy-reply"] = "yes"
if (pprd): ap["pitr-proxy-reply-drop"] = "yes"
if (pra != ""): ap["proxy-reply-action"] = pra
prefix_list.append(data)
return("good")
#enddef
def delete_ms_site(self, site_name):
""" Delete LISP site and all allowed EID-prefixes previously added
for the site.
"""
if (site_name == ""): return("no site-name supplied")
if (self.enable_status == None): return
data = self.__delete("lisp site", { "site-name" : site_name })
if (self.__error(data)): return("delete error")
return("good")
#enddef
def add_etr_database_mapping(self, iid="0", prefix="", group="",
rloc_set=[]):
""" Add database-mapping for LISP site to ETR. The rloc-set can be an
array of address strings or an array of dictionaries that has been
created by making successive calls to build_rloc_record().
"""
if (prefix == ""): return("no prefix supplied")
if (rloc_set == ""): return("no rloc-set supplied")
if (self.__check_prefix_syntax(prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.__check_address_set_syntax(rloc_set, True) == False):
return("bad address syntax in rloc-set")
#endif
if (self.enable_status == None): return
data = self.__build_prefix_tuple(iid, prefix, group)
data = [ data ]
for ref in rloc_set:
if (type(ref) == dict):
data.append({"rloc" : ref})
continue
#endif
if (ref in ["en0", "en1", "eth0", "eth1"]):
data.append({"rloc" : {"interface" : ref}})
else:
if (self.__is_dist_name(ref)):
data.append({"rloc" : {"rloc-record-name" : ref}})
else:
data.append({"rloc" : {"address" : ref}})
#endif
#endif
#endfor
data = self.__put("lisp database-mapping", data)
if (self.__error(data)): return("put error")
return("good")
#enddef
def delete_etr_database_mapping(self, iid="0", prefix="", group=""):
""" Remove database-mapping for LISP site from ETR."""
if (prefix == ""): return("no prefix supplied")
if (self.__check_prefix_syntax(prefix) == False):
return("bad prefix syntax")
#endif
if (group != "" and self.__check_prefix_syntax(group) == False):
return("bad group syntax")
#endif
if (self.enable_status == None): return
data = self.__build_prefix_tuple(iid, prefix, group)
data = self.__delete("lisp database-mapping", data)
if (self.__error(data)): return("delete error")
return("good")
#enddef