Index: trunk/extensions/OpenStackManager/SpecialNovaInstance.php |
— | — | @@ -61,6 +61,7 @@ |
62 | 62 | |
63 | 63 | function createInstance() { |
64 | 64 | global $wgRequest, $wgOut; |
| 65 | + global $wgOpenStackManagerPuppetOptions; |
65 | 66 | |
66 | 67 | $this->setHeaders(); |
67 | 68 | $wgOut->setPagetitle("Create Instance"); |
— | — | @@ -146,6 +147,29 @@ |
147 | 148 | 'default' => $wgRequest->getText( 'project' ), |
148 | 149 | ); |
149 | 150 | |
| 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 | + |
150 | 174 | $instanceInfo['action'] = array( |
151 | 175 | 'type' => 'hidden', |
152 | 176 | 'default' => 'create', |
— | — | @@ -264,6 +288,7 @@ |
265 | 289 | |
266 | 290 | function tryCreateSubmit( $formData, $entryPoint = 'internal' ) { |
267 | 291 | global $wgOut, $wgUser; |
| 292 | + global $wgOpenStackManagerPuppetOptions; |
268 | 293 | |
269 | 294 | $sk = $wgUser->getSkin(); |
270 | 295 | $domain = OpenStackNovaDomain::getDomainByName( $formData['domain'] ); |
— | — | @@ -272,7 +297,22 @@ |
273 | 298 | } |
274 | 299 | $instance = $this->userNova->createInstance( $formData['instancename'], $formData['imageType'], '', $formData['instanceType'], $formData['availabilityZone'] ); |
275 | 300 | 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 ); |
277 | 317 | if ( $host ) { |
278 | 318 | $out = Html::element( 'p', array(), 'Created instance ' . $instance->getInstanceID() . ' with image ' . $instance->getImageId() . ' and hostname ' . $host->getFullyQualifiedHostName() . ' and ip ' . $instance->getInstancePrivateIP() ); |
279 | 319 | } else { |
Index: trunk/extensions/OpenStackManager/OpenStackNovaDomain.php |
— | — | @@ -132,7 +132,7 @@ |
133 | 133 | |
134 | 134 | wfSuppressWarnings(); |
135 | 135 | $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN, |
136 | | - '(cnamerecord=' . $instanceid . ')' ); |
| 136 | + '(cnamerecord=' . $instanceid . '.*)' ); |
137 | 137 | $hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result ); |
138 | 138 | wfRestoreWarnings(); |
139 | 139 | $fqdn = $hostInfo[0]['associateddomain'][0]; |
Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php |
— | — | @@ -26,8 +26,9 @@ |
27 | 27 | global $wgAuth; |
28 | 28 | global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword; |
29 | 29 | |
| 30 | + $hostname = $this->searchvalue . '.' . $this->domain->getFullyQualifiedDomainName(); |
30 | 31 | 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 . '))' ); |
32 | 33 | $this->hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result ); |
33 | 34 | wfRestoreWarnings(); |
34 | 35 | if ( $this->hostInfo["count"] == "0" ) { |
— | — | @@ -201,7 +202,7 @@ |
202 | 203 | |
203 | 204 | $host = OpenStackNovaHost::getHostByInstanceId( $instanceid ); |
204 | 205 | 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 ); |
206 | 207 | return false; |
207 | 208 | } |
208 | 209 | $dn = $host->hostDN; |
— | — | @@ -212,13 +213,14 @@ |
213 | 214 | wfRestoreWarnings(); |
214 | 215 | if ( $success ) { |
215 | 216 | $domain->updateSOA(); |
216 | | - $wgAuth->printDebug( "Successfully deleted host $hostname", NONSENSITIVE ); |
| 217 | + $wgAuth->printDebug( "Successfully deleted host $instanceid", NONSENSITIVE ); |
217 | 218 | return true; |
218 | 219 | } else { |
219 | | - $wgAuth->printDebug( "Failed to delete host $hostname", NONSENSITIVE ); |
| 220 | + $wgAuth->printDebug( "Failed to delete host $instanceid", NONSENSITIVE ); |
220 | 221 | return false; |
221 | 222 | } |
222 | 223 | } |
| 224 | + |
223 | 225 | /** |
224 | 226 | * @static |
225 | 227 | * @param $hostname |
— | — | @@ -254,17 +256,25 @@ |
255 | 257 | $hostEntry['associateddomain'][] = $hostname . '.' . $domainname; |
256 | 258 | $hostEntry['cnamerecord'][] = $instanceid . '.' . $domainname; |
257 | 259 | 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 ) { |
261 | 263 | $hostEntry['puppetclass'][] = $class; |
262 | 264 | } |
263 | 265 | } |
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; |
267 | 269 | } |
268 | 270 | } |
| 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 | + } |
269 | 279 | } |
270 | 280 | $dn = 'dc=' . $hostname . ',dc=' . $domain->getDomainName() . ',' . $wgOpenStackManagerLDAPInstanceBaseDN; |
271 | 281 | |