当前位置: 首页>>代码示例>>Python>>正文


Python utils.isMACAddress函数代码示例

本文整理汇总了Python中pulse2.utils.isMACAddress函数的典型用法代码示例。如果您正苦于以下问题:Python isMACAddress函数的具体用法?Python isMACAddress怎么用?Python isMACAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了isMACAddress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: computerUpdate

    def computerUpdate(self, MACAddress):
        """
        Method to update the menu a computer.

        @raise TypeError: if MACAddress is malformed
        @return: a deferred object resulting to 1 if update was
                 successful, else 0.
        @rtype: int
        """

        def onSuccess(result):
            # TODO : add menu re-generation here
            return 1

        if not isMACAddress(MACAddress):
            raise TypeError

        url, credentials = makeURL(PackageServerConfig().mmc_agent)

        self.logger.info('Imaging: Starting menu update for %s' % (MACAddress))
        client = self._getXMLRPCClient()
        func = 'imaging.getMenu'
        args = (MACAddress)
        d = client.callRemote(func, *args)
        d.addCallbacks(onSuccess, client.onError, errbackArgs = (func, args, 0))
        return d
开发者ID:jfmorcillo,项目名称:mmc,代码行数:26,代码来源:functions.py

示例2: POST

    def POST(self, authkey, mac_list, hostname):
        log("Authenticate computer %s with authkey %s" % (hostname, authkey))
        if not authkey == cherrypy.config.get("dlp.authkey"):
            log("Failed to authenticate computer %s, authkey missmatch." % hostname, severity=logging.ERROR)
            raise cherrypy.HTTPError(401, "Not authorized")

        if isinstance(mac_list, basestring):
            mac_list = [mac_list]

        # Validate input values
        for mac in mac_list:
            if not isMACAddress(mac):
                raise cherrypy.HTTPError(400, "MAC address is not correct")

        try:
            uuid = cherrypy.request.xmlrpc_client.pull_target_awake(hostname, mac_list)
            if uuid is not None and uuid:
                cherrypy.session[HOSTNAME_KEY] = hostname
                cherrypy.session[MAC_KEY] = mac_list
                cherrypy.session[UUID_KEY] = uuid
                cherrypy.session.save()
                log("Result: %s" % uuid)
                return "OK"
            else:
                log("Not recognized machine, hostname=%s, mac_list=%s" % (hostname, mac_list), severity=logging.WARNING, traceback=True)
                raise cherrypy.HTTPError(404, "Not found")
        except cherrypy.HTTPError:
            raise
        except:
            log("pull_target_awake failed\n", severity=logging.ERROR, traceback=True)
            raise cherrypy.HTTPError(503, "Service unavailable")
开发者ID:AnatomicJC,项目名称:mmc,代码行数:31,代码来源:v1.py

示例3: xmlrpc_logClientAction

    def xmlrpc_logClientAction(self, mac, level, phase, message):
        """
        Remote logging.

        Mainly used to send progress info to our mmc-agent.

        @param mac : The mac address of the client
        @param level : the log level
        @param phase : what the client was doing when the info was logged
        @param message : the log message itself
        @raise TypeError: if MACAddress is malformed
        @return: a deferred object resulting to 1 if processing was
                 successful, else 0.
        @rtype: int
        """

        def _getmacCB(result):
            if result and type(result) == dict :
                client = self._getXMLRPCClient()
                func = 'imaging.logClientAction'
                args = (self.config.imaging_api['uuid'], result['uuid'], level, phase, message)
                d = client.callRemote(func, *args)
                d.addCallbacks(lambda x : True, RPCReplay().onError, errbackArgs = (func, args, 0))
                return d

            self.logger.warn('Imaging: Failed resolving UUID for client %s : %s' % (mac, result))
            return False

        if not isMACAddress(mac):
            raise TypeError

        self.logger.debug('Imaging: Client %s sent a log message while %s (%s) : %s' % (mac, phase, level, message))
        d = self.xmlrpc_getComputerByMac(mac)
        d.addCallback(_getmacCB)
        return d
