Finishing upload !!!

This commit is contained in:
Yoggzo 2016-05-08 18:17:04 +02:00
parent f0e77d6b65
commit 80ce348e43
2 changed files with 630 additions and 599 deletions

View file

@ -38,7 +38,6 @@
<input type="hidden" name="task" value="image" />
<input type="hidden" name="token" value="{{ getToken()}}" />
<input type="hidden" name="action" value="uploadImage" />
<input type="hidden" name="diskFormat" value="QCOW2" />
<input type="hidden" name="id" value="{{ image.id}}" />
<input type="hidden" name="file_name" value="cirros-0.3.4-x86_64-disk.img" />

View file

@ -1,5 +1,4 @@
<?php
/**
* File containing the Image Class.
*
@ -9,6 +8,7 @@
* @author Evan Pisani 'yogg at epsina . com'
*
*/
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
@ -45,6 +45,7 @@ class image implements Core {
$this->libClass = $app->getLibClass("Image");
}
/**
* Execute an action
*
@ -84,7 +85,8 @@ class image implements Core {
}
}
$options['name'] = $opt['name'];
} else {
}
else{
$this->app->setOutput("Error", "Missing parameter 'name' for the new image");
}
@ -103,9 +105,13 @@ class image implements Core {
}
if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker
$options['containerFormat'] = $opt['containerFormat'];
}else{
$options['containerFormat'] = "bare";
}
if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso
$options['diskFormat'] = $opt['diskFormat'];
}else{
$options['diskFormat'] = "iso";
}
if(isset($opt['minDisk'])){ //int
$options['minDisk'] = $opt['minDisk'];
@ -133,6 +139,7 @@ class image implements Core {
$this->app->getErrorInstance()->OtherException($e);
}
$this->app->setOutput("Images", $image);
}
/**
@ -160,6 +167,7 @@ class image implements Core {
}
$this->app->setOutput("Images", $result);
}
/**
@ -174,13 +182,15 @@ class image implements Core {
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect id parameter");
} else {
}
else{
try{
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
} else {
}
else{
$this->app->setOutput("Images", $image);
}
}catch(BadResponseError $e){
@ -205,15 +215,18 @@ class image implements Core {
*
* @return void
*/
private function updateImage(){
$id = $this->app->getPostParam("id");
$opt = $this->app->getPostParam("opt");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect id parameter");
} else if (!isset($opt)) {
}
else if(!isset($opt)){
$this->app->setOutput("Error", "Incorrect opt parameter");
} else {
}
else{
try{
$service = $this->libClass;
$image = $service->getImage($id);
@ -234,7 +247,7 @@ class image implements Core {
$options['minRam'] = $opt['minRam'];
}
if(isset($opt['protected'])){ // boolean
$options['protected'] = $opt['protected'] == "true" ? true : false;
$options['protected'] = $opt['protected'];
}
if(isset($opt['visibility'])){ // public, private
$options['visibility'] = $opt['visibility'];
@ -269,7 +282,8 @@ class image implements Core {
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Image doesn't exist");
} else {
}
else{
try{
$service = $this->libClass;
$image = $this->libClass->getImage($id);
@ -303,7 +317,9 @@ class image implements Core {
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter");
} else {
}
else
{
try{
$service = $this->libClass;
$image = $service->getImage($id);
@ -338,7 +354,9 @@ class image implements Core {
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter");
} else {
}
else
{
try{
$service = $this->libClass;
$image = $service->getImage($id);
@ -376,9 +394,11 @@ class image implements Core {
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect id parameter");
} else if (!isset($file_name)) {
}
else if(!isset($file_name)){
$this->app->setOutput("Error", "Incorrect file name parameter");
} else {
}
else{
try{
$service = $this->libClass;
$image = $service->getImage($id);
@ -388,7 +408,8 @@ class image implements Core {
$stream = \GuzzleHttp\Psr7\stream_for($file);
$image->uploadData($stream);
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
echo $e;
//$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
@ -413,7 +434,8 @@ class image implements Core {
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect id parameter");
} else {
}
else{
try{
$service = $this->libClass;
$image = $service->getImage($id);
@ -450,9 +472,11 @@ class image implements Core {
if(!isset($image_id)){
$this->app->setOutput("Error", "Incorrect image id parameter");
} else if (!isset($member_id)) {
}
else if(!isset($member_id)){
$this->app->setOutput("Error", "Incorrect member id parameter");
} else {
}
else{
try{
$service = $this->libClass;
@ -476,6 +500,7 @@ class image implements Core {
}
}
/**
* List members of an image
*
@ -489,9 +514,11 @@ class image implements Core {
if(!isset($image_id)){
$this->app->setOutput("Error", "Incorrect image id parameter");
} else if (!isset($member_id)) {
}
else if(!isset($member_id)){
$this->app->setOutput("Error", "Incorrect member id parameter");
} else {
}
else{
try{
$service = $this->libClass;
$image = $service->getImage($image_id);
@ -531,9 +558,11 @@ class image implements Core {
if(!isset($image_id)){
$this->app->setOutput("Error", "Incorrect image id parameter");
} else if (!isset($member_id)) {
}
else if(!isset($member_id)){
$this->app->setOutput("Error", "Incorrect member id parameter");
} else {
}
else{
try{
$service = $this->libClass;
@ -575,9 +604,11 @@ class image implements Core {
if(!isset($image_id)){
$this->app->setOutput("Error", "Incorrect image id parameter");
} else if (!isset($member_id)) {
}
else if(!isset($member_id)){
$this->app->setOutput("Error", "Incorrect member id parameter");
} else {
}
else{
try{
$service = $this->libClass;
@ -620,9 +651,11 @@ class image implements Core {
if(!isset($image_id)){
$this->app->setOutput("Error", "Incorrect image id parameter");
} else if (!isset($member_id)) {
}
else if(!isset($member_id)){
$this->app->setOutput("Error", "Incorrect member id parameter");
} else {
}
else{
try{
$service = $this->libClass;
@ -650,5 +683,4 @@ class image implements Core {
}
}
?>