Skip to content
This repository was archived by the owner on Sep 22, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions oci-mscluster-instance-principals.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def no_variable():
list = ['node1_name', 'node2_name', 'private_ip_id_default_cluster', 'vnic_1', 'vnic_2']
for i in list:
if not str(settings[i]):
print '!!! EMPTY ' + i + ' !!!'
print ('!!! EMPTY ' + i + ' !!!')
error_log('!!! EMPTY ' + i + ' !!!')
status_list.append('nok')
else:
Expand All @@ -45,7 +45,7 @@ def no_variable():
settings = json.load(file)
file.close()
except IOError:
print '\n!!! No settings.json file !!!'
print ('\n!!! No settings.json file !!!')
error_log('No settings.json file')
time.sleep(2)
sys.exit()
Expand All @@ -64,7 +64,7 @@ def no_variable():
private_ip_id_sql_cluster = str(settings['private_ip_id_sql_cluster'])

if sql_cluster_name and not private_ip_id_sql_cluster:
print '!!! EMPTY private_ip_id_sql_cluster !!!'
print ('!!! EMPTY private_ip_id_sql_cluster !!!')
error_log('!!! EMPTY private_ip_id_sql_cluster !!!')
time.sleep(2)
sys.exit()
Expand All @@ -87,7 +87,7 @@ def first_contact():
var2 = str(var1.split()[int(len(default_cluster_name.split(" ")))])
if var2 == node1_name or var2 == node2_name or var2 == skip_dr_node_name:
history_nodes.append(var2)
print 'New MASTER DEFAULT NODE detected --> ' + var2
print ('New MASTER DEFAULT NODE detected --> ') + var2
error_log('New MASTER DEFAULT NODE detected --> ' + var2)
if var2 == node1_name:
assign_to_different_vnic(private_ip_id_default_cluster, vnic_1)
Expand All @@ -96,7 +96,7 @@ def first_contact():
elif var2 == skip_dr_node_name:
pass
else:
print 'Invalid NODE'
print ('Invalid NODE')
error_log('Invalid NODE --> ' + var2)
time.sleep(2)
sys.exit()
Expand All @@ -108,7 +108,7 @@ def first_contact():
var2 = str(var1.split()[int(len(sql_cluster_name.split(" ")))])
if var2 == node1_name or var2 == node2_name or var2 == skip_dr_node_name:
history_nodes_sql.append(var2)
print 'New MASTER SQL NODE detected --> ' + var2
print ('New MASTER SQL NODE detected --> ') + var2
error_log('New MASTER SQL NODE detected --> ' + var2)
if var2 == node1_name:
assign_to_different_vnic(private_ip_id_sql_cluster, vnic_1)
Expand All @@ -117,7 +117,7 @@ def first_contact():
elif var2 == skip_dr_node_name:
pass
else:
print 'Invalid NODE'
print ('Invalid NODE')
error_log('Invalid NODE --> ' + var2)
time.sleep(2)
sys.exit()
Expand All @@ -135,10 +135,10 @@ def first_contact():
if var1.startswith(default_cluster_name):
var2 = str(var1.split()[int(len(default_cluster_name.split(" ")))])
if var2 == history_nodes[-1]:
print 'Nothing to change on OCI, ' + var2 + ' is the MASTER DEFAULT NODE'
print ('Nothing to change on OCI, ') + var2 + (' is the MASTER DEFAULT NODE')
else:
if var2 == node1_name or var2 == node2_name or var2 == skip_dr_node_name:
print 'New MASTER DEFAULT NODE detected --> ' + var2
print ('New MASTER DEFAULT NODE detected --> ') + var2
error_log('New MASTER DEFAULT NODE detected --> ' + var2)

if var2 == node1_name:
Expand All @@ -152,7 +152,7 @@ def first_contact():
if len(history_nodes) > 3:
history_nodes = history_nodes[-3:]
else:
print 'Invalid NODE'
print ('Invalid NODE')
error_log('Invalid NODE --> ' + var2)
if not sql_cluster_name:
pass
Expand All @@ -163,10 +163,10 @@ def first_contact():
if var1.startswith(sql_cluster_name):
var2 = str(var1.split()[int(len(sql_cluster_name.split(" ")))])
if var2 == history_nodes_sql[-1]:
print 'Nothing to change on OCI, ' + var2 + ' is the MASTER SQL NODE'
print ('Nothing to change on OCI, ') + var2 + (' is the MASTER SQL NODE')
else:
if var2 == node1_name or var2 == node2_name or var2 == skip_dr_node_name:
print 'New MASTER SQL NODE detected --> ' + var2
print ('New MASTER SQL NODE detected --> ') + var2
error_log('New MASTER SQL NODE detected --> ' + var2)

if var2 == node1_name:
Expand All @@ -180,7 +180,7 @@ def first_contact():
if len(history_nodes_sql) > 3:
history_nodes_sql = history_nodes_sql[-3:]
else:
print 'Invalid NODE'
print ('Invalid NODE')
error_log('Invalid NODE --> ' + var2)

time.sleep(1)
30 changes: 15 additions & 15 deletions oci-mscluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


def error_log(message):
error_log = open(os.path.dirname(os.path.realpath(sys.argv[0])) + '\error.log', 'a+b')
error_log = open(os.path.dirname(os.path.realpath(sys.argv[0])) + '\error.log', 'a')
error_log.write(str(datetime.now().strftime('%Y-%B-%d %H:%M:%S')) + ' ---> ' + message + '\n')
error_log.close()

Expand All @@ -40,7 +40,7 @@ def no_variable():
list = ['node1_name', 'node2_name', 'private_ip_id_default_cluster', 'vnic_1', 'vnic_2']
for i in list:
if not str(settings[i]):
print '!!! EMPTY ' + i + ' !!!'
print ('!!! EMPTY ' + i + ' !!!')
error_log('!!! EMPTY ' + i + ' !!!')
status_list.append('nok')
else:
Expand All @@ -57,7 +57,7 @@ def no_variable():
settings = json.load(file)
file.close()
except IOError:
print '\n!!! No settings.json file !!!'
print ('\n!!! No settings.json file !!!')
error_log('No settings.json file')
time.sleep(2)
sys.exit()
Expand All @@ -76,7 +76,7 @@ def no_variable():
private_ip_id_sql_cluster = str(settings['private_ip_id_sql_cluster'])

if sql_cluster_name and not private_ip_id_sql_cluster:
print '!!! EMPTY private_ip_id_sql_cluster !!!'
print ('!!! EMPTY private_ip_id_sql_cluster !!!')
error_log('!!! EMPTY private_ip_id_sql_cluster !!!')
time.sleep(2)
sys.exit()
Expand All @@ -99,7 +99,7 @@ def first_contact():
var2 = str(var1.split()[int(len(default_cluster_name.split(" ")))])
if var2 == node1_name or var2 == node2_name or var2 == skip_dr_node_name:
history_nodes.append(var2)
print 'New MASTER DEFAULT NODE detected --> ' + var2
print ('New MASTER DEFAULT NODE detected --> ' + var2)
error_log('New MASTER DEFAULT NODE detected --> ' + var2)
if var2 == node1_name:
assign_to_different_vnic(private_ip_id_default_cluster, vnic_1)
Expand All @@ -108,7 +108,7 @@ def first_contact():
elif var2 == skip_dr_node_name:
pass
else:
print 'Invalid NODE'
print ('Invalid NODE')
error_log('Invalid NODE --> ' + var2)
time.sleep(2)
sys.exit()
Expand All @@ -120,7 +120,7 @@ def first_contact():
var2 = str(var1.split()[int(len(sql_cluster_name.split(" ")))])
if var2 == node1_name or var2 == node2_name or var2 == skip_dr_node_name:
history_nodes_sql.append(var2)
print 'New MASTER SQL NODE detected --> ' + var2
print ('New MASTER SQL NODE detected --> ' + var2)
error_log('New MASTER SQL NODE detected --> ' + var2)
if var2 == node1_name:
assign_to_different_vnic(private_ip_id_sql_cluster, vnic_1)
Expand All @@ -129,7 +129,7 @@ def first_contact():
elif var2 == skip_dr_node_name:
pass
else:
print 'Invalid NODE'
print ('Invalid NODE')
error_log('Invalid NODE --> ' + var2)
time.sleep(2)
sys.exit()
Expand All @@ -147,10 +147,10 @@ def first_contact():
if var1.startswith(default_cluster_name):
var2 = str(var1.split()[int(len(default_cluster_name.split(" ")))])
if var2 == history_nodes[-1]:
print 'Nothing to change on OCI, ' + var2 + ' is the MASTER DEFAULT NODE'
print ('Nothing to change on OCI, ' + var2 + ' is the MASTER DEFAULT NODE')
else:
if var2 == node1_name or var2 == node2_name or var2 == skip_dr_node_name:
print 'New MASTER DEFAULT NODE detected --> ' + var2
print ('New MASTER DEFAULT NODE detected --> ' + var2)
error_log('New MASTER DEFAULT NODE detected --> ' + var2)

if var2 == node1_name:
Expand All @@ -164,7 +164,7 @@ def first_contact():
if len(history_nodes) > 3:
history_nodes = history_nodes[-3:]
else:
print 'Invalid NODE'
print ('Invalid NODE')
error_log('Invalid NODE --> ' + var2)
if not sql_cluster_name:
pass
Expand All @@ -175,10 +175,10 @@ def first_contact():
if var1.startswith(sql_cluster_name):
var2 = str(var1.split()[int(len(sql_cluster_name.split(" ")))])
if var2 == history_nodes_sql[-1]:
print 'Nothing to change on OCI, ' + var2 + ' is the MASTER SQL NODE'
print ('Nothing to change on OCI, ' + var2 + ' is the MASTER SQL NODE')
else:
if var2 == node1_name or var2 == node2_name or var2 == skip_dr_node_name:
print 'New MASTER SQL NODE detected --> ' + var2
print ('New MASTER SQL NODE detected --> ' + var2)
error_log('New MASTER SQL NODE detected --> ' + var2)

if var2 == node1_name:
Expand All @@ -192,7 +192,7 @@ def first_contact():
if len(history_nodes_sql) > 3:
history_nodes_sql = history_nodes_sql[-3:]
else:
print 'Invalid NODE'
print ('Invalid NODE')
error_log('Invalid NODE --> ' + var2)

time.sleep(1)
time.sleep(1)