本文整理汇总了Golang中github.com/vmware/govmomi/vim25/types.VirtualMachineCloneSpec类的典型用法代码示例。如果您正苦于以下问题:Golang VirtualMachineCloneSpec类的具体用法?Golang VirtualMachineCloneSpec怎么用?Golang VirtualMachineCloneSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VirtualMachineCloneSpec类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: deployVirtualMachine
//.........这里部分代码省略.........
PlainText: true,
Value: vm.windowsOptionalConfig.adminPassword,
}
}
identity_options = &types.CustomizationSysprep{
GuiUnattended: guiUnattended,
Identification: customIdentification,
UserData: userData,
}
} 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)
开发者ID:mafrosis,项目名称:terraform,代码行数:66,代码来源:resource_vsphere_virtual_machine.go
示例2: Create
//.........这里部分代码省略.........
dcName, err := d.getDatacenterName(dc)
if err != nil {
return err
}
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)
}
开发者ID:containerx,项目名称:machine,代码行数:67,代码来源:vsphere.go
示例3: deployVirtualMachine
//.........这里部分代码省略.........
var ov []types.BaseOptionValue
for k, v := range vm.customConfigurations {
key := k
value := v
o := types.OptionValue{
Key: key,
Value: &value,
}
ov = append(ov, &o)
}
configSpec.ExtraConfig = ov
log.Printf("[DEBUG] virtual machine Extra Config spec: %v", configSpec.ExtraConfig)
}
// create CustomizationSpec
customSpec := types.CustomizationSpec{
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))
}
开发者ID:NetworkBytes,项目名称:terraform,代码行数:67,代码来源:resource_vsphere_virtual_machine.go
示例4: resourceVirtualMachineCreate
//.........这里部分代码省略.........
}
var relocateSpec types.VirtualMachineRelocateSpec
var pool_mor types.ManagedObjectReference
pool_mor = pool_ref.Reference()
relocateSpec.Pool = &pool_mor
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{},
},
},
}
开发者ID:ae6rt,项目名称:terraform-vsphere,代码行数:67,代码来源:resource_virtual_machine.go
示例5: setupVirtualMachine
//.........这里部分代码省略.........
log.Printf("[DEBUG] datastore: %#v", mds.Name)
scsi, err := object.SCSIControllerTypes().CreateSCSIController("scsi")
if err != nil {
log.Printf("[ERROR] %s", err)
}
configSpec.DeviceChange = append(configSpec.DeviceChange, &types.VirtualDeviceConfigSpec{
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 {
开发者ID:srikalyan,项目名称:terraform,代码行数:67,代码来源:resource_vsphere_virtual_machine.go
注:本文中的github.com/vmware/govmomi/vim25/types.VirtualMachineCloneSpec类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论