Exemple #1
0
    def callback(self, args):
        host_info = self.cloud.get_host_info(args)
        if host_info:
            if not args.reuse_host:
                raise YBOpsRuntimeError("Found host {} but was asked to not reuse host!".format(
                    args.search_pattern))
            else:
                logging.info("Host {} already created.".format(args.search_pattern))
        elif args.search_pattern != 'localhost':
            self.create_method.callback(args)
            host_info = self.cloud.get_host_info(args)
        self.update_ansible_vars_with_args(args)

        if host_info:
            self.extra_vars.update(get_ssh_host_port(host_info, args.custom_ssh_port))
        if args.local_package_path:
            self.extra_vars.update({"local_package_path": args.local_package_path})
        if args.air_gap:
            self.extra_vars.update({"air_gap": args.air_gap})
        if args.node_exporter_port:
            self.extra_vars.update({"node_exporter_port": args.node_exporter_port})
        if args.install_node_exporter:
            self.extra_vars.update({"install_node_exporter": args.install_node_exporter})
        self.extra_vars.update({"instance_type": args.instance_type})
        self.extra_vars["device_names"] = self.cloud.get_device_names(args)
        self.cloud.setup_ansible(args).run("yb-server-provision.yml", self.extra_vars, host_info)
Exemple #2
0
    def callback(self, args):
        logging.debug("Received args {}".format(args))

        host_infos = self.cloud.get_host_info(args, get_all=args.as_json)
        if not host_infos:
            return None

        if 'server_type' in host_infos and host_infos['server_type'] is None:
            del host_infos['server_type']

        if args.mount_points:
            for host_info in host_infos:
                try:
                    ssh_options = {
                        "ssh_user": host_info['ssh_user'],
                        "private_key_file": args.private_key_file
                    }
                    ssh_options.update(
                        get_ssh_host_port(self.cloud.get_host_info(args),
                                          args.custom_ssh_port))
                    host_info['mount_roots'] = get_mount_roots(
                        ssh_options, args.mount_points)

                except Exception as e:
                    logging.info(
                        "Error {} locating mount root for host '{}', ignoring."
                        .format(str(e), host_info))
                    continue

        if args.as_json:
            print(json.dumps(host_infos))
        else:
            print('\n'.join(
                ["{}={}".format(k, v) for k, v in iteritems(host_infos)]))
Exemple #3
0
 def wait_for_host(self, args, default_port=True):
     logging.info("Waiting for instance {}".format(args.search_pattern))
     host_lookup_count = 0
     # Cache the result of the cloud call outside of the loop.
     host_info = None
     while True:
         host_lookup_count += 1
         if not host_info:
             host_info = self.cloud.get_host_info(args)
         if host_info:
             self.extra_vars.update(
                 get_ssh_host_port(host_info,
                                   args.custom_ssh_port,
                                   default_port=default_port))
             if wait_for_ssh(self.extra_vars["ssh_host"],
                             self.extra_vars["ssh_port"],
                             self.extra_vars["ssh_user"],
                             args.private_key_file):
                 return host_info
         sys.stdout.write('.')
         sys.stdout.flush()
         time.sleep(1)
         if host_lookup_count > self.INSTANCE_LOOKUP_RETRY_LIMIT:
             raise YBOpsRuntimeError(
                 "Timed out waiting for instance: '{0}'".format(
                     args.search_pattern))
Exemple #4
0
    def run_control_script(self, process, command, args, extra_vars,
                           host_info):
        updated_vars = {"process": process, "command": command}
        updated_vars.update(extra_vars)
        updated_vars.update(get_ssh_host_port(host_info, args.custom_ssh_port))
        remote_shell = RemoteShell(updated_vars)

        if process == "thirdparty" or process == "platform-services":
            self.setup_ansible(args).run("yb-server-ctl.yml", updated_vars,
                                         host_info)
            return

        if args.systemd_services:
            if command == "start":
                remote_shell.run_command(
                    "sudo systemctl enable yb-{}".format(process))
            remote_shell.run_command("sudo systemctl {} yb-{}".format(
                command, process))
            if command == "stop":
                remote_shell.run_command(
                    "sudo systemctl disable yb-{}".format(process))
            return

        if os.environ.get("YB_USE_FABRIC", False):
            file_path = os.path.join(YB_HOME_DIR, "bin/yb-server-ctl.sh")
            remote_shell.run_command("{} {} {}".format(file_path, process,
                                                       command))
        else:
            self.setup_ansible(args).run("yb-server-ctl.yml", updated_vars,
                                         host_info)
Exemple #5
0
 def callback(self, args):
     """args.search_pattern should be a private ip address for the device for OnPrem.
     """
     self.extra_vars.update(
         get_ssh_host_port({"private_ip": args.search_pattern}))
     print validate_instance(self.extra_vars["ssh_host"],
                             self.extra_vars["ssh_port"], self.SSH_USER,
                             args.private_key_file,
                             self.mount_points.split(','))
Exemple #6
0
 def callback(self, args):
     self.cloud.update_disk(args)
     host_info = self.cloud.get_host_info(args)
     ssh_options = {
         # TODO: replace with args.ssh_user when it's setup in the flow
         "ssh_user": self.SSH_USER,
         "private_key_file": args.private_key_file
     }
     ssh_options.update(get_ssh_host_port(host_info, args.custom_ssh_port))
     self.cloud.expand_file_system(args, ssh_options)
Exemple #7
0
 def callback(self, args):
     host_info = self.cloud.get_host_info(args)
     ssh_options = {
         "ssh_user": self.get_ssh_user(),
         "private_key_file": args.private_key_file
     }
     ssh_options.update(get_ssh_host_port(host_info, args.custom_ssh_port))
     if not validate_cron_status(
             ssh_options['ssh_host'], ssh_options['ssh_port'], ssh_options['ssh_user'],
             ssh_options['private_key_file']):
         raise YBOpsRuntimeError(
             'Failed to find cronjobs on host {}'.format(ssh_options['ssh_host']))
Exemple #8
0
 def callback(self, args):
     ssh_options = {
         # TODO: replace with args.ssh_user when it's setup in the flow
         "ssh_user": "******",
         "private_key_file": args.private_key_file
     }
     host_info = self.cloud.get_host_info(args)
     if not host_info:
         raise YBOpsRuntimeError("Instance: {} does not exists, cannot call initysql".format(
                                 args.search_pattern))
     ssh_options.update(get_ssh_host_port(host_info, args.custom_ssh_port))
     logging.info("Initializing YSQL on Instance: {}".format(args.search_pattern))
     self.cloud.initYSQL(args.master_addresses, ssh_options)
Exemple #9
0
 def update_ansible_vars_with_host_info(self, host_info, custom_ssh_port):
     """Hook for subclasses to update Ansible extra-vars with host specifics before calling out.
     """
     self.extra_vars.update({
         "private_ip": host_info["private_ip"],
         "public_ip": host_info["public_ip"],
         "placement_cloud": self.cloud.name,
         "placement_region": host_info["region"],
         "placement_zone": host_info["zone"],
         "instance_name": host_info["name"],
         "instance_type": host_info["instance_type"]
     })
     self.extra_vars.update(get_ssh_host_port(host_info, custom_ssh_port))
Exemple #10
0
 def run_control_script(self, process, command, args, extra_vars,
                        host_info):
     updated_vars = {"process": process, "command": command}
     updated_vars.update(extra_vars)
     updated_vars.update(get_ssh_host_port(host_info, args.custom_ssh_port))
     if os.environ.get("YB_USE_FABRIC", False):
         remote_shell = RemoteShell(updated_vars)
         file_path = os.path.join(YB_HOME_DIR, "bin/yb-server-ctl.sh")
         remote_shell.run_command("{} {} {}".format(file_path, process,
                                                    command))
     else:
         self.setup_ansible(args).run("yb-server-ctl.yml", updated_vars,
                                      host_info)
Exemple #11
0
 def wait_for_host(self, args, default_port=True):
     logging.info("Waiting for instance {}".format(args.search_pattern))
     host_info = self.cloud.get_host_info(args)
     if host_info:
         self.extra_vars.update(
             get_ssh_host_port(host_info, args.custom_ssh_port, default_port=default_port))
         if wait_for_ssh(self.extra_vars["ssh_host"],
                         self.extra_vars["ssh_port"],
                         self.extra_vars["ssh_user"],
                         args.private_key_file):
             return host_info
     else:
         raise YBOpsRuntimeError("Unable to find host info.")
Exemple #12
0
 def wait_for_host(self, args, default_port=True):
     logging.info("Waiting for instance {}".format(args.search_pattern))
     host_info = self.cloud.get_host_info(args)
     if host_info:
         self.extra_vars.update(
             get_ssh_host_port(host_info, args.custom_ssh_port))
         # Expect onprem nodes to already exist.
         if wait_for_ssh(self.extra_vars["ssh_host"],
                         self.extra_vars["ssh_port"],
                         self.extra_vars["ssh_user"],
                         args.private_key_file,
                         num_retries=SSH_RETRY_LIMIT_PRECHECK):
             return host_info
     else:
         raise YBOpsRuntimeError("Unable to find host info.")
Exemple #13
0
 def run_control_script(self, process, command, args, extra_vars,
                        host_info):
     updated_vars = {"process": process, "command": command}
     updated_vars.update(extra_vars)
     updated_vars.update(get_ssh_host_port(host_info))
     if os.environ.get("YB_USE_FABRIC", False):
         remote_shell = RemoteShell(updated_vars)
         ssh_user = updated_vars.get("ssh_user")
         # TODO: change the home directory from being hard coded into a param passed in.
         remote_shell.run_command(
             "/home/yugabyte/bin/yb-server-ctl.sh {} {}".format(
                 process, command))
     else:
         self.setup_ansible(args).run("yb-server-ctl.yml", updated_vars,
                                      host_info)
Exemple #14
0
    def run_control_script(self, process, command, args, extra_vars, host_info):
        updated_vars = {
            "process": process,
            "command": command
        }
        updated_vars.update(extra_vars)
        updated_vars.update(get_ssh_host_port(host_info, args.custom_ssh_port))
        remote_shell = RemoteShell(updated_vars)
        if args.num_volumes:
            volume_cnt = remote_shell.run_command(
                "df | awk '{{print $6}}' | egrep '^{}[0-9]+' | wc -l".format(
                    AbstractCloud.MOUNT_PATH_PREFIX
                )
            )
            if int(volume_cnt.stdout) < int(args.num_volumes):
                raise YBOpsRuntimeError(
                    "Not all data volumes attached: needed {} found {}".format(
                        args.num_volumes, volume_cnt.stdout
                    )
                )

        if process == "thirdparty" or process == "platform-services":
            self.setup_ansible(args).run("yb-server-ctl.yml", updated_vars, host_info)
            return

        if args.systemd_services:
            if command == "start":
                remote_shell.run_command(
                    "sudo systemctl enable yb-{}".format(process)
                )
            remote_shell.run_command(
                "sudo systemctl {} yb-{}".format(command, process)
            )
            if command == "stop":
                remote_shell.run_command(
                    "sudo systemctl disable yb-{}".format(process)
                )
            return

        if os.environ.get("YB_USE_FABRIC", False):
            file_path = os.path.join(YB_HOME_DIR, "bin/yb-server-ctl.sh")
            remote_shell.run_command(
                "{} {} {}".format(file_path, process, command)
            )
        else:
            self.setup_ansible(args).run("yb-server-ctl.yml", updated_vars, host_info)
