-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclist
117 lines (97 loc) · 3.22 KB
/
clist
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
#!/usr/bin/env python2
try:
import sys, os
######### set defaultt c3 path ########################
try:
def_path = os.environ[ 'C3_PATH' ]
except KeyError:
def_path = '/opt/c3-4'
#######################################################
sys.path.append( def_path )
import c3_com_obj, c3_file_obj, socket, re
######## constants ####################################
help_info = """c3 version 4.0
Usage: clist [OPTIONS]
--help -h = this screen
--file -f = file containing list of ip's if
one is not supplied then
/etc/c3.conf will be used
"""
backslash = re.compile( r"\\" )
filename = "/etc/c3.conf" #default config file
#######################################################
# first create one large string of the command
command_line_list = sys.argv[1:]
command_line_string = ''
for item in command_line_list:
command_line_string = '%s %s' % (command_line_string, item)
# object used to parse command line
c3_command = c3_com_obj.c3_command_line( command_line_string )
# get first option
try:
file_set = 0
option = c3_command.get_opt()
while option: # while more options
if option == '-h' or option == "--help": # print help info
print help_info
print "exiting...."
sys.exit()
elif (option == '-f') or (option == '--file'): # alternate config file
if not file_set:
filename = c3_command.get_opt_string()
file_set = 1
else:
print "only one file name can be specified."
sys.exit()
else:
print "invalid option"
sys.exit()
option = c3_command.get_opt()
except c3_com_obj.end_of_option:
pass
######### set filename ##########################
if not file_set:
try:
filename = os.environ[ 'C3_CONF' ]
except KeyError:
filename = '/etc/c3.conf'
#######################################################
######### make cluster list object from file ##########
try: # open file & initialize file parser
file = c3_file_obj.cluster_def( filename )
except IOError:
print "error opening file: ", filename
sys.exit()
try:
while(1): #throws exception when no more clusters
file.get_next_cluster()
try:
local_ip = socket.gethostbyname( socket.gethostname() )
except socket.error:
print "Can not resolve local hostname"
sys.exit()
try:
int_ip = socket.gethostbyname( file.get_internal_head_node() )
except socket.error:
int_ip = ""
try:
ext_ip = socket.gethostbyname( file.get_external_head_node() )
except socket.error:
ext_ip = ""
except TypeError:
ext_ip = int_ip
if file.get_external_head_node():
if ext_ip == local_ip or int_ip == local_ip:
print "cluster ", file.get_cluster_name(), " is a direct local cluster"
else:
print "cluster ", file.get_cluster_name(), " is a direct remote cluster"
else:
print "cluster ", file.get_cluster_name(), " is an indirect remote cluster"
except c3_file_obj.no_more_clusters:
pass
except c3_file_obj.parse_error, error:
print error.description
print "somewhere around ", error.last
sys.exit()
except KeyboardInterrupt:
print "Keyboard interrupt\n"