Skip to content

Commit

Permalink
rbd: implement GetFenceClients
Browse files Browse the repository at this point in the history
implemented GetFenceClients which
connects to the ceph cluster and
returns the ceph clusterID and the
clientaddress that is used for rados
connection.

Signed-off-by: Madhu Rajanna <[email protected]>
  • Loading branch information
Madhu-1 authored and nixpanic committed Nov 6, 2024
1 parent c1382e0 commit ce25e16
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions internal/csi-addons/rbd/network_fence.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,59 @@ func (fcs *FenceControllerServer) UnfenceClusterNetwork(

return &fence.UnfenceClusterNetworkResponse{}, nil
}

// GetFenceClients fetches the ceph cluster ID and the client address that need to be fenced.
func (fcs *FenceControllerServer) GetFenceClients(
ctx context.Context,
req *fence.GetFenceClientsRequest,
) (*fence.GetFenceClientsResponse, error) {
options := req.GetParameters()
clusterID, err := util.GetClusterID(options)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}

cr, err := util.NewUserCredentials(req.GetSecrets())
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
defer cr.DeleteCredentials()

monitors, _ /* clusterID*/, err := util.GetMonsAndClusterID(ctx, clusterID, false)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

// Get the cluster ID of the ceph cluster.
conn := &util.ClusterConnection{}
err = conn.Connect(monitors, cr)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to connect to MONs %q: %s", monitors, err)
}
defer conn.Destroy()

fsID, err := conn.GetFSID()
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get cephfs id: %s", err)
}

address, err := conn.GetAddrs()
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get client address: %s", err)
}

resp := &fence.GetFenceClientsResponse{
Clients: []*fence.ClientDetails{
{
Id: fsID,
Addresses: []*fence.CIDR{
{
Cidr: address,
},
},
},
},
}

return resp, nil
}

0 comments on commit ce25e16

Please sign in to comment.