r78862 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78861‎ | r78862 | r78863 >
Date:23:38, 22 December 2010
Author:laner
Status:deferred
Tags:
Comment:
* Removing key-name as a field for instance creation
** This should be added back in as a configurable option. We don't need key injection, but others may
* Adding support for PowerDNS with an LDAP backend
** Adding a special page for creating and deleting DNS domains
** Adding a class for hosts and domains
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackManager.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaController.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaDomain.php (added) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaHost.php (added) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaProject.php (modified) (history)
  • /trunk/extensions/OpenStackManager/SpecialNovaDomain.php (added) (history)
  • /trunk/extensions/OpenStackManager/SpecialNovaInstance.php (modified) (history)
  • /trunk/extensions/OpenStackManager/SpecialNovaKey.php (modified) (history)
  • /trunk/extensions/OpenStackManager/SpecialNovaProject.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php
@@ -0,0 +1,183 @@
 2+<?php
 3+
 4+class OpenStackNovaHost {
 5+
 6+ var $hostname;
 7+ var $hostDN;
 8+ var $hostInfo;
 9+ var $domain;
 10+
 11+ function __construct( $hostname, $domain ) {
 12+ $this->hostname = $hostname;
 13+ $this->domain = $domain;
 14+ $this->connect();
 15+ $this->fetchHostInfo();
 16+ }
 17+
 18+ function connect() {
 19+ global $wgAuth;
 20+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 21+
 22+ $wgAuth->connect();
 23+ $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
 24+ }
 25+
 26+ function fetchHostInfo() {
 27+ global $wgAuth;
 28+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 29+
 30+ $result = @ldap_search( $wgAuth->ldapconn, $this->domain->domainDN, '(dc=' . $this->hostname . '))' );
 31+ $this->hostInfo = @ldap_get_entries( $wgAuth->ldapconn, $result );
 32+ $this->hostDN = $this->hostInfo[0]['dn'];
 33+ }
 34+
 35+ function getHostName() {
 36+ return $this->hostname;
 37+ }
 38+
 39+ function getARecords() {
 40+ $arecords = array();
 41+ if ( isset( $this->hostInfo[0]['arecord'] ) ) {
 42+ $arecords = $this->hostInfo[0]['arecord'];
 43+ $arecords = array_shift( $arecords );
 44+ }
 45+
 46+ return $arecords;
 47+ }
 48+
 49+ function deleteARecord( $ip ) {
 50+ global $wgAuth;
 51+
 52+ if ( isset( $this->hostInfo[0]['arecord'] ) ) {
 53+ $arecords = $this->hostInfo[0]['arecord'];
 54+ array_shift( $arecords );
 55+ $index = array_search( $ip, $arecords );
 56+ if ( $index === false ) {
 57+ $wgAuth->printDebug( "Failed to find ip address in arecords list", NONSENSITIVE );
 58+ return false;
 59+ }
 60+ unset( $arecords[$index] );
 61+ $values['arecord'] = array();
 62+ foreach ( $arecords as $arecord ) {
 63+ $values['arecord'][] = $arecord;
 64+ }
 65+ $success = @ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
 66+ if ( $success ) {
 67+ $wgAuth->printDebug( "Successfully removed $ip from $this->hostDN", NONSENSITIVE );
 68+ $this->domain->updateSOA();
 69+ return true;
 70+ } else {
 71+ $wgAuth->printDebug( "Failed to remove $ip from $this->hostDN", NONSENSITIVE );
 72+ return false;
 73+ }
 74+ } else {
 75+ return false;
 76+ }
 77+ }
 78+
 79+ function addARecord( $ip ) {
 80+ global $wgAuth;
 81+
 82+ $arecords = array();
 83+ if ( isset( $this->hostInfo[0]['arecord'] ) ) {
 84+ $arecords = $this->hostInfo[0]['arecord'];
 85+ array_shift( $arecords );
 86+ }
 87+ $arecords[] = $ip;
 88+ $values['arecord'] = $arecords;
 89+ $success = @ldap_modify( $wgAuth->ldapconn, $this->hostDN, $values );
 90+ if ( $success ) {
 91+ $wgAuth->printDebug( "Successfully added $ip to $this->hostDN", NONSENSITIVE );
 92+ $this->domain->updateSOA();
 93+ return true;
 94+ } else {
 95+ $wgAuth->printDebug( "Failed to add $ip to $this->hostDN", NONSENSITIVE );
 96+ return false;
 97+ }
 98+ }
 99+
 100+ static function getAllHosts( $domain ) {
 101+ global $wgAuth;
 102+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 103+
 104+ $wgAuth->connect();
 105+ $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
 106+
 107+ $hosts = array();
 108+ $result = @ldap_search( $wgAuth->ldapconn, $domain->domainDN, '(dc=*)' );
 109+ if ( $result ) {
 110+ $entries = @ldap_get_entries( $wgAuth->ldapconn, $result );
 111+ if ( $entries ) {
 112+ # First entry is always a count
 113+ array_shift( $entries );
 114+ foreach ( $entries as $entry ) {
 115+ $hosts[] = new OpenStackNovaHost( $entry['dc'][0], $domain );
 116+ }
 117+ }
 118+ }
 119+
 120+ return $hosts;
 121+ }
 122+
 123+ static function deleteHost( $hostname, $domain ) {
 124+ global $wgAuth;
 125+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 126+
 127+ $wgAuth->connect();
 128+ $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
 129+
 130+ $host = new OpenStackNovaHost( $hostname, $domain );
 131+ if ( ! $host ) {
 132+ return false;
 133+ }
 134+ $dn = $host->hostDN;
 135+
 136+ $success = @ldap_delete( $wgAuth->ldapconn, $dn );
 137+ if ( $success ) {
 138+ $domain->updateSOA();
 139+ return true;
 140+ } else {
 141+ return false;
 142+ }
 143+ }
 144+
 145+ static function addHost( $hostname, $ip, $domain ) {
 146+ global $wgAuth;
 147+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 148+ global $wgOpenStackManagerLDAPDNSDomainBaseDN;
 149+
 150+ $wgAuth->connect();
 151+ $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
 152+
 153+ $domainname = $domain->getFullyQualifiedDomainName();
 154+
 155+ $host = new OpenStackNovaHost( $hostname );
 156+ if ( $host ) {
 157+ return false;
 158+ }
 159+ $host = OpenStackNovaHost::getLDAPArray( $hostname, $ip, $domainname );
 160+ $dn = 'dc=' . $hostname . ',dc=' . $this->getDomainName() . ',' . $wgOpenStackManagerLDAPDNSDomainBaseDN;
 161+
 162+ $success = @ldap_add( $wgAuth->ldapconn, $dn, $host );
 163+ if ( $success ) {
 164+ $domain->updateSOA();
 165+ $wgAuth->printDebug( "Successfully added domain $domainname", NONSENSITIVE );
 166+ return true;
 167+ } else {
 168+ $wgAuth->printDebug( "Failed to add domain $domainname", NONSENSITIVE );
 169+ return false;
 170+ }
 171+ }
 172+
 173+ static function getLDAPArray( $hostname, $ip, $domain ) {
 174+ $host['objectclass'][] = 'dcobject';
 175+ $host['objectclass'][] = 'dnsdomain';
 176+ $host['objectclass'][] = 'domainrelatedobject';
 177+ $host['dc'] = $hostname;
 178+ $host['arecord'] = $ip;
 179+ $host['associateddomain'] = $hostname . '.' . $domain->getFullyQualifiedDomainName();
 180+
 181+ return $host;
 182+ }
 183+
 184+}
