Make parameters configurable via envoronment variables
This commit is contained in:
parent
0be4bce96f
commit
2e6826a414
36
main.py
36
main.py
@ -11,19 +11,22 @@ import csi_pb2_grpc
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
#csi_sock_full_path = "/Users/andre/Projects/opensource/gluster-dir-csi/csi.sock"
|
|
||||||
csi_sock_full_path = "/csi/csi.sock"
|
gluster_host = os.environ["GLUSTER_HOST"]
|
||||||
gluster_host = "10.0.114.218"
|
gluster_volume = os.environ["GLUSTER_VOLUME"]
|
||||||
gluster_volume = "vol_main"
|
|
||||||
|
csi_sock_full_path = os.environ.get("CSI_PATH", "/csi/csi.sock")
|
||||||
|
|
||||||
|
|
||||||
def unmount(path):
|
def unmount(path):
|
||||||
print("Unmounting", path)
|
print("Unmounting", path)
|
||||||
return subprocess.run(["umount", path])
|
return subprocess.run(["umount", path])
|
||||||
|
|
||||||
|
|
||||||
def mount(volume, path):
|
def mount(volume, path):
|
||||||
print("Mounting", volume, "at", path)
|
print("Mounting", volume, "at", path)
|
||||||
p = subprocess.run(["mount","-t", "glusterfs", "%s:/%s/%s" % (gluster_host, gluster_volume, volume), path])
|
p = subprocess.run(["mount", "-t", "glusterfs", "%s:/%s/%s" %
|
||||||
|
(gluster_host, gluster_volume, volume), path])
|
||||||
if p.returncode == 0:
|
if p.returncode == 0:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -45,15 +48,18 @@ class Identity(csi_pb2_grpc.Identity):
|
|||||||
return csi_pb2.GetPluginCapabilitiesResponse(
|
return csi_pb2.GetPluginCapabilitiesResponse(
|
||||||
capabilities=[
|
capabilities=[
|
||||||
csi_pb2.PluginCapability(
|
csi_pb2.PluginCapability(
|
||||||
service=csi_pb2.PluginCapability.Service(type=csi_pb2.PluginCapability.Service.Type.CONTROLLER_SERVICE)
|
service=csi_pb2.PluginCapability.Service(
|
||||||
|
type=csi_pb2.PluginCapability.Service.Type.CONTROLLER_SERVICE)
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
class Controller(csi_pb2_grpc.Controller):
|
class Controller(csi_pb2_grpc.Controller):
|
||||||
|
|
||||||
def ControllerGetCapabilities(self, request, context):
|
def ControllerGetCapabilities(self, request, context):
|
||||||
return csi_pb2.ControllerGetCapabilitiesResponse(capabilities=[
|
return csi_pb2.ControllerGetCapabilitiesResponse(capabilities=[
|
||||||
csi_pb2.ControllerServiceCapability(rpc = csi_pb2.ControllerServiceCapability.RPC(type=csi_pb2.ControllerServiceCapability.RPC.Type.CREATE_DELETE_VOLUME)),
|
csi_pb2.ControllerServiceCapability(rpc=csi_pb2.ControllerServiceCapability.RPC(
|
||||||
|
type=csi_pb2.ControllerServiceCapability.RPC.Type.CREATE_DELETE_VOLUME)),
|
||||||
])
|
])
|
||||||
|
|
||||||
def CreateVolume(self, request, context):
|
def CreateVolume(self, request, context):
|
||||||
@ -61,7 +67,8 @@ class Controller(csi_pb2_grpc.Controller):
|
|||||||
print("CreateVolume", name)
|
print("CreateVolume", name)
|
||||||
p = subprocess.run(["mkdir", "-p", "/mnt/main/%s" % name])
|
p = subprocess.run(["mkdir", "-p", "/mnt/main/%s" % name])
|
||||||
volume = csi_pb2.Volume(volume_id=name)
|
volume = csi_pb2.Volume(volume_id=name)
|
||||||
return csi_pb2.CreateVolumeResponse(volume=volume);
|
return csi_pb2.CreateVolumeResponse(volume=volume)
|
||||||
|
|
||||||
|
|
||||||
class Node(csi_pb2_grpc.Node):
|
class Node(csi_pb2_grpc.Node):
|
||||||
|
|
||||||
@ -71,8 +78,9 @@ class Node(csi_pb2_grpc.Node):
|
|||||||
|
|
||||||
def NodeGetCapabilities(self, request, context):
|
def NodeGetCapabilities(self, request, context):
|
||||||
return csi_pb2.NodeGetCapabilitiesResponse(capabilities=[
|
return csi_pb2.NodeGetCapabilitiesResponse(capabilities=[
|
||||||
csi_pb2.NodeServiceCapability(rpc= csi_pb2.NodeServiceCapability.RPC(type = csi_pb2.NodeServiceCapability.RPC.Type.STAGE_UNSTAGE_VOLUME))
|
csi_pb2.NodeServiceCapability(rpc=csi_pb2.NodeServiceCapability.RPC(
|
||||||
]);
|
type=csi_pb2.NodeServiceCapability.RPC.Type.STAGE_UNSTAGE_VOLUME))
|
||||||
|
])
|
||||||
|
|
||||||
def NodePublishVolume(self, request, context):
|
def NodePublishVolume(self, request, context):
|
||||||
volume_id = request.volume_id
|
volume_id = request.volume_id
|
||||||
@ -81,14 +89,14 @@ class Node(csi_pb2_grpc.Node):
|
|||||||
p = subprocess.run(["mkdir", "-p", path], check=True)
|
p = subprocess.run(["mkdir", "-p", path], check=True)
|
||||||
res = mount(volume_id, path)
|
res = mount(volume_id, path)
|
||||||
if res is True:
|
if res is True:
|
||||||
return csi_pb2.NodePublishVolumeResponse();
|
return csi_pb2.NodePublishVolumeResponse()
|
||||||
print(res)
|
print(res)
|
||||||
|
|
||||||
def NodeUnpublishVolume(self, request, context):
|
def NodeUnpublishVolume(self, request, context):
|
||||||
path = request.target_path
|
path = request.target_path
|
||||||
print("NodeUnpublishVolume", path)
|
print("NodeUnpublishVolume", path)
|
||||||
p = subprocess.run(["umount", path])
|
p = subprocess.run(["umount", path])
|
||||||
return csi_pb2.NodeUnpublishVolumeResponse();
|
return csi_pb2.NodeUnpublishVolumeResponse()
|
||||||
|
|
||||||
def NodeStageVolume(self, request, context):
|
def NodeStageVolume(self, request, context):
|
||||||
volume_id = request.volume_id
|
volume_id = request.volume_id
|
||||||
@ -118,9 +126,11 @@ def serve():
|
|||||||
print("Waiting for termination")
|
print("Waiting for termination")
|
||||||
server.wait_for_termination()
|
server.wait_for_termination()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
p = subprocess.run(["mkdir", "-p", "/mnt/main"])
|
p = subprocess.run(["mkdir", "-p", "/mnt/main"])
|
||||||
p = subprocess.run(["mount", "-t", "glusterfs", "%s:/%s" % (gluster_host, gluster_volume), "/mnt/main"],check=True)
|
p = subprocess.run(["mount", "-t", "glusterfs", "%s:/%s" %
|
||||||
|
(gluster_host, gluster_volume), "/mnt/main"], check=True)
|
||||||
|
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
serve()
|
serve()
|
||||||
|
Loading…
Reference in New Issue
Block a user