Example #1
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))
Example #2
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.")
Example #3
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.")
Example #4
0
    def configure_secondary_interface(self, args, extra_vars, subnet_cidr):
        logging.info("[app] Configuring second NIC")
        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"])
        # Make sure we can ssh into the node after the reboot as well.
        if wait_for_ssh(extra_vars["ssh_host"],
                        extra_vars["ssh_port"],
                        extra_vars["ssh_user"],
                        args.private_key_file,
                        num_retries=120):
            pass
        else:
            raise YBOpsRuntimeError("Could not ssh into node {}".format(
                extra_vars["ssh_host"]))

        # 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")