Added username support for libvirt over SSH

This commit is contained in:
Jurrian van Iersel
2016-01-09 14:20:57 +01:00
parent af95e46a50
commit 93e76a2b5a
3 changed files with 11 additions and 3 deletions
+1
View File
@@ -488,6 +488,7 @@ This array can be used to filter out syslog messages that you don't want to be s
```php ```php
$config['enable_libvirt'] = 1; $config['enable_libvirt'] = 1;
$config['libvirt_protocols'] = array("qemu+ssh","xen+ssh"); $config['libvirt_protocols'] = array("qemu+ssh","xen+ssh");
$config['libvirt_username'] = 'root';
``` ```
Enable this to switch on support for libvirt along with `libvirt_protocols` Enable this to switch on support for libvirt along with `libvirt_protocols`
to indicate how you connect to libvirt. You also need to: to indicate how you connect to libvirt. You also need to:
+2
View File
@@ -640,6 +640,8 @@ $config['libvirt_protocols'] = array(
'qemu+ssh', 'qemu+ssh',
'xen+ssh', 'xen+ssh',
); );
// Use different username for libvirt over SSH
$config['libvirt_username'] = null;
// Mechanisms used, add or remove if not using this on any of your machines. // Mechanisms used, add or remove if not using this on any of your machines.
// Hardcoded ASN descriptions // Hardcoded ASN descriptions
$config['astext'][65332] = 'Cymru FullBogon Feed'; $config['astext'][65332] = 'Cymru FullBogon Feed';
+8 -3
View File
@@ -9,18 +9,23 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == 'linux') {
$ssh_ok = 0; $ssh_ok = 0;
$userHostname = $device['hostname'];
if (!is_null($config['libvirt_username'])) {
$userHostname = $config['libvirt_username'].'@'.$userHostname;
}
foreach ($config['libvirt_protocols'] as $method) { foreach ($config['libvirt_protocols'] as $method) {
if (strstr($method, 'qemu')) { if (strstr($method, 'qemu')) {
$uri = $method.'://'.$device['hostname'].'/system'; $uri = $method.'://'.$userHostname.'/system';
} }
else { else {
$uri = $method.'://'.$device['hostname']; $uri = $method.'://'.$userHostname;
} }
if (strstr($method, 'ssh') && !$ssh_ok) { if (strstr($method, 'ssh') && !$ssh_ok) {
// Check if we are using SSH if we can log in without password - without blocking the discovery // Check if we are using SSH if we can log in without password - without blocking the discovery
// Also automatically add the host key so discovery doesn't block on the yes/no question, and run echo so we don't get stuck in a remote shell ;-) // Also automatically add the host key so discovery doesn't block on the yes/no question, and run echo so we don't get stuck in a remote shell ;-)
exec('ssh -o "StrictHostKeyChecking no" -o "PreferredAuthentications publickey" -o "IdentitiesOnly yes" '.$device['hostname'].' echo -e', $out, $ret); exec('ssh -o "StrictHostKeyChecking no" -o "PreferredAuthentications publickey" -o "IdentitiesOnly yes" '.$userHostname.' echo -e', $out, $ret);
if ($ret != 255) { if ($ret != 255) {
$ssh_ok = 1; $ssh_ok = 1;
} }