1 <?php
5 class DevicePartition
6 {
7 public $object =NULL;
8 public $partitionString =NULL;
10 public $addDialog = NULL;
12 function __construct($config, $partitionString)
13 {
14 $this->config = &$config;
15 $this->partitionString = $partitionString;
16 $this->init();
17 }
19 function init()
20 {
21 $rpc = $this->config->getRpcHandle();
22 $this->object = $rpc->openObject('libinst.preseed.diskdefinition', $this->partitionString);
24 #$this->object->addDisk('sda');
25 #$this->object->addDisk('sdb');
26 #$this->object->addDisk('sdc');
27 #$this->object->addPartition('/kekse', 2333, NULL, FALSE, TRUE, FALSE, FALSE, 'ext3','ro,user,nosuid' , FALSE, NULL, 'sda');
28 #$this->object->addPartition('/wurst', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda');
29 #$this->object->addPartition('raid.00', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda');
30 #$this->object->addPartition('raid.01', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda');
31 #$this->object->addPartition('pv.00', 2333, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda');
32 #$this->object->addPartition('pv.01', 2333, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda');
33 #$this->object->addPartition('pv.02', 2333, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda');
34 #$this->object->addRaidDevice('pv.01', 'md0', '0','0', NULL, NULL, TRUE, FALSE, array('raid.00', 'raid.01'));
35 #$this->object->addVolumeGroup('garnele', array('pv.00', 'pv.01'));
36 #$this->object->addVolume('/home', 'garnele_home', 'garnele', 2000);
38 // Prepare lists
39 $this->entryList = new sortableListing();
40 $this->entryList->setDeleteable(false);
41 $this->entryList->setEditable(false);
42 $this->entryList->setWidth("100%");
43 $this->entryList->setHeight("400px");
44 $this->entryList->setHeader(array(_("Type"),_("Target"),_("Size"),_("Uses device")." / "._("Used by"),
45 _("Filesystem"), _("Options"), _("Format"), "-"));
46 $this->entryList->setColspecs(array('*','*','*', '*'));
47 $this->entryList->setAcl('rwcdm');
48 $this->entryList->setReorderable(FALSE);
49 $this->entryList->sortingEnabled(FALSE);
50 }
52 function execute()
53 {
54 /*****
55 * Handle add-partition dialog
56 *****/
57 if(isset($_POST['create_partition'])){
58 $this->addDialog = new AddPartitionDialog($this->config, $this->object);
59 }
60 if(isset($_POST['cancel_partition_add'])){
61 $this->addDialog = NULL;
62 }
63 if(isset($_POST['save_partition_add'])){
64 $this->addDialog->save_object();
65 if($this->addDialog->save()){
66 $this->addDialog = NULL;
67 }
68 }
69 if($this->addDialog){
70 $this->addDialog->save_object();
71 return($this->addDialog->execute());
72 }
75 /*****
76 * Fill listing
77 *****/
79 // Receive list informations
80 $disks = $this->object->getDisks();
81 $partitions = $this->object->getPartitions();
82 $raids = $this->object->getRaidDevices();
83 $volumeGroups = $this->object->getVolumeGroups();
84 $volumes = $this->object->getVolumes();
86 // Create a mapping that show which partitions was used for which raid.
87 $map_partToRaid = array();
88 $raidTargets = array();
89 foreach($raids as $raid){
90 $raidTargets[] = $raid['target'];
91 foreach($raid['devices'] as $devName){
92 $map_partToRaid[$devName] = $raid['name'];
93 }
94 }
96 // Create a mapping that shows which partition was used in which volumeGroup.
97 $map_partToVolumeGroup = array();
98 foreach($volumeGroups as $vol){
99 foreach($vol['partitions'] as $part){
100 $map_partToVolumeGroup[$part] = $vol['name'];
101 }
102 }
104 // Create partition name map
105 $partNames = array();
107 // Create separators to create a visible indentation
108 $seps = array();
109 $seps[0] = "";
110 $seps[1] = str_pad("", 18, " ");
111 $seps[2] = str_pad("", 36, " ");
113 // Prepare images
114 $partitionImg = image('plugins/goto/images/partition.png');
115 $diskImg = image('plugins/goto/images/disk.png');
116 $raidImg = image('plugins/goto/images/raid.png');
117 $volumeGroupImg = image('plugins/goto/images/volumeGroups.png');
118 $volumeImg = image('plugins/goto/images/volume.png');
120 // Add raid devices
121 $lData = array();
122 if(count($raids)){
124 // Add raid header
125 $lData[] = array("data" => array("<b>"._("Raid devices")."</b>"));
127 // Add raids
128 foreach($raids as $id => $raid){
129 $str = "{$seps[1]}{$raidImg} {$raid['name']} ({$raid['level']})";
131 $devsStr = "";
132 foreach($raid['devices'] as $devName){
133 $devsStr .= $partitionImg." ".$devName.", ";
134 }
135 $devsStr = rtrim($devsStr, ', ');
137 $target = $raid['target'];
138 if(isset($map_partToVolumeGroup[$target])){
139 $target = $volumeGroupImg." ".$target;
140 }
142 $fsType = (isset($raid['fsType'])) ? $raid['fsType'] :"";
143 $fsOptions = (isset($raid['fsOptions'])) ? $raid['fsOptions'] :"";
145 $lData[] = array("data" => array($str,
146 $target,
147 '',
148 $devsStr,
149 $fsType,
150 $fsOptions
151 ));
152 }
153 }
155 // Add volume groups
156 if(count($volumeGroups)){
158 // Add LVM volume groups header
159 $lData[] = array("data" => array("<b>"._("LVM Volume Groups")."</b>"));
161 // Add volume groups
162 foreach($volumeGroups as $id => $vg){
163 $str = "{$seps[1]}{$volumeGroupImg} {$vg['name']}";
165 // Build up a list of all used partitions
166 $partStr = "";
167 foreach($vg['partitions'] as $partName){
168 if(in_array($partName, $raidTargets)){
169 $img = $raidImg;
170 }else{
171 $img = $partitionImg;
172 }
173 $partStr .= "{$img} {$partName}, ";
174 }
175 $partStr = rtrim($partStr, ", ");
177 // Add entry to the list.
178 $lData[] = array("data" => array($str, '', '', $partStr));
180 // Add volumes
181 foreach($volumes as $volume){
182 if($volume['volGroup'] == $vg['name']){
183 $str = "{$seps[2]}{$volumeImg} {$volume['name']}";
184 $lData[] = array("data" => array(
185 $str,
186 $volume['target'],
187 $this->__convertPartSize($volume['size']),
188 '',
189 $volume['fsType'],
190 $volume['fsOptions']
191 ));
195 }
196 }
197 }
198 }
200 // Add physical disks to the listing.
201 if(count($disks)){
203 // Add disks
204 $lData[] = array("data" => array("<b>"._("Disks")."</b>"));
205 foreach($disks as $id => $disk){
206 $str = "{$seps[1]}{$diskImg} {$disk['device']}";
207 $lData[] = array("data" => array($str));
209 // Add partitions
210 foreach($partitions as $pid => $part){
212 if($part['onDisk'] == $disk['device']){
214 // Prepare columns
215 $str = "{$seps[2]}{$partitionImg} {$part['target']}";
216 $device = "";
217 $fsType = $part['fsType'];
218 $target = "";
219 if(preg_match("/^(swap|\/)/", $part['target'])){
220 $target = $part['target'];
221 }
223 // Do we have a raid here? Then update the device column
224 // to point to the raid name
225 if(isset($map_partToRaid[$part['target']])){
226 $device = sprintf(_("Used by: %s"), $raidImg." ".$map_partToRaid[$part['target']]);
227 $fsType.= " "._("Software raid");
228 $fsType = trim($fsType);
229 }elseif(isset($map_partToVolumeGroup[$part['target']])){
230 $device = sprintf(_("Used by: %s"), $volumeGroupImg." ".$map_partToVolumeGroup[$part['target']]);
231 $fsType.= " "._("Physical volume LVM");
232 $fsType = trim($fsType);
233 }
235 $formatImg = ($part['format']) ? image('images/true.png') : "";
237 // Add entry to the listing
238 $lData[] = array("data" => array(
239 $str,
240 $target,
241 $this->__convertPartSize($part['size']),
242 $device,
243 $fsType,
244 $part['fsOptions'],
245 $formatImg));
246 }
247 }
248 }
249 }
251 // Updated columns length for all entries to avoid render errors.
252 $length = 8;
253 foreach($lData as $id => $entry){
254 while(count($lData[$id]['data']) < $length){
255 $lData[$id]['data'][] = '';
256 }
257 }
258 $this->entryList->setListData($lData, $lData);
259 $this->entryList->update();
261 $smarty = get_smarty();
262 $smarty->assign('list', $this->entryList->render());
263 return($smarty->fetch(get_template_path('goto/Device/DevicePartition.tpl', TRUE)));
264 }
266 function save_object()
267 {
269 }
271 function save()
272 {
273 return($this->object->dump());
274 }
276 function __convertPartSize($size)
277 {
278 return($size." MB");
279 }
280 }
282 ?>