Пример #1
0
 def __init__(self, id, netmask=24):
     checkip(id)
     ManagedEntity.__init__(self, ipwrap(id))
     ipobj = IPAddress(ipunwrap_strip(id))
     if ipobj.version == 6:
         # No user-definable subnet masks for IPv6
         netmask = 64
     self._netmask = maskToBits(netmask)
     self.ptrName = None
     self.title = ipunwrap(id)
     self.version = ipobj.version
Пример #2
0
 def __init__(self, id, netmask=24):
     checkip(id)
     ManagedEntity.__init__(self, ipwrap(id))
     ipobj = IPAddress(ipunwrap_strip(id))
     if ipobj.version == 6:
         # No user-definable subnet masks for IPv6
         netmask = 64
     self._netmask = maskToBits(netmask)
     self.ptrName = None
     self.title = ipunwrap(id)
     self.version = ipobj.version
Пример #3
0
    def addDeviceCreationJob(self, deviceName, devicePath, title=None,
                             discoverProto="none", manageIp="",
                             performanceMonitor='localhost',
                             rackSlot=0, productionState=1000, comments="",
                             hwManufacturer="", hwProductName="",
                             osManufacturer="", osProductName="", priority = 3,
                             locationPath="", systemPaths=[], groupPaths=[],
                             tag="", serialNumber="", zProperties={}, cProperties={},):

        # 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

        zendiscCmd = self._getZenDiscCommand(deviceName, devicePath,
                                             performanceMonitor, productionState)

        jobStatus = self.dmd.JobManager.addJob(DeviceCreationJob,
                description="Add device %s" % deviceName,
                kwargs=dict(
                    deviceName=deviceName,
                    devicePath=devicePath,
                    title=title,
                    discoverProto=discoverProto,
                    manageIp=manageIp,
                    performanceMonitor=performanceMonitor,
                    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,
                    zendiscCmd=zendiscCmd))
        return jobStatus
Пример #4
0
 def setIpAddress(self, ip):
     """
     Set the IP address. Use the format 1.1.1.1/24 to also set the netmask
     """
     iparray = ip.split("/")
     if len(iparray) > 1:
         ip = iparray[0]
         self._netmask = maskToBits(iparray[1])
     checkip(ip)
     aqself = self.primaryAq()  #set aq path
     network = aqself.aq_parent
     netip = netFromIpAndNet(ip, network.netmask)
     if netip == network.id:
         network._renameObject(aqself.id, ipwrap(ip))
     else:
         raise WrongSubnetError("IP %s is in a different subnet than %s" %
                                (ipunwrap(ip), ipunwrap(self.id)))
Пример #5
0
 def setIpAddress(self, ip):
     """
     Set the IP address. Use the format 1.1.1.1/24 to also set the netmask
     """
     iparray = ip.split("/")
     if len(iparray) > 1:
         ip = iparray[0]
         self._netmask = maskToBits(iparray[1])
     checkip(ip)
     aqself = self.primaryAq() #set aq path
     network = aqself.aq_parent
     netip = netFromIpAndNet(ip, network.netmask)
     if netip == network.id:
         network._renameObject(aqself.id, ipwrap(ip))
     else:
         raise WrongSubnetError(
                 "IP %s is in a different subnet than %s" % (ipunwrap(ip), ipunwrap(self.id)) )
Пример #6
0
    def addDeviceCreationJob(
        self,
        deviceName,
        devicePath,
        title=None,
        discoverProto="none",
        manageIp="",
        performanceMonitor='localhost',
        rackSlot=0,
        productionState=1000,
        comments="",
        hwManufacturer="",
        hwProductName="",
        osManufacturer="",
        osProductName="",
        priority=3,
        locationPath="",
        systemPaths=[],
        groupPaths=[],
        tag="",
        serialNumber="",
        zProperties={},
        cProperties={},
    ):

        # 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

        zendiscCmd = self._getZenDiscCommand(deviceName, devicePath,
                                             performanceMonitor,
                                             productionState)

        jobStatus = self.dmd.JobManager.addJob(
            DeviceCreationJob,
            description="Add device %s" % deviceName,
            kwargs=dict(deviceName=deviceName,
                        devicePath=devicePath,
                        title=title,
                        discoverProto=discoverProto,
                        manageIp=manageIp,
                        performanceMonitor=performanceMonitor,
                        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,
                        zendiscCmd=zendiscCmd))
        return jobStatus
Пример #7
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)
Пример #9
0
    def load_device(self,
                    deviceName,
                    devicePath='/Discovered',
                    discoverProto='snmp',
                    performanceMonitor='localhost',
                    manageIp="",
                    zProperties=None,
                    deviceProperties=None):
        """
        Load a single device into the database.
        """
        # Make the config dictionaries the proper type
        try:
            if zProperties is None:
                zProperties = {}
            if deviceProperties is None:
                deviceProperties = {}

            # Remove spaces from the name
            deviceName = deviceName.replace(' ', '')
            manageIp = manageIp.replace(' ', '')

            if not manageIp:
                try:
                    IPAddress(deviceName)
                    manageIp = deviceName
                    deviceName = ipwrap(deviceName)
                    deviceProperties.setdefault('title', manageIp)
                except ValueError:
                    pass

            # If we're not discovering and we have no IP, attempt the IP lookup
            # locally
            if discoverProto == 'none' and not manageIp:
                try:
                    manageIp = getHostByName(deviceName)
                except socket.error:
                    pass

            # move the zProperties required by manage_createDevice to
            # deviceProperties
            for key in 'zSnmpCommunity', 'zSnmpPort', 'zSnmpVer':
                if key in zProperties:
                    deviceProperties[key] = zProperties.pop(key)

            # Make a device object in the database
            self.deviceobj = manage_createDevice(
                self.context,
                deviceName,
                devicePath,
                performanceMonitor=performanceMonitor,
                manageIp=manageIp,
                zProperties=zProperties,
                **deviceProperties)

            # Flag this device as temporary.
            # If discovery goes well, zendisc will flip this to False.
            self.deviceobj._temp_device = True

            # If we're not discovering, we're done
            if discoverProto == 'none':
                return self.deviceobj

            # Pass production state from device properties
            productionState = deviceProperties.get('productionState', 1000)

            # Otherwise, time for zendisc to do its thing
            self.run_zendisc(deviceName, devicePath, performanceMonitor,
                             productionState)

        finally:
            # Check discovery's success and clean up accordingly
            self.cleanup()

        return self.deviceobj