Example #1
0
def _save_shares(dev, shares):
    wwns = []
    for share_id, (label, wwn, snapshot_size, size, share_type,
                   speed, full) in shares.iteritems():
        wwn = normalize_wwn(wwn)
        wwns.append(wwn)
        model, created = ComponentModel.create(
            ComponentType.share,
            name='3PAR %s disk share' % share_type,
            family=share_type,
            speed=speed,
            priority=0,   # FIXME: why 0?
        )
        share, created = DiskShare.concurrent_get_or_create(
            wwn=wwn,
            defaults={'device': dev},
        )
        if not created:
            if dev.id != share.device.id:
                raise ValueError(
                    'DiskShare %r: Conflict of devices %r and %r!' % (
                        share,
                        dev,
                        share.device,
                    )
                )
        share.model = model
        share.label = label
        share.full = full
        share.size = size
        share.share_id = share_id
        share.snapshot_size = snapshot_size
        share.save()
    dev.diskshare_set.exclude(wwn__in=wwns).delete()
Example #2
0
def _save_shares(dev, shares):
    wwns = []
    for share_id, (label, wwn, snapshot_size, size, share_type, speed,
                   full) in shares.iteritems():
        wwn = normalize_wwn(wwn)
        wwns.append(wwn)
        model, created = ComponentModel.create(
            ComponentType.share,
            name='3PAR %s disk share' % share_type,
            family=share_type,
            speed=speed,
            priority=0,  # FIXME: why 0?
        )
        share, created = DiskShare.concurrent_get_or_create(
            wwn=wwn,
            defaults={'device': dev},
        )
        if not created:
            if dev.id != share.device.id:
                raise ValueError(
                    'DiskShare %r: Conflict of devices %r and %r!' % (
                        share,
                        dev,
                        share.device,
                    ))
        share.model = model
        share.label = label
        share.full = full
        share.size = size
        share.share_id = share_id
        share.snapshot_size = snapshot_size
        share.save()
    dev.diskshare_set.exclude(wwn__in=wwns).delete()
Example #3
0
def _handle_shares(volumes):
    return [{
        'serial_number': normalize_wwn(serial),
        'model_name': 'MSA %s disk share' % volume_type,
        'label': label,
        'size': size * 512 / 1024 / 1024,
    } for (label, serial, size, volume_type, speed) in volumes]
Example #4
0
def _save_shares(dev, volumes):
    wwns = []
    for (label, serial, size, volume_type, speed) in volumes:
        wwn = normalize_wwn(serial)
        wwns.append(wwn)
        model, created = ComponentModel.create(
            ComponentType.share,
            speed=speed,
            family=volume_type,
            name='MSA %s disk share' % volume_type,
            priority=0,  # FIXME: why 0?
        )
        share, created = DiskShare.concurrent_get_or_create(
            wwn=wwn,
            defaults={'device': dev},
        )
        if not created:
            if dev.id != share.device.id:
                raise ValueError(
                    'DiskShare %r: Conflict of devices %r and %r!' % (
                        share,
                        dev,
                        share.device,
                    )
                )
        share.model = model
        share.label = label
        share.size = size * 512 / 1024 / 1024
        share.snapshot_size = 0
        share.save()
    dev.diskshare_set.exclude(wwn__in=wwns).delete()
Example #5
0
def parse_wwn(facts, dev):
    def make_mount(wwn):
        try:
            share = DiskShare.objects.get(wwn=wwn)
        except DiskShare.DoesNotExist:
            return None
        mount, created = DiskShareMount.concurrent_get_or_create(share=share,
                                                                 device=dev)
        return mount

    wwns = []
    for key, wwn in facts.iteritems():
        if not key.startswith('wwn_mpath'):
            continue
        wwns.append(hardware.normalize_wwn(wwn))
    for wwn in wwns:
        mount = make_mount(wwn)
        if not mount:
            continue
        path = key.replace('wwn_', '')
        mount.volume = '/dev/mapper/%s' % path
        mount.save(priority=SAVE_PRIORITY)
    for mount in dev.disksharemount_set.filter(server=None).exclude(
            share__wwn__in=wwns):
        mount.delete()