Exemple #15
0
    def callback(self, args):
        if args.type == self.YB_SERVER_TYPE:
            if args.master_addresses_for_tserver is None:
                raise YBOpsRuntimeError("Missing argument for YugaByte configure")
            self.extra_vars.update({
                "instance_name": args.search_pattern,
                "master_addresses_for_tserver": args.master_addresses_for_tserver,
                "master_http_port": args.master_http_port,
                "master_rpc_port": args.master_rpc_port,
                "tserver_http_port": args.tserver_http_port,
                "tserver_rpc_port": args.tserver_rpc_port,
                "cql_proxy_rpc_port": args.cql_proxy_rpc_port,
                "redis_proxy_rpc_port": args.redis_proxy_rpc_port,
                "cert_valid_duration": args.cert_valid_duration,
                "org_name": args.org_name,
                "certs_node_dir": args.certs_node_dir,
                "encryption_key_dir": args.encryption_key_target_dir
            })

            if args.master_addresses_for_master is not None:
                self.extra_vars["master_addresses_for_master"] = args.master_addresses_for_master

            if args.server_broadcast_addresses is not None:
                self.extra_vars["server_broadcast_addresses"] = args.server_broadcast_addresses

            if args.yb_process_type:
                self.extra_vars["yb_process_type"] = args.yb_process_type.lower()
        else:
            raise YBOpsRuntimeError("Supported types for this command are only: {}".format(
                self.supported_types))

        # Make sure we set server_type so we pick the right configure.
        self.update_ansible_vars_with_args(args)

        if args.gflags is not None:
            if args.package:
                raise YBOpsRuntimeError("When changing gflags, do not set packages info.")
            self.extra_vars["gflags"] = json.loads(args.gflags)

        if args.package is not None:
            self.extra_vars["package"] = args.package

        if args.extra_gflags is not None:
            self.extra_vars["extra_gflags"] = json.loads(args.extra_gflags)

        if args.gflags_to_remove is not None:
            self.extra_vars["gflags_to_remove"] = json.loads(args.gflags_to_remove)

        if args.rootCA_cert is not None:
            self.extra_vars["rootCA_cert"] = args.rootCA_cert

        if args.rootCA_key is not None:
            self.extra_vars["rootCA_key"] = args.rootCA_key

        if args.client_cert is not None:
            self.extra_vars["client_cert"] = args.client_cert

        if args.client_key is not None:
            self.extra_vars["client_key"] = args.client_key

        host_info = None
        if args.search_pattern != 'localhost':
            host_info = self.cloud.get_host_info(args)
            if not host_info:
                raise YBOpsRuntimeError("Instance: {} does not exists, cannot configure"
                                        .format(args.search_pattern))

            if host_info['server_type'] != args.type:
                raise YBOpsRuntimeError("Instance: {} is of type {}, not {}, cannot configure"
                                        .format(args.search_pattern,
                                                host_info['server_type'],
                                                args.type))
            self.update_ansible_vars_with_host_info(host_info, args.custom_ssh_port)
            # If we have a package, then manually copy it over using scp instead of going over
            # ansible, so we do not have issues such as ENG-3424.
            # Python based paramiko seemed to have the same problems as ansible copy module!
            #
            # NOTE: we should only do this if we have to download the package...
            # NOTE 2: itest should download package from s3 to improve speed for instances in AWS.
            # TODO: Add a variable to specify itest ssh_user depending on VM users.
            if args.package and (args.tags is None or args.tags == "download-software"):
                if args.itest_s3_package_path and args.type == self.YB_SERVER_TYPE:
                    itest_extra_vars = self.extra_vars.copy()
                    itest_extra_vars["itest_s3_package_path"] = args.itest_s3_package_path
                    itest_extra_vars["ssh_user"] = "******"
                    # Runs all itest-related tasks (e.g. download from s3 bucket).
                    itest_extra_vars["tags"] = "itest"
                    self.cloud.setup_ansible(args).run(
                        "configure-{}.yml".format(args.type), itest_extra_vars, host_info)
                else:
                    scp_package_to_tmp(
                        args.package,
                        self.extra_vars["private_ip"],
                        self.extra_vars["ssh_user"],
                        self.extra_vars["ssh_port"],
                        args.private_key_file)

        logging.info("Configuring Instance: {}".format(args.search_pattern))
        ssh_options = {
            # TODO: replace with args.ssh_user when it's setup in the flow
            "ssh_user": self.get_ssh_user(),
            "private_key_file": args.private_key_file
        }
        ssh_options.update(get_ssh_host_port(host_info, args.custom_ssh_port))

        if args.rootCA_cert and args.rootCA_key is not None:
            logging.info("Creating and copying over client TLS certificate")
            self.cloud.generate_client_cert(self.extra_vars, ssh_options)
        if args.encryption_key_source_file is not None:
            self.extra_vars["encryption_key_file"] = args.encryption_key_source_file
            logging.info("Copying over encryption-at-rest certificate from {} to {}".format(
                args.encryption_key_source_file, args.encryption_key_target_dir))
            self.cloud.create_encryption_at_rest_file(self.extra_vars, ssh_options)

        self.cloud.setup_ansible(args).run(
            "configure-{}.yml".format(args.type), self.extra_vars, host_info)