func (d *idm) Mount( ctx types.Context, volumeID, volumeName string, opts *types.VolumeMountOpts) (string, *types.Volume, error) { opts.Preempt = d.preempt() fields := log.Fields{ "volumeName": volumeName, "volumeID": volumeID, "opts": opts} ctx.WithFields(fields).Debug("mounting volume") mp, vol, err := d.IntegrationDriver.Mount( ctx.Join(d.ctx), volumeID, volumeName, opts) if err != nil { return "", nil, err } // if the volume has attachments assign the new mount point to the // MountPoint field of the first attachment element if len(vol.Attachments) > 0 { vol.Attachments[0].MountPoint = mp } d.incCount(volumeName) return mp, vol, err }
func (d *odm) IsMounted( ctx types.Context, mountPoint string, opts types.Store) (bool, error) { return d.OSDriver.IsMounted(ctx.Join(d.Context), mountPoint, opts) }
func (c *client) NextDevice( ctx types.Context, opts types.Store) (string, error) { if c.isController() { return "", utils.NewUnsupportedForClientTypeError( c.clientType, "NextDevice") } if supported, _ := c.Supported(ctx, opts); !supported { return "", errExecutorNotSupported } ctx = context.RequireTX(ctx.Join(c.ctx)) serviceName, ok := context.ServiceName(ctx) if !ok { return "", goof.New("missing service name") } si, err := c.getServiceInfo(serviceName) if err != nil { return "", err } driverName := si.Driver.Name out, err := c.runExecutor(ctx, driverName, types.LSXCmdNextDevice) if err != nil { return "", err } ctx.Debug("xli nextdevice success") return gotil.Trim(string(out)), nil }
func (d *odm) Unmount( ctx types.Context, mountPoint string, opts types.Store) error { return d.OSDriver.Unmount(ctx.Join(d.Context), mountPoint, opts) }
func (d *idm) List( ctx types.Context, opts types.Store) ([]types.VolumeMapping, error) { fields := log.Fields{ "opts": opts} ctx.WithFields(fields).Debug("listing volumes") volMaps, err := d.IntegrationDriver.List(ctx.Join(d.ctx), opts) if err != nil { return nil, err } volMapsWithNames := []types.VolumeMapping{} for _, vm := range volMaps { if vm.VolumeName() != "" { volMapsWithNames = append(volMapsWithNames, vm) } } if !d.pathCacheEnabled() { return volMapsWithNames, nil } for _, vm := range volMapsWithNames { vmn := vm.VolumeName() if !d.isCounted(vmn) && vm.MountPoint() != "" { d.initCount(vmn) } } return volMapsWithNames, nil }
func (d *odm) Mounts( ctx types.Context, deviceName, mountPoint string, opts types.Store) ([]*types.MountInfo, error) { ctx = ctx.Join(d.Context) return d.OSDriver.Mounts(ctx.Join(d.Context), deviceName, mountPoint, opts) }
func (c *client) requireCtx(ctx types.Context) types.Context { if ctx == nil { ctx = c.ctx } else { ctx = ctx.Join(c.ctx) } return context.RequireTX(ctx) }
func (d *odm) Mount( ctx types.Context, deviceName, mountPoint string, opts *types.DeviceMountOpts) error { ctx = ctx.Join(d.Context) return d.OSDriver.Mount(ctx.Join(d.Context), deviceName, mountPoint, opts) }
func (d *odm) Format( ctx types.Context, deviceName string, opts *types.DeviceFormatOpts) error { ctx = ctx.Join(d.Context) if strings.Contains(deviceName, ":") { return nil } return d.OSDriver.Format(ctx, deviceName, opts) }
func (d *idm) Inspect( ctx types.Context, volumeName string, opts types.Store) (types.VolumeMapping, error) { fields := log.Fields{ "volumeName": volumeName, "opts": opts} ctx.WithFields(fields).Debug("inspecting volume") return d.IntegrationDriver.Inspect(ctx.Join(d.ctx), volumeName, opts) }
func (c *client) Supported( ctx types.Context, opts types.Store) (bool, error) { if c.isController() { return false, utils.NewUnsupportedForClientTypeError( c.clientType, "Supported") } ctx = context.RequireTX(ctx.Join(c.ctx)) serviceName, ok := context.ServiceName(ctx) if !ok { return false, goof.New("missing service name") } si, err := c.getServiceInfo(serviceName) if err != nil { return false, err } driverName := strings.ToLower(si.Driver.Name) // check to see if the driver's executor is supported on this host if ok := c.supportedCache.IsSet(driverName); ok { return c.supportedCache.GetBool(driverName), nil } out, err := c.runExecutor(ctx, driverName, types.LSXCmdSupported) if err != nil { if err == types.ErrNotImplemented { ctx.WithField("serviceDriver", driverName).Warn( "supported cmd not implemented") c.supportedCache.Set(driverName, true) ctx.WithField("supported", true).Debug("cached supported flag") return true, nil } return false, err } if len(out) == 0 { return false, nil } out = bytes.TrimSpace(out) b, err := strconv.ParseBool(string(out)) if err != nil { return false, err } c.supportedCache.Set(driverName, b) ctx.WithField("supported", b).Debug("cached supported flag") return b, nil }
func (d *idm) Detach( ctx types.Context, volumeName string, opts *types.VolumeDetachOpts) error { fields := log.Fields{ "volumeName": volumeName, "opts": opts} ctx.WithFields(fields).Debug("detaching volume") return d.IntegrationDriver.Detach(ctx.Join(d.ctx), volumeName, opts) }
func (d *idm) Remove( ctx types.Context, volumeName string, opts types.Store) error { fields := log.Fields{ "volumeName": volumeName, "opts": opts} ctx.WithFields(fields).Debug("removing volume") if d.disableRemove() { ctx.Debug("disableRemove skipped deletion") return nil } return d.IntegrationDriver.Remove(ctx.Join(d.ctx), volumeName, opts) }
func (d *idm) Create( ctx types.Context, volumeName string, opts *types.VolumeCreateOpts) (*types.Volume, error) { fields := log.Fields{ "volumeName": volumeName, "opts": opts} ctx.WithFields(fields).Debug("creating volume") if d.disableCreate() { ctx.Debug("disableRemove skipped creation") return nil, nil } return d.IntegrationDriver.Create(ctx.Join(d.ctx), volumeName, opts) }
func (c *client) WaitForDevice( ctx types.Context, opts *types.WaitForDeviceOpts) (bool, *types.LocalDevices, error) { if c.isController() { return false, nil, utils.NewUnsupportedForClientTypeError( c.clientType, "WaitForDevice") } if supported, _ := c.Supported(ctx, opts.Opts); !supported { return false, nil, errExecutorNotSupported } ctx = context.RequireTX(ctx.Join(c.ctx)) serviceName, ok := context.ServiceName(ctx) if !ok { return false, nil, goof.New("missing service name") } si, err := c.getServiceInfo(serviceName) if err != nil { return false, nil, err } driverName := si.Driver.Name out, err := c.runExecutor( ctx, driverName, types.LSXCmdWaitForDevice, opts.ScanType.String(), opts.Token, opts.Timeout.String()) if err != types.ErrTimedOut { return false, nil, err } matched := err == nil ld, err := unmarshalLocalDevices(ctx, out) if err != nil { return false, nil, err } ctx.Debug("xli waitfordevice success") return matched, ld, nil }
func (c *client) LocalDevices( ctx types.Context, opts *types.LocalDevicesOpts) (*types.LocalDevices, error) { if c.isController() { return nil, utils.NewUnsupportedForClientTypeError( c.clientType, "LocalDevices") } if supported, _ := c.Supported(ctx, opts.Opts); !supported { return nil, errExecutorNotSupported } ctx = context.RequireTX(ctx.Join(c.ctx)) serviceName, ok := context.ServiceName(ctx) if !ok { return nil, goof.New("missing service name") } si, err := c.getServiceInfo(serviceName) if err != nil { return nil, err } driverName := si.Driver.Name out, err := c.runExecutor( ctx, driverName, types.LSXCmdLocalDevices, opts.ScanType.String()) if err != nil { return nil, err } ld, err := unmarshalLocalDevices(ctx, out) if err != nil { return nil, err } ctx.Debug("xli localdevices success") return ld, nil }
func (d *idm) Path( ctx types.Context, volumeID, volumeName string, opts types.Store) (string, error) { fields := log.Fields{ "volumeName": volumeName, "volumeID": volumeID, "opts": opts} ctx.WithFields(fields).Debug("getting path to volume") if !d.pathCacheEnabled() { return d.IntegrationDriver.Path( ctx.Join(d.ctx), volumeID, volumeName, opts) } if !d.isCounted(volumeName) { ctx.WithFields(fields).Debug("skipping path lookup") return "", nil } return d.IntegrationDriver.Path(ctx.Join(d.ctx), volumeID, volumeName, opts) }
func (d *idm) Unmount( ctx types.Context, volumeID, volumeName string, opts types.Store) (*types.Volume, error) { fields := log.Fields{ "volumeName": volumeName, "volumeID": volumeID, "opts": opts} ctx.WithFields(fields).Debug("unmounting volume") if d.ignoreUsedCount() || d.resetCount(volumeName) || !d.isCounted(volumeName) { d.initCount(volumeName) return d.IntegrationDriver.Unmount( ctx.Join(d.ctx), volumeID, volumeName, opts) } d.decCount(volumeName) return nil, nil }
func (c *client) InstanceID( ctx types.Context, opts types.Store) (*types.InstanceID, error) { if c.isController() { return nil, utils.NewUnsupportedForClientTypeError( c.clientType, "InstanceID") } if supported, _ := c.Supported(ctx, opts); !supported { return nil, errExecutorNotSupported } ctx = context.RequireTX(ctx.Join(c.ctx)) serviceName, ok := context.ServiceName(ctx) if !ok { return nil, goof.New("missing service name") } si, err := c.getServiceInfo(serviceName) if err != nil { return nil, err } driverName := strings.ToLower(si.Driver.Name) // check to see if the driver's instance ID is cached if iid := c.instanceIDCache.GetInstanceID(driverName); iid != nil { return iid, nil } out, err := c.runExecutor(ctx, driverName, types.LSXCmdInstanceID) if err != nil { return nil, err } iid := &types.InstanceID{} if err := iid.UnmarshalText(out); err != nil { return nil, err } ctx = ctx.WithValue(context.InstanceIDKey, iid) if iid.HasMetadata() { ctx.Debug("sending instanceID in API.InstanceInspect call") instance, err := c.InstanceInspect(ctx, serviceName) if err != nil { return nil, err } ctx.Debug("received instanceID from API.InstanceInspect call") iid.ID = instance.InstanceID.ID iid.Fields = instance.InstanceID.Fields iid.DeleteMetadata() } c.instanceIDCache.Set(driverName, iid) ctx.Debug("cached instanceID") ctx.Debug("xli instanceID success") return iid, nil }