dbus-systemd 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/dbus-systemd.gemspec +1 -0
  3. data/lib/dbus/systemd/helpers.rb +14 -0
  4. data/lib/dbus/systemd/hostnamed.rb +10 -0
  5. data/lib/dbus/systemd/importd/manager.rb +32 -0
  6. data/lib/dbus/systemd/importd/transfer.rb +6 -0
  7. data/lib/dbus/systemd/job.rb +6 -0
  8. data/lib/dbus/systemd/localed.rb +9 -0
  9. data/lib/dbus/systemd/logind/manager.rb +71 -0
  10. data/lib/dbus/systemd/logind/seat.rb +6 -0
  11. data/lib/dbus/systemd/logind/session.rb +6 -0
  12. data/lib/dbus/systemd/logind/user.rb +6 -0
  13. data/lib/dbus/systemd/machined/image.rb +6 -0
  14. data/lib/dbus/systemd/machined/machine.rb +6 -0
  15. data/lib/dbus/systemd/machined/manager.rb +50 -0
  16. data/lib/dbus/systemd/manager.rb +50 -0
  17. data/lib/dbus/systemd/mixin.rb +14 -0
  18. data/lib/dbus/systemd/networkd/link.rb +6 -0
  19. data/lib/dbus/systemd/networkd/manager.rb +15 -0
  20. data/lib/dbus/systemd/resolved/link.rb +6 -0
  21. data/lib/dbus/systemd/resolved/manager.rb +19 -0
  22. data/lib/dbus/systemd/timedated.rb +9 -0
  23. data/lib/dbus/systemd/unit.rb +6 -0
  24. data/lib/dbus/systemd/unit/automount.rb +1 -0
  25. data/lib/dbus/systemd/unit/device.rb +1 -0
  26. data/lib/dbus/systemd/unit/mount.rb +1 -0
  27. data/lib/dbus/systemd/unit/path.rb +1 -0
  28. data/lib/dbus/systemd/unit/scope.rb +1 -0
  29. data/lib/dbus/systemd/unit/service.rb +1 -0
  30. data/lib/dbus/systemd/unit/slice.rb +1 -0
  31. data/lib/dbus/systemd/unit/snapshot.rb +1 -0
  32. data/lib/dbus/systemd/unit/socket.rb +1 -0
  33. data/lib/dbus/systemd/unit/swap.rb +1 -0
  34. data/lib/dbus/systemd/unit/target.rb +1 -0
  35. data/lib/dbus/systemd/unit/timer.rb +1 -0
  36. data/lib/dbus/systemd/version.rb +2 -1
  37. metadata +15 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0d7cb7f2cc7465907d88f909e89cfab72fc2417
4
- data.tar.gz: f883e6d2188cb5ccda2c5a995ac480a611afda26
3
+ metadata.gz: 2cc0ac2b5457ce2194acfe99f01c52535421adb1
4
+ data.tar.gz: 3a52bf67e943a51bd21a3f271db5ad8e305b714c
5
5
  SHA512:
6
- metadata.gz: 759886ec0c0824f88ded4061564ced21937a9dc090c8cc8c3069dfa5493e3d54bf1345a95d4472bf52c09ca36e0db8e3d6adf00df31c20e5fcc4fab4fe1febfc
7
- data.tar.gz: 6d54949564d74a83c60cb9ee4d300d01fe1dbc8a0411740cc6b6463632affdf05f57eca30453fc92343aeeb31983be1cb01e1cfbdc37a1c33afc8df1f00a71d2
6
+ metadata.gz: 3e684fea2e6ae0f010e2317dae780776e3cb8d2447f31c074c0aaa3484cfc82143e7f8f854ace2d06720b667235eaf13643174daffe0b42eed0046918977ab4b
7
+ data.tar.gz: c389fa2907e2080ccefb3a567bd36d753994eebaebd42957e8535161dcde793fd3ccda7c3d172e08f039a1540ecffdf8c8e1cb49bb790c2565434e8e18bfa987
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'rake', '~> 10.5'
34
34
  spec.add_development_dependency 'rspec', '~> 3.0'
35
35
  spec.add_development_dependency 'rubocop', '~> 0.43'
36
+ spec.add_development_dependency 'yard', '~> 0.9'
36
37
  end
@@ -23,14 +23,28 @@ require 'dbus'
23
23
  module DBus
24
24
  module Systemd
25
25
  module Helpers
26
+ #
27
+ # get an instance of the system bus
28
+ #
29
+ # @return [DBus::SystemBus]
26
30
  def system_bus
27
31
  DBus::SystemBus.instance
28
32
  end
29
33
 
34
+ #
35
+ # get an instance of the session bus
36
+ #
37
+ # @return [DBus::SessionBus]
30
38
  def session_bus
31
39
  DBus::SessionBus.instance
32
40
  end
