-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
372 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
''' | ||
@helpdesk: SURFsara helpdesk <helpdesk@surfsara.nl> | ||
usage: python deleteTokens.py [viewname] | ||
e.g. python deleteTokens.py Monitor/error | ||
description: | ||
Connect to PiCaS server | ||
Delete all the Tokens in the [viewname] View | ||
''' | ||
|
||
import sys | ||
|
||
import couchdb | ||
import picasconfig | ||
|
||
|
||
def deleteDocs(db, viewname="Monitor/error"): | ||
v = db.view(viewname) | ||
for x in v: | ||
document = db[x['key']] | ||
db.delete(document) | ||
|
||
|
||
def get_db(): | ||
server = couchdb.Server(picasconfig.PICAS_HOST_URL) | ||
username = picasconfig.PICAS_USERNAME | ||
pwd = picasconfig.PICAS_PASSWORD | ||
server.resource.credentials = (username, pwd) | ||
db = server[picasconfig.PICAS_DATABASE] | ||
return db | ||
|
||
|
||
if __name__ == '__main__': | ||
# Create a connection to the server | ||
db = get_db() | ||
# Delete the Docs in [viewname] | ||
viewname = str(sys.argv[1]) | ||
deleteDocs(db, viewname) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
echo 'this is token 1' | ||
echo 'this is token 2' | ||
echo 'this is token 3' | ||
echo 'this is token A' | ||
echo 'this is token B' | ||
echo 'this is token C' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
''' | ||
@helpdesk: SURFsara helpdesk <helpdesk@surfsara.nl> | ||
usage: python resetTokens.py [viewname] [locktime] | ||
e.g. python resetTokens.py Monitor/locked 72 | ||
description: | ||
Connect to PiCaS server | ||
Reset all Tokens in [viewname] View that have been locked more than [hours] hours, | ||
defaults to 0 hours to reset all tokens | ||
''' | ||
|
||
import sys | ||
|
||
import couchdb | ||
from time import time | ||
import picasconfig | ||
|
||
def resetDocs(db, viewname="Monitor/locked", locktime=0): | ||
v = db.view(viewname) | ||
max_age = locktime * 3600 | ||
to_update = [] | ||
for x in v: | ||
document = db[x['key']] | ||
age = time() - document["lock"] | ||
print(age) | ||
if (age > max_age): | ||
document['lock'] = 0 | ||
document['done'] = 0 | ||
document['scrub_count'] += 1 | ||
document['hostname'] = '' | ||
document['exit_code'] = '' | ||
if '_attachments' in document: | ||
del document["_attachments"] | ||
to_update.append(document) | ||
db.update(to_update) | ||
print("Number of reset tokens: " + str(len(to_update))) | ||
|
||
|
||
def get_db(): | ||
server = couchdb.Server(picasconfig.PICAS_HOST_URL) | ||
username = picasconfig.PICAS_USERNAME | ||
pwd = picasconfig.PICAS_PASSWORD | ||
server.resource.credentials = (username, pwd) | ||
db = server[picasconfig.PICAS_DATABASE] | ||
return db | ||
|
||
|
||
if __name__ == '__main__': | ||
# Create a connection to the server | ||
db = get_db() | ||
|
||
if len(sys.argv)==1: | ||
sys.exit("Error: No viewname provided. To reset all locked tokens: `python resetTokens.py Monitor/locked`") | ||
elif len(sys.argv)>1: | ||
# reset the Docs in [viewname] | ||
viewname = str(sys.argv[1]) | ||
if len(sys.argv)==2: | ||
print("Warning: No locktime provided. Will reset all tokens in view ", viewname) | ||
input("Press Enter to continue or Ctrl+C to cancel.") | ||
# default: reset all locked tokens | ||
locktime=0 | ||
else: | ||
locktime=float(sys.argv[2]) | ||
|
||
|
||
resetDocs(db, viewname, locktime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,9 @@ def save(self, doc): | |
|
||
return doc | ||
|
||
def copy(self): | ||
return self | ||
|
||
|
||
class MockEmptyDB(MockDB): | ||
TASKS = [] | ||
|