def _get_vsrx_zone_list(self): os.putenv("CLASSPATH", self.classpath); executionList=['java', 'RunConfigurationCommand'] executionList.extend([self.mgmt_ip, self.username, self.password]) command_exec_success = False zone_list=[] try: while not command_exec_success: try: op_list=[] executionList.extend(["show security zones"]) retVal="" retVal = utils.execute(executionList, addl_env=self.addl_env) for line in retVal.splitlines(retVal.count('\n')): if re.search("security-zone", line): line = line.rstrip() op_list=re.split(" ", line) zone=op_list[len(op_list)-2] zone_list.extend([zone]) if "exception" in retVal: command_exec_success = False else: command_exec_success = True except Exception: pass finally: return zone_list
def _get_vsrx_interface_zone(self, interface): zone_list=[] os.putenv("CLASSPATH", self.classpath); executionList=['java', 'RunConfigurationCommand'] executionList.extend([self.mgmt_ip, self.uname, self.password]) command_exec_success = False zone_list = self._get_vsrx_zone_list() for zone in zone_list: command_exec_success = False cmd = "show security zones security-zone " + zone executionList.extend([cmd]) while not command_exec_success: try: op_list=[] retVal="" retVal = utils.execute(executionList, addl_env=self.addl_env) for line in retVal.splitlines(retVal.count('\n')): if re.search(interface, line): return zone command_exec_success = True except Exception: pass del executionList[len(executionList)-1] return ""
def _get_interface_mapping(self): os.putenv("CLASSPATH", self.classpath); executionList=['java', 'RunCliCommand'] executionList.extend([self.mgmt_ip, self.username, self.password]) executionList.extend(["show route terse"]) command_exec_success = False while not command_exec_success: interfaces_dict = dict() try: op_list=[] retVal="" retVal = utils.execute(executionList, addl_env=self.addl_env) for line in retVal.splitlines(retVal.count('\n')): op_list.append(line) for i in range(len(op_list)): iface_dict = dict() if op_list[i] != '\n': op_split = op_list[i].split(" ") if op_split[-4].find('ge') >=0: iface_dict['network'] = op_split[1] new_op = op_list[i+1] new_op_split = new_op.split(" ") iface_dict['ip'] = new_op_split[1] interfaces_dict[op_split[-4][1:]] = iface_dict command_exec_success = True except Exception as e: pass return interfaces_dict
def iproute_arg_supported(command, arg, root_helper=None): command += ['help'] stdout, stderr = utils.execute(command, root_helper=root_helper, check_exit_code=False, return_stderr=True) return any(arg in line for line in stderr.split('\n'))
def _execute(cls, options, command, args, root_helper=None, namespace=None): opt_list = ['-%s' % o for o in options] if namespace: ip_cmd = ['ip', 'netns', 'exec', namespace, 'ip'] else: ip_cmd = ['ip'] return utils.execute(ip_cmd + opt_list + [command] + list(args), root_helper=root_helper)
def _check_connection(self): ssh_connected = False # keep connecting till ssh is success executionList =[] executionList.extend(['sshpass','-p'+self.password,'ssh', '-T', self.uname+'@'+self.mgmt_ip]) while not ssh_connected: try: retVal = utils.execute(executionList) ssh_connected = True except Exception: pass
def executeCommands(self, command): executionList = ['yangcli'] executionList.extend([self.__ip, self.__uname, self.__password, self.__ncport]) executionList.append(command) for i in xrange(0,self.retries): retVal = utils.execute(executionList) if retVal.find("The replace command is not allowed in this mode") == -1: break elif i == self.retries-1: #raise exceptions.DriverException("Unable to connect to server") pass return retVal
def execute(self, cmds, addl_env={}, check_exit_code=True): ns_params = [] if self._parent.namespace: if not self._parent.root_helper: raise exceptions.SudoRequired() ns_params = ['ip', 'netns', 'exec', self._parent.namespace] env_params = [] if addl_env: env_params = (['env'] + ['%s=%s' % pair for pair in addl_env.items()]) return utils.execute(ns_params + env_params + list(cmds), root_helper=self._parent.root_helper, check_exit_code=check_exit_code)
def execute(self, cmds, addl_env={}, check_exit_code=True): ns_params = [] if self._parent.namespace: if not self._parent.root_helper: raise exceptions.SudoRequired() ns_params = ['ip', 'netns', 'exec', self._parent.namespace] env_params = [] if addl_env: env_params = (['env'] + ['%s=%s' % pair for pair in addl_env.items()]) return utils.execute( ns_params + env_params + list(cmds), root_helper=self._parent.root_helper, check_exit_code=check_exit_code)
def executeCommands(self, commands_list): os.putenv("CLASSPATH", self.classpath); executionList=['java', 'RunConfigurationCommand'] executionList.extend([self.mgmt_ip, self.username, self.password]) for command in commands_list: executionList.append(command); execute=False while not execute: try: retVal = utils.execute(executionList, addl_env=self.addl_env) execute=True except Exception: pass return retVal
def _get_vsrx_interface_name(self, network): os.putenv("CLASSPATH", self.classpath); executionList=['java', 'RunCliCommand'] executionList.extend([self.mgmt_ip, self.uname, self.password]) executionList.extend(["show route terse"]) command_exec_success = False while not command_exec_success: try: op_list=[] retVal="" retVal = utils.execute(executionList, addl_env=self.addl_env) for line in retVal.splitlines(retVal.count('\n')): if re.search(network, line): line = line.rstrip() op_list=re.split(" ", line) iface=op_list[len(op_list)-1].replace(">", "") return iface command_exec_success = True except Exception: pass return ""