Exemplo n.º 1
0
    def _run(self, nets=(), ranges=(), zProperties=(), collector='localhost'):
        # Store the nets and ranges
        self.nets = nets
        self.ranges = ranges

        # Store zProperties on the job
        if zProperties:
            self.setProperties(**zProperties)
        # Build the zendisc command
        cmd = self.dmd.Monitors.getPerformanceMonitor(collector)._getZenDiscCommand(
            '', '/Discovered', collector, 1000
            )
        # strip out the device option since we are discovering for a network
        cmd = [c.replace(" -d ", "") for c in cmd if c != '-d']
        cmd.extend([
                '--parallel', '8',
                '--job', self.request.id
                   ])
        if not self.nets and not self.ranges:
            # Gotta have something
            self.log.error("Must pass in either a network or a range.")
        elif self.nets and self.ranges:
            # Can't have both
            self.log.error("Must pass in either networks or ranges, not both")
        else:
            if self.nets:
                for net in self.nets:
                    cmd.extend(['--net', net])
            elif self.ranges:
                for iprange in self.ranges:
                    cmd.extend(['--range', iprange])
            SubprocessJob._run(self, cmd)
Exemplo n.º 2
0
    def _run(self, nets=(), ranges=(), zProperties=(), collector='localhost'):
        # Store the nets and ranges
        self.nets = nets
        self.ranges = ranges

        # Store zProperties on the job
        if zProperties:
            self.setProperties(**zProperties)
        # Build the zendisc command
        cmd = self.dmd.Monitors.getPerformanceMonitor(
            collector)._getZenDiscCommand('', '/Discovered', collector, 1000)
        # strip out the device option since we are discovering for a network
        cmd = [c for c in cmd if c != '-d']
        cmd.extend(['--parallel', '8', '--job', self.request.id])
        if not self.nets and not self.ranges:
            # Gotta have something
            self.log.error("Must pass in either a network or a range.")
        elif self.nets and self.ranges:
            # Can't have both
            self.log.error("Must pass in either networks or ranges, not both")
        else:
            if self.nets:
                for net in self.nets:
                    cmd.extend(['--net', net])
            elif self.ranges:
                for iprange in self.ranges:
                    cmd.extend(['--range', iprange])
            SubprocessJob._run(self, cmd)
Exemplo n.º 3
0
    def addCreateDeviceJob(
        self,
        deviceName,
        devicePath,
        title=None,
        discoverProto="none",
        manageIp="",
        performanceMonitor=None,
        rackSlot=0,
        productionState=1000,
        comments="",
        hwManufacturer="",
        hwProductName="",
        osManufacturer="",
        osProductName="",
        priority=3,
        locationPath="",
        systemPaths=[],
        groupPaths=[],
        tag="",
        serialNumber="",
        zProperties={},
        cProperties={},
    ):
        """
        Creating a device has two steps: creating a 'stub' device in the
        database, then (if requested) running zendisc to model the device.
        The modeling step can be skipped if the discoverProto argument
        is set to the string "none".

        @returns A list of JobRecord objects.
        """
        # Determine the name of the monitor to use.
        monitor = performanceMonitor or self.id

        # Check to see if we got passed in an IPv6 address
        try:
            IPAddress(deviceName)
            if not title:
                title = deviceName
            deviceName = ipwrap(deviceName)
        except ValueError:
            pass

        # Creating a device is, at most, a two-step process.  First a
        # device 'stub' is created in the database then, if the
        # discoverProto argument is not 'none', then zendisc is run to
        # discover and model the device.  The process is implemented using
        # two jobs.

        subjobs = [
            CreateDeviceJob.makeSubJob(args=(deviceName, ),
                                       kwargs=dict(
                                           devicePath=devicePath,
                                           title=title,
                                           discoverProto=discoverProto,
                                           manageIp=manageIp,
                                           performanceMonitor=monitor,
                                           rackSlot=rackSlot,
                                           productionState=productionState,
                                           comments=comments,
                                           hwManufacturer=hwManufacturer,
                                           hwProductName=hwProductName,
                                           osManufacturer=osManufacturer,
                                           osProductName=osProductName,
                                           priority=priority,
                                           tag=tag,
                                           serialNumber=serialNumber,
                                           locationPath=locationPath,
                                           systemPaths=systemPaths,
                                           groupPaths=groupPaths,
                                           zProperties=zProperties,
                                           cProperties=cProperties,
                                       ))
        ]
        if discoverProto != 'none':
            zendiscCmd = self._getZenDiscCommand(deviceName, devicePath,
                                                 monitor, productionState)
            subjobs.append(
                SubprocessJob.makeSubJob(
                    args=(zendiscCmd, ),
                    description="Discover and model device %s as %s" %
                    (deviceName, devicePath)))
        # Set the 'immutable' flag to indicate that the result of the prior
        # job is not passed as arguments into the next job (basically, args
        # to the jobs are immutable).
        return self.dmd.JobManager.addJobChain(*subjobs, immutable=True)
    def addCreateDeviceJob(self, deviceName, devicePath, title=None,
            discoverProto="none", manageIp="", performanceMonitor=None,
            rackSlot=0, productionState=1000, comments="",
            hwManufacturer="", hwProductName="", osManufacturer="",
            osProductName="", priority=3, locationPath="", systemPaths=[],
            groupPaths=[], tag="", serialNumber="",
            zProperties={}, cProperties={},):
        """
        Creating a device has two steps: creating a 'stub' device in the
        database, then (if requested) running zendisc to model the device.
        The modeling step can be skipped if the discoverProto argument
        is set to the string "none".

        @returns A list of JobRecord objects.
        """
        # Determine the name of the monitor to use.
        monitor = performanceMonitor or self.id

        # Check to see if we got passed in an IPv6 address
        try:
            IPAddress(deviceName)
            if not title:
                title = deviceName
            deviceName = ipwrap(deviceName)
        except ValueError:
            pass

        # Creating a device is, at most, a two-step process.  First a
        # device 'stub' is created in the database then, if the
        # discoverProto argument is not 'none', then zendisc is run to
        # discover and model the device.  The process is implemented using
        # two jobs.

        subjobs = [
                CreateDeviceJob.makeSubJob(
                    args=(deviceName,),
                    kwargs=dict(
                        devicePath=devicePath,
                        title=title,
                        discoverProto=discoverProto,
                        manageIp=manageIp,
                        performanceMonitor=monitor,
                        rackSlot=rackSlot,
                        productionState=productionState,
                        comments=comments,
                        hwManufacturer=hwManufacturer,
                        hwProductName=hwProductName,
                        osManufacturer=osManufacturer,
                        osProductName=osProductName,
                        priority=priority,
                        tag=tag,
                        serialNumber=serialNumber,
                        locationPath=locationPath,
                        systemPaths=systemPaths,
                        groupPaths=groupPaths,
                        zProperties=zProperties,
                        cProperties=cProperties,
                    )
                )
            ]
        if discoverProto != 'none':
            zendiscCmd = self._getZenDiscCommand(
                    deviceName, devicePath, monitor, productionState
                )
            subjobs.append(
                SubprocessJob.makeSubJob(
                    args=(zendiscCmd,),
                    description="Discover and model device %s as %s" % (
                        deviceName, devicePath
                    )
                )
            )
        # Set the 'immutable' flag to indicate that the result of the prior
        # job is not passed as arguments into the next job (basically, args
        # to the jobs are immutable).
        return self.dmd.JobManager.addJobChain(*subjobs, immutable=True)