コード例 #1
0
    def valid_ssh_key(self, config, run_instances_opts):
        """ Checks if the tools can log into the head node with the current key.

    Args:
      config: A dictionary that includes the IPs layout (which itself is a dict
        mapping role names to IPs) and, optionally, the keyname to use.
      run_instances_opts: The arguments parsed from the appscale-run-instances
        command.

    Returns:
      A bool indicating whether or not the specified keyname can be used to log
      into the head node.

    Raises:
      BadConfigurationException: If the IPs layout was not a dictionary.
    """
        keyname = config['keyname']
        verbose = config.get('verbose', False)

        if not isinstance(config['ips_layout'], dict):
            raise BadConfigurationException(
                'ips_layout should be a dictionary. Please fix it and try again.'
            )

        ssh_key_location = self.APPSCALE_DIRECTORY + keyname + ".key"
        if not os.path.exists(ssh_key_location):
            return False

        all_ips = LocalState.get_all_public_ips(keyname)

        # If a login node is defined, use that to communicate with other nodes.
        node_layout = NodeLayout(run_instances_opts)
        head_node = node_layout.head_node()
        if head_node is not None:
            remote_key = '{}/ssh.key'.format(RemoteHelper.CONFIG_DIR)
            try:
                RemoteHelper.scp(head_node.public_ip, keyname,
                                 ssh_key_location, remote_key, verbose)
            except ShellException:
                return False

            for ip in all_ips:
                ssh_to_ip = 'ssh -i {key} -o StrictHostkeyChecking=no root@{ip} true'\
                  .format(key=remote_key, ip=ip)
                try:
                    RemoteHelper.ssh(head_node.public_ip,
                                     keyname,
                                     ssh_to_ip,
                                     verbose,
                                     user='******')
                except ShellException:
                    return False
            return True

        for ip in all_ips:
            if not self.can_ssh_to_ip(ip, keyname, verbose):
                return False

        return True
コード例 #2
0
ファイル: appscale.py プロジェクト: menivaitsi/appscale-tools
  def valid_ssh_key(self, config, run_instances_opts):
    """ Checks if the tools can log into the head node with the current key.

    Args:
      config: A dictionary that includes the IPs layout (which itself is a dict
        mapping role names to IPs) and, optionally, the keyname to use.
      run_instances_opts: The arguments parsed from the appscale-run-instances
        command.

    Returns:
      A bool indicating whether or not the specified keyname can be used to log
      into the head node.

    Raises:
      BadConfigurationException: If the IPs layout was not a dictionary.
    """
    keyname = config['keyname']
    verbose = config.get('verbose', False)

    if not isinstance(config['ips_layout'], dict):
      raise BadConfigurationException(
        'ips_layout should be a dictionary. Please fix it and try again.')

    ssh_key_location = self.APPSCALE_DIRECTORY + keyname + ".key"
    if not os.path.exists(ssh_key_location):
      return False

    all_ips = LocalState.get_all_public_ips(keyname)

    # If a login node is defined, use that to communicate with other nodes.
    node_layout = NodeLayout(run_instances_opts)
    head_node = node_layout.head_node()
    if head_node is not None:
      remote_key = '{}/ssh.key'.format(RemoteHelper.CONFIG_DIR)
      try:
        RemoteHelper.scp(
          head_node.public_ip, keyname, ssh_key_location, remote_key, verbose)
      except ShellException:
        return False

      for ip in all_ips:
        ssh_to_ip = 'ssh -i {key} -o StrictHostkeyChecking=no root@{ip} true'\
          .format(key=remote_key, ip=ip)
        try:
          RemoteHelper.ssh(
            head_node.public_ip, keyname, ssh_to_ip, verbose, user='******')
        except ShellException:
          return False
      return True

    for ip in all_ips:
      if not self.can_ssh_to_ip(ip, keyname, verbose):
        return False

    return True
