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


Python AutoNetkit.rtr_folder_name方法代码示例

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


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

示例1: router_conf_file

# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import rtr_folder_name [as 别名]
def router_conf_file(network, router):
    """Returns filename for config file for router"""
    return "%s.conf" % ank.rtr_folder_name(network, router)
开发者ID:iainwp,项目名称:ank_le,代码行数:5,代码来源:junoscompiler.py

示例2: router_dir

# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import rtr_folder_name [as 别名]
def router_dir(network, rtr):
    """Returns path for router rtr"""
    foldername = ank.rtr_folder_name(network, rtr)
    return os.path.join(netkit_dir(network, rtr), foldername)
开发者ID:medim,项目名称:autonetkit,代码行数:6,代码来源:netkitcompiler.py

示例3: configure_netkit

# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import rtr_folder_name [as 别名]
    def configure_netkit(self):
        """Generates Netkit and Zebra/Quagga specific configuration files."""

        # Sets up netkit related files
        tap_host = ank.get_tap_host(self.network)

        ank_version = pkg_resources.get_distribution("AutoNetkit").version
        date = time.strftime("%Y-%m-%d %H:%M", time.localtime())

        lab_template = lookup.get_template("netkit/lab.mako")
        startup_template = lookup.get_template("netkit/startup.mako")
        zebra_daemons_template = lookup.get_template(
            "quagga/zebra_daemons.mako")
        zebra_template = lookup.get_template("quagga/zebra.mako")
        sshd_template = lookup.get_template("linux/sshd.mako")
        motd_template = lookup.get_template("quagga/motd.mako")

        # Shared (common) configuration
        startup_daemon_list = []
        #Setup ssh
        shutil.copy(resource_filename("AutoNetkit","lib/shadow"), shared_etc_dir())
        startup_daemon_list.append("ssh")
        # Need to chown root dir for ssh keys
# refer http://list.dia.uniroma3.it/pipermail/netkit.users/2010-February/000552.html
        use_ssh_key = False
        if config.settings['Netkit']['ssh key']:
            #chown root:root /root
            use_ssh_key = True

        f_startup = open( os.path.join(lab_dir(), "shared.startup"), 'wb')
        f_startup.write(startup_template.render(
            interfaces=[],
            add_localhost=True,
            #don't send out the tap interface
            del_default_route=True,
            daemons=startup_daemon_list,
            use_ssh_key = use_ssh_key,
            ))
        f_startup.close()


# Files for indvidual node configuration

        #TODO: this needs to be created for each netkit host machine
        f_lab = open(os.path.join(lab_dir(), "lab.conf"), 'wb')

        lab_conf = {}
        tap_list_strings = {}

        ibgp_routers = ank.ibgp_routers(self.network)
        ebgp_routers = ank.ebgp_routers(self.network)
        igp_graph = ank.igp_graph(self.network)

        dns_servers = set(self.network.dns_servers())
        routers = set(self.network.routers())

        for node in self.network.devices():
            #TODO: see if rtr label is still needed, if so replace with
            # appropriate naming module function
            rtr_folder_name = ank.rtr_folder_name(self.network, node)

            # sshd options
            f_sshd = open( os.path.join(sshd_dir(self.network, node), "sshd_config"), 'wb')
            f_sshd.write(sshd_template.render())
            f_sshd.close()

            lab_conf[rtr_folder_name] = []
            startup_daemon_list = ["zebra"]
            startup_int_list = []

            # convert tap list from ips into strings
            # tap_int_id cannot conflict with already allocated interfaces
            # assume edges number sequentially, so next free int id is number of
            # edges
            node_tap_id = self.tap_interface_id(self.network, node)
            tap_list_strings[rtr_folder_name] = (node_tap_id,
                                                 self.network[node].get('tap_ip'))

            if node in dns_servers:
                startup_daemon_list.append("bind")
                dns_memory = 64 # Allocate more memory to DNS server 
                #TODO: remove key, val and make it just key: val
                lab_conf[rtr_folder_name].append( ('mem', dns_memory))

            if config.settings['Netkit']['ssh key']:
                f_auth_keys = open(os.path.join(dot_ssh_dir(self.network, node), "authorized_keys"), "wb")
                f_auth_keys.write(config.settings['Netkit']['ssh key'])
                f_auth_keys.close()

            # Zebra Daemons
            zebra_daemon_list = []
            f_zdaemons = open( os.path.join(zebra_dir(self.network, node),
                                            "daemons"), 'wb')
