r79784 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79783‎ | r79784 | r79785 >
Date:01:31, 7 January 2011
Author:laner
Status:deferred
Tags:
Comment:
* Added a small amount of locailization to Special:NovaInstance
* Changed DNS configuration options for instances
** Can now choose a domain only based upon location
** Location and instance DNS is linked, as the DNS entry created will be a private DNS entry
* Added a location field to the form for domains, so that domains can be location specific
** Domains with no location attribute set will be public DNS domains; this likely needs to be made clear on the form
* Fixed instance list for Special:NovaInstance; was previously only showing one instance, even if multiple instances existed
* Added a OpenStackNovaHostJob, to add IP addresses to host entries in a deffered manner
** This is due to a change in Nova; previously IP addresses were assigned on instance creation, now they are created on instance scheduling, so IP address information is not available immediately
* Removed in-process caching for Nova API responses; was causing more trouble than it was worth. Should be re-added as memcache caches later
* Modified the behavior of getInstance to get all instances from Nova, and return a specific instance, since this behavior changed in the API (which is likely a bug)
* Added various extra error checking
* Removed t1.micro as an instance type, as it isn't valid in Nova
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackManager.i18n.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackManager.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaController.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaDomain.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaHost.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaHostJob.php (added) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaProject.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaUser.php (modified) (history)
  • /trunk/extensions/OpenStackManager/SpecialNovaDomain.php (modified) (history)
  • /trunk/extensions/OpenStackManager/SpecialNovaInstance.php (modified) (history)
  • /trunk/extensions/OpenStackManager/SpecialNovaProject.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/SpecialNovaInstance.php
@@ -64,12 +64,13 @@
6565 global $wgOpenStackManagerPuppetOptions;
6666
6767 $this->setHeaders();
68 - $wgOut->setPagetitle("Create Instance");
 68+ $wgOut->setPagetitle( wfMsg('openstackmanager-createinstance') );
6969
7070 $instanceInfo = Array();
7171 $instanceInfo['instancename'] = array(
7272 'type' => 'text',
73 - 'label-message' => 'instancename',
 73+ 'label-message' => 'openstackmanager-instancename',
 74+ 'validation-callback' => array( $this, 'validateInstanceName' ),
7475 'default' => '',
7576 'section' => 'instance/info',
7677 );
@@ -81,9 +82,9 @@
8283 }
8384 $instanceInfo['instanceType'] = array(
8485 'type' => 'select',
 86+ 'label-message' => 'openstackmanager-instancetype',
8587 'section' => 'instance/info',
8688 'options' => $instanceType_keys,
87 - 'label-message' => 'instancetype',
8889 );
8990
9091 # Availability zone names can't be translated. Get the keys, and make an array
@@ -97,7 +98,7 @@
9899 'type' => 'select',
99100 'section' => 'instance/info',
100101 'options' => $availabilityZone_keys,
101 - 'label-message' => 'availabilityzone',
 102+ 'label-message' => 'openstackmanager-availabilityzone',
102103 );
103104
104105 # Image names can't be translated. Get the image, and make an array
@@ -111,7 +112,7 @@
112113 'type' => 'select',
113114 'section' => 'instance/info',
114115 'options' => $image_keys,
115 - 'label-message' => 'imagetype',
 116+ 'label-message' => 'openstackmanager-imagetype',
116117 );
117118
118119 # Keypair names can't be translated. Get the keys, and make an array
@@ -129,7 +130,7 @@
130131 # 'label-message' => 'keypair',
131132 #);
132133
133 - $domains = OpenStackNovaDomain::getAllDomains();
 134+ $domains = OpenStackNovaDomain::getAllDomains( true );
134135 $domain_keys = array();
135136 foreach ( $domains as $domain ) {
136137 $domainname = $domain->getDomainName();
@@ -139,7 +140,7 @@
140141 'type' => 'select',
141142 'section' => 'instance/info',
142143 'options' => $domain_keys,
143 - 'label-message' => 'domain',
 144+ 'label-message' => 'openstackmanager-dnsdomain',
144145 );
145146
146147 $instanceInfo['project'] = array(
@@ -157,7 +158,7 @@
158159 'type' => 'multiselect',
159160 'section' => 'instance/puppetinfo',
160161 'options' => $classes,
161 - 'label-message' => 'puppetclasses',
 162+ 'label-message' => 'openstackmanager-puppetclasses',
162163 );
163164 }
164165
@@ -177,9 +178,9 @@
178179 'default' => 'create',
179180 );
180181
181 - $instanceForm = new SpecialNovaInstanceForm( $instanceInfo, 'novainstance-form' );
 182+ $instanceForm = new SpecialNovaInstanceForm( $instanceInfo, 'openstackmanager-novainstance' );
182183 $instanceForm->setTitle( SpecialPage::getTitleFor( 'NovaInstance' ));
183 - $instanceForm->setSubmitID( 'novainstance-form-createinstancesubmit' );
 184+ $instanceForm->setSubmitID( 'openstackmanager-novainstance-createinstancesubmit' );
184185 $instanceForm->setSubmitCallback( array( $this, 'tryCreateSubmit' ) );
185186 $instanceForm->show();
186187
@@ -313,6 +314,7 @@
314315 $header .= Html::element( 'th', array(), 'Instance ID' );
315316 $header .= Html::element( 'th', array(), 'Instance State' );
316317 $header .= Html::element( 'th', array(), 'Instance Type' );
 318+ $header .= Html::element( 'th', array(), 'Instance IP' );
317319 $header .= Html::element( 'th', array(), 'Image ID' );
318320 $header .= Html::element( 'th', array(), 'Actions' );
319321 $projectArr = array();
@@ -324,11 +326,12 @@
325327 $instanceName = (string)$instance->getInstanceName();
326328 $title = Title::newFromText( $instanceName, NS_VM );
327329 $instanceNameLink = $sk->link( $title, $instanceName, array(), array(), array() );
328 - $projectArr["$project"] = Html::rawElement( 'td', array(), $instanceNameLink );
329 - $projectArr["$project"] .= Html::element( 'td', array(), $instance->getInstanceId() );
330 - $projectArr["$project"] .= Html::element( 'td', array(), $instance->getInstanceState() );
331 - $projectArr["$project"] .= Html::element( 'td', array(), $instance->getInstanceType() );
332 - $projectArr["$project"] .= Html::element( 'td', array(), $instance->getImageId() );
 330+ $instanceOut = Html::rawElement( 'td', array(), $instanceNameLink );
 331+ $instanceOut .= Html::element( 'td', array(), $instance->getInstanceId() );
 332+ $instanceOut .= Html::element( 'td', array(), $instance->getInstanceState() );
 333+ $instanceOut .= Html::element( 'td', array(), $instance->getInstanceType() );
 334+ $instanceOut .= Html::element( 'td', array(), $instance->getInstancePrivateIP() );
 335+ $instanceOut .= Html::element( 'td', array(), $instance->getImageId() );
333336 $actions = $sk->link( $this->getTitle(), 'delete', array(),
334337 array( 'action' => 'delete',
335338 'project' => $project,
@@ -346,7 +349,8 @@
347350 'project' => $project,
348351 'instanceid' => $instance->getInstanceId() ),
349352 array() );
350 - $projectArr["$project"] .= Html::rawElement( 'td', array(), $actions );
 353+ $instanceOut .= Html::rawElement( 'td', array(), $actions );
 354+ $projectArr["$project"] .= Html::rawElement( 'tr', array(), $instanceOut );
351355 }
352356 foreach ( $userProjects as $project ) {
353357 $out .= Html::element( 'h2', array(), $project );
@@ -354,7 +358,7 @@
355359 array( 'action' => 'create', 'project' => $project ), array() );
356360 if ( isset( $projectArr["$project"] ) ) {
357361 $projectOut = $header;
358 - $projectOut .= Html::rawElement( 'tr', array(), $projectArr["$project"] );
 362+ $projectOut .= $projectArr["$project"];
359363 $out .= Html::rawElement( 'table',
360364 array( 'id' => 'novainstancelist', 'class' => 'wikitable' ), $projectOut );
361365 }
@@ -371,6 +375,7 @@
372376 $domain = OpenStackNovaDomain::getDomainByName( $formData['domain'] );
373377 if ( ! $domain ) {
374378 $out = Html::element( 'p', array(), 'Requested domain is invalid' );
 379+ return false;
375380 }
376381 $instance = $this->userNova->createInstance( $formData['instancename'], $formData['imageType'], '', $formData['instanceType'], $formData['availabilityZone'] );
377382 if ( $instance ) {
@@ -388,8 +393,12 @@
389394 }
390395 }
391396 $host = OpenStackNovaHost::addHost( $instance, $domain, $puppetinfo );
 397+
392398 if ( $host ) {
393 - $out = Html::element( 'p', array(), 'Created instance ' . $instance->getInstanceID() . ' with image ' . $instance->getImageId() . ' and hostname ' . $host->getFullyQualifiedHostName() . ' and ip ' . $instance->getInstancePrivateIP() );
 399+ $title = Title::newFromText( $wgOut->getPageTitle() );
 400+ $job = new OpenStackNovaHostJob( $title, array( 'instanceid' => (string)$instance->getInstanceId() ) );
 401+ $job->insert();
 402+ $out = Html::element( 'p', array(), 'Created instance ' . $instance->getInstanceID() . ' with image ' . $instance->getImageId() . ' and hostname ' . $host->getFullyQualifiedHostName() );
394403 } else {
395404 $this->userNova->terminateInstance( $instance->getInstanceId() );
396405 $out = Html::element( 'p', array(), 'Failed to create instance as the host could not be added to LDAP' );
@@ -407,20 +416,24 @@
408417 function tryDeleteSubmit( $formData, $entryPoint = 'internal' ) {
409418 global $wgOut, $wgUser;
410419
 420+ $sk = $wgUser->getSkin();
411421 $instance = $this->adminNova->getInstance( $formData['instanceid'] );
 422+ if ( ! $instance ) {
 423+ $out = Html::element( 'p', array(), 'The instance requested does not exist.' );
 424+ return true;
 425+ }
412426 $instancename = $instance->getInstanceName();
413427 $instanceid = $instance->getInstanceId();
414 - $success = $this->userNova->terminateInstance( $formData['instanceid'] );
415 - $sk = $wgUser->getSkin();
 428+ $success = $this->userNova->terminateInstance( $instanceid );
416429 if ( $success ) {
417430 $success = OpenStackNovaHost::deleteHostByInstanceId( $instanceid );
418431 if ( $success ) {
419 - $out = Html::element( 'p', array(), "Deleted instance $instancename" );
 432+ $out = Html::element( 'p', array(), "Deleted instance $instanceid" );
420433 } else {
421 - $out = Html::element( 'p', array(), "Successfully deleted instance, but failed to remove $instancename DNS entry" );
 434+ $out = Html::element( 'p', array(), "Successfully deleted instance, but failed to remove $instancename DNS entry for instance $instanceid" );
422435 }
423436 } else {
424 - $out = Html::element( 'p', array(), 'Failed to create instance' );
 437+ $out = Html::element( 'p', array(), 'Failed to delete instance' );
425438 }
426439 $out .= $sk->link( $this->getTitle(), 'Back to instance list', array(), array(), array() );
427440
@@ -463,6 +476,14 @@
464477 return true;
465478 }
466479
 480+ function validateInstanceName( $instancename, $alldata ) {
 481+ if ( ! preg_match( "/^[a-z][a-z0-9\-]*$/", $instancename ) ) {
 482+ return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'openstackmanager-badinstancename' ) );
 483+ } else {
 484+ return true;
 485+ }
 486+ }
 487+
467488 }
468489
469490 class SpecialNovaInstanceForm extends HTMLForm {
Index: trunk/extensions/OpenStackManager/SpecialNovaProject.php
@@ -34,6 +34,7 @@
3535 # return false;
3636 #}
3737 if ( ! $wgUser->isLoggedIn() ) {
 38+ $this->notLoggedIn();
3839 return false;
3940 }
4041
@@ -207,6 +208,9 @@
208209 $projectsOut .= Html::element( 'th', array(), 'Members' );
209210 $projectsOut .= Html::element( 'th', array(), 'Action' );
210211 $projects = OpenStackNovaProject::getAllProjects();
 212+ if ( ! $projects ) {
 213+ $projectsOut = '';
 214+ }
211215 foreach ( $projects as $project ) {
212216 $projectName = $project->getProjectName();
213217 $projectOut = Html::element( 'td', array(), $projectName );
@@ -218,17 +222,21 @@
219223 $projectMemberOut = htmlentities( $projectMember) . ' (' . $link . ')';
220224 $memberOut .= Html::rawElement( 'li', array(), $projectMemberOut );
221225 }
222 - $memberOut .= '<br />';
 226+ if ( $memberOut ) {
 227+ $memberOut .= '<br />';
 228+ $memberOut = Html::rawElement( 'ul', array(), $memberOut );
 229+ }
223230 $memberOut .= $sk->link( $this->getTitle(), 'Add a member', array(),
224231 array( 'action' => 'addmember', 'projectname' => $projectName ), array() );
225 - $membersOut = Html::rawElement( 'ul', array(), $memberOut );
226 - $projectOut .= Html::rawElement( 'td', array(), $membersOut );
 232+ $projectOut .= Html::rawElement( 'td', array(), $memberOut );
227233 $link = $sk->link( $this->getTitle(), 'delete project', array(),
228234 array( 'action' => 'delete', 'projectname' => $projectName ), array() );
229235 $projectOut .= Html::rawElement( 'td', array(), $link );
230236 $projectsOut .= Html::rawElement( 'tr', array(), $projectOut );
231237 }
232 - $out .= Html::rawElement( 'table', array( 'class' => 'wikitable' ), $projectsOut );
 238+ if ( $projectsOut ) {
 239+ $out .= Html::rawElement( 'table', array( 'class' => 'wikitable' ), $projectsOut );
 240+ }
233241
234242 $wgOut->addHTML( $out );
235243 }
Index: trunk/extensions/OpenStackManager/SpecialNovaDomain.php
@@ -23,6 +23,7 @@
2424 # return false;
2525 #}
2626 if ( ! $wgUser->isLoggedIn() ) {
 27+ $this->notLoggedIn();
2728 return false;
2829 }
2930
@@ -36,8 +37,16 @@
3738 }
3839 }
3940
 41+ function notLoggedIn() {
 42+ global $wgOut;
 43+ $this->setHeaders();
 44+ $wgOut->setPagetitle("Not logged in");
 45+ $wgOut->addHTML('<p>You must be logged in to perform this action</p>');
 46+ }
 47+
4048 function createDomain() {
4149 global $wgRequest, $wgOut;
 50+ global $wgOpenStackManagerDNSOptions;
4251
4352 $this->setHeaders();
4453 $wgOut->setPagetitle("Create Domain");
@@ -55,8 +64,12 @@
5665 'default' => '',
5766 'section' => 'domain/info',
5867 );
59 -
60 -
 68+ $domainInfo['location'] = array(
 69+ 'type' => 'text',
 70+ 'label-message' => 'location',
 71+ 'default' => '',
 72+ 'section' => 'domain/info',
 73+ );
6174 $domainInfo['action'] = array(
6275 'type' => 'hidden',
6376 'default' => 'create',
@@ -111,21 +124,26 @@
112125 $out = '';
113126 $sk = $wgUser->getSkin();
114127 $out .= $sk->link( $this->getTitle(), 'Create a new domain', array(), array( 'action' => 'create' ), array() );
115 - $domainsOut = Html::element( 'th', array(), 'Domain name' );
116 - $domainsOut .= Html::element( 'th', array(), 'FQDN' );
117 - $domainsOut .= Html::element( 'th', array(), 'Action' );
 128+ $domainsOut = Html::element( 'th', array(), 'Domain name' );
 129+ $domainsOut .= Html::element( 'th', array(), 'FQDN' );
 130+ $domainsOut .= Html::element( 'th', array(), 'Location' );
 131+ $domainsOut .= Html::element( 'th', array(), 'Action' );
118132 $domains = OpenStackNovaDomain::getAllDomains();
119133 foreach ( $domains as $domain ) {
120134 $domainName = $domain->getDomainName();
121135 $fqdn = $domain->getFullyQualifiedDomainName();
 136+ $location = $domain->getLocation();
122137 $domainOut = Html::element( 'td', array(), $domainName );
123138 $domainOut .= Html::element( 'td', array(), $fqdn );
 139+ $domainOut .= Html::element( 'td', array(), $location );
124140 $link = $sk->link( $this->getTitle(), 'delete domain', array(),
125141 array( 'action' => 'delete', 'domainname' => $domainName ), array() );
126142 $domainOut .= Html::rawElement( 'td', array(), $link );
127143 $domainsOut .= Html::rawElement( 'tr', array(), $domainOut );
128144 }
129 - $out .= Html::rawElement( 'table', array( 'class' => 'wikitable' ), $domainsOut );
 145+ if ( $domains ) {
 146+ $out .= Html::rawElement( 'table', array( 'class' => 'wikitable' ), $domainsOut );
 147+ }
130148
131149 $wgOut->addHTML( $out );
132150 }
@@ -133,7 +151,7 @@
134152 function tryCreateSubmit( $formData, $entryPoint = 'internal' ) {
135153 global $wgOut, $wgUser;
136154
137 - $success = OpenStackNovaDomain::createDomain( $formData['domainname'], $formData['fqdn'] );
 155+ $success = OpenStackNovaDomain::createDomain( $formData['domainname'], $formData['fqdn'], $formData['location'] );
138156 if ( ! $success ) {
139157 $out = Html::element( 'p', array(), 'Failed to create domain' );
140158 $wgOut->addHTML( $out );
Index: trunk/extensions/OpenStackManager/OpenStackManager.i18n.php
@@ -39,17 +39,23 @@
4040 'openstackmanager' => 'Successfully deleted domain',
4141 'openstackmanager' => 'Failed to delete domain',
4242
43 - 'openstackmanager' => 'Create Instance',
 43+ 'openstackmanager-createinstance' => 'Create Instance',
 44+ 'openstackmanager-novainstance-instance' => 'Instance',
4445 'openstackmanager' => 'Configure Instance',
4546 'openstackmanager' => 'The host requested does not exist.',
 47+ 'openstackmanager-dnsdomain' => 'DNS Domain',
 48+ 'openstackmanager-puppetclasses' => 'Puppet Classes',
 49+ 'openstackmanager-novainstance-info' => 'Instance Information',
 50+ 'openstackmanager-novainstance-puppetinfo' => 'Puppet Information',
4651
4752 'openstackmanager' => 'Are you sure you wish to delete instance "$1"?',
4853 'openstackmanager' => 'Instance list',
49 - 'openstackmanager' => 'Instance Name',
 54+ 'openstackmanager-instancename' => 'Instance Name',
5055 'openstackmanager' => 'Instance ID',
5156 'openstackmanager' => 'Instance State',
52 - 'openstackmanager' => 'Instance Type',
53 - 'openstackmanager' => 'Image ID',
 57+ 'openstackmanager-instancetype' => 'Instance Type',
 58+ 'openstackmanager-availabilityzone' => 'Availability Zone',
 59+ 'openstackmanager-imagetype' => 'Image Type',
5460 'openstackmanager' => 'Actions',
5561
5662 'openstackmanager' => 'Create a new instance',
@@ -97,5 +103,6 @@
98104 'openstackmanager' => 'Failed to delete project',
99105 'openstackmanager' => 'Successfully added $1 to $2',
100106 'openstackmanager' => 'Failed to add $1 to $2',
 107+ 'openstackmanager-badinstancename' => 'Bad instance name provided. Instance names must start with a-z, and can only contain a-z, 0-9, and - characters.',
101108
102109 );
Index: trunk/extensions/OpenStackManager/OpenStackNovaProject.php
@@ -15,8 +15,9 @@
1616 function connect() {
1717 global $wgAuth;
1818 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 19+ global $wgOpenStackManagerLDAPDomain;
1920
20 - $wgAuth->connect();
 21+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
2122 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
2223 }
2324
@@ -120,8 +121,9 @@
121122 global $wgAuth;
122123 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
123124 global $wgOpenStackManagerLDAPProjectBaseDN;
 125+ global $wgOpenStackManagerLDAPDomain;
124126
125 - $wgAuth->connect();
 127+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
126128 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
127129
128130 $projects = array();
@@ -149,8 +151,9 @@
150152 global $wgAuth;
151153 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
152154 global $wgOpenStackManagerLDAPProjectBaseDN;
 155+ global $wgOpenStackManagerLDAPDomain;
153156
154 - $wgAuth->connect();
 157+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
155158 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
156159
157160 $project['objectclass'][] = 'groupofnames';
@@ -175,9 +178,10 @@
176179 static function deleteProject( $projectname ) {
177180 global $wgAuth;
178181 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 182+ global $wgOpenStackManagerLDAPDomain;
179183
180184
181 - $wgAuth->connect();
 185+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
182186 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
183187
184188 $project = new OpenStackNovaProject( $projectname );
@@ -210,6 +214,7 @@
211215 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
212216 global $wgOpenStackManagerLDAPDomain;
213217 global $wgExtraNamespaces;
 218+ global $wgOpenStackManagerLDAPDomain;
214219
215220 $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
216221 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
Index: trunk/extensions/OpenStackManager/OpenStackNovaDomain.php
@@ -16,8 +16,9 @@
1717 function connect() {
1818 global $wgAuth;
1919 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 20+ global $wgOpenStackManagerLDAPDomain;
2021
21 - $wgAuth->connect();
 22+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
2223 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
2324 }
2425
@@ -44,6 +45,14 @@
4546 return $this->fqdn;
4647 }
4748
 49+ function getLocation() {
 50+ if ( isset( $this->domainInfo[0]['l'] ) ) {
 51+ return $this->domainInfo[0]['l'][0];
 52+ } else {
 53+ return '';
 54+ }
 55+ }
 56+
4857 function updateSOA() {
4958 global $wgAuth;
5059
@@ -60,15 +69,21 @@
6170 }
6271 }
6372
64 - static function getAllDomains() {
 73+ static function getAllDomains( $bylocation=false) {
6574 global $wgAuth;
6675 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
6776 global $wgOpenStackManagerLDAPInstanceBaseDN;
 77+ global $wgOpenStackManagerLDAPDomain;
6878
69 - $wgAuth->connect();
 79+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
7080 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
7181
7282 $domains = array();
 83+ if ( $bylocation ) {
 84+ $query = '(&(soarecord=*)(l=*))';
 85+ } else {
 86+ $query = '(soarecord=*)';
 87+ }
7388 wfSuppressWarnings();
7489 $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN, '(soarecord=*)' );
7590 wfRestoreWarnings();
@@ -102,8 +117,9 @@
103118 global $wgAuth;
104119 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
105120 global $wgOpenStackManagerLDAPInstanceBaseDN;
 121+ global $wgOpenStackManagerLDAPDomain;
106122
107 - $wgAuth->connect();
 123+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
108124 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
109125
110126 wfSuppressWarnings();
@@ -126,8 +142,9 @@
127143 global $wgAuth;
128144 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
129145 global $wgOpenStackManagerLDAPInstanceBaseDN;
 146+ global $wgOpenStackManagerLDAPDomain;
130147
131 - $wgAuth->connect();
 148+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
132149 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
133150
134151 wfSuppressWarnings();
@@ -147,13 +164,14 @@
148165 }
149166
150167 # TODO: Allow generic domains; get rid of config set base name
151 - static function createDomain( $domainname, $fqdn ) {
 168+ static function createDomain( $domainname, $fqdn, $location ) {
152169 global $wgAuth;
153170 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
154171 global $wgOpenStackManagerLDAPInstanceBaseDN;
155 - global $wgOpenStackManagerDNSServers;
 172+ global $wgOpenStackManagerDNSOptions;
 173+ global $wgOpenStackManagerLDAPDomain;
156174
157 - $wgAuth->connect();
 175+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
158176 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
159177
160178 $soa = OpenStackNovaDomain::generateSOA();
@@ -161,8 +179,9 @@
162180 $domain['objectclass'][] = 'dnsdomain';
163181 $domain['objectclass'][] = 'domainrelatedobject';
164182 $domain['dc'] = $domainname;
165 - $domain['soarecord'] = $wgOpenStackManagerDNSServers['primary'] . ' ' . $soa;
 183+ $domain['soarecord'] = $wgOpenStackManagerDNSOptions['servers']['primary'] . ' ' . $soa;
166184 $domain['associateddomain'] = $fqdn;
 185+ $domain['l'] = $location;
167186 $dn = 'dc=' . $domainname . ',' . $wgOpenStackManagerLDAPInstanceBaseDN;
168187
169188 wfSuppressWarnings();
@@ -180,8 +199,9 @@
181200 static function deleteDomain( $domainname ) {
182201 global $wgAuth;
183202 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 203+ global $wgOpenStackManagerLDAPDomain;
184204
185 - $wgAuth->connect();
 205+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
186206 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
187207
188208 $domain = new OpenStackNovaDomain( $domainname );
@@ -211,12 +231,14 @@
212232 }
213233
214234 static function generateSOA() {
215 - global $wgOpenStackManagerDNSSOA;
 235+ global $wgOpenStackManagerDNSOptions;
216236
217237 $serial = date( 'YmdHis' );
218 - $soa = $wgOpenStackManagerDNSSOA['hostmaster'] . ' ' . $serial . ' ' .
219 - $wgOpenStackManagerDNSSOA['refresh'] . ' ' . $wgOpenStackManagerDNSSOA['retry'] . ' ' .
220 - $wgOpenStackManagerDNSSOA['expiry'] . ' ' . $wgOpenStackManagerDNSSOA['minimum'];
 238+ $soa = $wgOpenStackManagerDNSOptions['soa']['hostmaster'] . ' ' . $serial . ' ' .
 239+ $wgOpenStackManagerDNSOptions['soa']['refresh'] . ' ' .
 240+ $wgOpenStackManagerDNSOptions['soa']['retry'] . ' ' .
 241+ $wgOpenStackManagerDNSOptions['soa']['expiry'] . ' ' .
 242+ $wgOpenStackManagerDNSOptions['soa']['minimum'];
221243
222244 return $soa;
223245 }
Index: trunk/extensions/OpenStackManager/OpenStackNovaHostJob.php
@@ -0,0 +1,46 @@
 2+<?php
 3+class OpenStackNovaHostJob extends Job {
 4+ public function __construct( $title, $params ) {
 5+ // Replace synchroniseThreadArticleData with the an identifier for your job.
 6+ parent::__construct( 'addDNSHostToLDAP', $title, $params );
 7+ }
 8+
 9+ /**
 10+ * Execute the job
 11+ *
 12+ * @return bool
 13+ */
 14+ public function run() {
 15+ global $wgOpenStackManagerNovaAdminKeys;
 16+ global $wgAuth;
 17+
 18+ $instanceid = $this->params['instanceid'];
 19+ $wgAuth->printDebug( "Running DNS job for $instanceid", NONSENSITIVE );
 20+
 21+ $adminCredentials = $wgOpenStackManagerNovaAdminKeys;
 22+ $adminNova = new OpenStackNovaController( $adminCredentials );
 23+ $instance = $adminNova->getInstance( $instanceid );
 24+ if ( ! $instance ) {
 25+ $wgAuth->printDebug( "Instance doesn't exist for $instanceid", NONSENSITIVE );
 26+ # Instance no longer exists
 27+ return true;
 28+ }
 29+ $ip = (string)$instance->getInstancePrivateIP();
 30+ if ( trim( $ip ) == '' ) {
 31+ # IP hasn't been assigned yet
 32+ # re-add to queue
 33+ $wgAuth->printDebug( "Readding job for $instanceid", NONSENSITIVE );
 34+ $job = new OpenStackNovaHostJob( $this->title, $this->params );
 35+ $job->insert();
 36+ return true;
 37+ }
 38+ $host = OpenStackNovaHost::getHostByInstanceId( $instanceid );
 39+ if ( ! $host ) {
 40+ $wgAuth->printDebug( "Host record doesn't exist for $instanceid", NONSENSITIVE );
 41+ return true;
 42+ }
 43+ $host->setARecord( $ip );
 44+
 45+ return true;
 46+ }
 47+}
Property changes on: trunk/extensions/OpenStackManager/OpenStackNovaHostJob.php
___________________________________________________________________
Added: svn:eol-style
148 + native
Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php
@@ -17,8 +17,9 @@
1818 function connect() {
1919 global $wgAuth;
2020 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 21+ global $wgOpenStackManagerLDAPDomain;
2122
22 - $wgAuth->connect();
 23+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
2324 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
2425 }
2526
@@ -47,7 +48,7 @@
4849 }
4950
5051 function getFullyQualifiedHostName() {
51 - return $this->getHostName() . '.' . $this->domain->getFullyQualifiedDomainName();
 52+ return $this->getHostName();
5253 }
5354
5455 function getPuppetConfiguration() {
@@ -181,6 +182,23 @@
182183 }
183184 }
184185
 186+ function setARecord( $ip ) {
 187+ global $wgAuth;
 188+
 189+ $values = array( 'arecord' => array( $ip ) );
 190+ wfSuppressWarnings();
 191+ $success = ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
 192+ wfRestoreWarnings();
 193+ if ( $success ) {
 194+ $wgAuth->printDebug( "Successfully set $ip on $this->hostDN", NONSENSITIVE );
 195+ $this->domain->updateSOA();
 196+ return true;
 197+ } else {
 198+ $wgAuth->printDebug( "Failed to set $ip on $this->hostDN", NONSENSITIVE );
 199+ return false;
 200+ }
 201+ }
 202+
185203 static function getHostByName( $hostname, $domain ) {
186204 $host = new OpenStackNovaHost( $hostname, $domain );
187205 if ( $host->hostInfo ) {
@@ -198,8 +216,9 @@
199217 static function getAllHosts( $domain ) {
200218 global $wgAuth;
201219 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 220+ global $wgOpenStackManagerLDAPDomain;
202221
203 - $wgAuth->connect();
 222+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
204223 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
205224
206225 $hosts = array();
@@ -225,8 +244,9 @@
226245 static function deleteHost( $hostname, $domain ) {
227246 global $wgAuth;
228247 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 248+ global $wgOpenStackManagerLDAPDomain;
229249
230 - $wgAuth->connect();
 250+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
231251 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
232252
233253 $host = OpenStackNovaHost::getHostByName( $hostname, $domain );
@@ -252,8 +272,9 @@
253273 static function deleteHostByInstanceId( $instanceid ) {
254274 global $wgAuth;
255275 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 276+ global $wgOpenStackManagerLDAPDomain;
256277
257 - $wgAuth->connect();
 278+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
258279 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
259280
260281 $host = OpenStackNovaHost::getHostByInstanceId( $instanceid );
@@ -289,8 +310,9 @@
290311 global $wgAuth;
291312 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
292313 global $wgOpenStackManagerLDAPInstanceBaseDN, $wgOpenStackManagerPuppetOptions;
 314+ global $wgOpenStackManagerLDAPDomain;
293315
294 - $wgAuth->connect();
 316+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
295317 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
296318
297319 $hostname = $instance->getInstanceName();
@@ -324,7 +346,9 @@
325347 $hostEntry['puppetclass'][] = $class;
326348 }
327349 foreach( $puppetinfo['variables'] as $variable => $value ) {
328 - $hostEntry['puppetvar'][] = $variable . ' = ' . $value;
 350+ if ( $value ) {
 351+ $hostEntry['puppetvar'][] = $variable . ' = ' . $value;
 352+ }
329353 }
330354 }
331355 }
Index: trunk/extensions/OpenStackManager/OpenStackNovaUser.php
@@ -148,8 +148,9 @@
149149 function connect() {
150150 global $wgAuth;
151151 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 152+ global $wgOpenStackManagerLDAPDomain;
152153
153 - $wgAuth->connect();
 154+ $wgAuth->connect( $wgOpenStackManagerLDAPDomain );
154155 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
155156 }
156157
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php
@@ -6,7 +6,7 @@
77 var $novaConnection;
88 var $instances, $images, $keypairs, $availabilityZones;
99
10 - var $instanceTypes = array( 't1.micro', 'm1.small', 'm1.large', 'm1.xlarge', 'm2.xlarge', 'm2.2xlarge',
 10+ var $instanceTypes = array( 'm1.small', 'm1.large', 'm1.xlarge', 'm2.xlarge', 'm2.2xlarge',
1111 'm2.4xlarge', 'c1.medium', 'c1.xlarge', 'cc1.4xlarge' );
1212
1313 # TODO: Make disable_ssl, hostname, and resource_prefix config options
@@ -21,28 +21,23 @@
2222 $this->instances = array();
2323 }
2424
25 - function getInstance( $instanceId, $reload = false ) {
26 - if ( isset( $this->instances[$instanceId] ) && !$reload ) {
27 - $instance = $this->instances[$instanceId];
 25+ function getInstance( $instanceId ) {
 26+ $this->getInstances();
 27+ if ( isset( $this->instances["$instanceId"] ) ) {
 28+ return $this->instances["$instanceId"];
2829 } else {
29 - $response = $this->novaConnection->describe_instances( $instanceId );
30 - $instance = new OpenStackNovaInstance( $response->body->reservationSet->item, true );
31 - $instanceId = $instance->getInstanceId();
32 - $this->instances["$instanceId"] = $instance;
 30+ return null;
3331 }
34 - return $instance;
3532 }
3633
37 - function getInstances( $reload = false ) {
38 - if ( count( $this->instances ) == 0 || $reload ) {
39 - $this->instances = array();
40 - $response = $this->novaConnection->describe_instances();
41 - $instances = $response->body->reservationSet->item;
42 - foreach ( $instances as $instance ) {
43 - $instance = new OpenStackNovaInstance( $instance, true );
44 - $instanceId = $instance->getInstanceId();
45 - $this->instances["$instanceId"] = $instance;
46 - }
 34+ function getInstances() {
 35+ $this->instances = array();
 36+ $response = $this->novaConnection->describe_instances();
 37+ $instances = $response->body->reservationSet->item;
 38+ foreach ( $instances as $instance ) {
 39+ $instance = new OpenStackNovaInstance( $instance, true );
 40+ $instanceId = $instance->getInstanceId();
 41+ $this->instances["$instanceId"] = $instance;
4742 }
4843 return $this->instances;
4944 }
@@ -51,44 +46,38 @@
5247 return $this->instanceTypes;
5348 }
5449
55 - function getImages( $reload = false ) {
56 - if ( count( $this->images ) == 0 || $reload ) {
57 - $this->images = array();
58 - $images = $this->novaConnection->describe_images();
59 - $images = $images->body->imagesSet->item;
60 - foreach ( $images as $image ) {
61 - if ( $image->imageType == 'machine' ) {
62 - $this->images["$image->imageId"] = $image;
63 - }
 50+ function getImages() {
 51+ $this->images = array();
 52+ $images = $this->novaConnection->describe_images();
 53+ $images = $images->body->imagesSet->item;
 54+ foreach ( $images as $image ) {
 55+ if ( $image->imageType == 'machine' ) {
 56+ $this->images["$image->imageId"] = $image;
6457 }
6558 }
6659 return $this->images;
6760 }
6861
6962 # TODO: make this user specific
70 - function getKeypairs( $reload = false ) {
71 - if ( count( $this->keypairs ) == 0 || $reload ) {
72 - $this->keypairs = array();
73 - $response = $this->novaConnection->describe_key_pairs();
74 - $keypairs = $response->body->keypairsSet->item;
75 - foreach ( $keypairs as $keypair ) {
76 - $keypair = new OpenStackNovaKeypair( $keypair );
77 - $keyname = $keypair->getKeyName();
78 - $this->keypairs["$keyname"] = $keypair;
79 - }
 63+ function getKeypairs() {
 64+ $this->keypairs = array();
 65+ $response = $this->novaConnection->describe_key_pairs();
 66+ $keypairs = $response->body->keypairsSet->item;
 67+ foreach ( $keypairs as $keypair ) {
 68+ $keypair = new OpenStackNovaKeypair( $keypair );
 69+ $keyname = $keypair->getKeyName();
 70+ $this->keypairs["$keyname"] = $keypair;
8071 }
8172 return $this->keypairs;
8273 }
8374
84 - function getAvailabilityZones( $reload = false ) {
85 - if ( count( $this->availabilityZones ) == 0 || $reload ) {
86 - $this->availabilityZones = array();
87 - $availabilityZones = $this->novaConnection->describe_availability_zones();
88 - $availabilityZones = $availabilityZones->body->availabilityZoneInfo->item;
89 - foreach ( $availabilityZones as $availabilityZone ) {
90 - if ( $availabilityZones->zoneState == "available" ) {
91 - $this->availabilityZones["$availabilityZones->zoneName"] = $availabilityZone;
92 - }
 75+ function getAvailabilityZones() {
 76+ $this->availabilityZones = array();
 77+ $availabilityZones = $this->novaConnection->describe_availability_zones();
 78+ $availabilityZones = $availabilityZones->body->availabilityZoneInfo->item;
 79+ foreach ( $availabilityZones as $availabilityZone ) {
 80+ if ( $availabilityZones->zoneState == "available" ) {
 81+ $this->availabilityZones["$availabilityZones->zoneName"] = $availabilityZone;
9382 }
9483 }
9584 return $this->availabilityZones;
Index: trunk/extensions/OpenStackManager/OpenStackManager.php
@@ -67,6 +67,7 @@
6868 $wgAutoloadClasses['SpecialNovaProject'] = $dir . 'SpecialNovaProject.php';
6969 $wgAutoloadClasses['SpecialNovaDomain'] = $dir . 'SpecialNovaDomain.php';
7070 $wgAutoloadClasses['SpecialNova'] = $dir . 'SpecialNova.php';
 71+$wgAutoloadClasses['OpenStackNovaHostJob'] = $dir . 'OpenStackNovaHostJob.php';
7172 $wgAutoloadClasses['AmazonEC2'] = $dir . 'aws-sdk/sdk.class.php';
7273 $wgSpecialPages['NovaInstance'] = 'SpecialNovaInstance';
7374 $wgSpecialPageGroups['NovaInstance'] = 'other';
@@ -76,6 +77,7 @@
7778 $wgSpecialPageGroups['NovaProject'] = 'other';
7879 $wgSpecialPages['NovaDomain'] = 'SpecialNovaDomain';
7980 $wgSpecialPageGroups['NovaDomain'] = 'other';
 81+$wgJobClasses['addDNSHostToLDAP'] = 'OpenStackNovaHostJob';
8082
8183 $wgHooks['LDAPSetCreationValues'][] = 'OpenStackNovaUser::LDAPSetCreationValues';
8284 $wgHooks['LDAPModifyUITemplate'][] = 'OpenStackNovaUser::LDAPModifyUITemplate';

Status & tagging log