aboutsummaryrefslogtreecommitdiffstats
path: root/lib/AdminPanel/Shared/Hosts.pm
diff options
context:
space:
mode:
authorMatteo Pasotti <matteo.pasotti@gmail.com>2014-11-24 23:41:03 +0100
committerMatteo Pasotti <matteo.pasotti@gmail.com>2014-11-24 23:41:03 +0100
commitbe11b6af34ef1ed2e2ae62cf53023a47bc875ce2 (patch)
treead94d75fc2ec9a9edaea0cef4069b48fff997979 /lib/AdminPanel/Shared/Hosts.pm
parent3bd90f0c9f6d2c076ab6683194f6509aef16002a (diff)
downloadcolin-keep-be11b6af34ef1ed2e2ae62cf53023a47bc875ce2.tar
colin-keep-be11b6af34ef1ed2e2ae62cf53023a47bc875ce2.tar.gz
colin-keep-be11b6af34ef1ed2e2ae62cf53023a47bc875ce2.tar.bz2
colin-keep-be11b6af34ef1ed2e2ae62cf53023a47bc875ce2.tar.xz
colin-keep-be11b6af34ef1ed2e2ae62cf53023a47bc875ce2.zip
added getLocalHostName and setLocalHostName methods (rely on dbus hostnamed service)
Diffstat (limited to 'lib/AdminPanel/Shared/Hosts.pm')
-rw-r--r--lib/AdminPanel/Shared/Hosts.pm33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/AdminPanel/Shared/Hosts.pm b/lib/AdminPanel/Shared/Hosts.pm
index 9eed5b6..fa22c25 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;