r80035 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80034‎ | r80035 | r80036 >
Date:20:31, 11 January 2011
Author:laner
Status:deferred
Tags:
Comment:
Added support for allocating, release, associating, and deassociating floating IP addresses.
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackManager.i18n.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackManager.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaController.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/OpenStackManager.i18n.php
@@ -127,6 +127,26 @@
128128 'openstackmanager-shellaccountname' => 'Instance Shell Account Name',
129129 'openstackmanager-shellaccountnamehelp' => 'The shell account name must start with a-z, and can only contain a-z, 0-9, -, and _ characters',
130130
 131+ 'openstackmanager-addresslist' => 'Public IP Address List',
 132+ 'openstackmanager-address' => 'Public IP Address',
 133+ 'openstackmanager-allocateaddress' => 'Allocate a new public IP address',
 134+ 'openstackmanager-releaseaddress' => 'Release IP',
 135+ 'openstackmanager-associateaddress' => 'Associate IP',
 136+ 'openstackmanager-reassociateaddress' => 'Reassociate IP',
 137+ 'openstackmanager-disassociateaddress' => 'Disassociate IP',
 138+ 'openstackmanager-allocateaddressfailed' => 'Failed to allocate new public IP address',
 139+ 'openstackmanager-allocatedaddress' => 'Allocated new public IP address: $1',
 140+ 'openstackmanager-backaddresslist' => 'Back to address list',
 141+ 'openstackmanager-allocateaddress-confirm' => 'Are you sure you would like to allocate a new public IP address in project $1?',
 142+ 'openstackmanager-releasedaddress' => 'Successfully released address: $1',
 143+ 'openstackmanager-releaseaddressfailed' => 'Failed to release address: $1',
 144+ 'openstackmanager-associatedaddress' => 'Successfully associated $1 with instance id $2',
 145+ 'openstackmanager-associateaddressfailed' => 'Failed to associate $1 with instance id $2',
 146+ 'openstackmanager-disassociatedaddress' => 'Successfully disassociated $1',
 147+ 'openstackmanager-disassociateaddressfailed' => 'Failed to disassociate $1',
 148+ 'openstackmanager-disassociateaddress-confirm' => 'Are you sure you would like to disassociate $1?',
 149+ 'openstackmanager-releaseaddress-confirm' => 'Are you sure you would like to release $1?',
 150+
131151 );
132152
133153 /** Message documentation (Message documentation)
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php
@@ -5,8 +5,9 @@
66
77 var $novaConnection;
88 var $instances, $images, $keypairs, $availabilityZones;
 9+ var $addresses;
910
10 - var $instanceTypes = array( 'm1.small', 'm1.large', 'm1.xlarge', 'm2.xlarge', 'm2.2xlarge',
 11+ var $instanceTypes = array( 'm1.tiny', 'm1.small', 'm1.large', 'm1.xlarge', 'm2.xlarge', 'm2.2xlarge',
1112 'm2.4xlarge', 'c1.medium', 'c1.xlarge', 'cc1.4xlarge' );
1213
1314 # TODO: Make disable_ssl, hostname, and resource_prefix config options
@@ -21,6 +22,18 @@
2223 $this->instances = array();
2324 }
2425
 26+ function getAddresses() {
 27+ $this->addresses = array();
 28+ $response = $this->novaConnection->describe_addresses();
 29+ $addresses = $response->body->addressesSet->item;
 30+ foreach ( $addresses as $address ) {
 31+ $address = new OpenStackNovaAddress( $address );
 32+ $ip = $address->getPublicIp();
 33+ $this->addresses["$ip"] = $address;
 34+ }
 35+ return $this->addresses;
 36+ }
 37+
2538 function getInstance( $instanceId ) {
2639 $this->getInstances();
2740 if ( isset( $this->instances["$instanceId"] ) ) {
@@ -120,4 +133,38 @@
121134 return $keypair;
122135 }
123136
 137+ function allocateAddress() {
 138+ $response = $this->novaConnection->allocate_address();
 139+ if ( ! $response->isOK() ) {
 140+ return null;
 141+ } else {
 142+ $address = new OpenStackNovaAddress( $response->body->addressSet->item );
 143+ $this->addresses["$ip"] = $address;
 144+ return $address;
 145+ }
 146+ }
 147+
 148+ function releaseAddress( $ip ) {
 149+ $response = $this->novaConnection->release_address( $ip );
 150+
 151+ return $response->isOK();
 152+ }
 153+
 154+ function associateAddress( $instanceid, $ip ) {
 155+ $response = $this->novaConnection->associate_address( $instanceid, $ip );
 156+ if ( ! $response->isOK() ) {
 157+ return null;
 158+ } else {
 159+ $address = new OpenStackNovaAddress( $response->body->addressSet->item );
 160+ $this->addresses["$ip"] = $address;
 161+ return $address;
 162+ }
 163+ }
 164+
 165+ function disassociateAddress( $ip ) {
 166+ $response = $this->novaConnection->disassociate_address( $ip );
 167+
 168+ return $response->isOK();
 169+ }
 170+
124171 }
Index: trunk/extensions/OpenStackManager/OpenStackManager.php
@@ -62,10 +62,12 @@
6363 $wgAutoloadClasses['OpenStackNovaUser'] = $dir . 'OpenStackNovaUser.php';
6464 $wgAutoloadClasses['OpenStackNovaDomain'] = $dir . 'OpenStackNovaDomain.php';
6565 $wgAutoloadClasses['OpenStackNovaHost'] = $dir . 'OpenStackNovaHost.php';
 66+$wgAutoloadClasses['OpenStackNovaAddress'] = $dir . 'OpenStackNovaAddress.php';
6667 $wgAutoloadClasses['SpecialNovaInstance'] = $dir . 'SpecialNovaInstance.php';
6768 $wgAutoloadClasses['SpecialNovaKey'] = $dir . 'SpecialNovaKey.php';
6869 $wgAutoloadClasses['SpecialNovaProject'] = $dir . 'SpecialNovaProject.php';
6970 $wgAutoloadClasses['SpecialNovaDomain'] = $dir . 'SpecialNovaDomain.php';
 71+$wgAutoloadClasses['SpecialNovaAddress'] = $dir . 'SpecialNovaAddress.php';
7072 $wgAutoloadClasses['SpecialNova'] = $dir . 'SpecialNova.php';
7173 $wgAutoloadClasses['OpenStackNovaHostJob'] = $dir . 'OpenStackNovaHostJob.php';
7274 $wgAutoloadClasses['AmazonEC2'] = $dir . 'aws-sdk/sdk.class.php';
@@ -77,6 +79,8 @@
7880 $wgSpecialPageGroups['NovaProject'] = 'other';
7981 $wgSpecialPages['NovaDomain'] = 'SpecialNovaDomain';
8082 $wgSpecialPageGroups['NovaDomain'] = 'other';
 83+$wgSpecialPages['NovaAddress'] = 'SpecialNovaAddress';
 84+$wgSpecialPageGroups['NovaAddress'] = 'other';
8185 $wgJobClasses['addDNSHostToLDAP'] = 'OpenStackNovaHostJob';
8286
8387 $wgHooks['LDAPSetCreationValues'][] = 'OpenStackNovaUser::LDAPSetCreationValues';

Status & tagging log