def _start_servers(self): """Start two hardcoded named servers: server1 & server2 1. SSH to the instance 2. Start two http backends listening on ports 80 and 88 respectively """ for server_id, ip in self.server_ips.iteritems(): private_key = self.servers_keypairs[server_id]['private_key'] # server = self.servers_client.show_server(server_id)['server'] # server['name'] is not 'server1' as 2015-12 due to upstream change # server_name = server['name'] username = CONF.validation.image_ssh_user ssh_client = self.get_remote_client( server_or_ip=ip, private_key=private_key) # Write a backend's response into a file resp = ('echo -ne "HTTP/1.1 200 OK\r\nContent-Length: 7\r\n' 'Connection: close\r\nContent-Type: text/html; ' 'charset=UTF-8\r\n\r\n%s"; cat >/dev/null') with tempfile.NamedTemporaryFile() as script: script.write(resp % 'server1') script.flush() with tempfile.NamedTemporaryFile() as key: key.write(private_key) key.flush() commands.copy_file_to_host(script.name, "/tmp/script1", ip, username, key.name) # Start netcat start_server = ('while true; do ' 'sudo nc -ll -p %(port)s -e sh /tmp/%(script)s; ' 'done > /dev/null &') cmd = start_server % {'port': self.port1, 'script': 'script1'} ssh_client.exec_command(cmd, False) if len(self.server_ips) == 1: with tempfile.NamedTemporaryFile() as script: script.write(resp % 'server2') script.flush() with tempfile.NamedTemporaryFile() as key: key.write(private_key) key.flush() commands.copy_file_to_host(script.name, "/tmp/script2", ip, username, key.name) cmd = start_server % {'port': self.port2, 'script': 'script2'} ssh_client.exec_command(cmd, False)
def _start_servers(self): """ Start two backends 1. SSH to the instance 2. Start two http backends listening on ports 80 and 88 respectively """ for server_id, ip in self.server_ips.iteritems(): private_key = self.servers_keypairs[server_id].private_key server_name = self.compute_client.servers.get(server_id).name username = config.scenario.ssh_user ssh_client = self.get_remote_client( server_or_ip=ip, private_key=private_key) # Write a backend's responce into a file resp = """echo -ne "HTTP/1.1 200 OK\r\nContent-Length: 7\r\n""" \ """Connection: close\r\nContent-Type: text/html; """ \ """charset=UTF-8\r\n\r\n%s"; cat >/dev/null""" with tempfile.NamedTemporaryFile() as script: script.write(resp % server_name) script.flush() with tempfile.NamedTemporaryFile() as key: key.write(private_key) key.flush() commands.copy_file_to_host(script.name, "/tmp/script1", ip, username, key.name) # Start netcat start_server = """sudo nc -ll -p %(port)s -e sh """ \ """/tmp/%(script)s &""" cmd = start_server % {'port': self.port1, 'script': 'script1'} ssh_client.exec_command(cmd) if len(self.server_ips) == 1: with tempfile.NamedTemporaryFile() as script: script.write(resp % 'server2') script.flush() with tempfile.NamedTemporaryFile() as key: key.write(private_key) key.flush() commands.copy_file_to_host(script.name, "/tmp/script2", ip, username, key.name) cmd = start_server % {'port': self.port2, 'script': 'script2'} ssh_client.exec_command(cmd)
def _start_servers(self): """ Start two backends 1. SSH to the instance 2. Start two http backends listening on ports 80 and 88 respectively """ for server_id, ip in self.server_ips.iteritems(): private_key = self.servers_keypairs[server_id]['private_key'] server_name = self.servers_client.get_server(server_id)[1]['name'] username = config.scenario.ssh_user ssh_client = self.get_remote_client( server_or_ip=ip, private_key=private_key) # Write a backend's response into a file resp = ('echo -ne "HTTP/1.1 200 OK\r\nContent-Length: 7\r\n' 'Connection: close\r\nContent-Type: text/html; ' 'charset=UTF-8\r\n\r\n%s"; cat >/dev/null') with tempfile.NamedTemporaryFile() as script: script.write(resp % server_name) script.flush() with tempfile.NamedTemporaryFile() as key: key.write(private_key) key.flush() commands.copy_file_to_host(script.name, "/tmp/script1", ip, username, key.name) # Start netcat start_server = ('while true; do ' 'sudo nc -l -p %(port)s -e sh /tmp/%(script)s; ' 'done &') cmd = start_server % {'port': self.port1, 'script': 'script1'} ssh_client.exec_command(cmd) if len(self.server_ips) == 1: with tempfile.NamedTemporaryFile() as script: script.write(resp % 'server2') script.flush() with tempfile.NamedTemporaryFile() as key: key.write(private_key) key.flush() commands.copy_file_to_host(script.name, "/tmp/script2", ip, username, key.name) cmd = start_server % {'port': self.port2, 'script': 'script2'} ssh_client.exec_command(cmd)
def _start_servers(self): """ Start two backends 1. SSH to the instance 2. Start two http backends listening on ports 80 and 88 respectively """ for server_id, ip in self.server_ips.iteritems(): private_key = self.servers_keypairs[server_id].private_key server_name = self.compute_client.servers.get(server_id).name username = config.scenario.ssh_user ssh_client = self.get_remote_client(server_or_ip=ip, private_key=private_key) ssh_client.validate_authentication() # Write a backend's responce into a file resp = """HTTP/1.0 200 OK\r\nContent-Length: 8\r\n\r\n%s""" with tempfile.NamedTemporaryFile() as script: script.write(resp % server_name) script.flush() with tempfile.NamedTemporaryFile() as key: key.write(private_key) key.flush() commands.copy_file_to_host(script.name, "~/script1", ip, username, key.name) # Start netcat start_server = """sudo nc -ll -p %(port)s -e cat """ \ """~/%(script)s &""" cmd = start_server % {'port': self.port1, 'script': 'script1'} ssh_client.exec_command(cmd) if len(self.server_ips) == 1: with tempfile.NamedTemporaryFile() as script: script.write(resp % 'server2') script.flush() with tempfile.NamedTemporaryFile() as key: key.write(private_key) key.flush() commands.copy_file_to_host(script.name, "~/script2", ip, username, key.name) cmd = start_server % {'port': self.port2, 'script': 'script2'} ssh_client.exec_command(cmd)