0.8.1: switch dropdown shows type, interface and IP; chosen switch is written into the new VM config
This commit is contained in:
1 parent
dd395dfe76
commit
81b4d6a63e
5 files changed
+54
-10
No files matched your search
+19
-5
@@ -693,7 +693,7 @@ function vmm_job_running(string $id): bool
|
||||
return $job !== null && in_array($job['state'], ['queued', 'running'], true);
|
||||
}
|
||||
|
||||
function vmm_job_new(string $verb, string $name, array $argv = [], int $timeout = 0): array
|
||||
function vmm_job_new(string $verb, string $name, array $argv = [], int $timeout = 0, array $meta = []): array
|
||||
{
|
||||
vmm_ensure_state_dirs();
|
||||
$id = date('Ymd-His') . '-' . bin2hex(random_bytes(4));
|
||||
@@ -712,6 +712,11 @@ function vmm_job_new(string $verb, string $name, array $argv = [], int $timeout
|
||||
'error' => '',
|
||||
'by' => (string)($_SERVER['REMOTE_ADDR'] ?? 'cli'),
|
||||
];
|
||||
foreach ($meta as $k => $v) {
|
||||
if (is_scalar($v)) {
|
||||
$job[$k] = $v;
|
||||
}
|
||||
}
|
||||
vmm_job_write($job);
|
||||
@touch(VMM_JOBDIR . '/' . $id . '.log');
|
||||
|
||||
@@ -1152,6 +1157,15 @@ function vmm_vnc_connect(string $bind, string $host = ''): string
|
||||
* IP of the bridge that carries this VM's traffic (the address a client on
|
||||
* that network actually reaches). Falls back to the host name.
|
||||
*/
|
||||
function vmm_iface_ipv4(string $iface): string
|
||||
{
|
||||
if ($iface === '' || $iface === 'n/a') {
|
||||
return '';
|
||||
}
|
||||
$out = trim((string)@shell_exec('/sbin/ifconfig ' . escapeshellarg($iface) . ' inet 2>/dev/null'));
|
||||
return preg_match('/inet (\d+\.\d+\.\d+\.\d+)/', $out, $m) ? $m[1] : '';
|
||||
}
|
||||
|
||||
function vmm_vnc_host_for_vm(string $name): string
|
||||
{
|
||||
$switchName = '';
|
||||
@@ -1171,10 +1185,10 @@ function vmm_vnc_host_for_vm(string $name): string
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($iface !== '' && $iface !== 'n/a') {
|
||||
$out = trim((string)@shell_exec('/sbin/ifconfig ' . escapeshellarg($iface) . ' inet 2>/dev/null'));
|
||||
if (preg_match('/inet (\d+\.\d+\.\d+\.\d+)/', $out, $m)) {
|
||||
return $m[1];
|
||||
if ($iface !== '') {
|
||||
$ip = vmm_iface_ipv4($iface);
|
||||
if ($ip !== '') {
|
||||
return $ip;
|
||||
}
|
||||
}
|
||||
return trim((string)@shell_exec('hostname -f 2>/dev/null')) ?: (gethostname() ?: 'localhost');
|
||||
|
||||
Reference in new issue
Block a user