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

Inherits:
Object
  • Object
show all
Includes:
DBus::Systemd::Mixin::MethodMissing, DBus::Systemd::Mixin::Properties
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::Properties

#properties

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.



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

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.



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

def service
  @service
end

Instance Method Details

#get_image_by_path(path) ⇒ Object



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

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



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

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



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

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

#imagesObject



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

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

#machine(name) ⇒ Object



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

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

#machinesObject



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

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

#map_image(image_array) ⇒ Object



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

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

#map_machine(machine_array) ⇒ Object



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

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