# Always start Zebra
            zebra_daemon_list.append("zebra")

            if igp_graph.degree(node) > 0:
                zebra_daemon_list.append("ospfd") # Only start IGP process if IGP links
            if (node in ibgp_routers) or (node in ebgp_routers):
                zebra_daemon_list.append("bgpd")
#.........这里部分代码省略.........
开发者ID:medim,项目名称:autonetkit,代码行数:103,代码来源:netkitcompiler.py

示例4: collect_data

# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import rtr_folder_name [as 别名]
    def collect_data(self, commands):
        shell = self.server.get_shell()
        shell.setecho(False)

        collected_data_dir = config.collected_data_dir
        netkit_data_dir = os.path.join(collected_data_dir, "netkit")
        if not os.path.isdir(netkit_data_dir):
                os.mkdir(netkit_data_dir)
        host_data_dir = os.path.join(netkit_data_dir, self.host_alias)
        if not os.path.isdir(host_data_dir):
                os.mkdir(host_data_dir)
        collect_timestamp_dir = os.path.join(host_data_dir, time.strftime("%Y%m%d_%H%M%S", time.localtime()))
        if not os.path.isdir(collect_timestamp_dir):
            os.mkdir(collect_timestamp_dir)

        servers = set(self.network.servers())

        #TODO: need to have way to allow privexec.... or just disable enable password?
#TODO: Put term len 0 into configs

        for node in self.network.devices():
            routername = ank.fqdn(self.network, node)
            full_routername = ank.rtr_folder_name(self.network, node)
            user_exec_prompt = "%s>" % node.dns_hostname
            priv_exec_prompt = "%s#" % node.dns_hostname
            for port_command in commands:
                LOG.info("%s: running %s" % (routername, port_command))
                telnet_port, command = port_command.split(":")
                if telnet_port == 'ssh':
                    self.server.connect_vm(node.tap_ip, shell)
                    shell.sendline(command)
                    shell.expect(self.server.NETKIT_PROMPT)
                    command_output = shell.before
                    self.server.disconnect_vm(shell)
                    shell.prompt()
# need to ssh into this machine
                else:
                    if node in servers:
# don't try telnet into as zebra not running
                        continue
# use telnet
                    shell.sendline("telnet %s %s" % (node.tap_ip, telnet_port))
                    shell.expect("Password:")
                    shell.sendline("1234")
                    shell.expect(user_exec_prompt)
                    shell.sendline("en")
                    i = shell.expect(["Password:", priv_exec_prompt])
                    if i == 0:
                        shell.sendline("1234")
                    else:
# all good, in priv exec
                        pass
# just to be sure
                    set_term_length = "term len 0"
                    shell.sendline(set_term_length)
                    shell.expect(priv_exec_prompt)
                    shell.sendline(command)
                    shell.expect(priv_exec_prompt)
# Can be an issue with the telnet x zebra command (not for bgpd it seems)
                    command_output = shell.before
# If no command output, captured the previous command, try again
                    if command_output.strip() == set_term_length:
                        shell.expect(priv_exec_prompt)
                        command_output = shell.before
                    shell.sendline("exit")
                    shell.prompt() 
# from http://stackoverflow.com/q/295135/
                command_filename_format = (re.sub('[^\w\s-]', '', command).strip().lower())
                filename = "%s_%s_%s.txt" % (full_routername,
                        command_filename_format,
                        time.strftime("%Y%m%d_%H%M%S", time.localtime()))
                filename = os.path.join(collect_timestamp_dir, filename)
                
                with open( filename, 'w') as f_out:
                    f_out.write(command_output)
开发者ID:coaj,项目名称:autonetkit,代码行数:77,代码来源:netkit_deploy.py

示例5: folder_name

# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import rtr_folder_name [as 别名]
 def folder_name(self):
     return ank.rtr_folder_name(self.network, self)
开发者ID:coaj,项目名称:autonetkit,代码行数:4,代码来源:network.py

示例6: device_hostname

# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import rtr_folder_name [as 别名]
 def device_hostname(self):
     """ Replaces . with _ to make safe for router configs"""
     return ank.rtr_folder_name(self.network, self)
开发者ID:coaj,项目名称:autonetkit,代码行数:5,代码来源:network.py


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