Esempio n. 1
0
func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	inst := &driver{
		IoNotSupported:    &volume.IoNotSupported{},
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
	}
	inst.buseDevices = make(map[string]*buseDev)
	if err := os.MkdirAll(BuseMountPath, 0744); err != nil {
		return nil, err
	}
	volumeInfo, err := inst.DefaultEnumerator.Enumerate(
		&api.VolumeLocator{},
		nil,
	)
	if err == nil {
		for _, info := range volumeInfo {
			if info.Status == api.VolumeStatus_VOLUME_STATUS_NONE {
				info.Status = api.VolumeStatus_VOLUME_STATUS_UP
				inst.UpdateVol(info)
			}
		}
	} else {
		dlog.Println("Could not enumerate Volumes, ", err)
	}

	c, err := cluster.Inst()
	if err != nil {
		dlog.Println("BUSE initializing in single node mode")
	} else {
		dlog.Println("BUSE initializing in clustered mode")
		c.AddEventListener(inst)
	}

	dlog.Println("BUSE initialized and driver mounted at: ", BuseMountPath)
	return inst, nil
}
Esempio n. 2
0
func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	restUrl, ok := params["restUrl"]
	if !ok {
		return nil, fmt.Errorf("rest api 'url' configuration parameter must be set")
	}

	user, ok := params["user"]
	if !ok {
		return nil, fmt.Errorf("rest auth 'user' must be set")
	}

	pass, ok := params["password"]
	if !ok {
		return nil, fmt.Errorf("rest auth 'password' must be set")
	}

	consistency_group, ok := params["consistency_group"]
	if !ok {
		return nil, fmt.Errorf("'consistency_group' configuration parameter must be set")
	}

	project, ok := params["project"]
	if !ok {
		return nil, fmt.Errorf("'project' configuration parameter must be set")
	}

	varray, ok := params["varray"]
	if !ok {
		return nil, fmt.Errorf("'varray' configuration parameter must be set")
	}

	vpool, ok := params["vpool"]
	if !ok {
		return nil, fmt.Errorf("'vpool' configuration parameter must be set")
	}

	d := &driver{
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
		consistency_group: consistency_group,
		project:           project,
		varray:            varray,
		vpool:             vpool,
		url:               restUrl,
		creds:             url.UserPassword(user, pass),
		httpClient: &http.Client{
			Transport: &http.Transport{
				TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
			},
		},
	}

	return d, nil
}
Esempio n. 3
0
func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	root, ok := params[RootParam]
	if !ok {
		return nil, fmt.Errorf("Root directory should be specified with key %q", RootParam)
	}
	home := path.Join(root, Volumes)
	d, err := btrfs.Init(home, nil)
	if err != nil {
		return nil, err
	}
	s := volume.NewDefaultEnumerator(Name, kvdb.Instance())
	return &driver{btrfs: d, root: root, DefaultEnumerator: s}, nil
}
Esempio n. 4
0
// Init aws volume driver metadata.
func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	zone, err := metadata("placement/availability-zone")
	if err != nil {
		return nil, err
	}
	instance, err := metadata("instance-id")
	if err != nil {
		return nil, err
	}
	logrus.Infof("AWS instance %v zone %v", instance, zone)
	accessKey, ok := params["AWS_ACCESS_KEY_ID"]
	if !ok {
		if accessKey = os.Getenv("AWS_ACCESS_KEY_ID"); accessKey == "" {
			return nil, fmt.Errorf("AWS_ACCESS_KEY_ID environment variable must be set")
		}
	}
	secretKey, ok := params["AWS_SECRET_ACCESS_KEY"]
	if !ok {
		if secretKey = os.Getenv("AWS_SECRET_ACCESS_KEY"); secretKey == "" {
			return nil, fmt.Errorf("AWS_SECRET_ACCESS_KEY environment variable must be set")
		}
	}
	creds := credentials.NewStaticCredentials(accessKey, secretKey, "")
	region := zone[:len(zone)-1]
	d := &Driver{
		ec2: ec2.New(
			session.New(
				&aws.Config{
					Region:      &region,
					Credentials: creds,
				},
			),
		),
		md: &Metadata{
			zone:     zone,
			instance: instance,
		},
		IoNotSupported:    &volume.IoNotSupported{},
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
	}
	devPrefix, letters, err := d.freeDevices()
	if err != nil {
		return nil, err
	}
	d.SingleLetter, err = device.NewSingleLetter(devPrefix, letters)
	if err != nil {
		return nil, err
	}
	return d, nil
}
Esempio n. 5
0
func newVolumeDriver(
	name string,
	baseDirPath string,
	provider Provider,
) *volumeDriver {
	return &volumeDriver{
		name,
		baseDirPath,
		provider,
		&volume.DefaultBlockDriver{},
		volume.NewDefaultEnumerator(
			name,
			kvdb.Instance(),
		),
		&volume.SnapshotNotSupported{},
	}
}
Esempio n. 6
0
// Init aws volume driver metadata.
func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	zone, err := metadata("placement/availability-zone")
	if err != nil {
		return nil, err
	}
	instance, err := metadata("instance-id")
	if err != nil {
		return nil, err
	}
	log.Infof("AWS instance %v zone %v", instance, zone)
	if accessKey, ok := params["AWS_ACCESS_KEY_ID"]; ok {
		os.Setenv("AWS_ACCESS_KEY_ID", accessKey)
	}
	if secretKey, ok := params["AWS_SECRET_ACCESS_KEY"]; ok {
		os.Setenv("AWS_SECRET_ACCESS_KEY", secretKey)
	}
	if accessKey := os.Getenv("AWS_ACCESS_KEY_ID"); accessKey == "" {
		return nil, fmt.Errorf("AWS_ACCESS_KEY_ID environment variable must be set")
	}
	if secretKey := os.Getenv("AWS_SECRET_ACCESS_KEY"); secretKey == "" {
		return nil, fmt.Errorf("AWS_SECRET_ACCESS_KEY environment variable must be set")
	}

	creds := credentials.NewEnvCredentials()
	region := zone[:len(zone)-1]
	inst := &Driver{
		ec2: ec2.New(&aws.Config{
			Region:      &region,
			Credentials: creds,
		}),
		md: &Metadata{
			zone:     zone,
			instance: instance,
		},
		devices:           "abcdefghijklmnopqrstuvwxyz",
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
	}
	return inst, nil
}
Esempio n. 7
0
func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	path, ok := params["path"]
	if !ok {
		return nil, errors.New("No NFS path provided")
	}

	server, ok := params["server"]
	if !ok {
		log.Printf("No NFS server provided, will attempt to bind mount %s", path)
	} else {
		log.Printf("NFS driver initializing with %s:%s ", server, path)
	}

	inst := &driver{
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
		nfsServer:         server,
		nfsPath:           path}

	err := os.MkdirAll(nfsMountPath, 0744)
	if err != nil {
		return nil, err
	}

	// Mount the nfs server locally on a unique path.
	syscall.Unmount(nfsMountPath, 0)
	if server != "" {
		err = syscall.Mount(":"+inst.nfsPath, nfsMountPath, "nfs", 0, "nolock,addr="+inst.nfsServer)
	} else {
		err = syscall.Mount(inst.nfsPath, nfsMountPath, "", syscall.MS_BIND, "")
	}
	if err != nil {
		log.Printf("Unable to mount %s:%s at %s (%+v)", inst.nfsServer, inst.nfsPath, nfsMountPath, err)
		return nil, err
	}

	log.Println("NFS initialized and driver mounted at: ", nfsMountPath)
	return inst, nil
}
Esempio n. 8
0
func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	path, ok := params["path"]
	if !ok {
		return nil, errors.New("No NFS path provided")
	}
	server, ok := params["server"]
	if !ok {
		dlog.Printf("No NFS server provided, will attempt to bind mount %s", path)
	} else {
		dlog.Printf("NFS driver initializing with %s:%s ", server, path)
	}
	// Create a mount manager for this NFS server. Blank sever is OK.
	mounter, err := mount.New(mount.NFSMount, server)
	if err != nil {
		dlog.Warnf("Failed to create mount manager for server: %v (%v)", server, err)
		return nil, err
	}
	inst := &driver{
		IoNotSupported:    &volume.IoNotSupported{},
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
		nfsServer:         server,
		nfsPath:           path,
		mounter:           mounter,
	}
	if err := os.MkdirAll(nfsMountPath, 0744); err != nil {
		return nil, err
	}
	src := inst.nfsPath
	if server != "" {
		src = ":" + inst.nfsPath
	}
	// If src is already mounted at dest, leave it be.
	mountExists, err := mounter.Exists(src, nfsMountPath)
	if !mountExists {
		// Mount the nfs server locally on a unique path.
		syscall.Unmount(nfsMountPath, 0)
		if server != "" {
			err = syscall.Mount(src, nfsMountPath, "nfs", 0, "nolock,addr="+inst.nfsServer)
		} else {
			err = syscall.Mount(src, nfsMountPath, "", syscall.MS_BIND, "")
		}
		if err != nil {
			dlog.Printf("Unable to mount %s:%s at %s (%+v)", inst.nfsServer, inst.nfsPath, nfsMountPath, err)
			return nil, err
		}
	}
	volumeInfo, err := inst.DefaultEnumerator.Enumerate(&api.VolumeLocator{}, nil)
	if err == nil {
		for _, info := range volumeInfo {
			if info.Status == api.VolumeStatus_VOLUME_STATUS_NONE {
				info.Status = api.VolumeStatus_VOLUME_STATUS_UP
				inst.UpdateVol(info)
			}
		}
	} else {
		dlog.Println("Could not enumerate Volumes, ", err)
	}

	dlog.Println("NFS initialized and driver mounted at: ", nfsMountPath)
	return inst, nil
}
Esempio n. 9
0
// Init Driver intialization.
func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	return &driver{
		IoNotSupported:    &volume.IoNotSupported{},
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
	}, nil
}
Esempio n. 10
0
func Init(params map[string]string) (volume.VolumeDriver, error) {
	host, ok := params["url"]
	if !ok {
		return nil, ErrApiUrlRequired
	}

	token, ok := params["token"]
	if !ok {
		return nil, ErrApiAuthTokenRequired
	}

	// create a coprhd api client instance
	client := coprhd.NewClient(host, token)

	d := &driver{
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()),
		client:            client,
	}

	if projectName, ok := params["project"]; ok {
		if project, err := client.Project().Name(projectName).Query(); err != nil {
			return nil, err
		} else {
			d.project = project
		}
	} else {
		dlog.Warnln("Default coprhd 'project' not set")
	}

	if varrayName, ok := params["varray"]; ok {
		if varray, err := client.VArray().Name(varrayName).Query(); err != nil {
			return nil, err
		} else {
			d.varray = varray
		}
	} else {
		dlog.Warnf("Default coprhd 'varray' not set")
	}

	if vpoolName, ok := params["vpool"]; ok {
		if vpool, err := client.VPool().Name(vpoolName).Query(); err != nil {
			return nil, err
		} else {
			d.vpool = vpool
		}
	} else {
		dlog.Warnf("Default coprhd 'vpool' not set")
	}

	if port, ok := params["port"]; ok {
		if initiator, err := client.Initiator().Port(port).Query(); err != nil {
			return nil, err
		} else {
			d.initiator = initiator
		}
	} else {
		return nil, ErrPortRequired
	}

	return d, nil
}
Esempio n. 11
0
// Init Driver intialization.
func Init(params volume.DriverParams) (volume.VolumeDriver, error) {
	return &driver{
		DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance())}, nil
}