Exemplo n.º 1
0
 def execute(self, ns, devices=None):
     """
     Implementation of 'device list' command.
     """
     devices = get_devices(ns, devices)
     for dev in devices:
         yield get_device_info(ns, dev, self.app.config.human_friendly)
Exemplo n.º 2
0
 def execute(self, ns, devices=None):
     """
     Implementation of 'device list' command.
     """
     devices = get_devices(ns, devices)
     for dev in devices:
         yield get_device_info(ns, dev, self.app.config.human_friendly)
Exemplo n.º 3
0
 def execute(self, ns, devices=None):
     """
     Implementation of 'device show' command.
     """
     if not devices:
         devices = get_devices(ns)
     for dev in devices:
         dev = str2device(ns, dev)
         cmd = fcmd.NewTableCommand(title=dev.DeviceID)
         yield cmd
         for line in show.device_show(ns, dev, self.app.config.human_friendly):
             yield line
Exemplo n.º 4
0
 def execute(self, ns, devices=None):
     """
     Implementation of 'device show' command.
     """
     if not devices:
         devices = get_devices(ns)
     for dev in devices:
         dev = str2device(ns, dev)
         cmd = formatter.NewTableCommand(title=dev.DeviceID)
         yield cmd
         for line in show.device_show(ns, dev,
                                      self.app.config.human_friendly):
             yield line
Exemplo n.º 5
0
    def execute(self, ns, device=None):
        """
        Implementation of 'device tree' command.
        """
        # Note, this is high-speed version of the device tree.
        # Walking through associations using get_children() functions
        # was kind of slow, even for small number of devices (~5).

        # devices = dict devid -> LMIInstance
        devices = {}
        # Load *all* CIM_StorageExtents to speed things up.
        for dev in get_devices(ns):
            devices[self.get_obj_id(ns, dev)] = dev
        # Add *all* LMI_VGStoragePools.
        for vg in lvm.get_vgs(ns):
            devices[self.get_obj_id(ns, vg)] = vg
        for tp in lvm.get_tps(ns):
            devices[self.get_obj_id(ns, tp)] = tp

        # deps = array of tuples (parent devid, child devid)
        # Load all dependencies, calling get_children iteratively is slow
        # Add CIM_BasedOn dependencies (and omit LMI_LVBasedOn, we need
        # LMI_LVAllocatedFromStoragePool instead)
        LOG().debug("Loading list of CIM_BasedOn associations.")
        deps = [
            (self.get_obj_id(ns, i.Antecedent), self.get_obj_id(ns, i.Dependent))
            for i in ns.CIM_BasedOn.instances()
            if not lmi_isinstance(i, ns.LMI_LVBasedOn)
        ]

        # Be careful with logical partitions - they are BasedOn on appropriate
        # extended partition, but we want to draw them as children of
        # appropriate disk.
        LOG().debug("Reworking BasedOn associations for logical partitions.")
        logical = ns.LMI_DiskPartition.PartitionTypeValues.Logical
        extended = ns.LMI_DiskPartition.PartitionTypeValues.Extended
        for i in xrange(len(deps)):
            dev = devices[deps[i][0]]
            child = devices[deps[i][1]]
            LOG().debug("Inspecting %s - %s" % deps[i])
            if (
                "PartitionType" in dev.properties()
                and "PartitionType" in child.properties()
                and dev.PartitionType == extended
                and child.PartitionType == logical
            ):
                # We found ext. partition - logical partition dependency
                # Find the disk
                disk_id = None
                for (d, c) in deps:
                    if c == deps[i][0]:
                        disk_id = d
                # Replace the extended->logical dependency with disk->logical
                deps[i] = (disk_id, deps[i][1])
                LOG().debug("--- Replaced with %s - %s" % deps[i])

        # Add VG-LV dependencies from LMI_LVAllocatedFromStoragePool association
        LOG().debug("Loading LVAllocatedFromStoragePool associations.")
        deps += [
            (self.get_obj_id(ns, i.Antecedent), self.get_obj_id(ns, i.Dependent))
            for i in ns.LMI_LVAllocatedFromStoragePool.instances()
        ]

        # Add PV-VG dependencies from LMI_VGAssociatedComponentExtent
        LOG().debug("Loading VGAssociatedComponentExtent associations.")
        deps += [
            (self.get_obj_id(ns, i.PartComponent), self.get_obj_id(ns, i.GroupComponent))
            for i in ns.LMI_VGAssociatedComponentExtent.instances()
        ]

        # Add VG-ThinPool dependencies from LMI_VGAllocatedFromStoragePool
        if "LMI_VGAllocatedFromStoragePool" in ns.classes():
            LOG().debug("Loading VGAllocatedFromStoragePool associations.")
            deps += [
                (self.get_obj_id(ns, i.Antecedent), self.get_obj_id(ns, i.Dependent))
                for i in ns.LMI_VGAllocatedFromStoragePool.instances()
            ]

        # queue = array of tuples (devid, level), queue of items to inspect
        # and display
        queue = []
        if device:
            device = str2device(ns, device[0])
            queue = [(self.get_obj_id(ns, device), 0)]
        else:
            for (devid, device) in devices.iteritems():
                if device.Primordial:
                    queue.append((devid, 0))
        shown = set()

        while queue:
            (devid, level) = queue.pop()

            device = devices[devid]
            info = get_obj_info(ns, device, self.app.config.human_friendly)
            if devid in shown:
                # If the device was already displayed, just show reference to it
                yield (self.prepare_tree_line(level, info[0], queue), "***")
                # Don't show children of already displayed elements
                continue

            # Display the device
            yield (self.prepare_tree_line(level, info[0], queue),) + info[1:]
            shown.add(devid)
            # And inspect all children
            children = [dep[1] for dep in deps if dep[0] == devid]
            for child in reversed(children):
                queue.append((child, level + 1))
