istic-openstack/server/core/Compute.php

202 lines
5 KiB
PHP
Raw Normal View History

2016-02-28 10:48:28 +01:00
<?php
//namespace istic-openstack\Server\core;
// TODO introduce error-handling based on errors specific to the compute module
use OpenStack\Common\Error;
class compute
{
/** @var App $app protected, contains the main app object */
protected $app;
/** @var OpenStack\Identity $libClass protected, contains the library Compute object */
protected $libClass;
public function __construct($app)
{
$this->app = $app;
$this->libClass = $app->getLibClass("Compute");
}
2016-02-28 20:49:52 +01:00
/**
* Execute an action
*
* @param String $action name of another function of this class
*
* @return void
*/
public function action($action){
$this->{$action.""}();
}
/**
* List servers.
* @return array
*/
2016-02-28 10:48:28 +01:00
public function listServers()
{
2016-03-01 16:53:23 +01:00
$serverList = $this->libClass->listServers(true);
2016-02-29 16:59:27 +01:00
$servers = Array();
foreach($serverList as $server){
$servers[$server->id] = Array();
$server->flavor->retrieve();
$server->image->retrieve();
2016-03-01 16:12:19 +01:00
$servers[$server->id]["id"] = $server->id;
$servers[$server->id]["name"] = $server->name;
$servers[$server->id]["imageId"] = $server->image->id;
$servers[$server->id]["flavorId"] = $server->flavor->id;
$servers[$server->id]["status"] = $server->status;
2016-03-01 18:52:29 +01:00
$servers[$server->id]["ram"] = $server->flavor->ram;
$servers[$server->id]["disk"] = $server->flavor->disk;
2016-02-29 16:59:27 +01:00
}
$this->app->setOutput("Servers", $servers);
return;
2016-02-28 10:48:28 +01:00
}
/**
* List flavors.
* @return array
*/
public function listFlavors()
{
2016-02-29 16:59:27 +01:00
$flavorList = $this->libClass->listFlavors();
$flavors = Array();
foreach($flavorList as $flavor){
$flavors[$flavor->id] = Array();
2016-03-01 16:12:19 +01:00
$flavors[$flavor->id]["id"] = $flavor->id;
$flavors[$flavor->id]["name"] = $flavor->name;
2016-02-29 16:59:27 +01:00
}
$this->app->setOutput("Flavors", $flavors);
return;
2016-02-28 10:48:28 +01:00
}
/**
* List images.
* @return array
*/
public function listImages()
{
2016-02-29 16:59:27 +01:00
$imageList = $this->libClass->listImages();
$images = Array();
foreach($imageList as $image){
$images[$image->id] = Array();
2016-03-01 16:12:19 +01:00
$images[$image->id]["id"] = $image->id;
$images[$image->id]["name"] = $image->name;
2016-02-29 16:59:27 +01:00
}
$this->app->setOutput("Images", $images);
return;
2016-02-28 10:48:28 +01:00
}
/**
* Create server.
* @return array
2016-02-28 20:49:52 +01:00
*
public function createServer()
2016-02-28 10:48:28 +01:00
{
$server = $this->libClass->createServer();
}
2016-02-28 20:49:52 +01:00
*/
2016-02-28 10:48:28 +01:00
/**
* Get server details.
* @return array
*/
public function getServer()
2016-02-28 10:48:28 +01:00
{
$serverId = $this->app->getPostParam("serverId");
$opt = array('id' => $serverId);
$server = $this->libClass->getServer($opt);
2016-02-28 21:23:28 +01:00
$server->retrieve();
$this->app->setOutput("MyServer", $server);
return;
2016-02-28 10:48:28 +01:00
}
/**
* Get flavor details.
* @return array
*/
public function getFlavor()
2016-02-28 10:48:28 +01:00
{
$flavorId = $this->app->getPostParam("flavorId");
$opt = array('id' => $flavorId);
$flavor = $this->libClass->getFlavor($opt);
2016-02-28 21:23:28 +01:00
$flavor->retrieve();
$this->app->setOutput("MyFlavor", $flavor);
return;
2016-02-28 10:48:28 +01:00
}
/**
* Get image details.
* @return array
*/
2016-02-28 20:29:18 +01:00
public function getImage()
2016-02-28 10:48:28 +01:00
{
$imageId = $this->app->getPostParam("imageId");
$opt = array('id' => $imageId);
$image = $this->libClass->getImage($opt);
2016-02-28 21:23:28 +01:00
$image->retrieve();
$this->app->setOutput("MyImage", $image);
return;
2016-02-28 10:48:28 +01:00
}
/* working on tests
2016-02-28 10:48:28 +01:00
public function update()
{
$image = $this->app->getServer(array $options = []);
}
public function delete()
{
//TODO
}
public function changePassword($newPassword)
{
//TODO
}
public function reboot($type = Enum::REBOOT_SOFT)
{
//TODO
}
public function rebuild(array $options)
{
//TODO
}
public function resize($flavorId)
{
//TODO
}
public function confirmResize()
{
//TODO
}
public function revertResize()
{
//TODO
}
public function createImage(array $options)
{
//TODO
}
public function listAddresses(array $options = [])
{
//TODO
}
public function getMetadata()
{
//TODO
}
public function resetMetadata(array $metadata)
{
//TODO
}
public function mergeMetadata(array $metadata)
{
//TODO
}
public function getMetadataItem($key)
{
//TODO
}
public function deleteMetadataItem($key)
{
//TODO
}
*/
2016-02-28 10:48:28 +01:00
}