|
1 | 1 | #!/usr/bin/env python
|
2 | 2 |
|
3 | 3 | import logging
|
4 |
| -import sys |
5 |
| -import os |
6 |
| -import errno |
7 | 4 | import six
|
8 | 5 | import argparse
|
9 | 6 | import sys
|
10 | 7 | try:
|
11 | 8 | from fuse import FUSE, FuseOSError, Operations, LoggingMixIn
|
12 | 9 | except EnvironmentError:
|
13 |
| - print "It looks like the Fuse system library is missing." |
14 |
| - print "Please install libfuse using your OS's package manager, or download OSXFUSE if you're on a Mac" |
| 10 | + print("It looks like the Fuse system library is missing.") |
| 11 | + print("Please install libfuse using your OS's package manager, or download OSXFUSE if you're on a Mac") |
15 | 12 | sys.exit(1)
|
16 | 13 |
|
17 | 14 |
|
18 | 15 | from . import client
|
19 |
| -from . import filesystem |
| 16 | +from . import filesystem |
| 17 | + |
20 | 18 |
|
21 | 19 | class KubeFuse(LoggingMixIn, Operations):
|
22 | 20 |
|
23 |
| - def __init__(self, mount, kubeconfig = None, cluster = None, context = None, user = None): |
| 21 | + def __init__(self, mount, kubeconfig=None, cluster=None, context=None, user=None): |
24 | 22 | self.client = client.KubernetesClient(kubeconfig, cluster, context, user)
|
25 | 23 | self.fs = filesystem.KubeFileSystem(self.client)
|
26 | 24 | self.fd = 0
|
@@ -58,23 +56,32 @@ def release(self, path, fh):
|
58 | 56 |
|
59 | 57 | def parse_args():
|
60 | 58 | parser = argparse.ArgumentParser(description='A file system view for Kubernetes')
|
61 |
| - parser.add_argument('mountpoint', metavar='MOUNTPOINT', type=str, |
62 |
| - help='The directory to mount on') |
63 |
| - parser.add_argument('--kubeconfig', dest='kubeconfig', |
64 |
| - help='Path to the kubeconfig file') |
65 |
| - parser.add_argument('--cluster', dest='cluster', |
66 |
| - help='The name of the kubeconfig cluster to use') |
67 |
| - parser.add_argument('--context', dest='context', |
68 |
| - help='The name of the kubeconfig context to use') |
69 |
| - parser.add_argument('--user', dest='user', |
70 |
| - help='The name of the kubeconfig user to use') |
| 59 | + parser.add_argument('mountpoint', metavar='MOUNTPOINT', type=str, |
| 60 | + help='The directory to mount on') |
| 61 | + parser.add_argument('--kubeconfig', dest='kubeconfig', |
| 62 | + help='Path to the kubeconfig file') |
| 63 | + parser.add_argument('--cluster', dest='cluster', |
| 64 | + help='The name of the kubeconfig cluster to use') |
| 65 | + parser.add_argument('--context', dest='context', |
| 66 | + help='The name of the kubeconfig context to use') |
| 67 | + parser.add_argument('--user', dest='user', |
| 68 | + help='The name of the kubeconfig user to use') |
| 69 | + parser.add_argument('--verbose', '-v', action='count', dest='verbosity', |
| 70 | + default=0, help='Verbosity of program output') |
71 | 71 | return parser.parse_args()
|
72 | 72 |
|
73 | 73 | def main():
|
74 | 74 | args = parse_args()
|
75 |
| - logging.basicConfig(level=logging.INFO) |
76 |
| - fuse = FUSE(KubeFuse(args.mountpoint, args.kubeconfig, args.cluster, args.context), |
77 |
| - args.mountpoint, foreground=True) |
| 75 | + if args.verbosity == 0: |
| 76 | + logging.basicConfig(level=logging.WARNING) |
| 77 | + elif args.verbosity == 1: |
| 78 | + logging.basicConfig(level=logging.INFO) |
| 79 | + elif args.verbosity == 2: |
| 80 | + logging.basicConfig(level=logging.DEBUG) |
| 81 | + else: |
| 82 | + logging.basicConfig(level=0) |
| 83 | + FUSE(KubeFuse(args.mountpoint, args.kubeconfig, args.cluster, args.context), |
| 84 | + args.mountpoint, foreground=True) |
78 | 85 |
|
79 | 86 | if __name__ == '__main__':
|
80 | 87 | main()
|
0 commit comments