Exemplo n.º 6
0
    def execute(self, ns, device=None):
        """
        Implementation of 'device tree' command.
        """
        # Note, this is high-speed version of the device tree.
        # Walking through associations using get_children() functions
        # was kind of slow, even for small number of devices (~5).

        # devices = dict devid -> LMIInstance
        devices = {}
        # Load *all* CIM_StorageExtents to speed things up.
        for dev in get_devices(ns):
            devices[self.get_obj_id(ns, dev)] = dev
        # Add *all* LMI_VGStoragePools.
        for vg in get_vgs(ns):
            devices[self.get_obj_id(ns, vg)] = vg

        # deps = array of tuples (parent devid, child devid)
        # Load all dependencies, calling get_children iteratively is slow
        # Add CIM_BasedOn dependencies (and omit LMI_LVBasedOn, we need
        # LMI_LVAllocatedFromStoragePool instead)
        LOG().debug("Loading list of CIM_BasedOn associations.")
        deps = [(self.get_obj_id(ns, i.Antecedent),
                 self.get_obj_id(ns, i.Dependent))
                for i in ns.CIM_BasedOn.instances()
                if not lmi_isinstance(i, ns.LMI_LVBasedOn)]

        # Be careful with logical partitions - they are BasedOn on appropriate
        # extended partition, but we want to draw them as children of
        # appropriate disk.
        LOG().debug("Reworking BasedOn associations for logical partitions.")
        logical = ns.LMI_DiskPartition.PartitionTypeValues.Logical
        extended = ns.LMI_DiskPartition.PartitionTypeValues.Extended
        for i in xrange(len(deps)):
            dev = devices[deps[i][0]]
            child = devices[deps[i][1]]
            LOG().debug("Inspecting %s - %s" % deps[i])
            if ("PartitionType" in dev.properties()
                    and "PartitionType" in child.properties()
                    and dev.PartitionType == extended
                    and child.PartitionType == logical):
                # We found ext. partition - logical partition dependency
                # Find the disk
                disk_id = None
                for (d, c) in deps:
                    if c == deps[i][0]:
                        disk_id = d
                # Replace the extended->logical dependency with disk->logical
                deps[i] = (disk_id, deps[i][1])
                LOG().debug("--- Replaced with %s - %s" % deps[i])

        # Add VG-LV dependencies from LMI_LVAllocatedFromStoragePool association
        LOG().debug("Loading LVAllocatedFromStoragePool associations.")
        deps += [(self.get_obj_id(ns, i.Antecedent),
                  self.get_obj_id(ns, i.Dependent))
                 for i in ns.LMI_LVAllocatedFromStoragePool.instances()]

        # Add PV-VG dependencies from LMI_VGAssociatedComponentExtent
        LOG().debug("Loading VGAssociatedComponentExtent associations.")
        deps += [(self.get_obj_id(ns, i.PartComponent),
                  self.get_obj_id(ns, i.GroupComponent))
                 for i in ns.LMI_VGAssociatedComponentExtent.instances()]

        # queue = array of tuples (devid, level), queue of items to inspect
        # and display
        queue = []
        if device:
            device = str2device(ns, device[0])
            queue = [
                (self.get_obj_id(ns, device), 0),
            ]
        else:
            for (devid, device) in devices.iteritems():
                if device.Primordial:
                    queue.append((devid, 0))
        shown = set()

        while queue:
            (devid, level) = queue.pop()

            device = devices[devid]
            info = get_obj_info(ns, device, self.app.config.human_friendly)
            if devid in shown:
                # If the device was already displayed, just show reference to it
                yield (self.prepare_tree_line(level, info[0], queue), "***")
                # Don't show children of already displayed elements
                continue

            # Display the device
            yield (self.prepare_tree_line(level, info[0], queue), ) + info[1:]
            shown.add(devid)
            # And inspect all children
            children = [dep[1] for dep in deps if dep[0] == devid]
            for child in reversed(children):
                queue.append((child, level + 1))