开发者ID:neoclust,项目名称:mmc,代码行数:35,代码来源:__init__.py

示例4: _validate_target

    def _validate_target (self, target):
        """ 
        Validating of target format 

        @param target: target container
        @type target: list

        @return: True if format is valid
        @rtype: bool
        """
        if not isinstance(target, tuple) or not isinstance(target, list):
            log.warn("Invalid target format.")
            return False

        if len(target) != 3 :
            log.warn("Invalid target format.")
            return False

        hostname, fqdn, ifaces = target

        if not isinstance(ifaces, dict) :
            log.warn("Invalid target format.")
            return False

        for iface in ifaces :
            for key, value in iface.items():
                if not isinstance(value, str) :
                    log.warn("Invalid interface format, section '%s' (hostname='%s')" % (key, hostname))
                    return False
                if key == "mac" :
                    if not isMACAddress(value) :
                        log.warn("Invalid MAC address format : '%s' (hostname='%s')" % (value, hostname))
                        return False
        return True
开发者ID:pavelpromin,项目名称:mmc,代码行数:34,代码来源:network.py

示例5: computerRegister

    def computerRegister(self, computerName, MACAddress, 
                         imagingData, waitToBeInventoried=False):
        """
        Called by pulse2-imaging-server to tell the Package Server to
        register a new computer. The computer name may contain a profile
        and an entity path (self,like profile:/entityA/entityB/computer)

        @type computerName: str
        @type MACAddress: str
        @raise : TypeError is computerName is not a str
        @raise : TypeError is MACAddress is not a mac addr
        @rtype : bool
        """
        if type(computerName) != str and type(computerName) != unicode:
            raise TypeError('Bad Computer name: %s' % computerName)
        if not isMACAddress(MACAddress):
            raise TypeError('BAD MAC address: %s' % MACAddress)
        d = self.callRemote("computerRegister", 
                            computerName, 
                            MACAddress, 
                            imagingData, 
                            waitToBeInventoried)
        d.addErrback(self.onErrorRaise, 
                     "Imaging:computerRegister",
                     [computerName, MACAddress, imagingData, waitToBeInventoried])
        return d
开发者ID:pulse-project,项目名称:pulse,代码行数:26,代码来源:imaging.py

示例6: computerCreateImageDirectory

 def computerCreateImageDirectory(self, MACAddress):
     """
     Asks the Package Server to create the file system structure for the given computer uuid thanks to imagingData content.
     """
     if not isMACAddress(MACAddress):
         raise TypeError
     d = self.callRemote("computerCreateImageDirectory", MACAddress)
     d.addErrback(self.onErrorRaise, "Imaging:computerCreateImageDirectory", [MACAddress])
     return d
开发者ID:tekmans,项目名称:mmc,代码行数:9,代码来源:imaging.py

示例7: computerPrepareImagingDirectory

 def computerPrepareImagingDirectory(self, MACAddress, imagingData=False):
     """
     Asks the Package Server to create the file system structure for the given computer uuid thanks to imagingData content.
     If imagingData is False, the package server queries the MMC agent for the imaging data.
     """
     if not isMACAddress(MACAddress):
         raise TypeError
     d = self.callRemote("computerPrepareImagingDirectory", MACAddress, imagingData)
     d.addErrback(self.onErrorRaise, "Imaging:computerPrepareImagingDirectory", [MACAddress, imagingData])
     return d
开发者ID:tekmans,项目名称:mmc,代码行数:10,代码来源:imaging.py

