r78164 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78163‎ | r78164 | r78165 >
Date:01:01, 10 December 2010
Author:laner
Status:deferred
Tags:
Comment:
Making an object for instances, which is a wrapper for the xml returned data
Modified paths:
  • /trunk/extensions/OpenStackManager/OpenStackNovaController.php (modified) (history)
  • /trunk/extensions/OpenStackManager/OpenStackNovaInstance.php (added) (history)
  • /trunk/extensions/OpenStackManager/SpecialCreateInstance.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenStackManager/SpecialCreateInstance.php
@@ -97,13 +97,11 @@
9898 function tryCreateSubmit( $formData, $entryPoint = 'internal' ) {
9999 global $wgOut;
100100
101 - $instanceId = $this->adminNova->createInstance( $formData['imageType'], $formData['keypair'],
 101+ $instance = $this->adminNova->createInstance( $formData['imageType'], $formData['keypair'],
102102 $formData['instanceType'], $formData['availabilityZone'] );
103103
104 - print_r($instanceId);
 104+ $wgOut->addHTML('<p>Created instance ' . $instance->getInstanceID() . ' with image ' . $instance->getImageId() . '</p>');
105105
106 - $wgOut->addHTML('<p>Created instance ' . $instanceId . '</p>');
107 -
108106 return true;
109107 }
110108 }
Index: trunk/extensions/OpenStackManager/OpenStackNovaController.php
@@ -24,9 +24,10 @@
2525 if ( isset( $this->instances[$instanceId] ) && !$reload ) {
2626 $instance = $this->instances[$instanceId];
2727 } else {
28 - $instance = $this->novaConnection->describe_instances( $instanceId );
29 - $instance = $instance->body->reservationSet->item;
30 - $this->instances["$instance->instancesSet->item->instanceId"] = $instance;
 28+ $response = $this->novaConnection->describe_instances( $instanceId );
 29+ $instance = new OpenStackNovaInstance($response->body->reservationSet->item);
 30+ $instanceId = $instance->getInstanceId();
 31+ $this->instances["$instanceId"] = $instance;
3132 }
3233 return $instance;
3334 }
@@ -34,10 +35,12 @@
3536 function getInstances( $reload = false ) {
3637 if ( count( $this->instances ) == 0 || $reload ) {
3738 $this->instances = array();
38 - $instances = $this->novaConnection->describe_instances();
 39+ $response = $this->novaConnection->describe_instances();
3940 $instances = $instances->body->reservationSet->item;
4041 foreach ( $instances as $instance ) {
41 - $this->instances["$instance->instancesSet->item->instanceId"] = $instance;
 42+ $instance = new OpenStackNovaInstance($instance);
 43+ $instanceId = $instance->getInstanceId();
 44+ $this->instances["$instanceId"] = $instance;
4245 }
4346 }
4447 return $this->instances;
@@ -97,11 +100,11 @@
98101 'Placement.AvailabilityZone' => $availabilityZone,
99102 ));
100103
101 - $instance = $instance->body->reservationSet->item;
102 - $instanceId = $instance->instancesSet->item->instanceId;
 104+ $instance = new OpenStackNovaInstance($response->body->reservationSet->item);
 105+ $instanceId = $instance->getInstanceId();
103106 $this->instances["$instanceId"] = $instance;
104107
105 - return $instanceId;
 108+ return $instance;
106109 }
107110
108111 }
Index: trunk/extensions/OpenStackManager/OpenStackNovaInstance.php
@@ -0,0 +1,40 @@
 2+<?php
 3+
 4+# TODO: Make this an abstract class, and make the EC2 API a subclass
 5+class OpenStackNovaInstance {
 6+
 7+ var $instance;
 8+
 9+ function __construct( $apiInstanceResponse ) {
 10+ $this->instance = $apiInstanceResponse;
 11+ }
 12+
 13+ function getReservationId() {
 14+ return $this->instance->reservationId;
 15+ }
 16+
 17+ function getInstanceId() {
 18+ return $this->instance->instancesSet->item->instanceId;
 19+ }
 20+
 21+ function getInstanceState() {
 22+ return $this->instance->instancesSet->item->instanceState->name;
 23+ }
 24+
 25+ function getInstanceType() {
 26+ return $this->instance->instancesSet->item->instanceType;
 27+ }
 28+
 29+ function getImageId() {
 30+ return $this->instance->instancesSet->item->imageId;
 31+ }
 32+
 33+ function getKeyName() {
 34+ return $this->instance->instancesSet->item->keyName;
 35+ }
 36+
 37+ function getOwner() {
 38+ return $this->instance->ownerId;
 39+ }
 40+
 41+}

Status & tagging log