Skip to content

Instantly share code, notes, and snippets.

@lauriehawkins
Last active January 12, 2016 09:47
Show Gist options
  • Save lauriehawkins/63c9acfed9af8b59d3be to your computer and use it in GitHub Desktop.
Save lauriehawkins/63c9acfed9af8b59d3be to your computer and use it in GitHub Desktop.
dropping mongo tables
__author__ = 'laurie'
import bottle
import os
from bottle import route, run, template, static_file
from pymongo import MongoClient
bottle.TEMPLATE_PATH.insert(0, '/home/laurie/devops_tools/table_drop')
qa_uri = "mongodb://mtkAdmin:M0t0rtr4k@mongod.qa2.motortrak.com:27107,mongod.docker-dev-01.motortrak.com:27107,mongod.mtkdb401.motortrak.com:27017/?replicaSet=mtk-devqa-rs0"
qa_client = MongoClient(qa_uri)
qa_db = qa_client["mtk-dev-vehicle-inventory"]
uat_uri= "mongodb://mongod.docker-dev-01.motortrak.com:49154"
uat_client = MongoClient(uat_uri)
uat_db= uat_client["mtk-uat-vehicle-inventory"]
unwanted_tables = ["vehicles", "currencies", "invalid_docs", "sync_reports",
"system.indexes", "transkiaford", "vehicle_api_test"]
@route('/tables', method='POST')
def index():
table = bottle.request.forms.get('table')
database = bottle.request.forms.get('database')
if (database == "qa_db"):
drop_table(database, table)
bottle.redirect('/tables')
elif (database == "uat_db"):
drop_table(database, table)
bottle.redirect('/tables')
@route('/tables')
def show_table():
qa_collections = qa_db.collection_names()
uat_collections = uat_db.collection_names()
for item in unwanted_tables:
if item in qa_collections:
qa_collections.remove(item)
if item in uat_collections:
uat_collections.remove(item)
else:
pass
return template("tables.tpl", qa_collections=qa_collections,
uat_collections=uat_collections)
def drop_table(database, table):
database.drop_collection(str(table))
if __name__ == '__main__':
port = int(os.environ.get('PORT', 8088))
run(host='0.0.0.0', port=port, debug=True)
<html>
<head>
<title>Mongo Tables</title>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;border-color:#999;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:12px 17px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#444;background-color:#F7FDFA;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:12px 17px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#999;color:#fff;background-color:#26ADE4;}
.tg .tg-s6z2{text-align:center}
</style>
</head>
<body>
<h1> QA Mongo Tables</h1>
<table id='t1' class="tg">
<form action="/tables" method="POST">
<input type="hidden" name="database" value="qa_db" />
%for table in qa_collections:
<button type="submit" name="table" value="{{table}}">{{table}}</button>
%end
</form>
</table>
<h1> UAT Mongo Tables</h1>
<table id='t1' class="tg">
<form action="/tables" method="POST">
<input type="hidden" name="database" value="uat_db" />
%for table in uat_collections:
<button type="submit" name="table" value="{{table}}">{{table}}</button>
%end
</form>
</table>
<!--<h1> Production Mongo Tables</h1>-->
<!--<table id='t1' class="tg">-->
<!--%for table in collections:-->
<!--<button type="button" onclick="alert('{{table}}')">{{table}}</button>-->
<!--&lt;!&ndash;<td>{{table}}</td>&ndash;&gt;-->
<!--%end-->
<!--</table>-->
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment