r79092 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79091‎ | r79092 | r79093 >
Date:00:43, 28 December 2010
Author:laner
Status:deferred
Tags:
Comment:
Refactoring, some minor bug fixes, and very initial support for puppet.
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackNovaController.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaDomain.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaHost.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaInstance.php (modified) (history)
  • /trunk/extensions/OpenStackManager/SpecialNovaInstance.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/SpecialNovaInstance.php
@@ -266,7 +266,6 @@
267267 global $wgOut, $wgUser;
268268
269269 $sk = $wgUser->getSkin();
270 - $domain = new OpenStackNovaDomain( $formData['domain'] );
271270 $domain = OpenStackNovaDomain::getDomainByName( $formData['domain'] );
272271 if ( ! $domain ) {
273272 $out = Html::element( 'p', array(), 'Requested domain is invalid' );
@@ -295,15 +294,15 @@
296295
297296 $instance = $this->adminNova->getInstance( $formData['instanceid'] );
298297 $instancename = $instance->getInstanceName();
 298+ $instanceid = $instance->getInstanceId();
299299 $success = $this->userNova->terminateInstance( $formData['instanceid'] );
300300 $sk = $wgUser->getSkin();
301301 if ( $success ) {
302 - $domain = OpenStackNovaDomain::getDomainByHostIP( $instance->getInstancePrivateIP() );
303 - $success = OpenStackNovaHost::deleteHost( $instancename, $domain );
 302+ $success = OpenStackNovaHost::deleteHostByInstanceId( $instanceid );
304303 if ( $success ) {
305304 $out = Html::element( 'p', array(), "Deleted instance $instancename" );
306305 } else {
307 - $out = Html::element( 'p', array(), "Successfully deleted instance, but failed to remove $instancename entry from LDAP" );
 306+ $out = Html::element( 'p', array(), "Successfully deleted instance, but failed to remove $instancename DNS entry" );
308307 }
309308 } else {
310309 $out = Html::element( 'p', array(), 'Failed to create instance' );
Index: trunk/extensions/OpenStackManager/OpenStackNovaInstance.php
@@ -4,11 +4,25 @@
55 class OpenStackNovaInstance {
66
77 var $instance;
 8+ var $host;
89
9 - function __construct( $apiInstanceResponse ) {
 10+ function __construct( $apiInstanceResponse, $loadhost=false ) {
1011 $this->instance = $apiInstanceResponse;
 12+ if ( $loadhost ) {
 13+ $this->host = OpenStackNovaHost::getHostByInstanceId( $this->getInstanceId() );
 14+ } else {
 15+ $this->host = null;
 16+ }
1117 }
1218
 19+ function setHost( $host ) {
 20+ $this->host = $host;
 21+ }
 22+
 23+ function getHost() {
 24+ return $this->host;
 25+ }
 26+
1327 function getReservationId() {
1428 return $this->instance->reservationId;
1529 }
@@ -51,4 +65,14 @@
5266 return $this->instance->ownerId;
5367 }
5468
 69+ function getAvailabilityZone() {
 70+ # NOTE: This is non-existant in openstack for now
 71+ return $this->instance->instancesSet->item->availabilityZone;
 72+ }
 73+
 74+ function getRegion() {
 75+ # NOTE: This is non-existant in openstack for now
 76+ return $this->instance->instancesSet->item->region;
 77+ }
 78+
5579 }
Index: trunk/extensions/OpenStackManager/OpenStackNovaDomain.php
@@ -26,6 +26,7 @@
2727 global $wgOpenStackManagerLDAPInstanceBaseDN;
2828 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
2929
 30+ # TODO: memcache this
3031 wfSuppressWarnings();
3132 $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN,
3233 '(dc=' . $this->domainname . ')' );
@@ -121,6 +122,30 @@
122123 }
123124 }
124125
 126+ static function getDomainByInstanceId( $instanceid ) {
 127+ global $wgAuth;
 128+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 129+ global $wgOpenStackManagerLDAPInstanceBaseDN;
 130+
 131+ $wgAuth->connect();
 132+ $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
 133+
 134+ wfSuppressWarnings();
 135+ $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN,
 136+ '(cnamerecord=' . $instanceid . ')' );
 137+ $hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
 138+ wfRestoreWarnings();
 139+ $fqdn = $hostInfo[0]['associateddomain'][0];
 140+ $domainname = explode( '.', $fqdn );
 141+ $domainname = $domainname[1];
 142+ $domain = new OpenStackNovaDomain( $domainname );
 143+ if ( $domain->domainInfo ) {
 144+ return $domain;
 145+ } else {
 146+ return null;
 147+ }
 148+ }
 149+
