vsphereimages

package module
v0.0.0-...-ec4c6ea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2018 License: MIT Imports: 15 Imported by: 1

README

vsphere-images

Usage

Copy image

Copy foobar from vSphere 192.0.2.1 to 192.0.2.2:

$ vphere-images copy-image \
	--src-url=https://admin:password@192.0.2.1/sdk \
	--dest-url=https://admin:password@192.0.2.2/sdk \
	--dest-datastore-path=/Datacenter-2/datastore/DS-1 \
	--dest-pool-path=/Datacenter-2/host/main_pool \
	--dest-host-path=/Datacenter-2/host/main_pool/host01 \
	--dest-network-name=/Datacenter-2/network/PortGroupName \
	"/Datacenter-1/vm/base/foobar" \
	"/Datacenter-2/vm/base/foobar"

The destination pool and host are both required, even if the destination pool has DRS enabled.

Move image in datastore
$ vsphere-images datastore-move \
	--vsphere-url=https://admin:password@192.0.2.1/sdk \
	"/Datacenter-2/vm/base/foobar" \
	"[DS-1] /foobar" \
	"[DS-1] /images/foobar"
Resnapshot an image
$ vsphere-images resnapshot \
	--vsphere-url=https://admin:password@192.0.2.1/sdk \
	"/Datacenter-2/vm/base/foobar"

License

See LICENSE file.

© 2016 Travis CI GmbH

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckInHost

func CheckInHost(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, clusterInventoryPath string, destinationClusterPath string, s progress.Sinker) (*object.HostSystem, error)

func CheckOutHost

func CheckOutHost(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, clusterInventoryPath string, destinationClusterPath string, s progress.Sinker) (*object.HostSystem, error)

func CheckOutSelectedHost

func CheckOutSelectedHost(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, host *object.HostSystem, destinationClusterPath string, s progress.Sinker) error

func ConfigureImage

func ConfigureImage(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, imageInventoryPath string, config types.VirtualMachineConfigSpec, networkName string, s progress.Sinker) error

func CopyImage

func CopyImage(ctx context.Context, source ImageSource, destination ImageDestination, s progress.Sinker) error
Example
package main

import (
	"context"
	"net/url"

	vsphereimages "github.com/travis-ci/vsphere-images"
)

func main() {
	vSphereSourceURL, _ := url.Parse("https://admin@password:vsphere1.example.com/sdk")
	vSphereDestinationURL, _ := url.Parse("https://admin@password:vsphere2.example.com/sdk")

	source := vsphereimages.ImageSource{
		VSphereEndpoint: vSphereSourceURL,
		VMPath:          "/dc01/vm/base vms/foo",
	}
	destination := vsphereimages.ImageDestination{
		VSphereEndpoint:  vSphereDestinationURL,
		FolderPath:       "/dc02/vm/base vms/",
		DatastorePath:    "/dc02/datastore/main-datastore",
		ResourcePoolPath: "/dc02/host/main-pool",
		HostPath:         "/dc02/host/main-pool/host01",
		VMName:           "foo",
	}

	vsphereimages.CopyImage(context.TODO(), source, destination, nil)
}
Output:

func DatastoreMoveImage

func DatastoreMoveImage(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, imageInventoryPath, srcDatastorePath, dstDatastorePath string, s progress.Sinker) error

func IsHostCheckedOut

func IsHostCheckedOut(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, destinationClusterPath string) (bool, error)

func ListImages

func ListImages(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, folderPath string) ([]*object.VirtualMachine, error)

ListImages returns a list of all of the virtual machines in a folder.

func MigrateImage

func MigrateImage(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, imageInventoryPath string, poolInventoryPath string, s progress.Sinker) error

func MoveImage

func MoveImage(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, imageInventoryPath string, newFolderPath string, newName string, s progress.Sinker) error

func RestoreBackup

func RestoreBackup(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, sourceImagePath string, destinationFolderPath string, defaultDatastorePath string, defaultResourcePool string, s progress.Sinker) error

RestoreBackup clones a backed up VM image into its original location within the same datacenter.

The VM will be cloned initialially with its name suffixed with "-restoring" in the destination folder. Once the clone is complete, the cloned VM will receive a new base snapshot. If there is an existing VM at the destination path, it will be renamed with a "-old" suffix. Finally, the restored VM will be renamed to match its original name.

func SelectAvailableHost

func SelectAvailableHost(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, clusterInventoryPath string) (*object.HostSystem, error)

func SnapshotImage

func SnapshotImage(ctx context.Context, vSphereEndpoint *url.URL, vSphereInsecureSkipVerify bool, imageInventoryPath string, s progress.Sinker) error

Types

type ImageDestination

type ImageDestination struct {
	// VSphereEndpoint is the URL to the vSphere API, including the
	// credentials. Usually this is something like
	// `https://user@password:your-vsphere-host/sdk`.
	VSphereEndpoint *url.URL

	// VSphereInsecureSkipVerify controls whether the server's certificate
	// chain and hostname should be verified. If VSphereInsecureSkipVerify is
	// true, any certificate presented by the server and any host name in that
	// certificate will be accepted. See also
	// crypto/tls.Config.InsecureSkipVerify.
	VSphereInsecureSkipVerify bool

	// VSphereSHA1Fingerprint is the SHA-1 fingerprint of the vSphere API
	// endpoint. It should be formatted as a series of :-separated uppercase
	// hexadecimal numbers. If the string is empty, the ImageCopier will
	// attempt to connect to the endpoint and use that fingerprint.
	VSphereSHA1Fingerprint string

	// FolderPath is the inventory path to the folder in the destination
	// vCenter to copy the VM to. Folder inventory paths usually look something
	// like `/your-datacenter/vm/folder-name`.
	FolderPath string

	// DatastorePath is the inventory path to the datastore in the destination
	// vCenter to copy the VM to. Datastore inventory paths usually look
	// something like `/your-datacenter/datastore/datastore-name`.
	DatastorePath string

	// ResourcePoolPath is the inventory path to the resource pool in the
	// destination vCenter to copy the VM to. Resource pool paths usually look
	// something like `/your-datacenter/host/pool-name`.
	ResourcePoolPath string

	// HostPath is the inventory path to the host in the destination vCenter to
	// copy the VM to. Note that this host should be a part of the resource
	// pool in ResourcePoolPath. Host inventory paths for hosts in a resource
	// pool usually look something like
	// `/your-datacenter/host/pool-name/host-name`.
	HostPath string

	// NetworkPath is the inventory path to the network (dvSwitch, dvPortGroup,
	// etc.) to connect the copied VM to. Network inventory paths usually look
	// something like `/your-datacenter/network/name-of-portgroup`.
	NetworkPath string

	// VMName is the name to give to the destination VM.
	VMName string
}

type ImageSource

type ImageSource struct {
	// VSphereEndpoint is the URL to the vSphere API, including the
	// credentials. Usually this is something like
	// `https://user@password:your-vsphere-host/sdk`.
	VSphereEndpoint *url.URL

	// VSphereInsecureSkipVerify controls whether the server's certificate
	// chain and hostname should be verified. If VSphereInsecureSkipVerify is
	// true, any certificate presented by the server and any host name in that
	// certificate will be accepted. See also
	// crypto/tls.Config.InsecureSkipVerify.
	VSphereInsecureSkipVerify bool

	// VMPath is the inventory path to the source VM. This is usually something
	// like `/your-datacenter/vm/folder-name/vm-name`.
	VMPath string
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL