def configure_secondary_interface(self, args, extra_vars, subnet_cidr): logging.info("[app] Configuring second NIC") self.wait_for_ssh_port(extra_vars["ssh_host"], args.search_pattern, extra_vars["ssh_port"]) subnet_network, subnet_netmask = subnet_cidr.split('/') # Copy and run script to configure routes scp_to_tmp(get_datafile_path('configure_nic.sh'), extra_vars["ssh_host"], extra_vars["ssh_user"], extra_vars["ssh_port"], args.private_key_file) cmd = ("sudo /tmp/configure_nic.sh " "--subnet_network {} --subnet_netmask {} --cloud {}").format( subnet_network, subnet_netmask, self.name) rc, stdout, stderr = remote_exec_command(extra_vars["ssh_host"], extra_vars["ssh_port"], extra_vars["ssh_user"], args.private_key_file, cmd) if rc: raise YBOpsRuntimeError( "Could not configure second nic {} {}".format(stdout, stderr)) # Since this is on start, wait for ssh on default port # Reboot instance remote_exec_command(extra_vars["ssh_host"], extra_vars["ssh_port"], extra_vars["ssh_user"], args.private_key_file, 'sudo reboot') self.wait_for_ssh_port(extra_vars["ssh_host"], args.search_pattern, extra_vars["ssh_port"]) # Verify that the command ran successfully: rc, stdout, stderr = remote_exec_command(extra_vars["ssh_host"], extra_vars["ssh_port"], extra_vars["ssh_user"], args.private_key_file, 'ls /tmp/dhclient-script-*') if rc: raise YBOpsRuntimeError("Second nic not configured at start up")
def callback(self, args): host_info = self.cloud.get_host_info(args) if not host_info: raise YBOpsRuntimeError("Instance: {} does not exist, cannot run preflight checks" .format(args.search_pattern)) results = {} logging.info("Running {} preflight checks for instance: {}".format( args.precheck_type, args.search_pattern)) self.update_ansible_vars_with_args(args) self.update_ansible_vars_with_host_info(host_info, args.custom_ssh_port) try: is_configure = args.precheck_type == "configure" self.wait_for_host(args, default_port=is_configure) except YBOpsRuntimeError as e: logging.info("Failed to connect to node {}: {}".format(args.search_pattern, e)) # No point continuing test if ssh fails. results["SSH Connection"] = False print(json.dumps(results, indent=2)) return scp_result = scp_to_tmp( get_datafile_path('preflight_checks.sh'), self.extra_vars["private_ip"], self.extra_vars["ssh_user"], self.extra_vars["ssh_port"], args.private_key_file) results["SSH Connection"] = scp_result == 0 ansible_status = self.cloud.setup_ansible(args).run("test_connection.yml", self.extra_vars, host_info, print_output=False) results["Try Ansible Command"] = ansible_status == 0 cmd = "/tmp/preflight_checks.sh --type {} --yb_home_dir {} --mount_points {}".format( args.precheck_type, YB_HOME_DIR, self.cloud.get_mount_points_csv(args)) if args.install_node_exporter: cmd += " --install_node_exporter" if args.air_gap: cmd += " --airgap" self.update_ansible_vars_with_args(args) self.update_ansible_vars_with_host_info(host_info, args.custom_ssh_port) rc, stdout, stderr = remote_exec_command( self.extra_vars["private_ip"], self.extra_vars["ssh_port"], self.extra_vars["ssh_user"], args.private_key_file, cmd) if rc != 0: results["Preflight Script Error"] = stderr else: # stdout will be returned as a list of lines, which should just be one line of json. stdout = json.loads(stdout[0]) stdout = {k: v == "true" for k, v in stdout.iteritems()} results.update(stdout) output = json.dumps(results, indent=2) print(output)
def callback(self, args): config = {'devops_home': ybutils.YB_DEVOPS_HOME, 'cloud': self.cloud.name} file_name = 'provision_instance.py.j2' try: config.update(vars(args)) config["yb_home_dir"] = YB_HOME_DIR data_dir = os.path.dirname(get_datafile_path(file_name)) template = Environment(loader=FileSystemLoader(data_dir)).get_template(file_name) with open(os.path.join(args.destination, args.name), 'w') as f: f.write(template.render(config)) os.chmod(f.name, stat.S_IRWXU) print(json.dumps({'script_path': f.name})) except Exception as e: logging.error(e) print(json.dumps({"error": "Unable to create script: {}".format(e.message)}))
def callback(self, args): host_info = self.cloud.get_host_info(args) if not host_info: raise YBOpsRuntimeError( "Instance: {} does not exist, cannot run preflight checks". format(args.search_pattern)) results = {} logging.info("Running {} preflight checks for instance: {}".format( args.precheck_type, args.search_pattern)) self.update_ansible_vars_with_args(args) self.update_ansible_vars_with_host_info(host_info, args.custom_ssh_port) try: is_configure = args.precheck_type == "configure" self.wait_for_host(args, default_port=is_configure) except YBOpsRuntimeError as e: logging.info("Failed to connect to node {}: {}".format( args.search_pattern, e)) # No point continuing test if ssh fails. results["SSH Connection"] = False print(json.dumps(results, indent=2)) return scp_result = scp_to_tmp(get_datafile_path('preflight_checks.sh'), self.extra_vars["private_ip"], self.extra_vars["ssh_user"], self.extra_vars["ssh_port"], args.private_key_file) results["SSH Connection"] = scp_result == 0 ssh_options = { "ssh_user": "******", "ssh_host": self.extra_vars["private_ip"], "ssh_port": self.extra_vars["ssh_port"], "private_key_file": args.private_key_file } if args.root_cert_path is not None: self.verify_certificates("Server", args.root_cert_path, args.server_cert_path, args.server_key_path, ssh_options, args.skip_cert_validation, results) if args.root_cert_path_client_to_server is not None: self.verify_certificates("Server clientRootCA", args.root_cert_path_client_to_server, args.server_cert_path_client_to_server, args.server_key_path_client_to_server, ssh_options, args.skip_cert_validation, results) if args.client_cert_path is not None: root_cert_path = args.root_cert_path_client_to_server \ if args.root_cert_path_client_to_server is not None else args.root_cert_path self.verify_certificates( "Client", root_cert_path, args.client_cert_path, args.client_key_path, ssh_options, 'HOSTNAME', # not checking hostname for that serts results) sudo_pass_file = '/tmp/.yb_sudo_pass.sh' self.extra_vars['sudo_pass_file'] = sudo_pass_file ansible_status = self.cloud.setup_ansible(args).run( "send_sudo_pass.yml", self.extra_vars, host_info, print_output=False) results["Try Ansible Command"] = ansible_status == 0 ports_to_check = ",".join([ str(p) for p in [ args.master_http_port, args.master_rpc_port, args.tserver_http_port, args.tserver_rpc_port, args.cql_proxy_http_port, args.cql_proxy_rpc_port, args.ysql_proxy_http_port, args.ysql_proxy_rpc_port, args.redis_proxy_http_port, args.redis_proxy_rpc_port, args.node_exporter_http_port ] if p is not None ]) cmd = "/tmp/preflight_checks.sh --type {} --yb_home_dir {} --mount_points {} " \ "--ports_to_check {} --sudo_pass_file {} --cleanup".format( args.precheck_type, YB_HOME_DIR, self.cloud.get_mount_points_csv(args), ports_to_check, sudo_pass_file) if args.install_node_exporter: cmd += " --install_node_exporter" if args.air_gap: cmd += " --airgap" self.update_ansible_vars_with_args(args) self.update_ansible_vars_with_host_info(host_info, args.custom_ssh_port) rc, stdout, stderr = remote_exec_command(self.extra_vars["private_ip"], self.extra_vars["ssh_port"], self.extra_vars["ssh_user"], args.private_key_file, cmd) if rc != 0: results["Preflight Script Error"] = stderr else: # stdout will be returned as a list of lines, which should just be one line of json. stdout = json.loads(stdout[0]) stdout = {k: v == "true" for k, v in iteritems(stdout)} results.update(stdout) output = json.dumps(results, indent=2) print(output)