/**
  * 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;
 }
 function execute()
 {
     $result = $this->getResult();
     $this->params = $this->extractRequestParams();
     $this->userLDAP = new OpenStackNovaUser();
     $this->canExecute();
     $this->userNova = OpenStackNovaController::newFromUser($this->userLDAP);
     $this->userNova->setProject($this->params['project']);
     $this->userNova->setRegion($this->params['region']);
     $address = $this->userNova->getAddress($this->params['id']);
     if (!$address) {
         $this->dieUsage('Address specified does not exist.', 'openstackmanager-nonexistenthost');
     }
     $ipAddr = $address->getPublicIp();
     $instanceId = $address->getInstanceId();
     $subaction = $this->params['subaction'];
     switch ($subaction) {
         case 'disassociate':
             $success = $this->userNova->disassociateAddress($instanceId, $ipAddr);
             if (!$success) {
                 $this->dieUsage('Failed to disassociate address', 'openstackmanager-disassociateaddressfailed');
             }
             $result->addValue(null, $this->getModuleName(), array('addressstate' => 'free'));
             break;
     }
 }
 function execute($par)
 {
     if (!$this->getUser()->isLoggedIn()) {
         $this->notLoggedIn();
         return;
     }
     $this->userLDAP = new OpenStackNovaUser();
     if (!$this->userLDAP->exists()) {
         $this->noCredentials();
         return;
     }
     $this->checkTwoFactor();
     $project = $this->getRequest()->getText('project');
     $region = $this->getRequest()->getText('region');
     $this->userNova = OpenStackNovaController::newFromUser($this->userLDAP);
     $this->userNova->setProject($project);
     $this->userNova->setRegion($region);
     $action = $this->getRequest()->getVal('action');
     if ($action === "allocate") {
         $this->allocateAddress();
     } elseif ($action === "release") {
         $this->releaseAddress();
     } elseif ($action === "associate") {
         $this->associateAddress();
     } elseif ($action === "disassociate") {
         $this->disassociateAddress();
     } elseif ($action === "addhost") {
         $this->addHost();
     } elseif ($action === "removehost") {
         $this->removeHost();
     } else {
         $this->listAddresses();
     }
 }
 public function execute()
 {
     global $wgAuth;
     global $wgOpenStackManagerLDAPUsername;
     global $wgOpenStackManagerLDAPUserPassword;
     $user = new OpenStackNovaUser($wgOpenStackManagerLDAPUsername);
     $userNova = OpenStackNovaController::newFromUser($user);
     $projects = OpenStackNovaProject::getAllProjects();
     # HACK (please fix): Keystone doesn't deliver services and endpoints unless
     # a project token is returned, so we need to feed it a project. Ideally this
     # should be configurable, and not hardcoded like this.
     $userNova->setProject('bastion');
     $userNova->authenticate($wgOpenStackManagerLDAPUsername, $wgOpenStackManagerLDAPUserPassword);
     $regions = $userNova->getRegions('compute');
     foreach ($regions as $region) {
         $this->output("Running region : " . $region . "\n");
         foreach ($projects as $project) {
             $projectName = $project->getProjectName();
             $this->output("Running project : " . $projectName . "\n");
             $userNova->setProject($projectName);
             $userNova->setRegion($region);
             $instances = $userNova->getInstances();
             if (!$instances) {
                 $wgAuth->printDebug("No instance, continuing", NONSENSITIVE);
                 continue;
             }
             foreach ($instances as $instance) {
                 $this->output("Updating instance : " . $instance->getInstanceId() . "\n");
                 $instance->editArticle($userNova);
             }
         }
     }
     $this->output("Done.\n");
 }
 public function execute()
 {
     global $wgAuth;
     global $wgOpenStackManagerLDAPUsername;
     global $wgOpenStackManagerLDAPUserPassword;
     if ($this->hasOption('all-instances')) {
         if ($this->hasOption('region')) {
             $this->error("--all-instances cannot be used with --region.\n", true);
         }
         $instancelist = array();
         $user = new OpenStackNovaUser($wgOpenStackManagerLDAPUsername);
         $userNova = OpenStackNovaController::newFromUser($user);
         $projects = OpenStackNovaProject::getAllProjects();
         $userNova->setProject('bastion');
         $userNova->authenticate($wgOpenStackManagerLDAPUsername, $wgOpenStackManagerLDAPUserPassword);
         $regions = $userNova->getRegions('compute');
         foreach ($regions as $region) {
             foreach ($projects as $project) {
                 $projectName = $project->getProjectName();
                 $userNova->setProject($projectName);
                 $userNova->setRegion($region);
                 $instances = $userNova->getInstances();
                 if ($instances) {
                     foreach ($instances as $instance) {
                         $instancelist[] = array($region, $instance->getInstanceName(), $projectName);
                     }
                 }
             }
         }
     } elseif ($this->hasOption('name')) {
         if (!$this->hasOption('region')) {
             $this->error("--name requires --region.\n", true);
         }
         if (!$this->hasOption('project')) {
             $this->error("--name requires --project.\n", true);
         }
         $instancelist = array(array($this->getOption('region'), $this->getOption('name'), $this->getOption('project')));
     } else {
         $this->error("Must specify either --name or --all-instances.\n", true);
     }
     if (!class_exists('OpenStackNovaHost')) {
         $this->error("Couldn't find OpenStackNovaHost class.\n", true);
     }
     OpenStackNovaLdapConnection::connect();
     foreach ($instancelist as $instancepair) {
         list($instanceregion, $instancename, $instanceproject) = $instancepair;
         $host = OpenStackNovaHost::getHostByNameAndProject($instancename, $instanceproject, $instanceregion);
         if (!$host) {
             print "Skipping {$instancename}.{$instanceproject}.{$instanceregion}; not found.\n";
             continue;
         }
         print "\nFor instance {$instancename} in region {$instanceregion} and project {$instanceproject}:\n\n";
         $namefqdn = $instancename . '.' . $instanceproject . '.' . $instanceregion . '.' . 'wmflabs';
         $host->addAssociatedDomain($namefqdn);
     }
 }
 /**
  * @return array
  */
 function getGroup()
 {
     $properties = array();
     $properties['groupname'] = OpenStackNovaController::_get_property($this->rule->group, 'name');
     $properties['project'] = OpenStackNovaController::_get_property($this->rule->group, 'tenant_id');
     if ($properties['groupname'] && $properties['project']) {
         return $properties;
     } else {
         return array();
     }
 }
 /**
  * @param  $formData
  * @param string $entryPoint
  * @return bool
  */
 function tryRemoveRuleSubmit($formData, $entryPoint = 'internal')
 {
     $ruleid = $formData['ruleid'];
     $success = $this->userNova->removeSecurityGroupRule($ruleid);
     if ($success) {
         # TODO: Ensure group isn't being used
         $this->getOutput()->addWikiMsg('openstackmanager-removedrule');
     } else {
         $this->getOutput()->addWikiMsg('openstackmanager-removerulefailed');
     }
     $out = '<br />';
     $out .= Linker::link($this->getPageTitle(), $this->msg('openstackmanager-backsecuritygrouplist')->escaped());
     $this->getOutput()->addHTML($out);
     return true;
 }
 function getInstances($projectName, $region, &$instanceCount)
 {
     global $wgMemc;
     $this->userNova->setRegion($region);
     $headers = array('openstackmanager-instancename', 'openstackmanager-instanceid', 'openstackmanager-instancestate', 'openstackmanager-instanceip', 'openstackmanager-projectname', 'openstackmanager-launchtime', 'openstackmanager-instancecreator');
     $instances = $this->userNova->getInstances();
     $instanceRows = array();
     $instanceCount = 0;
     /**
      * @var $instance OpenStackNovaInstance
      */
     foreach ($instances as $instance) {
         # Only display instances created by the current user.
         if ($instance->getInstanceCreator() != $this->userLDAP->getUid()) {
             continue;
         }
         $instanceRow = array();
         $this->pushResourceColumn($instanceRow, $instance->getInstanceName(), array('class' => 'novainstancename'));
         $host = $instance->getHost();
         if ($host) {
             $this->pushRawResourceColumn($instanceRow, $this->createResourceLink($host->getFullyQualifiedHostName()), array('class' => 'novainstanceid'));
         } else {
             $this->pushResourceColumn($instanceRow, $instance->getInstanceId(), array('class' => 'novainstanceid'));
         }
         $state = $instance->getInstanceState();
         $taskState = $instance->getInstanceTaskState();
         if ($taskState) {
             $stateDisplay = "{$state} ({$taskState})";
         } else {
             $stateDisplay = $state;
         }
         $this->pushResourceColumn($instanceRow, $stateDisplay, array('class' => 'novainstancestate'));
         $this->pushRawResourceColumn($instanceRow, $this->createResourceList($instance->getInstancePrivateIPs()));
         $this->pushResourceColumn($instanceRow, $projectName);
         $this->pushResourceColumn($instanceRow, $instance->getLaunchTime());
         $this->pushResourceColumn($instanceRow, $instance->getInstanceCreator());
         $actions = array();
         $instanceDataAttributes = array('data-osid' => $instance->getInstanceOSId(), 'data-id' => $instance->getInstanceId(), 'data-name' => $instance->getInstanceName(), 'data-project' => $projectName, 'data-region' => $region, 'class' => 'novainstanceaction');
         $instanceRows[] = $instanceRow;
         $instanceCount += 1;
     }
     if ($instanceRows) {
         return $this->createResourceTable($headers, $instanceRows);
     }
     return '';
 }
 /**
  * @param  $formData
  * @param string $entryPoint
  * @return bool
  */
 function tryDetachSubmit($formData, $entryPoint = 'internal')
 {
     if (isset($formData['force']) && $formData['force']) {
         $force = true;
     } else {
         $force = false;
     }
     $success = $this->userNova->detachVolume($formData['volumeid'], $force);
     if ($success) {
         $this->getOutput()->addWikiMsg('openstackmanager-detachedvolume');
     } else {
         $this->getOutput()->addWikiMsg('openstackmanager-detachvolumefailed');
     }
     $out = '<br />';
     $out .= Linker::link($this->getPageTitle(), $this->msg('openstackmanager-backvolumelist')->escaped());
     $this->getOutput()->addHTML($out);
     return true;
 }
 /**
  * @param  $formData
  * @param string $entryPoint
  * @return bool
  */
 function tryConfigureSubmit($formData, $entryPoint = 'internal')
 {
     $instance = $this->userNova->getInstance($formData['instanceid']);
     $host = $instance->getHost();
     if ($host) {
         $success = $host->modifyPuppetConfiguration($this->getPuppetInfo($formData));
         if ($success) {
             $instance->editArticle($this->userNova);
             $this->getOutput()->addWikiMsg('openstackmanager-modifiedinstance', $instance->getInstanceId(), $instance->getInstanceName());
         } else {
             $this->getOutput()->addWikiMsg('openstackmanager-modifyinstancefailed');
         }
     } else {
         $this->getOutput()->addWikiMsg('openstackmanager-nonexistanthost');
     }
     $out = '<br />';
     $out .= Linker::link($this->getPageTitle(), $this->msg('openstackmanager-backinstancelist')->escaped());
     $this->getOutput()->addHTML($out);
     return true;
 }
 function execute($par)
 {
     if (!$this->getUser()->isLoggedIn()) {
         $this->notLoggedIn();
         return;
     }
     $this->userLDAP = new OpenStackNovaUser();
     if (!$this->userLDAP->exists()) {
         $this->noCredentials();
         return;
     }
     $this->checkTwoFactor();
     $action = $this->getRequest()->getVal('action');
     $this->projectName = $this->getRequest()->getText('project');
     $this->project = OpenStackNovaProject::getProjectByName($this->projectName);
     $region = $this->getRequest()->getVal('region');
     $this->userNova = OpenStackNovaController::newFromUser($this->userLDAP);
     $this->userNova->setProject($this->projectName);
     $this->userNova->setRegion($region);
     if ($action === "create") {
         if (!$this->userLDAP->inProject($this->projectName)) {
             $this->notInProject($this->projectName);
             return;
         }
         $this->createProxy();
     } elseif ($action === "delete") {
         if (!$this->userLDAP->inProject($this->projectName)) {
             $this->notInProject($this->project);
             return;
         }
         $this->deleteProxy();
     } elseif ($action === "modify") {
         if (!$this->userLDAP->inProject($this->projectName)) {
             $this->notInProject($this->project);
             return;
         }
         $this->modifyProxy();
     } else {
         $this->listProxies();
     }
 }
 public function execute()
 {
     global $wgAuth;
     global $wgOpenStackManagerLDAPUsername;
     global $wgOpenStackManagerLDAPUserPassword;
     $user = new OpenStackNovaUser($wgOpenStackManagerLDAPUsername);
     $userNova = OpenStackNovaController::newFromUser($user);
     $projects = OpenStackNovaProject::getAllProjects();
     # HACK (please fix): Keystone doesn't deliver services and endpoints unless
     # a project token is returned, so we need to feed it a project. Ideally this
     # should be configurable, and not hardcoded like this.
     $userNova->setProject('bastion');
     $userNova->authenticate($wgOpenStackManagerLDAPUsername, $wgOpenStackManagerLDAPUserPassword);
     $regions = $userNova->getRegions('compute');
     foreach ($regions as $region) {
         $this->output("Running region: " . $region . "\n");
         foreach ($projects as $project) {
             $projectName = $project->getProjectName();
             $this->output("Running project: " . $projectName . "\n");
             $userNova->setProject($projectName);
             $userNova->setRegion($region);
             $instances = $userNova->getInstances();
             if (!$instances) {
                 $wgAuth->printDebug("No instance, continuing", NONSENSITIVE);
                 continue;
             }
             foreach ($instances as $instance) {
                 $host = $instance->getHost();
                 if (!$host) {
                     $this->output("Skipping instance due to missing host entry: " . $instance->getInstanceId() . "\n");
                     continue;
                 }
                 $this->output("Renaming instance: " . $instance->getInstanceId() . "\n");
                 $ot = Title::newFromText($instance->getInstanceId(), NS_NOVA_RESOURCE);
                 $nt = Title::newFromText($host->getFullyQualifiedHostName(), NS_NOVA_RESOURCE);
                 $ot->moveTo($nt, false, 'Maintenance script move from id to fqdn.');
             }
         }
     }
     $this->output("Done.\n");
 }
 public function run()
 {
     global $wgOpenStackManagerLDAPUsername;
     global $wgOpenStackManagerLDAPUserPassword;
     global $wgMemc;
     $params = $this->extractRequestParams();
     $project = OpenStackNovaProject::getProjectByName($params['project']);
     if (!$project) {
         // This shouldn't be possible since the API should enforce valid names
         $this->dieUsage('Invalid project specified.', 'badproject');
     }
     $key = wfMemcKey('openstackmanager', 'apilistnovainstances', $params['region'], $params['project']);
     $instancesInfo = $wgMemc->get($key);
     if ($instancesInfo === false) {
         $user = new OpenStackNovaUser($wgOpenStackManagerLDAPUsername);
         $userNova = OpenStackNovaController::newFromUser($user);
         $userNova->authenticate($wgOpenStackManagerLDAPUsername, $wgOpenStackManagerLDAPUserPassword);
         $userNova->setProject($project->getName());
         $userNova->setRegion($params['region']);
         // validated by API
         $instances = $userNova->getInstances();
         $instancesInfo = array();
         foreach ($instances as $instance) {
             $instancesInfo[] = array('name' => $instance->getInstanceName(), 'state' => $instance->getInstanceState(), 'ip' => $instance->getInstancePrivateIPs(), 'id' => $instance->getInstanceId(), 'floatingip' => $instance->getInstancePublicIPs(), 'securitygroups' => $instance->getSecurityGroups(), 'imageid' => $instance->getImageId());
         }
     }
     // Cache info for 1 minute, not caching for longer since we do not invalidate
     $wgMemc->set($key, $instancesInfo, 1 * 60);
     foreach ($instancesInfo as $info) {
         // UGH I hate XML
         $this->getResult()->setIndexedTagName($info['securitygroups'], 'group');
         $this->getResult()->setIndexedTagName($info['ip'], 'ip');
         $this->getResult()->setIndexedTagName($info['floatingip'], 'floatingip');
         $this->getResult()->addValue(array('query', $this->getModuleName()), null, $info);
     }
     if (defined('ApiResult::META_CONTENT')) {
         $this->getResult()->addIndexedTagName(array('query', $this->getModuleName()), 'instance');
     } else {
         $this->getResult()->setIndexedTagName_internal(array('query', $this->getModuleName()), 'instance');
     }
 }
 function execute()
 {
     global $wgUser;
     $this->params = $this->extractRequestParams();
     $this->userLDAP = new OpenStackNovaUser();
     $this->canExecute();
     $this->userNova = OpenStackNovaController::newFromUser($this->userLDAP);
     $this->userNova->setProject($this->params['project']);
     $this->userNova->setRegion($this->params['region']);
     switch ($this->params['subaction']) {
         case 'reboot':
             $success = $this->userNova->rebootInstance($this->params['instanceid']);
             if (!$success) {
                 $this->dieUsage('Failed to reboot instance.', 'openstackmanager-rebootinstancefailed');
             }
             $instance = $this->userNova->getInstance($this->params['instanceid']);
             if ($instance) {
                 $this->getResult()->addValue(null, $this->getModuleName(), array('instancestate' => $instance->getInstanceState()));
             }
             break;
         case 'consoleoutput':
             $output = $this->userNova->getConsoleOutput($this->params['instanceid']);
             $this->getResult()->addValue(null, $this->getModuleName(), array('consoleoutput' => $output));
             break;
         case 'delete':
             $instanceOSID = $this->params['instanceid'];
             $instance = $this->userNova->getInstance($instanceOSID);
             if (!$instance) {
                 $this->dieUsage('The instance requested does not exist.', 'openstackmanager-nonexistanthost');
             }
             $result = $instance->deleteInstance($this->userNova);
             if (!$result) {
                 $this->dieUsage('Failed to delete the instance.', 'openstackmanager-deleteinstancefailed');
             }
             break;
     }
 }
 /**
  * Return the number of security groups used
  *
  * @return string
  */
 function getSecurityGroupsUsed()
 {
     return OpenStackNovaController::_get_property($this->absolute, 'totalSecurityGroupsUsed');
 }
 /**
  * @param  $formData
  * @param string $entryPoint
  * @return bool
  */
 function tryCreateSubmit($formData, $entryPoint = 'internal')
 {
     global $wgOpenStackManagerDefaultSecurityGroupRules;
     $success = OpenStackNovaProject::createProject($formData['projectname']);
     if (!$success) {
         $this->getOutput()->addWikiMsg('openstackmanager-createprojectfailed');
         return false;
     }
     $project = OpenStackNovaProject::getProjectByName($formData['projectname']);
     $username = $this->userLDAP->getUsername();
     $project->addMember($username);
     $members = explode(',', $formData['member']);
     foreach ($members as $member) {
         $project->addMember($member);
     }
     $roles = $project->getRoles();
     foreach ($roles as $role) {
         if (in_array($role->getRoleName(), $formData['roles'])) {
             foreach ($members as $member) {
                 $role->addMember($member);
             }
         }
         // We also need to ensure the project creator is in all roles
         $role->addMember($username);
     }
     # Change the connection to reference this project
     $this->userNova->setProject($formData['projectname']);
     $regions = $this->userNova->getRegions('compute');
     foreach ($regions as $region) {
         $this->userNova->setRegion($region);
         $securityGroups = $this->userNova->getSecurityGroups();
         $groupid = '';
         foreach ($securityGroups as $securityGroup) {
             if ($securityGroup->getGroupName() === 'default') {
                 $groupid = $securityGroup->getGroupId();
             }
         }
         if (!$groupid) {
             continue;
         }
         foreach ($wgOpenStackManagerDefaultSecurityGroupRules as $rule) {
             $fromport = '';
             $toport = '';
             $protocol = '';
             $range = '';
             $sourcegroupid = '';
             if (array_key_exists('fromport', $rule)) {
                 $fromport = $rule['fromport'];
             }
             if (array_key_exists('toport', $rule)) {
                 $toport = $rule['toport'];
             }
             if (array_key_exists('protocol', $rule)) {
                 $protocol = $rule['protocol'];
             }
             if (array_key_exists('range', $rule)) {
                 $range = $rule['range'];
             }
             if (array_key_exists('group', $rule)) {
                 foreach ($securityGroups as $securityGroup) {
                     if ($rule['group'] === $securityGroup->getGroupName()) {
                         $sourcegroupid = $securityGroup->getGroupId();
                     }
                 }
             }
             $this->userNova->addSecurityGroupRule($groupid, $fromport, $toport, $protocol, $range, $sourcegroupid);
         }
     }
     $project->setVolumeSettings(array('home', 'project'));
     $project->editArticle();
     $this->getOutput()->addWikiMsg('openstackmanager-createdproject');
     $out = '<br />';
     $out .= Linker::link($this->getPageTitle(), $this->msg('openstackmanager-addadditionalproject')->escaped());
     $this->getOutput()->addHTML($out);
     return true;
 }
 /**
  * Return the value of the metadata key requested
  *
  * @return string
  */
 function getImageMetadata($key)
 {
     return OpenStackNovaController::_get_property($this->image->metadata, $key);
 }
 function getAddressId()
 {
     return OpenStackNovaController::_get_property($this->address, 'id');
 }
 /**
  * Return the volume's availability zone
  *
  * @return string
  */
 function getVolumeAvailabilityZone()
 {
     return OpenStackNovaController::_get_property($this->volume, 'availability_zone');
 }
    /**
     * Adds or edits an article for this instance
     *
     * @return void
     */
    function editArticle()
    {
        global $wgOpenStackManagerNovaAdminKeys;
        if (!OpenStackNovaArticle::canCreatePages()) {
            return;
        }
        $format = <<<RESOURCEINFO
{{Nova Resource
|Resource Type=instance
|Instance Name=%s
|Reservation Id=%s
|Instance Id=%s
|Private IP=%s
|Public IP=%s
|Instance State=%s
|Instance Host=%s
|Instance Type=%s
|RAM Size=%s
|Number of CPUs=%s
|Amount of Storage=%s
|Image Id=%s
|Project=%s
|Availability Zone=%s
|Region=%s
|Security Group=%s
|Launch Time=%s
|FQDN=%s
|Puppet Class=%s
|Puppet Var=%s}}
RESOURCEINFO;
        $host = $this->getHost();
        $puppetinfo = $host->getPuppetConfiguration();
        if ($puppetinfo['puppetclass']) {
            $puppetclasses = implode(',', $puppetinfo['puppetclass']);
        } else {
            $puppetclasses = '';
        }
        $puppetvars = '';
        if ($puppetinfo['puppetvar']) {
            foreach ($puppetinfo['puppetvar'] as $key => $val) {
                # Let's not leak user's email addresses; we know this
                # will be set, since we are setting it.
                if ($key == 'instancecreator_email') {
                    continue;
                }
                $puppetvars .= $key . '=' . $val . ',';
            }
        }
        $adminNova = new OpenStackNovaController($wgOpenStackManagerNovaAdminKeys);
        $instanceType = $adminNova->getInstanceType($this->getInstanceType());
        $text = sprintf($format, $this->getInstanceName(), $this->getReservationId(), $this->getInstanceId(), $this->getInstancePrivateIP(), $this->getInstancePublicIP(), $this->getInstanceState(), $this->getInstanceHost(), $this->getInstanceType(), $instanceType->getMemorySize(), $instanceType->getNumberOfCPUs(), $instanceType->getStorageSize(), $this->getImageId(), $this->getOwner(), $this->getAvailabilityZone(), $this->getRegion(), implode(',', $this->getSecurityGroups()), $this->getLaunchTime(), $host->getFullyQualifiedHostName(), $puppetclasses, $puppetvars);
        OpenStackNovaArticle::editArticle($this->getInstanceId(), $text);
    }
 /**
  * @param $user OpenStackNovaUser
  * @return string
  */
 static function getKeyList($user)
 {
     global $wgOpenStackManagerNovaKeypairStorage;
     $keyInfo = array();
     if ($wgOpenStackManagerNovaKeypairStorage === 'nova') {
         $projects = $user->getProjects();
         $keyInfo['keyname'] = array('type' => 'text', 'label-message' => 'openstackmanager-novakeyname', 'default' => '', 'name' => 'keyname');
         $project_keys = array();
         foreach ($projects as $project) {
             $project_keys[$project] = $project;
         }
         $keyInfo['project'] = array('type' => 'select', 'options' => $project_keys, 'label-message' => 'openstackmanager-project', 'name' => 'project');
     }
     $keyInfo['key'] = array('type' => 'textarea', 'default' => '', 'label-message' => 'openstackmanager-novapublickey', 'name' => 'key');
     $out = '';
     if ($wgOpenStackManagerNovaKeypairStorage === 'nova') {
         # TODO: add project filter
         foreach ($projects as $project) {
             $userCredentials = $user->getCredentials();
             $userNova = new OpenStackNovaController($userCredentials, $project);
             $keypairs = $userNova->getKeypairs();
             if (!$keypairs) {
                 continue;
             }
             $out .= Html::element('h2', array(), $project);
             $headers = array('openstackmanager-name', 'openstackmanager-fingerprint');
             $keyRows = array();
             foreach ($keypairs as $keypair) {
                 $keyRow = array();
                 SpecialNova::pushResourceColumn($keyRow, $keypair->getKeyName());
                 SpecialNova::pushResourceColumn($keyRow, $keypair->getKeyFingerprint());
                 $keyRows[] = $keyRow;
             }
             $out .= SpecialNova::createResourceTable($headers, $keyRows);
         }
     } elseif ($wgOpenStackManagerNovaKeypairStorage === 'ldap') {
         $headers = array('openstackmanager-keys', 'openstackmanager-actions');
         $keypairs = $user->getKeypairs();
         $keyRows = array();
         foreach ($keypairs as $hash => $key) {
             $keyRow = array();
             SpecialNova::pushResourceColumn($keyRow, $key, array('class' => 'Nova_col'));
             $actions = array();
             $actions[] = SpecialNova::createNovaKeyActionLink('openstackmanager-delete', array('action' => 'delete', 'hash' => $hash, 'returnto' => SpecialPage::getTitleFor('Preferences', false, 'mw-prefsection-openstack')->getFullText()));
             SpecialNova::pushRawResourceColumn($keyRow, SpecialNova::createResourceList($actions));
             $keyRows[] = $keyRow;
         }
         $out .= SpecialNova::createResourceTable($headers, $keyRows);
     }
     $out .= Linker::link(SpecialPage::getTitleFor('NovaKey'), wfMessage('openstackmanager-addkey')->escaped(), array(), array('returnto' => SpecialPage::getTitleFor('Preferences', false, 'mw-prefsection-openstack')->getFullText()));
     return $out;
 }
 /**
  * @return string
  */
 function getProject()
 {
     return OpenStackNovaController::_get_property($this->group, 'tenant_id');
 }
 /**
  * Return the time at which this instance was created
  *
  * @return string
  */
 function getLaunchTime()
 {
     return OpenStackNovaController::_get_property($this->instance, 'created');
 }
 /**
  * @param  $instanceName
  * @param  $image
  * @param  $key
  * @param  $instanceType
  * @param  $groups
  * @return null|OpenStackNovaInstance
  */
 function createInstance($instanceName, $image, $key, $instanceType, $groups)
 {
     global $wgOpenStackManagerInstanceUserData;
     $data = array('server' => array());
     if ($key) {
         $data['key_name'] = $key;
     }
     $data['server']['flavorRef'] = $instanceType;
     $data['server']['imageRef'] = $image;
     $data['server']['name'] = $instanceName;
     if ($wgOpenStackManagerInstanceUserData) {
         $random_hash = md5(date('r', time()));
         $endl = OpenStackNovaController::getLineEnding();
         $boundary = '===============' . $random_hash . '==';
         $userdata = 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . $endl;
         $userdata .= 'MIME-Version: 1.0' . $endl;
         $boundary = '--' . $boundary;
         $userdata .= $endl;
         $userdata .= $boundary;
         if ($wgOpenStackManagerInstanceUserData['cloud-config']) {
             $userdata .= $endl . $this->getAttachmentMime(Spyc::YAMLDump($wgOpenStackManagerInstanceUserData['cloud-config']), 'text/cloud-config', 'cloud-config.txt');
             $userdata .= $endl . $boundary;
         }
         if ($wgOpenStackManagerInstanceUserData['scripts']) {
             foreach ($wgOpenStackManagerInstanceUserData['scripts'] as $scriptname => $script) {
                 wfSuppressWarnings();
                 $stat = stat($script);
                 wfRestoreWarnings();
                 if (!$stat) {
                     continue;
                 }
                 $scripttext = file_get_contents($script);
                 $userdata .= $endl . $this->getAttachmentMime($scripttext, 'text/x-shellscript', $scriptname);
                 $userdata .= $endl . $boundary;
             }
         }
         if ($wgOpenStackManagerInstanceUserData['upstarts']) {
             foreach ($wgOpenStackManagerInstanceUserData['upstarts'] as $upstartname => $upstart) {
                 wfSuppressWarnings();
                 $stat = stat($upstart);
                 wfRestoreWarnings();
                 if (!$stat) {
                     continue;
                 }
                 $upstarttext = file_get_contents($upstart);
                 $userdata .= $endl . $this->getAttachmentMime($upstarttext, 'text/upstart-job', $upstartname);
                 $userdata .= $endl . $boundary;
             }
         }
         $userdata .= '--';
         $data['server']['user_data'] = base64_encode($userdata);
     }
     $data['server']['security_groups'] = array();
     foreach ($groups as $group) {
         $data['server']['security_groups'][] = array('name' => $group);
     }
     $ret = $this->restCall('compute', '/servers', 'POST', $data);
     if ($ret['code'] !== 202) {
         return null;
     }
     $instance = new OpenStackNovaInstance($ret['body']->server, $this->getRegion());
     return $instance;
 }