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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 667259711ddfa036e529c429db4ae5fcf06a4574ffea0398e2d1edf0e9dc619c
4
- data.tar.gz: 5d11b22f8e97e64612ab04e0df18bbd4e6366e09f986199732c502121aa162cc
2
+ SHA1:
3
+ metadata.gz: 54690c92b60368321ef8dea8d70845c9fb38b7c4
4
+ data.tar.gz: 743b3d4a5e7bef4cce3b2b5ab502353a4e513053
5
5
  SHA512:
6
- metadata.gz: bbfb514565c1d94585d5d333e9f845d24e841774260e33163722d2213d7901ad5114fda216a0cd4e7a23d8d82f35281aa10bdcfd240f083f0dbab7df94dee601
7
- data.tar.gz: 7c55b018645c51a1a76f944eab648677c8cd4c8a6ca38bac9a4af9543a7853c2673711548987be4af3eb8e2754ad0d966fc5b393af66dffe63f7a107efb32a15
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
- #import the libraries
46
-
47
- require 'cnos-rbapi/connect'
48
-
49
- require 'cnos-rbapi/vlan'
50
-
51
- ##### create connection to the node using the configuration file
52
- conn = Connect.new(param)
53
-
54
- where param is a dictionary formed either from the config file or hardcoded
55
- with the following key value pairs
56
-
57
- ##### transport (HTTP/HTTPs)
58
- transport => 'http'
59
-
60
- ##### HTTP(s) port number (8090 - HTTP, 443 - HTTPs)
61
- port => '8090'  
62
-
63
- ##### Switch IP address
64
- ip => 'switch ip address'
65
-
66
- ##### Switch Credentials
67
- user => 'username'  
68
- password => 'password'
69
-
70
- ##### Use VLAN APIs to retrieve VLAN information
71
- Vlan.get_all_vlan(conn)
72
-
73
- params = {"vlan_name" => "test", "vlan_id" => 10, "admin_state" => "up"}
74
-
75
- ##### Use VLAN APIs to create/update and delete VLANs
76
- resp = Vlan.create_vlan(conn, params)
77
-
78
- resp = Vlan.get_vlan_prop(conn, 10)
79
-
80
- params = {"vlan_name" => "test", "admin_state" => "up"}
81
-
82
- resp = Vlan.update_vlan(conn, 10, params)
83
-
84
- Vlan.delete_vlan(conn, 10)
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 (c) 2017, Lenovo. 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
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
- ### 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
  #
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
+
@@ -1,16 +1,15 @@
1
1
  ##
2
- ## Copyright (c) 2017, Lenovo. All rights reserved.
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
- ## 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.
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
- @cfg = '/nos/api/cfg/arp'
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, @cfg)
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, @cfg + '_interface')
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, @cfg)
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, @cfg + '_interface/' + temp)
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, @cfg + '_interface/' + temp)
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)
@@ -1,16 +1,15 @@
1
1
  ##
2
- ## Copyright (c) 2017, Lenovo. All rights reserved.
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
- ## 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.
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(params)
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']
@@ -1,16 +1,15 @@
1
1
  ##
2
- ## Copyright (c) 2017, Lenovo. All rights reserved.
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
- ## 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.
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
- @cfg = '/nos/api/cfg/igmp'
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, @cfg + '/snoop')
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, @cfg + '/snoop')
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 = @cfg.dup
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 = @cfg.dup
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)
@@ -1,16 +1,15 @@
1
1
  ##
2
- ## Copyright (c) 2017, Lenovo. All rights reserved.
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
- ## 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.
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
- @cfg = '/nos/api/cfg/ip_interface'
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, @cfg)
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, @cfg + '/' + temp)
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, @cfg + '/' + temp)
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)