125150 # TODO: Allow generic domains; get rid of config set base name
126151 static function createDomain( $domainname, $fqdn ) {
127152 global $wgAuth;
Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php
@@ -2,13 +2,13 @@
33
44 class OpenStackNovaHost {
55
6 - var $hostname;
 6+ var $searchvalue;
77 var $hostDN;
88 var $hostInfo;
99 var $domain;
1010
1111 function __construct( $hostname, $domain ) {
12 - $this->hostname = $hostname;
 12+ $this->searchvalue = $hostname;
1313 $this->domain = $domain;
1414 $this->connect();
1515 $this->fetchHostInfo();
@@ -27,7 +27,7 @@
2828 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
2929
3030 wfSuppressWarnings();
31 - $result = ldap_search( $wgAuth->ldapconn, $this->domain->domainDN, '(dc=' . $this->hostname . ')' );
 31+ $result = ldap_search( $wgAuth->ldapconn, $this->domain->domainDN, '(|(associateddomain=' . $this->searchvalue . ')(cnamerecord=' . $this->searchvalue . '))' );
3232 $this->hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result );
3333 wfRestoreWarnings();
3434 if ( $this->hostInfo["count"] == "0" ) {
@@ -38,11 +38,15 @@
3939 }
4040
4141 function getHostName() {
42 - return $this->hostname;
 42+ return $this->hostInfo[0]['associateddomain'][0];
4343 }
4444
 45+ function getDomain() {
 46+ return $this->domain;
 47+ }
 48+
4549 function getFullyQualifiedHostName() {
46 - return $this->hostname . '.' . $this->domain->getFullyQualifiedDomainName();
 50+ return $this->getHostName() . '.' . $this->domain->getFullyQualifiedDomainName();
4751 }
4852
4953 function getARecords() {
@@ -55,6 +59,16 @@
5660 return $arecords;
5761 }
5862
 63+ function getCNAMERecords() {
 64+ $cnamerecords = array();
 65+ if ( isset( $this->hostInfo[0]['cnamerecord'] ) ) {
 66+ $cnamerecords = $this->hostInfo[0]['cnamearecord'];
 67+ $cnamerecords = array_shift( $cnamerecords );
 68+ }
 69+
 70+ return $cnamerecords;
 71+ }
 72+
5973 function deleteARecord( $ip ) {
6074 global $wgAuth;
6175
@@ -119,6 +133,11 @@
120134 }
121135 }
122136
 137+ static function getHostByInstanceId( $instanceid ) {
 138+ $domain = OpenStackNovaDomain::getDomainByInstanceId( $instanceid );
 139+ return self::getHostByName( $instanceid, $domain );
 140+ }
 141+
123142 static function getAllHosts( $domain ) {
124143 global $wgAuth;
125144 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
@@ -173,22 +192,51 @@
174193 }
175194 }
176195
 196+ static function deleteHostByInstanceId( $instanceid ) {
 197+ global $wgAuth;
 198+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 199+
 200+ $wgAuth->connect();
 201+ $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
 202+
 203+ $host = OpenStackNovaHost::getHostByInstanceId( $instanceid );
 204+ if ( ! $host ) {
 205+ $wgAuth->printDebug( "Failed to delete host $hostname as the DNS entry does not exist", NONSENSITIVE );
 206+ return false;
 207+ }
 208+ $dn = $host->hostDN;
 209+ $domain = $host->getDomain();
 210+
 211+ wfSuppressWarnings();
 212+ $success = ldap_delete( $wgAuth->ldapconn, $dn );
 213+ wfRestoreWarnings();
 214+ if ( $success ) {
 215+ $domain->updateSOA();
 216+ $wgAuth->printDebug( "Successfully deleted host $hostname", NONSENSITIVE );
 217+ return true;
 218+ } else {
 219+ $wgAuth->printDebug( "Failed to delete host $hostname", NONSENSITIVE );
 220+ return false;
 221+ }
 222+ }
