本文整理汇总了Golang中github.com/vmware/vic/pkg/trace.Begin函数的典型用法代码示例。如果您正苦于以下问题:Golang Begin函数的具体用法?Golang Begin怎么用?Golang Begin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Begin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ScopesAddContainer
func (handler *ScopesHandlersImpl) ScopesAddContainer(params scopes.AddContainerParams) middleware.Responder {
defer trace.End(trace.Begin("ScopesAddContainer"))
h := exec.GetHandle(params.Config.Handle)
if h == nil {
return scopes.NewAddContainerNotFound().WithPayload(&models.Error{Message: "container not found"})
}
err := func() error {
var ip *net.IP
if params.Config.NetworkConfig.Address != nil {
i := net.ParseIP(*params.Config.NetworkConfig.Address)
if i == nil {
return fmt.Errorf("invalid ip address")
}
ip = &i
}
return handler.netCtx.AddContainer(h, params.Config.NetworkConfig.NetworkName, ip)
}()
if err != nil {
if _, ok := err.(*network.ResourceNotFoundError); ok {
return scopes.NewAddContainerNotFound().WithPayload(errorPayload(err))
}
return scopes.NewAddContainerInternalServerError().WithPayload(errorPayload(err))
}
return scopes.NewAddContainerOK().WithPayload(h.String())
}
开发者ID:jak-atx,项目名称:vic,代码行数:32,代码来源:scopes_handlers.go
示例2: FetchAuthToken
func (u *URLFetcher) FetchAuthToken(url *url.URL) (*Token, error) {
defer trace.End(trace.Begin(url.String()))
data, err := u.Fetch(context.Background(), url, false, nil)
if err != nil {
log.Errorf("Download failed: %v", err)
return nil, err
}
token := &Token{}
err = json.Unmarshal([]byte(data), &token)
if err != nil {
log.Errorf("Incorrect token format: %v", err)
return nil, err
}
if token.ExpiresIn == 0 {
token.Expires = time.Now().Add(DefaultTokenExpirationDuration)
} else {
token.Expires = time.Now().Add(time.Duration(token.ExpiresIn) * time.Second)
}
return token, nil
}
开发者ID:vmware,项目名称:vic,代码行数:25,代码来源:fetcher.go
示例3: configIso
func (d *Dispatcher) configIso(conf *metadata.VirtualContainerHostConfigSpec, vm *vm.VirtualMachine) (object.VirtualDeviceList, error) {
defer trace.End(trace.Begin(""))
var devices object.VirtualDeviceList
var err error
vmDevices, err := vm.Device(d.ctx)
if err != nil {
log.Errorf("Failed to get vm devices for appliance: %s", err)
return nil, err
}
ide, err := vmDevices.FindIDEController("")
if err != nil {
log.Errorf("Failed to find IDE controller for appliance: %s", err)
return nil, err
}
cdrom, err := devices.CreateCdrom(ide)
if err != nil {
log.Errorf("Failed to create Cdrom device for appliance: %s", err)
return nil, err
}
cdrom = devices.InsertIso(cdrom, fmt.Sprintf("[%s] %s/appliance.iso", conf.ImageStores[0].Host, d.vmPathName))
devices = append(devices, cdrom)
return devices, nil
}
开发者ID:jak-atx,项目名称:vic,代码行数:25,代码来源:appliance.go
示例4: SessionLog
// sessionLogWriter returns a writer that will persist the session output
func (t *operations) SessionLog(session *tether.SessionConfig) (dio.DynamicMultiWriter, error) {
com := "COM3"
defer trace.End(trace.Begin("configure session log writer"))
if t.logging {
detail := "unable to log more than one session concurrently"
log.Error(detail)
return nil, errors.New(detail)
}
t.logging = true
// redirect backchannel to the serial connection
log.Infof("opening %s%s for session logging", pathPrefix, com)
f, err := OpenPort(fmt.Sprintf("%s%s", pathPrefix, com))
if err != nil {
detail := fmt.Sprintf("failed to open serial port for session log: %s", err)
log.Error(detail)
return nil, errors.New(detail)
}
// use multi-writer so it goes to both screen and session log
return dio.MultiWriter(f, os.Stdout), nil
}
开发者ID:jak-atx,项目名称:vic,代码行数:26,代码来源:ops_windows.go
示例5: lsFolder
func (d *Dispatcher) lsFolder(ds *object.Datastore, dsPath string) (*types.HostDatastoreBrowserSearchResults, error) {
defer trace.End(trace.Begin(dsPath))
spec := types.HostDatastoreBrowserSearchSpec{
MatchPattern: []string{"*"},
}
b, err := ds.Browser(d.ctx)
if err != nil {
return nil, err
}
task, err := b.SearchDatastore(d.ctx, dsPath, &spec)
if err != nil {
return nil, err
}
info, err := task.WaitForResult(d.ctx, nil)
if err != nil {
return nil, err
}
res := info.Result.(types.HostDatastoreBrowserSearchResults)
return &res, nil
}
开发者ID:vmware,项目名称:vic,代码行数:25,代码来源:store_files.go
示例6: newBridgeScope
func (c *Context) newBridgeScope(id uid.UID, name string, subnet *net.IPNet, gateway net.IP, dns []net.IP, pools []string) (newScope *Scope, err error) {
defer trace.End(trace.Begin(""))
bnPG, ok := c.config.PortGroups[c.config.BridgeNetwork]
if !ok || bnPG == nil {
return nil, fmt.Errorf("bridge network not set")
}
if ip.IsUnspecifiedSubnet(subnet) {
// get the next available subnet from the default bridge pool
var err error
subnet, err = c.defaultBridgePool.NextIP4Net(c.defaultBridgeMask)
if err != nil {
return nil, err
}
}
s, err := c.newScopeCommon(id, name, constants.BridgeScopeType, subnet, gateway, dns, pools, bnPG)
if err != nil {
return nil, err
}
// add the gateway address to the bridge interface
if err = c.config.BridgeLink.AddrAdd(net.IPNet{IP: s.Gateway(), Mask: s.Subnet().Mask}); err != nil {
if errno, ok := err.(syscall.Errno); !ok || errno != syscall.EEXIST {
log.Warnf("failed to add gateway address %s to bridge interface: %s", s.Gateway(), err)
}
}
return s, nil
}
开发者ID:vmware,项目名称:vic,代码行数:30,代码来源:context.go
示例7: Scopes
func (c *Context) Scopes(ctx context.Context, idName *string) ([]*Scope, error) {
defer trace.End(trace.Begin(""))
c.Lock()
defer c.Unlock()
scopes, err := c.findScopes(idName)
if err != nil {
return nil, err
}
// collate the containers to update
containers := make(map[uid.UID]*Container)
for _, s := range scopes {
if !s.isDynamic() {
continue
}
for _, c := range s.Containers() {
containers[c.ID()] = c
}
}
for _, c := range containers {
c.Refresh(ctx)
}
return scopes, nil
}
开发者ID:vmware,项目名称:vic,代码行数:29,代码来源:context.go
示例8: updates
// updates acquires updates from the infrastructure without holding a lock
func (c *containerBase) updates(ctx context.Context) (*containerBase, error) {
defer trace.End(trace.Begin(c.ExecConfig.ID))
var o mo.VirtualMachine
// make sure we have vm
if c.vm == nil {
return nil, NotYetExistError{c.ExecConfig.ID}
}
if err := c.vm.Properties(ctx, c.vm.Reference(), []string{"config", "runtime"}, &o); err != nil {
return nil, err
}
base := &containerBase{
vm: c.vm,
Config: o.Config,
Runtime: &o.Runtime,
ExecConfig: &executor.ExecutorConfig{},
}
// Get the ExtraConfig
extraconfig.Decode(vmomi.OptionValueSource(o.Config.ExtraConfig), base.ExecConfig)
return base, nil
}
开发者ID:vmware,项目名称:vic,代码行数:27,代码来源:base.go
示例9: Reload
// Reload - tether.Extension implementation
func (t *attachServerSSH) Reload(config *tether.ExecutorConfig) error {
defer trace.End(trace.Begin("attach reload"))
t.config = config
// process the sessions and launch if needed
for id, session := range config.Sessions {
log.Infof("Processing config for session %s", id)
if session.Attach {
log.Infof("Session %s is configured for attach", id)
// this will return nil if already running - calling server.start not t.start so that
// test impl gets invoked (couldn't find a better way of doing this without full polymorphism)
err := server.start()
if err != nil {
detail := fmt.Sprintf("unable to start attach server: %s", err)
log.Error(detail)
return errors.New(detail)
}
return nil
}
}
// none of the sessions allows attach, so stop the server - calling server.start not t.start so that
// test impl gets invoked
server.stop()
return nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:28,代码来源:attach.go
示例10: VolumeCreate
//VolumeCreate : docker personality implementation for VIC
func (v *Volume) VolumeCreate(name, driverName string, opts, labels map[string]string) (*types.Volume, error) {
defer trace.End(trace.Begin("Volume.VolumeCreate"))
result := &types.Volume{}
//TODO: design a way to have better error returns.
client := PortLayerClient()
if client == nil {
return nil, derr.NewErrorWithStatusCode(fmt.Errorf("Failed to get a portlayer client"), http.StatusInternalServerError)
}
//TODO: support having another driver besides vsphere.
//assign the values of the model to be passed to the portlayer handler
model, varErr := translateInputsToPortlayerRequestModel(name, driverName, opts, labels)
if varErr != nil {
return result, derr.NewErrorWithStatusCode(fmt.Errorf("Bad Driver Arg: %s", varErr), http.StatusBadRequest)
}
//TODO: setup name randomization if name == nil
res, err := client.Storage.CreateVolume(storage.NewCreateVolumeParams().WithVolumeRequest(&model))
if err != nil {
return result, derr.NewErrorWithStatusCode(fmt.Errorf("Server error from Portlayer: %s", err), http.StatusInternalServerError)
}
result = fillDockerVolumeModel(res.Payload, labels)
return result, nil
}
开发者ID:jak-atx,项目名称:vic,代码行数:29,代码来源:volume.go
示例11: startGuestProgram
func (c *containerBase) startGuestProgram(ctx context.Context, name string, args string) error {
// make sure we have vm
if c.vm == nil {
return NotYetExistError{c.ExecConfig.ID}
}
defer trace.End(trace.Begin(c.ExecConfig.ID))
o := guest.NewOperationsManager(c.vm.Client.Client, c.vm.Reference())
m, err := o.ProcessManager(ctx)
if err != nil {
return err
}
spec := types.GuestProgramSpec{
ProgramPath: name,
Arguments: args,
}
auth := types.NamePasswordAuthentication{
Username: c.ExecConfig.ID,
}
_, err = m.StartProgram(ctx, &auth, &spec)
return err
}
开发者ID:vmware,项目名称:vic,代码行数:26,代码来源:base.go
示例12: LinkSetAlias
func (t *Mocker) LinkSetAlias(link netlink.Link, alias string) error {
defer trace.End(trace.Begin(fmt.Sprintf("Adding alias %s to %s", alias, link.Attrs().Name)))
iface := link.(*Interface)
iface.Alias = alias
return nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:7,代码来源:ops_linux_test.go
示例13: LinkSetUp
func (t *Mocker) LinkSetUp(link netlink.Link) error {
defer trace.End(trace.Begin(fmt.Sprintf("Bringing %s up", link.Attrs().Name)))
iface := link.(*Interface)
iface.Up = true
return nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:7,代码来源:ops_linux_test.go
示例14: storage
func (v *Validator) storage(ctx context.Context, input *data.Data, conf *config.VirtualContainerHostConfigSpec) {
defer trace.End(trace.Begin(""))
// Image Store
imageDSpath, ds, err := v.DatastoreHelper(ctx, input.ImageDatastorePath, "", "--image-store")
if imageDSpath == nil {
v.NoteIssue(err)
return
}
// provide a default path if only a DS name is provided
if imageDSpath.Path == "" {
imageDSpath.Path = input.DisplayName
}
v.NoteIssue(err)
if ds != nil {
v.SetDatastore(ds, imageDSpath)
conf.AddImageStore(imageDSpath)
}
if conf.VolumeLocations == nil {
conf.VolumeLocations = make(map[string]*url.URL)
}
// TODO: add volume locations
for label, volDSpath := range input.VolumeLocations {
dsURL, _, err := v.DatastoreHelper(ctx, volDSpath, label, "--volume-store")
v.NoteIssue(err)
if dsURL != nil {
conf.VolumeLocations[label] = dsURL
}
}
}
开发者ID:kjplatz,项目名称:vic,代码行数:35,代码来源:storage.go
示例15: ContainerWaitHandler
func (handler *ContainersHandlersImpl) ContainerWaitHandler(params containers.ContainerWaitParams) middleware.Responder {
defer trace.End(trace.Begin(fmt.Sprintf("%s:%d", params.ID, params.Timeout)))
// default context timeout in seconds
defaultTimeout := int64(containerWaitTimeout.Seconds())
// if we have a positive timeout specified then use it
if params.Timeout > 0 {
defaultTimeout = params.Timeout
}
timeout := time.Duration(defaultTimeout) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
c := exec.Containers.Container(uid.Parse(params.ID).String())
if c == nil {
return containers.NewContainerWaitNotFound().WithPayload(&models.Error{
Message: fmt.Sprintf("container %s not found", params.ID),
})
}
select {
case <-c.WaitForState(exec.StateStopped):
c.Refresh(context.Background())
containerInfo := convertContainerToContainerInfo(c.Info())
return containers.NewContainerWaitOK().WithPayload(containerInfo)
case <-ctx.Done():
return containers.NewContainerWaitInternalServerError().WithPayload(&models.Error{
Message: fmt.Sprintf("ContainerWaitHandler(%s) Error: %s", params.ID, ctx.Err()),
})
}
}
开发者ID:vmware,项目名称:vic,代码行数:35,代码来源:containers_handlers.go
示例16: open
func (path fileReader) open() (entry, error) {
defer trace.End(trace.Begin(string(path)))
f, err := os.Open(string(path))
if err != nil {
return nil, err
}
s, err := os.Stat(string(path))
if err != nil {
return nil, err
}
// Files in /proc always have struct stat.st_size==0, so just read it into memory.
if s.Size() == 0 && strings.HasPrefix(f.Name(), "/proc/") {
b, err := ioutil.ReadAll(f)
_ = f.Close()
if err != nil {
return nil, err
}
return newBytesEntry(f.Name(), b), nil
}
return &fileEntry{
ReadCloser: f,
FileInfo: s,
}, nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:29,代码来源:vicadm.go
示例17: DeleteScope
func (c *Context) DeleteScope(ctx context.Context, name string) error {
defer trace.End(trace.Begin(""))
c.Lock()
defer c.Unlock()
s, err := c.resolveScope(name)
if err != nil {
return err
}
if s == nil {
return ResourceNotFoundError{}
}
if s.builtin {
return fmt.Errorf("cannot remove builtin scope")
}
if len(s.Endpoints()) != 0 {
return fmt.Errorf("%s has active endpoints", s.Name())
}
if c.kv != nil {
if err = c.kv.Delete(ctx, scopeKey(s.Name())); err != nil && err != kvstore.ErrKeyNotFound {
return err
}
}
c.deleteScope(s)
return nil
}
开发者ID:vmware,项目名称:vic,代码行数:32,代码来源:context.go
示例18: listVMPaths
// listVMPaths returns an array of datastore paths for VMs assocaited with the
// VCH - this includes containerVMs and the appliance
func listVMPaths(ctx context.Context, s *session.Session) ([]url.URL, error) {
defer trace.End(trace.Begin(""))
var err error
var children []*vm.VirtualMachine
if len(vchConfig.ComputeResources) == 0 {
return nil, errors.New("compute resources is empty")
}
ref := vchConfig.ComputeResources[0]
rp := compute.NewResourcePool(ctx, s, ref)
if children, err = rp.GetChildrenVMs(ctx, s); err != nil {
return nil, err
}
log.Infof("Found %d candidate VMs in resource pool %s for log collection", len(children), ref.String())
directories := []url.URL{}
for _, child := range children {
path, err := child.DSPath(ctx)
if err != nil {
log.Errorf("Unable to get datastore path for child VM %s: %s", child.Reference(), err)
// we need to get as many logs as possible
continue
}
log.Debugf("Adding VM for log collection: %s", path.String())
directories = append(directories, path)
}
log.Infof("Collecting logs from %d VMs", len(directories))
return directories, nil
}
开发者ID:kjplatz,项目名称:vic,代码行数:36,代码来源:vicadm.go
示例19: NewScope
func (c *Context) NewScope(ctx context.Context, scopeType, name string, subnet *net.IPNet, gateway net.IP, dns []net.IP, pools []string) (*Scope, error) {
defer trace.End(trace.Begin(""))
c.Lock()
defer c.Unlock()
s, err := c.newScope(scopeType, name, subnet, gateway, dns, pools)
if err != nil {
return nil, err
}
defer func() {
if err != nil {
c.deleteScope(s)
}
}()
// save the scope in the kv store
if c.kv != nil {
var d []byte
d, err = s.MarshalJSON()
if err != nil {
return nil, err
}
if err = c.kv.Put(ctx, scopeKey(s.Name()), d); err != nil {
return nil, err
}
}
return s, nil
}
开发者ID:vmware,项目名称:vic,代码行数:31,代码来源:context.go
示例20: Join
// Join adds network backed serial port to the caller and configures them
func Join(h interface{}) (interface{}, error) {
defer trace.End(trace.Begin(""))
handle, ok := h.(*exec.Handle)
if !ok {
return nil, fmt.Errorf("Type assertion failed for %#+v", handle)
}
// Tether serial port - backed by network
serial := &types.VirtualSerialPort{
VirtualDevice: types.VirtualDevice{
Backing: &types.VirtualSerialPortURIBackingInfo{
VirtualDeviceURIBackingInfo: types.VirtualDeviceURIBackingInfo{
Direction: string(types.VirtualDeviceURIBackingOptionDirectionClient),
// Set it to 0.0.0.0 during Join call, VCH IP will be set when we call Bind
ServiceURI: fmt.Sprintf("tcp://0.0.0.0:%d", constants.SerialOverLANPort),
},
},
Connectable: &types.VirtualDeviceConnectInfo{
Connected: false,
StartConnected: false,
AllowGuestControl: true,
},
},
YieldOnPoll: true,
}
config := &types.VirtualDeviceConfigSpec{
Device: serial,
Operation: types.VirtualDeviceConfigSpecOperationAdd,
}
handle.Spec.DeviceChange = append(handle.Spec.DeviceChange, config)
return handle, nil
}
开发者ID:vmware,项目名称:vic,代码行数:35,代码来源:attach.go
注:本文中的github.com/vmware/vic/pkg/trace.Begin函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论