Package VMBuilder :: Module disk :: Class Disk
[frames] | no frames]

Class Disk

source code

object --+
         |
        Disk

Virtual disk.

Nested Classes
  Partition
Instance Methods
 
__init__(self, vm, filename, size=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
string
devletters(self)
Returns: the series of letters that ought to correspond to the device inside the VM.
source code
 
create(self)
Creates the disk image (if it doesn't already exist).
source code
 
partition(self)
Partitions the disk image.
source code
 
map_partitions(self)
Create loop devices corresponding to the partitions.
source code
 
mkfs(self)
Creates the partitions' filesystems
source code
string
get_grub_id(self)
Returns: name of the disk as known by grub
source code
number
get_index(self)
Returns: index of the disk (starting from 0 for the hypervisor's first disk)
source code
 
unmap(self, ignore_fail=False)
Destroy all mapping devices
source code
 
add_part(self, begin, length, type, mntpnt)
Add a partition to the disk
source code
string
convert(self, destdir, format)
Convert the disk image
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables
  vm
The hypervisor to which the disk belongs.
  filename
The filename of the disk image.
  partitions
The list of partitions on the disk.
  preallocated
Whether the file existed already (True if it did, False if we had to create it).
  size
The size of the disk.
  format_type
The format type of the disks.
Properties

Inherited from object: __class__

Method Details

__init__(self, vm, filename, size=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • vm (Hypervisor) - The Hypervisor to which the disk belongs
  • filename (string) - filename of the disk image
  • size (string or number) - The size of the disk image to create (passed to parse_size). If specified and filename already exists, VMBuilderUserError will be raised. Otherwise, a disk image of this size will be created once create() is called.
Overrides: object.__init__
(inherited documentation)

devletters(self)

source code 
Returns: string
the series of letters that ought to correspond to the device inside the VM. E.g. the first disk of a VM would return 'a', while the 702nd would return 'zz'

create(self)

source code 

Creates the disk image (if it doesn't already exist).

Once this method returns succesfully, filename can be expected to points to point to whatever holds the virtual disk (be it a file, partition, logical volume, etc.).

partition(self)

source code 

Partitions the disk image. First adds a partition table and then adds the individual partitions.

Should only be called once and only after you've added all partitions.

map_partitions(self)

source code 

Create loop devices corresponding to the partitions.

Once this has returned succesfully, each partition's map device is set as its filename attribute.

Call this after partition.

get_grub_id(self)

source code 
Returns: string
name of the disk as known by grub

get_index(self)

source code 
Returns: number
index of the disk (starting from 0 for the hypervisor's first disk)

unmap(self, ignore_fail=False)

source code 

Destroy all mapping devices

Unsets Partitions' and Filesystems' filename attribute

add_part(self, begin, length, type, mntpnt)

source code 

Add a partition to the disk

Parameters:
  • begin (number) - Start offset of the new partition (in megabytes)
  • length () - Size of the new partition (in megabytes)
  • type (string) - Type of the new partition. Valid options are: ext2 ext3 xfs swap linux-swap
  • mntpnt (string) - Intended mountpoint inside the guest of the new partition

convert(self, destdir, format)

source code 

Convert the disk image

Parameters:
  • destdir (string) - Target location of converted disk image
  • format (string) - The target format (as understood by qemu-img or vdi)
Returns: string
the name of the converted image

Instance Variable Details

partitions

The list of partitions on the disk. Is kept in order by add_part.

size

The size of the disk. For preallocated disks, this is detected.

format_type

The format type of the disks. Only used for converted disks.