Example #6
0
def _handle_shares(volumes):
    return [{
        'serial_number': normalize_wwn(serial),
        'model_name': 'MSA %s disk share' % volume_type,
        'label': label,
        'size': size * 512 / 1024 / 1024,
    } for (label, serial, size, volume_type, speed) in volumes]
Example #7
0
def _save_shares(dev, volumes):
    wwns = []
    for (label, serial, size, volume_type, speed) in volumes:
        wwn = normalize_wwn(serial)
        wwns.append(wwn)
        model, created = ComponentModel.create(
            ComponentType.share,
            speed=speed,
            family=volume_type,
            name='MSA %s disk share' % volume_type,
            priority=0,  # FIXME: why 0?
        )
        share, created = DiskShare.concurrent_get_or_create(
            wwn=wwn,
            defaults={'device': dev},
        )
        if not created:
            if dev.id != share.device.id:
                raise ValueError(
                    'DiskShare %r: Conflict of devices %r and %r!' % (
                        share,
                        dev,
                        share.device,
                    ))
        share.model = model
        share.label = label
        share.size = size * 512 / 1024 / 1024
        share.snapshot_size = 0
        share.save()
    dev.diskshare_set.exclude(wwn__in=wwns).delete()
Example #8
0
def _handle_shares(volumes):
    return [
        {
            "serial_number": normalize_wwn(serial),
            "model_name": "MSA %s disk share" % volume_type,
            "label": label,
            "size": size * 512 / 1024 / 1024,
        }
        for (label, serial, size, volume_type, speed) in volumes
    ]
Example #9
0
def _shares(volumes):
    shares = []
    for (label, serial, size, volume_type, speed) in volumes:
        wwn = normalize_wwn(serial)
        share = {
            'serial_number': str(wwn),
            'size': size * 512 / 1024 / 1024,
            'label': 'MSA %s disk share' % volume_type,
        }
        shares.append(share)
    return shares
Example #10
0
def _shares(volumes):
    shares = []
    for (label, serial, size, volume_type, speed) in volumes:
        wwn = normalize_wwn(serial)
        share = {
            'serial_number': str(wwn),
            'size': size * 512 / 1024 / 1024,
            'label': 'MSA %s disk share' % volume_type,
        }
        shares.append(share)
    return shares
Example #11
0
def handle_facts_wwn(facts):
    disk_shares = []
    for key, wwn in facts.iteritems():
        if not key.startswith('wwn_mpath'):
            continue
        path = key.replace('wwn_', '')
        disk_shares.append({
            'serial_number': normalize_wwn(wwn),
            'volume': '/dev/mapper/%s' % path,
        })
    return disk_shares
Example #12
0
def _handle_shares(shares):
    return [{
        'model_name': '3PAR %s disk share' % share_type,
        'label': label,
        'share_id': share_id,
        'snapshot_size': snapshot_size,
        'size': size,
        'full': full,
        'serial_number': normalize_wwn(wwn),
    } for share_id, (label, wwn, snapshot_size, size, share_type, speed,
                     full) in shares.iteritems()]
Example #13
0
File: facts.py Project: 4i60r/ralph
def handle_facts_wwn(facts):
    disk_shares = []
    for key, wwn in facts.iteritems():
        if not key.startswith('wwn_mpath'):
            continue
        path = key.replace('wwn_', '')
        disk_shares.append({
            'serial_number': normalize_wwn(wwn),
            'volume': '/dev/mapper/%s' % path,

        })
    return disk_shares
