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


Python HenManager.initLogging方法代码示例

本文整理汇总了Python中henmanager.HenManager.initLogging方法的典型用法代码示例。如果您正苦于以下问题:Python HenManager.initLogging方法的具体用法?Python HenManager.initLogging怎么用?Python HenManager.initLogging使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在henmanager.HenManager的用法示例。


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

示例1: interfaceid_to_mac

# 需要导入模块: from henmanager import HenManager [as 别名]
# 或者: from henmanager.HenManager import initLogging [as 别名]
def interfaceid_to_mac(node_str,interface_str):
    manager = HenManager()
    manager.initLogging()
    nodes = manager.getNodes("all","all")
    for nt in nodes:
        for nn in nodes[nt]:
            if nodes[nt][nn].getNodeID().upper() == str(node_str).upper():
                mac = getmac_from_interface(nodes[nt][nn],interface_str)
                return mac
    return None
开发者ID:benroeder,项目名称:HEN,代码行数:12,代码来源:interfaceid_to_mac.py

示例2: check_port

# 需要导入模块: from henmanager import HenManager [as 别名]
# 或者: from henmanager.HenManager import initLogging [as 别名]
def check_port(computer_str,interface_str):
	print computer_str,interface_str,
	switch_str = ""
        port_str = ""

        computer = None
        interface = None
        switch = None
        port = None

        switch_obj = None
        
        manager = HenManager()
        manager.initLogging()
        nodes = manager.getNodes("all")
        
        for node_type in nodes:
            for node in nodes[node_type]:
                if nodes[node_type][node].getNodeID() == computer_str:
                    computer = nodes[node_type][node]
                    break
                
        if computer != None:
            interfaces = computer.getInterfaces()
            for interface_type in interfaces:
                for iface in interfaces[interface_type]:
                    if iface.getInterfaceID() == interface_str:
                        switch_str = iface.getSwitch()
                        port_str = iface.getPort()

        for node_type in nodes:
            for node in nodes[node_type]:
                #print node,switch_str
                if nodes[node_type][node].getNodeID() == switch_str:
                    switch = nodes[node_type][node]
                    break

        if switch != None:
            switch_obj = switch.getInstance()
        
        if switch_obj != None:
	   port_internal_id = switch_obj.getPortInternalID(port_str)
           if (switch_obj.getPortStatus(port_str) == 1):
	      print "up",
	   else:
	      print "down"
	   #print switch_obj.getPortsSpeedByInternalID([port_internal_id])[0][1]
	   print switch_obj.getPortTdr(port_str)
开发者ID:benroeder,项目名称:HEN,代码行数:50,代码来源:check_port.py

示例3: main

# 需要导入模块: from henmanager import HenManager [as 别名]
# 或者: from henmanager.HenManager import initLogging [as 别名]
def main():
    form = cgi.FieldStorage()
    manager = HenManager()
    manager.initLogging()


    if form.has_key("id"):
        experimentid = form["id"].value
        print experimentid
        #manager.experimentDelete(targetNode)

        #cmd = "export PYTHONPATH=$HOME/hen_scripts/hen_scripts/trunk/lib"
        #os.system(cmd)
        #cmd = "sudo hm experiment delete " + targetNode
        #os.system(cmd)


        server = xmlrpclib.ServerProxy(uri="http://localhost:50001/")
        server.delete(experimentid)
开发者ID:benroeder,项目名称:HEN,代码行数:21,代码来源:deleteconfigcgi.py

示例4: main

# 需要导入模块: from henmanager import HenManager [as 别名]
# 或者: from henmanager.HenManager import initLogging [as 别名]
def main():
    form = cgi.FieldStorage()
    manager = HenManager()
    manager.initLogging()


    print "Cache-Control: no-store, no-cache, must-revalidate"
    print "Content-type: text/xml\n"
    print "<experiments>"

    experiments = manager.getExperimentEntries()
    for experimentID in experiments.keys():
        #segments = experiment.split("/")
        #Bfilename = segments[len(segments) - 1]
        # slice off the '.xml' extension
        #fileid = filename[:-4]
        print "\t<experiment id=\"" + experimentID + "\"/>"

    print "</experiments>"
