Skip to content

Instantly share code, notes, and snippets.

@ytjohn
Created June 24, 2016 18:47
Show Gist options
  • Save ytjohn/a4f4f99ac9146a21e23c04c558b329a1 to your computer and use it in GitHub Desktop.
Save ytjohn/a4f4f99ac9146a21e23c04c558b329a1 to your computer and use it in GitHub Desktop.
add interface-map to rubicon catalog data
#!/usr/bin/env python
# requires: `pip install pymongo`
from pymongo import MongoClient
INTERFACE_MAP = {"p3p2": "eth1", "p3p1": "eth0"}
def update_catalogs(db):
result = db.catalogs.update_many(
{u'source': u'rubicon'},
{
"$set": {
"data.interface-map": INTERFACE_MAP
},
}
)
print(result.matched_count)
print(result.modified_count)
if __name__ == '__main__':
client = MongoClient()
db = client.pxe
r1 = db.catalogs.find({"source": "rubicon"})
print("{0} found".format(r1.count()))
print r1[0]
update_catalogs(db)
r2 = db.catalogs.find({"source": "rubicon"})
print("{0} found".format(r2.count()))
print r1[0]['data']['interface-map']
@ytjohn
Copy link
Author

ytjohn commented Jun 24, 2016

This is heavy fisted because it updates any catalog of source rubicon. Once we get away from Dell Ark nodes, we will not want to run this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment