Index: trunk/extensions/OpenStackManager/SpecialNovaInstance.php |
— | — | @@ -266,7 +266,6 @@ |
267 | 267 | global $wgOut, $wgUser; |
268 | 268 | |
269 | 269 | $sk = $wgUser->getSkin(); |
270 | | - $domain = new OpenStackNovaDomain( $formData['domain'] ); |
271 | 270 | $domain = OpenStackNovaDomain::getDomainByName( $formData['domain'] ); |
272 | 271 | if ( ! $domain ) { |
273 | 272 | $out = Html::element( 'p', array(), 'Requested domain is invalid' ); |
— | — | @@ -295,15 +294,15 @@ |
296 | 295 | |
297 | 296 | $instance = $this->adminNova->getInstance( $formData['instanceid'] ); |
298 | 297 | $instancename = $instance->getInstanceName(); |
| 298 | + $instanceid = $instance->getInstanceId(); |
299 | 299 | $success = $this->userNova->terminateInstance( $formData['instanceid'] ); |
300 | 300 | $sk = $wgUser->getSkin(); |
301 | 301 | if ( $success ) { |
302 | | - $domain = OpenStackNovaDomain::getDomainByHostIP( $instance->getInstancePrivateIP() ); |
303 | | - $success = OpenStackNovaHost::deleteHost( $instancename, $domain ); |
| 302 | + $success = OpenStackNovaHost::deleteHostByInstanceId( $instanceid ); |
304 | 303 | if ( $success ) { |
305 | 304 | $out = Html::element( 'p', array(), "Deleted instance $instancename" ); |
306 | 305 | } 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" ); |
308 | 307 | } |
309 | 308 | } else { |
310 | 309 | $out = Html::element( 'p', array(), 'Failed to create instance' ); |
Index: trunk/extensions/OpenStackManager/OpenStackNovaInstance.php |
— | — | @@ -4,11 +4,25 @@ |
5 | 5 | class OpenStackNovaInstance { |
6 | 6 | |
7 | 7 | var $instance; |
| 8 | + var $host; |
8 | 9 | |
9 | | - function __construct( $apiInstanceResponse ) { |
| 10 | + function __construct( $apiInstanceResponse, $loadhost=false ) { |
10 | 11 | $this->instance = $apiInstanceResponse; |
| 12 | + if ( $loadhost ) { |
| 13 | + $this->host = OpenStackNovaHost::getHostByInstanceId( $this->getInstanceId() ); |
| 14 | + } else { |
| 15 | + $this->host = null; |
| 16 | + } |
11 | 17 | } |
12 | 18 | |
| 19 | + function setHost( $host ) { |
| 20 | + $this->host = $host; |
| 21 | + } |
| 22 | + |
| 23 | + function getHost() { |
| 24 | + return $this->host; |
| 25 | + } |
| 26 | + |
13 | 27 | function getReservationId() { |
14 | 28 | return $this->instance->reservationId; |
15 | 29 | } |
— | — | @@ -51,4 +65,14 @@ |
52 | 66 | return $this->instance->ownerId; |
53 | 67 | } |
54 | 68 | |
| 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 | + |
55 | 79 | } |
Index: trunk/extensions/OpenStackManager/OpenStackNovaDomain.php |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | global $wgOpenStackManagerLDAPInstanceBaseDN; |
28 | 28 | global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword; |
29 | 29 | |
| 30 | + # TODO: memcache this |
30 | 31 | wfSuppressWarnings(); |
31 | 32 | $result = ldap_search( $wgAuth->ldapconn, $wgOpenStackManagerLDAPInstanceBaseDN, |
32 | 33 | '(dc=' . $this->domainname . ')' ); |
— | — | @@ -121,6 +122,30 @@ |
122 | 123 | } |
123 | 124 | } |
124 | 125 | |
| 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 | + |
125 | 150 | # TODO: Allow generic domains; get rid of config set base name |
126 | 151 | static function createDomain( $domainname, $fqdn ) { |
127 | 152 | global $wgAuth; |
Index: trunk/extensions/OpenStackManager/OpenStackNovaHost.php |
— | — | @@ -2,13 +2,13 @@ |
3 | 3 | |
4 | 4 | class OpenStackNovaHost { |
5 | 5 | |
6 | | - var $hostname; |
| 6 | + var $searchvalue; |
7 | 7 | var $hostDN; |
8 | 8 | var $hostInfo; |
9 | 9 | var $domain; |
10 | 10 | |
11 | 11 | function __construct( $hostname, $domain ) { |
12 | | - $this->hostname = $hostname; |
| 12 | + $this->searchvalue = $hostname; |
13 | 13 | $this->domain = $domain; |
14 | 14 | $this->connect(); |
15 | 15 | $this->fetchHostInfo(); |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword; |
29 | 29 | |
30 | 30 | 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 . '))' ); |
32 | 32 | $this->hostInfo = ldap_get_entries( $wgAuth->ldapconn, $result ); |
33 | 33 | wfRestoreWarnings(); |
34 | 34 | if ( $this->hostInfo["count"] == "0" ) { |
— | — | @@ -38,11 +38,15 @@ |
39 | 39 | } |
40 | 40 | |
41 | 41 | function getHostName() { |
42 | | - return $this->hostname; |
| 42 | + return $this->hostInfo[0]['associateddomain'][0]; |
43 | 43 | } |
44 | 44 | |
| 45 | + function getDomain() { |
| 46 | + return $this->domain; |
| 47 | + } |
| 48 | + |
45 | 49 | function getFullyQualifiedHostName() { |
46 | | - return $this->hostname . '.' . $this->domain->getFullyQualifiedDomainName(); |
| 50 | + return $this->getHostName() . '.' . $this->domain->getFullyQualifiedDomainName(); |
47 | 51 | } |
48 | 52 | |
49 | 53 | function getARecords() { |
— | — | @@ -55,6 +59,16 @@ |
56 | 60 | return $arecords; |
57 | 61 | } |
58 | 62 | |
| 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 | + |
59 | 73 | function deleteARecord( $ip ) { |
60 | 74 | global $wgAuth; |
61 | 75 | |
— | — | @@ -119,6 +133,11 @@ |
120 | 134 | } |
121 | 135 | } |
122 | 136 | |
| 137 | + static function getHostByInstanceId( $instanceid ) { |
| 138 | + $domain = OpenStackNovaDomain::getDomainByInstanceId( $instanceid ); |
| 139 | + return self::getHostByName( $instanceid, $domain ); |
| 140 | + } |
| 141 | + |
123 | 142 | static function getAllHosts( $domain ) { |
124 | 143 | global $wgAuth; |
125 | 144 | global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword; |
— | — | @@ -173,22 +192,51 @@ |
174 | 193 | } |
175 | 194 | } |
176 | 195 | |
| 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 | + } |
177 | 223 | /** |
178 | 224 | * @static |
179 | 225 | * @param $hostname |
180 | 226 | * @param $ip |
181 | 227 | * @param $domain OpenStackNovaDomain |
| 228 | + * @param $puppetinfo |
182 | 229 | * @return bool |
183 | 230 | */ |
184 | | - static function addHost( $instance, $domain ) { |
| 231 | + static function addHost( $instance, $domain, $puppetinfo=array() ) { |
185 | 232 | global $wgAuth; |
186 | 233 | global $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword; |
187 | | - global $wgOpenStackManagerLDAPInstanceBaseDN; |
| 234 | + global $wgOpenStackManagerLDAPInstanceBaseDN, $wgOpenStackManagerPuppetOptions; |
188 | 235 | |
189 | 236 | $wgAuth->connect(); |
190 | 237 | $wgAuth->bindAs( $wgOpenStackManagerLDAPUser, $wgOpenStackManagerLDAPUserPassword ); |
191 | 238 | |
192 | 239 | $hostname = $instance->getInstanceName(); |
| 240 | + $instanceid = $instance->getInstanceId(); |
193 | 241 | $ip = $instance->getInstancePrivateIP(); |
194 | 242 | $domainname = $domain->getFullyQualifiedDomainName(); |
195 | 243 | $host = OpenStackNovaHost::getHostByName( $hostname, $domain ); |
— | — | @@ -201,8 +249,23 @@ |
202 | 250 | $hostEntry['objectclass'][] = 'dnsdomain'; |
203 | 251 | $hostEntry['objectclass'][] = 'domainrelatedobject'; |
204 | 252 | $hostEntry['dc'] = $hostname; |
| 253 | + #$hostEntry['l'] = $instance->getInstanceAvailabilityZone(); |
205 | 254 | $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 | + } |
207 | 270 | $dn = 'dc=' . $hostname . ',dc=' . $domain->getDomainName() . ',' . $wgOpenStackManagerLDAPInstanceBaseDN; |
208 | 271 | |
209 | 272 | wfSuppressWarnings(); |
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | $instance = $this->instances[$instanceId]; |
28 | 28 | } else { |
29 | 29 | $response = $this->novaConnection->describe_instances( $instanceId ); |
30 | | - $instance = new OpenStackNovaInstance( $response->body->reservationSet->item ); |
| 30 | + $instance = new OpenStackNovaInstance( $response->body->reservationSet->item, true ); |
31 | 31 | $instanceId = $instance->getInstanceId(); |
32 | 32 | $this->instances["$instanceId"] = $instance; |
33 | 33 | } |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | $response = $this->novaConnection->describe_instances(); |
41 | 41 | $instances = $response->body->reservationSet->item; |
42 | 42 | foreach ( $instances as $instance ) { |
43 | | - $instance = new OpenStackNovaInstance( $instance ); |
| 43 | + $instance = new OpenStackNovaInstance( $instance, true ); |
44 | 44 | $instanceId = $instance->getInstanceId(); |
45 | 45 | $this->instances["$instanceId"] = $instance; |
46 | 46 | } |