rbd: parse IP address

The address we get from ceph
contains the ip in the format
of 10.244.0.1:0/2686266785 we
need to extract the client IP
from this address, we already
have a helper to extract it,
This makes the helper more generic
can be reused by multiple packages
in the fence controller.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna
2024-11-05 11:17:22 +01:00
committed by mergify[bot]
parent facf805941
commit b4592a55eb
3 changed files with 80 additions and 26 deletions

View File

@ -155,13 +155,23 @@ func (fcs *FenceControllerServer) GetFenceClients(
return nil, status.Errorf(codes.Internal, "failed to get client address: %s", err)
}
// The example address we get is 10.244.0.1:0/2686266785 from
// which we need to extract the IP address.
addr, err := nf.ParseClientIP(address)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to parse client address: %s", err)
}
// adding /32 to the IP address to make it a CIDR block.
addr += "/32"
resp := &fence.GetFenceClientsResponse{
Clients: []*fence.ClientDetails{
{
Id: fsID,
Addresses: []*fence.CIDR{
{
Cidr: address,
Cidr: addr,
},
},
},