def read_appscalefile(self): """ Checks the local directory for an AppScalefile and reads its contents. Raises: AppScalefileException: If there is no AppScalefile in the local directory. Returns: The contents of the AppScalefile in the current working directory. """ try: with open(self.get_appscalefile_location()) as file_handle: return file_handle.read() except IOError: raise AppScalefileException("No AppScalefile found in this " + "directory. Please run 'appscale init' to generate one and try " + "again.")
def init(self, environment=None): """ Writes an AppScalefile in the local directory, that contains common configuration parameters. Args: environment: A str that indicates whether the AppScalefile to write should be tailored to a 'cloud' environment or a 'cluster' environment or both. Raises: AppScalefileException: If there already is an AppScalefile in the local directory. """ # first, make sure there isn't already an AppScalefile in this # directory appscalefile_location = self.get_appscalefile_location() if os.path.exists(appscalefile_location): raise AppScalefileException("There is already an AppScalefile" + " in this directory. Please remove it and run 'appscale init'" + " again to generate a new AppScalefile.") # finally, copy the template AppScalefile there shutil.copy(self.TEMPLATE_APPSCALEFILE, appscalefile_location)
def up(self): """ Starts an AppScale deployment with the configuration options from the AppScalefile in the current directory. Raises: AppScalefileException: If there is no AppScalefile in the current directory. """ contents = self.read_appscalefile() # If running in a cluster environment, we first need to set up SSH keys contents_as_yaml = yaml.safe_load(contents) if not LocalState.ensure_appscalefile_is_up_to_date(): contents = self.read_appscalefile() contents_as_yaml = yaml.safe_load(contents) # Construct a run-instances command from the file's contents command = [] for key, value in contents_as_yaml.items(): if key in self.DEPRECATED_ASF_ARGS: raise AppScalefileException( "'{0}' has been deprecated. Refer to {1} to see the full changes." .format(key, NodeLayout.APPSCALEFILE_INSTRUCTIONS)) if value is True: command.append(str("--%s" % key)) elif value is False: pass else: if key == "ips_layout": command.append("--ips_layout") command.append(base64.b64encode(yaml.dump(value))) elif key == "disks": command.append("--disks") command.append(base64.b64encode(yaml.dump(value))) elif key == "user_commands": command.append("--user_commands") command.append(base64.b64encode(yaml.dump(value))) else: command.append(str("--%s" % key)) command.append(str("%s" % value)) run_instances_opts = ParseArgs(command, "appscale-run-instances").args if 'infrastructure' not in contents_as_yaml: # Generate a new keypair if necessary. if not self.valid_ssh_key(contents_as_yaml, run_instances_opts): add_keypair_command = [] if 'keyname' in contents_as_yaml: add_keypair_command.append('--keyname') add_keypair_command.append(str( contents_as_yaml['keyname'])) add_keypair_command.append('--ips_layout') add_keypair_command.append( base64.b64encode(yaml.dump( contents_as_yaml['ips_layout']))) add_keypair_opts = ParseArgs(add_keypair_command, 'appscale-add-keypair').args AppScaleTools.add_keypair(add_keypair_opts) AppScaleTools.run_instances(run_instances_opts)