summaryrefslogtreecommitdiff
path: root/server/core/Image.php
blob: 242bb5f71a1f8b005210a2e0e54d48750606f2d5 (plain)
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
<?php
ini_set('display_errors', 1);
date_default_timezone_set("Europe/Paris");
//require '../vendor/autoload.php';

class Image {
	
	protected $oidentity;
	//protected $plugins;

	/*
	* Constructor 
	*
	* @param $openstack
	*		
	* @param $options
	*
	*/
	public function __construct($ostack, $options){ //, $apiP
		$this->oidentity = $ostack->imagesV2($options);
		//$this->plugins = $apiP;
	}

	public function create_image(array $opt){
		$service = $openstack->imagesV2();

		// OPTIONS A VOIR
		$image = $service->createImage([
	    	'name'            => $opt[name],
	    	'tags'            => ['{tag1}', '{tag2}'], // A VOIR
	    	'containerFormat' => $opt[containerFormat],
	    	'diskFormat'      => $opt[diskFormat],
	    	'visibility'      => $opt[visibility],
	    	'minDisk'         => 10,
	    	'protected'       => true,
	    	'minRam'          => 10,
		]);

		return $image;
	}

	/*
	* List images
	*/
	public function list_images(){
		$images = $this->oidentity->listImages();
		return $images;
	}


	public function image_details($id){
		$service = $openstack->imagesV2();
		$image = $service->getImage($id);
		return $image;
	}


	public function update_image($id, array $opt){
		$service = $openstack->imagesV2();

		//OPTIONS A VOIR
		$image = $service->getImage($id);
		$image->update([
	    	'minDisk'    => 1,
	    	'minRam'     => 1,
	    	'name'       => $opt[name],
	    	'protected'  => false,
	    	'visibility' => $opt[visibility],
		]);

		return $image;
	}

	// RETOUR A VOIR
	public function delete_image($name){
		$openstack->imagesV2()->getImage($name)->delete();
	}

	// RETOUR A VOIR
	public function reactivate_image($id){
		$service = $openstack->imagesV2();
		$image = $service->getImage($id);
		$image->reactivate();
	}

	// RETOUR A VOIR
	public function desactivate_function($id){
		$service = $openstack->imagesV2();
		$image = $service->getImage($id);
		$image->deactivate();
	}

	// RETOUR A VOIR
	public function upload_image($id, $file_name){
		$service = $openstack->imagesV2();
		$image  = $service->getImage($id);
		$stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR
		$image->uploadData($stream);
	}

	// RETOUR A VOIR
	public function download_image($id){
		$service = $openstack->imagesV2();
		$image  = $service->getImage($id);
		$stream = $image->downloadData();
	}
}
?>