-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
df55d62
239eacd
7ee0730
6cba466
e7c153b
42a37e4
4af7df1
88513b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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| | ||
|
@@ -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 | ||
|
@@ -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} "\ | ||
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [89/80] |
||
ports = if br_ports.include? "set" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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 のほうにクラスをコピーしてもらうのが良いと思います (ライセンスなど問題がなければ)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
しょうちしました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コピーしてきました。
7ee0730