restype = 'managementnode';
$this->restypename = 'Management Node';
$this->namefield = 'hostname';
$this->hasmapping = 1;
$this->maptype = 'computer';
$this->maptypename = 'Computer';
$this->defaultGetDataArgs = array('alive' => 'neither',
'includedeleted' => 0,
'rscid' => 0);
$this->basecdata['obj'] = $this;
$this->deletetoggled = 1;
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn getData($args)
///
/// \param $args - array of arguments that determine what data gets returned;
/// must include:\n
/// \b alive - 'now', 'future', or 'neither'
/// \b includedeleted - 0 or 1; include deleted images\n
/// \b rscid - only return data for resource with this id; pass 0 for all
/// (from managementnode table)
///
/// \return array of data as returned from getManagementNodes
///
/// \brief wrapper for calling getManagementNodes
///
/////////////////////////////////////////////////////////////////////////////
function getData($args) {
return getManagementNodes($args['alive'], $args['includedeleted'], $args['rscid']);
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn fieldWidth($field)
///
/// \param $field - name of a resource field
///
/// \return string for setting width of field (includes width= part)
///
/// \brief generates the required width for the field; can return an empty
/// string if field should default to auto width
///
/////////////////////////////////////////////////////////////////////////////
function fieldWidth($field) {
switch($field) {
case 'IPaddress':
case 'publicIPconfig':
case 'publicnetmask':
case 'publicgateway':
case 'natpublicIPaddress':
case 'natinternalIPaddress':
$w = 8;
break;
case 'installpath':
case 'publicdnsserver':
$w = 11;
break;
case 'imagelibgroup':
case 'imagelibkey':
case 'federatedauth':
$w = 9.5;
break;
case 'keys':
case 'owner':
case 'sharedmailbox':
$w = 12;
break;
case 'keys':
case 'sysadminemail':
case 'timeservers':
$w = 18;
break;
default:
return '';
}
if(preg_match('/MSIE/i', $_SERVER['HTTP_USER_AGENT']) ||
preg_match('/Trident/i', $_SERVER['HTTP_USER_AGENT']))
$w = round($w * 11.5) . 'px';
else
$w = "{$w}em";
return "width=\"$w\"";
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn fieldDisplayName($field)
///
/// \param $field - name of a resource field
///
/// \return display value for $field
///
/// \brief generates the display value for $field
///
/////////////////////////////////////////////////////////////////////////////
function fieldDisplayName($field) {
switch($field) {
case 'IPaddress':
return 'IP Address';
case 'lastcheckin':
return 'Last Check-in';
case 'checkininterval':
return 'Check-in interval';
case 'installpath':
return 'Install Path';
case 'imagelibenable':
return 'Enable Image Library';
case 'imagelibgroup':
return 'Image Library Group';
case 'imagelibuser':
return 'Image Library User';
case 'imagelibkey':
return 'Image Library Key';
case 'sshport':
return 'Image Library SSH Port';
case 'publicIPconfig':
return 'Public NIC Config.';
case 'publicnetmask':
return 'Public Netmask';
case 'publicgateway':
return 'Public Gateway';
case 'publicdnsserver':
return 'Public DNS Server';
case 'sysadminemail':
return 'Sysadmin Email Address';
case 'sharedmailbox':
return 'Shadow Email Address';
case 'federatedauth':
return 'Federated Auth. Affiliations';
case 'timeservers':
return 'Time Servers';
case 'nathostenabled':
return 'Use as NAT Host';
case 'natpublicIPaddress':
return 'NAT Public IP Address';
case 'natinternalIPaddress':
return 'NAT Internal IP Address';
}
return ucfirst($field);
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn checkResourceInUse($rscid)
///
/// \return empty string if not being used; string of where resource is
/// being used if being used
///
/// \brief checks to see if a management node is being used
///
/////////////////////////////////////////////////////////////////////////////
function checkResourceInUse($rscid) {
$msgs = array();
# check reservations
$query = "SELECT rq.end "
. "FROM request rq, "
. "reservation rs "
. "WHERE rs.requestid = rq.id AND "
. "rs.managementnodeid = $rscid AND "
. "rq.stateid NOT IN (1, 12) AND "
. "rq.end > NOW() "
. "ORDER BY rq.end DESC "
. "LIMIT 1";
$qh = doQuery($query);
if($row = mysql_fetch_assoc($qh))
$msgs[] = "There is at least one reservation being processed by this management node. The latest end time is " . prettyDatetime($row['end'], 1) . '.';
# check blockRequest
$query = "SELECT br.name, "
. "bt.end "
. "FROM blockRequest br, "
. "blockTimes bt "
. "WHERE br.managementnodeid = $rscid AND "
. "bt.blockRequestid = br.id AND "
. "bt.end > NOW() AND "
. "bt.skip = 0 AND "
. "br.status = 'accepted' "
. "ORDER BY bt.end DESC "
. "LIMIT 1";
$qh = doQuery($query);
if($row = mysql_fetch_assoc($qh))
$msgs[] = "There is at least one Block Allocation being handled by this management node. Block Allocation \"{$row['name']}\" has the latest end time which is " . prettyDatetime($row['end'], 1) . '.';
if(empty($msgs))
return '';
$msg = "The selected management node is currently being used in the following ways and cannot be deleted at this time.
\n";
$msg .= implode("
\n", $msgs) . "
\n";
return $msg;
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn toggleDeleteResource($rscid)
///
/// \param $rscid - id of a resource (from managementnode table)
///
/// \return 1 on success, 0 on failure
///
/// \brief uses state of management node to flag as deleted or not; if
/// undeleting, sets state to maintenance
///
/////////////////////////////////////////////////////////////////////////////
function toggleDeleteResource($rscid) {
$query = "SELECT stateid FROM managementnode WHERE id = $rscid";
$qh = doQuery($query);
if($row = mysql_fetch_assoc($qh)) {
if($row['stateid'] == 1)
$query = "UPDATE managementnode SET stateid = 10 WHERE id = $rscid";
else
$query = "UPDATE managementnode SET stateid = 1 WHERE id = $rscid";
doQuery($query);
}
else
return 0;
# clear user resource cache for this type
$key = getKey(array(array($this->restype . "Admin", 'mgmtnodeAdmin'), array("administer"), 0, 1, 0, 0));
unset($_SESSION['userresources'][$key]);
$key = getKey(array(array($this->restype . "Admin", 'mgmtnodeAdmin'), array("administer"), 0, 0, 0, 0));
unset($_SESSION['userresources'][$key]);
return 1;
}
/////////////////////////////////////////////////////////////////////////////
///
/// \fn addEditDialogHTML($add)
///
/// \param $add - unused for this class
///
/// \brief generates HTML for dialog used to edit resource
///
/////////////////////////////////////////////////////////////////////////////
function addEditDialogHTML($add=0) {
global $user;
# dialog for on page editing
$h = '';
$h .= "