Property changes on: trunk/extensions/OpenStackManager/OpenStackNovaHost.php
___________________________________________________________________
Added: svn:eol-style
1185 + native
Index: trunk/extensions/OpenStackManager/SpecialNovaInstance.php
@@ -95,7 +95,7 @@
9696 # TODO: Add project name field
9797
9898 $instanceInfo = Array();
99 - $instanceInfo['instanceName'] = array(
 99+ $instanceInfo['instancename'] = array(
100100 'type' => 'text',
101101 'label-message' => 'instancename',
102102 'default' => '',
@@ -145,17 +145,17 @@
146146 # Keypair names can't be translated. Get the keys, and make an array
147147 # where the name points to itself as a value
148148 # TODO: get keypairs as the user, not the admin
149 - $keypairs = $this->userNova->getKeypairs();
150 - $keypair_keys = Array();
151 - foreach ( array_keys( $keypairs ) as $keypair_key ) {
152 - $keypair_keys["$keypair_key"] = $keypair_key;
153 - }
154 - $instanceInfo['keypair'] = array(
155 - 'type' => 'select',
156 - 'section' => 'instance/info',
157 - 'options' => $keypair_keys,
158 - 'label-message' => 'keypair',
159 - );
 149+ #$keypairs = $this->userNova->getKeypairs();
 150+ #$keypair_keys = Array();
 151+ #foreach ( array_keys( $keypairs ) as $keypair_key ) {
 152+ # $keypair_keys["$keypair_key"] = $keypair_key;
 153+ #}
 154+ #$instanceInfo['keypair'] = array(
 155+ # 'type' => 'select',
 156+ # 'section' => 'instance/info',
 157+ # 'options' => $keypair_keys,
 158+ # 'label-message' => 'keypair',
 159+ #);
160160
161161 $instanceInfo['action'] = array(
162162 'type' => 'hidden',
@@ -234,7 +234,8 @@
235235 function tryCreateSubmit( $formData, $entryPoint = 'internal' ) {
236236 global $wgOut;
237237
238 - $instance = $this->userNova->createInstance( $formData['instanceName'], $formData['imageType'], $formData['keypair'], $formData['instanceType'], $formData['availabilityZone'] );
 238+ #$instance = $this->userNova->createInstance( $formData['instancename'], $formData['imageType'], $formData['keypair'], $formData['instanceType'], $formData['availabilityZone'] );
 239+ $instance = $this->userNova->createInstance( $formData['instancename'], $formData['imageType'], '', $formData['instanceType'], $formData['availabilityZone'] );
239240
240241 $out = Html::element( 'p', array(), 'Created instance ' . $instance->getInstanceID() . ' with image ' . $instance->getImageId() );
241242 $out .= $sk->link( $this->getTitle(), 'Back to instance list', array(), array(), array() );
Index: trunk/extensions/OpenStackManager/SpecialNovaProject.php
@@ -75,7 +75,7 @@
7676 $wgOut->setPagetitle("Create Project");
7777
7878 $projectInfo = Array();
79 - $projectInfo['projectName'] = array(
 79+ $projectInfo['projectname'] = array(
8080 'type' => 'text',
8181 'label-message' => 'projectname',
8282 'default' => '',
@@ -232,7 +232,7 @@
233233 function tryCreateSubmit( $formData, $entryPoint = 'internal' ) {
234234 global $wgOut, $wgUser;
235235
236 - $success = OpenStackNovaProject::createProject( $formData['projectName'] );
 236+ $success = OpenStackNovaProject::createProject( $formData['projectname'] );
237237 if ( ! $success ) {
238238 $out = Html::element( 'p', array(), 'Failed to create project' );
239239 return false;
Index: trunk/extensions/OpenStackManager/SpecialNovaDomain.php
@@ -0,0 +1,186 @@
 2+<?php
 3+class SpecialNovaDomain extends SpecialPage {
 4+
 5+ var $userNova, $adminNova;
 6+
 7+ function __construct() {
 8+ parent::__construct( 'NovaDomain' );
 9+
 10+ global $wgOpenStackManagerNovaAdminKeys;
 11+
 12+ $this->userLDAP = new OpenStackNovaUser();
 13+ $this->adminNova = new OpenStackNovaController( $wgOpenStackManagerNovaAdminKeys );
 14+ }
 15+
 16+ public function isRestricted() {
 17+ return true;
 18+ }
 19+
 20+ function execute( $par ) {
 21+ global $wgRequest, $wgUser;
 22+
 23+ wfLoadExtensionMessages('OpenStackManager');
 24+
 25+ #if ( ! $wgUser->isAllowed( 'manageproject' ) ) {
 26+ # return false;
 27+ #}
 28+ if ( ! $wgUser->isLoggedIn() ) {
 29+ return false;
 30+ }
 31+
 32+ $action = $wgRequest->getVal('action');
 33+ if ( $action == "create" ) {
 34+ $this->createDomain();
 35+ } else if ( $action == "delete" ) {
 36+ $this->deleteDomain();
 37+ } else {
 38+ $this->listDomains();
 39+ }
 40+ }
 41+
 42+ function notLoggedIn() {
 43+ global $wgOut;
 44+
 45+ $this->setHeaders();
 46+ $wgOut->setPagetitle("Not logged in");
 47+ $wgOut->addHTML('<p>You must be logged in to perform this action</p>');
 48+ }
 49+
 50+ function noCredentials() {
 51+ global $wgOut;
 52+
 53+ $this->setHeaders();
 54+ $wgOut->setPagetitle("No Nova credentials found for your account");
 55+ $wgOut->addHTML('<p>There were no Nova credentials found for your user account. Please ask a Nova administrator to create credentials for you.</p>');
 56+ }
 57+
 58+ function createDomain() {
 59+ global $wgRequest, $wgOut;
 60+
 61+ $this->setHeaders();
 62+ $wgOut->setPagetitle("Create Domain");
 63+
 64+ $domainInfo = Array();
 65+ $domainInfo['domainname'] = array(
 66+ 'type' => 'text',
 67+ 'label-message' => 'domainname',
 68+ 'default' => '',
 69+ 'section' => 'domain/info',
 70+ );
 71+ $domainInfo['fqdn'] = array(
 72+ 'type' => 'text',
 73+ 'label-message' => 'fqdn',
 74+ 'default' => '',
 75+ 'section' => 'domain/info',
 76+ );
 77+
 78+
 79+ $domainInfo['action'] = array(
 80+ 'type' => 'hidden',
 81+ 'default' => 'create',
 82+ );
 83+
 84+ $domainForm = new SpecialNovaDomainForm( $domainInfo, 'novadomainform' );
 85+ $domainForm->setTitle( SpecialPage::getTitleFor( 'NovaDomain' ) );
 86+ $domainForm->setSubmitID( 'novadomain-form-createdomainsubmit' );
 87+ $domainForm->setSubmitCallback( array( $this, 'tryCreateSubmit' ) );
 88+ $domainForm->show();
 89+
 90+ return true;
 91+ }
 92+
 93+ function deleteDomain() {
 94+ global $wgOut, $wgRequest;
 95+
 96+ $this->setHeaders();
 97+ $wgOut->setPagetitle("Delete domain");
 98+
 99+ $domainname = $wgRequest->getText('domainname');
 100+ if ( ! $wgRequest->wasPosted() ) {
 101+ $out = Html::element( 'p', array(), 'Are you sure you wish to delete domain "' . $domainname . '"? This action has reprecusions on all VMs. Do not take this action lightly!' );
 102+ $wgOut->addHTML( $out );
 103+ }
 104+ $domainInfo = Array();
 105+ $domainInfo['domainname'] = array(
 106+ 'type' => 'hidden',
 107+ 'default' => $domainname,
 108+ );
 109+ $domainInfo['action'] = array(
 110+ 'type' => 'hidden',
 111+ 'default' => 'delete',
 112+ );
 113+ $domainForm = new SpecialNovaDomainForm( $domainInfo, 'novadomain-form' );
 114+ $domainForm->setTitle( SpecialPage::getTitleFor( 'NovaDomain' ));
 115+ $domainForm->setSubmitID( 'novadomain-form-deletedomainsubmit' );
 116+ $domainForm->setSubmitCallback( array( $this, 'tryDeleteSubmit' ) );
 117+ $domainForm->setSubmitText( 'confirm' );
 118+ $domainForm->show();
 119+
 120+ return true;
 121+ }
 122+
 123+ function listDomains() {
 124+ global $wgOut, $wgUser;
 125+
 126+ $this->setHeaders();
 127+ $wgOut->setPagetitle("Domain list");
 128+
 129+ $out = '';
 130+ $sk = $wgUser->getSkin();
 131+ $out .= $sk->link( $this->getTitle(), 'Create a new domain', array(), array( 'action' => 'create' ), array() );
 132+ $domainsOut = Html::element( 'th', array(), 'Domain name' );
 133+ $domainsOut .= Html::element( 'th', array(), 'FQDN' );
 134+ $domainsOut .= Html::element( 'th', array(), 'Action' );
 135+ $domains = OpenStackNovaDomain::getAllDomains();
 136+ foreach ( $domains as $domain ) {
 137+ $domainName = $domain->getDomainName();
 138+ $fqdn = $domain->getFullyQualifiedDomainName();
 139+ $domainOut = Html::element( 'td', array(), $domainName );
 140+ $domainOut .= Html::element( 'td', array(), $fqdn );
 141+ $link = $sk->link( $this->getTitle(), 'delete domain', array(), array( 'action' => 'delete', 'domainname' => $domainName ), array() );
 142+ $domainOut .= Html::rawElement( 'td', array(), $link );
 143+ $domainsOut .= Html::rawElement( 'tr', array(), $domainOut );
 144+ }
 145+ $out .= Html::rawElement( 'table', array( 'class' => 'wikitable' ), $domainsOut );
 146+
 147+ $wgOut->addHTML( $out );
 148+ }
 149+
 150+ function tryCreateSubmit( $formData, $entryPoint = 'internal' ) {
 151+ global $wgOut, $wgUser;
 152+
 153+ $success = OpenStackNovaDomain::createDomain( $formData['domainname'], $formData['fqdn'] );
 154+ if ( ! $success ) {
 155+ $out = Html::element( 'p', array(), 'Failed to create domain' );
 156+ return false;
 157+ }
 158+ $out = Html::element( 'p', array(), 'Created domain' );
 159+ $out .= '<br />';
 160+ $sk = $wgUser->getSkin();
 161+ $out .= $sk->link( $this->getTitle(), 'Back to domain list', array(), array(), array() );
 162+ $wgOut->addHTML( $out );
 163+
 164+ return true;
 165+ }
 166+
 167+ function tryDeleteSubmit( $formData, $entryPoint = 'internal' ) {
 168+ global $wgOut, $wgUser;
 169+
 170+ $success = OpenStackNovaDomain::deleteDomain( $formData['domainname'] );
 171+ if ( $success ) {
 172+ $out = Html::element( 'p', array(), 'Successfully deleted domain' );
 173+ } else {
 174+ $out = Html::element( 'p', array(), 'Failed to delete domain' );
 175+ }
 176+ $out .= '<br />';
 177+ $sk = $wgUser->getSkin();
 178+ $out .= $sk->link( $this->getTitle(), 'Back to domain list', array(), array(), array() );
 179+ $wgOut->addHTML( $out );
 180+
 181+ return true;
 182+ }
 183+
 184+}
 185+
 186+class SpecialNovaDomainForm extends HTMLForm {
 187+}
Property changes on: trunk/extensions/OpenStackManager/SpecialNovaDomain.php
___________________________________________________________________
Added: svn:eol-style
1188 + native
Index: trunk/extensions/OpenStackManager/SpecialNovaKey.php
@@ -80,7 +80,7 @@
8181 $keyInfo = Array();
8282
8383 if ( $wgOpenStackManagerNovaKeypairStorage == 'nova' ) {
84 - $keyInfo['keyName'] = array(
 84+ $keyInfo['keyname'] = array(
8585 'type' => 'text',
8686 'label-message' => 'keyname',
8787 'default' => '',
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php
@@ -96,13 +96,14 @@
9797 function createInstance( $instanceName, $image, $key, $instanceType, $availabilityZone ) {
9898 # 1, 1 is min and max number of instances to create.
9999 # We never want to make more than one at a time.
100 - $response = $this->novaConnection->run_instances($image, 1, 1, array(
101 - 'KeyName' => $key,
102 - 'InstanceType' => $instanceType,
103 - 'Placement.AvailabilityZone' => $availabilityZone,
104 - 'DisplayName' => $instanceName,
105 - ));
106 -
 100+ $options = array();
 101+ if ( $key ) {
 102+ $options['KeyName'] = $key;
 103+ }
 104+ $options['InstanceType'] = $instanceType;
 105+ $options['Placement.AvailabilityZone'] = $availabilityZone;
 106+ $options['DisplayName'] = $instanceName;
 107+ $response = $this->novaConnection->run_instances( $image, 1, 1, $options );
107108 $instance = new OpenStackNovaInstance( $response->body->reservationSet->item );
108109 $instanceId = $instance->getInstanceId();
109110 $this->instances["$instanceId"] = $instance;
Index: trunk/extensions/OpenStackManager/OpenStackManager.php
@@ -44,9 +44,12 @@
4545 $wgAutoloadClasses['OpenStackNovaKeypair'] = $dir . 'OpenStackNovaKeypair.php';
4646 $wgAutoloadClasses['OpenStackNovaController'] = $dir . 'OpenStackNovaController.php';
4747 $wgAutoloadClasses['OpenStackNovaUser'] = $dir . 'OpenStackNovaUser.php';
 48+$wgAutoloadClasses['OpenStackNovaDomain'] = $dir . 'OpenStackNovaDomain.php';
 49+$wgAutoloadClasses['OpenStackNovaHost'] = $dir . 'OpenStackNovaHost.php';
4850 $wgAutoloadClasses['SpecialNovaInstance'] = $dir . 'SpecialNovaInstance.php';
4951 $wgAutoloadClasses['SpecialNovaKey'] = $dir . 'SpecialNovaKey.php';
5052 $wgAutoloadClasses['SpecialNovaProject'] = $dir . 'SpecialNovaProject.php';
 53+$wgAutoloadClasses['SpecialNovaDomain'] = $dir . 'SpecialNovaDomain.php';
5154 $wgAutoloadClasses['AmazonEC2'] = $dir . 'aws-sdk/sdk.class.php';
5255 $wgSpecialPages['NovaInstance'] = 'SpecialNovaInstance';
5356 $wgSpecialPageGroups['NovaInstance'] = 'other';
@@ -54,6 +57,8 @@
5558 $wgSpecialPageGroups['NovaKey'] = 'other';
5659 $wgSpecialPages['NovaProject'] = 'SpecialNovaProject';
5760 $wgSpecialPageGroups['NovaProject'] = 'other';
 61+$wgSpecialPages['NovaDomain'] = 'SpecialNovaDomain';
 62+$wgSpecialPageGroups['NovaDomain'] = 'other';
5863
5964 $wgHooks['LDAPSetCreationValues'][] = 'OpenStackNovaUser::LDAPSetCreationValues';
6065
Index: trunk/extensions/OpenStackManager/OpenStackNovaProject.php
@@ -174,15 +174,13 @@
175175 }
176176 $dn = $project->projectDN;
177177
178 - # Projects can have roles as sub entries, delete them first
 178+ # Projects can have roles as sub entries, fail if they exist
 179+ # It is a bad idea to rely on LDAP failure here, as some directories
 180+ # may simply delete sub entries.
179181 $result = ldap_list( $wgAuth->ldapconn, $dn, 'objectclass=*' );
180182 $roles = ldap_get_entries( $wgAuth->ldapconn, $result );
181 - array_shift( $roles );
182 - foreach ( $roles as $role ) {
183 - $success = @ldap_delete( $wgAuth->ldapconn, $role[0]['dn'] );
184 - if ( ! $success ) {
185 - return false;
186 - }
 183+ if ( $roles['count'] != "0" ) {
 184+ return false;
187185 }
188186 $success = @ldap_delete( $wgAuth->ldapconn, $dn );
189187 if ( $success ) {
Index: trunk/extensions/OpenStackManager/OpenStackNovaDomain.php
@@ -0,0 +1,166 @@
 2+<?php
 3+
 4+class OpenStackNovaDomain {
 5+
 6+ var $domainname;
 7+ var $domainDN;
 8+ var $domainInfo;
 9+ var $fqdn;
 10+
 11+ function __construct( $domainname ) {
 12+ $this->domainname = $domainname;
 13+ $this->connect();
 14+ $this->fetchDomainInfo();
 15+ }
 16+
 17+ function connect() {
 18+ global $wgAuth;
 19+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 20+
 21+ $wgAuth->connect();
 22+ $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
 23+ }
 24+
 25+ function fetchDomainInfo() {
 26+ global $wgAuth;
 27+ global $wgOpenStackManagerLDAPDNSDomainBaseDN;
 28+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 29+
 30+ $result = @ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPDNSDomainBaseDN, '(dc=' . $this->domainname . ')' );
 31+ $this->domainInfo = @ldap_get_entries( $wgAuth->ldapconn, $result );
 32+ $this->fqdn = $this->domainInfo[0]['associateddomain'][0];
 33+ $this->domainDN = $this->domainInfo[0]['dn'];
 34+ }
 35+
 36+ function getDomainName() {
 37+ return $this->domainname;
 38+ }
 39+
 40+ function getFullyQualifiedDomainName() {
 41+ return $this->fqdn;
 42+ }
 43+
 44+ function getHosts() {
 45+ global $wgAuth;
 46+
 47+ # Domains can have records as sub entries. If sub-entries exist, fail.
 48+ $result = ldap_list( $wgAuth->ldapconn, $this->domainDN, 'objectclass=*' );
 49+ $hostsLDAP = ldap_get_entries( $wgAuth->ldapconn, $result );
 50+ array_shift( $hostsLDAP );
 51+ foreach ( $hostsLDAP as $hostLDAP ) {
 52+ $hosts[] = new OpenStackNovaHost( $hostLDAP[0]['dc'] );
 53+ }
 54+
 55+ return $hosts;
 56+ }
 57+
 58+ function updateSOA() {
 59+ global $wgAuth;
 60+
 61+ $domain['soarecord'] = $OpenStackNovaDomain::generateSOA();
 62+ $success = @ldap_modify( $wgAuth->ldapconn, $this->domainDN, $domain );
 63+ if ( $success ) {
 64+ $wgAuth->printDebug( "Successfully modified soarecord for " . $this->domainDN, NONSENSITIVE );
 65+ return true;
 66+ } else {
 67+ $wgAuth->printDebug( "Failed to modify soarecord for " . $this->domainDN, NONSENSITIVE );
 68+ return false;
 69+ }
 70+ }
 71+
 72+ static function getAllDomains() {
 73+ global $wgAuth;
 74+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 75+ global $wgOpenStackManagerLDAPDNSDomainBaseDN;
 76+
 77+ $wgAuth->connect();
 78+ $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
 79+
 80+ $domains = array();
 81+ $result = @ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPDNSDomainBaseDN, '(soarecord=*)' );
 82+ if ( $result ) {
 83+ $entries = @ldap_get_entries( $wgAuth->ldapconn, $result );
 84+ if ( $entries ) {
 85+ # First entry is always a count
 86+ array_shift( $entries );
 87+ foreach ( $entries as $entry ) {
 88+ $domain = new OpenStackNovaDomain( $entry['dc'][0] );
 89+ array_push( $domains, $domain );
 90+ }
 91+ }
 92+ }
 93+
 94+ return $domains;
 95+ }
 96+
 97+ # TODO: Allow generic domains; get rid of config set base name
 98+ static function createDomain( $domainname, $fqdn ) {
 99+ global $wgAuth;
 100+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 101+ global $wgOpenStackManagerLDAPDNSDomainBaseDN, $wgOpenStackManagerLDAPDNSDomainBaseName;
 102+ global $wgOpenStackManagerDNSServers;
 103+
 104+ $wgAuth->connect();
 105+ $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
 106+
 107+ $soa = OpenStackNovaDomain::generateSOA();
 108+ $domain['objectclass'][] = 'dcobject';
 109+ $domain['objectclass'][] = 'dnsdomain';
 110+ $domain['objectclass'][] = 'domainrelatedobject';
 111+ $domain['dc'] = $domainname;
 112+ $domain['soarecord'] = $wgOpenStackManagerDNSServers['primary'] . ' ' . $soa;
 113+ $domain['associateddomain'] = $fqdn;
 114+ $dn = 'dc=' . $domainname . ',' . $wgOpenStackManagerLDAPDNSDomainBaseDN;
 115+
 116+ $success = @ldap_add( $wgAuth->ldapconn, $dn, $domain );
 117+ if ( $success ) {
 118+ $wgAuth->printDebug( "Successfully added domain $domainname", NONSENSITIVE );
 119+ return true;
 120+ } else {
 121+ $wgAuth->printDebug( "Failed to add domain $domainname", NONSENSITIVE );
 122+ return false;
 123+ }
 124+ }
 125+
 126+ static function deleteDomain( $domainname ) {
 127+ global $wgAuth;
 128+ global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword;
 129+
 130+ $wgAuth->connect();
 131+ $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword );
 132+
 133+ $domain = new OpenStackNovaDomain( $domainname );
 134+ if ( ! $domain ) {
 135+ $wgAuth->printDebug( "Domain $domainname does not exist", NONSENSITIVE );
 136+ return false;
 137+ }
 138+ $dn = $domain->domainDN;
 139+
 140+ # Domains can have records as sub entries. If sub-entries exist, fail.
 141+ $result = ldap_list( $wgAuth->ldapconn, $dn, 'objectclass=*' );
 142+ $hosts = ldap_get_entries( $wgAuth->ldapconn, $result );
 143+ if ( $hosts['count'] != "0" ) {
 144+ $wgAuth->printDebug( "Failed to delete domain $domainname, since it had sub entries", NONSENSITIVE );
 145+ return false;
 146+ }
 147+ $success = @ldap_delete( $wgAuth->ldapconn, $dn );
 148+ if ( $success ) {
 149+ $wgAuth->printDebug( "Successfully deleted domain $domainname", NONSENSITIVE );
 150+ return true;
 151+ } else {
 152+ $wgAuth->printDebug( "Failed to delete domain $domainname, since it had sub entries", NONSENSITIVE );
 153+ return false;
 154+ }
 155+ }
 156+
 157+ static function generateSOA() {
 158+ global $wgOpenStackManagerDNSSOA;
 159+
 160+ $serial = date( 'YmdHis' );
 161+ $soa = $wgOpenStackManagerDNSSOA['hostmaster'] . ' ' . $serial . ' ' . $wgOpenStackManagerDNSSOA['refresh'] . ' ' . $wgOpenStackManagerDNSSOA['retry'] . '
 162+' . $wgOpenStackManagerDNSSOA['expiry'] . ' ' . $wgOpenStackManagerDNSSOA['minimum'];
 163+
 164+ return $soa;
 165+ }
 166+
 167+}
Property changes on: trunk/extensions/OpenStackManager/OpenStackNovaDomain.php
___________________________________________________________________
Added: svn:eol-style
1168 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r92647MFT r75956 - r92645 for LandingCheck.i18n.ph, r78862 - r92646 for SpecialLand...awjrichards17:54, 20 July 2011

Status & tagging log