Skip to content

Commit

Permalink
[WIP] add Manager for RBD volumes and snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpanic committed Jun 25, 2024
1 parent f93651b commit b397f90
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
42 changes: 42 additions & 0 deletions internal/rbd/manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package rbd

import (
"context"

types "github.com/ceph/ceph-csi/internal/rbd_types"
"github.com/ceph/ceph-csi/internal/util"
)

var _ types.Manager = &rbdManager{}

type rbdManager struct{}

func (mgr *rbdManager) GetVolumeByID(ctx context.Context, id string, secrets map[string]string) (types.Volume, error) {
creds, err := util.NewUserCredentials(secrets)
if err != nil {
return nil, err
}
defer creds.DeleteCredentials()

volume, err := GenVolFromVolID(ctx, id, creds, secrets)
if err != nil {
return nil, err
}

return volume, nil
}

func (mgr *rbdManager) GetSnapshotByID(ctx context.Context, id string, secrets map[string]string) (types.Snapshot, error) {
creds, err := util.NewUserCredentials(secrets)
if err != nil {
return nil, err
}
defer creds.DeleteCredentials()

snap, err := genSnapFromSnapID(ctx, id, creds, secrets)
if err != nil {
return nil, err
}

return snap, nil
}
28 changes: 28 additions & 0 deletions internal/rbd_types/manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2024 The Ceph-CSI Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:golint // this package should be renamed to rbd/types
package rbd_types

import (
"context"
)

// Manager provides a way for other packages to get Volumes and Snapshots.
type Manager interface {
GetVolumeByID(ctx context.Context, id string, secrets map[string]string) (Volume, error)
GetSnapshotByID(ctx context.Context, id string, secrets map[string]string) (Snapshot, error)
}

0 comments on commit b397f90

Please sign in to comment.