begining of automating

This commit is contained in:
Yoggzo 2016-04-18 17:38:25 +02:00
parent 9e7eb6774b
commit e1b15c38d7
2 changed files with 41 additions and 40 deletions

View file

@ -118,12 +118,6 @@ class AppTest{
return $this->errorClass; return $this->errorClass;
} }
public function getOutput($key){
return $this->output[$key];
}
} }

View file

@ -22,6 +22,7 @@ class automating implements Core{
protected $appImage; protected $appImage;
protected $appNetwork; protected $appNetwork;
protected $appIdentity; protected $appIdentity;
protected $appFloatingIp;
protected $app; protected $app;
/** /**
@ -39,6 +40,7 @@ class automating implements Core{
$this->appImage = $appImage; $this->appImage = $appImage;
$this->appNetwork = $appNetwork; $this->appNetwork = $appNetwork;
$this->appIdentity = $appIdentity; $this->appIdentity = $appIdentity;
$this->appFloatingIp = $appFloatingIp;
$this->app = $app; $this->app = $app;
} }
@ -52,51 +54,56 @@ class automating implements Core{
public function action($action){ public function action($action){
$this->{$action.""}(); $this->{$action.""}();
} }
public function script()
{
$opt = Array();
$opt['name'] = getPostParam('name');
appImage->setPostParam('opt' $opt);
appImage->createImage();
appNetwork->create_network();
appnetwork->list_network_ids();
appNetwork->create_subnet();
appCompute->listFlavors(); //to show all flavors with detail.
appCompute->listImages(); //to show all images with detail and to verify that the image was created successfully by the call above.
appCompute->setPostParam("name","Test");
appCompute->setPostParam("imageId","CREATED_ABOVE");
appCompute->setPostParam("flavorId","1");
appCompute->createServer();
}
/**
* create a new server and associate a public ip
*
* @param String $imageName name of the new image
* @param String $serverName name ofthe new server
* @param String $flavor kind of server
*
* @return void
*/
private function createServer() private function createServer()
{ {
$imageName = $this->app->getPostParam('imageName'); $imageName = $this->app->getPostParam('imageName');
$serverName = $this->app->getPostParam('serverName'); $serverName = $this->app->getPostParam('serverName');
$flavor = $this->app->getPostParam('flavor'); $flavor = $this->app->getPostParam('flavor');
// Création image if(!isset($imageName)){
$opt = Array(); $this->app->setOutput("Error", "Incorrect imageName parameter");
$opt['name'] = $imageName; }
$this->app->setPostParam('opt' $opt); else if(!isset($serverName)){
$this->appImage->createImage(); $this->app->setOutput("Error", "Incorrect serverName parameter");
$image = json_decode($this->app->show(), true)["Images"]; }
else if(!isset($flavor)){
$this->app->setOutput("Error", "Incorrect flavor parameter");
}
else{
// Création image
$opt = array();
$opt['name'] = $imageName;
$this->appImage->setPostParam('opt' $opt);
$this->appImage->createImage();
$image = json_decode($this->app->show(), true)["Images"];
// Création server // Création server
$this->app->setPostParam('name', $serverName); $this->appCompute->setPostParam('name', $serverName);
$this->app->setPostParam('imageId', $image['id']); $this->appCompute->setPostParam('imageId', $image['id']);
$this->app->setPostParam('flavorId', $flavor); $this->appCompute->setPostParam('flavorId', $flavor);
$this->appNetwork->createServer(); $this->appCompute->createServer();
$server = json_decode($this->app->show(), true)["Compute"];
// Ajout adresse IP public // Ajout adresse IP public
$optIp = array();
$opt['floatingip'] = null; //new floatingip(); ???
$opt['floating_network_id'] = $server['id'];
$this->appFloatingIp->setPostParam('opt', $optIp);
$this->appFloatingIp->create();
}
} }
} }
?> ?>