forked from openebs/rawfile-localpv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rawfile.py
executable file
·57 lines (47 loc) · 1.65 KB
/
rawfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
import logging
from concurrent import futures
import click
import grpc
import bd2fs
import rawfile_servicer
from consts import CONFIG
from csi import csi_pb2_grpc
from metrics import expose_metrics
from rawfile_util import migrate_all_volume_schemas, gc_all_volumes
@click.group()
@click.option("--image-repository", envvar="IMAGE_REPOSITORY")
@click.option("--image-tag", envvar="IMAGE_TAG")
def cli(image_repository, image_tag):
CONFIG["image_repository"] = image_repository
CONFIG["image_tag"] = image_tag
@cli.command()
@click.option("--endpoint", envvar="CSI_ENDPOINT", default="0.0.0.0:5000")
@click.option("--nodeid", envvar="NODE_ID")
@click.option("--enable-metrics/--disable-metrics", default=True)
def csi_driver(endpoint, nodeid, enable_metrics):
migrate_all_volume_schemas()
if enable_metrics:
expose_metrics(nodeid)
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
csi_pb2_grpc.add_IdentityServicer_to_server(
bd2fs.Bd2FsIdentityServicer(rawfile_servicer.RawFileIdentityServicer()), server
)
csi_pb2_grpc.add_NodeServicer_to_server(
bd2fs.Bd2FsNodeServicer(rawfile_servicer.RawFileNodeServicer(node_name=nodeid)),
server,
)
csi_pb2_grpc.add_ControllerServicer_to_server(
bd2fs.Bd2FsControllerServicer(rawfile_servicer.RawFileControllerServicer()),
server,
)
server.add_insecure_port(endpoint)
server.start()
server.wait_for_termination()
@cli.command()
@click.option("--dry-run/--seriously", default=True)
def gc(dry_run):
gc_all_volumes(dry_run=dry_run)
if __name__ == "__main__":
logging.basicConfig()
cli()