Exemplo n.º 1
0
    def _CreateScratchDiskFromDisks(self, disk_spec, disks):
        """Helper method to prepare data disks.

    Given a list of BaseDisk objects, this will do most of the work creating,
    attaching, striping, formatting, and mounting them. If multiple BaseDisk
    objects are passed to this method, it will stripe them, combining them
    into one 'logical' data disk (it will be treated as a single disk from a
    benchmarks perspective). This is intended to be called from within a cloud
    specific VM's CreateScratchDisk method.

    Args:
      disk_spec: The BaseDiskSpec object corresponding to the disk.
      disks: A list of the disk(s) to be created, attached, striped,
          formatted, and mounted. If there is more than one disk in
          the list, then they will be striped together.
    """
        if len(disks) > 1:
            # If the disk_spec called for a striped disk, create one.
            data_disk = disk.StripedDisk(disk_spec, disks)
        else:
            data_disk = disks[0]

        self.scratch_disks.append(data_disk)

        if data_disk.disk_type != disk.LOCAL:
            data_disk.Create()
            data_disk.Attach(self)

        # Create and then run a Diskpart script that will initialize the disks,
        # create a volume, and then format and mount the volume.
        script = ''

        disk_numbers = [str(d.disk_number) for d in disks]
        for disk_number in disk_numbers:
            # For each disk, set the status to online (if it is not already),
            # remove any formatting or partitioning on the disks, and convert
            # it to a dynamic disk so it can be used to create a volume.
            script += ('select disk %s\n'
                       'online disk noerr\n'
                       'attributes disk clear readonly\n'
                       'clean\n'
                       'convert dynamic\n' % disk_number)

        # Create a volume out of the disk(s).
        if data_disk.is_striped:
            script += 'create volume stripe disk=%s\n' % ','.join(disk_numbers)
        else:
            script += 'create volume simple\n'

        # If a mount point has been specified, create the directory where it will be
        # mounted, format the volume, and assign the mount point to the volume.
        if disk_spec.mount_point:
            self.RemoteCommand('mkdir %s' % disk_spec.mount_point)
            script += ('format quick\n'
                       'assign mount=%s\n' % disk_spec.mount_point)

        self._RunDiskpartScript(script)
Exemplo n.º 2
0
    def _CreateScratchDiskFromDisks(self, disk_spec, disks):
        """Helper method to prepare data disks.

    Given a list of BaseDisk objects, this will do most of the work creating,
    attaching, striping, formatting, and mounting them. If multiple BaseDisk
    objects are passed to this method, it will stripe them, combining them
    into one 'logical' data disk (it will be treated as a single disk from a
    benchmarks perspective). This is intended to be called from within a cloud
    specific VM's CreateScratchDisk method.

    Args:
      disk_spec: The BaseDiskSpec object corresponding to the disk.
      disks: A list of the disk(s) to be created, attached, striped,
          formatted, and mounted. If there is more than one disk in
          the list, then they will be striped together.
    """
        if len(disks) > 1:
            # If the disk_spec called for a striped disk, create one.
            disk_spec.device_path = '/dev/md%d' % len(self.scratch_disks)
            data_disk = disk.StripedDisk(disk_spec, disks)
        else:
            data_disk = disks[0]

        self.scratch_disks.append(data_disk)

        if data_disk.disk_type != disk.LOCAL:
            data_disk.Create()
            data_disk.Attach(self)

        if data_disk.is_striped:
            device_paths = [d.GetDevicePath() for d in data_disk.disks]
            self.StripeDisks(device_paths, data_disk.GetDevicePath())

        if disk_spec.mount_point:
            self.FormatDisk(data_disk.GetDevicePath())
            self.MountDisk(data_disk.GetDevicePath(), disk_spec.mount_point)