|
@@ 1850-1867 (lines=18) @@
|
| 1847 |
|
* @return Iterator |
| 1848 |
|
* a hostid that matches the role |
| 1849 |
|
*/ |
| 1850 |
|
function firstHostWithRole($roleName) |
| 1851 |
|
{ |
| 1852 |
|
$listOfHosts = fromRolesTable()->getDetailsForRole($roleName); |
| 1853 |
|
if (!count(get_object_vars($listOfHosts))) { |
| 1854 |
|
throw new E5xx_ActionFailed(__METHOD__, "unknown role '{$roleName}' or no hosts for that role"); |
| 1855 |
|
} |
| 1856 |
|
|
| 1857 |
|
// what are we doing? |
| 1858 |
|
$log = usingLog()->startAction("for the first host with role '{$roleName}' ... "); |
| 1859 |
|
|
| 1860 |
|
// we yield a single host ID ... |
| 1861 |
|
$hostsAsArray = get_object_vars($listOfHosts); |
| 1862 |
|
$hostDetails = array_pop($hostsAsArray); |
| 1863 |
|
yield($hostDetails->hostId); |
| 1864 |
|
|
| 1865 |
|
// all done |
| 1866 |
|
$log->endAction(); |
| 1867 |
|
} |
| 1868 |
|
|
| 1869 |
|
/** |
| 1870 |
|
* iterate over all hosts that match the given role, and return only the last one |
|
@@ 1878-1895 (lines=18) @@
|
| 1875 |
|
* @return Iterator |
| 1876 |
|
* a hostid that matches the role |
| 1877 |
|
*/ |
| 1878 |
|
function lastHostWithRole($roleName) |
| 1879 |
|
{ |
| 1880 |
|
$listOfHosts = fromRolesTable()->getDetailsForRole($roleName); |
| 1881 |
|
if (!count(get_object_vars($listOfHosts))) { |
| 1882 |
|
throw new E5xx_ActionFailed(__METHOD__, "unknown role '{$roleName}' or no hosts for that role"); |
| 1883 |
|
} |
| 1884 |
|
|
| 1885 |
|
// what are we doing? |
| 1886 |
|
$log = usingLog()->startAction("for the last host with role '{$roleName}' ... "); |
| 1887 |
|
|
| 1888 |
|
// we yield a single host ID ... |
| 1889 |
|
$hostsAsArray = get_object_vars($listOfHosts); |
| 1890 |
|
$hostDetails = end($hostsAsArray); |
| 1891 |
|
yield($hostDetails->hostId); |
| 1892 |
|
|
| 1893 |
|
// all done |
| 1894 |
|
$log->endAction(); |
| 1895 |
|
} |
| 1896 |
|
|
| 1897 |
|
/** |
| 1898 |
|
* iterate over all hosts that match the given role |