/**
  * 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;
 }
Esempio n. 2
0
 /**
  * @param  $formData
  * @param string $entryPoint
  * @return bool
  */
 function tryCreateSubmit($formData, $entryPoint = 'internal')
 {
     $domain = OpenStackNovaDomain::getDomainByName($formData['domain']);
     if (!$domain) {
         $this->getOutput()->addWikiMsg('openstackmanager-invaliddomain');
         return true;
     }
     $instance = $this->userNova->createInstance($formData['instancename'], $formData['imageType'], '', $formData['instanceType'], $formData['availabilityZone'], $formData['groups']);
     if ($instance) {
         $host = OpenStackNovaHost::addHost($instance, $domain, $this->getPuppetInfo($formData));
         if ($host) {
             $title = Title::newFromText($this->getOutput()->getPageTitle());
             $job = new OpenStackNovaHostJob($title, array('instanceid' => $instance->getInstanceId()));
             $job->insert();
             $this->getOutput()->addWikiMsg('openstackmanager-createdinstance', $instance->getInstanceID(), $instance->getImageId(), $host->getFullyQualifiedHostName());
         } else {
             $this->userNova->terminateInstance($instance->getInstanceId());
             $this->getOutput()->addWikiMsg('openstackmanager-createfailedldap');
         }
         # TODO: also add puppet
     } else {
         $this->getOutput()->addWikiMsg('openstackmanager-createinstancefailed');
     }
     $out = '<br />';
     $out .= Linker::link($this->getTitle(), wfMsgHtml('openstackmanager-backinstancelist'));
     $this->getOutput()->addHTML($out);
     return true;
 }