Index: trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php |
— | — | @@ -91,7 +91,12 @@ |
92 | 92 | $instanceTypes = $this->adminNova->getInstanceTypes(); |
93 | 93 | $instanceType_keys = array(); |
94 | 94 | 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; |
96 | 101 | } |
97 | 102 | $instanceInfo['instanceType'] = array( |
98 | 103 | 'type' => 'select', |
Index: trunk/extensions/OpenStackManager/OpenStackManager.i18n.php |
— | — | @@ -84,6 +84,7 @@ |
85 | 85 | 'openstackmanager-availabilityzone' => 'Availability zone', |
86 | 86 | 'openstackmanager-imageid' => 'Image ID', |
87 | 87 | 'openstackmanager-imagetype' => 'Image type', |
| 88 | + 'openstackmanager-instancetypelabel' => '{{PLURAL:$1|$1 CPU|$1 CPUs}}, $2 MB RAM, $3 GB storage', |
88 | 89 | 'openstackmanager-launchtime' => 'Launch time', |
89 | 90 | 'openstackmanager-createinstance' => 'Create a new instance', |
90 | 91 | '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 |
1 | 70 | + native |
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php |
— | — | @@ -6,10 +6,8 @@ |
7 | 7 | var $novaConnection; |
8 | 8 | var $instances, $images, $keypairs, $availabilityZones; |
9 | 9 | var $addresses, $securityGroups; |
| 10 | + var $instanceTypes; |
10 | 11 | |
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 | | - |
14 | 12 | /** |
15 | 13 | * @param $credentials |
16 | 14 | */ |
— | — | @@ -85,6 +83,19 @@ |
86 | 84 | * @return array |
87 | 85 | */ |
88 | 86 | 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 ); |
89 | 100 | return $this->instanceTypes; |
90 | 101 | } |
91 | 102 | |
Index: trunk/extensions/OpenStackManager/OpenStackManager.php |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | $wgOpenStackManagerNovaServerName = 'localhost'; |
40 | 40 | $wgOpenStackManagerNovaPort = 8773; |
41 | 41 | $wgOpenStackManagerNovaResourcePrefix = '/services/Cloud/'; |
| 42 | +$wgOpenStackManagerNovaAdminResourcePrefix = '/services/Admin/'; |
42 | 43 | $wgOpenStackManagerNovaAdminKeys = array( 'accessKey' => '', 'secretKey' => '' ); |
43 | 44 | $wgOpenStackManagerNovaKeypairStorage = 'ldap'; |
44 | 45 | $wgOpenStackManagerLDAPDomain = ''; |
— | — | @@ -78,6 +79,7 @@ |
79 | 80 | $wgExtensionMessagesFiles['OpenStackManager'] = $dir . 'OpenStackManager.i18n.php'; |
80 | 81 | $wgExtensionAliasesFiles['OpenStackManager'] = $dir . 'OpenStackManager.alias.php'; |
81 | 82 | $wgAutoloadClasses['OpenStackNovaInstance'] = $dir . 'OpenStackNovaInstance.php'; |
| 83 | +$wgAutoloadClasses['OpenStackNovaInstanceType'] = $dir . 'OpenStackNovaInstanceType.php'; |
82 | 84 | $wgAutoloadClasses['OpenStackNovaKeypair'] = $dir . 'OpenStackNovaKeypair.php'; |
83 | 85 | $wgAutoloadClasses['OpenStackNovaController'] = $dir . 'OpenStackNovaController.php'; |
84 | 86 | $wgAutoloadClasses['OpenStackNovaUser'] = $dir . 'OpenStackNovaUser.php'; |