Commit 60055b97 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

[#33] Get the IP from the Host Network Interfaces

parent e8c97885
......@@ -26,6 +26,7 @@ Clone the sources:
- perlmagick
- libmoosex-types-netaddr-ip-perl
- libsys-statistics-linux-perl
- libio-interace-perl
##Old debian
......
......@@ -7,6 +7,8 @@ use Carp qw(croak);
use Data::Dumper;
use Socket qw( inet_aton inet_ntoa );
use Moose::Role;
use IO::Socket;
use IO::Interface;
use Sys::Hostname;
requires 'connect';
......@@ -25,9 +27,6 @@ requires 'list_domains';
# storage volume
requires 'create_volume';
# networks
requires 'list_networks';
############################################################
has 'host' => (
......@@ -156,12 +155,25 @@ sub ip {
$ip =~ s/.*?address (\d+)/$1/;
return $ip if $ip && $ip !~ /^127\./;
$ip = $self->_interface_ip();
return $ip if $ip && $ip !~ /^127/ && $ip =~ /^\d+\.\d+\.\d+\.\d+$/;
warn "WARNING: I can't find the IP of host $name, using localhost."
." This virtual machine won't be available from the network.";
return '127.0.0.1';
}
sub _interface_ip {
my $s = IO::Socket::INET->new(Proto => 'tcp');
for my $if ( $s->if_list) {
my $addr = $s->if_addr($if);
return $addr if $addr;
}
return;
}
sub _check_memory {
my $self = shift;
my %args = @_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment