r79137 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79136‎ | r79137 | r79138 >
Date:22:25, 28 December 2010
Author:laner
Status:deferred (Comments)
Tags:
Comment:
* Adding puppet support for instance creation
* Fixing domain and host lookup by instanceid
* Other minor bug fixes
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackNovaDomain.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaHost.php (modified) (history)
  • /trunk/extensions/OpenStackManager/SpecialNovaInstance.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/SpecialNovaInstance.php
@@ -61,6 +61,7 @@
6262
6363 function createInstance() {
6464 global $wgRequest, $wgOut;
 65+ global $wgOpenStackManagerPuppetOptions;
6566
6667 $this->setHeaders();
6768 $wgOut->setPagetitle("Create Instance");
@@ -146,6 +147,29 @@
147148 'default' => $wgRequest->getText( 'project' ),
148149 );
149150
 151+ if ( isset( $wgOpenStackManagerPuppetOptions['availableclasses'] ) ) {
 152+ $classes = array();
 153+ foreach ( $wgOpenStackManagerPuppetOptions['availableclasses'] as $class ) {
 154+ $classes["$class"] = $class;
 155+ }
 156+ $instanceInfo['puppetclasses'] = array(
 157+ 'type' => 'multiselect',
 158+ 'section' => 'instance/puppetinfo',
 159+ 'options' => $classes,
 160+ 'label-message' => 'puppetclasses',
 161+ );
 162+ }
 163+
 164+ if ( isset( $wgOpenStackManagerPuppetOptions['availablevariables'] ) ) {
 165+ foreach ( $wgOpenStackManagerPuppetOptions['availablevariables'] as $variable ) {
 166+ $instanceInfo["$variable"] = array(
 167+ 'type' => 'text',
 168+ 'section' => 'instance/puppetinfo',
 169+ 'label' => $variable,
 170+ );
 171+ }
 172+ }
 173+
150174 $instanceInfo['action'] = array(
151175 'type' => 'hidden',
152176 'default' => 'create',
@@ -264,6 +288,7 @@
265289
266290 function tryCreateSubmit( $formData, $entryPoint = 'internal' ) {
267291 global $wgOut, $wgUser;
 292+ global $wgOpenStackManagerPuppetOptions;
268293
269294 $sk = $wgUser->getSkin();
270295 $domain = OpenStackNovaDomain::getDomainByName( $formData['domain'] );
@@ -272,7 +297,22 @@
273298 }
274299 $instance = $this->userNova->createInstance( $formData['instancename'], $formData['imageType'], '', $formData['instanceType'], $formData['availabilityZone'] );
275300 if ( $instance ) {
276 - $host = OpenStackNovaHost::addHost( $instance, $domain );
 301+ $puppetinfo = array();
 302+ if ( isset( $wgOpenStackManagerPuppetOptions['availableclasses'] ) ) {
 303+ foreach ( $formData['puppetclasses'] as $class ) {
 304+ if ( in_array( $class, $wgOpenStackManagerPuppetOptions['availableclasses'] ) ) {
 305+ $puppetinfo['classes'][] = $class;
 306+ }
 307+ }
 308+ }
 309+ if ( isset( $wgOpenStackManagerPuppetOptions['availablevariables'] ) ) {
 310+ foreach ( $wgOpenStackManagerPuppetOptions['availablevariables'] as $variable ) {
 311+ if ( isset ( $formData["$variable"] ) ) {
 312+ $puppetinfo['variables']["$variable"] = $formData["$variable"];
 313+ }
 314+ }
 315+ }
 316+ $host = OpenStackNovaHost::addHost( $instance, $domain, $puppetinfo );
277317 if ( $host ) {
278318 $out = Html::element( 'p', array(), 'Created instance ' . $instance->getInstanceID() . ' with image ' . $instance->getImageId() . ' and hostname ' . $host->getFullyQualifiedHostName() . ' and ip ' . $instance->getInstancePrivateIP() );
279319 } else {
Index: trunk/extensions/OpenStackManager/OpenStackNovaDomain.php
@@ -132,7 +132,7 @@
133133
134134 wfSuppressWarnings();
135135 $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN,
136 - '(cnamerecord=' . $instanceid . ')' );
 136+ '(cnamerecord=' . $instanceid . '.*)' );
137137 $hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
138138 wfRestoreWarnings();
139139 $fqdn = $hostInfo[0]['associateddomain'][0];
Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php
@@ -26,8 +26,9 @@
2727 global $wgAuth;
2828 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
2929
 30+ $hostname = $this->searchvalue . '.' . $this->domain->getFullyQualifiedDomainName();
3031 wfSuppressWarnings();
31 - $result = ldap_search( $wgAuth->ldapconn, $this->domain->domainDN, '(|(associateddomain=' . $this->searchvalue . ')(cnamerecord=' . $this->searchvalue . '))' );
 32+ $result = ldap_search( $wgAuth->ldapconn, $this->domain->domainDN, '(|(associateddomain=' . $hostname . ')(cnamerecord=' . $hostname . '))' );
3233 $this->hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
3334 wfRestoreWarnings();
3435 if ( $this->hostInfo["count"] == "0" ) {
@@ -201,7 +202,7 @@
202203
203204 $host = OpenStackNovaHost::getHostByInstanceId( $instanceid );
204205 if ( ! $host ) {
205 - $wgAuth->printDebug( "Failed to delete host $hostname as the DNS entry does not exist", NONSENSITIVE );
 206+ $wgAuth->printDebug( "Failed to delete host $instanceid as the DNS entry does not exist", NONSENSITIVE );
206207 return false;
207208 }
208209 $dn = $host->hostDN;
@@ -212,13 +213,14 @@
213214 wfRestoreWarnings();
214215 if ( $success ) {
215216 $domain->updateSOA();
216 - $wgAuth->printDebug( "Successfully deleted host $hostname", NONSENSITIVE );
 217+ $wgAuth->printDebug( "Successfully deleted host $instanceid", NONSENSITIVE );
217218 return true;
218219 } else {
219 - $wgAuth->printDebug( "Failed to delete host $hostname", NONSENSITIVE );
 220+ $wgAuth->printDebug( "Failed to delete host $instanceid", NONSENSITIVE );
220221 return false;
221222 }
222223 }
 224+
223225 /**
224226 * @static
225227 * @param $hostname
@@ -254,17 +256,25 @@
255257 $hostEntry['associateddomain'][] = $hostname . '.' . $domainname;
256258 $hostEntry['cnamerecord'][] = $instanceid . '.' . $domainname;
257259 if ( $wgOpenStackManagerPuppetOptions ) {
258 - $hostEntry['objectclass'][] = 'puppetClient';
259 - if ( isset( $wgOpenStackManagerPuppetOptions['requiredclasses'] ) ) {
260 - foreach ( $wgOpenStackManagerPuppetOptions['requiredclasses'] as $class ) {
 260+ $hostEntry['objectclass'][] = 'puppetclient';
 261+ if ( isset( $wgOpenStackManagerPuppetOptions['defaultclasses'] ) ) {
 262+ foreach ( $wgOpenStackManagerPuppetOptions['defaultclasses'] as $class ) {
261263 $hostEntry['puppetclass'][] = $class;
262264 }
263265 }
264 - if ( isset( $wgOpenStackManagerPuppetOptions['requiredvariables'] ) ) {
265 - foreach ( $wgOpenStackManagerPuppetOptions['requiredvariables'] as $variable ) {
266 - $hostEntry['puppetvariable'][] = $variable;
 266+ if ( isset( $wgOpenStackManagerPuppetOptions['defaultvariables'] ) ) {
 267+ foreach ( $wgOpenStackManagerPuppetOptions['defaultvariables'] as $variable => $value ) {
 268+ $hostEntry['puppetvar'][] = $variable . ' = ' . $value;
267269 }
268270 }
 271+ if ( $puppetinfo ) {
 272+ foreach( $puppetinfo['classes'] as $class ) {
 273+ $hostEntry['puppetclass'][] = $class;
 274+ }
 275+ foreach( $puppetinfo['variables'] as $variable => $value ) {
 276+ $hostEntry['puppetvar'][] = $variable . ' = ' . $value;
 277+ }
 278+ }
269279 }
270280 $dn = 'dc=' . $hostname . ',dc=' . $domain->getDomainName() . ',' . $wgOpenStackManagerLDAPInstanceBaseDN;
271281

Comments

#Comment by Reedy (talk | contribs)   01:30, 30 December 2010

Don't you need to declare a default value for wgOpenStackManagerPuppetOptions?

#Comment by Catrope (talk | contribs)   08:56, 30 December 2010

Yes he does, register_globals and all. Marking fixme.

#Comment by Ryan lane (talk | contribs)   17:27, 30 December 2010

Fixed r79269.

Status & tagging log