├── .gitignore ├── .rspec ├── .rubocop.yml ├── .travis.yml ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── Vagrantfile ├── bin ├── console └── setup ├── dbus-systemd.gemspec ├── lib └── dbus │ ├── systemd.rb │ └── systemd │ ├── helpers.rb │ ├── hostnamed.rb │ ├── importd.rb │ ├── importd │ ├── manager.rb │ └── transfer.rb │ ├── job.rb │ ├── localed.rb │ ├── logind.rb │ ├── logind │ ├── manager.rb │ ├── seat.rb │ ├── session.rb │ └── user.rb │ ├── machined.rb │ ├── machined │ ├── image.rb │ ├── machine.rb │ └── manager.rb │ ├── manager.rb │ ├── mixin.rb │ ├── networkd.rb │ ├── networkd │ ├── link.rb │ └── manager.rb │ ├── resolved.rb │ ├── resolved │ ├── link.rb │ └── manager.rb │ ├── timedated.rb │ ├── unit.rb │ ├── unit │ ├── automount.rb │ ├── device.rb │ ├── mount.rb │ ├── path.rb │ ├── scope.rb │ ├── service.rb │ ├── slice.rb │ ├── snapshot.rb │ ├── socket.rb │ ├── swap.rb │ ├── target.rb │ └── timer.rb │ └── version.rb ├── spec ├── dbus │ ├── systemd │ │ ├── helpers_spec.rb │ │ ├── hostnamed_spec.rb │ │ ├── importd │ │ │ ├── manager_spec.rb │ │ │ └── transfer_spec.rb │ │ ├── importd_spec.rb │ │ ├── job_spec.rb │ │ ├── localed_spec.rb │ │ ├── logind │ │ │ ├── manager_spec.rb │ │ │ ├── seat_spec.rb │ │ │ ├── session_spec.rb │ │ │ └── user_spec.rb │ │ ├── logind_spec.rb │ │ ├── machined │ │ │ ├── machine_spec.rb │ │ │ └── manager_spec.rb │ │ ├── machined_spec.rb │ │ ├── manager_spec.rb │ │ ├── mixin_spec.rb │ │ ├── networkd │ │ │ ├── link_spec.rb │ │ │ └── manager_spec.rb │ │ ├── networkd_spec.rb │ │ ├── resolved │ │ │ ├── link_spec.rb │ │ │ └── manager_spec.rb │ │ ├── resolved_spec.rb │ │ ├── timedated_spec.rb │ │ ├── unit │ │ │ ├── automount_spec.rb │ │ │ ├── device_spec.rb │ │ │ ├── mount_spec.rb │ │ │ ├── path_spec.rb │ │ │ ├── scope_spec.rb │ │ │ ├── service_spec.rb │ │ │ ├── slice_spec.rb │ │ │ ├── snapshot_spec.rb │ │ │ ├── socket_spec.rb │ │ │ ├── swap_spec.rb │ │ │ ├── target_spec.rb │ │ │ └── timer_spec.rb │ │ └── unit_spec.rb │ └── systemd_spec.rb └── spec_helper.rb └── test ├── hostnamed.rb ├── localed.rb ├── logind.rb ├── machined.rb ├── manager.rb ├── networkd.rb ├── resolved.rb └── timedated.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /*.gem 2 | /.vagrant/ 3 | /.bundle/ 4 | /.yardoc 5 | /_yardoc/ 6 | Gemfile.lock 7 | /coverage/ 8 | /doc/ 9 | /pkg/ 10 | /spec/reports/ 11 | /tmp/ 12 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | Exclude: 3 | - dbus-systemd.gemspec 4 | - spec/**/* 5 | - test/**/* 6 | Metrics/LineLength: 7 | Max: 100 8 | Documentation: 9 | Enabled: false 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: ruby 3 | rvm: 4 | - 2.3.0 5 | before_install: gem install bundler -v 1.12.5 6 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Nathan Williams 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DBus::Systemd 2 | 3 | [![Gem Version](https://badge.fury.io/rb/dbus-systemd.svg)](https://badge.fury.io/rb/dbus-systemd) 4 | [![Test Status](https://travis-ci.org/nathwill/ruby-dbus-systemd.svg?branch=master)](https://travis-ci.org/nathwill/ruby-dbus-systemd) 5 | 6 | Ruby library for simplifying access to systemd dbus interfaces. 7 | 8 | *Huge* thanks to the [ruby-dbus](https://rubygems.org/gems/ruby-dbus) library, 9 | without which this would have been awful to write. 10 | 11 | Recommended Reading 12 | 13 | - [introduction to d-bus concepts section of sd-bus announcement blog post](http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html) 14 | - [systemd D-Bus specification](https://www.freedesktop.org/wiki/Software/systemd/dbus/) 15 | - [D-Bus specification](https://dbus.freedesktop.org/doc/dbus-specification.html) 16 | - ruby-dbus [examples](https://github.com/mvidner/ruby-dbus/tree/master/examples) & [docs](https://github.com/mvidner/ruby-dbus/tree/master/doc) 17 | 18 | ## Installation 19 | 20 | Add this line to your application's Gemfile: 21 | 22 | ```ruby 23 | gem 'dbus-systemd' 24 | ``` 25 | 26 | And then execute: 27 | 28 | $ bundle 29 | 30 | Or install it yourself as: 31 | 32 | $ gem install dbus-systemd 33 | 34 | ## Usage 35 | 36 | ### DBus::Systemd::Hostnamed 37 | 38 | For full docs, see [official docs](https://www.freedesktop.org/wiki/Software/systemd/hostnamed/). 39 | 40 | ```ruby 41 | irb(main):001:0> h = DBus::Systemd::Hostnamed.new 42 | => ... 43 | irb(main):002:0> h.object.methods - Object.methods 44 | => [:Set, :Get, :GetAll, :Ping, :GetMachineId, :Introspect, :SetHostname, :SetStaticHostname, :SetPrettyHostname, :SetIconName, :SetChassis, :SetDeployment, :SetLocation, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 45 | irb(main):004:0> h.Get(DBus::Systemd::Hostnamed::INTERFACE, 'Hostname').first 46 | => "derp.localdomain" 47 | irb(main):005:0> h.SetHostname('my-hostname.localdomain', false) 48 | => [] 49 | irb(main):006:0> h.properties['Hostname'] 50 | => "my-hostname.localdomain" 51 | ``` 52 | 53 | ### DBus::Systemd::Importd 54 | 55 | For full docs, see [official docs](https://www.freedesktop.org/wiki/Software/systemd/importd/). 56 | 57 | ```ruby 58 | irb(main):007:0> im = DBus::Systemd::Importd::Manager.new 59 | => ... 60 | irb(main):008:0> im.object.methods - Object.methods 61 | => [:Set, :Get, :GetAll, :ListTransfers, :Ping, :GetMachineId, :Introspect, :ImportTar, :ImportRaw, :ExportTar, :ExportRaw, :PullTar, :PullRaw, :CancelTransfer, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 62 | irb(main):008:0> im.PullRaw('https://dl.fedoraproject.org/pub/fedora/linux/releases/24/CloudImages/x86_64/images/Fedora-Cloud-Base-24-1.2.x86_64.raw.xz', 'Fedora-24', 'no', false) 63 | => [1, "/org/freedesktop/import1/transfer/_1"] 64 | > im.transfers 65 | => [{:id=>1, :operation=>"pull-raw", :remote_file=>"https://dl.fedoraproject.org/pub/fedora/linux/releases/24/CloudImages/x86_64/images/Fedora-Cloud-Base-24-1.2.x86_64.raw.xz", :machine_name=>"Fedora-24", :progress=>0.0, :object_path=>"/org/freedesktop/import1/transfer/_1"}] 66 | ``` 67 | 68 | ### DBus::Systemd::Localed 69 | 70 | For full docs, see [official docs](https://www.freedesktop.org/wiki/Software/systemd/localed/). 71 | 72 | ```ruby 73 | irb(main):009:0> l = DBus::Systemd::Localed.new 74 | => ... 75 | irb(main):010:0> l.object.methods - Object.methods 76 | => [:Set, :Get, :GetAll, :Ping, :GetMachineId, :Introspect, :SetLocale, :SetVConsoleKeyboard, :SetX11Keyboard, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 77 | irb(main):011:0> l.properties 78 | => {"Locale"=>["LANG=en_US.UTF-8"], "X11Layout"=>"", "X11Model"=>"", "X11Variant"=>"", "X11Options"=>"", "VConsoleKeymap"=>"us", "VConsoleKeymapToggle"=>""} 79 | ``` 80 | 81 | ### DBus::Systemd::Logind 82 | 83 | For full docs, see [official docs](https://www.freedesktop.org/wiki/Software/systemd/logind/). 84 | 85 | ```ruby 86 | irb(main):012:0> l = DBus::Systemd::Logind::Manager.new 87 | => ... 88 | irb(main):013:0> l.object.methods - Object.methods 89 | => [:Set, :Get, :GetAll, :ListSeats, :ListSessions, :ListUsers, :GetSession, :GetUser, :GetSeat, :Ping, :GetMachineId, :Introspect, :GetSessionByPID, :GetUserByPID, :ListInhibitors, :CreateSession, :ReleaseSession, :ActivateSession, :ActivateSessionOnSeat, :LockSession, :UnlockSession, :LockSessions, :UnlockSessions, :KillSession, :KillUser, :TerminateSession, :TerminateUser, :TerminateSeat, :SetUserLinger, :AttachDevice, :FlushDevices, :PowerOff, :Reboot, :Suspend, :Hibernate, :HybridSleep, :CanPowerOff, :CanReboot, :CanSuspend, :CanHibernate, :CanHybridSleep, :ScheduleShutdown, :CancelScheduledShutdown, :Inhibit, :CanRebootToFirmwareSetup, :SetRebootToFirmwareSetup, :SetWallMessage, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 90 | irb(main):014:0> l.users 91 | => [{:id=>1000, :name=>"vagrant", :object_path=>"/org/freedesktop/login1/user/_1000"}] 92 | irb(main):015:0> l.seats 93 | => [{:id=>"seat0", :object_path=>"/org/freedesktop/login1/seat/seat0"}] 94 | irb(main):016:0> l.sessions 95 | => [{:id=>"3", :user_id=>1000, :user_name=>"vagrant", :seat_id=>"", :object_path=>"/org/freedesktop/login1/session/_33"}] 96 | irb(main):017:0> u = l.user(1000) 97 | => ... 98 | irb(main):019:0> u.properties 99 | => {"UID"=>1000, "GID"=>1000, "Name"=>"vagrant", "Timestamp"=>1475452037907590, "TimestampMonotonic"=>122159600, "RuntimePath"=>"/run/user/1000", "Service"=>"user@1000.service", "Slice"=>"user-1000.slice", "Display"=>["3", "/org/freedesktop/login1/session/_33"], "State"=>"active", "Sessions"=>[["3", "/org/freedesktop/login1/session/_33"]], "IdleHint"=>false, "IdleSinceHint"=>0, "IdleSinceHintMonotonic"=>0, "Linger"=>false} 100 | ``` 101 | 102 | ### DBus::Systemd::Machined 103 | 104 | For full docs, see [official docs](https://www.freedesktop.org/wiki/Software/systemd/machined/). 105 | 106 | ```ruby 107 | irb(main):021:0> mm = DBus::Systemd::Machined::Manager.new 108 | => ... 109 | irb(main):022:0> mm.object.methods - Object.methods 110 | => [:Set, :Get, :GetAll, :ListMachines, :ListImages, :GetMachine, :GetImage, :Ping, :GetMachineId, :Introspect, :GetMachineByPID, :CreateMachine, :CreateMachineWithNetwork, :RegisterMachine, :RegisterMachineWithNetwork, :TerminateMachine, :KillMachine, :GetMachineAddresses, :GetMachineOSRelease, :OpenMachinePTY, :OpenMachineLogin, :OpenMachineShell, :BindMountMachine, :CopyFromMachine, :CopyToMachine, :RemoveImage, :RenameImage, :CloneImage, :MarkImageReadOnly, :SetPoolLimit, :SetImageLimit, :MapFromMachineUser, :MapToMachineUser, :MapFromMachineGroup, :MapToMachineGroup, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 111 | irb(main):024:0> mm.machines 112 | => [{:name=>".host", :class=>"host", :service_id=>"", :object_path=>"/org/freedesktop/machine1/machine/_2ehost"}] 113 | irb(main):023:0> mm.images 114 | => [{:name=>"Fedora-23", :type=>"raw", :read_only=>false, :creation_time=>1446171608000000, :modification_time=>1446171608000000, :disk_space=>589676544, :object_path=>"/org/freedesktop/machine1/image/Fedora_2d23"}, {:name=>".raw-https:\\x2f\\x2fdl\\x2efedoraproject\\x2eorg\\x2fpub\\x2ffedora\\x2flinux\\x2freleases\\x2f24\\x2fCloudImages\\x2fx86_64\\x2fimages\\x2fFedora-Cloud-Base-24-1\\x2e2\\x2ex86_64\\x2eraw\\x2exz.\\x227fef0a4-5353f9c7441a0\\x22", :type=>"raw", :read_only=>true, :creation_time=>1465922207000000, :modification_time=>1465922207000000, :disk_space=>540872704, :object_path=>"/org/freedesktop/machine1/image/_2eraw_2dhttps_3a_5cx2f_5cx2fdl_5cx2efedoraproject_5cx2eorg_5cx2fpub_5cx2ffedora_5cx2flinux_5cx2freleases_5cx2f24_5cx2fCloudImages_5cx2fx86_5f64_5cx2fimages_5cx2fFedora_2dCloud_2dBase_2d24_2d1_5cx2e2_5cx2ex86_5f64_5cx2eraw_5cx2exz_2e_5cx227fef0a4_2d5353f9c7441a0_5cx22"}, {:name=>".raw-https:\\x2f\\x2fdl\\x2efedoraproject\\x2eorg\\x2fpub\\x2ffedora\\x2flinux\\x2freleases\\x2f23\\x2fCloud\\x2fx86_64\\x2fImages\\x2fFedora-Cloud-Base-23-20151030\\x2ex86_64\\x2eraw\\x2exz.\\x229205894-5234910faa600\\x22", :type=>"raw", :read_only=>true, :creation_time=>1446171608000000, :modification_time=>1446171608000000, :disk_space=>589676544, :object_path=>"/org/freedesktop/machine1/image/_2eraw_2dhttps_3a_5cx2f_5cx2fdl_5cx2efedoraproject_5cx2eorg_5cx2fpub_5cx2ffedora_5cx2flinux_5cx2freleases_5cx2f23_5cx2fCloud_5cx2fx86_5f64_5cx2fImages_5cx2fFedora_2dCloud_2dBase_2d23_2d20151030_5cx2ex86_5f64_5cx2eraw_5cx2exz_2e_5cx229205894_2d5234910faa600_5cx22"}, {:name=>"Fedora-24", :type=>"raw", :read_only=>false, :creation_time=>1465922207000000, :modification_time=>1465922207000000, :disk_space=>540872704, :object_path=>"/org/freedesktop/machine1/image/Fedora_2d24"}, {:name=>"test", :type=>"raw", :read_only=>false, :creation_time=>1446171608000000, :modification_time=>1446171608000000, :disk_space=>589676544, :object_path=>"/org/freedesktop/machine1/image/test"}, {:name=>".host", :type=>"directory", :read_only=>false, :creation_time=>0, :modification_time=>0, :disk_space=>18446744073709551615, :object_path=>"/org/freedesktop/machine1/image/_2ehost"}] 115 | irb(main):025:0> mm.properties 116 | => {"PoolPath"=>"/var/lib/machines", "PoolUsage"=>1191448576, "PoolLimit"=>2105020416} 117 | irb(main):026:0> mi = mm.image('Fedora-24') 118 | => ... 119 | irb(main):027:0> mi.object.methods - Object.methods 120 | => [:Set, :Get, :GetAll, :Ping, :GetMachineId, :Introspect, :Remove, :Rename, :Clone, :MarkReadOnly, :SetLimit, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 121 | irb(main):028:0> mi.properties 122 | => {"Name"=>"Fedora-24", "Path"=>"/var/lib/machines/Fedora-24.raw", "Type"=>"raw", "ReadOnly"=>false, "CreationTimestamp"=>1465922207000000, "ModificationTimestamp"=>1465922207000000, "Usage"=>540872704, "Limit"=>3221225472, "UsageExclusive"=>540872704, "LimitExclusive"=>3221225472} 123 | irb(main):029:0> machine = mm.machine('.host') 124 | => .. 125 | irb(main):030:0> machine.object.methods - Object.methods 126 | => [:Set, :Get, :GetAll, :Kill, :Ping, :GetMachineId, :Introspect, :Terminate, :GetAddresses, :GetOSRelease, :OpenPTY, :OpenLogin, :OpenShell, :BindMount, :CopyFrom, :CopyTo, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 127 | irb(main):032:0> machine.properties 128 | => {"Name"=>".host", "Id"=>[77, 46, 68, 242, 105, 232, 78, 52, 157, 152, 76, 171, 175, 145, 140, 130], "Timestamp"=>1475451915747985, "TimestampMonotonic"=>0, "Service"=>"", "Unit"=>"-.slice", "Leader"=>1, "Class"=>"host", "RootDirectory"=>"/", "NetworkInterfaces"=>[], "State"=>"running"} 129 | ``` 130 | 131 | ### DBus::Systemd::Networkd 132 | 133 | There's not really documentation published for this, but some busctl work will show you what's available. 134 | 135 | e.g.... 136 | 137 | ```bash 138 | [root@localhost vagrant]# busctl introspect org.freedesktop.network1 /org/freedesktop/network1 139 | NAME TYPE SIGNATURE RESULT/VALUE FLAGS 140 | org.freedesktop.DBus.Introspectable interface - - - 141 | .Introspect method - s - 142 | org.freedesktop.DBus.Peer interface - - - 143 | .GetMachineId method - s - 144 | .Ping method - - - 145 | org.freedesktop.DBus.Properties interface - - - 146 | .Get method ss v - 147 | .GetAll method s a{sv} - 148 | .Set method ssv - - 149 | .PropertiesChanged signal sa{sv}as - - 150 | org.freedesktop.network1.Manager interface - - - 151 | .OperationalState property s "routable" emits-change 152 | [root@localhost vagrant]# busctl introspect org.freedesktop.network1 /org/freedesktop/network1/link/1 153 | NAME TYPE SIGNATURE RESULT/VALUE FLAGS 154 | org.freedesktop.DBus.Introspectable interface - - - 155 | .Introspect method - s - 156 | org.freedesktop.DBus.Peer interface - - - 157 | .GetMachineId method - s - 158 | .Ping method - - - 159 | org.freedesktop.DBus.Properties interface - - - 160 | .Get method ss v - 161 | .GetAll method s a{sv} - 162 | .Set method ssv - - 163 | .PropertiesChanged signal sa{sv}as - - 164 | org.freedesktop.network1.Link interface - - - 165 | .AdministrativeState property s "unmanaged" emits-change 166 | .OperationalState property s "carrier" emits-change 167 | ``` 168 | 169 | ```ruby 170 | irb(main):003:0> nm = DBus::Systemd::Networkd::Manager.new 171 | => ... 172 | irb(main):004:0> nm.properties 173 | => {"OperationalState"=>"routable"} 174 | irb(main):003:0> l = nm.link(1) 175 | => ... 176 | irb(main):004:0> l.properties 177 | => {"OperationalState"=>"carrier", "AdministrativeState"=>"unmanaged"} 178 | ``` 179 | 180 | ### DBus::Systemd::Resolved 181 | 182 | For full docs, see [official docs](https://www.freedesktop.org/wiki/Software/systemd/resolved/). 183 | 184 | ```ruby 185 | irb(main):030:0> rm = DBus::Systemd::Resolved::Manager.new 186 | => ... 187 | irb(main):030:0> rm.object.methods - Object.methods 188 | => [:Set, :Get, :GetAll, :Ping, :GetMachineId, :Introspect, :GetLink, :ResolveHostname, :ResolveAddress, :ResolveRecord, :ResolveService, :ResetStatistics, :SetLinkDNS, :SetLinkDomains, :SetLinkLLMNR, :SetLinkMulticastDNS, :SetLinkDNSSEC, :SetLinkDNSSECNegativeTrustAnchors, :RevertLink, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 189 | irb(main):030:0> rm.Get(DBus::Resolved::Manager::INTERFACE, 'DNSSECSupported').first 190 | => false 191 | ``` 192 | 193 | ### DBus::Systemd::Timedated 194 | 195 | For full docs, see [official docs](https://www.freedesktop.org/wiki/Software/systemd/timedated/). 196 | 197 | ```ruby 198 | irb(main):030:0> t = DBus::Systemd::Timedated.new 199 | => ... 200 | irb(main):030:0> t.object.methods - Object.methods 201 | => [:Set, :Get, :GetAll, :Ping, :GetMachineId, :Introspect, :SetTime, :SetTimezone, :SetLocalRTC, :SetNTP, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 202 | irb(main):030:0> t.GetAll(DBus::Systemd::Timedated::INTERFACE).first 203 | => {"Timezone"=>"UTC", "LocalRTC"=>true, "CanNTP"=>true, "NTP"=>false, "NTPSynchronized"=>true, "TimeUSec"=>1475454744352557, "RTCTimeUSec"=>1475454742000000} 204 | irb(main):030:0> t.SetTimezone('America/Los_Angeles', false) 205 | => [] 206 | irb(main):030:0> t.properties['Timezone'] 207 | => "America/Los_Angeles" 208 | ``` 209 | 210 | ### DBus::Systemd::Manager 211 | 212 | For full docs, see [official docs](https://www.freedesktop.org/wiki/Software/systemd/dbus/). 213 | 214 | ```ruby 215 | irb(main):030:0> mgr = DBus::Systemd::Manager.new 216 | => ... 217 | irb(main):030:0> mgr.object.methods - Object.methods 218 | => [:Set, :Get, :ListUnits, :GetAll, :GetUnit, :GetJob, :Ping, :GetMachineId, :Introspect, :GetUnitByPID, :LoadUnit, :StartUnit, :StartUnitReplace, :StopUnit, :ReloadUnit, :RestartUnit, :TryRestartUnit, :ReloadOrRestartUnit, :ReloadOrTryRestartUnit, :KillUnit, :ResetFailedUnit, :SetUnitProperties, :StartTransientUnit, :CancelJob, :ClearJobs, :ResetFailed, :ListUnitsFiltered, :ListJobs, :Subscribe, :Unsubscribe, :Dump, :CreateSnapshot, :RemoveSnapshot, :Reload, :Reexecute, :Exit, :Reboot, :PowerOff, :Halt, :KExec, :SwitchRoot, :SetEnvironment, :UnsetEnvironment, :UnsetAndSetEnvironment, :ListUnitFiles, :GetUnitFileState, :EnableUnitFiles, :DisableUnitFiles, :ReenableUnitFiles, :LinkUnitFiles, :PresetUnitFiles, :PresetUnitFilesWithMode, :MaskUnitFiles, :UnmaskUnitFiles, :SetDefaultTarget, :GetDefaultTarget, :PresetAllUnitFiles, :AddDependencyUnitFiles, :SetExitCode, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 219 | irb(main):030:0> mgr.GetDefaultTarget.first 220 | => "multi-user.target" 221 | irb(main):036:0> mgr.Get(DBus::Systemd::Manager::INTERFACE, 'Version').first 222 | => "229" 223 | irb(main):037:0> mgr.Get(DBus::Systemd::Manager::INTERFACE, 'UnitPath').first 224 | => ["/etc/systemd/system", "/run/systemd/system", "/run/systemd/generator", "/usr/local/lib/systemd/system", "/usr/lib/systemd/system", "/run/systemd/generator.late"] 225 | irb(main):038:0> mgr.properties['NFailedUnits'] 226 | => 0 227 | ``` 228 | 229 | ### DBus::Systemd::Unit 230 | 231 | For full docs, see [official docs](https://www.freedesktop.org/wiki/Software/systemd/dbus/). 232 | 233 | ```ruby 234 | irb(main):005:0> sshd = DBus::Systemd::Unit.new('sshd.service') 235 | => ... 236 | irb(main):006:0> sshd.object.methods - Object.methods 237 | => [:Set, :Get, :GetAll, :Kill, :Ping, :GetMachineId, :Introspect, :ResetFailed, :Reload, :Start, :Stop, :Restart, :TryRestart, :ReloadOrRestart, :ReloadOrTryRestart, :SetProperties, :[], :[]=, :path, :destination, :bus, :introspect, :api, :subnodes, :introspected, :default_iface, :interfaces, :define_shortcut_methods, :has_iface?, :on_signal, :subnodes=, :introspected=, :default_iface=] 238 | irb(main):007:0> sshd.Get(DBus::Systemd::Unit::INTERFACE, 'Wants').first 239 | => ["sshd-keygen.target"] 240 | irb(main):008:0> sshd.Get(DBus::Systemd::Unit::Service::INTERFACE, 'ExecStart').first 241 | => [["/usr/sbin/sshd", ["/usr/sbin/sshd", "$OPTIONS"], false, 1475455155565079, 3239817089, 1475455155581392, 3239833403, 5860, 1, 0]] 242 | irb(main):010:0> sshd.Restart('replace') 243 | => ["/org/freedesktop/systemd1/job/3326"] 244 | ``` 245 | 246 | ## Development 247 | 248 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 249 | 250 | To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 251 | 252 | A Vagrantfile is provided in the VCS root that creates a Fedora vagrant box, with which library can be tested and D-Bus interfaces explored. 253 | 254 | ## Contributing 255 | 256 | Bug reports and pull requests are welcome on GitHub at https://github.com/nathwill/ruby-dbus-systemd. 257 | 258 | ## License 259 | 260 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 261 | 262 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require 'rspec/core/rake_task' 3 | require 'rubocop/rake_task' 4 | 5 | RuboCop::RakeTask.new 6 | RSpec::Core::RakeTask.new(:spec) 7 | 8 | task default: %i[rubocop spec] 9 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure('2') do |config| 5 | config.vm.box = 'bento/fedora-27' 6 | config.vm.box_check_update = true 7 | 8 | config.vm.provision 'shell', inline: <<-SHELL 9 | dnf install -y git ruby rubygem-bundler rubygem-rake systemd-container btrfs-progs 10 | SHELL 11 | end 12 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'bundler/setup' 4 | require 'dbus/systemd' 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require 'irb' 14 | IRB.start 15 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /dbus-systemd.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'dbus/systemd/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'dbus-systemd' 8 | spec.version = DBus::Systemd::VERSION 9 | spec.authors = ['Nathan Williams'] 10 | spec.email = ['nath.e.will@gmail.com'] 11 | 12 | spec.summary = 'systemd D-Bus API library' 13 | spec.description = 'library for interfacing with systemd D-Bus APIs' 14 | spec.homepage = 'https://github.com/nathwill/ruby-dbus-systemd' 15 | spec.license = 'MIT' 16 | 17 | # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' 18 | # to allow pushing to a single host or delete this section to allow pushing to any host. 19 | if spec.respond_to?(:metadata) 20 | spec.metadata['allowed_push_host'] = 'https://rubygems.org' 21 | else 22 | raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' 23 | end 24 | 25 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 26 | spec.bindir = 'exe' 27 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 28 | spec.require_paths = ['lib'] 29 | 30 | spec.add_runtime_dependency 'ruby-dbus', '~> 0.14' 31 | 32 | spec.add_development_dependency 'bundler', '~> 1.16' 33 | spec.add_development_dependency 'rake', '~> 12.3' 34 | spec.add_development_dependency 'rspec', '~> 3.7' 35 | spec.add_development_dependency 'rubocop', '~> 0.51' 36 | spec.add_development_dependency 'yard', '~> 0.9' 37 | end 38 | -------------------------------------------------------------------------------- /lib/dbus/systemd.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative 'systemd/helpers' 22 | require_relative 'systemd/hostnamed' 23 | require_relative 'systemd/importd' 24 | require_relative 'systemd/job' 25 | require_relative 'systemd/localed' 26 | require_relative 'systemd/logind' 27 | require_relative 'systemd/machined' 28 | require_relative 'systemd/manager' 29 | require_relative 'systemd/mixin' 30 | require_relative 'systemd/networkd' 31 | require_relative 'systemd/resolved' 32 | require_relative 'systemd/timedated' 33 | require_relative 'systemd/unit' 34 | require_relative 'systemd/version' 35 | -------------------------------------------------------------------------------- /lib/dbus/systemd/helpers.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require 'dbus' 22 | 23 | module DBus 24 | module Systemd 25 | module Helpers 26 | # 27 | # get an instance of the system bus 28 | # 29 | # @return [DBus::SystemBus] 30 | def system_bus 31 | DBus::SystemBus.instance 32 | end 33 | 34 | # 35 | # get an instance of the session bus 36 | # 37 | # @return [DBus::SessionBus] 38 | def session_bus 39 | DBus::SessionBus.instance 40 | end 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 48 | def map_array(array, map) 49 | mapped = {} 50 | 51 | array.each_with_index do |item, index| 52 | mapped[map.key(index)] = item 53 | end 54 | 55 | mapped 56 | end 57 | 58 | module_function :system_bus, :session_bus, :map_array 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /lib/dbus/systemd/hostnamed.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | # 22 | # See docs for full API description: 23 | # https://www.freedesktop.org/wiki/Software/systemd/hostnamed/ 24 | # 25 | require_relative 'helpers' 26 | require_relative 'mixin' 27 | 28 | module DBus 29 | module Systemd 30 | class Hostnamed 31 | # the hostnamed dbus node path 32 | NODE = '/org/freedesktop/hostname1'.freeze 33 | 34 | # the hostnamed dbus service & interface 35 | SERVICE = INTERFACE = 'org.freedesktop.hostname1'.freeze 36 | 37 | include Mixin::MethodMissing 38 | include Mixin::Properties 39 | 40 | # @return [DBus::Service] 41 | # @api private 42 | attr_reader :service 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 49 | def initialize(bus = Helpers.system_bus) 50 | @service = bus.service(SERVICE) 51 | @object = @service.object(NODE) 52 | @object.default_iface = INTERFACE 53 | @object.introspect 54 | end 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /lib/dbus/systemd/importd.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | # 22 | # See docs for full API description: 23 | # https://www.freedesktop.org/wiki/Software/systemd/importd/ 24 | # 25 | require_relative 'importd/manager' 26 | require_relative 'importd/transfer' 27 | -------------------------------------------------------------------------------- /lib/dbus/systemd/importd/manager.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../helpers' 22 | require_relative '../mixin' 23 | require_relative 'transfer' 24 | 25 | module DBus 26 | module Systemd 27 | module Importd 28 | # the importd dbus interface 29 | SERVICE = 'org.freedesktop.import1'.freeze 30 | 31 | class Manager 32 | # the importd manager dbus node path 33 | NODE = '/org/freedesktop/import1'.freeze 34 | 35 | # the importd manager dbus interface 36 | INTERFACE = 'org.freedesktop.import1.Manager'.freeze 37 | 38 | # index mapping of transfer array returned from ListTransfers() 39 | TRANSFER_INDICES = { 40 | id: 0, 41 | operation: 1, 42 | remote_file: 2, 43 | image_name: 3, 44 | progress: 4, 45 | object_path: 5 46 | }.freeze 47 | 48 | include Systemd::Mixin::MethodMissing 49 | include Systemd::Mixin::Properties 50 | 51 | # @return [DBus::Service] 52 | # @api private 53 | attr_reader :service 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 60 | def initialize(bus = Systemd::Helpers.system_bus) 61 | @service = bus.service(Importd::SERVICE) 62 | @object = @service.object(NODE) 63 | @object.default_iface = INTERFACE 64 | @object.introspect 65 | end 66 | 67 | # 68 | # return a list of mapped transfers 69 | # 70 | # @return [Array] array of hashes with transfer data 71 | def transfers 72 | self.ListTransfers.first.map { |t| map_transfer(t) } 73 | end 74 | 75 | # 76 | # Create a transfer object from a transfer id 77 | # 78 | # @param id [Integer] transfer id 79 | # @return [DBus::Systemd::Importd::Transfer] importd transfer object 80 | def transfer(id) 81 | Transfer.new(id, self) 82 | end 83 | 84 | # 85 | # Create a transfer object from the transfer node path 86 | # 87 | # @param path [String] transfer dbus node path 88 | # @return [DBus::Systemd::Importd::Transfer] importd transfer object 89 | def get_transfer_by_path(path) 90 | obj = @service.object(path) 91 | .tap(&:introspect) 92 | Transfer.new(obj.Get(Transfer::INTERFACE, 'Id').first, self) 93 | end 94 | 95 | # 96 | # map a transfer array as returned from ListTransfers 97 | # to a hash with keys from TRANSER_INDICES 98 | # 99 | # @param transfer_array [Array] a transfer array 100 | # @return [Hash] mapped transfer array to named fields 101 | def map_transfer(transfer_array) 102 | Systemd::Helpers.map_array(transfer_array, TRANSFER_INDICES) 103 | end 104 | end 105 | end 106 | end 107 | end 108 | -------------------------------------------------------------------------------- /lib/dbus/systemd/importd/transfer.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../mixin' 22 | require_relative 'manager' 23 | 24 | module DBus 25 | module Systemd 26 | module Importd 27 | class Transfer 28 | # importd transfer object dbus interface 29 | INTERFACE = 'org.freedesktop.import1.Transfer'.freeze 30 | 31 | include Systemd::Mixin::MethodMissing 32 | include Systemd::Mixin::Properties 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 39 | def initialize(id, manager = Manager.new) 40 | @object = manager.service.object("#{Manager::NODE}/transfer/_#{id}") 41 | @object.default_iface = INTERFACE 42 | @object.introspect 43 | end 44 | end 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/dbus/systemd/job.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative 'manager' 22 | require_relative 'mixin' 23 | 24 | module DBus 25 | module Systemd 26 | class Job 27 | # systemd job object dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Job'.freeze 29 | 30 | include Mixin::MethodMissing 31 | include Mixin::Properties 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 38 | def initialize(id, manager = Manager.new) 39 | job_path = manager.GetJob(id).first 40 | @object = manager.service.object(job_path) 41 | @object.default_iface = INTERFACE 42 | @object.introspect 43 | end 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/dbus/systemd/localed.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | # 22 | # See docs for full API description: 23 | # https://www.freedesktop.org/wiki/Software/systemd/localed/ 24 | # 25 | require_relative 'helpers' 26 | require_relative 'mixin' 27 | 28 | module DBus 29 | module Systemd 30 | class Localed 31 | # the localed object dbus node path 32 | NODE = '/org/freedesktop/locale1'.freeze 33 | 34 | # the localed object dbus service & interface 35 | SERVICE = INTERFACE = 'org.freedesktop.locale1'.freeze 36 | 37 | include Mixin::MethodMissing 38 | include Mixin::Properties 39 | 40 | # @return [DBus::Service] 41 | # @api private 42 | attr_reader :service 43 | 44 | # 45 | # Create a new DBus::Systemd::Localed object 46 | # 47 | # @param bus [DBus::SystemBus, DBus::SessionBus] the bus instance 48 | def initialize(bus = Helpers.system_bus) 49 | @service = bus.service(SERVICE) 50 | @object = @service.object(NODE) 51 | @object.default_iface = INTERFACE 52 | @object.introspect 53 | end 54 | end 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /lib/dbus/systemd/logind.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | # 22 | # See docs for full API description: 23 | # https://www.freedesktop.org/wiki/Software/systemd/logind/ 24 | # 25 | require_relative 'logind/manager' 26 | require_relative 'logind/seat' 27 | require_relative 'logind/session' 28 | require_relative 'logind/user' 29 | -------------------------------------------------------------------------------- /lib/dbus/systemd/logind/manager.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../helpers' 22 | require_relative '../mixin' 23 | require_relative 'session' 24 | require_relative 'user' 25 | require_relative 'seat' 26 | 27 | module DBus 28 | module Systemd 29 | module Logind 30 | # the logind objet dbus service 31 | SERVICE = 'org.freedesktop.login1'.freeze 32 | 33 | class Manager 34 | # the logind manager object dbus node path 35 | NODE = '/org/freedesktop/login1'.freeze 36 | 37 | # the logind manager object dbus interface 38 | INTERFACE = 'org.freedesktop.login1.Manager'.freeze 39 | 40 | # session array index map as returned by ListSessions 41 | SESSION_INDICES = { 42 | id: 0, 43 | user_id: 1, 44 | user_name: 2, 45 | seat_id: 3, 46 | object_path: 4 47 | }.freeze 48 | 49 | # user array index map as returned by ListUsers 50 | USER_INDICES = { 51 | id: 0, 52 | name: 1, 53 | object_path: 2 54 | }.freeze 55 | 56 | # seat array index map as returned by ListSeats 57 | SEAT_INDICES = { 58 | id: 0, 59 | object_path: 1 60 | }.freeze 61 | 62 | # inhibitor array index map as returned by ListInhibitors 63 | INHIBITOR_INDICES = { 64 | what: 0, 65 | who: 1, 66 | why: 2, 67 | mode: 3, 68 | user_id: 4, 69 | process_id: 5 70 | }.freeze 71 | 72 | include Systemd::Mixin::MethodMissing 73 | include Systemd::Mixin::Properties 74 | 75 | # @return [DBus::Service] 76 | # @api private 77 | attr_reader :service 78 | 79 | # 80 | # Create a logind manager dbus proxy object 81 | # 82 | # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance 83 | def initialize(bus = Systemd::Helpers.system_bus) 84 | @service = bus.service(Logind::SERVICE) 85 | @object = @service.object(NODE) 86 | @object.default_iface = INTERFACE 87 | @object.introspect 88 | end 89 | 90 | # 91 | # get mapped list of seats 92 | # 93 | # @return [Array] array of mapped seat hashes 94 | def seats 95 | self.ListSeats.first.map { |s| map_seat(s) } 96 | end 97 | 98 | # 99 | # get seat object 100 | # 101 | # @param id [String] seat id (e.g. 'seat0') 102 | # @return [DBus::Systemd::Logind::Seat] logind seat object 103 | def seat(id) 104 | Seat.new(id, self) 105 | end 106 | 107 | # 108 | # get seat object from dbus node path 109 | # 110 | # @param path [String] seat dbus node path 111 | # @return [DBus::Systemd::Logind::Seat] logind seat object 112 | def get_seat_by_path(path) 113 | obj = @service.object(path) 114 | .tap(&:introspect) 115 | Seat.new(obj.Get(Seat::INTERFACE, 'Id').first, self) 116 | end 117 | 118 | # 119 | # map seat array to named field hash 120 | # 121 | # @param seat_array [Array] seat array as returned from ListSeats 122 | # @return [Hash] mapped array as hash 123 | def map_seat(seat_array) 124 | Systemd::Helpers.map_array(seat_array, SEAT_INDICES) 125 | end 126 | 127 | # 128 | # array of property-mapped seat hashes 129 | # 130 | # @return [Array] array of seat-property hashes 131 | def sessions 132 | self.ListSessions.first.map { |s| map_session(s) } 133 | end 134 | 135 | # 136 | # dbus session object by id 137 | # 138 | # @param id [String] session id 139 | # @return [DBus::Systemd::Logind::Session] logind session object 140 | def session(id) 141 | Session.new(id, self) 142 | end 143 | 144 | # 145 | # get session object by dbus node path 146 | # 147 | # @param path [String] session dbus node path 148 | # @return [DBus::Systemd::Logind::Session] logind session object 149 | def get_session_by_path(path) 150 | obj = @service.object(path) 151 | .tap(&:introspect) 152 | Session.new(obj.Get(Session::INTERFACE, 'Id').first, self) 153 | end 154 | 155 | # 156 | # convert session array to mapped hash 157 | # 158 | # @param session_array [Array] session array as returned by ListSessions 159 | # @return [Hash] mapped session property hash 160 | def map_session(session_array) 161 | Systemd::Helpers.map_array(session_array, SESSION_INDICES) 162 | end 163 | 164 | # 165 | # get logind users 166 | # 167 | # @return [Array] array of mapped logind user property hashes 168 | def users 169 | self.ListUsers.first.map { |u| map_user(u) } 170 | end 171 | 172 | # 173 | # get user dbus object 174 | # 175 | # @param id [Integer] user id 176 | # @return [DBus::Systemd::Logind::User] logind user dbus object 177 | def user(id) 178 | User.new(id, self) 179 | end 180 | 181 | # 182 | # get user dbus object from dbus node path 183 | # 184 | # @param path [String] dbus node path for user 185 | # @return [DBus::Systemd::Logind::User] logind user dbus object 186 | def get_user_by_path(path) 187 | obj = @service.object(path) 188 | .tap(&:introspect) 189 | User.new(obj.Get(User::INTERFACE, 'Id').first, self) 190 | end 191 | 192 | # 193 | # convert user array to hash with mapped properties 194 | # 195 | # @param user_array [Array] user array as returned by ListUsers 196 | # @return [Hash] hash with mapped user properties 197 | def map_user(user_array) 198 | Systemd::Helpers.map_array(user_array, USER_INDICES) 199 | end 200 | end 201 | end 202 | end 203 | end 204 | -------------------------------------------------------------------------------- /lib/dbus/systemd/logind/seat.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../mixin' 22 | require_relative 'manager' 23 | 24 | module DBus 25 | module Systemd 26 | module Logind 27 | class Seat 28 | # logind seat object dbus interface 29 | INTERFACE = 'org.freedesktop.login1.Seat'.freeze 30 | 31 | include Systemd::Mixin::MethodMissing 32 | include Systemd::Mixin::Properties 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 39 | def initialize(id, manager = Manager.new) 40 | seat_path = manager.GetSeat(id).first 41 | @object = manager.service.object(seat_path) 42 | @object.default_iface = INTERFACE 43 | @object.introspect 44 | end 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/dbus/systemd/logind/session.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../mixin' 22 | require_relative 'manager' 23 | 24 | module DBus 25 | module Systemd 26 | module Logind 27 | class Session 28 | # logind session object dbus interface 29 | INTERFACE = 'org.freedesktop.login1.Session'.freeze 30 | 31 | include Systemd::Mixin::MethodMissing 32 | include Systemd::Mixin::Properties 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 39 | def initialize(id, manager = Manager.new) 40 | session_path = manager.GetSession(id).first 41 | @object = manager.service.object(session_path) 42 | @object.default_iface = INTERFACE 43 | @object.introspect 44 | end 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/dbus/systemd/logind/user.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../mixin' 22 | require_relative 'manager' 23 | 24 | module DBus 25 | module Systemd 26 | module Logind 27 | class User 28 | # logind user object dbus interface 29 | INTERFACE = 'org.freedesktop.login1.User'.freeze 30 | 31 | include Systemd::Mixin::MethodMissing 32 | include Systemd::Mixin::Properties 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 39 | def initialize(id, manager = Manager.new) 40 | user_path = manager.GetUser(id).first 41 | @object = manager.service.object(user_path) 42 | @object.default_iface = INTERFACE 43 | @object.introspect 44 | end 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/dbus/systemd/machined.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | # 22 | # See docs for full API description: 23 | # https://www.freedesktop.org/wiki/Software/systemd/machined/ 24 | # 25 | require_relative 'machined/image' 26 | require_relative 'machined/machine' 27 | require_relative 'machined/manager' 28 | -------------------------------------------------------------------------------- /lib/dbus/systemd/machined/image.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../mixin' 22 | require_relative 'manager' 23 | 24 | module DBus 25 | module Systemd 26 | module Machined 27 | class Image 28 | # machined image object dbus interface 29 | INTERFACE = 'org.freedesktop.machine1.Image'.freeze 30 | 31 | include Systemd::Mixin::MethodMissing 32 | include Systemd::Mixin::Properties 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 39 | def initialize(name, manager = Manager.new) 40 | image_path = manager.GetImage(name).first 41 | @object = manager.service.object(image_path) 42 | @object.default_iface = INTERFACE 43 | @object.introspect 44 | end 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/dbus/systemd/machined/machine.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../mixin' 22 | require_relative 'manager' 23 | 24 | module DBus 25 | module Systemd 26 | module Machined 27 | class Machine 28 | # machined machine object dbus interface 29 | INTERFACE = 'org.freedesktop.machine1.Machine'.freeze 30 | 31 | include Systemd::Mixin::MethodMissing 32 | include Systemd::Mixin::Properties 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 39 | def initialize(name, manager = Manager.new) 40 | machine_path = manager.GetMachine(name).first 41 | @object = manager.service.object(machine_path) 42 | @object.default_iface = INTERFACE 43 | @object.introspect 44 | end 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/dbus/systemd/machined/manager.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../helpers' 22 | require_relative '../mixin' 23 | require_relative 'machine' 24 | require_relative 'image' 25 | 26 | module DBus 27 | module Systemd 28 | module Machined 29 | # machined dbus service 30 | SERVICE = 'org.freedesktop.machine1'.freeze 31 | 32 | class Manager 33 | # machined manager dbus object node path 34 | NODE = '/org/freedesktop/machine1'.freeze 35 | 36 | # machined manager dbus interface 37 | INTERFACE = 'org.freedesktop.machine1.Manager'.freeze 38 | 39 | # machine array index map as returned by ListMachines 40 | MACHINE_INDICES = { 41 | name: 0, 42 | class: 1, 43 | service_id: 2, 44 | object_path: 3 45 | }.freeze 46 | 47 | # image array index map as returned by ListImages 48 | IMAGE_INDICES = { 49 | name: 0, 50 | type: 1, 51 | read_only: 2, 52 | creation_time: 3, 53 | modification_time: 4, 54 | disk_space: 5, 55 | object_path: 6 56 | }.freeze 57 | 58 | include Systemd::Mixin::MethodMissing 59 | include Systemd::Mixin::Properties 60 | 61 | # @return [DBus::Service] 62 | # @api private 63 | attr_reader :service 64 | 65 | # 66 | # Create machined Manager dbus proxy object 67 | # 68 | # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance 69 | def initialize(bus = Systemd::Helpers.system_bus) 70 | @service = bus.service(Machined::SERVICE) 71 | @object = @service.object(NODE) 72 | @object.default_iface = INTERFACE 73 | @object.introspect 74 | end 75 | 76 | # 77 | # array of machines with mapped properties 78 | # 79 | # @return [Array] array of machine property hashes 80 | def machines 81 | self.ListMachines.first.map { |m| map_machine(m) } 82 | end 83 | 84 | # 85 | # get machine dbus proxy object by machine name 86 | # 87 | # @param name [String] machine name 88 | # @return [DBus::Systemd::Machined::Machine] machine instance 89 | def machine(name) 90 | Machine.new(name, self) 91 | end 92 | 93 | # 94 | # get machine dbus proxy object by dbus node path 95 | # 96 | # @param path [String] machine dbus node path 97 | # @return [DBus::Systemd::Machined::Machine] machine instance 98 | def get_machine_by_path(path) 99 | obj = @service.object(path) 100 | .tap(&:introspect) 101 | Machine.new(obj.Get(Machine::INTERFACE, 'Name').first, self) 102 | end 103 | 104 | # 105 | # map machine property array from ListMachines to indexed property hash 106 | # 107 | # @param machine_array [Array] machine property array as returned by ListMachines 108 | # @return [Hash] hash containing mapped machine properties 109 | def map_machine(machine_array) 110 | Systemd::Helpers.map_array(machine_array, MACHINE_INDICES) 111 | end 112 | 113 | # 114 | # get mapped array of images 115 | # 116 | # @return [Array] array of mapped image property hashes 117 | def images 118 | self.ListImages.first.map { |i| map_image(i) } 119 | end 120 | 121 | # 122 | # get image proxy object by name 123 | # 124 | # @param name [String] image name 125 | # @return [DBus::Systemd::Machined::Machine] image dbus proxy object 126 | def image(name) 127 | Image.new(name, self) 128 | end 129 | 130 | # 131 | # get image dbus proxy object by dbus node path 132 | # 133 | # @param path [String] image dbus node path 134 | # @return [DBus::Systemd::Machined::Image] image dbus proxy object 135 | def get_image_by_path(path) 136 | obj = @service.object(path) 137 | .tap(&:introspect) 138 | Image.new(obj.Get(Image::INTERFACE, 'Name').first, self) 139 | end 140 | 141 | # 142 | # map image array as returned by ListImages to property hash 143 | # 144 | # @param image_array [Array] image property array as returned by ListImages 145 | # @return [Hash] image property hash 146 | def map_image(image_array) 147 | Systemd::Helpers.map_array(image_array, IMAGE_INDICES) 148 | end 149 | end 150 | end 151 | end 152 | end 153 | -------------------------------------------------------------------------------- /lib/dbus/systemd/manager.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | # 22 | # See docs for full API description: 23 | # https://www.freedesktop.org/wiki/Software/systemd/dbus/ 24 | # 25 | require_relative 'helpers' 26 | require_relative 'mixin' 27 | require_relative 'unit' 28 | require_relative 'job' 29 | 30 | module DBus 31 | module Systemd 32 | # systemd dbus service 33 | SERVICE = 'org.freedesktop.systemd1'.freeze 34 | 35 | class Manager 36 | # systemd manager object dbus node path 37 | NODE = '/org/freedesktop/systemd1'.freeze 38 | 39 | # systemd manager dbus interface 40 | INTERFACE = 'org.freedesktop.systemd1.Manager'.freeze 41 | 42 | # index map of unit array returned by ListUnits 43 | UNIT_INDICES = { 44 | name: 0, 45 | description: 1, 46 | load_state: 2, 47 | active_state: 3, 48 | sub_state: 4, 49 | following: 5, 50 | object_path: 6, 51 | job_id: 7, 52 | job_type: 8, 53 | job_object_path: 9 54 | }.freeze 55 | 56 | # index map of job array returned by ListJobs 57 | JOB_INDICES = { 58 | id: 0, 59 | unit: 1, 60 | type: 2, 61 | state: 3, 62 | object_path: 4, 63 | unit_object_path: 5 64 | }.freeze 65 | 66 | include Mixin::MethodMissing 67 | include Mixin::Properties 68 | 69 | # @return [DBus::Service] 70 | # @api private 71 | attr_reader :service 72 | 73 | # 74 | # Create a systemd manager dbus proxy object 75 | # 76 | # @param bus [DBus::SystemBus, DBus::SessionBus] bus instance 77 | def initialize(bus = Systemd::Helpers.system_bus) 78 | @service = bus.service(Systemd::SERVICE) 79 | @object = @service.object(NODE) 80 | @object.default_iface = INTERFACE 81 | @object.introspect 82 | end 83 | 84 | # 85 | # get an array of mapped units/unit properties 86 | # 87 | # @return [Array] array of mapped unit property hashes 88 | def units 89 | self.ListUnits.first.map { |u| map_unit(u) } 90 | end 91 | 92 | # 93 | # get a unit dbus proxy object by name 94 | # 95 | # @param name [String] unit name (e.g. 'sshd.service') 96 | # @return [DBus::Systemd::Unit] unit dbus proxy object 97 | def unit(name) 98 | Unit.new(name, self) 99 | end 100 | 101 | # 102 | # get unit object by dbus node path 103 | # 104 | # @param path [String] unit dbus node path 105 | # @return [DBus::Systemd::Unit] unit dbus proxy object 106 | def get_unit_by_object_path(path) 107 | obj = @service.object(path) 108 | .tap(&:introspect) 109 | Unit.new(obj.Get(Unit::INTERFACE, 'Id').first, self) 110 | end 111 | 112 | # 113 | # map unit array from ListUnits to property hash 114 | # 115 | # @param unit_array [Array] array as returned from ListUnits 116 | # @return [Hash] unit property hash 117 | def map_unit(unit_array) 118 | Helpers.map_array(unit_array, UNIT_INDICES) 119 | end 120 | 121 | # 122 | # array of jobs from ListJobs mapped to property hashes 123 | # 124 | # @return [Array] array of job property hashes 125 | def jobs 126 | self.ListJobs.first.map { |j| map_job(j) } 127 | end 128 | 129 | # 130 | # get job by id 131 | # 132 | # @param id [Integer] job id 133 | # @return [DBus::Systemd::Job] job dbus proxy object 134 | def job(id) 135 | Job.new(id, self) 136 | end 137 | 138 | # 139 | # get job by dbus node path 140 | # 141 | # @param path [String] job dbus node path 142 | # @return [DBus::Systemd::Job] job dbus proxy object 143 | def get_job_by_object_path(path) 144 | obj = @service.object(path) 145 | .tap(&:introspect) 146 | Job.new(obj.Get(Job::INTERFACE, 'Id').first, self) 147 | end 148 | 149 | # 150 | # map job array from ListJobs to property hash 151 | # 152 | # @param job_array [Array] job property array as returned by ListJobs 153 | # @return [Hash] mapped job property hash 154 | def map_job(job_array) 155 | Helpers.map_array(job_array, JOB_INDICES) 156 | end 157 | end 158 | end 159 | end 160 | -------------------------------------------------------------------------------- /lib/dbus/systemd/mixin.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | module DBus 22 | module Systemd 23 | module Mixin 24 | module MethodMissing 25 | # @return DBus::ProxyObject 26 | # @api private 27 | attr_reader :object 28 | 29 | # 30 | # use method_missing to proxy methods to 31 | # the dbus proxy object interface methods 32 | # 33 | def method_missing(name, *args, &blk) 34 | if @object.respond_to?(name) 35 | @object.send(name, *args, &blk) 36 | else 37 | super 38 | end 39 | end 40 | 41 | # 42 | # fix respond_to to also check the dbus methods 43 | # 44 | def respond_to_missing?(*args) 45 | @object.respond_to?(*args) || super 46 | end 47 | end 48 | 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 55 | def properties(interface = self.class::INTERFACE) 56 | self.GetAll(interface).first 57 | end 58 | end 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /lib/dbus/systemd/networkd.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative 'networkd/link' 22 | require_relative 'networkd/manager' 23 | -------------------------------------------------------------------------------- /lib/dbus/systemd/networkd/link.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../mixin' 22 | require_relative 'manager' 23 | 24 | module DBus 25 | module Systemd 26 | module Networkd 27 | class Link 28 | # networkd link dbus interface 29 | INTERFACE = 'org.freedesktop.network1.Link'.freeze 30 | 31 | include Systemd::Mixin::MethodMissing 32 | include Systemd::Mixin::Properties 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 39 | def initialize(id, manager = Manager.new) 40 | @object = manager.service.object("#{Manager::NODE}/link/#{id}") 41 | @object.default_iface = INTERFACE 42 | @object.introspect 43 | end 44 | end 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/dbus/systemd/networkd/manager.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../helpers' 22 | require_relative '../mixin' 23 | require_relative 'link' 24 | 25 | module DBus 26 | module Systemd 27 | module Networkd 28 | # networkd dbus service 29 | SERVICE = 'org.freedesktop.network1'.freeze 30 | 31 | class Manager 32 | # networkd manager object dbus node path 33 | NODE = '/org/freedesktop/network1'.freeze 34 | 35 | # networkd manager dbus interface 36 | INTERFACE = 'org.freedesktop.network1.Manager'.freeze 37 | 38 | include Systemd::Mixin::MethodMissing 39 | include Systemd::Mixin::Properties 40 | 41 | # @return [DBus::Service] 42 | # @api private 43 | attr_reader :service 44 | 45 | # 46 | # create a networkd manager dbus proxy object 47 | # 48 | # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance 49 | def initialize(bus = Systemd::Helpers.system_bus) 50 | @service = bus.service(Networkd::SERVICE) 51 | @object = @service.object(NODE) 52 | @object.default_iface = INTERFACE 53 | @object.introspect 54 | end 55 | 56 | # 57 | # get a link by id 58 | # 59 | # @param id [Integer] networkd link id 60 | # @return [DBus::Systemd::Networkd::Link] networkd link dbus proxy object 61 | def link(id) 62 | Link.new(id, self) 63 | end 64 | end 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /lib/dbus/systemd/resolved.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | # 22 | # See docs for full API description: 23 | # https://www.freedesktop.org/wiki/Software/systemd/resolved/ 24 | # 25 | require_relative 'resolved/link' 26 | require_relative 'resolved/manager' 27 | -------------------------------------------------------------------------------- /lib/dbus/systemd/resolved/link.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../mixin' 22 | require_relative 'manager' 23 | 24 | module DBus 25 | module Systemd 26 | module Resolved 27 | class Link 28 | # resolved link dbus interface 29 | INTERFACE = 'org.freedesktop.resolve1.Link'.freeze 30 | 31 | include Systemd::Mixin::MethodMissing 32 | include Systemd::Mixin::Properties 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 39 | def initialize(id, manager = Manager.new) 40 | link_path = manager.GetLink(id).first 41 | @object = manager.service.object(link_path) 42 | @object.default_iface = INTERFACE 43 | @object.introspect 44 | end 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /lib/dbus/systemd/resolved/manager.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../helpers' 22 | require_relative '../mixin' 23 | require_relative 'link' 24 | 25 | module DBus 26 | module Systemd 27 | module Resolved 28 | # resolved dbus interface 29 | INTERFACE = 'org.freedesktop.resolve1'.freeze 30 | 31 | class Manager 32 | # resolved manager object dbus node path 33 | NODE = '/org/freedesktop/resolve1'.freeze 34 | 35 | # resolved manager dbus interface 36 | INTERFACE = 'org.freedesktop.resolve1.Manager'.freeze 37 | 38 | include Systemd::Mixin::MethodMissing 39 | include Systemd::Mixin::Properties 40 | 41 | # @return [DBus::Service] 42 | # @api private 43 | attr_reader :service 44 | 45 | # 46 | # get a new resolved manager dbus proxy object 47 | # 48 | # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance 49 | def initialize(bus = Systemd::Helpers.system_bus) 50 | @service = bus.service(Resolved::INTERFACE) 51 | @object = @service.object(NODE) 52 | @object.default_iface = INTERFACE 53 | @object.introspect 54 | end 55 | 56 | # 57 | # get a resolved link by id 58 | # 59 | # @param id [Integer] resolved link id 60 | # @return [DBus::Systemd::Resolved::Link] resolved link dbus proxy object 61 | def link(id) 62 | Link.new(id, self) 63 | end 64 | end 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /lib/dbus/systemd/timedated.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative 'helpers' 22 | require_relative 'mixin' 23 | 24 | module DBus 25 | module Systemd 26 | class Timedated 27 | # the timedated dbus node path 28 | NODE = '/org/freedesktop/timedate1'.freeze 29 | 30 | # the timedated dbus service & interface 31 | SERVICE = INTERFACE = 'org.freedesktop.timedate1'.freeze 32 | 33 | include Mixin::MethodMissing 34 | include Mixin::Properties 35 | 36 | # @return [DBus::Service] 37 | # @api private 38 | attr_reader :service 39 | 40 | # 41 | # Create a new object for interfacing with timedated 42 | # 43 | # @param bus [DBus::SystemBus, DBus::SessionBus] dbus instance 44 | def initialize(bus = Helpers.system_bus) 45 | @service = bus.service(SERVICE) 46 | @object = @service.object(NODE) 47 | @object.default_iface = INTERFACE 48 | @object.introspect 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative 'manager' 22 | require_relative 'mixin' 23 | 24 | module DBus 25 | module Systemd 26 | class Unit 27 | # the unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Unit'.freeze 29 | 30 | include Mixin::MethodMissing 31 | include Mixin::Properties 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 38 | def initialize(name, manager = Manager.new) 39 | unit_path = manager.GetUnit(name).first 40 | @object = manager.service.object(unit_path) 41 | @object.default_iface = INTERFACE 42 | @object.introspect 43 | end 44 | end 45 | end 46 | end 47 | 48 | require_relative 'unit/automount' 49 | require_relative 'unit/device' 50 | require_relative 'unit/mount' 51 | require_relative 'unit/path' 52 | require_relative 'unit/scope' 53 | require_relative 'unit/service' 54 | require_relative 'unit/slice' 55 | require_relative 'unit/snapshot' 56 | require_relative 'unit/socket' 57 | require_relative 'unit/swap' 58 | require_relative 'unit/target' 59 | require_relative 'unit/timer' 60 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/automount.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Automount < Unit 27 | # systemd automount unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Automount'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/device.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Device < Unit 27 | # systemd device unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Device'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/mount.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Mount < Unit 27 | # systemd mount unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Mount'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/path.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Path < Unit 27 | # systemd path unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Path'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/scope.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Scope < Unit 27 | # systemd scope unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Scope'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/service.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Service < Unit 27 | # systemd service unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Service'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/slice.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Slice < Unit 27 | # systemd slice unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Slice'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/snapshot.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Snapshot < Unit 27 | # systemd snapshot unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Snapshot'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/socket.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Socket < Unit 27 | # systemd socket unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Socket'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/swap.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Swap < Unit 27 | # systemd swap unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Swap'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/target.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Target < Unit 27 | # systemd target unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Target'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/unit/timer.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | require_relative '../unit' 22 | 23 | module DBus 24 | module Systemd 25 | class Unit 26 | class Timer < Unit 27 | # systemd timer unit dbus interface 28 | INTERFACE = 'org.freedesktop.systemd1.Timer'.freeze 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/dbus/systemd/version.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2016 Nathan Williams 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | # this software and associated documentation files (the "Software"), to deal in 6 | # the Software without restriction, including without limitation the rights to 7 | # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | # the Software, and to permit persons to whom the Software is furnished to do so, 9 | # subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | # 21 | module DBus 22 | module Systemd 23 | # dbus-systemd gem version 24 | VERSION = '1.1.2'.freeze 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /spec/dbus/systemd/helpers_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Helpers do 4 | let(:raw_array) { ['Black', 'Cat', 4] } 5 | let(:array_map) { { color: 0, animal: 1, age: 2 } } 6 | let(:converted) { { color: 'Black', animal: 'Cat', age: 4 } } 7 | 8 | it 'maps positional array to named hash' do 9 | expect(DBus::Systemd::Helpers.map_array(raw_array, array_map)).to eq converted 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/dbus/systemd/hostnamed_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Hostnamed do 4 | it 'sets the right node path' do 5 | expect(DBus::Systemd::Hostnamed::NODE).to eq '/org/freedesktop/hostname1' 6 | end 7 | 8 | it 'sets the right service' do 9 | expect(DBus::Systemd::Hostnamed::SERVICE).to eq 'org.freedesktop.hostname1' 10 | end 11 | 12 | it 'sets the right interface' do 13 | expect(DBus::Systemd::Hostnamed::INTERFACE).to eq 'org.freedesktop.hostname1' 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/dbus/systemd/importd/manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Importd::Manager do 4 | it 'sets the appropriate dbus node path' do 5 | expect(DBus::Systemd::Importd::Manager::NODE).to eq '/org/freedesktop/import1' 6 | end 7 | 8 | it 'sets the appropriate interface' do 9 | expect(DBus::Systemd::Importd::Manager::INTERFACE).to eq 'org.freedesktop.import1.Manager' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/dbus/systemd/importd/transfer_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Importd::Transfer do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Importd::Transfer::INTERFACE).to eq 'org.freedesktop.import1.Transfer' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/importd_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Importd do 4 | it 'sets the right service' do 5 | expect(DBus::Systemd::Importd::SERVICE).to eq 'org.freedesktop.import1' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/job_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Job do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Job::INTERFACE).to eq 'org.freedesktop.systemd1.Job' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/localed_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Localed do 4 | it 'sets the right dbus node path' do 5 | expect(DBus::Systemd::Localed::NODE).to eq '/org/freedesktop/locale1' 6 | end 7 | 8 | it 'sets the right service' do 9 | expect(DBus::Systemd::Localed::SERVICE).to eq 'org.freedesktop.locale1' 10 | end 11 | 12 | it 'sets the right interface' do 13 | expect(DBus::Systemd::Localed::INTERFACE).to eq 'org.freedesktop.locale1' 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/dbus/systemd/logind/manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Logind::Manager do 4 | it 'sets the right dbus node path' do 5 | expect(DBus::Systemd::Logind::Manager::NODE).to eq '/org/freedesktop/login1' 6 | end 7 | 8 | it 'sets the right interface' do 9 | expect(DBus::Systemd::Logind::Manager::INTERFACE).to eq 'org.freedesktop.login1.Manager' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/dbus/systemd/logind/seat_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Logind::Seat do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Logind::Seat::INTERFACE).to eq 'org.freedesktop.login1.Seat' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/logind/session_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Logind::Session do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Logind::Session::INTERFACE).to eq 'org.freedesktop.login1.Session' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/logind/user_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Logind::User do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Logind::User::INTERFACE).to eq 'org.freedesktop.login1.User' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/logind_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Logind do 4 | it 'sets the right service' do 5 | expect(DBus::Systemd::Logind::SERVICE).to eq 'org.freedesktop.login1' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/machined/machine_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Machined::Machine do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Machined::Machine::INTERFACE).to eq 'org.freedesktop.machine1.Machine' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/machined/manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Machined::Manager do 4 | it 'sets the right dbus node path' do 5 | expect(DBus::Systemd::Machined::Manager::NODE).to eq '/org/freedesktop/machine1' 6 | end 7 | 8 | it 'sets the right interface' do 9 | expect(DBus::Systemd::Machined::Manager::INTERFACE).to eq 'org.freedesktop.machine1.Manager' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/dbus/systemd/machined_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Machined do 4 | it 'sets the right service' do 5 | expect(DBus::Systemd::Machined::SERVICE).to eq 'org.freedesktop.machine1' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Manager do 4 | it 'sets the right dbus node path' do 5 | expect(DBus::Systemd::Manager::NODE).to eq '/org/freedesktop/systemd1' 6 | end 7 | 8 | it 'sets the right interface' do 9 | expect(DBus::Systemd::Manager::INTERFACE).to eq 'org.freedesktop.systemd1.Manager' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/dbus/systemd/mixin_spec.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nathwill/ruby-dbus-systemd/cf1470301f7520bcd9e8e5e5c9b5d28c7d50fe16/spec/dbus/systemd/mixin_spec.rb -------------------------------------------------------------------------------- /spec/dbus/systemd/networkd/link_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Networkd::Link do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Networkd::Link::INTERFACE).to eq 'org.freedesktop.network1.Link' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/networkd/manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Networkd::Manager do 4 | it 'sets the right dbus node path' do 5 | expect(DBus::Systemd::Networkd::Manager::NODE).to eq '/org/freedesktop/network1' 6 | end 7 | 8 | it 'sets the right interface' do 9 | expect(DBus::Systemd::Networkd::Manager::INTERFACE).to eq 'org.freedesktop.network1.Manager' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/dbus/systemd/networkd_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Networkd do 4 | it 'sets the right service' do 5 | expect(DBus::Systemd::Networkd::SERVICE).to eq 'org.freedesktop.network1' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/resolved/link_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Resolved::Link do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Resolved::Link::INTERFACE).to eq 'org.freedesktop.resolve1.Link' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/resolved/manager_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Resolved::Manager do 4 | it 'sets the right dbus node path' do 5 | expect(DBus::Systemd::Resolved::Manager::NODE).to eq '/org/freedesktop/resolve1' 6 | end 7 | 8 | it 'sets the right interface' do 9 | expect(DBus::Systemd::Resolved::Manager::INTERFACE).to eq 'org.freedesktop.resolve1.Manager' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/dbus/systemd/resolved_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Resolved do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Resolved::INTERFACE).to eq 'org.freedesktop.resolve1' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/timedated_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Timedated do 4 | it 'sets the right dbus node path' do 5 | expect(DBus::Systemd::Timedated::NODE).to eq '/org/freedesktop/timedate1' 6 | end 7 | 8 | it 'sets the right service' do 9 | expect(DBus::Systemd::Timedated::SERVICE).to eq 'org.freedesktop.timedate1' 10 | end 11 | 12 | it 'sets the right interface' do 13 | expect(DBus::Systemd::Timedated::INTERFACE).to eq 'org.freedesktop.timedate1' 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/automount_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Automount do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Automount::INTERFACE).to eq 'org.freedesktop.systemd1.Automount' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/device_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Device do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Device::INTERFACE).to eq 'org.freedesktop.systemd1.Device' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/mount_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Mount do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Mount::INTERFACE).to eq 'org.freedesktop.systemd1.Mount' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/path_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Path do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Path::INTERFACE).to eq 'org.freedesktop.systemd1.Path' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/scope_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Scope do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Scope::INTERFACE).to eq 'org.freedesktop.systemd1.Scope' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/service_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Service do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Service::INTERFACE).to eq 'org.freedesktop.systemd1.Service' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/slice_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Slice do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Slice::INTERFACE).to eq 'org.freedesktop.systemd1.Slice' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/snapshot_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Snapshot do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Snapshot::INTERFACE).to eq 'org.freedesktop.systemd1.Snapshot' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/socket_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Socket do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Socket::INTERFACE).to eq 'org.freedesktop.systemd1.Socket' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/swap_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Swap do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Swap::INTERFACE).to eq 'org.freedesktop.systemd1.Swap' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/target_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Target do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Target::INTERFACE).to eq 'org.freedesktop.systemd1.Target' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit/timer_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit::Timer do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::Timer::INTERFACE).to eq 'org.freedesktop.systemd1.Timer' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd/unit_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd::Unit do 4 | it 'sets the right interface' do 5 | expect(DBus::Systemd::Unit::INTERFACE).to eq 'org.freedesktop.systemd1.Unit' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/dbus/systemd_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe DBus::Systemd do 4 | it 'has a version number' do 5 | expect(DBus::Systemd::VERSION).not_to be nil 6 | end 7 | 8 | it 'sets the appropriate service' do 9 | expect(DBus::Systemd::SERVICE).to eq 'org.freedesktop.systemd1' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) 2 | require 'dbus/systemd' 3 | -------------------------------------------------------------------------------- /test/hostnamed.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # test script for running the code 4 | # through its paces in the vagrant box. 5 | # 6 | # must be run as privileged user! 7 | # 8 | 9 | require 'dbus/systemd' 10 | 11 | # 12 | # Hostnamed 13 | # 14 | hostnamed = DBus::Systemd::Hostnamed.new 15 | 16 | test_domain = 'mydomain.localdomain' 17 | 18 | hostnamed.SetHostname(test_domain, false) 19 | raise "Bad hostnamed result unless" unless hostnamed.properties['Hostname'] == test_domain 20 | puts "successfully changed hostname" 21 | -------------------------------------------------------------------------------- /test/localed.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # test script for running the code 4 | # through its paces in the vagrant box. 5 | # 6 | # must be run as privileged user! 7 | # 8 | 9 | require 'dbus/systemd' 10 | 11 | # 12 | # Localed 13 | # 14 | localed = DBus::Systemd::Localed.new 15 | raise 'Bad localed result' unless localed.properties['VConsoleKeymap'] == 'us' 16 | puts "successfully checked locale properties" 17 | -------------------------------------------------------------------------------- /test/logind.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # test script for running the code 4 | # through its paces in the vagrant box. 5 | # 6 | # must be run as privileged user! 7 | # 8 | 9 | require 'dbus/systemd' 10 | 11 | # 12 | # Logind 13 | # 14 | logind = DBus::Systemd::Logind::Manager.new 15 | raise "oh noes" unless logind.properties['KillUserProcesses'] == false 16 | puts "successfully checked logind manager properties" 17 | 18 | seat = logind.seat(logind.seats.first[:id]) 19 | raise "bad seat result" unless seat.properties['CanTTY'] == true 20 | puts "successfully checked seat" 21 | 22 | user = logind.user(logind.users.first[:id]) 23 | raise "bad user result" unless user.properties['Name'] == 'vagrant' 24 | puts "successfully checked user" 25 | 26 | session = logind.session(logind.sessions.first[:id]) 27 | raise "bad session result" unless user.properties['Name'] == 'vagrant' 28 | puts "successfully checked session" 29 | -------------------------------------------------------------------------------- /test/machined.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # test script for running the code 4 | # through its paces in the vagrant box. 5 | # 6 | # must be run as privileged user! 7 | # 8 | 9 | require 'dbus/systemd' 10 | 11 | # 12 | # Importd 13 | # 14 | 15 | bus = DBus::Systemd::Helpers.system_bus 16 | 17 | importd = DBus::Systemd::Importd::Manager.new(bus) 18 | machined = DBus::Systemd::Machined::Manager.new(bus) 19 | 20 | loop = DBus::Main.new 21 | loop << bus 22 | 23 | transfer_id = nil 24 | 25 | importd.on_signal('TransferRemoved') do |id, path, result| 26 | puts "Finished transfer: #{id}; Result: #{result}" 27 | loop.quit if id == transfer_id 28 | end 29 | 30 | source = 'https://dl.fedoraproject.org/pub/fedora/linux/releases/24/CloudImages/x86_64/images/Fedora-Cloud-Base-24-1.2.x86_64.raw.xz' 31 | img_name = 'Fedora-24' 32 | verify_mode = 'no' 33 | force_dl = true 34 | 35 | transfer_id = importd.PullRaw(source, img_name, verify_mode, force_dl).first 36 | 37 | loop.run 38 | 39 | raise "no image found" unless machined.images.detect { |img| img[:name] == img_name } 40 | puts "found image" 41 | -------------------------------------------------------------------------------- /test/manager.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # test script for running the code 4 | # through its paces in the vagrant box. 5 | # 6 | # must be run as privileged user! 7 | # 8 | 9 | require 'dbus/systemd' 10 | 11 | # 12 | # Manager 13 | # 14 | mgr = DBus::Systemd::Manager.new 15 | raise "bad mgr result" unless mgr.properties['Virtualization'] == 'oracle' 16 | puts "successfully checked manager properties" 17 | 18 | unit = mgr.unit('sshd.service') 19 | raise "bad unit result" unless unit.properties['SubState'] == 'running' 20 | puts "successfully checked unit state" 21 | 22 | loop = DBus::Main.new 23 | loop << mgr.bus 24 | 25 | job_path = nil 26 | 27 | mgr.on_signal('JobRemoved') do |id, path, unit, result| 28 | puts "Job #{id} completed for #{unit} with result: #{result}" 29 | loop.quit if path == job_path 30 | end 31 | 32 | job_path = mgr.RestartUnit('sshd.service', 'replace').first 33 | 34 | loop.run 35 | -------------------------------------------------------------------------------- /test/networkd.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # test script for running the code 4 | # through its paces in the vagrant box. 5 | # 6 | # must be run as privileged user! 7 | # 8 | 9 | require 'dbus/systemd' 10 | 11 | # 12 | # Networkd 13 | # 14 | networkd = DBus::Systemd::Networkd::Manager.new 15 | raise "bad networkd result" unless networkd.properties['OperationalState'] == 'routable' 16 | puts "successfully checked networkd mgr properties" 17 | 18 | networkd_link = DBus::Systemd::Networkd::Link.new(1) 19 | raise "bad networkd link result" unless networkd_link.properties['AdministrativeState'] == 'unmanaged' 20 | puts "successfully checked networkd link properties" 21 | -------------------------------------------------------------------------------- /test/resolved.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # test script for running the code 4 | # through its paces in the vagrant box. 5 | # 6 | # must be run as privileged user! 7 | # 8 | 9 | require 'dbus/systemd' 10 | 11 | # 12 | # Resolved 13 | # 14 | resolved = DBus::Systemd::Resolved::Manager.new 15 | raise "bad resolved proxy" unless resolved.respond_to?(:ResolveHostname) 16 | puts "successfully checked resolved mgr" 17 | 18 | resolved_link = DBus::Systemd::Resolved::Link.new(1) 19 | raise "bad resolved link proxy" unless resolved_link.respond_to?(:SetDNS) 20 | puts "successfully checked resolved link" 21 | -------------------------------------------------------------------------------- /test/timedated.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # test script for running the code 4 | # through its paces in the vagrant box. 5 | # 6 | # must be run as privileged user! 7 | # 8 | 9 | require 'dbus/systemd' 10 | 11 | # 12 | # Timedated 13 | # 14 | timedated = DBus::Systemd::Timedated.new 15 | timedated.SetTimezone('America/Los_Angeles', false) 16 | raise "bad timedated result" unless timedated.properties['Timezone'] == 'America/Los_Angeles' 17 | puts "successfully set timezone" 18 | --------------------------------------------------------------------------------