Example #14
0
def _handle_shares(shares):
    return [
        {
            "model_name": "3PAR %s disk share" % share_type,
            "label": label,
            "share_id": share_id,
            "snapshot_size": snapshot_size,
            "size": size,
            "full": full,
            "serial_number": normalize_wwn(wwn),
        }
        for share_id, (label, wwn, snapshot_size, size, share_type, speed, full) in shares.iteritems()
    ]
Example #15
0
def _handle_shares(shares):
    return [
        {
            'model_name': '3PAR %s disk share' % share_type,
            'label': label,
            'share_id': share_id,
            'snapshot_size': snapshot_size,
            'size': size,
            'full': full,
            'serial_number': normalize_wwn(wwn),
        } for share_id, (label, wwn, snapshot_size, size, share_type,
                         speed, full) in shares.iteritems()
    ]
Example #16
0
def _save_shares(dev, volumes):
    wwns = []
    for (label, serial, size, type, speed) in volumes:
        wwn = normalize_wwn(serial)
        wwns.append(wwn)
        model, created = ComponentModel.concurrent_get_or_create(
            name='MSA %s disk share' % type, type=ComponentType.share.id,
            family=type, speed=speed)
        share, created = DiskShare.concurrent_get_or_create(wwn=wwn, device=dev)
        share.model = model
        share.label = label
        share.size = size * 512 / 1024 / 1024
        share.snapshot_size = 0
        share.save()
    dev.diskshare_set.exclude(wwn__in=wwns).delete()
Example #17
0
def _save_shares(dev, shares):
    wwns = []
    for share_id, (label, wwn, snapshot_size, size, type,
                   speed, full) in shares.iteritems():
        wwn = normalize_wwn(wwn)
        wwns.append(wwn)
        model, created = ComponentModel.concurrent_get_or_create(
            name='3PAR %s disk share' % type, type=ComponentType.share.id,
            family=type, speed=speed)
        share, created = DiskShare.concurrent_get_or_create(wwn=wwn, device=dev)
        share.model = model
        share.label = label
        share.full = full
        share.size = size
        share.share_id = share_id
        share.snapshot_size = snapshot_size
        share.save()
    dev.diskshare_set.exclude(wwn__in=wwns).delete()
Example #18
0
def parse_wwn(facts, dev):
    def make_mount(wwn):
        try:
            share = DiskShare.objects.get(wwn=wwn)
        except DiskShare.DoesNotExist:
            return None
        mount, created = DiskShareMount.concurrent_get_or_create(
            share=share, device=dev)
        return mount
    wwns = []
    for key, wwn in facts.iteritems():
        if not key.startswith('wwn_mpath'):
            continue
        wwns.append(hardware.normalize_wwn(wwn))
    for wwn in wwns:
        mount = make_mount(wwn)
        if not mount:
            continue
        path = key.replace('wwn_', '')
        mount.volume = '/dev/mapper/%s' % path
        mount.save(priority=SAVE_PRIORITY)
    for mount in dev.disksharemount_set.filter(
            server=None).exclude(share__wwn__in=wwns):
        mount.delete()
