rubybvc 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/lib/controller/controller.rb +445 -0
  3. data/lib/controller/netconf_node.rb +55 -0
  4. data/lib/controller/node.rb +41 -0
  5. data/lib/controller/openflow_node.rb +33 -0
  6. data/lib/netconfdev/vrouter/dataplane_firewall.rb +53 -0
  7. data/lib/netconfdev/vrouter/firewall.rb +44 -0
  8. data/lib/netconfdev/vrouter/rule.rb +53 -0
  9. data/lib/netconfdev/vrouter/rules.rb +53 -0
  10. data/lib/netconfdev/vrouter/vrouter5600.rb +242 -0
  11. data/lib/openflowdev/action_output.rb +71 -0
  12. data/lib/openflowdev/actions/action.rb +39 -0
  13. data/lib/openflowdev/actions/actions.rb +63 -0
  14. data/lib/openflowdev/actions/copy_ttl_inwards_action.rb +39 -0
  15. data/lib/openflowdev/actions/copy_ttl_outwards_action.rb +39 -0
  16. data/lib/openflowdev/actions/dec_mpls_ttl_action.rb +39 -0
  17. data/lib/openflowdev/actions/dec_nw_ttl_action.rb +39 -0
  18. data/lib/openflowdev/actions/drop_action.rb +37 -0
  19. data/lib/openflowdev/actions/flood_action.rb +39 -0
  20. data/lib/openflowdev/actions/flood_all_action.rb +39 -0
  21. data/lib/openflowdev/actions/group_action.rb +44 -0
  22. data/lib/openflowdev/actions/hw_path_action.rb +39 -0
  23. data/lib/openflowdev/actions/loopback_action.rb +39 -0
  24. data/lib/openflowdev/actions/output_action.rb +43 -0
  25. data/lib/openflowdev/actions/pop_mpls_header_action.rb +41 -0
  26. data/lib/openflowdev/actions/pop_pbb_header_action.rb +39 -0
  27. data/lib/openflowdev/actions/pop_vlan_header_action.rb +39 -0
  28. data/lib/openflowdev/actions/push_mpls_header_action.rb +41 -0
  29. data/lib/openflowdev/actions/push_pbb_header_action.rb +40 -0
  30. data/lib/openflowdev/actions/push_vlan_header_action.rb +46 -0
  31. data/lib/openflowdev/actions/set_dl_dst_action.rb +41 -0
  32. data/lib/openflowdev/actions/set_dl_src_action.rb +41 -0
  33. data/lib/openflowdev/actions/set_field_action.rb +43 -0
  34. data/lib/openflowdev/actions/set_mpls_ttl_action.rb +41 -0
  35. data/lib/openflowdev/actions/set_nw_dst_action.rb +41 -0
  36. data/lib/openflowdev/actions/set_nw_src_action.rb +41 -0
  37. data/lib/openflowdev/actions/set_nw_ttl_action.rb +41 -0
  38. data/lib/openflowdev/actions/set_queue_action.rb +44 -0
  39. data/lib/openflowdev/actions/set_tp_dst_action.rb +41 -0
  40. data/lib/openflowdev/actions/set_tp_src_action.rb +41 -0
  41. data/lib/openflowdev/actions/set_vlan_cfi_action.rb +41 -0
  42. data/lib/openflowdev/actions/set_vlan_id_action.rb +41 -0
  43. data/lib/openflowdev/actions/set_vlan_pcp_action.rb +41 -0
  44. data/lib/openflowdev/actions/strip_vlan_action.rb +35 -0
  45. data/lib/openflowdev/actions/sw_path_action.rb +39 -0
  46. data/lib/openflowdev/flow_entry.rb +91 -0
  47. data/lib/openflowdev/instruction.rb +53 -0
  48. data/lib/openflowdev/match.rb +121 -0
  49. data/lib/openflowdev/of_switch.rb +374 -0
  50. data/lib/rubybvc.rb +52 -0
  51. data/lib/utils/hash_with_compact.rb +46 -0
  52. data/lib/utils/netconf_response.rb +67 -0
  53. data/lib/utils/netconf_response_status.rb +41 -0
  54. data/lib/utils/rest_agent.rb +103 -0
  55. data/lib/utils/utilities.rb +51 -0
  56. metadata +111 -0
