Exemple #1
0
def _shares(unraid):
    # Parse shares page
    soup = BeautifulSoup(
        unraid.get(
            '/webGui/include/ShareList.php?compute=no&path=Shares&scale=-1' +
            '&number=.%2C').text, 'lxml')
    shares = []

    for share in soup.find_all('tr'):
        s = Share()

        # Find share status
        s.status = SHARE_STATUS[share.find_all('a')[0].text]

        # Find share name
        s.name = share.find_all('a')[1].text

        # Find share comment
        s.comment = share.find_all('td')[1].text

        # Find SMB security
        s.smb_security = SHARE_SECURITY[share.find_all('td')[2].text]

        # Find SMB security
        s.nfs_security = SHARE_SECURITY[share.find_all('td')[3].text]

        # Find free space
        s.free_size = parse_size(share.find_all('td')[6].text)

        s._set_unraid(unraid)

        shares.append(s)

    return shares
Exemple #2
0
    def _parse_directory(self, table):
        """Internal function to parse path directory table."""
        path = []

        for row in table.select('tbody tr'):
            p = {
                'type': '',
                'name': '',
                'size': 0,
                'last_modified': '',
                'location': ''
            }

            # Find path type
            if row.select('tr div.icon-file'):
                p['type'] = 'FILE'

            if row.select('tr div.icon-dir'):
                p['type'] = 'FOLDER'

            # Find path name
            p['name'] = row.find_all('td')[1].text.strip()

            # Find path size
            p['size'] = parse_size(row.find_all('td')[2].text.strip())

            # Find last modified date
            p['last_modified'] = row.find_all('td')[3].text.strip()

            # Find location
            p['location'] = row.find_all('td')[4].text.strip()

            path.append(p)

        return path
Exemple #3
0
def _find_vdisks(soup, index):
    vdisks = []

    row = soup.find(id="name-" + index)
    vdisk_rows = row.select('#domdisk_list tr')

    for row in vdisk_rows:
        vdisks.append({
            'path':
            row.find_all('td')[0].text,
            'bus':
            row.find_all('td')[1].text,
            'capacity':
            parse_size(_add_space(row.find_all('td')[2].text.strip())),
            'allocation':
            parse_size(_add_space(row.find_all('td')[3].text.strip()))
        })

    return vdisks
Exemple #4
0
def _vms(u):
    # Parse containers page
    soup = BeautifulSoup(
        u.get('/plugins/dynamix.vm.manager/include/VMMachines.php').text,
        'lxml')
    vms = []

    # Loop through each VM
    for vm_row in soup.find_all(class_="sortable"):
        vm = VM()

        # Find VM uuid
        vm.uuid = vm_row.find_all('td')[6].find_all("input")[0]['uuid']

        # Find VM name
        vm.name = vm_row.select(".vm-name a")[0].text

        # Find VM description
        vm.description = vm_row.find_all('td')[1].text

        # Find VM state
        vm.state = vm_row.select("span.state")[0].text

        # Find CPU count
        vm.cpu_count = int(vm_row.find_all('td')[2].text)

        # Find memory amount
        vm.memory = parse_size(
            vm_row.find_all('td')[3].text.replace('M', ' M'))

        # Find vdisks
        vm.vdisks = _find_vdisks(soup, vm_row['parent-id'])

        # Find VNC port
        vm.vnc_port = vm_row.find_all('td')[5].text.replace('VNC:', '')

        # Find autostart status
        vm.autostart = vm_row.find_all('td')[6].find_all("input")[0] \
            .has_attr('checked')

        vm._set_unraid(u)

        vms.append(vm)

    return vms
Exemple #5
0
def parse_disk_row(row):
    # Create disk object
    disk = Disk()
    disk.disk_type = "hdd"

    # Remove empty rows
    if row.get_text() == '':
        return None

    # Remove last status row
    try:
        if 'tr_last' in row.attrs['class']:
            return None
    except KeyError:
        pass

    # Find disk status
    status_span = row.find_all('span')[0].get_text()

    try:
        disk.status = DISK_STATUS[status_span]
    except KeyError:
        disk.status = None

    # Find disk name
    name_a = row.find_all('a')[1]
    disk.name = name_a.get_text()

    # Find storage type
    if disk.name == 'Parity':
        disk.type = 'parity'
    elif disk.name == 'Cache':
        disk.type = 'cache'
    elif disk.name == 'Flash':
        disk.type = 'boot'
    else:
        disk.type = 'storage'

    # Find disk identification, size and mount
    id_td = row.find_all('td')[1]
    info = id_td.get_text()
    disk.identification = info.split(' - ')[0]

    disk.mount = re.search('[(]([a-z]{3})[)]', info).group(0).strip('()')

    size = re.search('([0-9]+) (PB|TB|GB|MB)', info)
    disk.size = parse_size(size.group(0))

    # Find disk temperature
    temp_td = row.find_all('td')[2].get_text()
    if temp_td == '*':
        disk.temperature = None
    else:
        disk.temperature = int(temp_td.strip(' C'))

    # Find disk read statistics
    read_td = row.find_all('td')[3]
    disk.current_read_speed = parse_speed(
        read_td.find_all('span')[0].get_text()
    )
    disk.current_read_count = int(
        read_td.find_all('span')[1].get_text().replace(',', '')
    )

    # Find disk write statistics
    read_td = row.find_all('td')[4]
    disk.current_write_speed = parse_speed(
        read_td.find_all('span')[0].get_text()
    )
    disk.current_write_count = int(
        read_td.find_all('span')[1].get_text().replace(',', '')
    )

    # Find disk errors
    error_td = row.find_all('td')[5]
    disk.errors = int(error_td.get_text())

    # Find filesystem
    if disk.type == 'parity':
        disk.filesystem = None
    else:
        fs_td = row.find_all('td')[6]
        disk.filesystem = fs_td.get_text()

    # Find space used and available
    if disk.type == 'parity':
        disk.space_used = None
        disk.space_available = None
    else:
        disk.space_used = parse_size(row.find_all('td')[8].get_text())
        disk.space_available = parse_size(row.find_all('td')[9].get_text())

    # Add disk object to disks list
    return disk