177223 /**
178224 * @static
179225 * @param $hostname
180226 * @param $ip
181227 * @param $domain OpenStackNovaDomain
 228+ * @param $puppetinfo
182229 * @return bool
183230 */
184 - static function addHost( $instance, $domain ) {
 231+ static function addHost( $instance, $domain, $puppetinfo=array() ) {
185232 global $wgAuth;
186233 global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
187 - global $wgOpenStackManagerLDAPInstanceBaseDN;
 234+ global $wgOpenStackManagerLDAPInstanceBaseDN, $wgOpenStackManagerPuppetOptions;
188235
189236 $wgAuth->connect();
190237 $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
191238
192239 $hostname = $instance->getInstanceName();
 240+ $instanceid = $instance->getInstanceId();
193241 $ip = $instance->getInstancePrivateIP();
194242 $domainname = $domain->getFullyQualifiedDomainName();
195243 $host = OpenStackNovaHost::getHostByName( $hostname, $domain );
@@ -201,8 +249,23 @@
202250 $hostEntry['objectclass'][] = 'dnsdomain';
203251 $hostEntry['objectclass'][] = 'domainrelatedobject';
204252 $hostEntry['dc'] = $hostname;
 253+ #$hostEntry['l'] = $instance->getInstanceAvailabilityZone();
205254 $hostEntry['arecord'] = $ip;
206 - $hostEntry['associateddomain'] = $hostname . '.' . $domainname;
 255+ $hostEntry['associateddomain'][] = $hostname . '.' . $domainname;
 256+ $hostEntry['cnamerecord'][] = $instanceid . '.' . $domainname;
 257+ if ( $wgOpenStackManagerPuppetOptions ) {
 258+ $hostEntry['objectclass'][] = 'puppetClient';
 259+ if ( isset( $wgOpenStackManagerPuppetOptions['requiredclasses'] ) ) {
 260+ foreach ( $wgOpenStackManagerPuppetOptions['requiredclasses'] as $class ) {
 261+ $hostEntry['puppetclass'][] = $class;
 262+ }
 263+ }
 264+ if ( isset( $wgOpenStackManagerPuppetOptions['requiredvariables'] ) ) {
 265+ foreach ( $wgOpenStackManagerPuppetOptions['requiredvariables'] as $variable ) {
 266+ $hostEntry['puppetvariable'][] = $variable;
 267+ }
 268+ }
 269+ }
207270 $dn = 'dc=' . $hostname . ',dc=' . $domain->getDomainName() . ',' . $wgOpenStackManagerLDAPInstanceBaseDN;
208271
209272 wfSuppressWarnings();
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php
@@ -26,7 +26,7 @@
2727 $instance = $this->instances[$instanceId];
2828 } else {
2929 $response = $this->novaConnection->describe_instances( $instanceId );
30 - $instance = new OpenStackNovaInstance( $response->body->reservationSet->item );
 30+ $instance = new OpenStackNovaInstance( $response->body->reservationSet->item, true );
3131 $instanceId = $instance->getInstanceId();
3232 $this->instances["$instanceId"] = $instance;
3333 }
@@ -39,7 +39,7 @@
4040 $response = $this->novaConnection->describe_instances();
4141 $instances = $response->body->reservationSet->item;
4242 foreach ( $instances as $instance ) {
43 - $instance = new OpenStackNovaInstance( $instance );
 43+ $instance = new OpenStackNovaInstance( $instance, true );
4444 $instanceId = $instance->getInstanceId();
4545 $this->instances["$instanceId"] = $instance;
4646 }

Status & tagging log