r81803 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81802‎ | r81803 | r81804 >
Date:00:29, 9 February 2011
Author:laner
Status:deferred
Tags:
Comment:
* Added support for pulling instance type information from the Nova EC2 admin API
* Added a class to represent instance types
* Added support for the create action in Special:NovaInstance to list detailed information about instance types
* Added a global config option for the Nova EC2 admin API's endpoint
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackManager.i18n.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackManager.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaController.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaInstanceType.php (added) (history)
  • /trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php
@@ -91,7 +91,12 @@
9292 $instanceTypes = $this->adminNova->getInstanceTypes();
9393 $instanceType_keys = array();
9494 foreach ( $instanceTypes as $instanceType ) {
95 - $instanceType_keys["$instanceType"] = $instanceType;
 95+ $instanceTypeName = $instanceType->getInstanceTypeName();
 96+ $cpus = $instanceType->getNumberOfCPUs();
 97+ $ram = $instanceType->getMemorySize();
 98+ $storage = $instanceType->getStorageSize();
 99+ $instanceLabel = $instanceTypeName . ' (' . wfMsgExt( 'openstackmanager-instancetypelabel', 'parsemag', $cpus, $ram, $storage ) . ')';
 100+ $instanceType_keys["$instanceLabel"] = $instanceTypeName;
96101 }
97102 $instanceInfo['instanceType'] = array(
98103 'type' => 'select',
Index: trunk/extensions/OpenStackManager/OpenStackManager.i18n.php
@@ -84,6 +84,7 @@
8585 'openstackmanager-availabilityzone' => 'Availability zone',
8686 'openstackmanager-imageid' => 'Image ID',
8787 'openstackmanager-imagetype' => 'Image type',
 88+ 'openstackmanager-instancetypelabel' => '{{PLURAL:$1|$1 CPU|$1 CPUs}}, $2 MB RAM, $3 GB storage',
8889 'openstackmanager-launchtime' => 'Launch time',
8990 'openstackmanager-createinstance' => 'Create a new instance',
9091 'openstackmanager-invaliddomain' => 'Requested domain is invalid.',
Index: trunk/extensions/OpenStackManager/OpenStackNovaInstanceType.php
@@ -0,0 +1,68 @@
 2+<?php
 3+
 4+# TODO: Make this an abstract class, and make the EC2 API a subclass
 5+class OpenStackNovaInstanceType {
 6+
 7+ var $instanceType;
 8+
 9+ /**
 10+ * @param $apiInstanceResponse
 11+ */
 12+ function __construct( $apiInstanceResponse ) {
 13+ $this->instanceType = $apiInstanceResponse;
 14+ }
 15+
 16+ /**
 17+ * Return the amount of RAM this instance type will use
 18+ *
 19+ * @return string
 20+ */
 21+ function getMemorySize() {
 22+ return (string)$this->instanceType->memoryMb;
 23+ }
 24+
 25+ /**
 26+ * Return the number of CPUs this instance will have
 27+ *
 28+ * @return string
 29+ */
 30+ function getNumberOfCPUs() {
 31+ return (string)$this->instanceType->vcpus;
 32+ }
 33+
 34+ /**
 35+ * Return the name of this instanceType
 36+ *
 37+ * @return string
 38+ */
 39+ function getInstanceTypeName() {
 40+ return (string)$this->instanceType->name;
 41+ }
 42+
 43+ /**
 44+ * Return the amount of storage this instance will use
 45+ *
 46+ * @return string
 47+ */
 48+ function getStorageSize() {
 49+ return (string)$this->instanceType->diskGb;
 50+ }
 51+
 52+ /**
 53+ * Return the id of this instanceType
 54+ *
 55+ * @return int
 56+ */
 57+ function getInstanceTypeId() {
 58+ return (int)$this->instanceType->flavorId;
 59+ }
 60+
 61+ public static function sorter( $a, $b ) {
 62+ return $a->getInstanceTypeId() > $b->getInstanceTypeId();
 63+ }
 64+
 65+ public static function sort( &$collection ) {
 66+ usort( $collection, array( __CLASS__, 'sorter' ) );
 67+ }
 68+
 69+}
Property changes on: trunk/extensions/OpenStackManager/OpenStackNovaInstanceType.php
___________________________________________________________________
Added: svn:eol-style
170 + native
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php
@@ -6,10 +6,8 @@
77 var $novaConnection;
88 var $instances, $images, $keypairs, $availabilityZones;
99 var $addresses, $securityGroups;
 10+ var $instanceTypes;
1011
11 - var $instanceTypes = array( 'm1.tiny', 'm1.small', 'm1.large', 'm1.xlarge', 'm2.xlarge', 'm2.2xlarge',
12 - 'm2.4xlarge', 'c1.medium', 'c1.xlarge', 'cc1.4xlarge' );
13 -
1412 /**
1513 * @param $credentials
1614 */
@@ -85,6 +83,19 @@
8684 * @return array
8785 */
8886 function getInstanceTypes() {
 87+ global $wgOpenStackManagerNovaResourcePrefix;
 88+ global $wgOpenStackManagerNovaAdminResourcePrefix;
 89+
 90+ $this->novaConnection->set_resource_prefix( $wgOpenStackManagerNovaAdminResourcePrefix );
 91+ $response = $this->novaConnection->authenticate( 'DescribeInstanceTypes', array(), $this->novaConnection->hostname );
 92+ $instanceTypes = $response->body->instanceTypeSet->item;
 93+ foreach ( $instanceTypes as $instanceType ) {
 94+ $instanceType = new OpenStackNovaInstanceType( $instanceType );
 95+ $instanceTypeName = $instanceType->getInstanceTypeName();
 96+ $this->instanceTypes["$instanceTypeName"] = $instanceType;
 97+ }
 98+ $this->novaConnection->set_resource_prefix( $wgOpenStackManagerNovaResourcePrefix );
 99+ OpenStackNovaInstanceType::sort( $this->instanceTypes );
89100 return $this->instanceTypes;
90101 }
91102
Index: trunk/extensions/OpenStackManager/OpenStackManager.php
@@ -38,6 +38,7 @@
3939 $wgOpenStackManagerNovaServerName = 'localhost';
4040 $wgOpenStackManagerNovaPort = 8773;
4141 $wgOpenStackManagerNovaResourcePrefix = '/services/Cloud/';
 42+$wgOpenStackManagerNovaAdminResourcePrefix = '/services/Admin/';
4243 $wgOpenStackManagerNovaAdminKeys = array( 'accessKey' => '', 'secretKey' => '' );
4344 $wgOpenStackManagerNovaKeypairStorage = 'ldap';
4445 $wgOpenStackManagerLDAPDomain = '';
@@ -78,6 +79,7 @@
7980 $wgExtensionMessagesFiles['OpenStackManager'] = $dir . 'OpenStackManager.i18n.php';
8081 $wgExtensionAliasesFiles['OpenStackManager'] = $dir . 'OpenStackManager.alias.php';
8182 $wgAutoloadClasses['OpenStackNovaInstance'] = $dir . 'OpenStackNovaInstance.php';
 83+$wgAutoloadClasses['OpenStackNovaInstanceType'] = $dir . 'OpenStackNovaInstanceType.php';
8284 $wgAutoloadClasses['OpenStackNovaKeypair'] = $dir . 'OpenStackNovaKeypair.php';
8385 $wgAutoloadClasses['OpenStackNovaController'] = $dir . 'OpenStackNovaController.php';
8486 $wgAutoloadClasses['OpenStackNovaUser'] = $dir . 'OpenStackNovaUser.php';

Status & tagging log