Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OVSDB client in order to retrive port list #41

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ source 'https://rubygems.org'

gemspec

gem 'active_flow', github: 'shun159/active_flow', branch: 'feature/ovsdb/core'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここで shun159/active_flow に依存してしまうと、依存先が trema/active_flow と phut の active_flow とこの active_flow で 3 つになってしまうので 笑、まずは phut のほうにクラスをコピーしてもらうのが良いと思います (ライセンスなど問題がなければ)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

しょうちしました。

Copy link
Member Author

@shun159 shun159 Jun 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コピーしてきました。
7ee0730


group :guard do
gem 'guard', require: false
gem 'guard-bundler', require: false
Expand Down
28 changes: 28 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
GIT
remote: git://github.com/shun159/active_flow.git
revision: cfca63f79a926cdf6733f523bac05ea859331fd8
branch: feature/ovsdb/core
specs:
active_flow (0.0.1)
activemodel (~> 4.2, >= 4.2.6)
activesupport (~> 4.2, >= 4.2.6)
bundler (~> 1.11.2)
ffi-yajl (~> 2.2.3)
multi_json (>= 1.11.1)
representable (~> 3.0.0)
yajl-ruby (~> 1.2.1)

PATH
remote: .
specs:
Expand All @@ -10,6 +24,9 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activemodel (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
Expand Down Expand Up @@ -58,6 +75,8 @@ GEM
cucumber-core (1.5.0)
gherkin (~> 4.0)
cucumber-wire (0.0.1)
declarative (0.0.7)
uber (>= 0.0.15)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.2.5)
Expand All @@ -69,6 +88,8 @@ GEM
faker (1.6.3)
i18n (~> 0.5)
ffi (1.9.10)
ffi-yajl (2.2.3)
libyajl2 (~> 1.2)
flay (2.8.0)
erubis (~> 2.7.0)
path_expander (~> 1.0)
Expand Down Expand Up @@ -113,6 +134,7 @@ GEM
i18n (0.7.0)
ice_nine (0.11.2)
json (1.8.3)
libyajl2 (1.2.0)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand Down Expand Up @@ -151,6 +173,9 @@ GEM
archive-tar-minitar (>= 0.5.2)
json (>= 1.4.6)
rest-client (>= 1.7.2)
representable (3.0.0)
declarative (~> 0.0.5)
uber (~> 0.0.15)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
Expand Down Expand Up @@ -196,6 +221,7 @@ GEM
tins (1.6.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uber (0.0.15)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
Expand All @@ -205,12 +231,14 @@ GEM
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
yajl-ruby (1.2.1)
yard (0.8.7.6)

PLATFORMS
ruby

DEPENDENCIES
active_flow!
aruba
codeclimate-test-reporter
coveralls
Expand Down
1 change: 1 addition & 0 deletions lib/phut/open_vswitch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def <=>(other)
private

def start
@vsctl.set_manager
@vsctl.add_bridge
@vsctl.set_openflow_version_and_dpid
@vsctl.controller_tcp_port = @tcp_port
Expand Down
25 changes: 24 additions & 1 deletion lib/phut/vsctl.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# frozen_string_literal: true
require 'phut/shell_runner'
require 'pio'
require 'active_flow'

module Phut
# ovs-vsctl wrapper
class Vsctl
extend ShellRunner
include ActiveFlow::OVSDB::Transact
extend ActiveFlow::OVSDB::Transact

def self.list_br(prefix)
sudo('ovs-vsctl list-br').split.each_with_object([]) do |each, list|
Expand All @@ -18,6 +21,7 @@ def self.list_br(prefix)
include ShellRunner

def initialize(name:, name_prefix:, dpid:, bridge:)
@client = ActiveFlow::OVSDB::Client.new('localhost', 6632)
@name = name
@prefix = name_prefix
@dpid = dpid
Expand All @@ -38,6 +42,10 @@ def del_bridge
sudo "ovs-vsctl del-br #{@bridge}"
end

def set_manager
sudo 'ovs-vsctl set-manager ptcp:6632'
end

def set_openflow_version_and_dpid
sudo "ovs-vsctl set bridge #{@bridge} "\
"protocols=#{Pio::OpenFlow.version} "\
Expand Down Expand Up @@ -75,7 +83,22 @@ def bring_port_down(port_number)
end

def ports
sudo("ovs-vsctl list-ports #{@bridge}").split
br_query = [select('Bridge', [[:name, :==, @bridge]], [:ports])]
br_ports = @client.transact(1, 'Open_vSwitch', br_query).first[:rows].first[:ports]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [89/80]

ports = if br_ports.include? "set"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

br_ports[1]
else
[br_ports]
end
port_query = ports.map do |port|
select('Port', [[:_uuid, :==, port]], [:name])
end
iface_query = @client.transact(1, 'Open_vSwitch', port_query).map do |iface|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [82/80]

select('Interface', [[:name, :==, iface[:rows].first[:name]]], [:ofport, :name])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [88/80]

end
@client.transact(1, 'Open_vSwitch', iface_query).map do |iface|
OpenStruct.new(iface[:rows].first)
end
end

private
Expand Down