33
41
 
42
+ #
43
+ # map an array to a hash from an index map
44
+ #
45
+ # @param array [Array] array to be mapped
46
+ # @param map [Hash] map of positional elements to array indices
47
+ # @return [Hash] hash with keys from map and values from array
34
48
  def map_array(array, map)
35
49
  mapped = {}
36
50
 
@@ -28,14 +28,24 @@ require_relative 'mixin'
28
28
  module DBus
29
29
  module Systemd
30
30
  class Hostnamed
31
+ # the hostnamed dbus node path
31
32
  NODE = '/org/freedesktop/hostname1'.freeze
33
+
34
+ # the hostnamed dbus interface
32
35
  INTERFACE = 'org.freedesktop.hostname1'.freeze
33
36
 
34
37
  include Mixin::MethodMissing
35
38
  include Mixin::Properties
36
39
 
40
+ # @return [DBus::Service]
41
+ # @api private
37
42
  attr_reader :service
38
43
 
44
+ #
45
+ # Creates a new Hostnamed object for interfacing
46
+ # with hostnamed on the given bus
47
+ #
48
+ # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance
39
49
  def initialize(bus = Helpers.system_bus)
40
50
  @service = bus.service(INTERFACE)
41
51
  @object = @service.object(NODE)
@@ -25,12 +25,17 @@ require_relative 'transfer'
25
25
  module DBus
26
26
  module Systemd
27
27
  module Importd
28
+ # the importd dbus interface
28
29
  INTERFACE = 'org.freedesktop.import1'.freeze
29
30
 
30
31
  class Manager
32
+ # the importd manager dbus node path
31
33
  NODE = '/org/freedesktop/import1'.freeze
34
+
35
+ # the importd manager dbus interface
32
36
  INTERFACE = 'org.freedesktop.import1.Manager'.freeze
33
37
 
