linux-ip-addr 0.0.6 → 0.0.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: 88b9efd09118cb965dd704249f0925a455640c0f
4
- data.tar.gz: b4da92670195977f8dc5baf4fb3889d79fe33f45
3
+ metadata.gz: d872c524cb5965dd7d8c4caaec484924b7394bf0
4
+ data.tar.gz: 7322ee705ccbbda31c2fe125d071237b95dc4ded
5
5
  SHA512:
6
- metadata.gz: cf1f67a861b572dc648fb2418050174c0bc2cf8e10d3c7f90503719241929cb2deb0bd56d343d17e155f859ba57ce06c0a861f4a273e520f73617c3c9ee8f6cc
7
- data.tar.gz: 9909d5e253ce1ce86b04b252e779f813b3ed008478d8aef4bb8cdb5ad99201e013931bd0ffc6e71c9e11986e43918e6c0387d987b5aefed352ae56290b0a9689
6
+ metadata.gz: d468f7180a526b6da439d1e9729834174da2adb3f58335649edf92519995cdec7008f3cfeb1df2fca52bc39cb1f182a69c2440dd86067826a8ba6d3b221f0575
7
+ data.tar.gz: 0f44708913a3ca536958a3a486ce2441e4153705b182f4ad8f60aed922718ab0ec7259f3be640841e9ffc5f6afcfacaf4826916881deca9f6af9905944cdc5d3
@@ -12,10 +12,19 @@ module Linux
12
12
  @routes = []
13
13
  end
14
14
 
15
+ def as_commands(direction = 'add')
16
+ @routes.map do |route|
17
+ route.as_commands(direction)
18
+ end.flatten.compact.join("\n")
19
+ end
20
+
15
21
  class Options < OpenStruct
16
22
  def initialize(options_str)
17
23
  super(options_str.split(/\s+/).inject({}) { |r, i| r[i] = true; r })
18
24
  end
25
+ def as_ip
26
+ "" # there is some to do
27
+ end
19
28
  end
20
29
 
21
30
  class ViaRoute
@@ -26,8 +35,11 @@ module Linux
26
35
  @dev = dev
27
36
  @options = options
28
37
  end
38
+ def as_commands(direction)
39
+ "ip route #{direction} #{dst} via #{via} #{options.as_ip}"
40
+ end
29
41
  end
30
- def add_via(dev, dst, via, options)
42
+ def add_via(dev, dst, via, options = "")
31
43
  @interfaces[dev] ||= []
32
44
  route = ViaRoute.new(dst, via, dev, Options.new(options))
33
45
  @interfaces[dev] << route
@@ -41,6 +53,9 @@ module Linux
41
53
  @dev = dev
42
54
  @options = options
43
55
  end
56
+ def as_commands(direction)
57
+ "ip route #{direction} #{dst} dev #{dev} #{options.as_ip}"
58
+ end
44
59
  end
45
60
  def add_dev(dev, dst, options)
46
61
  @interfaces[dev] ||= []
@@ -0,0 +1,5 @@
1
+ module Linux
2
+ module Ip
3
+ VERSION = "0.0.7"
4
+ end
5
+ end
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'linux/ip/addr/version'
4
+ require 'linux/ip/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "linux-ip-addr"
8
- spec.version = Linux::Ip::Addr::VERSION
8
+ spec.version = Linux::Ip::VERSION
9
9
  spec.authors = ["Meno Abels"]
10
10
  spec.email = ["meno.abels@adviser.com"]
11
11
  spec.summary = %q{Parse the output of ip addr on a linux system}
@@ -104,5 +104,18 @@ SAMPLE
104
104
  def test_find
105
105
  end
106
106
 
107
+ def test_as_command
108
+ ip_route = Linux::Ip::Route.parse_from_lines(@ip_route_4_show.lines)
109
+ assert ip_route.as_commands("del").include?("ip route del 112.164.91.136/29 dev eth3.207")
110
+ ip_route = Linux::Ip::Route.parse_from_lines(@ip_route_6_show.lines)
111
+ assert ip_route.as_commands("add").include?("ip route add 3c04:3a60:0:fe82::/64 via 3c04:3a60:0:2::21")
112
+ end
113
+
114
+ def test_from_scratch
115
+ ip_route = Linux::Ip::Route::IpRoute.new
116
+ ip_route.add_via("eth0", "0.0.0.0/0", "47.11.1.1")
117
+ assert ip_route.as_commands("add").include?("ip route add 0.0.0.0/0 via 47.11.1.1")
118
+ end
119
+
107
120
  end
108
121
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux-ip-addr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meno Abels
@@ -37,8 +37,8 @@ files:
37
37
  - README.md
38
38
  - Rakefile
39
39
  - lib/linux/ip/addr.rb
40
- - lib/linux/ip/addr/version.rb
41
40
  - lib/linux/ip/route.rb
41
+ - lib/linux/ip/version.rb
42
42
  - linux-ip-addr.gemspec
43
43
  - test/linux_ip_addr_test.rb
44
44
  - test/linux_ip_route_test.rb
@@ -1,7 +0,0 @@
1
- module Linux
2
- module Ip
3
- module Addr
4
- VERSION = "0.0.6"
5
- end
6
- end
7
- end