-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathccm
More file actions
executable file
·141 lines (113 loc) · 4.44 KB
/
ccm
File metadata and controls
executable file
·141 lines (113 loc) · 4.44 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
import warnings
from six import print_
from ccmlib import common
from ccmlib.cmds import cluster_cmds, node_cmds
from ccmlib.cmds.common import get_command
from ccmlib.remote import (PARAMIKO_IS_AVAILABLE, execute_ccm_remotely,
get_remote_options, get_remote_usage)
try: # Python 3.8+
from importlib.metadata import entry_points
except ImportError: # pragma: no cover - fallback for older Pythons
try:
from importlib_metadata import entry_points # type: ignore
except ImportError:
entry_points = None
def print_subcommand_usage(kind):
for cmd_name in (cluster_cmds if kind.lower() == 'cluster' else node_cmds).commands():
cmd = get_command(kind, cmd_name)
if not cmd:
print_("Internal error, unknown command {0}".format(cmd_name))
exit(1)
print_(" {0:14} {1}".format(cmd_name, cmd.description()))
def print_global_usage():
print_("Usage:")
remote_options = ""
if PARAMIKO_IS_AVAILABLE:
remote_options = " [remote_options]"
print_(" ccm" + remote_options + " <cluster_cmd> [options]")
print_(" ccm" + remote_options + " <node_name> <node_cmd> [options]")
if PARAMIKO_IS_AVAILABLE:
print_("")
print_(get_remote_usage())
print_("")
print_("Where <cluster_cmd> is one of")
print_subcommand_usage('cluster')
print_("")
print_("or <node_name> is the name of a node of the current cluster and <node_cmd> is one of")
print_subcommand_usage('node')
exit(1)
def _iter_ccm_extension_entry_points():
if entry_points is None:
warnings.warn("importlib.metadata not available; skipping ccm_extension entry points")
return []
eps = entry_points()
if hasattr(eps, 'select'): # modern importlib.metadata
return eps.select(group='ccm_extension')
if isinstance(eps, dict): # older importlib_metadata returns dict
return eps.get('ccm_extension', [])
return [ep for ep in eps if getattr(ep, 'group', None) == 'ccm_extension']
for entry_point in _iter_ccm_extension_entry_points():
entry_point.load()()
common.check_win_requirements()
if len(sys.argv) <= 1:
print_("Missing arguments")
print_global_usage()
arg1 = sys.argv[1].lower()
# show-*-cmds are undocumented commands that emit a list of
# the appropriate type of subcommand. This is used by the bash completion script.
if arg1 == 'show-cluster-cmds':
for cmd_name in cluster_cmds.commands():
print_(cmd_name)
exit(1)
if arg1 == 'show-node-cmds':
for cmd_name in node_cmds.commands():
print_(cmd_name)
exit(1)
# Attempt a remote execution (only occurs if remote options are valid and ssh_host is set)
# NOTE: An execption may be thrown if there are errors
if PARAMIKO_IS_AVAILABLE:
remote_options, ccm_args = get_remote_options();
if not remote_options is None and not remote_options.ssh_host is None:
ouput, exit_status = execute_ccm_remotely(remote_options, ccm_args)
sys.exit(exit_status)
if arg1 in cluster_cmds.commands():
kind = 'cluster'
cmd = arg1
cmd_args = sys.argv[2:]
else:
if len(sys.argv) <= 2:
print_("Missing arguments")
print_global_usage()
kind = 'node'
node = arg1
cmd = sys.argv[2]
cmd_args = [node] + sys.argv[3:]
if os.getenv('CASSANDRA_HOME') is not None:
warnings.warn("'CASSANDRA_HOME' is set to be {}".format(os.getenv('CASSANDRA_HOME')))
cmd = get_command(kind, cmd)
if not cmd:
print_("Unknown node or command: {0}".format(arg1))
exit(1)
parser = cmd.get_parser()
(options, args) = parser.parse_args(cmd_args)
cmd.validate(parser, options, args)
cmd.run()