def __init__(self, *args, **kwargs): """Initialize device.""" self.args = args self.kwargs = kwargs config = kwargs.get("config", kwargs) self.unique_id = os.getenv("SUDO_USER", os.getenv("USER", "")) self.docker_network = config.get("docker_network", "prplMesh-net-{}".format(self.unique_id)) self.role = config.get("role", "agent") self.connection_type = config.get("connection_type", None) self.conn_cmd = config.get("conn_cmd", None) self.wan_ip = config.get("wan_ip", None) self.username = config.get("username", "root") self.name = "-".join((config.get("name", "netgear-rax40"), self.unique_id)) # If no WAN IP is set in config file retrieve IP from docker network set in config # X.X.X.245 IP will be selected from docker network if not self.wan_ip: self.connection = connection_decider.connection(device=self, conn_type="local_serial", **kwargs) self.connection.connect() self.consoles = [self] self.logfile_read = sys.stdout self.wan_network = self.get_docker_subnet() self.wan_ip = self.wan_network[+245] self.set_iface_ip("br-lan", self.wan_ip, self.wan_network.prefixlen) self.close() self.kill(signal.SIGTERM) # Removal of PID is required by pexpect in order to spawn a new process # serial connection should be terminated by 2 commands above self.pid = None self.wired_sniffer = Sniffer(_get_bridge_interface(self.docker_network), boardfarm.config.output_dir) self.connection = connection_decider.connection(device=self, conn_type="ssh", conn_cmd="ssh {}@{}".format( self.username, self.wan_ip)) self.connection.connect() # Append active connection to the general array for logging self.consoles = [self] # Point what to log as data read from child process of pexpect # Result: boardfarm will log communication in separate file self.logfile_read = sys.stdout self.add_iface_to_bridge(self.wan_iface, "br-lan") if self.role == "controller": self.controller_entity = ALEntityPrplWrt(self, is_controller=True) else: self.agent_entity = ALEntityPrplWrt(self, is_controller=False) self.prplmesh_start_agent()
def spawn_device(self, **kwargs): """Spwans a console device based on the class type specified in the paramter device_type. Currently the communication with the console occurs via the pexpect module.""" self.connection = conn_dec.connection(self.conn_type, device=self, conn_cmd=self.conn_cmd)
def __init__(self, *args, **kwargs): """Constructor method""" conn_cmd = kwargs.get("conn_cmd", None) connection_type = kwargs.get("connection_type", "local_serial") self.ipaddr = kwargs.get("ipaddr", None) self.password = kwargs.get("password", "cisco") self.password_admin = kwargs.get("password_admin", "cisco") self.mac_domain = kwargs.get("mac_domain", None) self.channel_bonding = kwargs.get("channel_bonding", 24) # 16x8 : total 24 if conn_cmd is None: # TODO: try to parse from ipaddr, etc raise Exception("No command specified to connect to CBR8 CMTS") self.connection = connection_decider.connection(connection_type, device=self, conn_cmd=conn_cmd) if kwargs.get("debug", False): self.logfile_read = sys.stdout self.connection.connect() self.connect() self.logfile_read = sys.stdout self.name = kwargs.get("name", "cBR8_cmts")
def connect(self): """This method is used to connect to cmts. Login to the cmts based on the connection type available :raises Exception: Unable to get prompt on Topvision device """ self.connection = connection_decider.connection(self.connection_type, device=self, conn_cmd=self.conn_cmd) self.logfile_read = sys.stdout self.connection.connect() try: if self.expect([pexpect.TIMEOUT, "Username:"******"Password:"******"enable") self.expect(self.prompt[1]) self.additional_setup() return except pexpect.exceptions.TIMEOUT: raise Exception( "Unable to get prompt on Topvision mini CMTS device due to timeout." ) except Exception as e: logger.error( "Something went wrong during CMTS initialisation. See exception below:" ) logger.error(repr(e)) raise e
def __init__(self, *args, **kwargs): """Instance initialization.""" self.args = args self.kwargs = kwargs self.syslog_ip = self.kwargs["ipaddr"] self.syslog_path = self.kwargs.get("syslog_path", "/var/log/BF/") self.username = self.kwargs["username"] self.password = self.kwargs["password"] conn_cmd = 'ssh -o "StrictHostKeyChecking no" %s@%s' % ( self.username, self.syslog_ip, ) self.connection = connection_decider.connection( "local_cmd", device=self, conn_cmd=conn_cmd ) self.connection.connect() self.linesep = "\r" if 0 == self.expect(["assword: "] + self.prompt): self.sendline(self.password) self.expect(self.prompt) # Hide login prints, resume after that's done self.logfile_read = sys.stdout
def connect(self): """This method is used to connect cmts, login to the cmts based on the connection type available :raises Exception: Unable to get prompt on ARRIS device """ self.connection = connection_decider.connection( self.connection_type, device=self, conn_cmd=self.conn_cmd, ssh_password=self.ssh_password, ) self.connection.connect() try: try: self.expect_exact("Escape character is '^]'.", timeout=5) except Exception: pass self.sendline() idx = self.expect(["\r\nLogin:"******"assword:") self.sendline(self.password) self.expect(self.prompt) elif idx > 1: # if we get a prompt we have probably ssh to the device pass else: # Over telnet we come in at the right prompt # over serial we could have a double login # not yet implemented raise Exception("Failed to connect to Arris via telnet") self.sendline("enable") if 0 == self.expect(["Password:"******"config") self.expect( "Enter configuration commands, one per line. End with exit or quit or CTRL Z" ) self.expect(self.prompt) self.sendline("no pagination") self.expect(self.prompt) return except Exception: self.close() self.pid = None raise Exception("Unable to get prompt on Arris device")
def __init__(self, *args, **kwargs): """ Constructor method """ self.args = args self.kwargs = kwargs self.ipaddr = self.kwargs['ipaddr'] self.username = self.kwargs['username'] self.password = self.kwargs['password'] conn_cmd = "ssh -o \"StrictHostKeyChecking no\" %s@%s" % ( self.username, self.ipaddr) self.connection = connection_decider.connection("local_cmd", device=self, conn_cmd=conn_cmd) self.connection.connect() if 0 == self.expect(['Password:'******'s done self.logfile_read = sys.stdout
def __init__(self, *args, **kwargs): """Instance initialization.""" self.args = args self.kwargs = kwargs self.syslog_ip = self.kwargs['ipaddr'] self.syslog_path = self.kwargs.get('syslog_path', '/var/log/BF/') self.username = self.kwargs['username'] self.password = self.kwargs['password'] conn_cmd = "ssh -o \"StrictHostKeyChecking no\" %s@%s" % ( self.username, self.syslog_ip) self.connection = connection_decider.connection("local_cmd", device=self, conn_cmd=conn_cmd) self.connection.connect() self.linesep = '\r' if 0 == self.expect(['assword: '] + self.prompt): self.sendline(self.password) self.expect(self.prompt) # Hide login prints, resume after that's done self.logfile_read = sys.stdout