示例8: computerChangeDefaultMenuItem

    def computerChangeDefaultMenuItem(self, mac, num):
        """
        Called by computer MAC when he want to set its default entry to num

        @param mac : The mac address of the client
        @param num : The menu number
        @type mac: MAC Address
        @type num: int
        """

        def _onSuccess(result):
            if type(result) != list and len(result) != 2:
                self.logger.error('Couldn\'t set default entry on %s for %s : %s' % (num, computerUUID, str(result)))
                ret = False
            elif not result[0]:
                self.logger.error('Couldn\'t set default entry on %s for %s : %s' % (num, computerUUID, str(result)))
                ret = False
            else:
                shortname = self.getClientShortname(mac)
                if shortname:
                    self.logger.info('Default entry set to %s after disk image creation/restoration for client %s (%s)' % (num, shortname, mac))
                else:
                    self.logger.info('Default entry set to %s after disk image creation/restoration for unknown client (%s)' % (num, mac))
                ret = True
            return ret

        def _onError(error, funcname, args, default_return):
            # Storing RPC so that it can be replayed lated
            RPCReplay().onError(error, funcname, args, default_return)
            # Manually update the computer boot menu
            self.logger.warning('MMC agent can\'t be contacted: updating default menu item to the first "manually"')
            if changeDefaultMenuItem(mac, 0):
                self.logger.warning('Update done')
            else:
                self.logger.error('Update failed')
            return default_return

        if not isMACAddress(mac):
            self.logger.error("Bad computer MAC %s" % str(mac))
            ret = False
        else:
            computerUUID = self.myUUIDCache.getByMac(mac)
            if not computerUUID:
                self.logger.error("Can't get computer UUID for MAC address %s" % mac)
                ret = False
            else:
                computerUUID = computerUUID['uuid']
                client = self._getXMLRPCClient()
                func = 'imaging.computerChangeDefaultMenuItem'
                args = (self.config.imaging_api['uuid'], computerUUID, num)
                d = client.callRemote(func, *args)
                d.addCallbacks(_onSuccess, _onError, errbackArgs = (func, args, True))
                return d
        return ret
开发者ID:jfmorcillo,项目名称:mmc,代码行数:54,代码来源:functions.py

示例9: mac

    def mac(self):
        """ Common argument for all PXE methods """
        if self.MAC_FLAG in self.packet :
            start = self.packet.index(self.MAC_FLAG) + len(self.MAC_FLAG)

            if len(self.packet[start:]) >= 17 :
                mac = self.packet[start:start+17]
                if isMACAddress(mac) :
                    return mac

        return None
开发者ID:AnatomicJC,项目名称:mmc,代码行数:11,代码来源:parser.py

示例10: injectInventory

    def injectInventory(self, MACAddress, inventory):
        """
        Method to process the inventory of a computer

        @raise TypeError: if MACAddress is malformed
        @return: a deferred object resulting to 1 if processing was
                 successful, else 0.
        @rtype: int
        """
        def _onSuccess(result):
            shortname = self.getClientShortname(MACAddress)
            if result and type(result) == list and len(result) == 2:
                if result[0] == True :
                    if shortname:
                        self.logger.debug('Imaging: Imaging database disks and partitions information successfully updated for client %s (%s)' % (shortname, MACAddress))
                    else:
                        self.logger.debug('Imaging: Imaging database disks and partitions information successfully updated for unknown client (%s)' % (MACAddress))
                    return True
                else:
                    if shortname:
                        self.logger.error('Imaging: Failed to update disks and partitions information for client %s (%s): %s' % (shortname, MACAddress, result[1]))
                    else:
                        self.logger.error('Imaging: Failed to update disks and partitions information for unknown client (%s): %s' % (MACAddress, result[1]))
                    return False
            else:
                if shortname:
                    self.logger.error('Imaging: Failed to update disks and partitions information for client %s (%s): %s' % (shortname, MACAddress, result))
                else:
                    self.logger.error('Imaging: Failed to update disks and partitions information for unknown client (%s): %s' % (MACAddress, result))
                return False

        def _getmacCB(result):
            if result and type(result) == dict:
                client = self._getXMLRPCClient()
                func = 'imaging.injectInventory'
                args = (self.config.imaging_api['uuid'], result['uuid'], inventory)
                d = client.callRemote(func, *args)
                d.addCallbacks(_onSuccess, client.onError, errbackArgs=(func, args, 0))
                return d
            return False

        if not isMACAddress(MACAddress):
            raise TypeError
        self.logger.debug('Imaging: New PXE inventory received from client %s' % (MACAddress))
        d = self.getComputerByMac(MACAddress)
        d.addCallback(_getmacCB)
        return d
