/**
  * Execute the job. Add an IP address to a DNS record when it is available
  * on the instance. If the instance does not exist, or it has not been
  * assigned an IP address, re-add the job.
  *
  * Upon successfully adding the host, this job will also add an Article for the
  * instance.
  *
  * @return bool
  */
 public function run()
 {
     global $wgOpenStackManagerNovaAdminKeys;
     global $wgAuth;
     $instanceid = $this->params['instanceid'];
     $wgAuth->printDebug("Running DNS job for {$instanceid}", NONSENSITIVE);
     $adminCredentials = $wgOpenStackManagerNovaAdminKeys;
     $adminNova = new OpenStackNovaController($adminCredentials);
     $instance = $adminNova->getInstance($instanceid);
     if (!$instance) {
         $wgAuth->printDebug("Instance doesn't exist for {$instanceid}", NONSENSITIVE);
         # Instance no longer exists
         return true;
     }
     $ip = $instance->getInstancePrivateIP();
     if (trim($ip) == '') {
         # IP hasn't been assigned yet
         # re-add to queue
         $wgAuth->printDebug("Readding job for {$instanceid}", NONSENSITIVE);
         $job = new OpenStackNovaHostJob($this->title, $this->params);
         $job->insert();
         return true;
     }
     $host = OpenStackNovaHost::getHostByInstanceId($instanceid);
     if (!$host) {
         $wgAuth->printDebug("Host record doesn't exist for {$instanceid}", NONSENSITIVE);
         return true;
     }
     $host->setARecord($ip);
     $instance->editArticle();
     return true;
 }
	/**
	 * @param  $apiInstanceResponse
	 * @param bool $loadhost, optional
	 */
	function __construct( $apiInstanceResponse, $loadhost = false ) {
		$this->instance = $apiInstanceResponse;
		if ( $loadhost ) {
			$this->host = OpenStackNovaHost::getHostByInstanceId( $this->getInstanceId() );
		} else {
			$this->host = null;
		}
	}
 /**
  * @return bool
  */
 function configureInstance()
 {
     global $wgOpenStackManagerPuppetOptions;
     $this->setHeaders();
     $this->getOutput()->setPagetitle(wfMsg('openstackmanager-configureinstance'));
     $project = $this->getRequest()->getText('project');
     if (!$this->userLDAP->inRole('sysadmin', $project)) {
         $this->notInRole('sysadmin');
         return false;
     }
     $instanceid = $this->getRequest()->getText('instanceid');
     $instanceInfo = array();
     $instanceInfo['instanceid'] = array('type' => 'hidden', 'default' => $instanceid, 'name' => 'instanceid');
     $instanceInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project');
     if ($wgOpenStackManagerPuppetOptions['enabled']) {
         $host = OpenStackNovaHost::getHostByInstanceId($instanceid);
         if (!$host) {
             $this->getOutput()->addWikiMsg('openstackmanager-nonexistenthost');
             return false;
         }
         $puppetinfo = $host->getPuppetConfiguration();
         $this->setPuppetInfo($instanceInfo, $puppetinfo);
     }
     $instanceInfo['action'] = array('type' => 'hidden', 'default' => 'configure', 'name' => 'action');
     $instanceForm = new SpecialNovaInstanceForm($instanceInfo, 'openstackmanager-novainstance');
     $instanceForm->setTitle(SpecialPage::getTitleFor('NovaInstance'));
     $instanceForm->setSubmitID('novainstance-form-configureinstancesubmit');
     $instanceForm->setSubmitCallback(array($this, 'tryConfigureSubmit'));
     $instanceForm->show();
     return true;
 }
	/**
	 * Deletes a host based on its instanceid.
	 *
	 * @static
	 * @param  $instanceid
	 * @return bool
	 */
	static function deleteHostByInstanceId( $instanceid ) {
		global $wgAuth;

		OpenStackNovaLdapConnection::connect();

		$host = OpenStackNovaHost::getHostByInstanceId( $instanceid );
		if ( ! $host ) {
			$wgAuth->printDebug( "Failed to delete host $instanceid as the DNS entry does not exist", NONSENSITIVE );
			return false;
		}
		$dn = $host->hostDN;
		$domain = $host->getDomain();

		$success = LdapAuthenticationPlugin::ldap_delete( $wgAuth->ldapconn, $dn );
		if ( $success ) {
			$domain->updateSOA();
			$wgAuth->printDebug( "Successfully deleted host $instanceid", NONSENSITIVE );
			return true;
		} else {
			$wgAuth->printDebug( "Failed to delete host $instanceid", NONSENSITIVE );
			return false;
		}
	}