aubergine 0.1.6 → 0.1.7

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
2
  SHA1:
3
- metadata.gz: 8d8f1385a686e55a079e071f26d9d2b9a195da97
4
- data.tar.gz: 5f721ac02520bb4438c917dcb4208850df15019f
3
+ metadata.gz: 388d030db072626bc9579ca8d02c396d3565b23a
4
+ data.tar.gz: cc43c7224d192a3f763448b89651628b69e001a2
5
5
  SHA512:
6
- metadata.gz: 700498141ba8f4e2ebff3cb565b5d7d20c3c8ceb2d99b1c9ccdc0e788abc2a036a65dd008b9e13a79f490146a5a1a17e965e1705165e0a75c8deade7e6ecaef1
7
- data.tar.gz: 6078de377ff8ece22146a8d09d08fd0723a8b4ca9eb097b2f5e090daaab5505cf69b8576362375aa99d5ae6c5853792a44d8cdd62b251b00c58016e9af1d4970
6
+ metadata.gz: 0f36e8c6fd9195638dd76ddd53d09289c333e507ae7dbc5bf871f9a9d87b8d82727e7c9fce34d2b2078789d2e7bcb479e3888ff36ec2fe5857f22880a1fe0419
7
+ data.tar.gz: bfa96c89c00451e5f581d0e5c230d072fe79a8208e80a8b8adeb0c3f3acdabe4cbf452db88424244ce783a6d685f8869eb2b8a01993ac9760a87febd9698deee
@@ -0,0 +1,28 @@
1
+ module Courgette
2
+ class Chain
3
+ def initialize(fetcher, processors)
4
+ @fetcher = fetcher
5
+ @processors = processors
6
+ end
7
+
8
+ def self.of(fetcher, *processors)
9
+ new(fetcher, processors)
10
+ end
11
+
12
+ def apply(ip, hash)
13
+ raw = @fetcher.new(ip, hash).fetch
14
+ @processors.map(&:new).inject(raw) { |acc, p| acc = p.process(acc) }
15
+ end
16
+
17
+ def responsible_of(vendor)
18
+ @fetcher.responsible_of(vendor)
19
+ end
20
+
21
+ def self.all
22
+ [
23
+ Chain.of(Fetchers::CommutateursFetcher, Processors::DefaultProcessor),
24
+ Chain.of(Fetchers::HpFetcher, Processors::DefaultProcessor)
25
+ ]
26
+ end
27
+ end
28
+ end
@@ -10,7 +10,7 @@ module Courgette
10
10
  def devices
11
11
  response = self.class.get("#{@base}/configuration.json", @headers)
12
12
  if response.code == 200
13
- response.parsed_response.map { |raw| Device.build(raw) }
13
+ response.parsed_response.map { |raw| Device.new(raw) }
14
14
  else
15
15
  raise "Configuration not found."
16
16
  end
@@ -1,35 +1,16 @@
1
1
  module Courgette
2
2
  class Device
3
- VENDOR_CLASSES = {
4
- 'hp' => Courgette::HP, # using sftp
5
- 'cisco' => Commutateurs::Cisco,
6
- 'juniper' => Commutateurs::Juniper,
7
- 'fortigate' => Commutateurs::Fortigate,
8
- 'h3c' => Commutateurs::H3c
9
- }
10
-
11
3
  attr_reader :ip, :vendor
12
4
 
13
- def initialize(ip, vendor, login, password, enable)
14
- @ip = ip
15
- @vendor = vendor
16
- @login = login
17
- @password = password
18
- @enable = enable
19
- end
20
-
21
- def self.build(hash)
22
- new(hash['ip'], hash['vendor'], hash['login'], hash['password'], hash['enable'] || hash['password'])
5
+ def initialize(details)
6
+ @ip = details['ip']
7
+ @vendor = details['vendor']
8
+ @details = details
23
9
  end
24
10
 
25
11
  def fetch(debug = false)
26
- credentials = Commutateurs::Credentials.new(@login, @password, @enable)
27
-
28
- device = VENDOR_CLASSES[vendor].new(ip, credentials, debug)
29
- device.connect
30
- device.enable
31
-
32
- device.configuration.unpack('C*').pack('U*').gsub("\r\n", "\n")
12
+ chain = Chain.all.find { |chain| chain.responsible_of(@vendor) }
13
+ chain ? chain.apply(@ip, @details) : raise("Vendor not found")
33
14
  end
34
15
  end
35
16
  end
