phut 0.6.2 → 0.6.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/bin/phut +0 -2
- data/lib/phut/configuration.rb +36 -10
- data/lib/phut/open_vswitch.rb +5 -0
- data/lib/phut/parser.rb +4 -33
- data/lib/phut/version.rb +1 -1
- data/lib/phut/vhost.rb +6 -5
- data/lib/phut/vhost_daemon.rb +1 -1
- data/lib/phut/virtual_link.rb +13 -3
- data/spec/phut/parser_spec.rb +21 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4760c8bc9db6a1b1f752aa738aa5eb844c8059e4
|
4
|
+
data.tar.gz: f5d34bbee5fdeb48167a8e7f2170a2193fbe073c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45d1513fcbbeba14e3b8f83c3d3842350721db909edaaa24d42e6dbce603957f8b90fa4701690086cdae7864c187f996c852db7163d4860342fc7c757a523aaf
|
7
|
+
data.tar.gz: 68877bd84eb271c7e54a0bec0e2860a0b1239f0a45ae55389f564531b8ae1db4721acde1a223b69c8a6ec4994b1a904d0a4a47e306cfaa5214e2af710bc7d6f2
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
## develop (unreleased)
|
4
4
|
|
5
5
|
|
6
|
+
## 0.6.3 (6/4/2015)
|
7
|
+
### Bugs fixed
|
8
|
+
* [#23](https://github.com/trema/phut/pull/23): Fix vhost restart failure.
|
9
|
+
|
10
|
+
|
6
11
|
## 0.6.2 (6/3/2015)
|
7
12
|
### Bugs fixed
|
8
13
|
* Delete a vhost.*.ctl socket file after the vhost process is killed.
|
data/bin/phut
CHANGED
@@ -53,10 +53,8 @@ module Phut
|
|
53
53
|
command :run do |c|
|
54
54
|
c.desc 'Location to put pid files'
|
55
55
|
c.flag [:p, :pid_dir], default_value: Phut.pid_dir
|
56
|
-
|
57
56
|
c.desc 'Location to put log files'
|
58
57
|
c.flag [:l, :log_dir], default_value: Phut.log_dir
|
59
|
-
|
60
58
|
c.desc 'Location to put socket files'
|
61
59
|
c.flag [:s, :socket_dir], default_value: Phut.socket_dir
|
62
60
|
|
data/lib/phut/configuration.rb
CHANGED
@@ -4,8 +4,6 @@ require 'phut/open_vswitch'
|
|
4
4
|
module Phut
|
5
5
|
# Parsed DSL data.
|
6
6
|
class Configuration
|
7
|
-
attr_reader :links
|
8
|
-
|
9
7
|
def initialize(logger = NullLogger.new)
|
10
8
|
@all = {}
|
11
9
|
@links = []
|
@@ -28,12 +26,10 @@ module Phut
|
|
28
26
|
end
|
29
27
|
# rubocop:enable MethodLength
|
30
28
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
fail "No network device found for #{name}."
|
29
|
+
def update_connections
|
30
|
+
update_vswitch_ports
|
31
|
+
update_vhost_interfaces
|
32
|
+
self
|
37
33
|
end
|
38
34
|
|
39
35
|
def vswitches
|
@@ -45,7 +41,7 @@ module Phut
|
|
45
41
|
end
|
46
42
|
|
47
43
|
def run
|
48
|
-
links.each(&:run)
|
44
|
+
@links.each(&:run)
|
49
45
|
vhosts.each { |each| each.run vhosts }
|
50
46
|
vswitches.each(&:run)
|
51
47
|
end
|
@@ -53,7 +49,7 @@ module Phut
|
|
53
49
|
def stop
|
54
50
|
vswitches.each(&:maybe_stop)
|
55
51
|
vhosts.each(&:maybe_stop)
|
56
|
-
links.each(&:maybe_stop)
|
52
|
+
@links.each(&:maybe_stop)
|
57
53
|
end
|
58
54
|
|
59
55
|
def add_vswitch(name, attrs)
|
@@ -78,5 +74,35 @@ module Phut
|
|
78
74
|
conflict = @all[name]
|
79
75
|
fail "The name #{name} conflicts with #{conflict}." if conflict
|
80
76
|
end
|
77
|
+
|
78
|
+
def update_vswitch_ports
|
79
|
+
@links.each do |each|
|
80
|
+
maybe_connect_link_to_vswitch each
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def maybe_connect_link_to_vswitch(link)
|
85
|
+
vswitches_connected_to(link).each do |each|
|
86
|
+
each.add_network_device link.find_network_device(each)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def vswitches_connected_to(link)
|
91
|
+
vswitches.select { |each| link.connect_to?(each) }
|
92
|
+
end
|
93
|
+
|
94
|
+
def update_vhost_interfaces
|
95
|
+
vhosts.each do |each|
|
96
|
+
each.network_device = find_network_device(each)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def find_network_device(vhost)
|
101
|
+
@links.each do |each|
|
102
|
+
device = each.find_network_device(vhost)
|
103
|
+
return device if device
|
104
|
+
end
|
105
|
+
fail "No network device found for #{vhost}."
|
106
|
+
end
|
81
107
|
end
|
82
108
|
end
|
data/lib/phut/open_vswitch.rb
CHANGED
@@ -77,6 +77,11 @@ module Phut
|
|
77
77
|
system "sudo ovs-vsctl br-exists #{bridge_name}"
|
78
78
|
end
|
79
79
|
|
80
|
+
def add_network_device(network_device)
|
81
|
+
network_device.port_number = @network_devices.size + 1
|
82
|
+
@network_devices << network_device
|
83
|
+
end
|
84
|
+
|
80
85
|
private
|
81
86
|
|
82
87
|
def bridge_name
|
data/lib/phut/parser.rb
CHANGED
@@ -6,43 +6,14 @@ module Phut
|
|
6
6
|
# Configuration DSL parser.
|
7
7
|
class Parser
|
8
8
|
def initialize(logger = NullLogger.new)
|
9
|
-
@
|
10
|
-
@port_number = Hash.new(0)
|
9
|
+
@logger = logger
|
11
10
|
end
|
12
11
|
|
13
12
|
def parse(file)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@config
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def connect_links_to_switches
|
23
|
-
@config.links.each do |each|
|
24
|
-
maybe_assign_network_device_to_vswitch each
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def connect_links_to_vhosts
|
29
|
-
@config.vhosts.each do |each|
|
30
|
-
each.network_device = @config.find_network_device_by_name(each.name)
|
13
|
+
Configuration.new(@logger).tap do |configuration|
|
14
|
+
Syntax.new(configuration).instance_eval IO.read(file), file
|
15
|
+
configuration.update_connections
|
31
16
|
end
|
32
17
|
end
|
33
|
-
|
34
|
-
def maybe_assign_network_device_to_vswitch(link)
|
35
|
-
@config.vswitches.each do |each|
|
36
|
-
switch_name = each.name
|
37
|
-
network_device = link.find_network_device_by_name(switch_name)
|
38
|
-
next unless network_device
|
39
|
-
network_device.port_number = new_port_number(switch_name)
|
40
|
-
each.network_devices << network_device
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def new_port_number(switch_name)
|
45
|
-
@port_number[switch_name] += 1
|
46
|
-
end
|
47
18
|
end
|
48
19
|
end
|
data/lib/phut/version.rb
CHANGED
data/lib/phut/vhost.rb
CHANGED
@@ -30,7 +30,8 @@ module Phut
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def run(all_hosts = [])
|
33
|
-
|
33
|
+
@all_hosts ||= all_hosts
|
34
|
+
sh "rvmsudo vhost run #{run_options}"
|
34
35
|
end
|
35
36
|
|
36
37
|
def stop
|
@@ -49,20 +50,20 @@ module Phut
|
|
49
50
|
|
50
51
|
private
|
51
52
|
|
52
|
-
def run_options
|
53
|
+
def run_options
|
53
54
|
["-n #{name}",
|
54
55
|
"-I #{@network_device}",
|
55
56
|
"-i #{@ip_address}",
|
56
57
|
"-m #{@mac_address}",
|
57
|
-
"-a #{arp_entries
|
58
|
+
"-a #{arp_entries}",
|
58
59
|
@promisc ? '--promisc' : nil,
|
59
60
|
"-P #{Phut.pid_dir}",
|
60
61
|
"-L #{Phut.log_dir}",
|
61
62
|
"-S #{Phut.socket_dir}"].compact.join(' ')
|
62
63
|
end
|
63
64
|
|
64
|
-
def arp_entries
|
65
|
-
all_hosts.map do |each|
|
65
|
+
def arp_entries
|
66
|
+
@all_hosts.map do |each|
|
66
67
|
"#{each.ip_address}/#{each.mac_address}"
|
67
68
|
end.join(',')
|
68
69
|
end
|
data/lib/phut/vhost_daemon.rb
CHANGED
@@ -49,7 +49,7 @@ module Phut
|
|
49
49
|
private
|
50
50
|
|
51
51
|
def start_logging
|
52
|
-
@logger = Logger.new(log_file)
|
52
|
+
@logger = Logger.new(File.open(log_file, 'a'))
|
53
53
|
@logger.info("#{@options.fetch(:name)} started " \
|
54
54
|
"(interface = #{@options.fetch(:interface)}," \
|
55
55
|
" IP address = #{@options.fetch(:ip_address)}," \
|
data/lib/phut/virtual_link.rb
CHANGED
@@ -17,6 +17,10 @@ module Phut
|
|
17
17
|
@name.gsub('.', '_') + port_number_string
|
18
18
|
end
|
19
19
|
|
20
|
+
def inspect
|
21
|
+
to_s
|
22
|
+
end
|
23
|
+
|
20
24
|
private
|
21
25
|
|
22
26
|
def port_number_string
|
@@ -58,11 +62,17 @@ module Phut
|
|
58
62
|
end
|
59
63
|
|
60
64
|
def up?
|
61
|
-
/^#{@device_a}\s+Link encap:Ethernet/ =~ `ifconfig -a`
|
65
|
+
/^#{@device_a}\s+Link encap:Ethernet/ =~ `ifconfig -a` || false
|
62
66
|
end
|
63
67
|
|
64
|
-
def
|
65
|
-
|
68
|
+
def connect_to?(vswitch)
|
69
|
+
find_network_device(vswitch) || false
|
70
|
+
end
|
71
|
+
|
72
|
+
def find_network_device(vswitch_or_vhost)
|
73
|
+
[@device_a, @device_b].detect do |each|
|
74
|
+
each.name == vswitch_or_vhost.name
|
75
|
+
end
|
66
76
|
end
|
67
77
|
|
68
78
|
private
|
data/spec/phut/parser_spec.rb
CHANGED
@@ -3,16 +3,18 @@ require 'stringio'
|
|
3
3
|
|
4
4
|
describe Phut::Parser do
|
5
5
|
describe '#parse' do
|
6
|
-
Given
|
7
|
-
|
6
|
+
Given do
|
7
|
+
allow(IO).to receive(:read).with('CONFIGURATION_FILE').and_return(string)
|
8
|
+
end
|
9
|
+
Given(:configuration) { Phut::Parser.new.parse 'CONFIGURATION_FILE' }
|
8
10
|
|
9
11
|
context "with 'vswitch { dpid '0xabc' }'" do
|
10
12
|
When(:string) { "vswitch { dpid '0xabc' }" }
|
11
13
|
|
12
14
|
describe '#vswitch' do
|
13
|
-
Then {
|
14
|
-
Then {
|
15
|
-
Then {
|
15
|
+
Then { configuration.vswitches.size == 1 }
|
16
|
+
Then { configuration.fetch('0xabc').datapath_id == 0xabc }
|
17
|
+
Then { configuration.fetch('0xabc').dpid == 0xabc }
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -20,9 +22,9 @@ describe Phut::Parser do
|
|
20
22
|
When(:string) { "vswitch { datapath_id '0xabc' }" }
|
21
23
|
|
22
24
|
describe '#vswitch' do
|
23
|
-
Then {
|
24
|
-
Then {
|
25
|
-
Then {
|
25
|
+
Then { configuration.vswitches.size == 1 }
|
26
|
+
Then { configuration.fetch('0xabc').dpid == 0xabc }
|
27
|
+
Then { configuration.fetch('0xabc').datapath_id == 0xabc }
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
@@ -30,39 +32,39 @@ describe Phut::Parser do
|
|
30
32
|
When(:string) { "vswitch('my_controller') { dpid '0xabc' }" }
|
31
33
|
|
32
34
|
describe '#vswitch' do
|
33
|
-
Then {
|
34
|
-
Then {
|
35
|
-
Then {
|
35
|
+
Then { configuration.vswitches.size == 1 }
|
36
|
+
Then { configuration.fetch('my_controller').dpid == 0xabc }
|
37
|
+
Then { configuration.fetch('my_controller').datapath_id == 0xabc }
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
39
41
|
context "with 'vhost { ip '192.168.0.1' }' ..." do
|
40
42
|
When(:string) do
|
41
|
-
<<-
|
43
|
+
<<-CONFIGURATION
|
42
44
|
vhost { ip '192.168.0.1' }
|
43
45
|
vhost { ip '192.168.0.2' }
|
44
46
|
link '192.168.0.1', '192.168.0.2'
|
45
|
-
|
47
|
+
CONFIGURATION
|
46
48
|
end
|
47
49
|
|
48
50
|
describe '#vhost' do
|
49
|
-
Then {
|
50
|
-
Then {
|
51
|
+
Then { configuration.vhosts.size == 2 }
|
52
|
+
Then { configuration.fetch('192.168.0.1').ip_address == '192.168.0.1' }
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
56
|
context "with 'vhost('host1') { ip '192.168.0.1' }' ..." do
|
55
57
|
When(:string) do
|
56
|
-
<<-
|
58
|
+
<<-CONFIGURATION
|
57
59
|
vhost('host1') { ip '192.168.0.1' }
|
58
60
|
vhost('host2') { ip '192.168.0.2' }
|
59
61
|
link 'host1', 'host2'
|
60
|
-
|
62
|
+
CONFIGURATION
|
61
63
|
end
|
62
64
|
|
63
65
|
describe '#vhost' do
|
64
|
-
Then {
|
65
|
-
Then {
|
66
|
+
Then { configuration.vhosts.size == 2 }
|
67
|
+
Then { configuration.fetch('host1').ip_address == '192.168.0.1' }
|
66
68
|
end
|
67
69
|
end
|
68
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yasuhito Takamiya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|