开发者ID:benroeder,项目名称:HEN,代码行数:21,代码来源:refreshconfigcgi.py

示例5: run

# 需要导入模块: from henmanager import HenManager [as 别名]
# 或者: from henmanager.HenManager import initLogging [as 别名]
    def run(self,argv):
        if len(argv) != 2:
            print "Usage :"+argv[0]+" <powerswitch name>"
            sys.exit(1)

        self.target_name = argv[1]
        
        manager = HenManager()
        manager.initLogging()
        nodes = manager.getNodes("powerswitch","all")

        self.target = None
        for node in nodes.values():
            if (node.getNodeID() == self.target_name):
                self.target = node.getInstance()
                
        if self.target == None:
            print "Unknown powerswitch "+argv[1]
            sys.exit(1)

        self.run_tests()
开发者ID:benroeder,项目名称:HEN,代码行数:23,代码来源:test.py

示例6: old

# 需要导入模块: from henmanager import HenManager [as 别名]
# 或者: from henmanager.HenManager import initLogging [as 别名]
 def old(self):
     BASE_URL="cgi-bin/gui/components/network/"
     
     manager = HenManager()
     manager.initLogging()
     
     links = manager.getLinks("all","all")
     graph = pydot.Dot()
 
     switches = manager.getNodes("switch")
     for switch in switches.values():
         if self.__switchStatuses.has_key(switch.getNodeID()):
             if self.__switchStatuses[switch.getNodeID()] == 1:
                 graph.add_node(pydot.Node(switch.getNodeID(),URL=BASE_URL+\
                   "switchinfocgi.py?id="+switch.getNodeID(),\
                   style="filled",color="chartreuse1"))
             else:
                 graph.add_node(pydot.Node(switch.getNodeID(),URL=BASE_URL+\
                   "switchinfocgi.py?id="+switch.getNodeID(),\
                   style="filled",color="firebrick"))
         else:
             graph.add_node(pydot.Node(switch.getNodeID(),URL=BASE_URL+\
                               "switchinfocgi.py?id="+switch.getNodeID()))
     for linktype in links.values():
         for link in linktype.values():
             members = link.getLinkMembers()
             
             graph.add_edge(pydot.Edge(str(members[0].getDeviceId()),\
               str(members[1].getDeviceId()),label=link.getLinkId(),\
               arrowhead="none",headlabel=str(members[1].getDevicePort().\
               replace('GigabitEthernet ','').replace('Management','M')),\
               taillabel=str(members[0].getDevicePort().\
               replace('GigabitEthernet','')),fontsize=8,\
               tooltip=link.getLinkId(),\
               URL=BASE_URL+"linkinfocgi.py?id="+link.getLinkId()))
 
     # prog='circo' isn't bad
     print graph.create_svg(prog='dot')
开发者ID:benroeder,项目名称:HEN,代码行数:40,代码来源:test_switch_topology.py

示例7: HenManager

# 需要导入模块: from henmanager import HenManager [as 别名]
# 或者: from henmanager.HenManager import initLogging [as 别名]
import commands, re
from henmanager import HenManager

# First create a list containing the mac addresses of all the running interfaces
macAddresses = []
macAddressMatcher = re.compile("(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}")
lines = commands.getstatusoutput("ifconfig")[1].splitlines()
for line in lines:
    matchObject = macAddressMatcher.search(line)
    if matchObject:
        macAddresses.append(line[matchObject.start() : matchObject.end()].upper())

# Now match the created list against all of the management mac addresses in the testbed's database
# for computer nodes
manager = HenManager()
manager.initLogging()
nodes = manager.getNodes("computer", "all")
nodeName = None
for node in nodes.values():
    for interface in node.getInterfaces("management"):
        for macAddress in macAddresses:
            if macAddress == interface.getMAC().upper():
                nodeName = node.getNodeID()
if nodeName == None:
    nodes = manager.getNodes("virtualcomputer", "all")
    for node in nodes.values():
        for interface in node.getInterfaces("management"):
            for macAddress in macAddresses:
                if macAddress == interface.getMAC().upper():
                    nodeName = node.getNodeID()
