本文整理汇总了Golang中github.com/vmware/govmomi/vim25/types.VirtualMachineCloneSpec.Snapshot方法的典型用法代码示例。如果您正苦于以下问题:Golang VirtualMachineCloneSpec.Snapshot方法的具体用法?Golang VirtualMachineCloneSpec.Snapshot怎么用?Golang VirtualMachineCloneSpec.Snapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/govmomi/vim25/types.VirtualMachineCloneSpec
的用法示例。
在下文中一共展示了VirtualMachineCloneSpec.Snapshot方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deployVirtualMachine
//.........这里部分代码省略.........
} else {
identity_options = &types.CustomizationLinuxPrep{
HostName: &types.CustomizationFixedName{
Name: strings.Split(vm.name, ".")[0],
},
Domain: vm.domain,
TimeZone: vm.timeZone,
HwClockUTC: types.NewBool(true),
}
}
// create CustomizationSpec
customSpec := types.CustomizationSpec{
Identity: identity_options,
GlobalIPSettings: types.CustomizationGlobalIPSettings{
DnsSuffixList: vm.dnsSuffixes,
DnsServerList: vm.dnsServers,
},
NicSettingMap: networkConfigs,
}
log.Printf("[DEBUG] custom spec: %v", customSpec)
// make vm clone spec
cloneSpec := types.VirtualMachineCloneSpec{
Location: relocateSpec,
Template: false,
Config: &configSpec,
PowerOn: false,
}
if vm.linkedClone {
if err != nil {
return fmt.Errorf("Error reading base VM properties: %s", err)
}
if template_mo.Snapshot == nil {
return fmt.Errorf("`linkedClone=true`, but image VM has no snapshots")
}
cloneSpec.Snapshot = template_mo.Snapshot.CurrentSnapshot
}
log.Printf("[DEBUG] clone spec: %v", cloneSpec)
task, err := template.Clone(context.TODO(), folder, vm.name, cloneSpec)
if err != nil {
return err
}
_, err = task.WaitForResult(context.TODO(), nil)
if err != nil {
return err
}
newVM, err := finder.VirtualMachine(context.TODO(), vm.Path())
if err != nil {
return err
}
log.Printf("[DEBUG] new vm: %v", newVM)
devices, err := newVM.Device(context.TODO())
if err != nil {
log.Printf("[DEBUG] Template devices can't be found")
return err
}
for _, dvc := range devices {
// Issue 3559/3560: Delete all ethernet devices to add the correct ones later
if devices.Type(dvc) == "ethernet" {
err := newVM.RemoveDevice(context.TODO(), dvc)
示例2: Create
//.........这里部分代码省略.........
image, err := d.getVMTemplate(d.VMTemplate, dcName, c.Client)
if err != nil {
return err
}
var imageMoRef mo.VirtualMachine
err = image.Properties(ctx, image.Reference(), []string{"parent", "config.template", "resourcePool", "snapshot", "guest.toolsVersionStatus2", "config.guestFullName"}, &imageMoRef)
if err != nil {
return fmt.Errorf("Error reading base VM properties: %s", err)
}
// Create a CloneSpec to clone the VM
datastoreref := dss.Reference()
folderref := folder.Reference()
poolref := rp.Reference()
relocateSpec.Datastore = &datastoreref
relocateSpec.Folder = &folderref
relocateSpec.Pool = &poolref
spec := types.VirtualMachineConfigSpec{
Name: d.MachineName,
GuestId: "otherLinux64Guest",
Files: &types.VirtualMachineFileInfo{VmPathName: fmt.Sprintf("[%s]", dss.Name())},
NumCPUs: d.CPU,
MemoryMB: int64(d.Memory),
}
cloneSpec := types.VirtualMachineCloneSpec{
Config: &spec,
}
if imageMoRef.Snapshot != nil {
relocateSpec.DiskMoveType = "createNewChildDiskBacking"
cloneSpec.Snapshot = imageMoRef.Snapshot.CurrentSnapshot
} else {
return fmt.Errorf("No snapshots for template, cannot use for cloning")
}
if d.Network != "" {
// search for the first network card of the source
devices, err := image.Device(ctx)
if err != nil {
return fmt.Errorf("Error reading base VM devices: %s", err)
}
var card *types.VirtualEthernetCard
for _, device := range devices {
if c, ok := device.(types.BaseVirtualEthernetCard); ok {
card = c.GetVirtualEthernetCard()
break
}
}
if card == nil {
return fmt.Errorf("No network device found for the template.")
}
// get the new backing information
net, err := f.NetworkOrDefault(ctx, d.Network)
if err != nil {
return fmt.Errorf("Network not found: %s", err)
}
backing, err := net.EthernetCardBackingInfo(ctx)
if err != nil {
return fmt.Errorf("Network backing not found: %s", err)
}
示例3: deployVirtualMachine
//.........这里部分代码省略.........
Identity: &types.CustomizationLinuxPrep{
HostName: &types.CustomizationFixedName{
Name: strings.Split(vm.name, ".")[0],
},
Domain: vm.domain,
TimeZone: vm.timeZone,
HwClockUTC: types.NewBool(true),
},
GlobalIPSettings: types.CustomizationGlobalIPSettings{
DnsSuffixList: vm.dnsSuffixes,
DnsServerList: vm.dnsServers,
},
NicSettingMap: networkConfigs,
}
log.Printf("[DEBUG] custom spec: %v", customSpec)
// make vm clone spec
cloneSpec := types.VirtualMachineCloneSpec{
Location: relocateSpec,
Template: false,
Config: &configSpec,
PowerOn: false,
}
// We need to supply a snapshot if it's a linked clone.
if vm.template.linked {
var mvm mo.VirtualMachine
collector := property.DefaultCollector(c.Client)
if err := collector.RetrieveOne(context.TODO(), template.Reference(), []string{"snapshot"}, &mvm); err != nil {
return err
}
if mvm.Snapshot == nil || mvm.Snapshot.CurrentSnapshot == nil {
return errors.New("The source of the linked clone must have at least one existing snapshot")
}
if vm.template.snapshot == "" {
cloneSpec.Snapshot = mvm.Snapshot.CurrentSnapshot
} else {
// Search for the requested snapshot. Error out if we can't find it.
for _, s := range mvm.Snapshot.RootSnapshotList {
if s.Name == vm.template.snapshot {
cloneSpec.Snapshot = &s.Snapshot
}
}
if cloneSpec.Snapshot == nil {
return errors.New(fmt.Sprintf("No snapshot found with the name %s", vm.template.snapshot))
}
}
}
log.Printf("[DEBUG] clone spec: %v", cloneSpec)
task, err := template.Clone(context.TODO(), folder, vm.name, cloneSpec)
if err != nil {
return err
}
_, err = task.WaitForResult(context.TODO(), nil)
if err != nil {
return err
}
newVM, err := finder.VirtualMachine(context.TODO(), vm.Path())
示例4: resourceVirtualMachineCreate
//.........这里部分代码省略.........
if d.Get("linked_clone").(bool) {
relocateSpec.DiskMoveType = "createNewChildDiskBacking"
}
var confSpec types.VirtualMachineConfigSpec
if d.Get("cpus") != nil {
confSpec.NumCPUs = d.Get("cpus").(int)
}
if d.Get("memory") != nil {
confSpec.MemoryMB = int64(d.Get("memory").(int))
}
params := d.Get("configuration_parameters").(map[string]interface{})
var ov []types.BaseOptionValue
if len(params) > 0 {
for k, v := range params {
key := k
value := v
o := types.OptionValue{
Key: key,
Value: &value,
}
ov = append(ov, &o)
}
confSpec.ExtraConfig = ov
}
cloneSpec := types.VirtualMachineCloneSpec{
Location: relocateSpec,
Config: &confSpec,
PowerOn: d.Get("power_on").(bool),
}
if d.Get("linked_clone").(bool) {
if image_mo.Snapshot == nil {
return fmt.Errorf("`linked_clone=true`, but image VM has no snapshots")
}
cloneSpec.Snapshot = image_mo.Snapshot.CurrentSnapshot
}
domain := d.Get("domain").(string)
ip_address := d.Get("ip_address").(string)
if domain != "" {
if image_mo.Guest.ToolsVersionStatus2 == "guestToolsNotInstalled" {
return fmt.Errorf("VMware tools are not installed in base VM")
}
if !strings.Contains(image_mo.Config.GuestFullName, "Linux") && !strings.Contains(image_mo.Config.GuestFullName, "CentOS") {
return fmt.Errorf("Guest customization is supported only for Linux. Base image OS is: %s", image_mo.Config.GuestFullName)
}
customizationSpec := types.CustomizationSpec{
GlobalIPSettings: types.CustomizationGlobalIPSettings{},
Identity: &types.CustomizationLinuxPrep{
HostName: &types.CustomizationVirtualMachineName{},
Domain: domain,
},
NicSettingMap: []types.CustomizationAdapterMapping{
{
Adapter: types.CustomizationIPSettings{},
},
},
}
if ip_address != "" {
mask := d.Get("subnet_mask").(string)
if mask == "" {
return fmt.Errorf("'subnet_mask' must be set, if static 'ip_address' is specified")
}
customizationSpec.NicSettingMap[0].Adapter.Ip = &types.CustomizationFixedIp{
示例5: setupVirtualMachine
//.........这里部分代码省略.........
Operation: types.VirtualDeviceConfigSpecOperationAdd,
Device: scsi,
})
configSpec.Files = &types.VirtualMachineFileInfo{VmPathName: fmt.Sprintf("[%s]", mds.Name)}
task, err = folder.CreateVM(context.TODO(), configSpec, resourcePool, nil)
if err != nil {
log.Printf("[ERROR] %s", err)
}
err = task.Wait(context.TODO())
if err != nil {
log.Printf("[ERROR] %s", err)
}
} else {
relocateSpec, err := buildVMRelocateSpec(resourcePool, datastore, template, vm.linkedClone, vm.hardDisks[0].initType)
if err != nil {
return err
}
log.Printf("[DEBUG] relocate spec: %v", relocateSpec)
// make vm clone spec
cloneSpec := types.VirtualMachineCloneSpec{
Location: relocateSpec,
Template: false,
Config: &configSpec,
PowerOn: false,
}
if vm.linkedClone {
if template_mo.Snapshot == nil {
return fmt.Errorf("`linkedClone=true`, but image VM has no snapshots")
}
cloneSpec.Snapshot = template_mo.Snapshot.CurrentSnapshot
}
log.Printf("[DEBUG] clone spec: %v", cloneSpec)
task, err = template.Clone(context.TODO(), folder, vm.name, cloneSpec)
if err != nil {
return err
}
}
err = task.Wait(context.TODO())
if err != nil {
log.Printf("[ERROR] %s", err)
}
newVM, err := finder.VirtualMachine(context.TODO(), vm.Path())
if err != nil {
return err
}
log.Printf("[DEBUG] new vm: %v", newVM)
devices, err := newVM.Device(context.TODO())
if err != nil {
log.Printf("[DEBUG] Template devices can't be found")
return err
}
for _, dvc := range devices {
// Issue 3559/3560: Delete all ethernet devices to add the correct ones later
if devices.Type(dvc) == "ethernet" {