aviz-sonic-rbapi 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2019, Aviz Networks. All rights reserved.
3
+ #
4
+ # This program and the accompanying materials are licensed and made available
5
+ # under the terms and conditions of the 3-clause BSD License that accompanies
6
+ # this distribution.
7
+ #
8
+ # The full text of the license may be found at
9
+ #
10
+ # https://opensource.org/licenses/BSD-3-Clause
11
+ #
12
+ # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
+ require 'rest-client'
15
+ require 'json'
16
+ require_relative 'connect'
17
+ require_relative 'rest_utils'
18
+
19
+ # The Devenvs class provides a class implementation and methods for getting
20
+ # device environment details. This class presents an abstraction
21
+
22
+ class Devenvs
23
+ @devenvs_cfg = '/api/devenvs'
24
+
25
+ # This API gets the device environment details
26
+ #
27
+ # Request URL: http://IP-ADDR:REST-PORT/api/devenvs
28
+ #
29
+ # @param conn [Class] Connect object to the node
30
+ #
31
+ # @return [RestClient::Request] Rest output from SONIC in JSON format as below
32
+ # {
33
+ # "Fans": {"fan1": "rpm", "fan2": "rpm"}
34
+ # “Temperature”:{ },
35
+ # “Power”:{ “name”:””, “status”:””},
36
+ # “Platform”:{ “Platform Name”:””, “ONIE version”: “”, “CRC-32”:””}
37
+ # }
38
+ def self.get_devenvs_data(conn)
39
+ url = form_url(conn, @devenvs_cfg)
40
+ hdr = form_hdr(conn)
41
+ Rest.get(conn, url, hdr)
42
+ end
43
+ end
@@ -0,0 +1,174 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2019, Aviz Networks. All rights reserved.
3
+ #
4
+ # This program and the accompanying materials are licensed and made available
5
+ # under the terms and conditions of the 3-clause BSD License that accompanies
6
+ # this distribution.
7
+ #
8
+ # The full text of the license may be found at
9
+ #
10
+ # https://opensource.org/licenses/BSD-3-Clause
11
+ #
12
+ # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
+ require 'rest-client'
15
+ require 'json'
16
+ require_relative 'connect'
17
+ require_relative 'rest_utils'
18
+
19
+ # The Interface class provides a class implementation and methods for managing the Interfaces
20
+ # on the node. This class presents an abstraction
21
+
22
+ class Interfaces
23
+ @interface_cfg = '/api/interfaces/cfgs'
24
+ @interface_info = '/api/interfaces/info'
25
+ @interface_stats = '/api/interfaces/info/stats'
26
+ @interface_transceiver = '/api/interfaces/transceivers'
27
+
28
+ # This API get the interface information.
29
+ #
30
+ # Request URL: http://IP-ADDR:REST-PORT/api/interfaces/info/Ethernet0
31
+ # http://IP-ADDR:REST-PORT/api/interfaces/info
32
+ #
33
+ # @param conn [Class] Connect object to the node
34
+ # @param interface [String] Interface Name
35
+ #
36
+ # @return [RestClient::Request] Rest output from SONIC in JSON format
37
+ # {
38
+ # "InterfaceName": Ethernet0 {
39
+ # "lanes": "",
40
+ # "alias": "",
41
+ # "admin_status": "up or down",
42
+ # "oper_status": "up or down",
43
+ # "speed": "",
44
+ # "transceiver": ""
45
+ # }
46
+ # }
47
+ def self.get_interface_info(conn, interface=nil)
48
+ if interface == nil
49
+ url = form_url(conn, @interface_info)
50
+ else
51
+ url = form_url(conn, @interface_info + '/' + interface.to_s)
52
+ end
53
+ hdr = form_hdr(conn)
54
+ Rest.get(conn, url, hdr)
55
+ end
56
+
57
+ # This API get the interface statistics.
58
+ #
59
+ # Request URL: http://IP-ADDR:REST-PORT/api/interfaces/info/stats/Ethernet0
60
+ # http://IP-ADDR:REST-PORT/api/interfaces/info/stats
61
+ #
62
+ # @param conn [Class] Connect object to the node
63
+ # @param interface [String] Interface Name
64
+ #
65
+ # @return [RestClient::Request] Rest output from SONIC in JSON format
66
+ # {
67
+ # "collected_time": "03/20/2019, 18:53:05",
68
+ # "Ethernet120": {
69
+ # "IF_IN_OCTETS": 0,
70
+ # "IF_IN_UCAST_PKTS": 0,
71
+ # "IF_IN_NON_UCAST_PKTS": 0,
72
+ # "IF_IN_DISCARDS": 0,
73
+ # "IF_IN_ERRORS": 0,
74
+ # ...
75
+ # }
76
+ # }
77
+ def self.get_interface_stats(conn, interface=nil)
78
+ if interface == nil
79
+ url = form_url(conn, @interface_stats)
80
+ else
81
+ url = form_url(conn, @interface_stats + '/' + interface.to_s)
82
+ end
83
+ hdr = form_hdr(conn)
84
+ Rest.get(conn, url, hdr)
85
+ end
86
+
87
+ # This API get the interface transceiver information.
88
+ #
89
+ # Request URL: http://IP-ADDR:REST-PORT/api/interfaces/transceivers/Ethernet0
90
+ # http://IP-ADDR:REST-PORT/api/interfaces/transceivers
91
+ #
92
+ # @param conn [Class] Connect object to the node
93
+ # @param interface [String] Interface Name
94
+ #
95
+ # @return [RestClient::Request] Rest output from SONIC in JSON format
96
+ # {
97
+ # "Interface Name":
98
+ # {
99
+ # Present :”true or false”,
100
+ # Encoding: “’,
101
+ # Length Cable Assembly(m): ,
102
+ # Specification compliance: “”
103
+ # Vendor Date Code(YYYY-MM-DD Lot): “”
104
+ # Vendor Name: “”
105
+ # Vendor OUI: “”
106
+ # Vendor PN: “”
107
+ # Vendor Rev: “”
108
+ # Vendor SN: “”
109
+ # }
110
+ # }
111
+ def self.get_interface_transceivers(conn, interface=nil)
112
+ if interface == nil
113
+ url = form_url(conn, @interface_transceiver)
114
+ else
115
+ url = form_url(conn, @interface_transceiver + '/' + interface.to_s)
116
+ end
117
+ hdr = form_hdr(conn)
118
+ Rest.get(conn, url, hdr)
119
+ end
120
+
121
+ # This API updates properties of a interface.
122
+ #
123
+ # Request URL: http://IP-ADDR:REST-PORT/api/interfaces/cfgs/Ethernet0
124
+ # payload format of key-value pairs
125
+ # {
126
+ # "fec": "none",
127
+ # "mtu": "9100",
128
+ # "speed": "100000",
129
+ # "admin_status": "up",
130
+ # }
131
+ #
132
+ # @param conn [Class] Connect object to the node
133
+ # @param interface [String] Interface Name
134
+ # @param fec {String] Forwarding error correction setting(optional). Valid Values: "none", "rs", "fc"
135
+ # @param mtu [Integer] Maximum transmission unit (optional)
136
+ # @param speed [Integer] Interface's speed in Mbps (optional)
137
+ # @param admin_status [String] Admin status of the interface (mandatory). Valid Values: "up" or "down"
138
+ #
139
+ # @return [RestClient::Request] Rest output from SONIC in JSON format
140
+ def self.update_interface_cfg(conn, interface, fec="none", mtu=9100, speed=100000, admin_status="up")
141
+ url = form_url(conn, @interface_cfg + '/' + interface.to_s)
142
+ hdr = form_hdr(conn)
143
+ params = {"fec": fec, "mtu": mtu, "speed": speed, "admin_status": admin_status}
144
+ params = params.to_json
145
+ Rest.post(conn, url, hdr, params)
146
+ end
147
+
148
+ # This API get the configuration of particular or all interface.
149
+ #
150
+ # Request URL: http://IP-ADDR:REST-PORT/api/interfaces/cfgs/Ethernet0
151
+ #
152
+ # @param conn [Class] Connect object to the node
153
+ # @param interface [String] Interface Name or nil
154
+ #
155
+ # @return [RestClient::Request] Rest output from SONIC in JSON format as below
156
+ # {
157
+ # "interface": "<interfaceid>",
158
+ # "alias": "hundredGigE1/1"
159
+ # "fec": "none",
160
+ # "speed": "100000",
161
+ # "mtu": "9100",
162
+ # "lanes": "33,34,35,36",
163
+ # "admin_status": "up",
164
+ # }
165
+ def self.get_interface_cfg(conn, interface=nil)
166
+ if (interface != nil)
167
+ url = form_url(conn, @interface_cfg + '/' + interface.to_s)
168
+ else
169
+ url = form_url(conn, @interface_cfg)
170
+ end
171
+ hdr = form_hdr(conn)
172
+ Rest.get(conn, url, hdr)
173
+ end
174
+ end
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2019, Aviz Networks. All rights reserved.
3
+ #
4
+ # This program and the accompanying materials are licensed and made available
5
+ # under the terms and conditions of the 3-clause BSD License that accompanies
6
+ # this distribution.
7
+ #
8
+ # The full text of the license may be found at
9
+ #
10
+ # https://opensource.org/licenses/BSD-3-Clause
11
+ #
12
+ # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
+ require 'rest-client'
15
+ require 'json'
16
+ require_relative 'connect'
17
+ require_relative 'rest_utils'
18
+
19
+ # The Ipintf class provides a class implementation and methods for managing the Ip Interfaces
20
+ # on the node. This class presents an abstraction
21
+
22
+ class Ipintf
23
+ @ip_cfg = '/api/ips/cfgs'
24
+
25
+ # This API gets the IP interface.
26
+ #
27
+ # Request URL: http://IP-ADDR:REST-PORT/api/ips/cfgs
28
+ #
29
+ # @param conn [Class] Connect object to the node
30
+ # @param intf_name [String] IP interface name as a string like Ethernet0, Vlan100, PortChannel20(optional)
31
+ #
32
+ # @return [RestClient::Request] Rest output from SONIC in JSON format
33
+ # {
34
+ # "IntfName": {
35
+ # "ipv4_addr ": "",
36
+ # "ipv4_prefix_len": "",
37
+ # "ipv6_addr ": "",
38
+ # "ipv6_prefix_len": "",
39
+ # “mtu”:
40
+ # “admin_status”:””
41
+ # },
42
+ # …………
43
+ # }
44
+ def self.get_ip_intf(conn, intf_name=nil)
45
+ if intf_name == nil
46
+ url = form_url(conn, @ip_cfg)
47
+ else
48
+ url = form_url(conn, @ip_cfg + '/' + intf_name)
49
+ end
50
+ hdr = form_hdr(conn)
51
+ Rest.get(conn, url, hdr)
52
+ end
53
+
54
+ # This API creates the IP interface.
55
+ #
56
+ # Request URL: http://IP-ADDR:REST-PORT/api/ips/cfgs
57
+ # payload format of key-value pairs
58
+ # {
59
+ # "inf_name": <inf_name>,
60
+ # "inf_name": <inf_name>,
61
+ # "ipv4_addr": <ipv4_addr>,
62
+ # "ipv4_prefix_len": <ipv4_prefix_len>,
63
+ # "ipv6_addr": <ipv6_addr>,
64
+ # "ipv6_prefix_len": <ipv6_prefix_len>,
65
+ # "gwaddr": <gwaddr>,
66
+ # "forced_routes": <forced_routes>
67
+ # }
68
+ #
69
+ # @param conn [Class] Connect object to the node
70
+ # @param intf [String] IP interface name like EthernetX, PortChannelXXX, VlanXXX, LoopbackX or eth0 for management interface
71
+ # @param ipv4_addr [String] IPv4 address
72
+ # @param ipv4_prefix_len [Integer] Prefix len for the IPv4 address. Valid Values: 0-32 for IPv4
73
+ # @param ipv6_addr [String] IPv6 address
74
+ # @param ipv6_prefix_len [Integer] Prefix len for the IPv6 address. Valid Values: 0-128 for IPv4
75
+ # @param gwaddr [String] Gateway addr for mgmt interface only (optional). Valid Values: Valid IPv4 or IPv6 addresses
76
+ # @param forced_routes [String] Routes for mgmt interface only (optional). Valid Values: A list of strings. Eg: ["10.10.10.0/24", "192.168.5.0/24"]
77
+ #
78
+ # @return [RestClient::Request] Rest output from SONIC in JSON format
79
+ def self.create_ip_intf(conn, intf, ipv4_addr=nil, ipv4_prefix_len=0, ipv6_addr=nil, ipv6_prefix_len=0, gwaddr=nil, forced_routes=nil)
80
+ url = form_url(conn, @ip_cfg + '/' + intf)
81
+ hdr = form_hdr(conn)
82
+ params = {"inf_name": intf}
83
+ if ipv4_addr != nil
84
+ p1 = {"ipv4_addr": ipv4_addr, "ipv4_prefix_len": ipv4_prefix_len}
85
+ params = params.merge(p1);
86
+ end
87
+ if ipv6_addr != nil
88
+ p2 = {"ipv6_addr": ipv6_addr, "ipv6_prefix_len": ipv6_prefix_len}
89
+ params = params.merge(p2);
90
+ end
91
+ if gwaddr != nil
92
+ p3 = {"gwaddr": gwaddr}
93
+ params = params.merge(p3);
94
+ end
95
+ if forced_routes != nil
96
+ p4 = {"forced_routes": forced_routes}
97
+ params = params.merge(p4);
98
+ end
99
+ params = params.to_json
100
+ Rest.post(conn, url, hdr, params)
101
+ end
102
+
103
+ # This API deletes the ip interface.
104
+ #
105
+ # Request URI: /api/ips/cfgs/inf_name?ip_addr=10.1.1.1&mask=24
106
+ #
107
+ # @param conn [Class] Connect object to the node
108
+ # @param intf_name [String] IP interface name as a string like Ethernet0, Vlan100, PortChannel20
109
+ # @param ip_addr [String] IP address of the interface is about to delete
110
+ # @param netmask [String] Net mask of the interface is about to delete
111
+ #
112
+ # @return [RestClient::Request] Rest output from SONIC in JSON format
113
+ def self.delete_ip_intf(conn, intf_name, ip_addr, netmask)
114
+ url = form_url(conn, @ip_cfg + '/' + intf_name + '?ip_addr=' + ip_addr + '&mask=' + netmask.to_s)
115
+ hdr = form_hdr(conn)
116
+ Rest.delete(conn, url, hdr)
117
+ end
118
+ end
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2019, Aviz Networks. All rights reserved.
3
+ #
4
+ # This program and the accompanying materials are licensed and made available
5
+ # under the terms and conditions of the 3-clause BSD License that accompanies
6
+ # this distribution.
7
+ #
8
+ # The full text of the license may be found at
9
+ #
10
+ # https://opensource.org/licenses/BSD-3-Clause
11
+ #
12
+ # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
+ require 'rest-client'
15
+ require 'json'
16
+ require_relative 'connect'
17
+ require_relative 'rest_utils'
18
+
19
+ # The Lldp class provides a class implementation and methods for managing LLdp
20
+ # on the node. This class presents an abstraction
21
+
22
+ class Lldp
23
+ @lldp_cfg = '/api/lldps/cfgs'
24
+ @lldp_info = '/api/lldps'
25
+
26
+ # This API gets LLDP information from the switch
27
+ #
28
+ # Request URL: http://IP-ADDR:REST-PORT/api/lldps/info/chassis: Get chassis (switch) detailed information
29
+ # http://IP-ADDR:REST-PORT/api/lldps/info/stats: Get statistics summary information
30
+ # http://IP-ADDR:REST-PORT/api/lldps/info/stats/Ethernet0: Get statistics information for a specific port
31
+ # http://IP-ADDR:REST-PORT/api/lldps/info/config: Get LLDP configuration
32
+ # http://IP-ADDR:REST-PORT/api/lldps/neighbors: Get LLDP neighbor information for all ports
33
+ # http://IP-ADDR:REST-PORT/api/lldps/info/neighbors/Ethernet0: Get LLDP neighbor information for a specific port
34
+ #
35
+ # @param conn [Class] Connect object to the node
36
+ # @param filter [String] LLDP info filter which holds the value chassis/stats/config/neighbors
37
+ # @param port_name [String] Port name
38
+ #
39
+ # @return [RestClient::Request] Rest output from SONIC in JSON format
40
+ def self.get_lldp_info(conn, filter, port_name=nil)
41
+ chassis_filter = "chassis"
42
+ stats_filter = "stats"
43
+ cfg_filter = "config"
44
+ neighbor_filter = "neighbors"
45
+
46
+ if filter == chassis_filter
47
+ url = form_url(conn, @lldp_info + '/' + chassis_filter)
48
+ elsif filter == stats_filter
49
+ if port_name == nil
50
+ url = form_url(conn, @lldp_info + '/' + stats_filter)
51
+ else
52
+ url = form_url(conn, @lldp_info + '/' + stats_filter + '/' + port_name)
53
+ end
54
+ elsif filter == cfg_filter
55
+ url = form_url(conn, @lldp_info + '/' + cfg_filter)
56
+ elsif filter == neighbor_filter
57
+ if port_name == nil
58
+ url = form_url(conn, @lldp_info + '/' + neighbor_filter)
59
+ else
60
+ url = form_url(conn, @lldp_info + '/' + neighbor_filter + '/' + port_name)
61
+ end
62
+ end
63
+ hdr = form_hdr(conn)
64
+ Rest.get(conn, url, hdr)
65
+ end
66
+
67
+ # This API updates the global LLDP config on the switch.
68
+ #
69
+ # Request URL: http://IP-ADDR:REST-PORT/api/lldps/cfgs
70
+ # payload format of key-value pairs
71
+ # {
72
+ # "tx_interval": <tx_interval>,
73
+ # "tx_hold": <tx_hold>,
74
+ # "admin_status": <admin_status>,
75
+ # "capabilities_ad": <cap_status>,
76
+ # "mgmt_addr_ad": <mgmt_status>,
77
+ # }
78
+ #
79
+ # @param conn [Class] Connect object to the node
80
+ # @param tx_interval [Integer] LLDP transmit delay in seconds (optional)
81
+ # @param tx_hold [Integer] LLDP transmit hold in seconds (optional)
82
+ # @param admin_status [String] LLDP admin status(mandatory). Valid values: tx-only, rx-only, rx-and-tx, disabled
83
+ # @param capabilities_ad [Boolean] Enable/disable capabilities advertisement (optional). Valid values: true, false
84
+ # @param mgmt_addr_ad [Boolean] Enable/disable management address advertisement (optional). Valid values: true, false
85
+ #
86
+ # @return [RestClient::Request] Rest output from SONIC in JSON format
87
+ def self.update_lldp_global_config(conn, tx_interval=0, tx_hold=0, admin_status='rx-and-tx', capabilities_ad='true', mgmt_addr_ad='false')
88
+ url = form_url(conn, @lldp_cfg)
89
+ hdr = form_hdr(conn)
90
+ params = {"tx_interval": tx_interval, "tx_hold": tx_hold, "admin_status": admin_status, "capabilities_ad": capabilities_ad, "mgmt_addr_ad": mgmt_addr_ad}
91
+ params = params.to_json
92
+ Rest.put(conn, url, hdr, params)
93
+ end
94
+
95
+ # This API updates the LLDP port configuration on the switch.
96
+ #
97
+ # Request URL: http://IP-ADDR:REST-PORT/api/lldps/cfgs/Ethernet0
98
+ # payload format of key-value pairs
99
+ # {
100
+ # "admin_status": <admin_status>,
101
+ # "mgmt_addr_ad": <mgmt_status>,
102
+ # }
103
+ #
104
+ # @param conn [Class] Connect object to the node
105
+ # @param port_name [String] Port Name
106
+ # @param admin_status [String] LLDP admin status (mandatory). Valid values: tx-only, rx-only, rx-and-tx, disabled
107
+ # @param mgmt_status [Boolean] Enable/disable management address advertisement (optional). Valid values: true, false
108
+ #
109
+ # @return [RestClient::Request] Rest output from SONIC in JSON format
110
+ def self.update_lldp_port_config(conn, port_name, admin_status='rx-and-tx', mgmt_status='false')
111
+ url = form_url(conn, @lldp_cfg + '/' + port_name)
112
+ hdr = form_hdr(conn)
113
+ params = {"admin_status": admin_status, "mgmt_addr_ad": mgmt_status}
114
+ params = params.to_json
115
+ Rest.put(conn, url, hdr, params)
116
+ end
117
+ end
118
+