api: Added parent_id to VMs that have a host #3523 (#5621)

This commit is contained in:
Neil Lathwood
2017-01-26 22:38:43 +00:00
committed by GitHub
parent 8b453889fc
commit 483c40eddd
3 changed files with 21 additions and 2 deletions

View File

@@ -178,6 +178,10 @@ function get_device()
echo _json_encode($output);
$app->stop();
} else {
$host_id = get_vm_parent_id($device);
if (is_numeric($host_id)) {
$device = array_merge($device, array('parent_id' => $host_id));
}
$output = array(
'status' => 'ok',
'devices' => array($device),
@@ -186,7 +190,6 @@ function get_device()
}
}
function list_devices()
{
// This will return a list of devices
@@ -232,7 +235,11 @@ function list_devices()
}
$devices = array();
foreach (dbFetchRows("SELECT * FROM `devices` $join WHERE $sql ORDER by $order", $param) as $device) {
$host_id = get_vm_parent_id($device);
$device['ip'] = inet6_ntop($device['ip']);
if (is_numeric($host_id)) {
$device['parent_id'] = $host_id;
}
$devices[] = $device;
}

View File

@@ -17,7 +17,7 @@ if ($device['disabled'] == '1') {
$class = 'alert-info';
}
$host_id = dbFetchCell("SELECT `device_id` FROM `vminfo` WHERE `vmwVmDisplayName` = ? OR `vmwVmDisplayName` = ?", array($device['hostname'],$device['hostname'].'.'.$config['mydomain']));
$host_id = get_vm_parent_id($device);
echo '
<tr bgcolor="'.$device_colour.'" class="alert '.$class.'">

View File

@@ -1615,6 +1615,7 @@ function set_numeric($value, $default = 0)
}
return $value;
}
function check_git_exists()
{
if (`which git`) {
@@ -1623,3 +1624,14 @@ function check_git_exists()
return false;
}
}
function get_vm_parent_id($device)
{
global $config;
if (empty($device['hostname'])) {
return false;
}
return dbFetchCell("SELECT `device_id` FROM `vminfo` WHERE `vmwVmDisplayName` = ? OR `vmwVmDisplayName` = ?", array($device['hostname'],$device['hostname'].'.'.$config['mydomain']));
}