本文整理汇总了Golang中github.com/vmware/govmomi/object.VirtualMachine.Clone方法的典型用法代码示例。如果您正苦于以下问题:Golang VirtualMachine.Clone方法的具体用法?Golang VirtualMachine.Clone怎么用?Golang VirtualMachine.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/govmomi/object.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CloneVM
func (cmd *vmdk) CloneVM(vm *object.VirtualMachine, name string) (*object.VirtualMachine, error) {
folders, err := cmd.Datacenter.Folders(context.TODO())
if err != nil {
return nil, err
}
spec := types.VirtualMachineCloneSpec{
Config: &types.VirtualMachineConfigSpec{},
Location: types.VirtualMachineRelocateSpec{},
}
task, err := vm.Clone(context.TODO(), folders.VmFolder, name, spec)
if err != nil {
return nil, err
}
info, err := task.WaitForResult(context.TODO(), nil)
if err != nil {
return nil, err
}
return object.NewVirtualMachine(cmd.Client, info.Result.(types.ManagedObjectReference)), nil
}
示例2: setupVirtualMachine
//.........这里部分代码省略.........
o := types.OptionValue{
Key: key,
Value: &value,
}
log.Printf("[DEBUG] virtual machine Extra Config spec: %s,%s", k, v)
ov = append(ov, &o)
}
configSpec.ExtraConfig = ov
log.Printf("[DEBUG] virtual machine Extra Config spec: %v", configSpec.ExtraConfig)
}
var datastore *object.Datastore
if vm.datastore == "" {
datastore, err = finder.DefaultDatastore(context.TODO())
if err != nil {
return err
}
} else {
datastore, err = finder.Datastore(context.TODO(), vm.datastore)
if err != nil {
// TODO: datastore cluster support in govmomi finder function
d, err := getDatastoreObject(c, dcFolders, vm.datastore)
if err != nil {
return err
}
if d.Type == "StoragePod" {
sp := object.StoragePod{
Folder: object.NewFolder(c.Client, d),
}
var sps types.StoragePlacementSpec
if vm.template != "" {
sps = buildStoragePlacementSpecClone(c, dcFolders, template, resourcePool, sp)
} else {
sps = buildStoragePlacementSpecCreate(dcFolders, resourcePool, sp, configSpec)
}
datastore, err = findDatastore(c, sps)
if err != nil {
return err
}
} else {
datastore = object.NewDatastore(c.Client, d)
}
}
}
log.Printf("[DEBUG] datastore: %#v", datastore)
// network
networkDevices := []types.BaseVirtualDeviceConfigSpec{}
networkConfigs := []types.CustomizationAdapterMapping{}
for _, network := range vm.networkInterfaces {
// network device
var networkDeviceType string
if vm.template == "" {
networkDeviceType = "e1000"
} else {
networkDeviceType = "vmxnet3"
}
nd, err := buildNetworkDevice(finder, network.label, networkDeviceType)
if err != nil {
return err
}
networkDevices = append(networkDevices, nd)