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 =

machined manager dbus object node path

'/org/freedesktop/machine1'.freeze
INTERFACE =

machined manager dbus interface

'org.freedesktop.machine1.Manager'.freeze
MACHINE_INDICES =

machine array index map as returned by ListMachines

{
  name: 0,
  class: 1,
  service_id: 2,
  object_path: 3
}.freeze
IMAGE_INDICES =

image array index map as returned by ListImages

{
  name: 0,
  type: 1,
  read_only: 2,
  creation_time: 3,
  modification_time: 4,
  disk_space: 5,
  object_path: 6
}.freeze

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

Create machined Manager dbus proxy object

Parameters:

  • bus (DBus::SystemBus, DBus::SessionBus) (defaults to: Systemd::Helpers.system_bus)

    dbus instance



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

def initialize(bus = Systemd::Helpers.system_bus)
  @service = bus.service(Machined::SERVICE)
  @object = @service.object(NODE)
  @object.default_iface = INTERFACE
  @object.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

#serviceDBus::Service (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (DBus::Service)


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

def service
  @service
end

Instance Method Details

#get_image_by_path(path) ⇒ DBus::Systemd::Machined::Image

get image dbus proxy object by dbus node path

Parameters:

  • path (String)

    image dbus node path

Returns:



135
136
137
138
139
# File 'lib/dbus/systemd/machined/manager.rb', line 135

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) ⇒ DBus::Systemd::Machined::Machine

get machine dbus proxy object by dbus node path

Parameters:

  • path (String)

    machine dbus node path

Returns:



98
99
100
101
102
# File 'lib/dbus/systemd/machined/manager.rb', line 98

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

#image(name) ⇒ DBus::Systemd::Machined::Machine

get image proxy object by name

Parameters:

  • name (String)

    image name

Returns:



126
127
128
# File 'lib/dbus/systemd/machined/manager.rb', line 126

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

#imagesArray

get mapped array of images

Returns:

  • (Array)

    array of mapped image property hashes



117
118
119
# File 'lib/dbus/systemd/machined/manager.rb', line 117

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

#machine(name) ⇒ DBus::Systemd::Machined::Machine

get machine dbus proxy object by machine name

Parameters:

  • name (String)

    machine name

Returns:



89
90
91
# File 'lib/dbus/systemd/machined/manager.rb', line 89

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

#machinesArray

array of machines with mapped properties

Returns:

  • (Array)

    array of machine property hashes



80
81
82
# File 'lib/dbus/systemd/machined/manager.rb', line 80

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

#map_image(image_array) ⇒ Hash

map image array as returned by ListImages to property hash

Parameters:

  • image_array (Array)

    image property array as returned by ListImages

Returns:

  • (Hash)

    image property hash



146
147
148
# File 'lib/dbus/systemd/machined/manager.rb', line 146

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

#map_machine(machine_array) ⇒ Hash

map machine property array from ListMachines to indexed property hash

Parameters:

  • machine_array (Array)

    machine property array as returned by ListMachines

Returns:

  • (Hash)

    hash containing mapped machine properties



109
110
111
# File 'lib/dbus/systemd/machined/manager.rb', line 109

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