38
+ # index mapping of transfer array returned from ListTransfers()
34
39
  TRANSFER_INDICES = {
35
40
  id: 0,
36
41
  operation: 1,
@@ -43,28 +48,55 @@ module DBus
43
48
  include Systemd::Mixin::MethodMissing
44
49
  include Systemd::Mixin::Properties
45
50
 
51
+ # @return [DBus::Service]
52
+ # @api private
46
53
  attr_reader :service
47
54
 
55
+ #
56
+ # Creates a new Manager object for interfacing with
57
+ # the hostnamed Manager interface
58
+ #
59
+ # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance
48
60
  def initialize(bus = Systemd::Helpers.system_bus)
49
61
  @service = bus.service(Importd::INTERFACE)
50
62
  @object = @service.object(NODE)
51
63
  .tap(&:introspect)
52
64
  end
53
65
 
66
+ #
67
+ # return a list of mapped transfers
68
+ #
69
+ # @return [Array] array of hashes with transfer data
54
70
  def transfers
55
71
  self.ListTransfers.first.map { |t| map_transfer(t) }
56
72
  end
57
73
 
74
+ #
75
+ # Create a transfer object from a transfer id
76
+ #
77
+ # @param id [Integer] transfer id
78
+ # @return [DBus::Systemd::Importd::Transfer] importd transfer object
58
79
  def transfer(id)
59
80
  Transfer.new(id, self)
60
81
  end
61
82
 
83
+ #
84
+ # Create a transfer object from the transfer node path
85
+ #
86
+ # @param path [String] transfer dbus node path
87
+ # @return [DBus::Systemd::Importd::Transfer] importd transfer object
62
88
  def get_transfer_by_path(path)
63
89
  obj = @service.object(path)
64
90
  .tap(&:introspect)
65
91
  Transfer.new(obj.Get(Transfer::INTERFACE, 'Id').first, self)
66
92
  end
67
93
 
94
+ #
95
+ # map a transfer array as returned from ListTransfers
96
+ # to a hash with keys from TRANSER_INDICES
97
+ #
98
+ # @param transfer_array [Array] a transfer array
99
+ # @return [Hash] mapped transfer array to named fields
68
100
  def map_transfer(transfer_array)
69
101
  Systemd::Helpers.map_array(transfer_array, TRANSFER_INDICES)
70
102
  end
@@ -25,11 +25,17 @@ module DBus
25
25
  module Systemd
26
26
  module Importd
27
27
  class Transfer
28
+ # importd transfer object dbus interface
28
29
  INTERFACE = 'org.freedesktop.import1.Transfer'.freeze
29
30
 
30
31
  include Systemd::Mixin::MethodMissing
31
32
  include Systemd::Mixin::Properties
32
33
 
34
+ #
35
+ # create a transfer object for interfacing with importd transfers
36
+ #
37
+ # @param id [Integer] transfer id
38
+ # @param manager [DBus::Systemd::Importd::Manager] the importd manager object
33
39
  def initialize(id, manager = Manager.new)
34
40
  @object = manager.service.object("#{Manager::NODE}/transfer/_#{id}")
35
41
  .tap(&:introspect)
@@ -24,11 +24,17 @@ require_relative 'mixin'
24
24
  module DBus
25
25
  module Systemd
26
26
  class Job
27
+ # systemd job object dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Job'.freeze
28
29
 
29
30
  include Mixin::MethodMissing
30
31
  include Mixin::Properties
31
32
 
33
+ #
34
+ # Creates a job object for interfacing with a systemd job
35
+ #
36
+ # @param id [Integer] the job id
37
+ # @param manager [DBus::Systemd::Manager] the systemd manager to query
32
38
  def initialize(id, manager = Manager.new)
33
39
  job_path = manager.GetJob(id).first
34
40
  @object = manager.service.object(job_path)
@@ -28,14 +28,23 @@ require_relative 'mixin'
28
28
  module DBus
29
29
  module Systemd
30
30
  class Localed
31
+ # the localed object dbus node path
31
32
  NODE = '/org/freedesktop/locale1'.freeze
33
+
34
+ # the localed object dbus interface
32
35
  INTERFACE = 'org.freedesktop.locale1'.freeze
33
36
 
34
37
  include Mixin::MethodMissing
35
38
  include Mixin::Properties
36
39
 
40
+ # @return [DBus::Service]
41
+ # @api private
37
42
  attr_reader :service
38
43
 
44
+ #
45
+ # Create a new DBus::Systemd::Localed object
46
+ #
47
+ # @param bus [DBus::SystemBus, DBus::SessionBus] the bus instance
39
48
  def initialize(bus = Helpers.system_bus)
40
49
  @service = bus.service(INTERFACE)
41
50
  @object = @service.object(NODE)
@@ -27,12 +27,17 @@ require_relative 'seat'
27
27
  module DBus
28
28
  module Systemd
29
29
  module Logind
30
+ # the logind objet dbus interface
30
31
  INTERFACE = 'org.freedesktop.login1'.freeze
31
32
 
32
33
  class Manager
34
+ # the logind manager object dbus node path
33
35
  NODE = '/org/freedesktop/login1'.freeze
36
+
37
+ # the logind manager object dbus interface
34
38
  INTERFACE = 'org.freedesktop.login1.Manager'.freeze
35
39
 
40
+ # session array index map as returned by ListSessions
36
41
  SESSION_INDICES = {
37
42
  id: 0,
38
43
  user_id: 1,
@@ -41,17 +46,20 @@ module DBus
41
46
  object_path: 4
42
47
  }.freeze
43
48
 
49
+ # user array index map as returned by ListUsers
44
50
  USER_INDICES = {
45
51
  id: 0,
46
52
  name: 1,
47
53
  object_path: 2
48
54
  }.freeze
49
55
 
56
+ # seat array index map as returned by ListSeats
50
57
  SEAT_INDICES = {
51
58
  id: 0,
52
59
  object_path: 1
53
60
  }.freeze
54
61
 
62
+ # inhibitor array index map as returned by ListInhibitors
55
63
  INHIBITOR_INDICES = {
56
64
  what: 0,
57
65
  who: 1,
@@ -64,64 +72,127 @@ module DBus
64
72
  include Systemd::Mixin::MethodMissing
65
73
  include Systemd::Mixin::Properties
66
74
 
75
+ # @return [DBus::Service]
76
+ # @api private
67
77
  attr_reader :service
68
78
 
79
+ #
80
+ # Create a logind manager dbus proxy object
81
+ #
82
+ # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance
69
83
  def initialize(bus = Systemd::Helpers.system_bus)
70
84
  @service = bus.service(Logind::INTERFACE)
71
85
  @object = @service.object(NODE)
72
86
  .tap(&:introspect)
73
87
  end
74
88
 
89
+ #
90
+ # get mapped list of seats
91
+ #
92
+ # @return [Array] array of mapped seat hashes
75
93
  def seats
76
94
  self.ListSeats.first.map { |s| map_seat(s) }
77
95
  end
78
96
 
97
+ #
98
+ # get seat object
99
+ #
100
+ # @param id [String] seat id (e.g. 'seat0')
101
+ # @return [DBus::Systemd::Logind::Seat] logind seat object
79
102
  def seat(id)
80
103
  Seat.new(id, self)
81
104
  end
82
105
 
106
+ #
107
+ # get seat object from dbus node path
108
+ #
109
+ # @param path [String] seat dbus node path
110
+ # @return [DBus::Systemd::Logind::Seat] logind seat object
83
111
  def get_seat_by_path(path)
84
112
  obj = @service.object(path)
85
113
  .tap(&:introspect)
86
114
  Seat.new(obj.Get(Seat::INTERFACE, 'Id').first, self)
87
115
  end
88
116
 
117
+ #
118
+ # map seat array to named field hash
119
+ #
120
+ # @param seat_array [Array] seat array as returned from ListSeats
121
+ # @return [Hash] mapped array as hash
89
122
  def map_seat(seat_array)
90
123
  Systemd::Helpers.map_array(seat_array, SEAT_INDICES)
91
124
  end
92
125
 
126
+ #
127
+ # array of property-mapped seat hashes
128
+ #
129
+ # @return [Array] array of seat-property hashes
93
130
  def sessions
94
131
  self.ListSessions.first.map { |s| map_session(s) }
95
132
  end
96
133
 
134
+ #
135
+ # dbus session object by id
136
+ #
137
+ # @param id [String] session id
138
+ # @return [DBus::Systemd::Logind::Session] logind session object
97
139
  def session(id)
98
140
  Session.new(id, self)
99
141
  end
100
142
 
143
+ #
144
+ # get session object by dbus node path
145
+ #
146
+ # @param path [String] session dbus node path
147
+ # @return [DBus::Systemd::Logind::Session] logind session object
101
148
  def get_session_by_path(path)
102
149
  obj = @service.object(path)
103
150
  .tap(&:introspect)
104
151
  Session.new(obj.Get(Session::INTERFACE, 'Id').first, self)
105
152
  end
106
153
 
154
+ #
155
+ # convert session array to mapped hash
156
+ #
157
+ # @param session_array [Array] session array as returned by ListSessions
158
+ # @return [Hash] mapped session property hash
107
159
  def map_session(session_array)
108
160
  Systemd::Helpers.map_array(session_array, SESSION_INDICES)
109
161
  end
110
162
 
163
+ #
164
+ # get logind users
165
+ #
166
+ # @return [Array] array of mapped logind user property hashes
111
167
  def users
112
168
  self.ListUsers.first.map { |u| map_user(u) }
113
169
  end
114
170
 
171
+ #
172
+ # get user dbus object
173
+ #
174
+ # @param id [Integer] user id
175
+ # @return [DBus::Systemd::Logind::User] logind user dbus object
115
176
  def user(id)
116
177
  User.new(id, self)
117
178
  end
118
179
 
180
+ #
181
+ # get user dbus object from dbus node path
182
+ #
183
+ # @param path [String] dbus node path for user
184
+ # @return [DBus::Systemd::Logind::User] logind user dbus object
119
185
  def get_user_by_path(path)
120
186
  obj = @service.object(path)
121
187
  .tap(&:introspect)
122
188
  User.new(obj.Get(User::INTERFACE, 'Id').first, self)
123
189
  end
124
190
 
191
+ #
192
+ # convert user array to hash with mapped properties
193
+ #
194
+ # @param user_array [Array] user array as returned by ListUsers
195
+ # @return [Hash] hash with mapped user properties
125
196
  def map_user(user_array)
126
197
  Systemd::Helpers.map_array(user_array, USER_INDICES)
127
198
  end
@@ -25,11 +25,17 @@ module DBus
25
25
  module Systemd
26
26
  module Logind
27
27
  class Seat
28
+ # logind seat object dbus interface
28
29
  INTERFACE = 'org.freedesktop.login1.Seat'.freeze
29
30
 
30
31
  include Systemd::Mixin::MethodMissing
31
32
  include Systemd::Mixin::Properties
32
33
 
34
+ #
35
+ # create a new logind seat dbus object
36
+ #
37
+ # @param id [String] logind seat id
38
+ # @param manager [DBus::Systemd::Logind::Manager] logind manager object
33
39
  def initialize(id, manager = Manager.new)
34
40
  seat_path = manager.GetSeat(id).first
35
41
  @object = manager.service.object(seat_path)
@@ -25,11 +25,17 @@ module DBus
25
25
  module Systemd
26
26
  module Logind
27
27
  class Session
28
+ # logind session object dbus interface
28
29
  INTERFACE = 'org.freedesktop.login1.Session'.freeze
29
30
 
30
31
  include Systemd::Mixin::MethodMissing
31
32
  include Systemd::Mixin::Properties
32
33
 
34
+ #
35
+ # create logind session dbus proxy object
36
+ #
37
+ # @param id [String] logind session id
38
+ # @param manager [DBus::Systemd::Logind::Manager] logind manager object
33
39
  def initialize(id, manager = Manager.new)
34
40
  session_path = manager.GetSession(id).first
35
41
  @object = manager.service.object(session_path)
@@ -25,11 +25,17 @@ module DBus
25
25
  module Systemd
26
26
  module Logind
27
27
  class User
28
+ # logind user object dbus interface
28
29
  INTERFACE = 'org.freedesktop.login1.User'.freeze
29
30
 
30
31
  include Systemd::Mixin::MethodMissing
31
32
  include Systemd::Mixin::Properties
32
33
 
34
+ #
35
+ # create new logind user dbus proxy object
36
+ #
37
+ # @param id [Integer] logind user id
38
+ # @param manager [DBus::Systemd::Logind::Manager] logind manager object
33
39
  def initialize(id, manager = Manager.new)
34
40
  user_path = manager.GetUser(id).first
35
41
  @object = manager.service.object(user_path)
@@ -25,11 +25,17 @@ module DBus
25
25
  module Systemd
26
26
  module Machined
27
27
  class Image
28
+ # machined image object dbus interface
28
29
  INTERFACE = 'org.freedesktop.machine1.Image'.freeze
29
30
 
30
31
  include Systemd::Mixin::MethodMissing
31
32
  include Systemd::Mixin::Properties
32
33
 
34
+ #
35
+ # Create a machined image dbus proxy object
36
+ #
37
+ # @param name [String] image name
38
+ # @param manager [DBus::Systemd::Machined::Manager] manager dbus proxy object
33
39
  def initialize(name, manager = Manager.new)
34
40
  image_path = manager.GetImage(name).first
35
41
  @object = manager.service.object(image_path)
@@ -25,11 +25,17 @@ module DBus
25
25
  module Systemd
26
26
  module Machined
27
27
  class Machine
28
+ # machined machine object dbus interface
28
29
  INTERFACE = 'org.freedesktop.machine1.Machine'.freeze
29
30
 
30
31
  include Systemd::Mixin::MethodMissing
31
32
  include Systemd::Mixin::Properties
32
33
 
34
+ #
35
+ # create machined machine dbus proxy object
36
+ #
37
+ # @param name [String] machine name
38
+ # @param manager [DBus::Systemd::Machined::Manager] machined manager object
33
39
  def initialize(name, manager = Manager.new)
34
40
  machine_path = manager.GetMachine(name).first
35
41
  @object = manager.service.object(machine_path)
@@ -26,12 +26,17 @@ require_relative 'image'
26
26
  module DBus
27
27
  module Systemd
28
28
  module Machined
29
+ # machined dbus interface
29
30
  INTERFACE = 'org.freedesktop.machine1'.freeze
30
31
 
31
32
  class Manager
33
+ # machined manager dbus object node path
32
34
  NODE = '/org/freedesktop/machine1'.freeze
35
+
36
+ # machined manager dbus interface
33
37
  INTERFACE = 'org.freedesktop.machine1.Manager'.freeze
34
38
 
39
+ # machine array index map as returned by ListMachines
35
40
  MACHINE_INDICES = {
36
41
  name: 0,
37
42
  class: 1,
@@ -39,6 +44,7 @@ module DBus
39
44
  object_path: 3
40
45
  }.freeze
41
46
 
47
+ # image array index map as returned by ListImages
42
48
  IMAGE_INDICES = {
43
49
  name: 0,
44
50
  type: 1,
@@ -52,46 +58,90 @@ module DBus
52
58
  include Systemd::Mixin::MethodMissing
53
59
  include Systemd::Mixin::Properties
54
60
 
61
+ # @return [DBus::Service]
62
+ # @api private
55
63
  attr_reader :service
56
64
 
65
+ #
66
+ # Create machined Manager dbus proxy object
67
+ #
68
+ # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance
57
69
  def initialize(bus = Systemd::Helpers.system_bus)
58
70
  @service = bus.service(Machined::INTERFACE)
59
71
  @object = @service.object(NODE)
60
72
  .tap(&:introspect)
61
73
  end
62
74
 
75
+ #
76
+ # array of machines with mapped properties
77
+ #
78
+ # @return [Array] array of machine property hashes
63
79
  def machines
64
80
  self.ListMachines.first.map { |m| map_machine(m) }
65
81
  end
66
82
 
83
+ #
84
+ # get machine dbus proxy object by machine name
85
+ #
86
+ # @param name [String] machine name
87
+ # @return [DBus::Systemd::Machined::Machine] machine instance
67
88
  def machine(name)
68
89
  Machine.new(name, self)
69
90
  end
70
91
 
92
+ #
93
+ # get machine dbus proxy object by dbus node path
94
+ #
95
+ # @param path [String] machine dbus node path
96
+ # @return [DBus::Systemd::Machined::Machine] machine instance
71
97
  def get_machine_by_path(path)
72
98
  obj = @service.object(path)
73
99
  .tap(&:introspect)
74
100
  Machine.new(obj.Get(Machine::INTERFACE, 'Name').first, self)
75
101
  end
76
102
 
103
+ #
104
+ # map machine property array from ListMachines to indexed property hash
105
+ #
106
+ # @param machine_array [Array] machine property array as returned by ListMachines
107
+ # @return [Hash] hash containing mapped machine properties
77
108
  def map_machine(machine_array)
78
109
  Systemd::Helpers.map_array(machine_array, MACHINE_INDICES)
79
110
  end
80
111
 
112
+ #
113
+ # get mapped array of images
114
+ #
115
+ # @return [Array] array of mapped image property hashes
81
116
  def images
82
117
  self.ListImages.first.map { |i| map_image(i) }
83
118
  end
84
119
 
120
+ #
121
+ # get image proxy object by name
122
+ #
123
+ # @param name [String] image name
124
+ # @return [DBus::Systemd::Machined::Machine] image dbus proxy object
85
125
  def image(name)
86
126
  Image.new(name, self)
87
127
  end
88
128
 
129
+ #
130
+ # get image dbus proxy object by dbus node path
131
+ #
132
+ # @param path [String] image dbus node path
133
+ # @return [DBus::Systemd::Machined::Image] image dbus proxy object
89
134
  def get_image_by_path(path)
90
135
  obj = @service.object(path)
91
136
  .tap(&:introspect)
92
137
  Image.new(obj.Get(Image::INTERFACE, 'Name').first, self)
93
138
  end
94
139
 
140
+ #
141
+ # map image array as returned by ListImages to property hash
142
+ #
143
+ # @param image_array [Array] image property array as returned by ListImages
144
+ # @return [Hash] image property hash
95
145
  def map_image(image_array)
96
146
  Systemd::Helpers.map_array(image_array, IMAGE_INDICES)
97
147
  end
@@ -29,12 +29,17 @@ require_relative 'job'
29
29
 
30
30
  module DBus
31
31
  module Systemd
32
+ # systemd dbus interface
32
33
  INTERFACE = 'org.freedesktop.systemd1'.freeze
33
34
 
34
35
  class Manager
36
+ # systemd manager object dbus node path
35
37
  NODE = '/org/freedesktop/systemd1'.freeze
38
+
39
+ # systemd manager dbus interface
36
40
  INTERFACE = 'org.freedesktop.systemd1.Manager'.freeze
37
41
 
42
+ # index map of unit array returned by ListUnits
38
43
  UNIT_INDICES = {
39
44
  name: 0,
40
45
  description: 1,
@@ -48,6 +53,7 @@ module DBus
48
53
  job_object_path: 9
49
54
  }.freeze
50
55
 
56
+ # index map of job array returned by ListJobs
51
57
  JOB_INDICES = {
52
58
  id: 0,
53
59
  unit: 1,
@@ -60,46 +66,90 @@ module DBus
60
66
  include Mixin::MethodMissing
61
67
  include Mixin::Properties
62
68
 
69
+ # @return [DBus::Service]
70
+ # @api private
63
71
  attr_reader :service
64
72
 
73
+ #
74
+ # Create a systemd manager dbus proxy object
75
+ #
76
+ # @param bus [DBus::SystemBus, DBus::SessionBus] bus instance
65
77
  def initialize(bus = Systemd::Helpers.system_bus)
66
78
  @service = bus.service(Systemd::INTERFACE)
67
79
  @object = @service.object(NODE)
68
80
  .tap(&:introspect)
69
81
  end
70
82
 
83
+ #
84
+ # get an array of mapped units/unit properties
85
+ #
86
+ # @return [Array] array of mapped unit property hashes
71
87
  def units
72
88
  self.ListUnits.first.map { |u| map_unit(u) }
73
89
  end
74
90
 
91
+ #
92
+ # get a unit dbus proxy object by name
93
+ #
94
+ # @param name [String] unit name (e.g. 'sshd.service')
95
+ # @return [DBus::Systemd::Unit] unit dbus proxy object
75
96
  def unit(name)
76
97
  Unit.new(name, self)
77
98
  end
78
99
 
100
+ #
101
+ # get unit object by dbus node path
102
+ #
103
+ # @param path [String] unit dbus node path
104
+ # @return [DBus::Systemd::Unit] unit dbus proxy object
79
105
  def get_unit_by_object_path(path)
80
106
  obj = @service.object(path)
81
107
  .tap(&:introspect)
82
108
  Unit.new(obj.Get(Unit::INTERFACE, 'Id').first, self)
83
109
  end
84
110
 
111
+ #
112
+ # map unit array from ListUnits to property hash
113
+ #
114
+ # @param unit_array [Array] array as returned from ListUnits
115
+ # @return [Hash] unit property hash
85
116
  def map_unit(unit_array)
86
117
  Helpers.map_array(unit_array, UNIT_INDICES)
87
118
  end
88
119
 
120
+ #
121
+ # array of jobs from ListJobs mapped to property hashes
122
+ #
123
+ # @return [Array] array of job property hashes
89
124
  def jobs
90
125
  self.ListJobs.first.map { |j| map_job(j) }
91
126
  end
92
127
 
128
+ #
129
+ # get job by id
130
+ #
131
+ # @param id [Integer] job id
132
+ # @return [DBus::Systemd::Job] job dbus proxy object
93
133
  def job(id)
94
134
  Job.new(id, self)
95
135
  end
96
136
 
137
+ #
138
+ # get job by dbus node path
139
+ #
140
+ # @param path [String] job dbus node path
141
+ # @return [DBus::Systemd::Job] job dbus proxy object
97
142
  def get_job_by_object_path(path)
98
143
  obj = @service.object(path)
99
144
  .tap(&:introspect)
100
145
  Job.new(obj.Get(Job::INTERFACE, 'Id').first, self)
101
146
  end
102
147
 
148
+ #
149
+ # map job array from ListJobs to property hash
150
+ #
151
+ # @param job_array [Array] job property array as returned by ListJobs
152
+ # @return [Hash] mapped job property hash
103
153
  def map_job(job_array)
104
154
  Helpers.map_array(job_array, JOB_INDICES)
105
155
  end
@@ -22,8 +22,14 @@ module DBus
22
22
  module Systemd
23
23
  module Mixin
24
24
  module MethodMissing
25
+ # @return DBus::ProxyObject
26
+ # @api private
25
27
  attr_reader :object
26
28
 
29
+ #
30
+ # use method_missing to proxy methods to
31
+ # the dbus proxy object interface methods
32
+ #
27
33
  def method_missing(name, *args, &blk)
28
34
  if @object.respond_to?(name)
29
35
  @object.send(name, *args, &blk)
@@ -32,12 +38,20 @@ module DBus
32
38
  end
33
39
  end
34
40
 
41
+ #
42
+ # fix respond_to to also check the dbus methods
43
+ #
35
44
  def respond_to_missing?(*args)
36
45
  @object.respond_to?(*args) || super
37
46
  end
38
47
  end
39
48
 
40
49
  module Properties
50
+ #
51
+ # fetches properties from a named interface
52
+ #
53
+ # @param interface [String], interface to get properties from
54
+ # @return [Hash] interface property hash
41
55
  def properties(interface = self.class::INTERFACE)
42
56
  self.GetAll(interface).first
43
57
  end
@@ -25,11 +25,17 @@ module DBus
25
25
  module Systemd
26
26
  module Networkd
27
27
  class Link
28
+ # networkd link dbus interface
28
29
  INTERFACE = 'org.freedesktop.network1.Link'.freeze
29
30
 
30
31
  include Systemd::Mixin::MethodMissing
31
32
  include Systemd::Mixin::Properties
32
33
 
34
+ #
35
+ # create new networkd link dbus proxy object
36
+ #
37
+ # @param id [Integer] networkd link id
38
+ # @param manager [DBus::Systemd::Networkd::Manager] networkd manager object
33
39
  def initialize(id, manager = Manager.new)
34
40
  @object = manager.service.object("#{Manager::NODE}/link/#{id}")
35
41
  .tap(&:introspect)
@@ -25,23 +25,38 @@ require_relative 'link'
25
25
  module DBus
26
26
  module Systemd
27
27
  module Networkd
28
+ # networkd dbus interface
28
29
  INTERFACE = 'org.freedesktop.network1'.freeze
29
30
 
30
31
  class Manager
32
+ # networkd manager object dbus node path
31
33
  NODE = '/org/freedesktop/network1'.freeze
34
+
35
+ # networkd manager dbus interface
32
36
  INTERFACE = 'org.freedesktop.network1.Manager'.freeze
33
37
 
34
38
  include Systemd::Mixin::MethodMissing
35
39
  include Systemd::Mixin::Properties
36
40
 
41
+ # @return [DBus::Service]
42
+ # @api private
37
43
  attr_reader :service
38
44
 
45
+ #
46
+ # create a networkd manager dbus proxy object
47
+ #
48
+ # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance
39
49
  def initialize(bus = Systemd::Helpers.system_bus)
40
50
  @service = bus.service(Networkd::INTERFACE)
41
51
  @object = @service.object(NODE)
42
52
  .tap(&:introspect)
43
53
  end
44
54
 
55
+ #
56
+ # get a link by id
57
+ #
58
+ # @param id [Integer] networkd link id
59
+ # @return [DBus::Systemd::Networkd::Link] networkd link dbus proxy object
45
60
  def link(id)
46
61
  Link.new(id, self)
47
62
  end
@@ -25,11 +25,17 @@ module DBus
25
25
  module Systemd
26
26
  module Resolved
27
27
  class Link
28
+ # resolved link dbus interface
28
29
  INTERFACE = 'org.freedesktop.resolve1.Link'.freeze
29
30
 
30
31
  include Systemd::Mixin::MethodMissing
31
32
  include Systemd::Mixin::Properties
32
33
 
34
+ #
35
+ # create a new link dbus proxy object
36
+ #
37
+ # @param id [Integer] resolved link id
38
+ # @param manager [DBus::Systemd::Resolved::Manager] resolved manager object
33
39
  def initialize(id, manager = Manager.new)
34
40
  link_path = manager.GetLink(id).first
35
41
  @object = manager.service.object(link_path)
@@ -25,22 +25,41 @@ require_relative 'link'
25
25
  module DBus
26
26
  module Systemd
27
27
  module Resolved
28
+ # resolved dbus interface
28
29
  INTERFACE = 'org.freedesktop.resolve1'.freeze
29
30
 
30
31
  class Manager
32
+ # resolved manager object dbus node path
31
33
  NODE = '/org/freedesktop/resolve1'.freeze
34
+
35
+ # resolved manager dbus interface
32
36
  INTERFACE = 'org.freedesktop.resolve1.Manager'.freeze
33
37
 
34
38
  include Systemd::Mixin::MethodMissing
35
39
  include Systemd::Mixin::Properties
36
40
 
41
+ # @return [DBus::Service]
42
+ # @api private
37
43
  attr_reader :service
38
44
 
45
+ #
46
+ # get a new resolved manager dbus proxy object
47
+ #
48
+ # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance
39
49
  def initialize(bus = Systemd::Helpers.system_bus)
40
50
  @service = bus.service(Resolved::INTERFACE)
41
51
  @object = @service.object(NODE)
42
52
  .tap(&:introspect)
43
53
  end
54
+
55
+ #
56
+ # get a resolved link by id
57
+ #
58
+ # @param id [Integer] resolved link id
59
+ # @return [DBus::Systemd::Resolved::Link] resolved link dbus proxy object
60
+ def link(id)
61
+ Link.new(id, self)
62
+ end
44
63
  end
45
64
  end
46
65
  end
@@ -24,14 +24,23 @@ require_relative 'mixin'
24
24
  module DBus
25
25
  module Systemd
26
26
  class Timedated
27
+ # the timedated dbus node path
27
28
  NODE = '/org/freedesktop/timedate1'.freeze
29
+
30
+ # the timedated dbus interface
28
31
  INTERFACE = 'org.freedesktop.timedate1'.freeze
29
32
 
30
33
  include Mixin::MethodMissing
31
34
  include Mixin::Properties
32
35
 
36
+ # @return [DBus::Service]
37
+ # @api private
33
38
  attr_reader :service
34
39
 
40
+ #
41
+ # Create a new object for interfacing with timedated
42
+ #
43
+ # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance
35
44
  def initialize(bus = Helpers.system_bus)
36
45
  @service = bus.service(INTERFACE)
37
46
  @object = @service.object(NODE)
@@ -24,11 +24,17 @@ require_relative 'mixin'
24
24
  module DBus
25
25
  module Systemd
26
26
  class Unit
27
+ # the unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Unit'.freeze
28
29
 
29
30
  include Mixin::MethodMissing
30
31
  include Mixin::Properties
31
32
 
33
+ #
34
+ # create a new unit object for interfacing with systemd units
35
+ #
36
+ # @param name [String] unit name
37
+ # @param manager [DBus::Systemd::Manager] systemd manager object
32
38
  def initialize(name, manager = Manager.new)
33
39
  unit_path = manager.GetUnit(name).first
34
40
  @object = manager.service.object(unit_path)
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Automount < Unit
27
+ # systemd automount unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Automount'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Device < Unit
27
+ # systemd device unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Device'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Mount < Unit
27
+ # systemd mount unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Mount'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Path < Unit
27
+ # systemd path unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Path'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Scope < Unit
27
+ # systemd scope unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Scope'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Service < Unit
27
+ # systemd service unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Service'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Slice < Unit
27
+ # systemd slice unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Slice'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Snapshot < Unit
27
+ # systemd snapshot unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Snapshot'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Socket < Unit
27
+ # systemd socket unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Socket'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Swap < Unit
27
+ # systemd swap unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Swap'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Target < Unit
27
+ # systemd target unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Target'.freeze
28
29
  end
29
30
  end
@@ -24,6 +24,7 @@ module DBus
24
24
  module Systemd
25
25
  class Unit
26
26
  class Timer < Unit
27
+ # systemd timer unit dbus interface
27
28
  INTERFACE = 'org.freedesktop.systemd1.Timer'.freeze
28
29
  end
29
30
  end
@@ -20,6 +20,7 @@
20
20
  #
21
21
  module DBus
22
22
  module Systemd
23
- VERSION = '0.8.0'.freeze
23
+ # dbus-systemd gem version
24
+ VERSION = '0.9.0'.freeze
24
25
  end
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbus-systemd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Williams
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.43'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
83
97
  description: library for interfacing with systemd D-Bus APIs
84
98
  email:
85
99
  - nath.e.will@gmail.com