Esempio n. 1
0
def create_db(device, db_device):
    """Creates a document to update with progress_db.
    :param device: The device object
    :param db_device: The bare name of the device ('sda', 'sdb')
    """
    verify_db_table(conn, 'wipe_results')
    # Insert Data
    inserted = r.db('wanwipe').table('wipe_results').insert({
        'started_at': r.now(),
        'updated_at': r.now(),
        'boot_id': get_boot_id(),
        'machine_id': get_dbus_machine_id(),
        'ip': get_global_ip(),
        'device': device.device_node,
        'name': device.name,
        'model': device.model,
        'serial': device.serial_no,
        'wwn': device.wwn_id,
        'wwn_long': device.wwn_long,
        'finished': False,
        'completed': False,
        'bus_type': device.bus_type,
        'bus_path': device.bus_path,
        'bus_topology': device.bus_topology,
        'in_progress': True,
        'progress': "  0%",
        'progress_bar': "==============================",
        'time_elapsed': "0:00:00",
        'time_remaining': "0:00:00",
        'total_bytes': device.size,
        'read_bytes': 0,
        'read_megs': 0,
        'total_megs': (device.size / (1024 * 1024)),
        'long_info': "{}".format(device)
    }).run(conn)
    print("diskaction: LocalDB: Writing to key: {}".format(inserted['generated_keys'][0]))
    # noinspection PyUnusedLocal
    machine_updated = r.db('wanwipe').table('machine_state').get(machine_state_uuid).update({ 'disks': {
        db_device: {'available': False, 'busy': True, 'wipe_results': inserted['generated_keys'][0],
                    'updated_at': r.now()}},
        'updated_at': r.now()}).run(conn)  # Update the record timestamp.
    return inserted['generated_keys'][0]
Esempio n. 2
0
def db_register_disk(conn, device):
    """Permanently stores a disk to the disks database.
    :param device: The device to add
    """
    # First we must populate basic information for the disk.
    try:
        inserted = r.db('wanwipe').table('disks').insert(
            {
                'serial_no': get_disk_serial(device),
                'device_name': device,
                'device_node': "/dev/{}".format(device),
                'host_ip': get_global_ip(),
                'boot_id': get_boot_id(),
                'machine_id': get_dbus_machine_id()
            }
        ).run(conn)
        print("{}: RegisterDisk: disk created: {}".format(dt.isoformat(dt.now()), inserted['generated_keys'][0]), file=sys.stderr)
        return inserted['generated_keys'][0]
    except RqlRuntimeError as kaboom:
        print("{}: RegisterDisk: disk creation failed somehow: {}".format(dt.isoformat(dt.now()), kaboom), file=sys.stderr)