diff options
author | Matteo Pasotti <matteo.pasotti@gmail.com> | 2014-11-24 23:41:03 +0100 |
---|---|---|
committer | Matteo Pasotti <matteo.pasotti@gmail.com> | 2014-11-24 23:41:03 +0100 |
commit | be11b6af34ef1ed2e2ae62cf53023a47bc875ce2 (patch) | |
tree | ad94d75fc2ec9a9edaea0cef4069b48fff997979 /lib/AdminPanel | |
parent | 3bd90f0c9f6d2c076ab6683194f6509aef16002a (diff) | |
download | manatools-be11b6af34ef1ed2e2ae62cf53023a47bc875ce2.tar manatools-be11b6af34ef1ed2e2ae62cf53023a47bc875ce2.tar.gz manatools-be11b6af34ef1ed2e2ae62cf53023a47bc875ce2.tar.bz2 manatools-be11b6af34ef1ed2e2ae62cf53023a47bc875ce2.tar.xz manatools-be11b6af34ef1ed2e2ae62cf53023a47bc875ce2.zip |
added getLocalHostName and setLocalHostName methods (rely on dbus hostnamed service)
Diffstat (limited to 'lib/AdminPanel')
-rw-r--r-- | lib/AdminPanel/Shared/Hosts.pm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/AdminPanel/Shared/Hosts.pm b/lib/AdminPanel/Shared/Hosts.pm index 9eed5b61..fa22c25f 100644 --- a/lib/AdminPanel/Shared/Hosts.pm +++ b/lib/AdminPanel/Shared/Hosts.pm @@ -22,6 +22,7 @@ package AdminPanel::Shared::Hosts; use Moose; use diagnostics; use Config::Hosts; +use Net::DBus; use utf8; # costants by Config::Hosts @@ -35,11 +36,23 @@ has 'configHosts' => ( builder => '_initialize' ); +has 'dbus' => ( + is => 'ro', + isa => 'HashRef', + builder => '_initDBusServiceObject', +); + sub _initialize { my $self = shift(); $self->configHosts(Config::Hosts->new()); } +sub _initDBusServiceObject { + my $self = shift(); + my %dbus_so = ( 'servicePath' => 'org.freedesktop.hostname1', 'objectPath' => '/org/freedesktop/hostname1' ); + return \%dbus_so; +} + =pod =head2 _getHosts @@ -99,4 +112,24 @@ sub _writeHosts { return $self->configHosts->write_hosts(); } +sub _getLocalHostName { + my $self = shift(); + my %params = %{$self->dbus()}; + my $bus = Net::DBus->system; + my $service = $bus->get_service($params{'servicePath'}); + my $object = $service->get_object($params{'objectPath'}); + my $properties = $object->GetAll($params{'servicePath'}); + return $properties->{Hostname}; +} + +sub _setLocalHostName { + my $self = shift(); + my $hostname = shift(); + my %params = %{$self->dbus()}; + my $bus = Net::DBus->system; + my $service = $bus->get_service($params{'servicePath'}); + my $object = $service->get_object($params{'objectPath'}); + $object->SetPrettyHostname($hostname, 1); +} + 1; |