networkmanager-dbus 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rbenv-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +6 -0
- data/MIT-LICENSE +20 -0
- data/README.md +37 -0
- data/Rakefile +65 -0
- data/TODO.md +11 -0
- data/examples/connectivity.rb +7 -0
- data/examples/list_ips.rb +6 -0
- data/lib/dbus_interface/class.rb +32 -0
- data/lib/dbus_interface/object.rb +35 -0
- data/lib/dbus_interface.rb +21 -0
- data/lib/network_manager/dbus/active_connection.rb +4 -0
- data/lib/network_manager/dbus/device.rb +65 -0
- data/lib/network_manager/dbus/dhcp4_config.rb +4 -0
- data/lib/network_manager/dbus/ethernet_device.rb +4 -0
- data/lib/network_manager/dbus/ip4_config.rb +4 -0
- data/lib/network_manager/dbus/root.rb +47 -0
- data/lib/network_manager/dbus/settings.rb +21 -0
- data/lib/network_manager/dbus/settings_connection.rb +4 -0
- data/lib/network_manager/dbus.rb +6 -0
- data/lib/network_manager/ip4_helper.rb +14 -0
- data/lib/network_manager/version.rb +3 -0
- data/lib/network_manager.rb +28 -0
- data/lib/networkmanager-dbus.rb +1 -0
- data/networkmanager-dbus.gemspec +30 -0
- data/script/spec_client +10 -0
- data/script/spec_server +18 -0
- data/spec/fixtures/devices.yml +60 -0
- data/spec/fixtures/settings.yml +14 -0
- data/spec/network_manager/dbus/active_connection_spec.rb +19 -0
- data/spec/network_manager/dbus/device_spec.rb +36 -0
- data/spec/network_manager/dbus/dhcp4_config_spec.rb +14 -0
- data/spec/network_manager/dbus/ethernet_device_spec.rb +21 -0
- data/spec/network_manager/dbus/ip4_config_spec.rb +14 -0
- data/spec/network_manager/dbus/root_spec.rb +22 -0
- data/spec/network_manager/dbus/settings_connection_spec.rb +13 -0
- data/spec/network_manager/dbus/settings_spec.rb +30 -0
- data/spec/network_manager_spec.rb +12 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/support/fixture_helper.rb +11 -0
- metadata +175 -0
data/.gitignore
ADDED
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.2-p290
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jens Bissinger
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# NetworkManager-Ruby
|
2
|
+
|
3
|
+
This library provides a Ruby API to NetworkManager using its DBus Interface.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Please make sure that you have `dbus` and `networkmanager` installed on the machine
|
8
|
+
were you want to use this library. Remote DBus wasn't tested.
|
9
|
+
|
10
|
+
gem install networkmanager-dbus
|
11
|
+
|
12
|
+
## Examples
|
13
|
+
|
14
|
+
At the moment this is incomplete. So for now,
|
15
|
+
please have a look at the `examples` folder and the `specs`.
|
16
|
+
|
17
|
+
require 'networkmanager-dbus'
|
18
|
+
NetworkManager.devices.first['Interface'] # => 'eth0' or something similar
|
19
|
+
NetworkManager.settings.hostname # => 'your.host.name'
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
Development currently happens from my OSX machine where no dbus/networkmanager
|
24
|
+
is running. Therefore, i hacked some scripts together to be able to run rspec
|
25
|
+
over the wire
|
26
|
+
|
27
|
+
On the remote-machine (linux, dbus, networkmanager)
|
28
|
+
|
29
|
+
`script/spec_server`
|
30
|
+
|
31
|
+
On the local-machine (osx)
|
32
|
+
|
33
|
+
`guard`
|
34
|
+
|
35
|
+
# License
|
36
|
+
|
37
|
+
Please see file `MIT-LICENSE`. Copyright 2011 Jens Bissinger.
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
def pump_dumps(dumps)
|
4
|
+
dumps.each do |obj|
|
5
|
+
case obj['action']
|
6
|
+
when 'dump_failures'
|
7
|
+
|
8
|
+
puts "\n"*50
|
9
|
+
puts "= RSPEC START "*10
|
10
|
+
|
11
|
+
failures = obj['body'].map do |spec, exception, backtrace|
|
12
|
+
|
13
|
+
puts "\n"
|
14
|
+
puts " #{spec} (FAILED)"
|
15
|
+
puts " #{"- "*10}"
|
16
|
+
puts " #{exception}"
|
17
|
+
puts " #{backtrace.join("\n ")}"
|
18
|
+
|
19
|
+
[spec,exception].join("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
puts ""
|
23
|
+
puts "= RSPEC END "*10
|
24
|
+
|
25
|
+
Growl.notify(failures.join("\n\n"), {:title => "#{failures.size} specs failed", :name => 'rspec'})
|
26
|
+
when 'dump_summary'
|
27
|
+
total = obj['body']['example_count']
|
28
|
+
failed = obj['body']['failure_count']
|
29
|
+
pending = obj['body']['pending_count']
|
30
|
+
succeded = total - (obj['body']['failure_count'] + obj['body']['pending_count'])
|
31
|
+
|
32
|
+
title = "#{total} specs finished in #{obj['body']['duration'].round(1)}s"
|
33
|
+
msg = "#{failed} failed, #{pending} pending, #{succeded} succeded"
|
34
|
+
Growl.notify(msg, {:title => title, :name => 'rspec'})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
namespace :spec do
|
40
|
+
desc 'run specs on a remote server (script/spec_server)'
|
41
|
+
task :remote do
|
42
|
+
begin
|
43
|
+
client = MarilynRPC::NativeClient.connect_tcp('192.168.56.101', 8483)
|
44
|
+
runner = client.for :rspec
|
45
|
+
json = runner.run
|
46
|
+
begin
|
47
|
+
dumps = JSON.parse(json)
|
48
|
+
pump_dumps(dumps)
|
49
|
+
rescue => e
|
50
|
+
title = "ERROR: Tests were broken #{e}!"
|
51
|
+
msg = json
|
52
|
+
puts msg
|
53
|
+
puts title
|
54
|
+
Growl.notify(msg, {:title => title, :name => 'rspec'})
|
55
|
+
end
|
56
|
+
rescue => e
|
57
|
+
title = "FATAL: Spec server down!?"
|
58
|
+
msg = e.to_s
|
59
|
+
puts title
|
60
|
+
puts msg
|
61
|
+
Growl.notify(msg, {:title => title, :name => 'rspec'})
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/TODO.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '../lib/network_manager')
|
2
|
+
|
3
|
+
puts "Internet Connection: #{NetworkManager.internet_connection? ? 'yes' : 'no'}"
|
4
|
+
|
5
|
+
puts "States are described as NM_STATE_... in NetworkManager::DBus::Root"
|
6
|
+
puts "State is == #{NetworkManager::DBus::Root.instance.object.state}"
|
7
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module DBusInterface::Class
|
2
|
+
def map_dbus(conf)
|
3
|
+
@dbus ||= begin
|
4
|
+
# ensure hash
|
5
|
+
raise ArgumentError.new "adapt_dbus must receive a hash instead of"\
|
6
|
+
"#{conf.class}" unless conf.is_a? Hash
|
7
|
+
# ensure :default_iface is set
|
8
|
+
raise ArgumentError.new "adapt_dbus must specify at least :default_iface"\
|
9
|
+
unless conf.has_key? :default_iface
|
10
|
+
conf
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_iface
|
15
|
+
dbus[:default_iface]
|
16
|
+
end
|
17
|
+
|
18
|
+
def object_path
|
19
|
+
dbus[:object_path]
|
20
|
+
end
|
21
|
+
|
22
|
+
# singletons must be given an :object_path
|
23
|
+
def instance
|
24
|
+
@instance ||= new
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def dbus
|
30
|
+
@dbus
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module DBusInterface::Object
|
2
|
+
def self.included(some_base)
|
3
|
+
some_base.extend(DBusInterface::Class)
|
4
|
+
end
|
5
|
+
|
6
|
+
def object
|
7
|
+
@object ||= begin
|
8
|
+
object = DBusInterface.service.object(object_path)
|
9
|
+
object.default_iface = self.class.default_iface
|
10
|
+
object.introspect
|
11
|
+
object
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def properties
|
16
|
+
object.all_properties
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(object_path = nil)
|
20
|
+
self.object_path = object_path if object_path
|
21
|
+
end
|
22
|
+
|
23
|
+
def object_path=(p)
|
24
|
+
@object_path = p
|
25
|
+
end
|
26
|
+
|
27
|
+
def object_path
|
28
|
+
@object_path || self.class.object_path
|
29
|
+
end
|
30
|
+
|
31
|
+
# shortcut to access properties
|
32
|
+
def [](key)
|
33
|
+
properties[key]
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DBusInterface
|
2
|
+
require 'dbus'
|
3
|
+
require File.join(File.dirname(__FILE__), 'dbus_interface/class')
|
4
|
+
require File.join(File.dirname(__FILE__), 'dbus_interface/object')
|
5
|
+
|
6
|
+
def self.system_bus
|
7
|
+
::DBus::SystemBus.instance
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.service
|
11
|
+
@@service
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.service=(s)
|
15
|
+
@@service = system_bus.service s
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure(&block)
|
19
|
+
yield self
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class NetworkManager::DBus::Device
|
2
|
+
include DBusInterface::Object
|
3
|
+
map_dbus :default_iface => 'org.freedesktop.NetworkManager.Device'
|
4
|
+
|
5
|
+
NM_DEVICE_TYPE__PROPERTY = 'DeviceType'
|
6
|
+
# The device type is unknown.
|
7
|
+
NM_DEVICE_TYPE_UNKNOWN = 0
|
8
|
+
# The device is wired Ethernet device.
|
9
|
+
NM_DEVICE_TYPE_ETHERNET = 1
|
10
|
+
# The device is an 802.11 WiFi device.
|
11
|
+
NM_DEVICE_TYPE_WIFI = 2
|
12
|
+
# Unused
|
13
|
+
NM_DEVICE_TYPE_UNUSED1 = 3
|
14
|
+
# Unused
|
15
|
+
NM_DEVICE_TYPE_UNUSED2 = 4
|
16
|
+
# The device is Bluetooth device that provides PAN or DUN capabilities.
|
17
|
+
NM_DEVICE_TYPE_BT = 5
|
18
|
+
# The device is an OLPC mesh networking device.
|
19
|
+
NM_DEVICE_TYPE_OLPC_MESH = 6
|
20
|
+
# The device is an 802.16e Mobile WiMAX device.
|
21
|
+
NM_DEVICE_TYPE_WIMAX = 7
|
22
|
+
# The device is a modem
|
23
|
+
# supporting one or more of analog telephone, CDMA/EVDO, GSM/UMTS/HSPA,
|
24
|
+
# or LTE standards to access a cellular or wireline data network.
|
25
|
+
NM_DEVICE_TYPE_MODEM = 8
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
"#{self.class} #{properties}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def ip4_address
|
32
|
+
@ip_addr ||= begin
|
33
|
+
ip4_int = self['Ip4Address']
|
34
|
+
NetworkManager::Ip4Helper.ip4_integer_to_dot_decimal ip4_int
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [NetworkManager::DBus::Ip4Config] conf
|
39
|
+
def ip4_config
|
40
|
+
@ip4_config ||= NetworkManager::DBus::Ip4Config.new properties['Ip4Config']
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [NetworkManager::DBus::ActiveConnection] con
|
44
|
+
def active_connection
|
45
|
+
@active_connection ||=
|
46
|
+
NetworkManager::DBus::ActiveConnection.new properties['ActiveConnection']
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# ETHERNET
|
51
|
+
#
|
52
|
+
|
53
|
+
def ethernet?
|
54
|
+
properties[NM_DEVICE_TYPE__PROPERTY] == NM_DEVICE_TYPE_ETHERNET
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [NetworkManager::DBus::EthernetDevice] dev
|
58
|
+
def ethernet
|
59
|
+
if ethernet?
|
60
|
+
@ethernet ||= NetworkManager::DBus::EthernetDevice.new(self.object_path)
|
61
|
+
else
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class NetworkManager::DBus::Root
|
2
|
+
include DBusInterface::Object
|
3
|
+
map_dbus :default_iface => 'org.freedesktop.NetworkManager',
|
4
|
+
:object_path => '/org/freedesktop/NetworkManager'
|
5
|
+
|
6
|
+
# Networking state is unknown.
|
7
|
+
NM_STATE_UNKNOWN = 0
|
8
|
+
# Networking is inactive and all devices are disabled.
|
9
|
+
NM_STATE_ASLEEP = 10
|
10
|
+
# There is no active network connection.
|
11
|
+
NM_STATE_DISCONNECTED = 20
|
12
|
+
# Network connections are being cleaned up.
|
13
|
+
NM_STATE_DISCONNECTING = 30
|
14
|
+
# A network device is connecting to a network and there is no other available network connection.
|
15
|
+
NM_STATE_CONNECTING = 40
|
16
|
+
# A network device is connected, but there is only link-local connectivity.
|
17
|
+
NM_STATE_CONNECTED_LOCAL = 50
|
18
|
+
# A network device is connected, but there is only site-local connectivity.
|
19
|
+
NM_STATE_CONNECTED_SITE = 60
|
20
|
+
# A network device is connected, with global network connectivity.
|
21
|
+
NM_STATE_CONNECTED_GLOBAL = 70
|
22
|
+
|
23
|
+
# @return [Array<NetworkManager::DBus::Device>]] devices
|
24
|
+
def self.devices
|
25
|
+
instance.object.GetDevices.map do |list|
|
26
|
+
list.map do |object_path|
|
27
|
+
new_device(object_path)
|
28
|
+
end
|
29
|
+
end.flatten
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.device_by_interface(interface)
|
33
|
+
paths = instance.object.GetDeviceByIpIface(interface)
|
34
|
+
paths.empty? ? nil : new_device(paths.first)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.internet_connection?
|
38
|
+
instance.object.state.first == NM_STATE_CONNECTED_GLOBAL
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def self.new_device(object_path)
|
44
|
+
NetworkManager::DBus::Device.new object_path
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class NetworkManager::DBus::Settings
|
2
|
+
include DBusInterface::Object
|
3
|
+
map_dbus :default_iface => 'org.freedesktop.NetworkManager.Settings',
|
4
|
+
:object_path => '/org/freedesktop/NetworkManager/Settings'
|
5
|
+
|
6
|
+
def self.connections
|
7
|
+
instance.object.ListConnections.map do |list|
|
8
|
+
list.map do |object_path|
|
9
|
+
::NetworkManager::DBus::SettingsConnection.new(object_path)
|
10
|
+
end
|
11
|
+
end.flatten
|
12
|
+
end
|
13
|
+
|
14
|
+
def hostname=(new_name)
|
15
|
+
object.SaveHostname(new_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def hostname
|
19
|
+
properties['Hostname']
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module NetworkManager::Ip4Helper
|
2
|
+
def self.ip4_integer_to_dot_decimal(ip4_integer)
|
3
|
+
integer = ip4_integer
|
4
|
+
result = []
|
5
|
+
4.times.map do
|
6
|
+
# bitwise AND 255 bits
|
7
|
+
result.push integer & 255
|
8
|
+
|
9
|
+
# bitwise SHIFT RIGHT 8 bits
|
10
|
+
integer = integer >> 8
|
11
|
+
end
|
12
|
+
result.join '.'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# This Library provides an API based on the specs for network manager dbus api
|
2
|
+
# found here: http://projects.gnome.org/NetworkManager/developers/api/09/spec.html
|
3
|
+
module NetworkManager
|
4
|
+
# generic dbus api
|
5
|
+
require File.join(File.dirname(__FILE__), 'dbus_interface')
|
6
|
+
|
7
|
+
# version
|
8
|
+
require File.join(File.dirname(__FILE__), 'network_manager/version')
|
9
|
+
|
10
|
+
# helper
|
11
|
+
require File.join(File.dirname(__FILE__), 'network_manager/ip4_helper')
|
12
|
+
|
13
|
+
# network manager dbus api
|
14
|
+
require File.join(File.dirname(__FILE__), 'network_manager/dbus')
|
15
|
+
|
16
|
+
def self.settings
|
17
|
+
NetworkManager::DBus::Settings.instance
|
18
|
+
end
|
19
|
+
|
20
|
+
# delegate to dbus root object
|
21
|
+
def self.method_missing(*args)
|
22
|
+
NetworkManager::DBus::Root.send(*args)
|
23
|
+
end
|
24
|
+
|
25
|
+
DBusInterface.configure do |config|
|
26
|
+
config.service = 'org.freedesktop.NetworkManager'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "network_manager"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "network_manager/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "networkmanager-dbus"
|
7
|
+
s.version = NetworkManager::VERSION
|
8
|
+
s.authors = ["Jens Bissinger"]
|
9
|
+
s.email = ["whiterabbit.init@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{NetworkManager Interface written in Ruby}
|
12
|
+
s.description = %q{Utilizing the official NetworkManager DBus API}
|
13
|
+
|
14
|
+
s.rubyforge_project = "networkmanager-dbus"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# dependencies
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "guard"
|
25
|
+
s.add_development_dependency "guard-shell"
|
26
|
+
s.add_development_dependency "growl"
|
27
|
+
s.add_development_dependency "json"
|
28
|
+
s.add_development_dependency "marilyn-rpc"
|
29
|
+
s.add_runtime_dependency "ruby-dbus"
|
30
|
+
end
|
data/script/spec_client
ADDED
data/script/spec_server
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'marilyn-rpc'
|
5
|
+
require 'eventmachine'
|
6
|
+
|
7
|
+
class RSpecRunner < MarilynRPC::Service
|
8
|
+
register :rspec
|
9
|
+
|
10
|
+
def run()
|
11
|
+
`rspec`
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
EM.run {
|
16
|
+
EM.start_server "192.168.56.101", 8483, MarilynRPC::Server
|
17
|
+
puts "Marilyn has entered the stage, playing port 8483"
|
18
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
0:
|
2
|
+
properties:
|
3
|
+
"Interface": "eth0"
|
4
|
+
"Ip4Address": 1698212032
|
5
|
+
"Udi": "/sys/devices/pci0000:00/0000:00:03.0/net/eth0"
|
6
|
+
"Interface": "eth0"
|
7
|
+
"IpInterface": "eth0"
|
8
|
+
"Driver": "e1000"
|
9
|
+
"Capabilities": 3
|
10
|
+
"State": 100
|
11
|
+
"ActiveConnection": "/org/freedesktop/NetworkManager/ActiveConnection/0"
|
12
|
+
"Ip4Config": "/org/freedesktop/NetworkManager/IP4Config/1"
|
13
|
+
"Dhcp4Config": "/org/freedesktop/NetworkManager/DHCP4Config/0"
|
14
|
+
"Ip6Config": "/"
|
15
|
+
"Dhcp6Config": "/"
|
16
|
+
"Managed": yes
|
17
|
+
"FirmwareMissing": no
|
18
|
+
"DeviceType": 1
|
19
|
+
ethernet:
|
20
|
+
properties:
|
21
|
+
"HwAddress": "08:00:27:FB:3B:10"
|
22
|
+
"PermHwAddress": "08:00:27:FB:3B:10"
|
23
|
+
"Speed": 1000
|
24
|
+
"Carrier": yes
|
25
|
+
ip4_config:
|
26
|
+
0:
|
27
|
+
properties:
|
28
|
+
"Addresses": [ [1698212032, 24, 0] ]
|
29
|
+
"Nameservers": []
|
30
|
+
"WinsServers": []
|
31
|
+
"Domains": []
|
32
|
+
"Routes": []
|
33
|
+
dhcp4_config:
|
34
|
+
properties:
|
35
|
+
"Options":
|
36
|
+
"4163": "4163"
|
37
|
+
"1500": "1500"
|
38
|
+
"subnet_cidr": "24"
|
39
|
+
"broadcast_address": "192.168.56.255"
|
40
|
+
"dhcp_message_type": "5"
|
41
|
+
"eth0": "eth0"
|
42
|
+
"dhcp_lease_time": "3600"
|
43
|
+
"ip_address": "192.168.56.101"
|
44
|
+
"subnet_mask": "255.255.255.0"
|
45
|
+
"0": "0"
|
46
|
+
"202": "202"
|
47
|
+
"lookup-hostname": "lookup-hostname"
|
48
|
+
"network_number": "192.168.56.0"
|
49
|
+
"dhcp_server_identifier": "192.168.56.100"
|
50
|
+
active_connection:
|
51
|
+
properties:
|
52
|
+
"Connection": "/org/freedesktop/NetworkManager/Settings/0"
|
53
|
+
"SpecificObject": "/"
|
54
|
+
"Uuid": "9bd14d22-6da6-45d0-b68a-596c3c3297c2"
|
55
|
+
"Devices": ["/org/freedesktop/NetworkManager/Devices/0"]
|
56
|
+
"State": 2
|
57
|
+
"Default": no
|
58
|
+
"Default6": no
|
59
|
+
"Vpn": no
|
60
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
properties:
|
2
|
+
Hostname: 'dev-vm'
|
3
|
+
CanModify: yes
|
4
|
+
connections:
|
5
|
+
-
|
6
|
+
settings:
|
7
|
+
"connection":
|
8
|
+
"id": "Wired connection 1"
|
9
|
+
"uuid": "6190ee1e-c5c5-41f5-8de3-500d229970f9"
|
10
|
+
"timestamp": "1320083832"
|
11
|
+
"type": "802-3-ethernet"
|
12
|
+
"802-3-ethernet":
|
13
|
+
"s390-options": {}
|
14
|
+
"mac-address": [8, 0, 39, 251, 59, 16]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::ActiveConnection" do
|
4
|
+
before :each do
|
5
|
+
@devices = fixture('devices.yml')
|
6
|
+
@device = @devices[0]
|
7
|
+
@config = @device['active_connection']
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should map interface "org.freedesktop.NetworkManager.Connection.Active"' do
|
11
|
+
NetworkManager::DBus::ActiveConnection.default_iface.should ==
|
12
|
+
'org.freedesktop.NetworkManager.Connection.Active'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'shoud list properties' do
|
16
|
+
config = NetworkManager::DBus::ActiveConnection.new @device['properties']['ActiveConnection']
|
17
|
+
config.properties.should == @config['properties']
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::Device" do
|
4
|
+
before :each do
|
5
|
+
@devices = fixture('devices.yml')
|
6
|
+
@list = NetworkManager::DBus::Root.devices
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should list poperties" do
|
10
|
+
# simple test
|
11
|
+
@list.first.properties['Interface'].should ==
|
12
|
+
@devices[0]['properties']['Interface']
|
13
|
+
|
14
|
+
# total comparison
|
15
|
+
@list.first.properties.should ==
|
16
|
+
@devices[0]['properties']
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "NM_DEVICE_TYPE" do
|
20
|
+
it "should detect ethernet devices" do
|
21
|
+
@list.first.ethernet?.should == true
|
22
|
+
@list.first.ethernet.class.should ==
|
23
|
+
NetworkManager::DBus::EthernetDevice
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should provide ip4_config' do
|
28
|
+
@list.first.ip4_config.class.should ==
|
29
|
+
NetworkManager::DBus::Ip4Config
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should provide active_connection' do
|
33
|
+
@list.first.active_connection.class.should ==
|
34
|
+
NetworkManager::DBus::ActiveConnection
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::Dhcp4Config" do
|
4
|
+
before :each do
|
5
|
+
@devices = fixture('devices.yml')
|
6
|
+
@device = @devices[0]
|
7
|
+
@config = @device['dhcp4_config']
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'shoud list properties' do
|
11
|
+
config = NetworkManager::DBus::Dhcp4Config.new @device['properties']['Dhcp4Config']
|
12
|
+
config.properties.should == @config['properties']
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::EthernetDevice" do
|
4
|
+
before :each do
|
5
|
+
@devices = fixture('devices.yml')
|
6
|
+
@device = @devices[0]
|
7
|
+
@ethernet_device = @device['ethernet']
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should list poperties" do
|
11
|
+
object_path = NetworkManager::DBus::Root.devices.first.object_path
|
12
|
+
ethernet_device = NetworkManager::DBus::EthernetDevice.new object_path
|
13
|
+
|
14
|
+
# simple test
|
15
|
+
ethernet_device.properties['HwAddress'].should ==
|
16
|
+
@ethernet_device['properties']['HwAddress']
|
17
|
+
|
18
|
+
# total comparison
|
19
|
+
ethernet_device.properties.should == @ethernet_device['properties']
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::Ip4Config" do
|
4
|
+
before :each do
|
5
|
+
@devices = fixture('devices.yml')
|
6
|
+
@device = @devices[0]
|
7
|
+
@config = @device['ip4_config'][0]
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'shoud list properties' do
|
11
|
+
config = NetworkManager::DBus::Ip4Config.new @device['properties']['Ip4Config']
|
12
|
+
config.properties.should == @config['properties']
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::Root" do
|
4
|
+
before :each do
|
5
|
+
@devices = fixture('devices.yml')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should list devices" do
|
9
|
+
list = NetworkManager::DBus::Root.devices
|
10
|
+
list.size.should > 0
|
11
|
+
list.first.class.should == NetworkManager::DBus::Device
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return device_by_interface" do
|
15
|
+
dev = NetworkManager::DBus::Root.device_by_interface 'eth0'
|
16
|
+
dev.properties.should == @devices[0]['properties']
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should tell about internet_connection?' do
|
20
|
+
NetworkManager::DBus::Root.internet_connection?.should be_true
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::SettingsConnection" do
|
4
|
+
before :each do
|
5
|
+
@settings = fixture('settings.yml')
|
6
|
+
@connection = @settings['connections'][0]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should get settings" do
|
10
|
+
NetworkManager::DBus::Settings.connections.first.object.GetSettings.first['connection']['id'].should ==
|
11
|
+
@connection['settings']['connection']['id']
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager::DBus::Settings" do
|
4
|
+
before :each do
|
5
|
+
@settings = fixture('settings.yml')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should provide properties" do
|
9
|
+
NetworkManager::DBus::Settings.instance.properties.should == @settings['properties']
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should list connections" do
|
13
|
+
NetworkManager::DBus::Settings.connections.size.should == 3
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'hostname' do
|
17
|
+
after :each do
|
18
|
+
NetworkManager::DBus::Settings.instance.hostname = @settings['properties']['Hostname']
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should get hostname' do
|
22
|
+
NetworkManager::DBus::Settings.instance.hostname.should == @settings['properties']['Hostname']
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should set hostname' do
|
26
|
+
NetworkManager::DBus::Settings.instance.hostname = 'a-host-name'
|
27
|
+
NetworkManager::DBus::Settings.instance.hostname.should == 'a-host-name'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NetworkManager" do
|
4
|
+
it 'should expose all devices' do
|
5
|
+
NetworkManager.devices.size.should == NetworkManager::DBus::Root.devices.size
|
6
|
+
NetworkManager.devices.first.class.should == NetworkManager::DBus::Device
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should expose settings' do
|
10
|
+
NetworkManager.settings.should == NetworkManager::DBus::Settings.instance
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# load spec helper
|
2
|
+
require File.join(File.dirname(__FILE__), 'support/fixture_helper.rb')
|
3
|
+
|
4
|
+
# load lib
|
5
|
+
require File.join(File.dirname(__FILE__), '../lib/network_manager')
|
6
|
+
|
7
|
+
require 'json'
|
8
|
+
require 'rspec/core/formatters/base_formatter'
|
9
|
+
class JsonFormatter < RSpec::Core::Formatters::BaseFormatter
|
10
|
+
|
11
|
+
def start(example_count)
|
12
|
+
@_dump_out = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def close
|
16
|
+
output.puts ::JSON.generate(@_dump_out)
|
17
|
+
end
|
18
|
+
|
19
|
+
def dump_failures
|
20
|
+
return if failed_examples.empty?
|
21
|
+
map = failed_examples.map do |example|
|
22
|
+
#example.metadata
|
23
|
+
[ example.full_description,
|
24
|
+
example.metadata[:execution_result][:exception].message,
|
25
|
+
example.metadata[:execution_result][:exception].backtrace ]
|
26
|
+
end
|
27
|
+
@_dump_out << {:action => :dump_failures, :body => map}
|
28
|
+
end
|
29
|
+
|
30
|
+
def dump_summary(duration, example_count, failure_count, pending_count)
|
31
|
+
@_dump_out << {:action => :dump_summary, :body => {
|
32
|
+
:duration => duration,
|
33
|
+
:example_count => example_count,
|
34
|
+
:failure_count => failure_count,
|
35
|
+
:pending_count => pending_count}}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
RSpec.configure do |config|
|
40
|
+
config.formatter = 'JsonFormatter'
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: networkmanager-dbus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jens Bissinger
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-01 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70103547674940 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70103547674940
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70103547663160 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70103547663160
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: guard
|
38
|
+
requirement: &70103547662100 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70103547662100
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: guard-shell
|
49
|
+
requirement: &70103547660880 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70103547660880
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: growl
|
60
|
+
requirement: &70103547659060 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70103547659060
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json
|
71
|
+
requirement: &70103547657180 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70103547657180
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: marilyn-rpc
|
82
|
+
requirement: &70103547656600 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70103547656600
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: ruby-dbus
|
93
|
+
requirement: &70103547656060 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70103547656060
|
102
|
+
description: Utilizing the official NetworkManager DBus API
|
103
|
+
email:
|
104
|
+
- whiterabbit.init@gmail.com
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- .gitignore
|
110
|
+
- .rbenv-version
|
111
|
+
- Gemfile
|
112
|
+
- Guardfile
|
113
|
+
- MIT-LICENSE
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- TODO.md
|
117
|
+
- examples/connectivity.rb
|
118
|
+
- examples/list_ips.rb
|
119
|
+
- lib/dbus_interface.rb
|
120
|
+
- lib/dbus_interface/class.rb
|
121
|
+
- lib/dbus_interface/object.rb
|
122
|
+
- lib/network_manager.rb
|
123
|
+
- lib/network_manager/dbus.rb
|
124
|
+
- lib/network_manager/dbus/active_connection.rb
|
125
|
+
- lib/network_manager/dbus/device.rb
|
126
|
+
- lib/network_manager/dbus/dhcp4_config.rb
|
127
|
+
- lib/network_manager/dbus/ethernet_device.rb
|
128
|
+
- lib/network_manager/dbus/ip4_config.rb
|
129
|
+
- lib/network_manager/dbus/root.rb
|
130
|
+
- lib/network_manager/dbus/settings.rb
|
131
|
+
- lib/network_manager/dbus/settings_connection.rb
|
132
|
+
- lib/network_manager/ip4_helper.rb
|
133
|
+
- lib/network_manager/version.rb
|
134
|
+
- lib/networkmanager-dbus.rb
|
135
|
+
- networkmanager-dbus.gemspec
|
136
|
+
- script/spec_client
|
137
|
+
- script/spec_server
|
138
|
+
- spec/fixtures/devices.yml
|
139
|
+
- spec/fixtures/settings.yml
|
140
|
+
- spec/network_manager/dbus/active_connection_spec.rb
|
141
|
+
- spec/network_manager/dbus/device_spec.rb
|
142
|
+
- spec/network_manager/dbus/dhcp4_config_spec.rb
|
143
|
+
- spec/network_manager/dbus/ethernet_device_spec.rb
|
144
|
+
- spec/network_manager/dbus/ip4_config_spec.rb
|
145
|
+
- spec/network_manager/dbus/root_spec.rb
|
146
|
+
- spec/network_manager/dbus/settings_connection_spec.rb
|
147
|
+
- spec/network_manager/dbus/settings_spec.rb
|
148
|
+
- spec/network_manager_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- spec/support/fixture_helper.rb
|
151
|
+
homepage: ''
|
152
|
+
licenses: []
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ! '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project: networkmanager-dbus
|
171
|
+
rubygems_version: 1.8.10
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: NetworkManager Interface written in Ruby
|
175
|
+
test_files: []
|