コード例 #3
0
    def upgrade(cls, options):
        """ Upgrades the deployment to the latest AppScale version.
    Args:
      options: A Namespace that has fields for each parameter that can be
        passed in via the command-line interface.
    """
        node_layout = NodeLayout(options)
        if not node_layout.is_valid():
            raise BadConfigurationException(
                'Your ips_layout is invalid:\n{}'.format(node_layout.errors()))

        latest_tools = APPSCALE_VERSION
        try:
            AppScaleLogger.log(
                'Checking if an update is available for appscale-tools')
            latest_tools = latest_tools_version()
        except:
            # Prompt the user if version metadata can't be fetched.
            if not options.test:
                response = raw_input(
                    'Unable to check for the latest version of appscale-tools. Would '
                    'you like to continue upgrading anyway? (y/N) ')
                if response.lower() not in ['y', 'yes']:
                    raise AppScaleException('Cancelled AppScale upgrade.')

        if latest_tools > APPSCALE_VERSION:
            raise AppScaleException(
                "There is a newer version ({}) of appscale-tools available. Please "
                "upgrade the tools package before running 'appscale upgrade'.".
                format(latest_tools))

        master_ip = node_layout.head_node().public_ip
        upgrade_version_available = cls.get_upgrade_version_available()

        current_version = RemoteHelper.get_host_appscale_version(
            master_ip, options.keyname, options.verbose)

        # Don't run bootstrap if current version is later that the most recent
        # public one. Covers cases of revoked versions/tags and ensures we won't
        # try to downgrade the code.
        if current_version >= upgrade_version_available:
            AppScaleLogger.log(
                'AppScale is already up to date. Skipping code upgrade.')
            AppScaleLogger.log(
                'Running upgrade script to check if any other upgrades are needed.'
            )
            cls.shut_down_appscale_if_running(options)
            cls.run_upgrade_script(options, node_layout)
            return

        cls.shut_down_appscale_if_running(options)
        cls.upgrade_appscale(options, node_layout)
コード例 #4
0
    def test_with_login_override(self):
        # if the user wants to set a login host, make sure that gets set as the
        # login node's public IP address instead of what we'd normally put in

        # use a simple deployment so we can get the login node with .head_node()
        input_yaml_1 = {'controller': self.ip_1, 'servers': [self.ip_2]}
        options_1 = self.default_options.copy()
        options_1['ips'] = input_yaml_1
        options_1['login_host'] = "www.booscale.com"
        layout_1 = NodeLayout(options_1)
        self.assertEquals(True, layout_1.is_valid())

        head_node = layout_1.head_node()
        self.assertEquals(options_1['login_host'], head_node.public_ip)
コード例 #5
0
 def test_with_right_number_of_unique_disks(self):
     # suppose that the user has specified two nodes, and two EBS / PD disks
     # with different names. This is the desired user behavior.
     input_yaml = {'controller': self.ip_1, 'servers': [self.ip_2]}
     options = self.default_options.copy()
     options['ips'] = input_yaml
     options['disks'] = {
         self.ip_1: 'disk_number_one',
         self.ip_2: 'disk_number_two'
     }
     layout = NodeLayout(options)
     self.assertEquals(True, layout.is_valid())
     self.assertEquals('disk_number_one', layout.head_node().disk)
     self.assertEquals('disk_number_two', layout.other_nodes()[0].disk)
コード例 #6
0
    def upgrade(cls, options):
        """ Upgrades the deployment to the latest AppScale version.
    Args:
      options: A Namespace that has fields for each parameter that can be
        passed in via the command-line interface.
    """
        node_layout = NodeLayout(options)
        if not node_layout.is_valid():
            raise BadConfigurationException("Your ips_layout is invalid:\n{}".format(node_layout.errors()))

        latest_tools = APPSCALE_VERSION
        try:
            AppScaleLogger.log("Checking if an update is available for appscale-tools")
            latest_tools = latest_tools_version()
        except:
            # Prompt the user if version metadata can't be fetched.
            if not options.test:
                response = raw_input(
                    "Unable to check for the latest version of appscale-tools. Would "
                    "you like to continue upgrading anyway? (y/N) "
                )
                if response.lower() not in ["y", "yes"]:
                    raise AppScaleException("Cancelled AppScale upgrade.")

        if latest_tools > APPSCALE_VERSION:
            raise AppScaleException(
                "There is a newer version ({}) of appscale-tools available. Please "
                "upgrade the tools package before running 'appscale upgrade'.".format(latest_tools)
            )

        master_ip = node_layout.head_node().public_ip
        upgrade_version_available = cls.get_upgrade_version_available()

        current_version = RemoteHelper.get_host_appscale_version(master_ip, options.keyname, options.verbose)

        # Don't run bootstrap if current version is later that the most recent
        # public one. Covers cases of revoked versions/tags and ensures we won't
        # try to downgrade the code.
        if current_version >= upgrade_version_available:
            AppScaleLogger.log("AppScale is already up to date. Skipping code upgrade.")
            AppScaleLogger.log("Running upgrade script to check if any other upgrades are needed.")
            cls.shut_down_appscale_if_running(options)
            cls.run_upgrade_script(options, node_layout)
            return

        cls.shut_down_appscale_if_running(options)
        cls.upgrade_appscale(options, node_layout)
