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', '');
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"),_("Filesystem"), _("Options")));
45 $this->entryList->setColspecs(array('*','*','*', '*'));
46 $this->entryList->setAcl('rwcdm');
47 $this->entryList->setReorderable(FALSE);
48 $this->entryList->sortingEnabled(FALSE);
49 }
51 function execute()
52 {
53 /*****
54 * Handle add-partition dialog
55 *****/
56 if(isset($_POST['create_partition'])){
57 $this->addDialog = new AddPartitionDialog($this->config, $this->object);
58 }
59 if(isset($_POST['cancel_partition_add'])){
60 $this->addDialog = NULL;
61 }
62 if(isset($_POST['save_partition_add'])){
63 $this->addDialog->save_object();
64 if($this->addDialog->save()){
65 $this->addDialog = NULL;
66 }
67 }
68 if($this->addDialog){
69 $this->addDialog->save_object();
70 return($this->addDialog->execute());
71 }
74 /*****
75 * Fill listing
76 *****/
78 // Receive list informations
79 $disks = $this->object->getDisks();
80 $partitions = $this->object->getPartitions();
81 $raids = $this->object->getRaidDevices();
82 $volumeGroups = $this->object->getVolumeGroups();
83 $volumes = $this->object->getVolumes();
85 // Create a mapping that show which partitions was used for which raid.
86 $map_partToRaid = array();
87 $raidTargets = array();
88 foreach($raids as $raid){
89 $raidTargets[] = $raid['target'];
90 foreach($raid['devices'] as $devName){
91 $map_partToRaid[$devName] = $raid['name'];
92 }
93 }
95 // Create a mapping that shows which partition was used in which volumeGroup.
96 $map_partToVolumeGroup = array();
97 foreach($volumeGroups as $vol){
98 foreach($vol['partitions'] as $part){
99 $map_partToVolumeGroup[$part] = $vol['name'];
100 }
101 }
103 // Create partition name map
104 $partNames = array();
106 // Create separators to create a visible indentation
107 $seps = array();
108 $seps[0] = "";
109 $seps[1] = str_pad("", 18, " ");
110 $seps[2] = str_pad("", 36, " ");
112 // Prepare images
113 $partitionImg = image('plugins/goto/images/partition.png');
114 $diskImg = image('plugins/goto/images/disk.png');
115 $raidImg = image('plugins/goto/images/raid.png');
116 $volumeGroupImg = image('plugins/goto/images/volumeGroups.png');
117 $volumeImg = image('plugins/goto/images/volume.png');
119 // Add raid devices
120 $lData = array();
121 if(count($raids)){
123 // Add raid header
124 $lData[] = array("data" => array("<b>"._("Raid devices")."</b>"));
126 // Add raids
127 foreach($raids as $id => $raid){
128 $str = "{$seps[1]}{$raidImg} {$raid['name']} ({$raid['level']})";
130 $devsStr = "";
131 foreach($raid['devices'] as $devName){
132 $devsStr .= $partitionImg." ".$devName.", ";
133 }
134 $devsStr = rtrim($devsStr, ', ');
136 $target = $raid['target'];
137 if(isset($map_partToVolumeGroup[$target])){
138 $target = $volumeGroupImg." ".$target;
139 }
141 $lData[] = array("data" => array($str,
142 $target,
143 '',
144 $devsStr,
145 $raid['fsType'],
146 $raid['fsOptions']
147 ));
148 }
149 }
151 // Add volume groups
152 if(count($volumeGroups)){
154 // Add LVM volume groups header
155 $lData[] = array("data" => array("<b>"._("LVM Volume Groups")."</b>"));
157 // Add volume groups
158 foreach($volumeGroups as $id => $vg){
159 $str = "{$seps[1]}{$volumeGroupImg} {$vg['name']}";
161 // Build up a list of all used partitions
162 $partStr = "";
163 foreach($vg['partitions'] as $partName){
164 if(in_array($partName, $raidTargets)){
165 $img = $raidImg;
166 }else{
167 $img = $partitionImg;
168 }
169 $partStr .= "{$img} {$partName}, ";
170 }
171 $partStr = rtrim($partStr, ", ");
173 // Add entry to the list.
174 $lData[] = array("data" => array($str, '', '', $partStr));
176 // Add volumes
177 foreach($volumes as $volume){
178 if($volume['volGroup'] == $vg['name']){
179 $str = "{$seps[2]}{$volumeImg} {$volume['name']}";
180 $lData[] = array("data" => array(
181 $str,
182 $volume['target'],
183 $this->__convertPartSize($volume['size']),
184 '',
185 $volume['fsType'],
186 $volume['fsOptions']
187 ));
191 }
192 }
193 }
194 }
196 // Add physical disks to the listing.
197 if(count($disks)){
199 // Add disks
200 $lData[] = array("data" => array("<b>"._("Disks")."</b>"));
201 foreach($disks as $id => $disk){
202 $str = "{$seps[1]}{$diskImg} {$disk['device']}";
203 $lData[] = array("data" => array($str));
205 // Add partitions
206 foreach($partitions as $pid => $part){
208 if($part['onDisk'] == $disk['device']){
210 // Prepare columns
211 $str = "{$seps[2]}{$partitionImg} {$part['target']}";
212 $device = "";
213 $fsType = $part['fsType'];
214 $target = "";
215 if(preg_match("/^(swap|\/)/", $part['target'])){
216 $target = $part['target'];
217 }
219 // Do we have a raid here? Then update the device column
220 // to point to the raid name
221 if(isset($map_partToRaid[$part['target']])){
222 $device = sprintf(_("Used by: %s"), $raidImg." ".$map_partToRaid[$part['target']]);
223 $fsType.= " "._("Software raid");
224 $fsType = trim($fsType);
225 }elseif(isset($map_partToVolumeGroup[$part['target']])){
226 $device = sprintf(_("Used by: %s"), $volumeGroupImg." ".$map_partToVolumeGroup[$part['target']]);
227 $fsType.= " "._("Physical volume LVM");
228 $fsType = trim($fsType);
229 }
231 // Add entry to the listing
232 $lData[] = array("data" => array(
233 $str,
234 $target,
235 $this->__convertPartSize($part['size']),
236 $device,
237 $fsType,
238 $part['fsOptions']));
239 }
240 }
241 }
242 }
244 // Updated columns length for all entries to avoid render errors.
245 $length = 6;
246 foreach($lData as $id => $entry){
247 while(count($lData[$id]['data']) < $length){
248 $lData[$id]['data'][] = '';
249 }
250 }
251 $this->entryList->setListData($lData, $lData);
252 $this->entryList->update();
254 $smarty = get_smarty();
255 $smarty->assign('list', $this->entryList->render());
256 return($smarty->fetch(get_template_path('goto/Device/DevicePartition.tpl', TRUE)));
257 }
259 function save_object()
260 {
262 }
264 function save()
265 {
266 return($this->object->dump());
267 }
269 function __convertPartSize($size)
270 {
271 return($size." MB");
272 }
273 }
275 ?>