Documentation
¶
Index ¶
- Constants
- Variables
- func Import(ctx context.Context, c *vim25.Client, name string, datastore *object.Datastore, ...) error
- type Descriptor
- type DiskContentID
- type Extent
- type ImportParams
- type Info
- type SparseExtentHeaderOnDisk
- type SparseGrainLBAHeaderOnDisk
- type SparseMetaDataMarkerOnDisk
- type StreamOptimizedWriter
- type VirtualDiskCryptoKey
- type VirtualDiskInfo
Constants ¶
const ( // SparseMagicNumber is copied from // https://github.com/vmware/open-vmdk/blob/c977d2012d33cff8df3e809f20aa5df01e017f64/vmdk/vmware_vmdk.h#L48. SparseMagicNumber = 0x564d444b // "VMDK" // SparseVersionIncompatFlags is copied from // https://github.com/vmware/open-vmdk/blob/c977d2012d33cff8df3e809f20aa5df01e017f64/vmdk/vmware_vmdk.h#L51. SparseVersionIncompatFlags = 3 // SparseFlagCompressed is copied from // https://github.com/vmware/open-vmdk/blob/c977d2012d33cff8df3e809f20aa5df01e017f64/vmdk/vmware_vmdk.h#L61. SparseFlagCompressed = (1 << 16) // SparseFlagEmbeddedLBA is copied from // https://github.com/vmware/open-vmdk/blob/c977d2012d33cff8df3e809f20aa5df01e017f64/vmdk/vmware_vmdk.h#L62. SparseFlagEmbeddedLBA = (1 << 17) // SparseFlagValidNewlineDetector is copied from // https://github.com/vmware/open-vmdk/blob/c977d2012d33cff8df3e809f20aa5df01e017f64/vmdk/vmware_vmdk.h#L57. SparseFlagValidNewlineDetector = (1 << 0) // GrainMarkerEndOfStream is copied from // https://github.com/vmware/open-vmdk/blob/c977d2012d33cff8df3e809f20aa5df01e017f64/vmdk/vmware_vmdk.h#L93. GrainMarkerEndOfStream = 0 // GrainSize represents the size of a grain in sectors (128 sectors = 64KB). // This is the default grain size for VMDK sparse extents as specified in the VMDK specification. // The grain size must be a power of 2 and greater than 8 (4KB). GrainSize = 128 // GrainDirectoryOffset is the offset in sectors where the Grain Directory starts. // This is calculated as 1 sector for the sparse extent header + 20 sectors for the embedded descriptor. GrainDirectoryOffset = 1 + 20 )
const (
SectorSize = 512
)
Variables ¶
var (
ErrInvalidFormat = errors.New("vmdk: invalid format (must be streamOptimized)")
)
Functions ¶
Types ¶
type Descriptor ¶ added in v0.47.0
type Descriptor struct {
Encoding string `json:"encoding"`
Version int `json:"version"`
CID DiskContentID `json:"cid"`
ParentCID DiskContentID `json:"parentCID"`
Type string `json:"type"`
Extent []Extent `json:"extent"`
DDB map[string]string `json:"ddb"`
EncryptionKeys *crypto.KeyLocator `json:"encryptionKeys,omitempty"`
}
func NewDescriptor ¶ added in v0.47.0
func NewDescriptor(extent ...Extent) *Descriptor
func ParseDescriptor ¶ added in v0.47.0
func ParseDescriptor(r io.Reader) (*Descriptor, error)
func (*Descriptor) Capacity ¶ added in v0.51.0
func (d *Descriptor) Capacity() int64
Capacity in bytes of the vmdk
type DiskContentID ¶ added in v0.47.0
type DiskContentID uint32
func (DiskContentID) String ¶ added in v0.47.0
func (cid DiskContentID) String() string
type ImportParams ¶
type ImportParams struct {
Path string
Logger progress.Sinker
Type types.VirtualDiskType
Force bool
Datacenter *object.Datacenter
Pool *object.ResourcePool
Folder *object.Folder
Host *object.HostSystem
}
ImportParams contains the set of optional params to the Import function. Note that "optional" may depend on environment, such as ESX or vCenter.
type Info ¶ added in v0.39.0
type Info struct {
// SparseExtentHeaderOnDisk https://github.com/vmware/open-vmdk/blob/master/vmdk/vmware_vmdk.h#L24
Header struct {
MagicNumber uint32
Version uint32
Flags uint32
Capacity int64
// contains filtered or unexported fields
} `json:"header"`
Descriptor *Descriptor `json:"descriptor"`
Capacity int64 `json:"capacity"`
Size int64 `json:"size"`
Name string `json:"name"`
ImportName string `json:"importName"`
}
Info is used to inspect a vmdk and generate an ovf template
func Seek ¶ added in v0.51.0
Seek reads the vmdk header and descriptor. ErrInvalidFormat is returned if the format (MagicNumber) is not streamOptimized. Capacity field is set for use with ovf descriptor generation.
func Stat ¶ added in v0.39.0
Stat opens file name and calls Seek() to read the vmdk header and descriptor. Size field is set to the file size, for use as Content-Length when uploading. Name field is set to filepath.Base(name). ImportName is set to Name with .vmdk extension removed.
type SparseExtentHeaderOnDisk ¶ added in v0.53.0
type SparseExtentHeaderOnDisk struct {
MagicNumber uint32
Version uint32
Flags uint32
Capacity uint64
GrainSize uint64
DescriptorOffset uint64
DescriptorSize uint64
NumGTEsPerGT uint32
RGDOffset uint64
GDOffset uint64
Overhead uint64
UncleanShutdown byte
SingleEndLine byte
NonEndLine byte
DoubleEndLineChar1 byte
DoubleEndLineChar2 byte
CompressAlgorithm uint16
Padding [433]byte
}
SparseExtentHeaderOnDisk represents the on-disk structure of a sparse VMDK extent header. Corresponds to SparseExtentHeaderOnDisk in open-vmdk/vmdk/sparse.h
type SparseGrainLBAHeaderOnDisk ¶ added in v0.53.0
SparseGrainLBAHeaderOnDisk represents the on-disk structure of a sparse grain LBA header. Corresponds to SparseGrainLBAHeaderOnDisk in open-vmdk/vmdk/sparse.h
type SparseMetaDataMarkerOnDisk ¶ added in v0.53.0
type SparseMetaDataMarkerOnDisk struct {
NumSectors uint64
Size uint32
SectorType uint32
Padding [496]byte
}
SparseMetaDataMarkerOnDisk represents the on-disk structure of a sparse metadata marker. Corresponds to SparseMetaDataMarkerOnDisk in open-vmdk/vmdk/sparse.h
type StreamOptimizedWriter ¶ added in v0.53.0
type StreamOptimizedWriter struct {
Capacity int64
GrainTables []uint64 // stores individual grain table locations
GrainDirectory []uint64 // stores grain table locations
// contains filtered or unexported fields
}
StreamOptimizedWriter creates stream-optimised VMDK files. It converts raw disk images into compressed VMDK format on-the-fly.
func NewStreamOptimizedWriter ¶ added in v0.53.0
func NewStreamOptimizedWriter(filename string, capacity int64) (*StreamOptimizedWriter, error)
NewStreamOptimizedWriter creates a new StreamOptimizedWriter for writing VMDK files. It takes the output filename and the total capacity of the virtual disk in bytes as inputs It returns a pointer to the StreamOptimizedWriter and an error if any.
Corresponds to StreamOptimized_Create() in open-vmdk/vmdk/sparse.c
func (*StreamOptimizedWriter) Abort ¶ added in v0.53.0
func (w *StreamOptimizedWriter) Abort() error
Abort cleans up the VMDK file in case of an error during writing. It closes and removes the partially written file. Corresponds to StreamOptimizedAbort() in open-vmdk/vmdk/sparse.c
func (*StreamOptimizedWriter) Close ¶ added in v0.53.0
func (w *StreamOptimizedWriter) Close() error
Close finalizes the VMDK file by writing Grain Tables, Grain Directory, and Metadata Marker. And marking the End of Stream. Corresponds to StreamOptimizedClose() in open-vmdk/vmdk/sparse.c
func (*StreamOptimizedWriter) Write ¶ added in v0.53.0
func (w *StreamOptimizedWriter) Write(data io.Reader) error
Write reads raw disk data from the provided io.Reader, compresses it, and writes it to the VMDK file. It handles grain allocation, compression, and updates the Grain Tables and Grain Directory accordingly. Corresponds to StreamOptimizedPwrite() in open-vmdk/vmdk/sparse.c
type VirtualDiskCryptoKey ¶ added in v0.46.0
type VirtualDiskInfo ¶ added in v0.39.0
type VirtualDiskInfo struct {
CapacityInBytes int64
DeviceKey int32
FileName string
Size int64
UniqueSize int64
CryptoKey VirtualDiskCryptoKey
}
func GetVirtualDiskInfoByUUID ¶ added in v0.39.0
func GetVirtualDiskInfoByUUID( ctx context.Context, client *vim25.Client, mo mo.VirtualMachine, fetchProperties bool, excludeSnapshots bool, diskUUID string, ) (VirtualDiskInfo, error)
GetVirtualDiskInfoByUUID returns information about a virtual disk identified by the provided UUID. This method is valid for the following backing types:
- VirtualDiskFlatVer2BackingInfo - VirtualDiskSeSparseBackingInfo - VirtualDiskRawDiskMappingVer1BackingInfo - VirtualDiskSparseVer2BackingInfo - VirtualDiskRawDiskVer2BackingInfo
These are the only backing types that have a UUID property for comparing the provided value.
excludeSnapshots is used to determine if the delta disks for snapshot should be excluded when calculating the disk size. If true, only the file keys from the last chain, which is last delta disk, will be used. If false, all the file keys from all the chains will be included.