コード例 #7
0
  def test_with_login_override(self):
    # if the user wants to set a login host, make sure that gets set as the
    # login node's public IP address instead of what we'd normally put in

    # use a simple deployment so we can get the login node with .head_node()
    input_yaml_1 = {
      'controller' : self.ip_1,
      'servers' : [self.ip_2]
    }
    options_1 = self.default_options.copy()
    options_1['ips'] = input_yaml_1
    options_1['login_host'] = "www.booscale.com"
    layout_1 = NodeLayout(options_1)
    self.assertEquals(True, layout_1.is_valid())

    head_node = layout_1.head_node()
    self.assertEquals(options_1['login_host'], head_node.public_ip)
コード例 #8
0
 def test_with_right_number_of_unique_disks(self):
   # suppose that the user has specified two nodes, and two EBS / PD disks
   # with different names. This is the desired user behavior.
   input_yaml = {
     'controller' : self.ip_1,
     'servers' : [self.ip_2]
   }
   options = self.default_options.copy()
   options['ips'] = input_yaml
   options['disks'] = {
     self.ip_1 : 'disk_number_one',
     self.ip_2 : 'disk_number_two'
   }
   layout = NodeLayout(options)
   self.assertEquals(True, layout.is_valid())
   self.assertEquals('disk_number_one', layout.head_node().disk)
   self.assertEquals('disk_number_two', layout.other_nodes()[0].disk)
コード例 #9
0
  def run_instances(cls, options):
    """Starts a new AppScale deployment with the parameters given.

    Args:
      options: A Namespace that has fields for each parameter that can be
        passed in via the command-line interface.
    Raises:
      AppControllerException: If the AppController on the head node crashes.
        When this occurs, the message in the exception contains the reason why
        the AppController crashed.
      BadConfigurationException: If the user passes in options that are not
        sufficient to start an AppScale deployment (e.g., running on EC2 but
        not specifying the AMI to use), or if the user provides us
        contradictory options (e.g., running on EC2 but not specifying EC2
        credentials).
    """
    LocalState.make_appscale_directory()
    LocalState.ensure_appscale_isnt_running(options.keyname, options.force)
    if options.infrastructure:
      if not options.disks and not options.test and not options.force:
        LocalState.ensure_user_wants_to_run_without_disks()

    reduced_version = '.'.join(x for x in APPSCALE_VERSION.split('.')[:2])
    AppScaleLogger.log("Starting AppScale " + reduced_version)

    my_id = str(uuid.uuid4())
    AppScaleLogger.remote_log_tools_state(options, my_id, "started",
      APPSCALE_VERSION)

    node_layout = NodeLayout(options)
    if not node_layout.is_valid():
      raise BadConfigurationException("There were errors with your " + \
                                      "placement strategy:\n{0}".format(str(node_layout.errors())))

    head_node = node_layout.head_node()
    # Start VMs in cloud via cloud agent.
    if options.infrastructure:
      instance_ids, public_ips, private_ips = RemoteHelper.start_all_nodes(
        options, len(node_layout.nodes))
      AppScaleLogger.log("\nPlease wait for AppScale to prepare your machines "
                         "for use. This can take few minutes.")

      # Set newly obtained node layout info for this deployment.
      for i, _ in enumerate(instance_ids):
        node_layout.nodes[i].public_ip = public_ips[i]
        node_layout.nodes[i].private_ip = private_ips[i]
        node_layout.nodes[i].instance_id = instance_ids[i]

      # Enables root logins and SSH access on the head node.
      RemoteHelper.enable_root_ssh(options, head_node.public_ip)
    AppScaleLogger.verbose("Node Layout: {}".format(node_layout.to_list()),
                           options.verbose)

    # Ensure all nodes are compatible.
    RemoteHelper.ensure_machine_is_compatible(
      head_node.public_ip, options.keyname, options.verbose)

    # Use rsync to move custom code into the deployment.
    if options.scp:
      AppScaleLogger.log("Copying over local copy of AppScale from {0}".
        format(options.scp))
      RemoteHelper.rsync_files(head_node.public_ip, options.keyname, options.scp,
        options.verbose)

    # Start services on head node.
    RemoteHelper.start_head_node(options, my_id, node_layout)

    # Write deployment metadata to disk (facilitates SSH operations, etc.)
    db_master = node_layout.db_master().private_ip
    head_node = node_layout.head_node().public_ip
    LocalState.update_local_metadata(options, db_master, head_node)

    # Copy the locations.json to the head node
    RemoteHelper.copy_local_metadata(node_layout.head_node().public_ip,
                                     options.keyname, options.verbose)

    # Wait for services on head node to start.
    secret_key = LocalState.get_secret_key(options.keyname)
    acc = AppControllerClient(head_node, secret_key)
    try:
      while not acc.is_initialized():
        AppScaleLogger.log('Waiting for head node to initialize...')
        # This can take some time in particular the first time around, since
        # we will have to initialize the database.
        time.sleep(cls.SLEEP_TIME*3)
    except socket.error as socket_error:
      AppScaleLogger.warn('Unable to initialize AppController: {}'.
                          format(socket_error.message))
      message = RemoteHelper.collect_appcontroller_crashlog(
        head_node, options.keyname, options.verbose)
      raise AppControllerException(message)

    # Set up admin account.
    try:
      # We don't need to have any exception information here: we do expect
      # some anyway while the UserAppServer is coming up.
      acc.does_user_exist("non-existent-user", True)
    except Exception:
      AppScaleLogger.log('UserAppServer not ready yet. Retrying ...')
      time.sleep(cls.SLEEP_TIME)

    if options.admin_user and options.admin_pass:
      AppScaleLogger.log("Using the provided admin username/password")
      username, password = options.admin_user, options.admin_pass
    elif options.test:
      AppScaleLogger.log("Using default admin username/password")
      username, password = LocalState.DEFAULT_USER, LocalState.DEFAULT_PASSWORD
    else:
      username, password = LocalState.get_credentials()

    RemoteHelper.create_user_accounts(username, password, head_node,
                                      options.keyname)
    acc.set_admin_role(username, 'true', cls.ADMIN_CAPABILITIES)

    # Wait for machines to finish loading and AppScale Dashboard to be deployed.
    RemoteHelper.wait_for_machines_to_finish_loading(head_node, options.keyname)
    RemoteHelper.sleep_until_port_is_open(LocalState.get_login_host(
      options.keyname), RemoteHelper.APP_DASHBOARD_PORT, options.verbose)

    AppScaleLogger.success("AppScale successfully started!")
    AppScaleLogger.success("View status information about your AppScale " + \
                           "deployment at http://{0}:{1}".format(LocalState.get_login_host(
                           options.keyname), RemoteHelper.APP_DASHBOARD_PORT))
    AppScaleLogger.remote_log_tools_state(options, my_id,
      "finished", APPSCALE_VERSION)
