Class: DBus::Systemd::Machined::Manager

Inherits:
Object
  • Object
show all
Includes:
DBus::Systemd::Mixin::MethodMissing
Defined in:
lib/dbus/systemd/machined/manager.rb

Constant Summary collapse

NODE =
'/org/freedesktop/machine1'
INTERFACE =
'org.freedesktop.machine1.Manager'
MACHINE_INDICES =
{
  name: 0,
  class: 1,
  service_id: 2,
  object_path: 3
}
IMAGE_INDICES =
{
  name: 0,
  type: 1,
  read_only: 2,
  creation_time: 3,
  modification_time: 4,
  disk_space: 5,
  object_path: 6
}

Instance Attribute Summary collapse

Attributes included from DBus::Systemd::Mixin::MethodMissing

#object

Instance Method Summary collapse

Methods included from DBus::Systemd::Mixin::MethodMissing

#method_missing, #respond_to_missing?

Constructor Details

#initialize(bus = Systemd::Helpers.system_bus) ⇒ Manager

Returns a new instance of Manager.



36
37
38
39
40
# File 'lib/dbus/systemd/machined/manager.rb', line 36

def initialize(bus = Systemd::Helpers.system_bus)
  @service = bus.service(Machined::INTERFACE)
  @object = @service.object(NODE)
                    .tap(&:introspect)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DBus::Systemd::Mixin::MethodMissing

Instance Attribute Details

#serviceObject (readonly)

Returns the value of attribute service.



34
35
36
# File 'lib/dbus/systemd/machined/manager.rb', line 34

def service
  @service
end

Instance Method Details

#get_image_by_path(path) ⇒ Object



68
69
70
71
72
# File 'lib/dbus/systemd/machined/manager.rb', line 68

def get_image_by_path(path)
  obj = @service.object(path)
                .tap(&:introspect)
  Image.new(obj.Get(Image::INTERFACE, 'Name').first, self)
end

#get_machine_by_path(path) ⇒ Object



50
51
52
53
54
# File 'lib/dbus/systemd/machined/manager.rb', line 50

def get_machine_by_path(path)
  obj = @service.object(path)
                .tap(&:introspect)
  Machine.new(obj.Get(Machine::INTERFACE, 'Name').first, self)
end

#image(name) ⇒ Object



64
65
66
# File 'lib/dbus/systemd/machined/manager.rb', line 64

def image(name)
  Image.new(name, self)
end

#imagesObject



60
61
62
# File 'lib/dbus/systemd/machined/manager.rb', line 60

def images
  self.ListImages.first.map { |i| map_image(i) }
end

#machine(name) ⇒ Object



46
47
48
# File 'lib/dbus/systemd/machined/manager.rb', line 46

def machine(name)
  Machine.new(name, self)
end

#machinesObject



42
43
44
# File 'lib/dbus/systemd/machined/manager.rb', line 42

def machines
  self.ListMachines.first.map { |m| map_machine(m) }
end

#map_image(image_array) ⇒ Object



74
75
76
# File 'lib/dbus/systemd/machined/manager.rb', line 74

def map_image(image_array)
  Systemd::Helpers.map_array(image_array, IMAGE_INDICES)
end

#map_machine(machine_array) ⇒ Object



56
57
58
# File 'lib/dbus/systemd/machined/manager.rb', line 56

def map_machine(machine_array)
  Systemd::Helpers.map_array(machine_array, MACHINE_INDICES)
end