Capsuling a tube shape in a volume
Ok, after quite a bit of experimentation, this is what I came up with:


The green group (which is duplicated, because I couldn't get it to work otherwise) creates  half spheres, which I then append to the ends of a cylinder. As of now, changing the node setup is made so that the cylinder is aligned with the Z axis; you can model your object that way, to start, and then rotate it around, remembering not to apply the rotation. Also, changing the Z Cylinder Scale input value in the material allows you to scale the whole construction.

You can get the blend file here.