开发者ID:jfmorcillo,项目名称:mmc,代码行数:47,代码来源:functions.py

示例11: computerRegister

    def computerRegister(self, computerName, macAddress, imagingData = False, waitToBeInventoried=False):
        """
        Method to register a new computer.

        if imagingData is set, we know that the method is called from a MMC
        agent !

        @raise TypeError: if computerName or MACAddress are malformed
        @return: a deferred object resulting to True if registration was
                 successful, else False.
        @rtype: bool
        """

        def onSuccess(result):
            if type(result) != list and len(result) != 2:
                self.logger.error('Imaging: Registering client %s (%s) failed: %s' % (computerName, macAddress, str(result)))
                ret = False
            elif not result[0]:
                self.logger.error('Imaging: Registering client %s (%s) failed: %s' % (computerName, macAddress, result[1]))
                ret = False
            else:
                uuid = result[1]
                self.logger.info('Imaging: Client %s (%s) registered as %s' % (computerName, macAddress, uuid))
                self.myUUIDCache.set(uuid, macAddress, hostname, domain, entity)
                ret = self.computerPrepareImagingDirectory(uuid, {'mac': macAddress, 'hostname': hostname})
            return ret

        try:
            # check MAC Addr is conform
            if not isMACAddress(macAddress):
                raise TypeError('Malformed MAC address: %s' % macAddress)
            # check computer name is conform
            if not len(computerName):
                raise TypeError('Malformed computer name: %s' % computerName)
            profile, entity_path, hostname, domain = splitComputerPath(computerName)
            entity_path = entity_path.split('/')
            entity = entity_path.pop()
        except TypeError, ex:
            self.logger.error('Imaging: Won\'t register %s as %s : %s' % (macAddress, computerName, ex))
            return maybeDeferred(lambda x: x, False)
开发者ID:jfmorcillo,项目名称:mmc,代码行数:40,代码来源:functions.py

示例12: computerMenuUpdate

    def computerMenuUpdate(self, mac):
        """
        Perform a menu refresh.

        @param mac : The mac address of the client
        @return: a deferred object resulting to 1 if processing was
                 successful, else 0.
        @rtype: int
        """

        def _getmacCB(result):
            if result and type(result) == dict :
                # TODO : call menu refresh here
                return True
            return False

        if not isMACAddress(mac):
            raise TypeError
        self.logger.debug('Imaging: Client %s asked for a menu update' % (mac))
        d = self.getComputerByMac(mac)
        d.addCallback(_getmacCB)
        return d
开发者ID:jfmorcillo,项目名称:mmc,代码行数:22,代码来源:functions.py

