本文整理汇总了Python中tcutils.commands.ssh函数的典型用法代码示例。如果您正苦于以下问题:Python ssh函数的具体用法?Python ssh怎么用?Python ssh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ssh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tcpdump_stop_on_all_compute
def tcpdump_stop_on_all_compute(self):
sessions = {}
for compute_ip in self.inputs.compute_ips:
compute_user = self.inputs.host_data[compute_ip]['username']
compute_password = self.inputs.host_data[compute_ip]['password']
session = ssh(compute_ip, compute_user, compute_password)
self.stop_tcpdump(session)
示例2: stop_tcpdump_on_intf
def stop_tcpdump_on_intf(self, host, tapintf):
session = ssh(host["host_ip"], host["username"], host["password"])
self.logger.info("Waiting for tcpdump to complete")
time.sleep(20)
output_cmd = "cat /tmp/%s_out.log" % tapintf
out, err = execute_cmd_out(session, output_cmd, self.logger)
return out
示例3: tcpdump_start_on_all_compute
def tcpdump_start_on_all_compute(self):
for compute_ip in self.inputs.compute_ips:
compute_user = self.inputs.host_data[compute_ip]['username']
compute_password = self.inputs.host_data[compute_ip]['password']
session = ssh(compute_ip, compute_user, compute_password)
self.stop_tcpdump(session)
inspect_h = self.agent_inspect[compute_ip]
comp_intf = inspect_h.get_vna_interface_by_type('eth')
if len(comp_intf) == 1:
comp_intf = comp_intf[0]
self.logger.info('Agent interface name: %s' % comp_intf)
pcap1 = '/tmp/encap-udp.pcap'
pcap2 = '/tmp/encap-gre.pcap'
pcap3 = '/tmp/encap-vxlan.pcap'
cmd1 = 'tcpdump -ni %s udp port 51234 -w %s -s 0' % (
comp_intf, pcap1)
cmd_udp = "nohup " + cmd1 + " >& /dev/null < /dev/null &"
cmd2 = 'tcpdump -ni %s proto 47 -w %s -s 0' % (comp_intf, pcap2)
cmd_gre = "nohup " + cmd2 + " >& /dev/null < /dev/null &"
cmd3 = 'tcpdump -ni %s dst port 4789 -w %s -s 0' % (
comp_intf, pcap3)
cmd_vxlan = "nohup " + cmd3 + " >& /dev/null < /dev/null &"
self.start_tcpdump(session, cmd_udp)
self.start_tcpdump(session, cmd_gre)
self.start_tcpdump(session, cmd_vxlan)
示例4: verify_vrrp_action
def verify_vrrp_action(self, src_vm, dst_vm, ip, vsrx=False):
result = False
self.logger.info('Will ping %s from %s and check if %s responds' % (
ip, src_vm.vm_name, dst_vm.vm_name))
compute_ip = dst_vm.vm_node_ip
compute_user = self.inputs.host_data[compute_ip]['username']
compute_password = self.inputs.host_data[compute_ip]['password']
session = ssh(compute_ip, compute_user, compute_password)
if vsrx:
vm_tapintf = dst_vm.tap_intf[dst_vm.vn_fq_names[1]]['name']
else:
vm_tapintf = dst_vm.tap_intf[dst_vm.vn_fq_name]['name']
cmd = 'tcpdump -nni %s -c 10 > /tmp/%s_out.log' % (
vm_tapintf, vm_tapintf)
execute_cmd(session, cmd, self.logger)
assert src_vm.ping_with_certainty(ip), 'Ping to vIP failure'
output_cmd = 'cat /tmp/%s_out.log' % vm_tapintf
output, err = execute_cmd_out(session, output_cmd, self.logger)
if ip in output:
result = True
self.logger.info(
'%s is seen responding to ICMP Requests' % dst_vm.vm_name)
else:
self.logger.error('ICMP Requests not seen on the VRRP Master')
result = False
return result
示例5: set_cpu_performance
def set_cpu_performance(self, hosts):
sessions = {}
cmd = 'for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do echo performance > $f; cat $f; done'
for i in range(0, 2):
session = ssh(hosts[i]['host_ip'], hosts[i]['username'], hosts[i]['password'])
execute_cmd(session, cmd, self.logger)
return
示例6: start_tcpdump
def start_tcpdump(self, server_ip, tap_intf):
session = ssh(server_ip,self.inputs.host_data[server_ip]['username'],self.inputs.host_data[server_ip]['password'])
pcap = '/tmp/%s.pcap' % tap_intf
cmd = "tcpdump -nei %s tcp -w %s" % (tap_intf, pcap)
self.logger.info("Staring tcpdump to capture the packets on server %s" % (server_ip))
execute_cmd(session, cmd, self.logger)
return pcap, session
示例7: verify_mirroring
def verify_mirroring(self, si_fix, src_vm, dst_vm, mirr_vm=None):
result = True
if mirr_vm:
svm = mirr_vm.vm_obj
else:
svms = self.get_svms_in_si(si_fix)
svm = svms[0]
if svm.status == 'ACTIVE':
svm_name = svm.name
host = self.get_svm_compute(svm_name)
if mirr_vm:
tapintf = self.get_svm_tapintf(svm_name)
else:
tapintf = self.get_bridge_svm_tapintf(svm_name, 'left')
session = ssh(host['host_ip'], host['username'], host['password'])
cmd = 'sudo tcpdump -nni %s -c 5 > /tmp/%s_out.log' % (tapintf, tapintf)
execute_cmd(session, cmd, self.logger)
assert src_vm.ping_with_certainty(dst_vm.vm_ip)
sleep(10)
output_cmd = 'sudo cat /tmp/%s_out.log' % tapintf
out, err = execute_cmd_out(session, output_cmd, self.logger)
print out
if '8099' in out:
self.logger.info('Mirroring action verified')
else:
result = False
self.logger.warning('No mirroring action seen')
return result
示例8: start_tcpdump_for_intf
def start_tcpdump_for_intf(ip, username, password, interface, filters='-v', logger=None):
if not logger:
logger = logging.getLogger(__name__)
session = ssh(ip, username, password)
pcap = '/tmp/%s_%s.pcap' % (interface, get_random_name())
cmd = 'tcpdump -ni %s -U %s -w %s' % (interface, filters, pcap)
execute_cmd(session, cmd, logger)
return (session, pcap)
示例9: config_intf_mirroring
def config_intf_mirroring(self, src_vm_fixture, analyzer_ip_address, analyzer_name, routing_instance, \
src_port=None, sub_intf=False, parent_intf=False, nic_mirror=False, header = 1, nh_mode = 'dynamic', direction = 'both', analyzer_mac_address = '', mirror_vm_fixture = None):
#Short desc of what the header values are:
#header 1 is the default value, which is header enabled. All present testcases will have this as default, should not affect legacy cases
#header 2 is for dynamic mirroring, with juniper header, and directionality of traffic and want the header verification to be done
#header 3 would mean header disabled. In this case, routes have to be imported from other VN vrf, so a change vn properties is needed
if header == 3:
self.add_vn_mirror_properties()
analyzer_mac_address = mirror_vm_fixture.mac_addr[self.vn3_fixture.vn_fq_name]
vnc = src_vm_fixture.vnc_lib_h
vlan = None
tap_intf_obj = None
parent_tap_intf_obj = None
vlan = None
tap_intf_objs = src_vm_fixture.get_tap_intf_of_vm()
for tap_intf_obj in tap_intf_objs:
if 'tap' in tap_intf_obj['name']:
parent_tap_intf_uuid = tap_intf_obj['uuid']
else:
sub_intf_tap_intf_uuid = tap_intf_obj['uuid']
if not sub_intf:
tap_intf_uuid = src_vm_fixture.get_tap_intf_of_vm()[0]['uuid']
tap_intf_obj = vnc.virtual_machine_interface_read(id=tap_intf_uuid)
else:
tap_intf_obj = src_port
vlan = self.vlan
if parent_intf:
parent_tap_intf_obj = vnc.virtual_machine_interface_read(id=parent_tap_intf_uuid)
if header == 1 or header == 2:
header_value = True
else:
header_value = False
if not nic_mirror:
self.enable_intf_mirroring(vnc, tap_intf_obj, analyzer_ip_address, analyzer_name, routing_instance, header = header_value, nh_mode = nh_mode, direction = direction, analyzer_mac_address = analyzer_mac_address)
if parent_intf:
self.logger.info("Intf mirroring enabled on both sub intf port and parent port")
self.enable_intf_mirroring(vnc, parent_tap_intf_obj, analyzer_ip_address, analyzer_name, routing_instance, header = header_value, nh_mode = nh_mode, direction = direction, analyzer_mac_address = analyzer_mac_address)
return vnc, tap_intf_obj, parent_tap_intf_obj, vlan
else:
self.enable_intf_mirroring(vnc, tap_intf_obj, analyzer_ip_address=None, analyzer_name=analyzer_name, \
routing_instance=None, udp_port=None, nic_assisted_mirroring=True, nic_assisted_mirroring_vlan=100, header = header_value, nh_mode = nh_mode, direction = direction, analyzer_mac_address = analyzer_mac_address)
if src_vm_fixture.vm_obj.status == 'ACTIVE':
host = self.get_svm_compute(src_vm_fixture.vm_obj.name)
session = ssh(host['host_ip'], host['username'], host['password'])
agent_physical_interface = src_vm_fixture.agent_inspect[host['host_ip']].get_agent_physical_interface()
pcap = self.start_tcpdump(session, agent_physical_interface, vlan=100)
src_vm_fixture.ping_with_certainty(mirror_vm_fixture.vm_ip, count=11, size='1400')
filt = '-e | grep \"vlan 100\"'
mirror_pkt_count = self.stop_tcpdump(session, pcap, filt)
if mirror_pkt_count == 0:
self.logger.error("Nic mirroring doesn't works correctly")
result = result and False
else:
self.logger.info("Nic mirroring works correctly")
示例10: tcpdump_on_analyzer
def tcpdump_on_analyzer(self, si_prefix):
sessions = {}
svm_name = si_prefix + '_1'
host = self.get_svm_compute(svm_name)
tapintf = self.get_svm_tapintf(svm_name)
session = ssh(host['host_ip'], host['username'], host['password'])
pcap = self.start_tcpdump(session, tapintf)
sessions.update({svm_name: (session, pcap)})
return sessions
示例11: tcpdump_on_all_analyzer
def tcpdump_on_all_analyzer(self, si_prefix, si_count=1):
sessions = {}
for i in range(0, si_count):
svm_name = si_prefix + str(i + 1) + '_1'
host = self.get_svm_compute(svm_name)
tapintf = self.get_svm_tapintf(svm_name)
session = ssh(host['host_ip'], host['username'], host['password'])
pcap = self.start_tcpdump(session, tapintf)
sessions.update({svm_name: (session, pcap)})
return sessions
示例12: start_tcpdump_for_vm_intf
def start_tcpdump_for_vm_intf(obj, vm_fix, vn_fq_name, filters='-v'):
compute_ip = vm_fix.vm_node_ip
compute_user = obj.inputs.host_data[compute_ip]['username']
compute_password = obj.inputs.host_data[compute_ip]['password']
session = ssh(compute_ip, compute_user, compute_password)
vm_tapintf = vm_fix.tap_intf[vn_fq_name]['name']
pcap = '/tmp/%s_%s.pcap' % (vm_tapintf, get_random_name())
cmd = 'tcpdump -ni %s -U %s -w %s' % (vm_tapintf, filters, pcap)
execute_cmd(session, cmd, obj.logger)
return (session, pcap)
示例13: tcpdump_on_all_analyzer
def tcpdump_on_all_analyzer(self, si_fixtures, si_prefix, si_count=1):
sessions = {}
for i in range(0, si_count):
si_fixture = si_fixtures[i]
svm_name = "__".join(si_fixture.si_fq_name) + "__" + str(1)
host = self.get_svm_compute(svm_name)
tapintf = self.get_svm_tapintf(svm_name)
session = ssh(host['host_ip'], host['username'], host['password'])
pcap = self.start_tcpdump(session, tapintf)
sessions.update({svm_name: (session, pcap)})
return sessions
示例14: verify_port_mirroring
def verify_port_mirroring(self, src_vm, dst_vm, mirr_vm, vlan=None, parent=False, direction = 'both', no_header = False):
result = True
svm = mirr_vm.vm_obj
if svm.status == 'ACTIVE':
svm_name = svm.name
host = self.get_svm_compute(svm_name)
tapintf = self.get_svm_tapintf(svm_name)
# Intf mirroring enabled on either sub intf or parent port
exp_count = 10
if direction != 'both':
exp_count = 5
if parent:
# Intf mirroring enabled on both sub intf and parent port
exp_count = 20
if self.inputs.pcap_on_vm:
filters = ''
if not no_header:
filters='udp port 8099'
vm_fix_pcap_pid_files = start_tcpdump_for_vm_intf(
None, [mirr_vm], None, filters=filters, pcap_on_vm=True)
else:
session = ssh(host['host_ip'], host['username'], host['password'])
pcap = self.start_tcpdump(session, tapintf, vlan=vlan, no_header = no_header)
src_ip = src_vm.vm_ip
dst_ip = dst_vm.vm_ip
if vlan:
sub_intf = 'eth0.' + str(vlan)
cmds = "/sbin/ifconfig " + sub_intf + " | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'"
src_ip = src_vm.run_cmd_on_vm(cmds=[cmds]).values()[0]
dst_ip = dst_vm.run_cmd_on_vm(cmds=[cmds]).values()[0]
assert src_vm.ping_with_certainty(dst_ip, count=5, size='1200')
#lets wait 10 sec for tcpdump to capture all the packets
sleep(10)
self.logger.info('Ping from %s to %s executed with c=5, expected mirrored packets 5 Ingress,5 Egress count = 10'
% (src_ip, dst_ip))
filters = '| grep \"length [1-9][2-9][0-9][0-9][0-9]*\"'
if self.inputs.pcap_on_vm:
output, mirror_pkt_count = stop_tcpdump_for_vm_intf(
None, None, None, vm_fix_pcap_pid_files=vm_fix_pcap_pid_files, filters=filters, verify_on_all=True)
mirror_pkt_count = int(mirror_pkt_count[0])
else:
mirror_pkt_count = self.stop_tcpdump(session, pcap, filters)
errmsg = "%s ICMP Packets mirrored to the analyzer VM %s,"\
"Expected %s packets" % (
mirror_pkt_count, svm_name, exp_count)
if mirror_pkt_count < exp_count:
self.logger.error(errmsg)
assert False, errmsg
self.logger.info("%s ICMP packets are mirrored to the analyzer "
"service VM '%s'", mirror_pkt_count, svm_name)
return result
示例15: tcpdump_on_all_analyzer
def tcpdump_on_all_analyzer(self, si_fixtures, si_prefix, si_count=1):
sessions = {}
for i in range(0, si_count):
si_fixture = si_fixtures[i]
svm_name = si_fixture.si_obj.uuid + '__' + str(i + 1)
svm_name=self.inputs.domain_name + '__' + self.inputs.project_name + '__' + svm_name
host = self.get_svm_compute(svm_name)
tapintf = self.get_svm_tapintf(svm_name)
session = ssh(host['host_ip'], host['username'], host['password'])
pcap = self.start_tcpdump(session, tapintf)
sessions.update({svm_name: (session, pcap)})
return sessions