aviz-sonic-rbapi 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +29 -0
- data/README.md +68 -0
- data/doc_script +5 -0
- data/lib/sonic-rbapi.rb +17 -0
- data/lib/sonic-rbapi/bgp.rb +152 -0
- data/lib/sonic-rbapi/config.rb +113 -0
- data/lib/sonic-rbapi/connect.rb +98 -0
- data/lib/sonic-rbapi/devenvs.rb +43 -0
- data/lib/sonic-rbapi/interfaces.rb +174 -0
- data/lib/sonic-rbapi/ip.rb +118 -0
- data/lib/sonic-rbapi/lldp.rb +118 -0
- data/lib/sonic-rbapi/portchnl.rb +175 -0
- data/lib/sonic-rbapi/rest_utils.rb +134 -0
- data/lib/sonic-rbapi/system.rb +99 -0
- data/lib/sonic-rbapi/vlan.rb +176 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 933b03c781d2e73cddd22210463b9a1b8164c60384656c64d5c770d8dea46e8f
|
4
|
+
data.tar.gz: 51b8700bfa1fd2dfa53290239b34c044f4162ede4148da8795558ccc52955185
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7309fbbf5c4760038c52117526f4236daa92522b7de6a041670ccd21a33c60ffb3b42184a3eba9410610fb38fe50ab4d7b6497adb0e2f778a88602c9d95af6c8
|
7
|
+
data.tar.gz: 7226798b8350612dbaafb5ddecb80c883635dade13a031c5344779cc7ce570dc21e9111a2510be6c5c5f6b64392c774a207dc86f82ae38108b1533f498f09a58
|
data/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2019, Aviz Networks
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
* Neither the name of the copyright holder nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Aviz Networks AIMS SONIC Ruby API Library
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
The Ruby Client for Azure SONIC REST API provides a native Ruby implementation for programming
|
5
|
+
Aviz Networks SONIC network devices using AIMS. The Ruby client provides the ability to
|
6
|
+
build native applications in Ruby that can communicate with SONIC remotely over
|
7
|
+
a HTTP transport protocol.
|
8
|
+
|
9
|
+
The Ruby API implemenation also provides an API layer for building native Ruby
|
10
|
+
objects that allow for configuration and management of Aviz Networks SONIC switches using AIMS.
|
11
|
+
|
12
|
+
## Requirements
|
13
|
+
* Aviz Networks SONIC switches
|
14
|
+
* Ruby 2.2.3 or later
|
15
|
+
|
16
|
+
## SONIC Ruby APIs
|
17
|
+
The SONIC Ruby Client was designed to be easy to use and develop plugins or tools
|
18
|
+
that interface with the Aviz Networks SONIC switches.
|
19
|
+
|
20
|
+
### Using the API
|
21
|
+
See the below example for using the API. Also refer test/ directory for more details.
|
22
|
+
|
23
|
+
#### Switch Configuration file
|
24
|
+
This configuration file is used to define the configuration options or model for switches (switch.yml or any xxx.yml)
|
25
|
+
|
26
|
+
```yaml
|
27
|
+
protocol : 'http' # protocol (HTTP)
|
28
|
+
port : '8090' # HTTP(s) port number (8090 - HTTP)
|
29
|
+
ip : 'switch ip address' # Switch IP address
|
30
|
+
user : 'username' # Switch Credentials
|
31
|
+
password : 'password' #switch credentials
|
32
|
+
```
|
33
|
+
|
34
|
+
#### Creating connection and sending configurations
|
35
|
+
Below demonstrates a basic connection using the API. For more examples please see the examples folder
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
#### import the libraries
|
39
|
+
require 'sonic-rbapi/connect'
|
40
|
+
require 'sonic-rbapi/vlan'
|
41
|
+
|
42
|
+
##### create connection to the node using the configuration file
|
43
|
+
conn = Connect.new(param)
|
44
|
+
|
45
|
+
where param is a dictionary formed either from the config file or hardcoded
|
46
|
+
with the following key value pairs
|
47
|
+
|
48
|
+
protocol => 'http' # protocol (HTTP)
|
49
|
+
port => '8090' # HTTP(s) port number (8090 - HTTP)
|
50
|
+
ip => 'switch ip address' # Switch IP address
|
51
|
+
user => 'username' #Switch Credentials
|
52
|
+
password => 'password' #Switch Credentials
|
53
|
+
|
54
|
+
##### Use VLAN APIs to retrieve all VLAN information
|
55
|
+
Vlan.get_all_vlan(conn)
|
56
|
+
|
57
|
+
##### Use VLAN APIs to create VLANs
|
58
|
+
vlan_id = 10
|
59
|
+
dhcp_servers = ["10.10.10.1", "10.10.10.2"]
|
60
|
+
resp = Vlan.create_vlan(conn, vlan_id, dhcp_servers)
|
61
|
+
|
62
|
+
##### Use VLAN APIs to retrieve specific VLAN information
|
63
|
+
resp = Vlan.get_vlan(conn, 20)
|
64
|
+
|
65
|
+
##### Use VLAN APIs to delete VLANs
|
66
|
+
Vlan.delete_vlan(conn, 20)
|
67
|
+
```
|
68
|
+
|
data/doc_script
ADDED
data/lib/sonic-rbapi.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
##
|
3
|
+
### Copyright (c) 2019, Aviz Networks. All rights reserved.
|
4
|
+
###
|
5
|
+
### This program and the accompanying materials are licensed and made available
|
6
|
+
### under the terms and conditions of the 3-clause BSD License that accompanies
|
7
|
+
### this distribution.
|
8
|
+
###
|
9
|
+
### The full text of the license may be found at
|
10
|
+
###
|
11
|
+
### https://opensource.org/licenses/BSD-3-Clause
|
12
|
+
###
|
13
|
+
### THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
14
|
+
### WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
15
|
+
###
|
16
|
+
#
|
17
|
+
require_relative 'sonic-rbapi/connect.rb'
|
@@ -0,0 +1,152 @@
|
|
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 Bgp class provides a class implementation and methods for managing BGP
|
20
|
+
# on the node. This class presents an abstraction
|
21
|
+
|
22
|
+
class Bgp
|
23
|
+
@bgp_cfg = '/api/bgps/neighbors/cfgs'
|
24
|
+
@bgp_info = '/api/bgps/neighbors/info'
|
25
|
+
@bgp_global = '/api/bgps/globals'
|
26
|
+
|
27
|
+
# This API gets BGP information from the switch.
|
28
|
+
#
|
29
|
+
# Request URL: http://IP-ADDR:REST-PORT/api/bgps/neighbors/info/summary
|
30
|
+
# http://IP-ADDR:REST-PORT/api/bgps/neighbors/info
|
31
|
+
#
|
32
|
+
# @param conn [Class] Connect object to the node
|
33
|
+
# @param filter [String] BGP info filter which holds the value "summary" or None
|
34
|
+
#
|
35
|
+
# @return [RestClient::Request] Rest output from SONIC in JSON format as below
|
36
|
+
# {
|
37
|
+
# "192.168.10.2": {
|
38
|
+
# "rxMsg": "6036",
|
39
|
+
# "bgp_version": "4",
|
40
|
+
# "txMsg": "6042",
|
41
|
+
# "up_down_time": "01:57:08",
|
42
|
+
# "outQ": "0",
|
43
|
+
# "state_prefix": "Active",
|
44
|
+
# "tblVer": "0",
|
45
|
+
# "inQ": "0",
|
46
|
+
# "peer_asn": "63100"
|
47
|
+
# },
|
48
|
+
# }
|
49
|
+
def self.get_bgp_info(conn, filter=nil)
|
50
|
+
summary_filter = "summary"
|
51
|
+
|
52
|
+
if filter == summary_filter
|
53
|
+
url = form_url(conn, @bgp_info + '/' + summary_filter)
|
54
|
+
elsif filter == nil
|
55
|
+
url = form_url(conn, @bgp_info)
|
56
|
+
end
|
57
|
+
hdr = form_hdr(conn)
|
58
|
+
Rest.get(conn, url, hdr)
|
59
|
+
end
|
60
|
+
|
61
|
+
# This API updates the BGP global configuration on the switch.
|
62
|
+
#
|
63
|
+
# Request URL: http://IP-ADDR:REST-PORT/api/bgps/globals
|
64
|
+
# payload format of key-value pairs
|
65
|
+
# {
|
66
|
+
# "default_bgp_status": "up",
|
67
|
+
# "bgp_asn": 5000
|
68
|
+
# }
|
69
|
+
#
|
70
|
+
# @param conn [Class] Connect object to the node
|
71
|
+
# @param bgp_status [String] Default BGP neighbor status. Valid Values: "up" or "down"
|
72
|
+
# @param bgp_asn [Integer] Default BGP AS number
|
73
|
+
#
|
74
|
+
# @return [RestClient::Request] Rest output from SONIC in JSON format
|
75
|
+
def self.update_bgp_global_config(conn, bgp_status='up', bgp_asn)
|
76
|
+
url = form_url(conn, @bgp_global)
|
77
|
+
hdr = form_hdr(conn)
|
78
|
+
params = {"default_bgp_status": bgp_status, "bgp_asn": bgp_asn}
|
79
|
+
params = params.to_json
|
80
|
+
Rest.put(conn, url, hdr, params)
|
81
|
+
end
|
82
|
+
|
83
|
+
# This API creates a new BGP neighbor on the switch.
|
84
|
+
#
|
85
|
+
# Request URL: http://IP-ADDR:REST-PORT/api/bgps/neighbors/cfgs/10.10.10.10
|
86
|
+
# payload format of key-value pairs
|
87
|
+
# {
|
88
|
+
# "local_addr": local_ip,
|
89
|
+
# "neighbor_addr": neighbor_ip,
|
90
|
+
# "admin_status": status,
|
91
|
+
# "asn": asn,
|
92
|
+
# "holdtime": 180,
|
93
|
+
# "keepalive": 60
|
94
|
+
# }
|
95
|
+
#
|
96
|
+
# @param conn [Class] Connect object to the node
|
97
|
+
# @param neighbor_ip [String] BGP Neighbor IPv4 or IPv6 address
|
98
|
+
# @param local_addr [String] Local IPv4 or IPv6 address
|
99
|
+
# @param admin_status [String] admin status of the neighbor. Valid Values: "up" or "down"
|
100
|
+
# @param asn [Integer] BGP autonomous system number
|
101
|
+
# @param holdtime [Integer] holdtime timer
|
102
|
+
# @param keepalive [Integer] keep-alive timer
|
103
|
+
#
|
104
|
+
# @return [RestClient::Request] Rest output from SONIC in JSON format
|
105
|
+
def self.create_bgp_neighbor(conn, neighbor_ip, local_addr, admin_status='up', asn=0, holdtime=180, keepalive=60)
|
106
|
+
url = form_url(conn, @bgp_cfg + '/' + neighbor_ip)
|
107
|
+
hdr = form_hdr(conn)
|
108
|
+
params = {"local_addr": local_addr, "neighbor_addr": neighbor_ip, "admin_status": admin_status, "asn": asn, "holdtime": holdtime, "keepalive": keepalive}
|
109
|
+
params = params.to_json
|
110
|
+
Rest.put(conn, url, hdr, params)
|
111
|
+
end
|
112
|
+
|
113
|
+
# This API delete BGP neighbor on the switch.
|
114
|
+
#
|
115
|
+
# Request URL: http://IP-ADDR:REST-PORT/api/bgps/neighbors/cfgs/10.10.10.10
|
116
|
+
#
|
117
|
+
# @param conn [Class] Connect object to the node
|
118
|
+
# @param neighbor_ip [String] Neighbor peer address (IPv4 or IPv6)
|
119
|
+
#
|
120
|
+
# @return [RestClient::Request] Rest output from SONIC in JSON format
|
121
|
+
def self.delete_bgp_neighbor(conn, neighbor_ip)
|
122
|
+
url = form_url(conn, @bgp_cfg + '/' + neighbor_ip)
|
123
|
+
hdr = form_hdr(conn)
|
124
|
+
Rest.delete(conn, url, hdr)
|
125
|
+
end
|
126
|
+
|
127
|
+
# This API gets all BGP neighbors
|
128
|
+
#
|
129
|
+
# Request URL: http://IP-ADDR:REST-PORT/api/bgps/neighbors/cfgs
|
130
|
+
#
|
131
|
+
# @param conn [Class] Connect object to the node
|
132
|
+
#
|
133
|
+
# @return [RestClient::Request] Rest output from SONIC in JSON format as below
|
134
|
+
# {
|
135
|
+
# "10.0.0.19": {
|
136
|
+
# "asn": "65200",
|
137
|
+
# "keepalive": "60",
|
138
|
+
# "rrclient": "0",
|
139
|
+
# "holdtime": "180",
|
140
|
+
# "name": "AVI10T2",
|
141
|
+
# "local_addr": "10.0.0.18",
|
142
|
+
# "nhopself": "0"
|
143
|
+
# },
|
144
|
+
# ...
|
145
|
+
# }
|
146
|
+
def self.get_all_bgp_neighbors(conn)
|
147
|
+
url = form_url(conn, @bgp_cfg)
|
148
|
+
hdr = form_hdr(conn)
|
149
|
+
Rest.get(conn, url, hdr)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
@@ -0,0 +1,113 @@
|
|
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 Config class provides a class implementation and methods for managing the configs
|
20
|
+
# on the node. This class presents an abstraction
|
21
|
+
|
22
|
+
class Config
|
23
|
+
@config_cfg = '/api/configs'
|
24
|
+
|
25
|
+
# This API gets the switch configuration.
|
26
|
+
#
|
27
|
+
# Request URL: http://IP-ADDR:REST-PORT/api/configs?cfgblk=running
|
28
|
+
#
|
29
|
+
# @param conn [Class] Connect object to the node
|
30
|
+
# @param cfgblk [String] Configuration blocks. Valid values are "running" and "bootup"
|
31
|
+
#
|
32
|
+
# @return [RestClient::Request] Rest output from SONIC in JSON format as below
|
33
|
+
# {
|
34
|
+
# "PORTCHANNEL": {
|
35
|
+
# "PortChannel200": {
|
36
|
+
# "mtu": "9100",
|
37
|
+
# "admin_status": "up",
|
38
|
+
# "fallback": "true",
|
39
|
+
# "min_links": "2"
|
40
|
+
# }
|
41
|
+
# },
|
42
|
+
# "INTERFACE": {
|
43
|
+
# "Ethernet4|4.4.4.1/24": {},
|
44
|
+
# "Ethernet8|10.0.0.4/31": {}
|
45
|
+
# },
|
46
|
+
# ...
|
47
|
+
# }
|
48
|
+
def self.get_switch_config(conn, cfgblk)
|
49
|
+
url = form_url(conn, @config_cfg + '?cfgblk=' + cfgblk)
|
50
|
+
hdr = form_hdr(conn)
|
51
|
+
Rest.get(conn, url, hdr)
|
52
|
+
end
|
53
|
+
|
54
|
+
# This API configure the switch actions related to configurations.
|
55
|
+
#
|
56
|
+
# Request URL: http://IP-ADDR:REST-PORT/api/configs
|
57
|
+
# payload format of key-value pairs
|
58
|
+
# {
|
59
|
+
# "action": "config_save"
|
60
|
+
# "protocol": "tftp"
|
61
|
+
# "serverip": "",
|
62
|
+
# "config_file": "",
|
63
|
+
# "username": "",
|
64
|
+
# "passwd": "”,
|
65
|
+
# "port": <int>,
|
66
|
+
# }
|
67
|
+
#
|
68
|
+
# @param conn [Class] Connect object to the node
|
69
|
+
# @param action [String] Configuration actions
|
70
|
+
# Valid Values:
|
71
|
+
# - "config_save" to save running configuration to bootup configuration file (default).
|
72
|
+
# - "config_upload" Upload file from a server to startup configuration block.
|
73
|
+
# Server details can be obtained from the further parameters.
|
74
|
+
# @param protocol [String] Protocol to communicate which includes "tftp" or "scp" or "http"
|
75
|
+
# @param server_ip [String] Server ip address
|
76
|
+
# @param config_file [String] Configuration file
|
77
|
+
# @param username [String] Username to login the server
|
78
|
+
# @param password [String] Password for the server
|
79
|
+
# @param port [Integer] TCP port used by file transfer protocol
|
80
|
+
#
|
81
|
+
# @return [RestClient::Request] Rest output from SONIC in JSON format
|
82
|
+
def self.switch_config_action(conn, action="config_save", protocol=nil, server_ip=nil, config_file=nil, username=nil, password=nil, port=0)
|
83
|
+
url = form_url(conn, @config_cfg)
|
84
|
+
hdr = form_hdr(conn)
|
85
|
+
params = {"action": action}
|
86
|
+
if protocol != nil
|
87
|
+
p1 = {"protocol": protocol}
|
88
|
+
params = params.merge(p1)
|
89
|
+
end
|
90
|
+
if server_ip != nil
|
91
|
+
p1 = {"serverip": server_ip}
|
92
|
+
params = params.merge(p1)
|
93
|
+
end
|
94
|
+
if config_file != nil
|
95
|
+
p1 = {"config_file": config_file}
|
96
|
+
params = params.merge(p1)
|
97
|
+
end
|
98
|
+
if username != nil
|
99
|
+
p1 = {"username": username}
|
100
|
+
params = params.merge(p1)
|
101
|
+
end
|
102
|
+
if password != nil
|
103
|
+
p1 = {"passwd": password}
|
104
|
+
params = params.merge(p1)
|
105
|
+
end
|
106
|
+
if port != nil
|
107
|
+
p1 = {"port": port}
|
108
|
+
params = params.merge(p1)
|
109
|
+
end
|
110
|
+
params = params.to_json
|
111
|
+
Rest.post(conn, url, hdr, params)
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,98 @@
|
|
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 'yaml'
|
16
|
+
|
17
|
+
def form_hdr(conn)
|
18
|
+
hdr = {}
|
19
|
+
hdr['Accept'] = 'application/json'
|
20
|
+
hdr['Content-type'] = 'application/json'
|
21
|
+
return hdr
|
22
|
+
end
|
23
|
+
|
24
|
+
def form_url(conn, url)
|
25
|
+
url = conn.getProtocol + '://' + conn.getIpAddr + ':' + conn.getPort + url
|
26
|
+
return url
|
27
|
+
end
|
28
|
+
|
29
|
+
# The Connect class provides a class implementation and methods for establishing node connections and
|
30
|
+
# initializations. This class presents an abstraction
|
31
|
+
|
32
|
+
class Connect
|
33
|
+
|
34
|
+
# This function is used to initialise node paramters.
|
35
|
+
#
|
36
|
+
# @param params [Hash] Hash to hold the switch connection parameters
|
37
|
+
#
|
38
|
+
# @return None
|
39
|
+
def initialize(params)
|
40
|
+
@protocol = params['protocol']
|
41
|
+
@port = params['port']
|
42
|
+
@ip_addr = params['ip_addr']
|
43
|
+
@user = params['user']
|
44
|
+
@password = params['password']
|
45
|
+
if @protocol == 'http'
|
46
|
+
@url = @protocol + '://' + @ip_addr + ':' + @port
|
47
|
+
end
|
48
|
+
|
49
|
+
# https is not supported
|
50
|
+
# Need to get certificate from user and form ssl connection for https
|
51
|
+
|
52
|
+
@hdr = {}
|
53
|
+
@hdr['Accept'] = 'application/json'
|
54
|
+
@hdr['Content-type'] = 'application/json'
|
55
|
+
end
|
56
|
+
|
57
|
+
# This API returns Protocol protocol for the current node connection.
|
58
|
+
#
|
59
|
+
# @return [String] Protocol protocol
|
60
|
+
def getProtocol()
|
61
|
+
return @protocol
|
62
|
+
end
|
63
|
+
|
64
|
+
# This API returns REST Port for the current node connection.
|
65
|
+
#
|
66
|
+
# @return [String] REST Port
|
67
|
+
def getPort()
|
68
|
+
return @port
|
69
|
+
end
|
70
|
+
|
71
|
+
# This API returns IP for the current node connection.
|
72
|
+
#
|
73
|
+
# @return [String] Node IP Address
|
74
|
+
def getIpAddr()
|
75
|
+
return @ip_addr
|
76
|
+
end
|
77
|
+
|
78
|
+
# This API returns User for the current node connection.
|
79
|
+
#
|
80
|
+
# @return [String] User name credentials
|
81
|
+
def getUser()
|
82
|
+
return @user
|
83
|
+
end
|
84
|
+
|
85
|
+
# This API returns Password for the current node connection.
|
86
|
+
#
|
87
|
+
# @return [String] Password credentials
|
88
|
+
def getPassword()
|
89
|
+
return @password
|
90
|
+
end
|
91
|
+
|
92
|
+
# This API returns Header Info for the current node connection.
|
93
|
+
#
|
94
|
+
# @return [String] REST Header
|
95
|
+
def getHdr()
|
96
|
+
return @hdr
|
97
|
+
end
|
98
|
+
end
|