@@ -0,0 +1,31 @@
1
+ module Courgette
2
+ module Fetchers
3
+ class CommutateursFetcher < Fetcher
4
+ VENDORS = {
5
+ 'cisco' => Commutateurs::Cisco,
6
+ 'fortigate' => Commutateurs::Fortigate,
7
+ 'h3c' => Commutateurs::H3c,
8
+ 'juniper' => Commutateurs::Juniper
9
+ }
10
+
11
+ def initialize(ip, details)
12
+ @ip = ip
13
+ @klass = VENDORS[details['vendor']]
14
+ @credentials = Commutateurs::Credentials.new(details['login'], details['password'], details['enable'])
15
+ end
16
+
17
+ def self.responsible_of(vendor)
18
+ ["cisco", "h3c", "juniper", "fortigate"].include? vendor
19
+ end
20
+
21
+ def fetch
22
+ device = @klass.new(@ip, @credentials, false)
23
+
24
+ device.connect
25
+ device.enable
26
+
27
+ device.configuration
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ module Courgette
2
+ module Fetchers
3
+ class Fetcher
4
+ def initialize(ip, details)
5
+ raise "Not implemented"
6
+ end
7
+
8
+ def fetch
9
+ raise "Not implemented"
10
+ end
11
+
12
+ def self.responsible_of(vendor)
13
+ raise "Not implemented"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ module Courgette
2
+ module Fetchers
3
+ class HpFetcher < Fetcher
4
+ def initialize(ip, details)
5
+ @ip = ip
6
+ @user = details['login']
7
+ @password = details['password']
8
+ end
9
+
10
+ def self.responsible_of(vendor)
11
+ "hp" == vendor
12
+ end
13
+
14
+ def fetch
15
+ begin
16
+ data = ""
17
+ Net::SFTP.start(@ip, @user, :password => @password) do |sftp|
18
+ data = sftp.download!("/cfg/running-config")
19
+ end
20
+ data
21
+ rescue IOError => e
22
+ data
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ module Courgette
2
+ module Processors
3
+ class DefaultProcessor < Processor
4
+ def process(text)
5
+ text.unpack('C*').pack('U*').gsub("\r\n", "\n")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Courgette
2
+ module Processors
3
+ class Processor
4
+ def process(text)
5
+ raise "Not implemented"
6
+ end
7
+ end
8
+ end
9
+ end
data/lib/courgette.rb CHANGED
@@ -9,7 +9,12 @@ require 'parallel'
9
9
 
10
10
  require 'net/sftp'
11
11
 
12
- require_relative './courgette/hp.rb'
12
+ require_relative './courgette/fetchers/fetcher.rb'
13
+ require_relative './courgette/fetchers/commutateurs_fetcher.rb'
14
+ require_relative './courgette/fetchers/hp_fetcher.rb'
15
+ require_relative './courgette/processors/processor.rb'
16
+ require_relative './courgette/processors/default_processor.rb'
17
+ require_relative './courgette/chain.rb'
13
18
  require_relative './courgette/device.rb'
14
19
  require_relative './courgette/client.rb'
15
20
  require_relative './courgette/executor.rb'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aubergine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Rose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-06 00:00:00.000000000 Z
11
+ date: 2013-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commutateurs
@@ -94,22 +94,97 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: ramcrest
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rack-test
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: mocha
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
97
167
  description: Distributed RANCID - backup your network devices
98
168
  email: guillaume.rose@gmail.com
99
169
  executables: []
100
170
  extensions: []
101
171
  extra_rdoc_files: []
102
172
  files:
103
- - lib/aubergine/path.rb
173
+ - lib/aubergine/device.rb
174
+ - lib/aubergine/server.rb
104
175
  - lib/aubergine/satellite.rb
105
- - lib/aubergine/satellite_provider.rb
106
176
  - lib/aubergine/file_satellite_provider.rb
177
+ - lib/aubergine/satellite_provider.rb
107
178
  - lib/aubergine/merge_satellite_provider.rb
108
- - lib/aubergine/server.rb
109
- - lib/aubergine/device.rb
110
- - lib/courgette/hp.rb
111
- - lib/courgette/client.rb
179
+ - lib/aubergine/path.rb
180
+ - lib/courgette/chain.rb
112
181
  - lib/courgette/device.rb
182
+ - lib/courgette/client.rb
183
+ - lib/courgette/fetchers/hp_fetcher.rb
184
+ - lib/courgette/fetchers/commutateurs_fetcher.rb
185
+ - lib/courgette/fetchers/fetcher.rb
186
+ - lib/courgette/processors/default_processor.rb
187
+ - lib/courgette/processors/processor.rb
113
188
  - lib/courgette/executor.rb
114
189
  - lib/aubergine.rb
115
190
  - lib/courgette.rb
data/lib/courgette/hp.rb DELETED
@@ -1,32 +0,0 @@
1
- module Courgette
2
- class HP
3
- def initialize(ip, credentials, verbose = false)
4
- @ip = ip
5
- @credentials = credentials
6
- end
7
-
8
- def enable
9
- end
10
-
11
- def connect
12
- end
13
-
14
- def configuration
15
- begin
16
- data = ""
17
- Net::SFTP.start(@ip, @credentials.user, :password => @credentials.password) do |sftp|
18
- data = sftp.download!("/cfg/running-config")
19
- end
20
- data
21
- rescue IOError => e
22
- data
23
- end
24
- end
25
-
26
- def save
27
- end
28
-
29
- def disconnect
30
- end
31
- end
32
- end