~ltrager/maas/remove_di_from_kernel_opts

« back to all changes in this revision

Viewing changes to src/maasserver/preseed_storage.py

  • Committer: Lee Trager
  • Date: 2016-10-22 06:06:12 UTC
  • mfrom: (5457.1.44 maas)
  • Revision ID: lee.trager@canonical.com-20161022060612-ukar20f6ffs45nas
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
)
18
18
from maasserver.models.partition import Partition
19
19
from maasserver.models.partitiontable import (
 
20
    BIOS_GRUB_PARTITION_SIZE,
20
21
    GPT_REQUIRED_SIZE,
21
22
    INITIAL_PARTITION_OFFSET,
22
23
    PARTITION_TABLE_EXTRA_SPACE,
118
119
            self.boot_disk.id == block_device.id and
119
120
            arch == "ppc64el")
120
121
 
 
122
    def _requires_bios_grub_partition(self, block_device):
 
123
        """Return True if block device requires the bios_grub partition."""
 
124
        arch, _ = self.node.split_arch()
 
125
        bios_boot_method = self.node.get_bios_boot_method()
 
126
        return (
 
127
            arch == "amd64" and
 
128
            bios_boot_method != "uefi" and
 
129
            block_device.size >= GPT_REQUIRED_SIZE)
 
130
 
121
131
    def _add_partition_operations(self):
122
132
        """Add all the partition operations.
123
133
 
126
136
        """
127
137
        for block_device in self.node.blockdevice_set.order_by('id'):
128
138
            requires_prep = self._requires_prep_partition(block_device)
 
139
            requires_bios_grub = self._requires_bios_grub_partition(
 
140
                block_device)
129
141
            partition_table = block_device.get_partitiontable()
130
142
            if partition_table is not None:
131
143
                partitions = list(partition_table.partitions.order_by('id'))
132
144
                for idx, partition in enumerate(partitions):
133
 
                    # If this is the last partition and prep partition is
134
 
                    # required then set boot_disk_first_partition so extra
135
 
                    # space can be removed.
136
 
                    if requires_prep and idx == 0:
 
145
                    # If this is the first partition and prep or bios_grub
 
146
                    # partition is required then set boot_disk_first_partition
 
147
                    # so partition creation can occur in the correct order.
 
148
                    if (requires_prep or requires_bios_grub) and idx == 0:
137
149
                        self.boot_disk_first_partition = partition
138
150
                    self.operations["partition"].append(partition)
139
151
 
195
207
        # Set the partition table type if a partition table exists or if this
196
208
        # is the boot disk.
197
209
        add_prep_partition = False
 
210
        add_bios_grub_partition = False
198
211
        partition_table = block_device.get_partitiontable()
199
212
        if partition_table is not None:
200
213
            disk_operation["ptable"] = self._get_ptable_type(
207
220
                disk_operation["ptable"] = "gpt"
208
221
                if node_arch == "ppc64el":
209
222
                    add_prep_partition = True
210
 
            elif block_device.size >= GPT_REQUIRED_SIZE:
 
223
            elif (block_device.size >= GPT_REQUIRED_SIZE and
 
224
                    node_arch == "amd64"):
211
225
                disk_operation["ptable"] = "gpt"
 
226
                add_bios_grub_partition = True
212
227
            else:
213
228
                disk_operation["ptable"] = "msdos"
214
229
 
221
236
            disk_operation["grub_device"] = True
222
237
        self.storage_config.append(disk_operation)
223
238
 
224
 
        # Add the prep partition at the end of the disk when it is required.
 
239
        # Add the prep partition at the beginning of the disk
 
240
        # when it is required.
225
241
        if add_prep_partition:
226
242
            self._generate_prep_partition(block_device.get_name())
227
243
 
 
244
        # Add the bios_grub partition at the beginning of the disk
 
245
        # when it is required.
 
246
        if add_bios_grub_partition:
 
247
            self._generate_bios_grub_partition(block_device.get_name())
 
248
 
228
249
    def _get_ptable_type(self, partition_table):
229
250
        """Return the value for the "ptable" entry in the physical operation.
230
251
        """
254
275
        }
255
276
        self.storage_config.append(partition_operation)
256
277
 
 
278
    def _generate_bios_grub_partition(self, device_name):
 
279
        """Generate the bios_grub partition at the beginning of the device."""
 
280
        partition_operation = {
 
281
            "id": "%s-part1" % (device_name),
 
282
            "type": "partition",
 
283
            "number": 1,
 
284
            "offset": "%dB" % INITIAL_PARTITION_OFFSET,
 
285
            "size": "%dB" % BIOS_GRUB_PARTITION_SIZE,
 
286
            "device": device_name,
 
287
            "wipe": "zero",
 
288
            "flag": "bios_grub",
 
289
        }
 
290
        self.storage_config.append(partition_operation)
 
291
 
257
292
    def _generate_partition_operations(self):
258
293
        """Generate all partition operations."""
259
294
        for partition in self.operations["partition"]:
261
296
                # This is the first partition in the boot disk and add prep
262
297
                # partition at the beginning of the partition table.
263
298
                device_name = partition.partition_table.block_device.get_name()
264
 
                self._generate_prep_partition(device_name)
 
299
                if self._requires_prep_partition(
 
300
                        partition.partition_table.block_device):
 
301
                    self._generate_prep_partition(device_name)
 
302
                elif self._requires_bios_grub_partition(
 
303
                        partition.partition_table.block_device):
 
304
                    self._generate_bios_grub_partition(device_name)
 
305
                else:
 
306
                    raise ValueError(
 
307
                        "boot_disk_first_partition set when prep and "
 
308
                        "bios_grub partition are not required.")
265
309
                self._generate_partition_operation(
266
310
                    partition, include_initial=False)
267
311
            else: