本文整理汇总了Golang中github.com/vmware/vic/lib/config.VirtualContainerHostConfigSpec.ComputeResources方法的典型用法代码示例。如果您正苦于以下问题:Golang VirtualContainerHostConfigSpec.ComputeResources方法的具体用法?Golang VirtualContainerHostConfigSpec.ComputeResources怎么用?Golang VirtualContainerHostConfigSpec.ComputeResources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/vic/lib/config.VirtualContainerHostConfigSpec
的用法示例。
在下文中一共展示了VirtualContainerHostConfigSpec.ComputeResources方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateVCH
func (d *Dispatcher) CreateVCH(conf *config.VirtualContainerHostConfigSpec, settings *data.InstallerData) error {
defer trace.End(trace.Begin(conf.Name))
var err error
if err = d.checkExistence(conf, settings); err != nil {
return err
}
if d.isVC && !settings.UseRP {
if d.vchVapp, err = d.createVApp(conf, settings); err != nil {
detail := fmt.Sprintf("Creating virtual app failed: %s", err)
if !d.force {
return errors.New(detail)
}
log.Error(detail)
log.Errorf("Deploying vch under parent pool %q, (--force=true)", settings.ResourcePoolPath)
d.vchPool = d.session.Pool
conf.ComputeResources = append(conf.ComputeResources, d.vchPool.Reference())
}
} else {
if d.vchPool, err = d.createResourcePool(conf, settings); err != nil {
detail := fmt.Sprintf("Creating resource pool failed: %s", err)
if !d.force {
return errors.New(detail)
}
log.Error(detail)
log.Errorf("Deploying vch under parent pool %q, (--force=true)", settings.ResourcePoolPath)
d.vchPool = d.session.Pool
conf.ComputeResources = append(conf.ComputeResources, d.vchPool.Reference())
}
}
if err = d.createBridgeNetwork(conf); err != nil {
return err
}
if err = d.createVolumeStores(conf); err != nil {
return errors.Errorf("Exiting because we could not create volume stores due to error: %s", err)
}
if err = d.createAppliance(conf, settings); err != nil {
return errors.Errorf("Creating the appliance failed with %s. Exiting...", err)
}
if err = d.uploadImages(settings.ImageFiles); err != nil {
return errors.Errorf("Uploading images failed with %s. Exiting...", err)
}
if d.session.IsVC() {
if err = d.RegisterExtension(conf, settings.Extension); err != nil {
return errors.Errorf("Error registering VCH vSphere extension: %s", err)
}
}
return d.startAppliance(conf)
}
示例2: createVApp
func (d *Dispatcher) createVApp(conf *config.VirtualContainerHostConfigSpec, settings *data.InstallerData) (*object.VirtualApp, error) {
defer trace.End(trace.Begin(""))
var err error
log.Infof("Creating virtual app %q", conf.Name)
resSpec := types.ResourceConfigSpec{
CpuAllocation: &types.ResourceAllocationInfo{
Shares: &types.SharesInfo{
Level: types.SharesLevelNormal,
},
ExpandableReservation: types.NewBool(true),
},
MemoryAllocation: &types.ResourceAllocationInfo{
Shares: &types.SharesInfo{
Level: types.SharesLevelNormal,
},
ExpandableReservation: types.NewBool(true),
},
}
cpu := resSpec.CpuAllocation.GetResourceAllocationInfo()
cpu.Limit = -1
if settings.VCHSize.CPU.Limit != 0 {
cpu.Limit = settings.VCHSize.CPU.Limit
}
// FIXME: govmomi omitempty
cpu.Reservation = 1
if settings.VCHSize.CPU.Reservation != 0 {
cpu.Reservation = settings.VCHSize.CPU.Reservation
}
if settings.VCHSize.CPU.Shares != nil {
cpu.Shares = settings.VCHSize.CPU.Shares
}
memory := resSpec.MemoryAllocation.GetResourceAllocationInfo()
memory.Limit = -1
if settings.VCHSize.Memory.Limit != 0 {
memory.Limit = settings.VCHSize.Memory.Limit
}
// FIXME: govmomi omitempty
memory.Reservation = 1
if settings.VCHSize.Memory.Reservation != 0 {
memory.Reservation = settings.VCHSize.Memory.Reservation
}
if settings.VCHSize.Memory.Shares != nil {
memory.Shares = settings.VCHSize.Memory.Shares
}
prodSpec := types.VAppProductSpec{
Info: &types.VAppProductInfo{
Name: "vSphere Integrated Containers",
Vendor: "VMware",
VendorUrl: "http://www.vmware.com/",
Version: version.Version,
},
ArrayUpdateSpec: types.ArrayUpdateSpec{
Operation: types.ArrayUpdateOperationAdd,
},
}
configSpec := types.VAppConfigSpec{
Annotation: "vSphere Integrated Containers",
VmConfigSpec: types.VmConfigSpec{
Product: []types.VAppProductSpec{prodSpec},
},
}
app, err := d.session.Pool.CreateVApp(d.ctx, conf.Name, resSpec, configSpec, d.session.Folders(d.ctx).VmFolder)
if err != nil {
log.Debugf("Failed to create virtual app %q: %s", conf.Name, err)
return nil, err
}
conf.ComputeResources = append(conf.ComputeResources, app.Reference())
return app, nil
}
示例3: createResourcePool
func (d *Dispatcher) createResourcePool(conf *config.VirtualContainerHostConfigSpec, settings *data.InstallerData) (*object.ResourcePool, error) {
defer trace.End(trace.Begin(""))
d.vchPoolPath = path.Join(settings.ResourcePoolPath, conf.Name)
rp, err := d.session.Finder.ResourcePool(d.ctx, d.vchPoolPath)
if err != nil {
_, ok := err.(*find.NotFoundError)
if !ok {
err = errors.Errorf("Failed to query compute resource (%q): %q", d.vchPoolPath, err)
return nil, err
}
} else {
conf.ComputeResources = append(conf.ComputeResources, rp.Reference())
return rp, nil
}
log.Infof("Creating Resource Pool %q", conf.Name)
// TODO: expose the limits and reservation here via options
resSpec := types.ResourceConfigSpec{
CpuAllocation: &types.ResourceAllocationInfo{
Shares: &types.SharesInfo{
Level: types.SharesLevelNormal,
},
ExpandableReservation: types.NewBool(true),
},
MemoryAllocation: &types.ResourceAllocationInfo{
Shares: &types.SharesInfo{
Level: types.SharesLevelNormal,
},
ExpandableReservation: types.NewBool(true),
},
}
cpu := resSpec.CpuAllocation.GetResourceAllocationInfo()
cpu.Limit = -1
if settings.VCHSize.CPU.Limit != 0 {
cpu.Limit = settings.VCHSize.CPU.Limit
}
// FIXME: govmomi omitempty
cpu.Reservation = 1
if settings.VCHSize.CPU.Reservation != 0 {
cpu.Reservation = settings.VCHSize.CPU.Reservation
}
if settings.VCHSize.CPU.Shares != nil {
cpu.Shares = settings.VCHSize.CPU.Shares
}
memory := resSpec.MemoryAllocation.GetResourceAllocationInfo()
memory.Limit = -1
if settings.VCHSize.Memory.Limit != 0 {
memory.Limit = settings.VCHSize.Memory.Limit
}
// FIXME: govmomi omitempty
memory.Reservation = 1
if settings.VCHSize.Memory.Reservation != 0 {
memory.Reservation = settings.VCHSize.Memory.Reservation
}
if settings.VCHSize.Memory.Shares != nil {
memory.Shares = settings.VCHSize.Memory.Shares
}
rp, err = d.session.Pool.Create(d.ctx, conf.Name, resSpec)
if err != nil {
log.Debugf("Failed to create resource pool %q: %s", d.vchPoolPath, err)
return nil, err
}
conf.ComputeResources = append(conf.ComputeResources, rp.Reference())
return rp, nil
}