Example #19
0
def run_ssh_aix(ip):
    ssh = _connect_ssh(ip)
    try:
        ethernets = []
        for model_line in _ssh_lines(ssh, 'lsattr -El sys0 | grep ^modelname'):
            machine_model = model_line.split(None, 2)[1]
            break
        for mac_line in _ssh_lines(ssh, 'netstat -ia | grep link'):
            interface, mtu, net, mac, rest = mac_line.split(None, 4)
            if '.' not in mac:
                continue
            octets = mac.split('.')
            mac = ''.join('%02x' % int(o, 16) for o in octets).upper()
            ethernets.append(Eth(label=interface, mac=mac, speed=0))
        disks = {}
        os_storage_size = 0
        for disk_line in _ssh_lines(ssh, 'lsdev -c disk'):
            disk, rest = disk_line.split(None, 1)
            wwn = None
            model = None
            for line in _ssh_lines(ssh, 'lscfg -vl %s' % disk):
                if 'hdisk' in line:
                    match = re.search(r'\(([0-9]+) MB\)', line)
                    if match:
                        os_storage_size += int(match.group(1))
                elif 'Serial Number...' in line:
                    label, sn = line.split('.', 1)
                    sn = sn.strip('. \n')
                elif 'Machine Type and Model.' in line:
                    label, model = line.split('.', 1)
                    model = model.strip('. \n')
            disks[disk] = (model, sn)
        os_version = ''
        for line in _ssh_lines(ssh, 'oslevel'):
            os_version = line.strip()
            break
        os_memory = 0
        for line in _ssh_lines(ssh, 'lsattr -El sys0 | grep ^realmem'):
            match = re.search(r'[0-9]+', line)
            if match:
                os_memory = int(int(match.group(0)) / 1024)
            break
        os_corescount = 0
        for line in _ssh_lines(ssh, 'lparstat -i|grep ^Active\ Phys'):
            match = re.search(r'[0-9]+', line)
            if match:
                os_corescount += int(match.group(0))
    finally:
        ssh.close()
    dev = Device.create(
        ethernets=ethernets, model_type=DeviceType.rack_server,
        model_name='%s AIX' % MODELS.get(machine_model, machine_model))
    ipaddr = IPAddress.objects.get(address=ip)
    ipaddr.device = dev
    ipaddr.save()
    wwns = []
    sns = []
    stors = []
    for disk, (model_name, sn) in disks.iteritems():
        if not sn:
            continue
        if model_name == 'VV':
            wwns.append(sn)
        else:
            stors.append((disk, model_name, sn))
            sns.append(sn)
    for mount in dev.disksharemount_set.exclude(share__wwn__in=wwns):
        mount.delete()
    for stor in dev.storage_set.exclude(sn__in=sns):
        stor.delete()
    for wwn in wwns:
        try:
            share = DiskShare.objects.get(wwn=wwn)
        except DiskShare.DoesNotExist:
            continue
        wwn = normalize_wwn(sn[-4:] + sn[:-4])
        mount, created = DiskShareMount.concurrent_get_or_create(
            share=share, device=dev, defaults={'is_virtual':False})
        mount.volume = disk
        mount.save(priority=SAVE_PRIORITY)
    for disk, model_name, sn in stors:
        # FIXME: storage with no size
        model, c = ComponentModel.create(
            ComponentType.disk,
            family=model_name,
            priority=SAVE_PRIORITY,
        )
        stor, created = Storage.concurrent_get_or_create(
            device=dev,
            sn=sn,
            mount_point=None,
        )
        stor.model = model
        stor.label = disk
        stor.save(priority=SAVE_PRIORITY)
    # FIXME: memory with no size
    mem, created = Memory.concurrent_get_or_create(device=dev, index=0)
    mem.label = 'Memory'
    mem.model, c = ComponentModel.create(
        ComponentType.memory,
        family='pSeries',
        priority=SAVE_PRIORITY,
    )
    mem.save(priority=SAVE_PRIORITY)
    # FIXME: CPUs without info
    cpu, created = Processor.concurrent_get_or_create(device=dev, index=0)
    cpu.label = 'CPU'
    cpu.model, c = ComponentModel.create(
        ComponentType.processor,
        family='pSeries',
        name='pSeries CPU',
        priority=SAVE_PRIORITY,
    )
    cpu.save(priority=SAVE_PRIORITY)
    OperatingSystem.create(dev=dev,
        os_name='AIX',
        version=os_version,
        family='AIX',
        memory=os_memory or None,
        cores_count=os_corescount or None,
        storage=os_storage_size or None,
        priority=SAVE_PRIORITY
    )
    return machine_model