print nodeName
开发者ID:benroeder,项目名称:HEN,代码行数:33,代码来源:nodeid.py

示例8: ComputerControl

# 需要导入模块: from henmanager import HenManager [as 别名]
# 或者: from henmanager.HenManager import initLogging [as 别名]
class ComputerControl(Daemon):
    """\brief Implements basic computer daemon functionality.
    """

    __version = "Computer Daemon v0.1 (simple)"
    __henManager = None

    def __init__(self):
        Daemon.__init__(self)
        self.__henManager = HenManager()
        # Allow specialized instance dictionary to be created in hm
        # self.__henManager.createNodeInstances()
        self.__registerMethods()
        self.__computerID = self.__getComputerID()
        self.__computerInfo = self.__henManager.getNodes("computer")[self.__computerID]
        self.__ifaceIDtoNameMappings = self.__getIfaceMappings()

    def getComputerManagementIP(self):
        # Get the management ip address so that we can bind to it.
        interfaces = self.__computerInfo.getInterfaces("management")
        try:
            return interfaces[0].getIP()
        except:
            return "0.0.0.0"

    def __getComputerID(self):
        # Prints the name of the node that the script is run from. To do so it matches the mac addresses of
        # all running interfaces against the mac addresses in the testbed's database. Prints None if no match is found

        # First create a list containing the mac addresses of all the running interfaces
        macAddresses = []
        macAddressMatcher = re.compile("(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}")
        lines = commands.getstatusoutput("ifconfig")[1].splitlines()
        for line in lines:
            matchObject = macAddressMatcher.search(line)
            if matchObject:
                macAddresses.append(line[matchObject.start() : matchObject.end()].upper())

        # Now match the created list against all of the management mac addresses in the testbed's database
        # for computer nodes
        self.__henManager.initLogging()
        nodes = self.__henManager.getNodes("computer", "all")
        nodeName = None
        for node in nodes.values():
            for interface in node.getInterfaces("management"):
                for macAddress in macAddresses:
                    if macAddress == interface.getMAC().upper():
                        nodeName = node.getNodeID()
        if nodeName == None:
            nodes = self.__henManager.getNodes("virtualcomputer", "all")
            for node in nodes.values():
                for interface in node.getInterfaces("management"):
                    for macAddress in macAddresses:
                        if macAddress == interface.getMAC().upper():
                            nodeName = node.getNodeID()
        return nodeName

    def __getIfaceMappings(self):
        mappings = {}

        # Supports only Linux for now
        interfaces = self.__computerInfo.getInterfaces("experimental")
        ifacesInfo = commands.getstatusoutput("ifconfig -a | grep HWaddr")[1].splitlines()
        for interface in interfaces:
            for infoLine in ifacesInfo:
                if infoLine.find(interface.getMAC()) != -1:
                    mappings[interface.getInterfaceID()] = infoLine[: infoLine.find(" ")]
        return mappings

    def __registerMethods(self):
        self.registerMethodHandler("get_computer_id", self.getComputerID)
        self.registerMethodHandler("autodetect", self.autodetect)
        self.registerMethodHandler("execute_command", self.executeCommand)
        self.registerMethodHandler("gcc_compile", self.gccCompile)
        self.registerMethodHandler("cat", self.cat)
        self.registerMethodHandler("make", self.make)
        self.registerMethodHandler("mkdir", self.mkdir)
        self.registerMethodHandler("untar", self.untar)
        self.registerMethodHandler("add_route", self.addRoute)
        self.registerMethodHandler("delete_route", self.delRoute)
        self.registerMethodHandler("config_iface", self.configIface)
        self.registerMethodHandler("click-align", self.clickAlign)
        self.registerMethodHandler("click-install", self.clickInstall)
        self.registerMethodHandler("click-uninstall", self.clickUninstall)
        self.registerMethodHandler("load_module", self.loadModule)
        self.registerMethodHandler("unload_module", self.unloadModule)
        self.registerMethodHandler("linux_forwarding_on", self.linuxForwardingOn)
        self.registerMethodHandler("linux_forwarding_off", self.linuxForwardingOff)

    def __sendReply(self, prot, code, seq, payload):
        if code == 0:
            code = 200
        else:
            code = 422  # returnCodes[422] = "error executing command"
        prot.sendReply(code, seq, payload)

    def autodetect(self, prot, seq, ln, payload):
        pass

    def getComputerID(self, prot, seq, ln, payload):
