cisco_node_utils 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +60 -1
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/cisco_node_utils.gemspec +1 -1
- data/docs/README-develop-node-utils-APIs.md +2 -0
- data/docs/README-maintainers.md +45 -80
- data/lib/cisco_node_utils/ace.rb +24 -43
- data/lib/cisco_node_utils/bfd_global.rb +1 -0
- data/lib/cisco_node_utils/bgp_af_aggr_addr.rb +207 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +8 -5
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +8 -6
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +40 -0
- data/lib/cisco_node_utils/cmd_ref/bfd_global.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/bgp.yaml +8 -4
- data/lib/cisco_node_utils/cmd_ref/bgp_af_aa.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +9 -4
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +8 -3
- data/lib/cisco_node_utils/cmd_ref/dhcp_relay_global.yaml +2 -1
- data/lib/cisco_node_utils/cmd_ref/feature.yaml +5 -0
- data/lib/cisco_node_utils/cmd_ref/interface.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +7 -3
- data/lib/cisco_node_utils/cmd_ref/inventory.yaml +3 -3
- data/lib/cisco_node_utils/cmd_ref/ntp_auth_key.yaml +10 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +13 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +10 -2
- data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +6 -1
- data/lib/cisco_node_utils/cmd_ref/route_map.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/span_session.yaml +65 -0
- data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +2 -1
- data/lib/cisco_node_utils/cmd_ref/vpc.yaml +22 -3
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +2 -1
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +6 -3
- data/lib/cisco_node_utils/cmd_ref/yum.yaml +48 -4
- data/lib/cisco_node_utils/command_reference.rb +5 -2
- data/lib/cisco_node_utils/feature.rb +14 -1
- data/lib/cisco_node_utils/interface.rb +13 -0
- data/lib/cisco_node_utils/interface_channel_group.rb +33 -25
- data/lib/cisco_node_utils/itd_device_group.rb +17 -37
- data/lib/cisco_node_utils/itd_service.rb +9 -32
- data/lib/cisco_node_utils/node.rb +12 -4
- data/lib/cisco_node_utils/ntp_auth_key.rb +67 -0
- data/lib/cisco_node_utils/ntp_config.rb +19 -1
- data/lib/cisco_node_utils/ntp_server.rb +28 -27
- data/lib/cisco_node_utils/route_map.rb +33 -51
- data/lib/cisco_node_utils/snmpuser.rb +2 -2
- data/lib/cisco_node_utils/span_session.rb +149 -0
- data/lib/cisco_node_utils/upgrade.rb +21 -17
- data/lib/cisco_node_utils/version.rb +2 -2
- data/lib/cisco_node_utils/vlan.rb +1 -1
- data/lib/cisco_node_utils/vpc.rb +40 -0
- data/lib/cisco_node_utils/yum.rb +136 -13
- data/spec/schema.yaml +2 -0
- data/tests/ciscotest.rb +36 -0
- data/tests/test_ace.rb +6 -0
- data/tests/test_bfd_global.rb +1 -7
- data/tests/test_bgp_af.rb +2 -2
- data/tests/test_bgp_af_aa.rb +108 -0
- data/tests/test_bgp_neighbor.rb +2 -1
- data/tests/test_bgp_neighbor_af.rb +6 -6
- data/tests/test_dhcp_relay_global.rb +1 -0
- data/tests/test_interface.rb +18 -2
- data/tests/test_interface_channel_group.rb +47 -0
- data/tests/test_interface_svi.rb +1 -1
- data/tests/test_ntp_auth_key.rb +77 -0
- data/tests/test_ntp_config.rb +51 -4
- data/tests/test_ntp_server.rb +69 -9
- data/tests/test_overlay_global.rb +1 -0
- data/tests/test_route_map.rb +13 -24
- data/tests/test_router_bgp.rb +14 -9
- data/tests/test_span_session.rb +155 -0
- data/tests/test_stp_global.rb +1 -0
- data/tests/test_upgrade.rb +2 -3
- data/tests/test_vlan.rb +24 -3
- data/tests/test_vlan_private.rb +1 -1
- data/tests/test_vpc.rb +42 -17
- data/tests/test_vxlan_vtep.rb +1 -0
- data/tests/test_vxlan_vtep_vni.rb +5 -1
- data/tests/test_yum.rb +7 -30
- data/tests/yum_package.yaml +20 -0
- metadata +13 -3
@@ -453,31 +453,6 @@ module Cisco
|
|
453
453
|
config_get_default('route_map', 'match_ipv4_route_src_prefix_list')
|
454
454
|
end
|
455
455
|
|
456
|
-
# extract value of property from match ip multicast
|
457
|
-
def extract_value(type, prop, prefix=nil)
|
458
|
-
prefix = prop if prefix.nil?
|
459
|
-
match =
|
460
|
-
type == 'ipv4' ? match_ipv4_multicast_get : match_ipv6_multicast_get
|
461
|
-
|
462
|
-
# matching not found
|
463
|
-
return nil if match.nil? # no matching found
|
464
|
-
|
465
|
-
# property not defined for matching
|
466
|
-
return nil unless match.names.include?(prop)
|
467
|
-
|
468
|
-
# extract and return value that follows prefix + <space>
|
469
|
-
regexp = Regexp.new("#{Regexp.escape(prefix)} (?<extracted>.*)")
|
470
|
-
value_match = regexp.match(match[prop])
|
471
|
-
return nil if value_match.nil?
|
472
|
-
value_match[:extracted]
|
473
|
-
end
|
474
|
-
|
475
|
-
# prepend property name prefix/keyword to value
|
476
|
-
def attach_prefix(val, prop, prefix=nil)
|
477
|
-
prefix = prop.to_s if prefix.nil?
|
478
|
-
@set_args[prop] = val.to_s.empty? ? val : "#{prefix} #{val}"
|
479
|
-
end
|
480
|
-
|
481
456
|
# match ip multicast source 242.1.1.1/32 group 239.2.2.2/32 rp 242.1.1.1/32
|
482
457
|
# rp-type ASM
|
483
458
|
# match ip multicast source 242.1.1.1/32 group-range
|
@@ -495,13 +470,13 @@ module Cisco
|
|
495
470
|
end
|
496
471
|
|
497
472
|
def match_ipv4_multicast_src_addr
|
498
|
-
val = extract_value(
|
473
|
+
val = Utils.extract_value(match_ipv4_multicast_get, 'src', 'source')
|
499
474
|
return default_match_ipv4_multicast_src_addr if val.nil?
|
500
475
|
val
|
501
476
|
end
|
502
477
|
|
503
478
|
def match_ipv4_multicast_src_addr=(src_addr)
|
504
|
-
attach_prefix(src_addr, :source)
|
479
|
+
@set_args[:source] = Utils.attach_prefix(src_addr, :source)
|
505
480
|
end
|
506
481
|
|
507
482
|
def default_match_ipv4_multicast_src_addr
|
@@ -509,13 +484,13 @@ module Cisco
|
|
509
484
|
end
|
510
485
|
|
511
486
|
def match_ipv4_multicast_group_addr
|
512
|
-
val = extract_value(
|
487
|
+
val = Utils.extract_value(match_ipv4_multicast_get, 'grp', 'group')
|
513
488
|
return default_match_ipv4_multicast_group_addr if val.nil?
|
514
489
|
val
|
515
490
|
end
|
516
491
|
|
517
492
|
def match_ipv4_multicast_group_addr=(grp_addr)
|
518
|
-
attach_prefix(grp_addr, :group)
|
493
|
+
@set_args[:group] = Utils.attach_prefix(grp_addr, :group)
|
519
494
|
end
|
520
495
|
|
521
496
|
def default_match_ipv4_multicast_group_addr
|
@@ -523,13 +498,15 @@ module Cisco
|
|
523
498
|
end
|
524
499
|
|
525
500
|
def match_ipv4_multicast_group_range_begin_addr
|
526
|
-
val = extract_value(
|
501
|
+
val = Utils.extract_value(match_ipv4_multicast_get,
|
502
|
+
'grp_range_start', 'group-range')
|
527
503
|
return default_match_ipv4_multicast_group_range_begin_addr if val.nil?
|
528
504
|
val
|
529
505
|
end
|
530
506
|
|
531
507
|
def match_ipv4_multicast_group_range_begin_addr=(begin_addr)
|
532
|
-
|
508
|
+
@set_args[:group_range] =
|
509
|
+
Utils.attach_prefix(begin_addr, :group_range, :'group-range')
|
533
510
|
end
|
534
511
|
|
535
512
|
def default_match_ipv4_multicast_group_range_begin_addr
|
@@ -538,13 +515,13 @@ module Cisco
|
|
538
515
|
end
|
539
516
|
|
540
517
|
def match_ipv4_multicast_group_range_end_addr
|
541
|
-
val = extract_value(
|
518
|
+
val = Utils.extract_value(match_ipv4_multicast_get, 'grp_range_end', 'to')
|
542
519
|
return default_match_ipv4_multicast_group_range_end_addr if val.nil?
|
543
520
|
val
|
544
521
|
end
|
545
522
|
|
546
523
|
def match_ipv4_multicast_group_range_end_addr=(end_addr)
|
547
|
-
attach_prefix(end_addr, :to)
|
524
|
+
@set_args[:to] = Utils.attach_prefix(end_addr, :to)
|
548
525
|
end
|
549
526
|
|
550
527
|
def default_match_ipv4_multicast_group_range_end_addr
|
@@ -553,13 +530,13 @@ module Cisco
|
|
553
530
|
end
|
554
531
|
|
555
532
|
def match_ipv4_multicast_rp_addr
|
556
|
-
val = extract_value(
|
533
|
+
val = Utils.extract_value(match_ipv4_multicast_get, 'rp')
|
557
534
|
return default_match_ipv4_multicast_rp_addr if val.nil?
|
558
535
|
val
|
559
536
|
end
|
560
537
|
|
561
538
|
def match_ipv4_multicast_rp_addr=(rp_addr)
|
562
|
-
attach_prefix(rp_addr, :rp)
|
539
|
+
@set_args[:rp] = Utils.attach_prefix(rp_addr, :rp)
|
563
540
|
end
|
564
541
|
|
565
542
|
def default_match_ipv4_multicast_rp_addr
|
@@ -567,13 +544,13 @@ module Cisco
|
|
567
544
|
end
|
568
545
|
|
569
546
|
def match_ipv4_multicast_rp_type
|
570
|
-
val = extract_value(
|
547
|
+
val = Utils.extract_value(match_ipv4_multicast_get, 'rp_type', 'rp-type')
|
571
548
|
return default_match_ipv4_multicast_rp_type if val.nil?
|
572
549
|
val
|
573
550
|
end
|
574
551
|
|
575
552
|
def match_ipv4_multicast_rp_type=(type)
|
576
|
-
attach_prefix(type, :rp_type, :'rp-type')
|
553
|
+
@set_args[:rp_type] = Utils.attach_prefix(type, :rp_type, :'rp-type')
|
577
554
|
end
|
578
555
|
|
579
556
|
def default_match_ipv4_multicast_rp_type
|
@@ -750,13 +727,13 @@ module Cisco
|
|
750
727
|
end
|
751
728
|
|
752
729
|
def match_ipv6_multicast_src_addr
|
753
|
-
val = extract_value(
|
730
|
+
val = Utils.extract_value(match_ipv6_multicast_get, 'src', 'source')
|
754
731
|
return default_match_ipv6_multicast_src_addr if val.nil?
|
755
732
|
val
|
756
733
|
end
|
757
734
|
|
758
735
|
def match_ipv6_multicast_src_addr=(src_addr)
|
759
|
-
attach_prefix(src_addr, :source)
|
736
|
+
@set_args[:source] = Utils.attach_prefix(src_addr, :source)
|
760
737
|
end
|
761
738
|
|
762
739
|
def default_match_ipv6_multicast_src_addr
|
@@ -764,13 +741,13 @@ module Cisco
|
|
764
741
|
end
|
765
742
|
|
766
743
|
def match_ipv6_multicast_group_addr
|
767
|
-
val = extract_value(
|
744
|
+
val = Utils.extract_value(match_ipv6_multicast_get, 'grp', 'group')
|
768
745
|
return default_match_ipv6_multicast_group_addr if val.nil?
|
769
746
|
val
|
770
747
|
end
|
771
748
|
|
772
749
|
def match_ipv6_multicast_group_addr=(grp_addr)
|
773
|
-
attach_prefix(grp_addr, :group)
|
750
|
+
@set_args[:group] = Utils.attach_prefix(grp_addr, :group)
|
774
751
|
end
|
775
752
|
|
776
753
|
def default_match_ipv6_multicast_group_addr
|
@@ -778,13 +755,15 @@ module Cisco
|
|
778
755
|
end
|
779
756
|
|
780
757
|
def match_ipv6_multicast_group_range_begin_addr
|
781
|
-
val = extract_value(
|
758
|
+
val = Utils.extract_value(match_ipv6_multicast_get,
|
759
|
+
'grp_range_start', 'group-range')
|
782
760
|
return default_match_ipv6_multicast_group_range_begin_addr if val.nil?
|
783
761
|
val
|
784
762
|
end
|
785
763
|
|
786
764
|
def match_ipv6_multicast_group_range_begin_addr=(begin_addr)
|
787
|
-
|
765
|
+
@set_args[:group_range] =
|
766
|
+
Utils.attach_prefix(begin_addr, :group_range, :'group-range')
|
788
767
|
end
|
789
768
|
|
790
769
|
def default_match_ipv6_multicast_group_range_begin_addr
|
@@ -793,13 +772,13 @@ module Cisco
|
|
793
772
|
end
|
794
773
|
|
795
774
|
def match_ipv6_multicast_group_range_end_addr
|
796
|
-
val = extract_value(
|
775
|
+
val = Utils.extract_value(match_ipv6_multicast_get, 'grp_range_end', 'to')
|
797
776
|
return default_match_ipv6_multicast_group_range_end_addr if val.nil?
|
798
777
|
val
|
799
778
|
end
|
800
779
|
|
801
780
|
def match_ipv6_multicast_group_range_end_addr=(end_addr)
|
802
|
-
attach_prefix(end_addr, :to)
|
781
|
+
@set_args[:to] = Utils.attach_prefix(end_addr, :to)
|
803
782
|
end
|
804
783
|
|
805
784
|
def default_match_ipv6_multicast_group_range_end_addr
|
@@ -808,13 +787,13 @@ module Cisco
|
|
808
787
|
end
|
809
788
|
|
810
789
|
def match_ipv6_multicast_rp_addr
|
811
|
-
val = extract_value(
|
790
|
+
val = Utils.extract_value(match_ipv6_multicast_get, 'rp')
|
812
791
|
return default_match_ipv6_multicast_rp_addr if val.nil?
|
813
792
|
val
|
814
793
|
end
|
815
794
|
|
816
795
|
def match_ipv6_multicast_rp_addr=(rp_addr)
|
817
|
-
attach_prefix(rp_addr, :rp)
|
796
|
+
@set_args[:rp] = Utils.attach_prefix(rp_addr, :rp)
|
818
797
|
end
|
819
798
|
|
820
799
|
def default_match_ipv6_multicast_rp_addr
|
@@ -822,13 +801,13 @@ module Cisco
|
|
822
801
|
end
|
823
802
|
|
824
803
|
def match_ipv6_multicast_rp_type
|
825
|
-
val = extract_value(
|
804
|
+
val = Utils.extract_value(match_ipv6_multicast_get, 'rp_type', 'rp-type')
|
826
805
|
return default_match_ipv6_multicast_rp_type if val.nil?
|
827
806
|
val
|
828
807
|
end
|
829
808
|
|
830
809
|
def match_ipv6_multicast_rp_type=(type)
|
831
|
-
attach_prefix(type, :rp_type, :'rp-type')
|
810
|
+
@set_args[:rp_type] = Utils.attach_prefix(type, :rp_type, :'rp-type')
|
832
811
|
end
|
833
812
|
|
834
813
|
def default_match_ipv6_multicast_rp_type
|
@@ -1596,14 +1575,17 @@ module Cisco
|
|
1596
1575
|
end
|
1597
1576
|
|
1598
1577
|
def set_metric_set(plus, bndw, del, reliability, eff_bw, mtu)
|
1599
|
-
state
|
1578
|
+
set_args_keys(state: 'no', additive: '', bw: '', delay: '',
|
1579
|
+
rel: '', eff: '', mtu: '')
|
1580
|
+
config_set('route_map', 'set_metric', @set_args)
|
1581
|
+
return unless bndw
|
1600
1582
|
additive = plus ? '+' : ''
|
1601
1583
|
bw = bndw ? bndw : ''
|
1602
1584
|
delay = del ? del : ''
|
1603
1585
|
rel = reliability ? reliability : ''
|
1604
1586
|
eff = eff_bw ? eff_bw : ''
|
1605
1587
|
lmtu = mtu ? mtu : ''
|
1606
|
-
set_args_keys(state:
|
1588
|
+
set_args_keys(state: '', additive: additive, bw: bw, delay: delay,
|
1607
1589
|
rel: rel, eff: eff, mtu: lmtu)
|
1608
1590
|
config_set('route_map', 'set_metric', @set_args)
|
1609
1591
|
end
|
@@ -241,7 +241,7 @@ module Cisco
|
|
241
241
|
# Retrieve password hashes
|
242
242
|
hashed_pw = SnmpUser.auth_password('dummy_user', @engine_id)
|
243
243
|
if hashed_pw.nil?
|
244
|
-
fail "SNMP dummy user
|
244
|
+
fail "SNMP dummy user dummy_user #{@engine_id} was configured " \
|
245
245
|
"but password is missing?\n" \
|
246
246
|
+ @@node.get(command: 'show run snmp all')
|
247
247
|
end
|
@@ -289,7 +289,7 @@ module Cisco
|
|
289
289
|
dummyau = SnmpUser.auth_password('dummy_user', @engine_id)
|
290
290
|
hashed_pw = SnmpUser.priv_password('dummy_user', @engine_id)
|
291
291
|
if hashed_pw.nil?
|
292
|
-
fail "SNMP dummy user
|
292
|
+
fail "SNMP dummy user dummy_user #{@engine_id} was configured " \
|
293
293
|
"but password is missing?\n" \
|
294
294
|
+ @@node.get(command: 'show run snmp all')
|
295
295
|
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# Insert appropriate license here
|
2
|
+
require_relative 'node_util'
|
3
|
+
require_relative 'interface'
|
4
|
+
|
5
|
+
module Cisco
|
6
|
+
# node utils class for SPAN (switchport analyzer) sessions
|
7
|
+
class SpanSession < NodeUtil
|
8
|
+
attr_reader :session_id
|
9
|
+
|
10
|
+
def initialize(session_id, instantiate=true)
|
11
|
+
validate_args(session_id.to_i)
|
12
|
+
create if instantiate
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.sessions
|
16
|
+
hash = {}
|
17
|
+
all = config_get('span_session', 'all_sessions')
|
18
|
+
return hash if all.nil?
|
19
|
+
|
20
|
+
all.each do |id|
|
21
|
+
hash[id] = SpanSession.new(id, false)
|
22
|
+
end
|
23
|
+
hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate_args(session_id)
|
27
|
+
fail TypeError unless session_id.is_a?(Integer)
|
28
|
+
@session_id = session_id
|
29
|
+
end
|
30
|
+
|
31
|
+
def create
|
32
|
+
config_set('span_session', 'create', id: @session_id)
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
config_set('span_session', 'destroy', id: @session_id)
|
37
|
+
end
|
38
|
+
|
39
|
+
def description
|
40
|
+
config_get('span_session', 'description', id: @session_id)
|
41
|
+
end
|
42
|
+
|
43
|
+
def description=(val)
|
44
|
+
val = val.to_s
|
45
|
+
if val.empty?
|
46
|
+
config_set('span_session', 'description', id: @session_id,
|
47
|
+
state: 'no', description: '')
|
48
|
+
else
|
49
|
+
config_set('span_session', 'description', id: @session_id,
|
50
|
+
state: '', description: val)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def destination
|
55
|
+
config_get('span_session', 'destination', id: @session_id).downcase
|
56
|
+
end
|
57
|
+
|
58
|
+
def destination=(int)
|
59
|
+
# fail if int is not a valid interface
|
60
|
+
fail TypeError unless Interface.interfaces.key?(int.downcase)
|
61
|
+
config_set('span_session', 'destination', state: '', id: @session_id,
|
62
|
+
intf_name: int)
|
63
|
+
end
|
64
|
+
|
65
|
+
def session_id
|
66
|
+
config_get('span_session', 'session_id')
|
67
|
+
end
|
68
|
+
|
69
|
+
def session_id=(id)
|
70
|
+
fail TypeError unless id.is_a?(Integer)
|
71
|
+
config_set('span_session', 'session_id', id: id, state: '')
|
72
|
+
end
|
73
|
+
|
74
|
+
def shutdown
|
75
|
+
config_get('span_session', 'shutdown', id: @session_id)
|
76
|
+
end
|
77
|
+
|
78
|
+
def shutdown=(bool)
|
79
|
+
fail TypeError unless bool.is_a?(Boolean)
|
80
|
+
config_set('span_session', 'shutdown', id: @session_id, shutdown: bool)
|
81
|
+
end
|
82
|
+
|
83
|
+
def source_interfaces
|
84
|
+
ints = config_get('span_session', 'source_interfaces', id: @session_id)
|
85
|
+
intf = []
|
86
|
+
ints.each { |i| intf << i.map(&:downcase) }
|
87
|
+
intf
|
88
|
+
end
|
89
|
+
|
90
|
+
def source_interfaces=(sources)
|
91
|
+
fail TypeError unless sources.is_a?(Hash)
|
92
|
+
delta_hash = Utils.delta_add_remove(sources.to_a, source_interfaces.to_a,
|
93
|
+
:updates_not_allowed)
|
94
|
+
return if delta_hash.values.flatten.empty?
|
95
|
+
[:remove, :add].each do |action|
|
96
|
+
delta_hash[action].each do |name, dir|
|
97
|
+
state = (action == :add) ? '' : 'no'
|
98
|
+
config_set('span_session', 'source_interfaces', id: @session_id,
|
99
|
+
state: state, int_name: name, direction: dir)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def default_source_interfaces
|
105
|
+
config_get_default('span_session', 'source_interfaces')
|
106
|
+
end
|
107
|
+
|
108
|
+
def source_vlans
|
109
|
+
v = config_get('span_session', 'source_vlans', id: @session_id)
|
110
|
+
v.empty? ? v : [Utils.normalize_range_array(v[0]), v[1]]
|
111
|
+
end
|
112
|
+
|
113
|
+
def source_vlans=(sources)
|
114
|
+
fail TypeError unless sources.is_a?(Hash)
|
115
|
+
is = Utils.dash_range_to_elements(source_vlans[0]) unless
|
116
|
+
source_vlans.empty?
|
117
|
+
should = Utils.dash_range_to_elements(sources[:vlans])
|
118
|
+
direction = sources[:direction]
|
119
|
+
delta_hash = Utils.delta_add_remove(should, is)
|
120
|
+
[:add, :remove].each do |action|
|
121
|
+
delta_hash[action].each do |vlans|
|
122
|
+
state = (action == :add) ? '' : 'no'
|
123
|
+
config_set('span_session', 'source_vlans',
|
124
|
+
id: @session_id, state: state,
|
125
|
+
vlans: vlans, direction: direction)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def default_source_vlans
|
131
|
+
config_get_default('span_session', 'source_vlans')
|
132
|
+
end
|
133
|
+
|
134
|
+
def type
|
135
|
+
config_get('span_session', 'type', id: @session_id)
|
136
|
+
end
|
137
|
+
|
138
|
+
def type=(str)
|
139
|
+
valid_types = ['local', 'rspan', 'erspan-source']
|
140
|
+
fail TypeError unless valid_types.include?(str)
|
141
|
+
destroy # need to destroy session before changing type
|
142
|
+
if str.empty?
|
143
|
+
config_set('span_session', 'type', id: @session_id, type: 'local')
|
144
|
+
else
|
145
|
+
config_set('span_session', 'type', id: @session_id, type: str)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end # class
|
149
|
+
end # module
|
@@ -58,10 +58,23 @@ module Cisco
|
|
58
58
|
if image && uri
|
59
59
|
config_get('upgrade', 'image_version', image: image, uri: uri)
|
60
60
|
else
|
61
|
-
config_get('show_version', 'version')
|
61
|
+
version = config_get('show_version', 'version')
|
62
|
+
# show version displays version differently for release and
|
63
|
+
# development builds.
|
64
|
+
# Eg: release build
|
65
|
+
# NXOS: version 7.0(3)I4(2)
|
66
|
+
# Eg: development build
|
67
|
+
# NXOS: version 7.0(3)IFD6(1) [build 7.0(3)IGD7(0.65)]
|
68
|
+
return version unless version[/build\s+\S+/]
|
69
|
+
version.split(' ')[-1].split(']')[0]
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
73
|
+
# Return the nxos image installed on the device
|
74
|
+
def self.package
|
75
|
+
config_get('show_version', 'system_image')
|
76
|
+
end
|
77
|
+
|
65
78
|
# Return true if box is online and config mode is ready to be used
|
66
79
|
def self.box_online?
|
67
80
|
output = config_set('upgrade', 'is_box_online')
|
@@ -85,32 +98,23 @@ module Cisco
|
|
85
98
|
end
|
86
99
|
|
87
100
|
# Attempts to upgrade the device to 'image'
|
88
|
-
def self.upgrade(
|
101
|
+
def self.upgrade(image, uri='bootflash:', del_boot=false,
|
89
102
|
force_all=false)
|
90
|
-
# Only 'bootflash:' is a supported URI. Fail otherwise.
|
91
|
-
fail "The Uri #{uri} is not supported" unless uri == 'bootflash:'
|
92
|
-
# IMPORTANT - Check if version of image equals the version provided.
|
93
|
-
# This is to avoid entering a loop with the Programmability Agent
|
94
|
-
# continuously trying to reload the device if versions don't match.
|
95
|
-
image_ver = image_version(image, uri)
|
96
|
-
err_str = "Version Mismatch.\n
|
97
|
-
The version of the image:#{image_ver}\n
|
98
|
-
The version provided:#{version}\n
|
99
|
-
Aborting upgrade."
|
100
|
-
fail err_str unless image_ver.to_s.strip == version.to_s.strip
|
101
103
|
delete_boot(uri) if del_boot
|
102
104
|
force_all ? upgrade_str = 'upgrade_force' : upgrade_str = 'upgrade'
|
103
105
|
begin
|
104
106
|
Cisco::Logger.debug("Upgrading to version: #{image}")
|
105
107
|
config_set('upgrade', upgrade_str, image: image, uri: uri)
|
106
|
-
rescue Cisco::RequestFailed
|
108
|
+
rescue Cisco::RequestFailed, Cisco::CliError => e1
|
109
|
+
# raise if install command failed
|
110
|
+
raise e1 if e1.class == Cisco::CliError
|
107
111
|
# Catch 'Backend Processing Error'. Install continues inspite of the
|
108
112
|
# error thrown. Resend install command and expect a CliError.
|
109
113
|
begin
|
110
114
|
config_set('upgrade', upgrade_str, image: image, uri: uri)
|
111
|
-
rescue Cisco::CliError =>
|
112
|
-
raise
|
113
|
-
|
115
|
+
rescue Cisco::CliError => e2
|
116
|
+
raise e2 unless
|
117
|
+
e2.message.include?('Another install procedure may be in progress')
|
114
118
|
end
|
115
119
|
end
|
116
120
|
end
|