Example #20
0
def run_ssh_aix(ip):
    ssh = _connect_ssh(ip)
    try:
        ethernets = []
        for model_line in _ssh_lines(ssh, 'lsattr -El sys0 | grep ^modelname'):
            machine_model = model_line.split(None, 2)[1]
            break
        for mac_line in _ssh_lines(ssh, 'netstat -ia | grep link'):
            interface, mtu, net, mac, rest = mac_line.split(None, 4)
            if '.' not in mac:
                continue
            octets = mac.split('.')
            mac = ''.join('%02x' % int(o, 16) for o in octets).upper()
            ethernets.append(Eth(label=interface, mac=mac, speed=0))
        disks = {}
        os_storage_size = 0
        for disk_line in _ssh_lines(ssh, 'lsdev -c disk'):
            disk, rest = disk_line.split(None, 1)
            wwn = None
            model = None
            for line in _ssh_lines(ssh, 'lscfg -vl %s' % disk):
                if 'hdisk' in line:
                    match = re.search(r'\(([0-9]+) MB\)', line)
                    if match:
                        os_storage_size += int(match.group(1))
                elif 'Serial Number...' in line:
                    label, sn = line.split('.', 1)
                    sn = sn.strip('. \n')
                elif 'Machine Type and Model.' in line:
                    label, model = line.split('.', 1)
                    model = model.strip('. \n')
            disks[disk] = (model, sn)
        os_version = ''
        for line in _ssh_lines(ssh, 'oslevel'):
            os_version = line.strip()
            break
        os_memory = 0
        for line in _ssh_lines(ssh, 'lsattr -El sys0 | grep ^realmem'):
            match = re.search(r'[0-9]+', line)
            if match:
                os_memory = int(int(match.group(0)) / 1024)
            break
        os_corescount = 0
        for line in _ssh_lines(ssh, 'lparstat -i|grep ^Active\ Phys'):
            match = re.search(r'[0-9]+', line)
            if match:
                os_corescount += int(match.group(0))
    finally:
        ssh.close()
    dev = Device.create(ethernets=ethernets,
                        model_type=DeviceType.rack_server,
                        model_name='%s AIX' %
                        MODELS.get(machine_model, machine_model))
    ipaddr = IPAddress.objects.get(address=ip)
    ipaddr.device = dev
    ipaddr.save()
    wwns = []
    sns = []
    stors = []
    for disk, (model_name, sn) in disks.iteritems():
        if not sn:
            continue
        if model_name == 'VV':
            wwns.append(sn)
        else:
            stors.append((disk, model_name, sn))
            sns.append(sn)
    for mount in dev.disksharemount_set.exclude(share__wwn__in=wwns):
        mount.delete()
    for stor in dev.storage_set.exclude(sn__in=sns):
        stor.delete()
    for wwn in wwns:
        try:
            share = DiskShare.objects.get(wwn=wwn)
        except DiskShare.DoesNotExist:
            continue
        wwn = normalize_wwn(sn[-4:] + sn[:-4])
        mount, created = DiskShareMount.concurrent_get_or_create(
            share=share, device=dev, is_virtual=False)
        mount.volume = disk
        mount.save()
    for disk, model_name, sn in stors:
        model, mcreated = ComponentModel.concurrent_get_or_create(
            type=ComponentType.disk.id, family=model_name, extra_hash='')
        model.name = model_name
        model.save()
        stor, created = Storage.concurrent_get_or_create(device=dev, sn=sn)
        stor.model = model
        stor.label = disk
        stor.save()

    mem, created = Memory.concurrent_get_or_create(device=dev, index=0)
    mem.label = 'Memory'
    mem.model, c = ComponentModel.concurrent_get_or_create(
        size=0,
        speed=0,
        type=ComponentType.memory.id,
        family='pSeries',
        extra_hash='')
    mem.model.name = 'pSeries Memory'
    mem.model.save()
    mem.save()
    cpu, created = Processor.concurrent_get_or_create(device=dev, index=0)
    cpu.label = 'CPU'
    cpu.model, c = ComponentModel.concurrent_get_or_create(
        speed=0,
        cores=0,
        type=ComponentType.processor.id,
        extra_hash='',
        family='pSeries CPU')
    cpu.model.name = 'pSeries CPU'
    cpu.model.save()
    cpu.save()
    os = OperatingSystem.create(dev=dev,
                                os_name='AIX',
                                version=os_version,
                                family='AIX')
    os.memory = os_memory if os_memory else None
    os.cores_count = os_corescount if os_corescount else None
    os.storage = os_storage_size if os_storage_size else None
    os.save()

    return machine_model