示例13: xmlrpc_injectInventory

    def xmlrpc_injectInventory(self, MACAddress, inventory):
        """
        Method to process the inventory of a computer

        @raise TypeError: if MACAddress is malformed
        @return: a deferred object resulting to 1 if processing was
                 successful, else 0.
        @rtype: int
        """
        def _onSuccess(result):
            if result and type(result) == list and len(result) == 2:
                if result[0] == True :
                    self.logger.info('Imaging: injected inventory for client %s' % (MACAddress))
                    return True
                else:
                    self.logger.warn('Imaging: failed injecting inventory for client %s : %s' % (MACAddress, result[1]))
                    return False
            else:
                self.logger.warn('Imaging: failed injecting inventory for client %s : %s' % (MACAddress, result))
                return False

        def _getmacCB(result):
            if result and type(result) == dict:
                client = self._getXMLRPCClient()
                func = 'imaging.injectInventory'
                args = (self.config.imaging_api['uuid'], result['uuid'], inventory)
                d = client.callRemote(func, *args)
                d.addCallbacks(_onSuccess, client.onError, errbackArgs=(func, args, 0))
                return d
            self.logger.warn('Imaging: Failed resolving UUID for client %s : %s' % (MACAddress, result))
            return False

        if not isMACAddress(MACAddress):
            raise TypeError
        self.logger.debug('Imaging: Starting inventory processing for %s' % (MACAddress))
        d = self.xmlrpc_getComputerByMac(MACAddress)
        d.addCallback(_getmacCB)
        return d
开发者ID:neoclust,项目名称:mmc,代码行数:38,代码来源:__init__.py

示例14: getDefaultMenuItem

    def getDefaultMenuItem(self, mac):
        """
        Getting of default menu entry from the database.

        @param mac: MAC address of machine
        @type mac: str

        @return: default menu entry
        @rtype: int
        """
        if not isMACAddress(mac):
            self.logger.error("Get default menu item: bad computer MAC %s" % str(mac))
            ret = False
        else:
            computerUUID = self.myUUIDCache.getByMac(mac)
            if not computerUUID:
                self.logger.error("Can't get computer UUID for MAC address %s" % mac)
                ret = False
            else:
                computerUUID = computerUUID['uuid']
                client = self._getXMLRPCClient()
                func = 'imaging.getDefaultMenuItem'
                d = client.callRemote(func, computerUUID)
                @d.addCallback
                def _cb(result):
                    if isinstance(result, list) :
                        success, order = result
                        if success :
                            shortname = self.getClientShortname(mac)
                            if shortname:
                                self.logger.debug("Client %s (%s) default menu entry is %s" % (shortname, str(mac), order))
                            else:
                                self.logger.debug("Unknown client (%s) default menu entry is %s" % (shortname, str(mac), order))
                            return order
                return d
        return ret
开发者ID:jfmorcillo,项目名称:mmc,代码行数:36,代码来源:functions.py

示例15: database

                if result[0]:
                    self.myUUIDCache.set(result[1]['uuid'],
                                         MACAddress,
                                         result[1]['shortname'].encode('utf-8'),
                                         result[1]['fqdn'].encode('utf-8'),
                                         result[1]['entity'].encode('utf-8')
                                        )
                    self.logger.debug('Imaging: Updating cache for %s' % (MACAddress))
                    return result[1]
                else:
                    self.logger.debug("Imaging: Unable to resolve %s neither from cache nor from database (unknown computer?)" % (MACAddress))
                    return False
            except Exception, e:
                self.logger.error('Imaging: While processing result %s for %s : %s' % (result, MACAddress, e))

        if not isMACAddress(MACAddress):
            raise TypeError('Bad MAC address: %s' % MACAddress)

        # try to extract from our cache
        res = self.myUUIDCache.getByMac(MACAddress)
        if res:  # fetched from cache
            res['shortname'] = res['shortname'].decode('utf-8')
            res['fqdn'] = res['fqdn'].decode('utf-8')
            res['entity'] = res['entity'].decode('utf-8')
            return maybeDeferred(lambda x: x, res)
        else:  # cache fetching failed, try to obtain the real value
            self.logger.debug('Imaging: Unable to resolve %s from cache, querying database' % (MACAddress))
            client = self._getXMLRPCClient()
            func = 'imaging.getComputerByMac'
            args = [MACAddress]
            d = client.callRemote(func, *args)
开发者ID:jfmorcillo,项目名称:mmc,代码行数:31,代码来源:functions.py


注:本文中的pulse2.utils.isMACAddress函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。