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) }
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 }
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 }