function handleHostActions($args) { // If we arent given any more parameters if (!isset($args[2])) { // Just output some helpful information and exit echo "Error: Action missing.\n\n"; $this->printHostHelpText($args); return; } // Handle actions switch ($args[2]) { // Handle add case 'add': // Check for parameters first if (!isset($args[3]) || !isset($args[4])) { throw new InputException("Error: The Hostname and Description of the Host to add are required.\n\n Example:\n\n\txbm " . $args[1] . ' add "db01.mydomain.com" "Production DB #1"'); } $hostname = $args[3]; $hostDesc = $args[4]; $hostGetter = new hostGetter(); $hostGetter->setLogStream($this->log); // Get the new Volume $host = $hostGetter->getNew($hostname, $hostDesc); echo "Action: New host created with hostname/description: " . $hostname . " -- " . $hostDesc . "\n\n"; break; // Handle list // Handle list case 'list': $hostGetter = new hostGetter(); $hostGetter->setLogStream($this->log); $hosts = $hostGetter->getAll(); echo "-- Listing all Hosts --\n\n"; foreach ($hosts as $host) { $hostInfo = $host->getInfo(); echo "Hostname: " . $hostInfo['hostname'] . " Description: " . $hostInfo['description'] . "\n"; echo "Active: " . $hostInfo['active'] . " Staging_path: " . $hostInfo['staging_path'] . " SSH Port: " . $hostInfo['ssh_port'] . "\n\n"; } if (sizeOf($hosts) == 0) { echo "\tNo hosts configured.\n\n"; } echo "\n"; break; // Handle edit // Handle edit case 'edit': if (!isset($args[3]) || !isset($args[4]) || !isset($args[5])) { $errMsg = "Error: Hostname of the host to edit must be given along with parameter and value.\n\n"; $errMsg .= " Parameters:\n\n"; $errMsg .= "\thostname - The hostname of the Host - May only be edited if no Scheduled Backups are configured for the host.\n"; $errMsg .= "\tdescription - The description of the Host - Can be edited at any time.\n"; $errMsg .= "\tstaging_path - The temporary dir to use on the host for staging incremental backups - Can be edited at any time.\n"; $errMsg .= "\tssh_port - The SSH port number to use to connect to the remote host - Can be edited at any time.\n"; $errMsg .= "\tactive - Whether or the Host is active Y or N - Can be edited at any time.\n\n"; $errMsg .= " Example:\n\n\txbm " . $args[1] . ' edit db01.mydomain.com staging_path /storage1/backuptmp'; throw new InputException($errMsg); } $hostname = $args[3]; $hostParam = $args[4]; $hostValue = $args[5]; $hostGetter = new hostGetter(); $hostGetter->setLogStream($this->log); if (!($host = $hostGetter->getByName($hostname))) { throw new ProcessingException("Error: No Host exists with name: " . $hostname); } $host->setParam($hostParam, $hostValue); echo "Action: Host with hostname: " . $hostname . " parameter '" . $hostParam . "' set to: " . $hostValue . "\n\n"; break; // Handle delete // Handle delete case 'delete': if (!isset($args[3])) { throw new InputException("Error: Hostname of Host to delete must be given."); } $hostname = $args[3]; $hostGetter = new hostGetter(); $hostGetter->setLogStream($this->log); if (!($host = $hostGetter->getByName($hostname))) { throw new ProcessingException("Error: No Host exists with hostname: " . $hostname); } $host->delete(); echo "Action: Host with hostname: " . $hostname . " deleted.\n\n"; break; // Handle unknown action // Handle unknown action default: echo "Error: Unrecognized action for " . $args[1] . " context: " . $args[2] . "\n\n"; $this->printHostHelpText($args); break; } return; }