lenovo-rbapi 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +84 -84
- data/lib/cnos-rbapi.rb +19 -11
- data/lib/cnos-rbapi/arp.rb +16 -17
- data/lib/cnos-rbapi/connect.rb +12 -12
- data/lib/cnos-rbapi/igmp.rb +15 -16
- data/lib/cnos-rbapi/ip_intf.rb +14 -15
- data/lib/cnos-rbapi/lacp.rb +13 -14
- data/lib/cnos-rbapi/lag.rb +18 -19
- data/lib/cnos-rbapi/lldp.rb +19 -20
- data/lib/cnos-rbapi/mstp.rb +20 -21
- data/lib/cnos-rbapi/rest_utils.rb +10 -11
- data/lib/cnos-rbapi/stp.rb +14 -15
- data/lib/cnos-rbapi/system.rb +32 -33
- data/lib/cnos-rbapi/telemetry.rb +23 -24
- data/lib/cnos-rbapi/vlag.rb +24 -25
- data/lib/cnos-rbapi/vlan.rb +16 -17
- data/lib/cnos-rbapi/vlan_intf.rb +14 -15
- data/lib/cnos-rbapi/vrrp.rb +17 -18
- data/test/jupiter.yml +6 -0
- data/test/mars.yml +6 -0
- data/test/mytest.rb +3 -0
- data/test/neptune.yml +6 -0
- data/test/voyager.yml +6 -0
- metadata +14 -7
- data/lib/cnos-rbapi/valn_intf.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54690c92b60368321ef8dea8d70845c9fb38b7c4
|
4
|
+
data.tar.gz: 743b3d4a5e7bef4cce3b2b5ab502353a4e513053
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8f8174ac969fc525a083bc918ee926cc7afab35aa2bda4c8352e2e7e10cba56cf491894e180eaca26955ed777647aaa5c5fe7302ab2732b77ed30c134f97228
|
7
|
+
data.tar.gz: 9f3315057ce874ba0cf74b973eb19b99fd086c031d31121fbf7727291eb78b28936638062fc47c37e7541c392e4d56175656f33a885bdbddfa412a7fdb576558
|
data/README.md
CHANGED
@@ -1,84 +1,84 @@
|
|
1
|
-
# Lenovo CNOS Ruby API Library
|
2
|
-
|
3
|
-
## Overview
|
4
|
-
The Ruby Client for CNOS API provides a native Ruby implementation for programming
|
5
|
-
Lenovo CNOS network devices using Ruby. The Ruby client provides the ability to
|
6
|
-
build native applications in Ruby that can communicate with CNOS remotely over
|
7
|
-
a HTTP/S transport (off-box).
|
8
|
-
|
9
|
-
The Ruby API implemenation also provides an API layer for building native Ruby
|
10
|
-
objects that allow for configuration and management of Lenovo CNOS switches.
|
11
|
-
|
12
|
-
The library is freely provided to the open source community for building applications
|
13
|
-
using CNOS REST API infrastrcuture. Support is provided as best effort through
|
14
|
-
Github iusses.
|
15
|
-
|
16
|
-
## Requirements
|
17
|
-
* Lenovo CNOS 10.4 or later
|
18
|
-
* Ruby 2.2.3 or later
|
19
|
-
|
20
|
-
## CNOS Ruby APIs
|
21
|
-
The CNOS Ruby Client was designed to be easy to use and develop plugins or tools
|
22
|
-
that interface with the Lenovo CNOS switches.
|
23
|
-
|
24
|
-
### Using the API
|
25
|
-
#### Switch Configutation file
|
26
|
-
This configuration file is used to define the configuration options or model for switches (switch.yml or any xxx.yml)
|
27
|
-
|
28
|
-
##### transport (HTTP/HTTPs)
|
29
|
-
transport : 'http'
|
30
|
-
|
31
|
-
##### HTTP(s) port number (8090 - HTTP, 443 - HTTPs)
|
32
|
-
port : '8090'
|
33
|
-
|
34
|
-
##### Switch IP address
|
35
|
-
ip : 'switch ip address'
|
36
|
-
|
37
|
-
##### Switch Credentials
|
38
|
-
user : 'username'
|
39
|
-
|
40
|
-
password : 'password'
|
41
|
-
|
42
|
-
#### Creating connection and sending configurations
|
43
|
-
Below demonstrates a basic connection using the API. For more examples, please see the examples folder.
|
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
|
-
|
1
|
+
# Lenovo CNOS Ruby API Library
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
The Ruby Client for CNOS API provides a native Ruby implementation for programming
|
5
|
+
Lenovo CNOS network devices using Ruby. The Ruby client provides the ability to
|
6
|
+
build native applications in Ruby that can communicate with CNOS remotely over
|
7
|
+
a HTTP/S transport (off-box).
|
8
|
+
|
9
|
+
The Ruby API implemenation also provides an API layer for building native Ruby
|
10
|
+
objects that allow for configuration and management of Lenovo CNOS switches.
|
11
|
+
|
12
|
+
The library is freely provided to the open source community for building applications
|
13
|
+
using CNOS REST API infrastrcuture. Support is provided as best effort through
|
14
|
+
Github iusses.
|
15
|
+
|
16
|
+
## Requirements
|
17
|
+
* Lenovo CNOS 10.4 or later
|
18
|
+
* Ruby 2.2.3 or later
|
19
|
+
|
20
|
+
## CNOS Ruby APIs
|
21
|
+
The CNOS Ruby Client was designed to be easy to use and develop plugins or tools
|
22
|
+
that interface with the Lenovo CNOS switches.
|
23
|
+
|
24
|
+
### Using the API
|
25
|
+
#### Switch Configutation file
|
26
|
+
This configuration file is used to define the configuration options or model for switches (switch.yml or any xxx.yml)
|
27
|
+
|
28
|
+
##### transport (HTTP/HTTPs)
|
29
|
+
transport : 'http'
|
30
|
+
|
31
|
+
##### HTTP(s) port number (8090 - HTTP, 443 - HTTPs)
|
32
|
+
port : '8090'
|
33
|
+
|
34
|
+
##### Switch IP address
|
35
|
+
ip : 'switch ip address'
|
36
|
+
|
37
|
+
##### Switch Credentials
|
38
|
+
user : 'username'
|
39
|
+
|
40
|
+
password : 'password'
|
41
|
+
|
42
|
+
#### Creating connection and sending configurations
|
43
|
+
Below demonstrates a basic connection using the API. For more examples, please see the examples folder.
|
44
|
+
#import the libraries
|
45
|
+
|
46
|
+
require 'cnos-rbapi/connect'
|
47
|
+
|
48
|
+
require 'cnos-rbapi/vlan'
|
49
|
+
|
50
|
+
##### create connection to the node using the configuration file
|
51
|
+
conn = Connect.new(param)
|
52
|
+
|
53
|
+
where param is a dictionary formed either from the config file or hardcoded
|
54
|
+
with the following key value pairs
|
55
|
+
|
56
|
+
##### transport (HTTP/HTTPs)
|
57
|
+
transport => 'http'
|
58
|
+
|
59
|
+
##### HTTP(s) port number (8090 - HTTP, 443 - HTTPs)
|
60
|
+
port => '8090'
|
61
|
+
|
62
|
+
##### Switch IP address
|
63
|
+
ip => 'switch ip address'
|
64
|
+
|
65
|
+
##### Switch Credentials
|
66
|
+
user => 'username'
|
67
|
+
password => 'password'
|
68
|
+
|
69
|
+
##### Use VLAN APIs to retrieve VLAN information
|
70
|
+
Vlan.get_all_vlan(conn)
|
71
|
+
|
72
|
+
params = {"vlan_name" => "test", "vlan_id" => 10, "admin_state" => "up"}
|
73
|
+
|
74
|
+
##### Use VLAN APIs to create/update and delete VLANs
|
75
|
+
resp = Vlan.create_vlan(conn, params)
|
76
|
+
|
77
|
+
resp = Vlan.get_vlan_prop(conn, 10)
|
78
|
+
|
79
|
+
params = {"vlan_name" => "test", "admin_state" => "up"}
|
80
|
+
|
81
|
+
resp = Vlan.update_vlan(conn, 10, params)
|
82
|
+
|
83
|
+
Vlan.delete_vlan(conn, 10)
|
84
|
+
|
data/lib/cnos-rbapi.rb
CHANGED
@@ -1,16 +1,24 @@
|
|
1
1
|
##
|
2
|
-
### Copyright (
|
3
|
-
###
|
4
|
-
###
|
5
|
-
###
|
6
|
-
###
|
7
|
-
###
|
8
|
-
### The full text of the license may be found at
|
2
|
+
### Copyright (C) 2017 Lenovo, Inc.
|
3
|
+
### Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
### you may not use this file except in compliance with the License.
|
5
|
+
### You may obtain a copy of the License at
|
6
|
+
### http://www.apache.org/licenses/LICENSE-2.0
|
9
7
|
###
|
10
|
-
###
|
11
|
-
###
|
12
|
-
###
|
13
|
-
###
|
8
|
+
### Unless required by applicable law or agreed to in writing, software
|
9
|
+
### distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
### See the License for the specific language governing permissions and
|
12
|
+
### limitations under the License.
|
14
13
|
###
|
15
14
|
#
|
16
15
|
require 'cnos-rbapi/connect.rb'
|
16
|
+
|
17
|
+
module LenovoGem
|
18
|
+
class Cnos
|
19
|
+
def self.lenovo?
|
20
|
+
puts "YOU ARE AWESOME!!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/lib/cnos-rbapi/arp.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
##
|
2
|
-
## Copyright (
|
2
|
+
## Copyright (C) 2017 Lenovo, Inc.
|
3
|
+
## Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
## you may not use this file except in compliance with the License.
|
5
|
+
## You may obtain a copy of the License at
|
6
|
+
## http://www.apache.org/licenses/LICENSE-2.0
|
3
7
|
##
|
4
|
-
##
|
5
|
-
## under the
|
6
|
-
##
|
7
|
-
##
|
8
|
-
##
|
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.
|
8
|
+
## Unless required by applicable law or agreed to in writing, software
|
9
|
+
## distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
## See the License for the specific language governing permissions and
|
12
|
+
## limitations under the License.
|
14
13
|
##
|
15
14
|
require 'rest-client'
|
16
15
|
require 'json'
|
@@ -24,7 +23,7 @@ require_relative 'rest_utils'
|
|
24
23
|
##
|
25
24
|
|
26
25
|
class Arp
|
27
|
-
|
26
|
+
@@cfg = '/nos/api/cfg/arp'
|
28
27
|
|
29
28
|
# This API gets the ARP properties of the system.
|
30
29
|
#
|
@@ -34,7 +33,7 @@ class Arp
|
|
34
33
|
#
|
35
34
|
# return: JSON response
|
36
35
|
def self.get_arp_sys_prop(conn)
|
37
|
-
url = form_url(conn,
|
36
|
+
url = form_url(conn, @@cfg)
|
38
37
|
hdr = form_hdr(conn)
|
39
38
|
Rest.get(conn, url, hdr)
|
40
39
|
end
|
@@ -47,7 +46,7 @@ class Arp
|
|
47
46
|
#
|
48
47
|
# return: JSON response
|
49
48
|
def self.get_arp_prop_all(conn)
|
50
|
-
url = form_url(conn,
|
49
|
+
url = form_url(conn, @@cfg + '_interface')
|
51
50
|
hdr = form_hdr(conn)
|
52
51
|
Rest.get(conn, url, hdr)
|
53
52
|
end
|
@@ -66,7 +65,7 @@ class Arp
|
|
66
65
|
#
|
67
66
|
# return: JSON response
|
68
67
|
def self.set_arp_sys_prop(conn, params)
|
69
|
-
url = form_url(conn,
|
68
|
+
url = form_url(conn, @@cfg)
|
70
69
|
hdr = form_hdr(conn)
|
71
70
|
params = params.to_json
|
72
71
|
Rest.put(conn, url, hdr, params)
|
@@ -82,7 +81,7 @@ class Arp
|
|
82
81
|
def self.get_arp_intf_prop(conn, intf)
|
83
82
|
temp = intf.dup
|
84
83
|
temp.sub! '/', '%2F'
|
85
|
-
url = form_url(conn,
|
84
|
+
url = form_url(conn, @@cfg + '_interface/' + temp)
|
86
85
|
hdr = form_hdr(conn)
|
87
86
|
Rest.get(conn, url, hdr)
|
88
87
|
end
|
@@ -105,7 +104,7 @@ class Arp
|
|
105
104
|
def self.set_arp_intf_prop(conn, intf, params)
|
106
105
|
temp = intf.dup
|
107
106
|
temp.sub! '/', '%2F'
|
108
|
-
url = form_url(conn,
|
107
|
+
url = form_url(conn, @@cfg + '_interface/' + temp)
|
109
108
|
hdr = form_hdr(conn)
|
110
109
|
params = params.to_json
|
111
110
|
Rest.put(conn, url, hdr, params)
|
data/lib/cnos-rbapi/connect.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
##
|
2
|
-
## Copyright (
|
2
|
+
## Copyright (C) 2017 Lenovo, Inc.
|
3
|
+
## Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
## you may not use this file except in compliance with the License.
|
5
|
+
## You may obtain a copy of the License at
|
6
|
+
## http://www.apache.org/licenses/LICENSE-2.0
|
3
7
|
##
|
4
|
-
##
|
5
|
-
## under the
|
6
|
-
##
|
7
|
-
##
|
8
|
-
##
|
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.
|
8
|
+
## Unless required by applicable law or agreed to in writing, software
|
9
|
+
## distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
## See the License for the specific language governing permissions and
|
12
|
+
## limitations under the License.
|
14
13
|
##
|
15
14
|
require 'rest-client'
|
16
15
|
require 'yaml'
|
@@ -42,7 +41,8 @@ class Connect
|
|
42
41
|
# file :config file
|
43
42
|
#
|
44
43
|
# return: Connect object
|
45
|
-
def initialize(
|
44
|
+
def initialize(file)
|
45
|
+
params = YAML.load_file(file)
|
46
46
|
@transport = params['transport']
|
47
47
|
@port = params['port']
|
48
48
|
@ip = params['ip']
|
data/lib/cnos-rbapi/igmp.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
##
|
2
|
-
## Copyright (
|
2
|
+
## Copyright (C) 2017 Lenovo, Inc.
|
3
|
+
## Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
## you may not use this file except in compliance with the License.
|
5
|
+
## You may obtain a copy of the License at
|
6
|
+
## http://www.apache.org/licenses/LICENSE-2.0
|
3
7
|
##
|
4
|
-
##
|
5
|
-
## under the
|
6
|
-
##
|
7
|
-
##
|
8
|
-
##
|
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.
|
8
|
+
## Unless required by applicable law or agreed to in writing, software
|
9
|
+
## distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
## See the License for the specific language governing permissions and
|
12
|
+
## limitations under the License.
|
14
13
|
##
|
15
14
|
require 'rest-client'
|
16
15
|
require 'json'
|
@@ -24,7 +23,7 @@ require_relative 'rest_utils'
|
|
24
23
|
## on the node. This class presents an abstraction
|
25
24
|
##
|
26
25
|
class Igmp
|
27
|
-
|
26
|
+
@@cfg = '/nos/api/cfg/igmp'
|
28
27
|
|
29
28
|
# This API gets IGMP Snooping properties of the system.
|
30
29
|
#
|
@@ -34,7 +33,7 @@ class Igmp
|
|
34
33
|
#
|
35
34
|
# return: JSON response
|
36
35
|
def self.get_igmp_snoop_prop(conn)
|
37
|
-
url = form_url(conn,
|
36
|
+
url = form_url(conn, @@cfg + '/snoop')
|
38
37
|
hdr = form_hdr(conn)
|
39
38
|
Rest.get(conn, url, hdr)
|
40
39
|
end
|
@@ -59,7 +58,7 @@ class Igmp
|
|
59
58
|
#
|
60
59
|
# return: JSON response
|
61
60
|
def self.set_igmp_snoop_prop(conn, params)
|
62
|
-
url = form_url(conn,
|
61
|
+
url = form_url(conn, @@cfg + '/snoop')
|
63
62
|
hdr = form_hdr(conn)
|
64
63
|
params = params.to_json
|
65
64
|
Rest.put(conn, url, hdr, params)
|
@@ -74,7 +73,7 @@ class Igmp
|
|
74
73
|
#
|
75
74
|
# return: JSON response
|
76
75
|
def self.get_igmp_vlan_prop(conn, vlan_id)
|
77
|
-
temp =
|
76
|
+
temp = @@cfg.dup
|
78
77
|
temp.sub! 'igmp', 'mc_vlan/' + vlan_id.to_s
|
79
78
|
url = form_url(conn, temp)
|
80
79
|
hdr = form_hdr(conn)
|
@@ -107,7 +106,7 @@ class Igmp
|
|
107
106
|
#
|
108
107
|
# return: JSON response
|
109
108
|
def self.set_igmp_vlan_prop(conn, vlan_id, params)
|
110
|
-
temp =
|
109
|
+
temp = @@cfg.dup
|
111
110
|
temp.sub! 'igmp', 'mc_vlan/' + vlan_id.to_s
|
112
111
|
url = form_url(conn, temp)
|
113
112
|
hdr = form_hdr(conn)
|
data/lib/cnos-rbapi/ip_intf.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
##
|
2
|
-
## Copyright (
|
2
|
+
## Copyright (C) 2017 Lenovo, Inc.
|
3
|
+
## Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
## you may not use this file except in compliance with the License.
|
5
|
+
## You may obtain a copy of the License at
|
6
|
+
## http://www.apache.org/licenses/LICENSE-2.0
|
3
7
|
##
|
4
|
-
##
|
5
|
-
## under the
|
6
|
-
##
|
7
|
-
##
|
8
|
-
##
|
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.
|
8
|
+
## Unless required by applicable law or agreed to in writing, software
|
9
|
+
## distributed under the License is distributed on an "AS IS" BASIS,
|
10
|
+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
11
|
+
## See the License for the specific language governing permissions and
|
12
|
+
## limitations under the License.
|
14
13
|
##
|
15
14
|
require 'rest-client'
|
16
15
|
require 'json'
|
@@ -24,7 +23,7 @@ require_relative 'rest_utils'
|
|
24
23
|
##
|
25
24
|
|
26
25
|
class Ipintf
|
27
|
-
|
26
|
+
@@cfg = '/nos/api/cfg/ip_interface'
|
28
27
|
# This API gets the IP properties of all interface.
|
29
28
|
#
|
30
29
|
#
|
@@ -33,7 +32,7 @@ class Ipintf
|
|
33
32
|
#
|
34
33
|
# return: JSON response
|
35
34
|
def self.get_ip_prop_all(conn)
|
36
|
-
url = form_url(conn,
|
35
|
+
url = form_url(conn, @@cfg)
|
37
36
|
hdr = form_hdr(conn)
|
38
37
|
Rest.get(conn, url, hdr)
|
39
38
|
end
|
@@ -49,7 +48,7 @@ class Ipintf
|
|
49
48
|
def self.get_ip_prop_intf(conn, intf)
|
50
49
|
temp = intf.dup
|
51
50
|
temp.sub! '/', '%2F'
|
52
|
-
url = form_url(conn,
|
51
|
+
url = form_url(conn, @@cfg + '/' + temp)
|
53
52
|
hdr = form_hdr(conn)
|
54
53
|
Rest.get(conn, url, hdr)
|
55
54
|
end
|
@@ -84,7 +83,7 @@ class Ipintf
|
|
84
83
|
def self.update_ip_prop_intf(conn, intf, params)
|
85
84
|
temp = intf.dup
|
86
85
|
temp.sub! '/', '%2F'
|
87
|
-
url = form_url(conn,
|
86
|
+
url = form_url(conn, @@cfg + '/' + temp)
|
88
87
|
hdr = form_hdr(conn)
|
89
88
|
params = params.to_json
|
90
89
|
Rest.put(conn, url, hdr, params)
|