예제 #1
0
func (client *localClient) Unmount(logger lager.Logger, driverId string, volumeName string) error {
	logger = logger.Session("unmount")
	logger.Info("start")
	defer logger.Info("end")
	logger.Debug("unmounting-volume", lager.Data{"volumeName": volumeName})

	unmountStart := client.clock.Now()

	defer func() {
		sendUnmountDurationMetrics(logger, time.Since(unmountStart), driverId)
	}()

	driver, found := client.driverRegistry.Driver(driverId)
	if !found {
		err := errors.New("Driver '" + driverId + "' not found in list of known drivers")
		logger.Error("mount-driver-lookup-error", err)
		volmanUnmountErrorsCounter.Increment()
		return err
	}

	env := driverhttp.NewHttpDriverEnv(logger, context.TODO())

	if response := driver.Unmount(env, voldriver.UnmountRequest{Name: volumeName}); response.Err != "" {
		err := errors.New(response.Err)
		logger.Error("unmount-failed", err)
		volmanUnmountErrorsCounter.Increment()
		return err
	}

	return nil
}
예제 #2
0
func (p *mountPurger) PurgeMounts(logger lager.Logger) error {
	logger = logger.Session("purge-mounts")
	logger.Info("start")
	defer logger.Info("end")

	drivers := p.registry.Drivers()

	for _, driver := range drivers {
		env := driverhttp.NewHttpDriverEnv(logger, context.TODO())
		listResponse := driver.List(env)
		for _, mount := range listResponse.Volumes {
			env = driverhttp.NewHttpDriverEnv(logger, context.TODO())
			errorResponse := driver.Unmount(env, voldriver.UnmountRequest{Name: mount.Name})
			if errorResponse.Err != "" {
				logger.Error("failed-purging-volume-mount", errors.New(errorResponse.Err))
			}
		}
	}

	return nil
}
func (r *driverSyncer) insertIfAliveAndNotFound(logger lager.Logger, endpoints map[string]voldriver.Driver, driverPath string, specs []string) map[string]voldriver.Driver {
	logger = logger.Session("insert-if-not-found")
	logger.Debug("start")
	defer logger.Debug("end")

	for _, spec := range specs {
		re := regexp.MustCompile("([^/]*/)?([^/]*)\\.(sock|spec|json)$")

		segs2 := re.FindAllStringSubmatch(spec, 1)
		if len(segs2) <= 0 {
			continue
		}
		specName := segs2[0][2]
		specFile := segs2[0][2] + "." + segs2[0][3]
		logger.Debug("insert-unique-spec", lager.Data{"specname": specName})
		_, ok := endpoints[specName]
		if ok == false {
			driver, err := r.driverFactory.Driver(logger, specName, driverPath, specFile)
			if err != nil {
				logger.Error("error-creating-driver", err)
				continue
			}

			env := driverhttp.NewHttpDriverEnv(logger, context.TODO())

			resp := driver.Activate(env)
			if resp.Err != "" {
				logger.Info("skipping-non-responsive-driver", lager.Data{"specname": specName})
			} else {
				driverImplementsErr := fmt.Errorf("driver-implements: %#v", resp.Implements)
				if len(resp.Implements) == 0 {
					logger.Error("driver-incorrect", driverImplementsErr)
					continue
				}

				if !driverImplements("VolumeDriver", resp.Implements) {
					logger.Error("driver-incorrect", driverImplementsErr)
					continue
				}
				endpoints[specName] = driver
			}
		}
	}
	return endpoints
}
예제 #4
0
func (client *localClient) create(logger lager.Logger, driverId string, volumeName string, opts map[string]interface{}) error {
	logger = logger.Session("create")
	logger.Info("start")
	defer logger.Info("end")
	driver, found := client.driverRegistry.Driver(driverId)
	if !found {
		err := errors.New("Driver '" + driverId + "' not found in list of known drivers")
		logger.Error("mount-driver-lookup-error", err)
		return err
	}

	env := driverhttp.NewHttpDriverEnv(logger, context.TODO())

	logger.Debug("creating-volume", lager.Data{"volumeName": volumeName, "driverId": driverId, "opts": opts})
	response := driver.Create(env, voldriver.CreateRequest{Name: volumeName, Opts: opts})
	if response.Err != "" {
		return errors.New(response.Err)
	}
	return nil
}
예제 #5
0
func (client *localClient) Mount(logger lager.Logger, driverId string, volumeId string, config map[string]interface{}) (volman.MountResponse, error) {
	logger = logger.Session("mount")
	logger.Info("start")
	defer logger.Info("end")

	mountStart := client.clock.Now()

	defer func() {
		sendMountDurationMetrics(logger, time.Since(mountStart), driverId)
	}()

	logger.Debug("driver-mounting-volume", lager.Data{"driverId": driverId, "volumeId": volumeId})

	driver, found := client.driverRegistry.Driver(driverId)
	if !found {
		err := errors.New("Driver '" + driverId + "' not found in list of known drivers")
		logger.Error("mount-driver-lookup-error", err)
		volmanMountErrorsCounter.Increment()
		return volman.MountResponse{}, err
	}

	err := client.create(logger, driverId, volumeId, config)
	if err != nil {
		volmanMountErrorsCounter.Increment()
		return volman.MountResponse{}, err
	}

	env := driverhttp.NewHttpDriverEnv(logger, context.TODO())

	mountRequest := voldriver.MountRequest{Name: volumeId}
	logger.Debug("calling-driver-with-mount-request", lager.Data{"driverId": driverId, "mountRequest": mountRequest})
	mountResponse := driver.Mount(env, mountRequest)
	logger.Debug("response-from-driver", lager.Data{"response": mountResponse})
	if mountResponse.Err != "" {
		volmanMountErrorsCounter.Increment()
		return volman.MountResponse{}, errors.New(mountResponse.Err)
	}

	return volman.MountResponse{mountResponse.Mountpoint}, nil
}