#.........这里部分代码省略.........
开发者ID:benroeder,项目名称:HEN,代码行数:103,代码来源:computerdaemon.py

示例9: main

# 需要导入模块: from henmanager import HenManager [as 别名]
# 或者: from henmanager.HenManager import initLogging [as 别名]
def main():
    
    manager = HenManager()
    manager.initLogging()
    #switchdb automatically loads most information into memory.
    switchdb = SwitchDB(manager)
开发者ID:benroeder,项目名称:HEN,代码行数:8,代码来源:test_switchd.py

示例10: AutodetectManager

# 需要导入模块: from henmanager import HenManager [as 别名]
# 或者: from henmanager.HenManager import initLogging [as 别名]
class AutodetectManager(Daemon):

    __hen_manager = None
    __hardware_processor = None

    def __init__(self):
        Daemon.__init__(self)
        self.__hen_manager = HenManager()
        self.__hen_manager.initLogging()
        self.__hardware_processor = LSHardwareProcessor(self.__hen_manager, \
                                                    self.__parseMacTableURL())
        self.__registerMethods()

    def __parseMacTableURL(self):
        """\brief Parses the Hen config file, and returns the MACTABLE_URL
            \return macTableURL - the value of MACTABLE_URL in the Hen config
        """
        configFile = ConfigParser.ConfigParser()
        configFile.read(HEN_CONFIG)
        return configFile.get('AUTODETECT', 'MACTABLE_URL')

    def __registerMethods(self):
        self.registerMethodHandler("receive_detectiondata", \
                                   self.receiveDetectionData)
        self.registerMethodHandler("enable_debug_mode", \
                                   self.enableDebugMode)
        self.registerMethodHandler("disable_debug_mode", \
                                   self.disableDebugMode)

    def enableDebugMode(self,prot,seq,ln,payload):
        self.__hardware_processor.enableDebugMode()
        prot.sendReply(200, seq, "")

    def disableDebugMode(self,prot,seq,ln,payload):
        self.__hardware_processor.disableDebugMode()
        prot.sendReply(200, seq, "")
        
    def receiveDetectionData(self,prot,seq,ln,payload):
        """\brief Method called when detection data is received from
            autodetectclient scripts being run on remote hosts.
        """
        log.debug("receiveDetectionData() called.")
        (nodeid, addr) = self.__ipAddressToNodeID(prot.getSocket())
        if not nodeid or not addr:
            log.warning("Bad results from __ipAddressToNodeID().")
            prot.sendReply(500, seq, \
                   "Failure: Daemon could not resolve IP to nodeid.")
            return
        log.info("received data from %s (%s)" % (str(addr), str(nodeid)))
        prot.sendReply(200, seq, "")
        self.__hardware_processor.parseFileAndPrint(nodeid, payload)


    def __ipAddressToNodeID(self, sock):
        """\brief Retrieves the IP address of the connected client, then tries
            to look up a nodeid for it from HenManager
            \param sock - socket on which the client is connected
            \return nodeid - id of node to which IP address belongs, -1 if not
                                found
        """
        try:
            (addr, port) = sock.getpeername()       
            log.debug("addr %" + str(addr))            
            computerNodes = self.__hen_manager.getNodes("computer", "all")
            for computerNode in computerNodes.values():
                interfaces = computerNode.getInterfaces("management")
                for interface in interfaces:
                    if (interface.getIP() == addr):
                        return (computerNode.getNodeID(), addr)
        except:
            pass
        return (None, None)
开发者ID:benroeder,项目名称:HEN,代码行数:74,代码来源:autodetectdaemon.py


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