racktables-vlanparse 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in racktables-vlanparse.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alexander Amanuel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # RackTables::VLANParse
2
+
3
+ Gem for parsing racktables-style vlan configuration of ports.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'racktables-vlanparse'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install racktables-vlanparse
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/iavael/racktables-vlanparse/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,59 @@
1
+ require 'racktables/vlanparse/exception'
2
+ require 'racktables/vlanparse/version'
3
+
4
+ module RackTables
5
+ class VLAN
6
+ def parse(vlan)
7
+ input = vlan + "\0"
8
+ output = {
9
+ :native => nil,
10
+ :allowed => [],
11
+ :type => nil
12
+ }
13
+ status = :start
14
+ vlanbuf = ""
15
+ input.each_char do |chr|
16
+ case chr
17
+ when "A", "T"
18
+ raise ParsingError.new("Port type can be only at the beginning of the string") if status != :start
19
+ output[:type] = chr == "A" ? :access : :trunk
20
+ status = chr == "A" ? :atype : :ttype
21
+ when "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
22
+ if status == :start
23
+ output[:type] = :access
24
+ status = :anum
25
+ elsif status == :atype || status == :anum
26
+ status = :anum
27
+ elsif status == :ttype || status == :tnum
28
+ status = :tnum
29
+ elsif status == :nextvlan || status == :nnum
30
+ status = :nnum
31
+ else
32
+ raise ParsingError.new("There shouldn't be number")
33
+ end
34
+ vlanbuf += chr
35
+ when "+", "\0"
36
+ raise ParsingError.new("Invalid character at the beginning of the string") if status == :start
37
+ raise ParsingError.new("VLAN number expected") if status == :nextvlan
38
+ raise ParsingError.new("Null character in the input") if status == :end
39
+ raise ParsingError.new("You must set native VLAN on access port") if status == :atype
40
+ raise ParsingError.new("You cannot set tagged VLAN on access port") if chr == "+" && status == :anum
41
+ raise ParsingError.new("VLAN number must be between 1 and 4095") if !vlanbuf.empty? && ( vlanbuf.to_i > 4095 || vlanbuf.to_i < 1 )
42
+ if status == :ttype
43
+ output[:native] = nil
44
+ elsif status == :tnum || ( chr == "\0" && status == :anum )
45
+ output[:native] = vlanbuf
46
+ output[:allowed] = [ vlanbuf ]
47
+ elsif status == :nnum
48
+ output[:allowed] += [ vlanbuf ]
49
+ end
50
+ vlanbuf = ""
51
+ status = chr == "+" ? :nextvlan : :end
52
+ else
53
+ raise ParsingError.new("Invalid character in the string")
54
+ end
55
+ end
56
+ return output
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,6 @@
1
+ module RackTables
2
+ class VLAN
3
+ class ParsingError < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module RackTables
2
+ module VLANParse
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'racktables/vlanparse/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "racktables-vlanparse"
8
+ spec.version = RackTables::VLANParse::VERSION
9
+ spec.authors = ["Iavael"]
10
+ spec.email = ["iavaelooeyt@gmail.com"]
11
+ spec.summary = %q{Gem for parsing racktables-style vlan configuration of ports.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe RackTables::VLANParse do
4
+ it 'should have a version number' do
5
+ expect(RackTables::VLANParse::VERSION).not_to be nil
6
+ end
7
+ end
8
+
9
+ describe RackTables::VLAN do
10
+ vlan = RackTables::VLAN.new
11
+
12
+ it 'should parse "100"' do
13
+ expect(vlan.parse("100")).to eq({ :native => "100", :allowed => ["100"], :type => :access })
14
+ end
15
+
16
+ it 'should parse "A100"' do
17
+ expect(vlan.parse("A100")).to eq({ :native => "100", :allowed => ["100"], :type => :access })
18
+ end
19
+
20
+ it 'should parse "T100"' do
21
+ expect(vlan.parse("T100")).to eq({ :native => "100", :allowed => ["100"], :type => :trunk })
22
+ end
23
+
24
+ it 'should parse "T100+200"' do
25
+ expect(vlan.parse("T100+200")).to eq({ :native => "100", :allowed => ["100", "200"], :type => :trunk })
26
+ end
27
+
28
+ it 'should parse "T100+200+300"' do
29
+ expect(vlan.parse("T100+200+300")).to eq({ :native => "100", :allowed => ["100", "200", "300"], :type => :trunk })
30
+ end
31
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'racktables/vlanparse'
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: racktables-vlanparse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Iavael
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description:
63
+ email:
64
+ - iavaelooeyt@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .travis.yml
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - lib/racktables/vlanparse.rb
77
+ - lib/racktables/vlanparse/exception.rb
78
+ - lib/racktables/vlanparse/version.rb
79
+ - racktables-vlanparse.gemspec
80
+ - spec/racktables/vlanparse_spec.rb
81
+ - spec/spec_helper.rb
82
+ homepage: ''
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.24
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Gem for parsing racktables-style vlan configuration of ports.
107
+ test_files:
108
+ - spec/racktables/vlanparse_spec.rb
109
+ - spec/spec_helper.rb