Example #21
0
def run_ssh_aix(ip):
    ssh = _connect_ssh(ip)
    try:
        ethernets = []
        for model_line in _ssh_lines(ssh, 'lsattr -El sys0 | grep ^modelname'):
            machine_model = model_line.split(None, 2)[1]
            break
        for mac_line in _ssh_lines(ssh, 'netstat -ia | grep link'):
            interface, mtu, net, mac, rest = mac_line.split(None, 4)
            if '.' not in mac:
                continue
            octets = mac.split('.')
            mac = ''.join('%02x' % int(o, 16) for o in octets).upper()
            ethernets.append(Eth(label=interface, mac=mac, speed=0))
        disks = {}
        for disk_line in _ssh_lines(ssh, 'lsdev -c disk'):
            disk, rest = disk_line.split(None, 1)
            wwn = None
            model = None
            for line in _ssh_lines(ssh, 'lscfg -vl %s' % disk):
                if 'Serial Number...' in line:
                    label, sn = line.split('.', 1)
                    sn = sn.strip('. \n')
                elif 'Machine Type and Model.' in line:
                    label, model = line.split('.', 1)
                    model = model.strip('. \n')
            disks[disk] = (model, sn)
    finally:
        ssh.close()
    dev = Device.create(
                ethernets=ethernets,
                model_type=DeviceType.rack_server,
                model_name='%s AIX' % MODELS.get(machine_model, machine_model))
    ipaddr = IPAddress.objects.get(address=ip)
    ipaddr.device = dev
    ipaddr.save()
    wwns = []
    sns = []
    stors = []
    for disk, (model_name, sn) in disks.iteritems():
        if not sn:
            continue
        if model_name == 'VV':
            wwns.append(sn)
        else:
            stors.append((disk, model_name, sn))
            sns.append(sn)
    for mount in dev.disksharemount_set.exclude(share__wwn__in=wwns):
        mount.delete()
    for stor in dev.storage_set.exclude(sn__in=sns):
        stor.delete()
    for wwn in wwns:
        try:
            share = DiskShare.objects.get(wwn=wwn)
        except DiskShare.DoesNotExist:
            continue
        wwn = normalize_wwn(sn[-4:] + sn[:-4])
        mount, created = DiskShareMount.concurrent_get_or_create(
                share=share, device=dev, is_virtual=False)
        mount.volume = disk
        mount.save()
    for disk, model_name, sn in stors:
        model, mcreated = ComponentModel.concurrent_get_or_create(
                type=ComponentType.disk.id, family=model_name, extra_hash='')
        model.name = model_name
        model.save()
        stor, created = Storage.concurrent_get_or_create(device=dev, sn=sn)
        stor.model = model
        stor.label = disk
        stor.save()


    mem, created = Memory.concurrent_get_or_create(device=dev, index=0)
    mem.label = 'Memory'
    mem.model, c = ComponentModel.concurrent_get_or_create( size=0, speed=0,
            type=ComponentType.memory.id, family='pSeries', extra_hash='')
    mem.model.name = 'pSeries Memory'
    mem.model.save()
    mem.save()
    cpu, created = Processor.concurrent_get_or_create(device=dev, index=0)
    cpu.label = 'CPU'
    cpu.model, c = ComponentModel.concurrent_get_or_create(speed=0, cores=0,
            type=ComponentType.processor.id, extra_hash='', family='pSeries CPU')
    cpu.model.name = 'pSeries CPU'
    cpu.model.save()
    cpu.save()

    return machine_model