Skip to content

Instantly share code, notes, and snippets.

@reillychase
Created November 13, 2018 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reillychase/df0fe45e405e381e9c78fd76b4cee867 to your computer and use it in GitHub Desktop.
Save reillychase/df0fe45e405e381e9c78fd76b4cee867 to your computer and use it in GitHub Desktop.
hostifi-mysql
# Get list of servers already built
db = MySQLdb.connect("localhost","user","password@!","hostifi" )
cursor = db.cursor()
sql = "SELECT * FROM server"
vultr_check = []
try:
# Execute the SQL command
cursor.execute(sql)
# Fetch all the rows in a list of lists.
results = cursor.fetchall()
for row in results:
this_list = []
id_no = int(row[0])
customer_id = int(row[1])
product_id = int(row[2])
status = str(row[3])
wp_edd_sub_id = int(row[4])
server_ip = row[5]
server_name = row[6]
admin_pw = row[7]
site_id = row[8]
site_name = row[9]
zabbix_host_id = row[15]
this_list.append(id_no)
this_list.append(customer_id)
this_list.append(product_id)
this_list.append(status)
this_list.append(wp_edd_sub_id)
this_list.append(server_ip)
this_list.append(server_name)
this_list.append(admin_pw)
this_list.append(site_id)
this_list.append(site_name)
this_list.append(zabbix_host_id)
vultr_check.append(this_list)
except Exception as e:
print "Error: " + str(e)
print vultr_check
sql = "SELECT * FROM wp_edd_subscriptions where status = 'active'"
wp_edd_subscriptions = []
try:
# Execute the SQL command
cursor.execute(sql)
# Fetch all the rows in a list of lists.
results = cursor.fetchall()
for row in results:
this_list = []
id_no = int(row[0])
customer_id = int(row[1])
product_id = int(row[8])
this_list.append(id_no)
this_list.append(customer_id)
this_list.append(product_id)
wp_edd_subscriptions.append(this_list)
except Exception as e:
print "Error: " + str(e)
for active_sub in wp_edd_subscriptions:
###
### Begin destroying cancelled packages:
###
sql = "SELECT * FROM vultr_check"
vultr_check = []
try:
# Execute the SQL command
cursor.execute(sql)
# Fetch all the rows in a list of lists.
results = cursor.fetchall()
for row in results:
this_list = []
id_no = int(row[0])
customer_id = int(row[1])
product_id = int(row[2])
status = str(row[3])
wp_edd_sub_id = int(row[4])
server_ip = row[5]
server_name = row[6]
admin_pw = row[7]
site_id = row[8]
site_name = row[9]
username = row[10]
email = row[11]
delete_request = row[17]
zabbix_host_id = row[15]
this_list.append(id_no)
this_list.append(customer_id)
this_list.append(product_id)
this_list.append(status)
this_list.append(wp_edd_sub_id)
this_list.append(server_ip)
this_list.append(server_name)
this_list.append(admin_pw)
this_list.append(site_id)
this_list.append(site_name)
this_list.append(username)
this_list.append(email)
this_list.append(zabbix_host_id)
this_list.append(delete_request)
vultr_check.append(this_list)
except Exception as e:
print "Error: " + str(e)
print vultr_check
sql = "SELECT * FROM wp_edd_subscriptions where status = 'cancelled'"
wp_edd_subscriptions = []
try:
# Execute the SQL command
cursor.execute(sql)
# Fetch all the rows in a list of lists.
results = cursor.fetchall()
for row in results:
this_list = []
id_no = int(row[0])
customer_id = int(row[1])
product_id = int(row[8])
this_list.append(id_no)
this_list.append(customer_id)
this_list.append(product_id)
wp_edd_subscriptions.append(this_list)
except Exception as e:
print "Error: " + str(e)
to_be_cancelled = []
for cancelled_sub in wp_edd_subscriptions:
for vultr_created in vultr_check:
if cancelled_sub[0] == vultr_created[4]:
print cancelled_sub
print "Needs to be cancelled"
to_be_cancelled.append(vultr_created)
for cancel_me in to_be_cancelled:
print cancel_me
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment