Ejemplo n.º 1
0
    def run_add_keypair(self):
        """ Sets up the add keypair arguments and attempts to add the
    keyname generated.

    Returns:
      True on success, False otherwise.
    """
        self.state = self.INIT_STATE
        add_keypair_args = [
            '--keyname', self.keyname, '--ips_layout', self.ips_yaml_b64,
            "--root_password", self.root_pass, "--auto"
        ]
        options = parse_args.ParseArgs(add_keypair_args, "appscale-add-keypair"). \
          args
        try:
            AppScaleTools.add_keypair(options)
            logging.info("AppScale add key pair was successful")
        except BadConfigurationException as bad_config:
            self.state = self.ERROR_STATE
            logging.error(str(bad_config))
            self.err_message = "Bad configuration. Unable to set up keypairs."
            return False
        except Exception as exception:
            self.state = self.ERROR_STATE
            logging.exception(exception)
            self.err_message = "Exception when running add key pair: {0}". \
              format(exception)
            return False
        return True
Ejemplo n.º 2
0
    def appscale_down(self):
        """ Terminates a currently running deployment of AppScale. Calls on the 
    AppScale tools by building an argument list, which varies based on 
    the deployment type.
   
    Returns:
      True on success, False otherwise. 
    """
        logging.debug("Starting AppScale down.")
        self.state = self.TERMINATING_STATE

        # We capture the stdout and stderr of the tools and use it to calculate
        # the percentage towards completion.
        old_stdout = sys.stdout
        old_stderr = sys.stderr
        sys.stdout = self.std_out_capture
        sys.stderr = self.std_err_capture

        terminate_args = ['--keyname', self.keyname, "--verbose"]

        if self.deployment_type == CLOUD:
            terminate_args.extend([
                "--EC2_SECRET_KEY", self.ec2_secret, "--EC2_ACCESS_KEY",
                self.ec2_access, "--EC2_URL", self.ec2_url, "--test"
            ])
        try:
            logging.info("Starting terminate instances.")

            options = parse_args.ParseArgs(terminate_args,
                                           "appscale-terminate-instances").args
            AppScaleTools.terminate_instances(options)
            self.state = self.TERMINATED_STATE

            logging.info("AppScale terminate instances successfully ran!")
        except BadConfigurationException as bad_config:
            self.state = self.ERROR_STATE
            logging.exception(bad_config)
            self.err_message = "Bad configuration. Unable to terminate AppScale. " \
              "{0}".format(bad_config)
        except Exception as exception:
            self.state = self.ERROR_STATE
            logging.exception(exception)
            self.err_message = "Exception when terminating: {0}".format(
                exception)
        finally:
            sys.stdout = old_stdout
            sys.stderr = old_stderr

        return self.state == self.TERMINATED_STATE
Ejemplo n.º 3
0
    def run_appscale(self):
        """ Executes the appscale tools with deployment specific arguments.

    Returns:
      True on success, False otherwise.
    """
        logging.info("Tools arguments: {0}".format(str(self.args)))

        self.state = self.RUNNING_STATE
        old_stdout = sys.stdout
        old_stderr = sys.stderr

        try:
            options = parse_args.ParseArgs(self.args,
                                           "appscale-run-instances").args
            sys.stdout = self.std_out_capture
            sys.stderr = self.std_err_capture

            AppScaleTools.run_instances(options)
            logging.info("AppScale run instances was successful!")
            self.state = self.COMPLETE_STATE
            self.set_status_link()
        except BadConfigurationException as bad_config:
            self.state = self.ERROR_STATE
            logging.exception(bad_config)
            self.err_message = "Bad configuration. {0}".format(bad_config)
        except Exception as exception:
            self.state = self.ERROR_STATE
            logging.exception(exception)
            self.err_message = "Exception--{0}".format(exception)
        except SystemExit as sys_exit:
            self.state = self.ERROR_STATE
            logging.error(str(sys_exit))
            self.err_message = str(
                "Error with given arguments caused system exit.")
        finally:
            sys.stdout = old_stdout
            sys.stderr = old_stderr

        return self.state == self.COMPLETE_STATE