r81805 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81804‎ | r81805 | r81806 >
Date:03:04, 9 February 2011
Author:laner
Status:deferred
Tags:
Comment:
* Added a class to represent images
* Changed logic of which images will be shown for image creation: only show images that are public, are available, are of type machine, and have an image name
* Changed behavior of create action for Special:NovaInstance to show image names instead of image ids
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackManager.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaController.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaImage.php (added) (history)
  • /trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/special/SpecialNovaInstance.php
@@ -123,8 +123,22 @@
124124 # where the name points to itself as a value
125125 $images = $this->adminNova->getImages();
126126 $image_keys = array();
127 - foreach ( array_keys( $images ) as $image_key ) {
128 - $image_keys["$image_key"] = $image_key;
 127+ foreach ( $images as $image ) {
 128+ if ( ! $image->imageIsPublic() ) {
 129+ continue;
 130+ }
 131+ if ( $image->getImageState() != "available" ) {
 132+ continue;
 133+ }
 134+ if ( $image->getImageType() != "machine" ) {
 135+ continue;
 136+ }
 137+ $imageName = $image->getImageName();
 138+ if ( $imageName == '' ) {
 139+ continue;
 140+ }
 141+ $imageLabel = $imageName . ' (' . $image->getImageArchitecture() . ')';
 142+ $image_keys["$imageLabel"] = $image->getImageId();
129143 }
130144 $instanceInfo['imageType'] = array(
131145 'type' => 'select',
Index: trunk/extensions/OpenStackManager/OpenStackNovaImage.php
@@ -0,0 +1,69 @@
 2+<?php
 3+
 4+# TODO: Make this an abstract class, and make the EC2 API a subclass
 5+class OpenStackNovaImage {
 6+
 7+ var $image;
 8+
 9+ /**
 10+ * @param $apiInstanceResponse
 11+ */
 12+ function __construct( $apiInstanceResponse ) {
 13+ $this->image = $apiInstanceResponse;
 14+ }
 15+
 16+ /**
 17+ * Return the name of this image
 18+ *
 19+ * @return string
 20+ */
 21+ function getImageName() {
 22+ return (string)$this->image->displayName;
 23+ }
 24+
 25+ /**
 26+ * Return the ID of this image
 27+ *
 28+ * @return string
 29+ */
 30+ function getImageId() {
 31+ return (string)$this->image->id;
 32+ }
 33+
 34+ /**
 35+ * Return the availability state of this image
 36+ *
 37+ * @return string
 38+ */
 39+ function getImageState() {
 40+ return (string)$this->image->imageState;
 41+ }
 42+
 43+ /**
 44+ * Return the image type
 45+ *
 46+ * @return string
 47+ */
 48+ function getImageType() {
 49+ return (string)$this->image->imageType;
 50+ }
 51+
 52+ /**
 53+ * Return the image architecture
 54+ *
 55+ * @return string
 56+ */
 57+ function getImageArchitecture() {
 58+ return (string)$this->image->architecture;
 59+ }
 60+
 61+ /**
 62+ * Return whether or not this image is public
 63+ *
 64+ * @return bool
 65+ */
 66+ function imageIsPublic() {
 67+ return (bool)$this->image->isPublic;
 68+ }
 69+
 70+}
Property changes on: trunk/extensions/OpenStackManager/OpenStackNovaImage.php
___________________________________________________________________
Added: svn:eol-style
171 + native
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php
@@ -107,9 +107,9 @@
108108 $images = $this->novaConnection->describe_images();
109109 $images = $images->body->imagesSet->item;
110110 foreach ( $images as $image ) {
111 - if ( $image->imageType == 'machine' ) {
112 - $this->images["$image->imageId"] = $image;
113 - }
 111+ $image = new OpenStackNovaImage( $image );
 112+ $imageId = $image->getImageId();
 113+ $this->images["$imageId"] = $image;
114114 }
115115 return $this->images;
116116 }
Index: trunk/extensions/OpenStackManager/OpenStackManager.php
@@ -80,6 +80,7 @@
8181 $wgExtensionAliasesFiles['OpenStackManager'] = $dir . 'OpenStackManager.alias.php';
8282 $wgAutoloadClasses['OpenStackNovaInstance'] = $dir . 'OpenStackNovaInstance.php';
8383 $wgAutoloadClasses['OpenStackNovaInstanceType'] = $dir . 'OpenStackNovaInstanceType.php';
 84+$wgAutoloadClasses['OpenStackNovaImage'] = $dir . 'OpenStackNovaImage.php';
8485 $wgAutoloadClasses['OpenStackNovaKeypair'] = $dir . 'OpenStackNovaKeypair.php';
8586 $wgAutoloadClasses['OpenStackNovaController'] = $dir . 'OpenStackNovaController.php';
8687 $wgAutoloadClasses['OpenStackNovaUser'] = $dir . 'OpenStackNovaUser.php';

Status & tagging log