本文整理汇总了Golang中github.com/vmware/vic/lib/config.VirtualContainerHostConfigSpec.SetMoref方法的典型用法代码示例。如果您正苦于以下问题:Golang VirtualContainerHostConfigSpec.SetMoref方法的具体用法?Golang VirtualContainerHostConfigSpec.SetMoref怎么用?Golang VirtualContainerHostConfigSpec.SetMoref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/vic/lib/config.VirtualContainerHostConfigSpec
的用法示例。
在下文中一共展示了VirtualContainerHostConfigSpec.SetMoref方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createAppliance
func createAppliance(ctx context.Context, sess *session.Session, conf *config.VirtualContainerHostConfigSpec, vConf *data.InstallerData, hasErr bool, t *testing.T) {
var err error
d := &Dispatcher{
session: sess,
ctx: ctx,
isVC: sess.IsVC(),
force: false,
}
delete(conf.Networks, "bridge") // FIXME: cannot create bridge network in simulator
if d.isVC {
if d.vchVapp, err = d.createVApp(conf, vConf); err != nil {
// FIXME: Got error: ServerFaultCode: ResourcePool:resourcepool-14 does not implement: CreateVApp. Simulator need to implement CreateVApp
// t.Errorf("Unable to create virtual app: %s", err)
}
}
if d.vchPool, err = d.createResourcePool(conf, vConf); err != nil {
t.Errorf("Unable to create resource pool: %s", err)
}
spec, err := d.createApplianceSpec(conf, vConf)
if err != nil {
t.Errorf("Unable to create appliance spec: %s", err)
return
}
// create appliance VM
info, err := tasks.WaitForResult(d.ctx, func(ctx context.Context) (tasks.ResultWaiter, error) {
return d.session.Folders(ctx).VmFolder.CreateVM(ctx, *spec, d.vchPool, d.session.Host)
})
// get VM reference and save it
moref := info.Result.(types.ManagedObjectReference)
conf.SetMoref(&moref)
obj, err := d.session.Finder.ObjectReference(d.ctx, moref)
if err != nil {
t.Errorf("Failed to reacquire reference to appliance VM after creation: %s", err)
return
}
gvm, ok := obj.(*object.VirtualMachine)
if !ok {
t.Errorf("Required reference after appliance creation was not for a VM: %T", obj)
return
}
vm2 := vm.NewVirtualMachineFromVM(d.ctx, d.session, gvm)
uuid, err := vm2.UUID(d.ctx)
if err != nil {
t.Errorf("Failed to get VM UUID: %s", err)
return
}
t.Logf("uuid: %s", uuid)
// leverage create volume method to create image datastore
conf.VolumeLocations["images-store"], _ = url.Parse(fmt.Sprintf("ds://LocalDS_0/VIC/%s/images", uuid))
if err := d.createVolumeStores(conf); err != nil {
t.Errorf("Unable to create volume stores: %s", err)
return
}
}
示例2: createAppliance
func (d *Dispatcher) createAppliance(conf *config.VirtualContainerHostConfigSpec, settings *data.InstallerData) error {
defer trace.End(trace.Begin(""))
log.Infof("Creating appliance on target")
spec, err := d.createApplianceSpec(conf, settings)
if err != nil {
log.Errorf("Unable to create appliance spec: %s", err)
return err
}
var info *types.TaskInfo
// create appliance VM
if d.isVC && d.vchVapp != nil {
info, err = tasks.WaitForResult(d.ctx, func(ctx context.Context) (tasks.ResultWaiter, error) {
return d.vchVapp.CreateChildVM_Task(ctx, *spec, d.session.Host)
})
} else {
// if vapp is not created, fall back to create VM under default resource pool
info, err = tasks.WaitForResult(d.ctx, func(ctx context.Context) (tasks.ResultWaiter, error) {
return d.session.Folders(ctx).VmFolder.CreateVM(ctx, *spec, d.vchPool, d.session.Host)
})
}
if err != nil {
log.Errorf("Unable to create appliance VM: %s", err)
return err
}
if info.Error != nil || info.State != types.TaskInfoStateSuccess {
log.Errorf("Create appliance reported: %s", info.Error.LocalizedMessage)
}
// get VM reference and save it
moref := info.Result.(types.ManagedObjectReference)
conf.SetMoref(&moref)
obj, err := d.session.Finder.ObjectReference(d.ctx, moref)
if err != nil {
log.Errorf("Failed to reacquire reference to appliance VM after creation: %s", err)
return err
}
gvm, ok := obj.(*object.VirtualMachine)
if !ok {
return fmt.Errorf("Required reference after appliance creation was not for a VM: %T", obj)
}
vm2 := vm.NewVirtualMachineFromVM(d.ctx, d.session, gvm)
// update the displayname to the actual folder name used
if d.vmPathName, err = vm2.FolderName(d.ctx); err != nil {
log.Errorf("Failed to get canonical name for appliance: %s", err)
return err
}
log.Debugf("vm folder name: %q", d.vmPathName)
log.Debugf("vm inventory path: %q", vm2.InventoryPath)
// create an extension to register the appliance as
if err = d.GenerateExtensionName(conf, vm2); err != nil {
return errors.Errorf("Could not generate extension name during appliance creation due to error: %s", err)
}
settings.Extension = types.Extension{
Description: &types.Description{
Label: "VIC",
Summary: "vSphere Integrated Containers Virtual Container Host",
},
Company: "VMware, Inc.",
Version: "0.0",
Key: conf.ExtensionName,
}
conf.AddComponent("vicadmin", &executor.SessionConfig{
User: "vicadmin",
Group: "vicadmin",
Cmd: executor.Cmd{
Path: "/sbin/vicadmin",
Args: []string{
"/sbin/vicadmin",
"-docker-host=unix:///var/run/docker.sock",
// FIXME: hack during config migration
"-insecure",
"-ds=" + conf.ImageStores[0].Host,
"-cluster=" + settings.ClusterPath,
"-pool=" + settings.ResourcePoolPath,
"-vm-path=" + vm2.InventoryPath,
},
Env: []string{
"PATH=/sbin:/bin",
},
Dir: "/home/vicadmin",
},
Restart: true,
},
)
if conf.HostCertificate != nil {
d.VICAdminProto = "https"
d.DockerPort = fmt.Sprintf("%d", opts.DefaultTLSHTTPPort)
} else {
d.VICAdminProto = "http"
d.DockerPort = fmt.Sprintf("%d", opts.DefaultHTTPPort)
}
//.........这里部分代码省略.........