Example #1
0
def timer_fired():
    """Do periodic housekeeping tasks. I'm a transient thread!
    """
    conn = connect_db(None)  # Assure this thread is connected to rethinkdb.
    try:
        r.now().run(conn, time_format="raw")  # Ping the database first.
    except RqlDriverError:
        print("{}: Database connection problem. Reconnecting.".format(dt.isoformat(dt.now())), file=sys.stderr)
        conn = connect_db(None)  # Make very sure we're connected to rethinkdb.
    db_refresh(conn)  # Refresh the timestamp on the machine_state
    conn.close()
    print("{}: Waiting for device changes (press ctrl+c to exit)".format(dt.isoformat(dt.now())))

    return True  # To fire the timer again.
Example #2
0
# System imports
import string
import sh
import re

# RethinkDB imports
from datetime import datetime
import rethinkdb as r
from rethinkdb.errors import RqlRuntimeError, RqlDriverError

from components.utils.basedb import connect_db, find_machine_state, verify_db_machine_state, verify_db_table
from components.utils.disktools import get_disk_sdinfo, get_disk_throughput

conn = None
conn = connect_db(conn)

machine_state_uuid = find_machine_state(conn)  # Verifies DB Automatically.
print("LocalDB: DiskUtils found a machine state: {}".format(machine_state_uuid))

### Local functions
def verify_db_tables(conn):
    try:
        verify_db_machine_state(conn)
        verify_db_table(conn, 'disk_results')
        verify_db_table(conn, 'job_results')
    except RqlRuntimeError:
        print("LocalDB: wanwipe database verified.")


### Remote commands
Example #3
0
import logging
import sys
import string
import re

from simplejson import dumps

from datetime import datetime as dt

# RethinkDB imports
import rethinkdb as r
from rethinkdb.errors import RqlRuntimeError, RqlDriverError

from components.utils.basedb import connect_db, find_machine_state, verify_db_table, verify_db_index

db_conn = connect_db(None)

machine_state_uuid = find_machine_state(db_conn)  # Verifies DB Automatically.
verify_db_table(db_conn, "disks")
verify_db_index(db_conn, "disks", "serial_no")
print("LocalDB: DiskMonitor found a machine state: {}".format(machine_state_uuid))

from components.utils.hosttools import get_global_ip, get_boot_id, get_dbus_machine_id
from components.utils.disktools import get_disk_sdinfo, get_disk_serial
from components.utils.smarttools import get_disk_smart, get_disk_realtime_status

from dbus import Array, SystemBus, Interface
from dbus.exceptions import DBusException
from dbus.mainloop.glib import DBusGMainLoop
# noinspection PyUnresolvedReferences
from gi.repository import GObject, GLib
Example #4
0
if __name__ == '__main__':
    # Create the option parser object
    parser = OptionParser(usage='Usage: %prog [options]')

    # Define command line options we'll respond to.
    parser.add_option('-c', '--connect', action='store', dest='hostname',
                      help='Manually select an image file. This image file must exist and be valid. Omitting this option will wipe a disk instead.')
    parser.add_option('-f', '--force', action='store_true', dest='force',
                      help='Force actions. This option will not prompt for confirmation before writing to a device, and implies the -u|--unmount option!')
    parser.add_option('-u', '--unmount', action='store_true', dest='unmount',
                      help='Unmount any mounted partitions on a device. This option will not prompt for unmounting any mounted partitions.')

    # If -h or --help are passed, the above will be displayed.
    options, args = parser.parse_args()

    if options.hostname:
        myhostname = options.hostname
    else:
        myhostname = 'localhost'

    # Redis queue connection setup so we can pass authentication
    q = Queue(connection=redis.StrictRedis(host=myhostname, port=6379, db=0, password=None))

    print("Trying to connect to Rethink...")
    conn = connect_db(None, myhostname)

    window = M3Window()
    window.connect("delete-event", Gtk.main_quit)
    window.show_all()
    Gtk.main()