-
Notifications
You must be signed in to change notification settings - Fork 30
Mac support #151
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
Closed
Closed
Mac support #151
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
lib/linux_admin/network_interface/network_interface_mac.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'socket' | ||
|
||
module LinuxAdmin | ||
class NetworkInterfaceMac < NetworkInterface | ||
# Determine the ip address of a ipv4 (non loopback) interface | ||
# NOTE: currently ignores the interface name | ||
# | ||
# @return [String] The command output | ||
# @raise [NetworkInterfaceError] if the command fails | ||
def ip_show | ||
socket = Socket.ip_address_list.detect { |intf| intf.ipv4? && !intf.ipv4_loopback? } | ||
if socket | ||
socket.ip_address | ||
else | ||
raise NetworkInterfaceError.new("could not find ipv4 interface", 4) | ||
end | ||
end | ||
|
||
# Determine the Runs the command `ip route` | ||
# | ||
# @return [String] The command output | ||
# @raise [NetworkInterfaceError] if the command fails | ||
def ip_route | ||
gateway = run!(cmd("route"), :params => %w(-n get default)).output | ||
.split("\n").detect { |l| l =~ /gateway/ }.split(":").last.strip | ||
"default via #{gateway} dev #{@interface}" | ||
rescue AwesomeSpawn::CommandResultError => e | ||
raise NetworkInterfaceError.new(e.message, e.result) | ||
end | ||
|
||
def parse_conf | ||
# currently a noop | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,12 @@ class TimeDate | |
TimeCommandError = Class.new(StandardError) | ||
|
||
def self.system_timezone_detailed | ||
result = run(cmd(COMMAND), :params => ["status"]) | ||
result = run!(cmd(COMMAND), :params => ["status"]) | ||
result.output.split("\n").each do |l| | ||
return l.split(':')[1].strip if l =~ /Time.*zone/ | ||
end | ||
rescue AwesomeSpawn::CommandResultError, AwesomeSpawn::NoSuchFileError | ||
Time.now.zone | ||
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. This isn't the same result as what we would get from |
||
end | ||
|
||
def self.system_timezone | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
describe LinuxAdmin::NetworkInterfaceMac do | ||
it "raises exception if none found" do | ||
expect(Socket).to receive(:ip_address_list).and_return([]) | ||
expect { described_class.new("eth0") }.to raise_error(LinuxAdmin::NetworkInterfaceError) | ||
end | ||
|
||
it "returns the ip of the first ipv4 non loopback device" do | ||
expect(Socket).to receive(:ip_address_list).at_least(:once).and_return([ | ||
double(:ipv4? => false, :ipv4_loopback? => false, :ip_address => "::1"), | ||
double(:ipv4? => true, :ipv4_loopback? => true, :ip_address => "127.0.0.1"), | ||
double(:ipv4? => true, :ipv4_loopback? => false, :ip_address => "192.168.10.10"), | ||
]) | ||
expect_any_instance_of(described_class).to receive(:ip_route).and_return("1921.68.1.1") | ||
ip = described_class.new("eth0") | ||
expect(ip.ip_show).to eq("192.168.10.10") | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe this can all be:
I think it's nicer than the array include followed by
==