@@ -0,0 +1,67 @@
1
+ # Copyright (c) 2015, BROCADE COMMUNICATIONS SYSTEMS, INC
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # 3. Neither the name of the copyright holder nor the names of its contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29
+ # THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ class NetconfResponse
32
+ require 'utils/netconf_response_status'
33
+
34
+ attr_accessor :status
35
+ attr_accessor :body
36
+
37
+ def initialize(netconf_response_status = nil, json_body = nil)
38
+ @status = netconf_response_status
39
+ @body = json_body
40
+ end
41
+
42
+ def message
43
+ case(@status)
44
+ when NetconfResponseStatus::OK
45
+ "Success"
46
+ when NetconfResponseStatus::NODE_CONNECTED
47
+ "Node is connected"
48
+ when NetconfResponseStatus::NODE_DISCONNECTED
49
+ "Node is disconnected"
50
+ when NetconfResponseStatus::NODE_NOT_FOUND
51
+ "Node not found"
52
+ when NetconfResponseStatus::NODE_CONFIGURED
53
+ "Node is configured"
54
+ when NetconfResponseStatus::CONN_ERROR
55
+ "Server connection error"
56
+ when NetconfResponseStatus::CTRL_INTERNAL_ERROR
57
+ "Internal server error"
58
+ when NetconfResponseStatus::HTTP_ERROR
59
+ msg = "HTTP error"
60
+ msg += " #{@body.code}" if @body && @body.code
61
+ msg += " - #{@body.message}" if @body && @body.message
62
+ msg
63
+ when NetconfResponseStatus::DATA_NOT_FOUND
64
+ "Requested data not found"
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2015, BROCADE COMMUNICATIONS SYSTEMS, INC
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # 3. Neither the name of the copyright holder nor the names of its contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29
+ # THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ class NetconfResponseStatus
32
+ OK = 200
33
+ NODE_CONNECTED = 210
34
+ NODE_DISCONNECTED = 410
35
+ NODE_NOT_FOUND = 404
36
+ NODE_CONFIGURED = 211
37
+ CONN_ERROR = 503
38
+ CTRL_INTERNAL_ERROR = 500
39
+ HTTP_ERROR = 400
40
+ DATA_NOT_FOUND = 444
41
+ end
@@ -0,0 +1,103 @@
1
+ # Copyright (c) 2015, BROCADE COMMUNICATIONS SYSTEMS, INC
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # 3. Neither the name of the copyright holder nor the names of its contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29
+ # THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ class RestAgent
32
+ require 'uri'
33
+ require 'net/http'
34
+ require 'logger'
35
+
36
+ attr_reader :service_uri
37
+ attr_accessor :headers
38
+
39
+ $LOG = Logger.new('rubybvc-requests.log')
40
+
41
+ def initialize(service_uri, headers: {}, username: nil, password: nil,
42
+ open_timeout: nil)
43
+ @service_uri = URI(service_uri)
44
+ @headers = {'Content-Type' => 'application/json', 'Accept' => 'application/json'}.merge(headers)
45
+ @username = username
46
+ @password = password
47
+ @open_timeout = open_timeout
48
+ end
49
+
50
+ def get_request(uri_endpoint, query_params = {})
51
+ uri = @service_uri + URI(uri_endpoint)
52
+ uri.query = URI.encode_www_form(query_params) unless query_params.empty?
53
+ req = Net::HTTP::Get.new(uri, @headers)
54
+ return send_request(uri, req)
55
+ end
56
+
57
+ def post_request(uri_endpoint, post_body, headers: {})
58
+ uri = @service_uri + URI(uri_endpoint)
59
+ req = Net::HTTP::Post.new(uri, @headers.merge(headers))
60
+ req.body = post_body.is_a?(String) ? post_body : post_body.to_json
61
+ return send_request(uri, req)
62
+ end
63
+
64
+ # def patch_request(uri_endpoint, patch_body, headers: {})
65
+ # uri = @service_uri + URI(uri_endpoint)
66
+ # req = Net::HTTP::Patch.new(uri, @headers.merge(headers))
67
+ # req.body = patch_body.to_json
68
+ # return send_request(uri, req)
69
+ # end
70
+
71
+ def put_request(uri_endpoint, put_body, headers: {})
72
+ uri = @service_uri + URI(uri_endpoint)
73
+ req = Net::HTTP::Put.new(uri, @headers.merge(headers))
74
+ req.body = put_body.to_json
75
+ return send_request(uri, req)
76
+ end
77
+
78
+ def delete_request(uri_endpoint)
79
+ uri = @service_uri + URI(uri_endpoint)
80
+ req = Net::HTTP::Delete.new(uri, @headers)
81
+ return send_request(uri, req)
82
+ end
83
+
84
+ private
85
+
86
+ def send_request(uri, request)
87
+ request.basic_auth(@username, @password) unless @username.nil? || @username.empty?
88
+ begin
89
+ $LOG.info request.to_yaml
90
+ response = Net::HTTP.start(uri.host, uri.port, :open_timeout => @open_timeout,
91
+ :use_ssl => uri.scheme == 'https') do |http|
92
+ http.request(request)
93
+ end
94
+ $LOG.info response.to_yaml
95
+ # catch html responses
96
+ return response
97
+ rescue Net::HTTPHeaderSyntaxError, Net::HTTPBadResponse, Net::OpenTimeout => e
98
+ $LOG.error "Error connecting to #{@service_uri}: #{e.message}"
99
+ return nil
100
+ end
101
+ end
102
+
103
+ end
@@ -0,0 +1,51 @@
1
+ # Copyright (c) 2015, BROCADE COMMUNICATIONS SYSTEMS, INC
2
+ #
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without modification,
6
+ # are permitted provided that the following conditions are met:
7
+ #
8
+ # 1. Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # 3. Neither the name of the copyright holder nor the names of its contributors
16
+ # may be used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29
+ # THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ def check_response_for_success(response)
32
+ netconf_response = nil
33
+ if response && ((response.body && response.code.to_i < 204) || (response.code.to_i == 204 && !response.body))
34
+ parsed_body = response.body ? JSON.parse(response.body) : nil
35
+ netconf_response = yield parsed_body
36
+ else
37
+ netconf_response = handle_error_response(response)
38
+ end
39
+ netconf_response
40
+ end
41
+
42
+ def handle_error_response(response)
43
+ if response && response.body.nil? && response.code.to_i < 204
44
+ netconf_response = NetconfResponse.new(NetconfResponseStatus::CTRL_INTERNAL_ERROR)
45
+ elsif response && response.code.to_i > 204
46
+ netconf_response = NetconfResponse.new(NetconfResponseStatus::HTTP_ERROR,
47
+ response)
48
+ elsif !response
49
+ netconf_response = NetconfResponse.new(NetconfResponseStatus::CONN_ERROR)
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubybvc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Sarah Dempsey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.6.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.6.2
27
+ description: Ruby support library for Brocade Vyatta Controller (BVC) RESTCONF API
28
+ email: support@elbrys.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/controller/controller.rb
34
+ - lib/controller/netconf_node.rb
35
+ - lib/controller/node.rb
36
+ - lib/controller/openflow_node.rb
37
+ - lib/netconfdev/vrouter/dataplane_firewall.rb
38
+ - lib/netconfdev/vrouter/firewall.rb
39
+ - lib/netconfdev/vrouter/rule.rb
40
+ - lib/netconfdev/vrouter/rules.rb
41
+ - lib/netconfdev/vrouter/vrouter5600.rb
42
+ - lib/openflowdev/action_output.rb
43
+ - lib/openflowdev/actions/action.rb
44
+ - lib/openflowdev/actions/actions.rb
45
+ - lib/openflowdev/actions/copy_ttl_inwards_action.rb
46
+ - lib/openflowdev/actions/copy_ttl_outwards_action.rb
47
+ - lib/openflowdev/actions/dec_mpls_ttl_action.rb
48
+ - lib/openflowdev/actions/dec_nw_ttl_action.rb
49
+ - lib/openflowdev/actions/drop_action.rb
50
+ - lib/openflowdev/actions/flood_action.rb
51
+ - lib/openflowdev/actions/flood_all_action.rb
52
+ - lib/openflowdev/actions/group_action.rb
53
+ - lib/openflowdev/actions/hw_path_action.rb
54
+ - lib/openflowdev/actions/loopback_action.rb
55
+ - lib/openflowdev/actions/output_action.rb
56
+ - lib/openflowdev/actions/pop_mpls_header_action.rb
57
+ - lib/openflowdev/actions/pop_pbb_header_action.rb
58
+ - lib/openflowdev/actions/pop_vlan_header_action.rb
59
+ - lib/openflowdev/actions/push_mpls_header_action.rb
60
+ - lib/openflowdev/actions/push_pbb_header_action.rb
61
+ - lib/openflowdev/actions/push_vlan_header_action.rb
62
+ - lib/openflowdev/actions/set_dl_dst_action.rb
63
+ - lib/openflowdev/actions/set_dl_src_action.rb
64
+ - lib/openflowdev/actions/set_field_action.rb
65
+ - lib/openflowdev/actions/set_mpls_ttl_action.rb
66
+ - lib/openflowdev/actions/set_nw_dst_action.rb
67
+ - lib/openflowdev/actions/set_nw_src_action.rb
68
+ - lib/openflowdev/actions/set_nw_ttl_action.rb
69
+ - lib/openflowdev/actions/set_queue_action.rb
70
+ - lib/openflowdev/actions/set_tp_dst_action.rb
71
+ - lib/openflowdev/actions/set_tp_src_action.rb
72
+ - lib/openflowdev/actions/set_vlan_cfi_action.rb
73
+ - lib/openflowdev/actions/set_vlan_id_action.rb
74
+ - lib/openflowdev/actions/set_vlan_pcp_action.rb
75
+ - lib/openflowdev/actions/strip_vlan_action.rb
76
+ - lib/openflowdev/actions/sw_path_action.rb
77
+ - lib/openflowdev/flow_entry.rb
78
+ - lib/openflowdev/instruction.rb
79
+ - lib/openflowdev/match.rb
80
+ - lib/openflowdev/of_switch.rb
81
+ - lib/rubybvc.rb
82
+ - lib/utils/hash_with_compact.rb
83
+ - lib/utils/netconf_response.rb
84
+ - lib/utils/netconf_response_status.rb
85
+ - lib/utils/rest_agent.rb
86
+ - lib/utils/utilities.rb
87
+ homepage: ''
88
+ licenses:
89
+ - BSD
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Ruby BVC
111
+ test_files: []