コード例 #10
0
    def run_instances(cls, options):
        """Starts a new AppScale deployment with the parameters given.

    Args:
      options: A Namespace that has fields for each parameter that can be
        passed in via the command-line interface.
    Raises:
      AppControllerException: If the AppController on the head node crashes.
        When this occurs, the message in the exception contains the reason why
        the AppController crashed.
      BadConfigurationException: If the user passes in options that are not
        sufficient to start an AppScale deployment (e.g., running on EC2 but
        not specifying the AMI to use), or if the user provides us
        contradictory options (e.g., running on EC2 but not specifying EC2
        credentials).
    """
        LocalState.make_appscale_directory()
        LocalState.ensure_appscale_isnt_running(options.keyname, options.force)
        if options.infrastructure:
            if not options.disks and not options.test and not options.force:
                LocalState.ensure_user_wants_to_run_without_disks()

        reduced_version = ".".join(x for x in APPSCALE_VERSION.split(".")[:2])
        AppScaleLogger.log("Starting AppScale " + reduced_version)

        my_id = str(uuid.uuid4())
        AppScaleLogger.remote_log_tools_state(options, my_id, "started", APPSCALE_VERSION)

        node_layout = NodeLayout(options)
        if not node_layout.is_valid():
            raise BadConfigurationException(
                "There were errors with your " + "placement strategy:\n{0}".format(str(node_layout.errors()))
            )

        head_node = node_layout.head_node()
        # Start VMs in cloud via cloud agent.
        if options.infrastructure:
            instance_ids, public_ips, private_ips = RemoteHelper.start_all_nodes(options, len(node_layout.nodes))
            AppScaleLogger.log(
                "\nPlease wait for AppScale to prepare your machines " "for use. This can take few minutes."
            )

            # Set newly obtained node layout info for this deployment.
            for i, _ in enumerate(instance_ids):
                node_layout.nodes[i].public_ip = public_ips[i]
                node_layout.nodes[i].private_ip = private_ips[i]
                node_layout.nodes[i].instance_id = instance_ids[i]

            # Enables root logins and SSH access on the head node.
            RemoteHelper.enable_root_ssh(options, head_node.public_ip)
        AppScaleLogger.verbose("Node Layout: {}".format(node_layout.to_list()), options.verbose)

        # Ensure all nodes are compatible.
        RemoteHelper.ensure_machine_is_compatible(head_node.public_ip, options.keyname, options.verbose)

        # Use rsync to move custom code into the deployment.
        if options.scp:
            AppScaleLogger.log("Copying over local copy of AppScale from {0}".format(options.scp))
            RemoteHelper.rsync_files(head_node.public_ip, options.keyname, options.scp, options.verbose)

        # Start services on head node.
        RemoteHelper.start_head_node(options, my_id, node_layout)

        # Write deployment metadata to disk (facilitates SSH operations, etc.)
        db_master = node_layout.db_master().private_ip
        head_node = node_layout.head_node().public_ip
        LocalState.update_local_metadata(options, db_master, head_node)

        # Copy the locations.json to the head node
        RemoteHelper.copy_local_metadata(node_layout.head_node().public_ip, options.keyname, options.verbose)

        # Wait for services on head node to start.
        secret_key = LocalState.get_secret_key(options.keyname)
        acc = AppControllerClient(head_node, secret_key)
        try:
            while not acc.is_initialized():
                AppScaleLogger.log("Waiting for head node to initialize...")
                # This can take some time in particular the first time around, since
                # we will have to initialize the database.
                time.sleep(cls.SLEEP_TIME * 3)
        except socket.error as socket_error:
            AppScaleLogger.warn("Unable to initialize AppController: {}".format(socket_error.message))
            message = RemoteHelper.collect_appcontroller_crashlog(head_node, options.keyname, options.verbose)
            raise AppControllerException(message)

        # Set up admin account.
        try:
            # We don't need to have any exception information here: we do expect
            # some anyway while the UserAppServer is coming up.
            acc.does_user_exist("non-existent-user", True)
        except Exception:
            AppScaleLogger.log("UserAppServer not ready yet. Retrying ...")
            time.sleep(cls.SLEEP_TIME)

        if options.admin_user and options.admin_pass:
            AppScaleLogger.log("Using the provided admin username/password")
            username, password = options.admin_user, options.admin_pass
        elif options.test:
            AppScaleLogger.log("Using default admin username/password")
            username, password = LocalState.DEFAULT_USER, LocalState.DEFAULT_PASSWORD
        else:
            username, password = LocalState.get_credentials()

        RemoteHelper.create_user_accounts(username, password, head_node, options.keyname)
        acc.set_admin_role(username, "true", cls.ADMIN_CAPABILITIES)

        # Wait for machines to finish loading and AppScale Dashboard to be deployed.
        RemoteHelper.wait_for_machines_to_finish_loading(head_node, options.keyname)
        RemoteHelper.sleep_until_port_is_open(
            LocalState.get_login_host(options.keyname), RemoteHelper.APP_DASHBOARD_PORT, options.verbose
        )

        AppScaleLogger.success("AppScale successfully started!")
        AppScaleLogger.success(
            "View status information about your AppScale "
            + "deployment at http://{0}:{1}".format(
                LocalState.get_login_host(options.keyname), RemoteHelper.APP_DASHBOARD_PORT
            )
        )
        AppScaleLogger.remote_log_tools_state(options, my_id, "finished", APPSCALE_VERSION)