1 <?php
5 class DevicePartition
6 {
7 public $object =NULL;
8 public $partitionString =NULL;
10 function __construct($config, $partitionString)
11 {
12 $this->config = &$config;
13 $this->partitionString = $partitionString;
14 }
16 function init()
17 {
18 $rpc = $this->config->getRpcHandle();
19 $this->object = $rpc->openObject('libinst.preseed.diskdefinition', '');
21 $this->object->addDisk('sda');
22 $this->object->addPartition('/kekse', 2333, NULL, FALSE, TRUE, FALSE, FALSE, 'ext3','ro,user,nosuid' , FALSE, NULL, 'sda');
23 $this->object->addPartition('/wurst', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda');
24 $this->object->addPartition('raid.00', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda');
25 $this->object->addPartition('raid.01', 2000, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda');
26 $this->object->addPartition('pv.00', 2333, NULL, FALSE, TRUE, FALSE, FALSE, NULL, NULL, FALSE, NULL, 'sda');
27 $this->object->addRaidDevice('pv.01', 'md0', '0','0', NULL, NULL, TRUE, FALSE, array('raid.00', 'raid.01'));
28 $this->object->addVolumeGroup('garnele', array('pv.00', 'pv.01'));
29 $this->object->addVolume('/home', 'garnele_home', 'garnele', 2000);
31 // Prepare lists
32 $this->entryList = new sortableListing();
33 $this->entryList->setDeleteable(false);
34 $this->entryList->setEditable(false);
35 $this->entryList->setWidth("100%");
36 $this->entryList->setHeight("400px");
37 $this->entryList->setHeader(array(_("Type"),_("Target"),_("Size"),_("Uses device")." / "._("Used by"),_("Filesystem"), _("Options")));
38 $this->entryList->setColspecs(array('*','*','*', '*'));
39 $this->entryList->setAcl('rwcdm');
40 $this->entryList->setReorderable(FALSE);
41 $this->entryList->sortingEnabled(FALSE);
43 // Receive list informations
44 $disks = $this->object->getDisks();
45 $partitions = $this->object->getPartitions();
46 $raids = $this->object->getRaidDevices();
47 $volumeGroups = $this->object->getVolumeGroups();
48 $volumes = $this->object->getVolumes();
50 // Create a mapping that show which partitions was used for which raid.
51 $map_partToRaid = array();
52 $raidTargets = array();
53 foreach($raids as $raid){
54 $raidTargets[] = $raid['target'];
55 foreach($raid['devices'] as $devName){
56 $map_partToRaid[$devName] = $raid['name'];
57 }
58 }
60 // Create a mapping that shows which partition was used in which volumeGroup.
61 $map_partToVolumeGroup = array();
62 foreach($volumeGroups as $vol){
63 foreach($vol['partitions'] as $part){
64 $map_partToVolumeGroup[$part] = $vol['name'];
65 }
66 }
68 // Create partition name map
69 $partNames = array();
71 // Create separators to create a visible indentation
72 $seps = array();
73 $seps[0] = "";
74 $seps[1] = str_pad("", 18, " ");
75 $seps[2] = str_pad("", 36, " ");
77 // Prepare images
78 $partitionImg = image('plugins/goto/images/partition.png');
79 $diskImg = image('plugins/goto/images/disk.png');
80 $raidImg = image('plugins/goto/images/raid.png');
81 $volumeGroupImg = image('plugins/goto/images/volumeGroups.png');
82 $volumeImg = image('plugins/goto/images/volume.png');
84 // Add raid devices
85 $lData = array();
86 if(count($raids)){
88 // Add raid header
89 $lData[] = array("data" => array("<b>"._("Raid devices")."</b>"));
91 // Add raids
92 foreach($raids as $id => $raid){
93 $str = "{$seps[1]}{$raidImg} {$raid['name']} ({$raid['level']})";
95 $devsStr = "";
96 foreach($raid['devices'] as $devName){
97 $devsStr .= $partitionImg." ".$devName.", ";
98 }
99 $devsStr = rtrim($devsStr, ', ');
101 $target = $raid['target'];
102 if(isset($map_partToVolumeGroup[$target])){
103 $target = $volumeGroupImg." ".$target;
104 }
106 $lData[] = array("data" => array($str,
107 $target,
108 '',
109 $devsStr,
110 $raid['fsType'],
111 $raid['fsOptions']
112 ));
113 }
114 }
116 // Add volume groups
117 if(count($volumeGroups)){
119 // Add LVM volume groups header
120 $lData[] = array("data" => array("<b>"._("LVM Volume Groups")."</b>"));
122 // Add volume groups
123 foreach($volumeGroups as $id => $vg){
124 $str = "{$seps[1]}{$volumeGroupImg} {$vg['name']}";
126 // Build up a list of all used partitions
127 $partStr = "";
128 foreach($vg['partitions'] as $partName){
129 if(in_array($partName, $raidTargets)){
130 $img = $raidImg;
131 }else{
132 $img = $partitionImg;
133 }
134 $partStr .= "{$img} {$partName}, ";
135 }
136 $partStr = rtrim($partStr, ", ");
138 // Add entry to the list.
139 $lData[] = array("data" => array($str, '', '', $partStr));
141 // Add volumes
142 foreach($volumes as $volume){
143 if($volume['volGroup'] == $vg['name']){
144 $str = "{$seps[2]}{$volumeImg} {$volume['name']}";
145 $lData[] = array("data" => array(
146 $str,
147 $volume['target'],
148 $this->__convertPartSize($volume['size']),
149 '',
150 $volume['fsType'],
151 $volume['fsOptions']
152 ));
156 }
157 }
158 }
159 }
161 // Add physical disks to the listing.
162 if(count($disks)){
164 // Add disks
165 $lData[] = array("data" => array("<b>"._("Disks")."</b>"));
166 foreach($disks as $id => $disk){
167 $str = "{$seps[1]}{$diskImg} {$disk['device']}";
168 $lData[] = array("data" => array($str));
170 // Add partitions
171 foreach($partitions as $pid => $part){
173 if($part['onDisk'] == $disk['device']){
175 // Prepare columns
176 $str = "{$seps[2]}{$partitionImg} {$part['target']}";
177 $device = "";
178 $fsType = $part['fsType'];
179 $target = "";
180 if(preg_match("/^(swap|\/)/", $part['target'])){
181 $target = $part['target'];
182 }
184 // Do we have a raid here? Then update the device column
185 // to point to the raid name
186 if(isset($map_partToRaid[$part['target']])){
187 $device = sprintf(_("Used by: %s"), $raidImg." ".$map_partToRaid[$part['target']]);
188 $fsType.= " "._("Software raid");
189 $fsType = trim($fsType);
190 }elseif(isset($map_partToVolumeGroup[$part['target']])){
191 $device = sprintf(_("Used by: %s"), $volumeGroupImg." ".$map_partToVolumeGroup[$part['target']]);
192 $fsType.= " "._("Physical volume LVM");
193 $fsType = trim($fsType);
194 }
196 // Add entry to the listing
197 $lData[] = array("data" => array(
198 $str,
199 $target,
200 $this->__convertPartSize($part['size']),
201 $device,
202 $fsType,
203 $part['fsOptions']));
204 }
205 }
206 }
207 }
209 // Updated columns length for all entries to avoid render errors.
210 $length = 6;
211 foreach($lData as $id => $entry){
212 while(count($lData[$id]['data']) < $length){
213 $lData[$id]['data'][] = '';
214 }
215 }
217 $this->entryList->setListData($lData, $lData);
218 $this->entryList->update();
221 }
223 function execute()
224 {
225 $this->init();
226 return($this->entryList->render());
227 }
229 function save_object()
230 {
232 }
234 function __convertPartSize($size)
235 {
236 return($size." MB");
237 }
238 }
240 ?>