1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
<?php
/**
* File containing the Automating Class.
*
* @version 1.0 Initialisation of this file
* @since 1.0 Core application's file
*
* @author Evan Pisani 'yogg at epsina . com' et bhupi
*
* @todo Complete the functions with errors detection and finish the descriptions
*/
include("CoreInterface.php");
include("Image.php");
include("Network.php");
include("Compute.php");
class automating implements Core{
/** @var App $app protected, contains the main app object */
protected $appCompute;
protected $appImage;
protected $appNetwork;
protected $appIdentity;
/**
* Our library's app constructor for all server app objects
*
* @param App $app the main app object, e.g. compute, image, network, etc.
*
* @return
*/
public function __construct($app){
if(!isset($app)){
$this->app->setOutput("Error", "Parameter app missing.");
}
$this->appCompute = $appCompute;
$this->appImage = $appImage;
$this->appNetwork = $appNetwork;
$this->appIdentity = $appIdentity;
}
/**
* Execute an action
*
* @param String $action name of another function of this class
*
* @return void
*/
public function action($action){
$this->{$action.""}();
}
public function script()
{
appImage->setPostParam("A_REMPLIR_PAR_Evan","VALEUR");
appImage->createImage();
appImage->create_network();
appImage->list_network_ids();
appImage->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 image on a new server
*
* @param $name the name of the new image
* @param $falvor_id the id of the flavor it will be used to create the new server
*
* @return Image the new image created
*/
private function createImageOnNewServer(){
try{
/* POURRI
$image = new Image($this->app);
$compute = new Compute($this->app);
$name = $this->app->getPostParam("name");
$falvor_id = $this->app->getPostParam("falvor_id"); // Compris entre 1 et 5 (1=petit serveur, 5=gros serveur)
$opt = Array();
$opt['name'] = $name;
$opt['visibility'] = 'public';
$opt['minDisk'] = 100; // A VOIR
$opt['minRam'] = 128; // A VOIR
$opt['protected'] = false;
$this->app->setPostParam("opt", $opt);
$image->action("createImage");
$res = json_decode($this->app->show(), true)["Images"];
$this->app->setPostParam("name", $name);
$this->app->setPostParam("imageId", $res['id']);
$this->app->setPostParam("flavorId", $falvor_id);
$compute->action("createServer");
*/
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
//$this->app->setOutput("Auto", $res);
}
/**
* Create a new image on an existing server
*
* @param $name the name of the new image
* @param $server_id the id of the server
*
* @return Image the new image created
*/
private function createImageOnServer(){
try{
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
}
}
?>
|