def requirement_missing(self, req: tool_requirements.Requirement): with self.assertRaises( tool_requirements.MissingRequirementsError) as cm: tool_requirements._REQUIREMENTS = [req] tool_requirements.check_and_handle_requirements(self.test_console) exception = cm.exception self.assertEqual(req.NAME, exception.missing_requirements[0].name)
def main(args: argparse.Namespace, console: io.IO = io.ConsoleIO()): try: tool_requirements.check_and_handle_requirements(console) except tool_requirements.MissingRequirementsError as e: console.tell('Please install the following requirements:') for req in e.missing_requirements: console.tell('* {}: {}'.format(req.name, req.how_to_install_message)) return prompt_order = [ 'credentials', 'database_password', 'django_directory_path', ] required_parameters_to_prompt = { 'credentials': prompt.CredentialsPrompt, 'database_password': prompt.PostgresPasswordUpdatePrompt, 'django_directory_path': prompt.DjangoFilesystemPathUpdate, } # Parameters that were *not* provided as command flags. remaining_parameters_to_prompt = {} actual_parameters = {} for parameter_name, prompter in required_parameters_to_prompt.items(): value = getattr(args, parameter_name, None) if value is not None: try: prompter.validate(value) except ValueError as e: print(e, file=sys.stderr) sys.exit(1) actual_parameters[parameter_name] = value else: remaining_parameters_to_prompt[parameter_name] = prompter if remaining_parameters_to_prompt: num_steps = len(remaining_parameters_to_prompt) console.tell('<b>{} steps to update project</b>'.format(num_steps)) console.tell() parameter_and_prompt = sorted(remaining_parameters_to_prompt.items(), key=lambda i: prompt_order.index(i[0])) for step, (parameter_name, prompter) in enumerate(parameter_and_prompt): step = '<b>[{}/{}]</b>'.format(step + 1, num_steps) actual_parameters[parameter_name] = prompter.prompt( console, step, actual_parameters) workflow_manager = workflow.WorkflowManager( actual_parameters['credentials']) workflow_manager.update_project(actual_parameters['django_directory_path'], actual_parameters['database_password'])
def main(args: argparse.Namespace, console: io.IO = io.ConsoleIO()): actual_parameters = { 'cluster_name': getattr(args, 'cluster_name', None), 'database_instance_name': getattr(args, 'database_instance_name', None), } prompt_args = {**vars(args), **actual_parameters} root_prompt = prompt.RootPrompt() actual_parameters = root_prompt.prompt(prompt.Command.UPDATE, console, prompt_args) # This got moved from the start because we wanted to save the user from # giving us another bit of information that we can automatically retrieve # It will be rare if they are updating, that they do not have the # requirements. django_dir = actual_parameters['django_directory_path_update'] config_obj = config.Configuration(django_dir) backend = config_obj.get('backend') if not backend: raise InvalidConfigError( 'Configuration file in [{}] does not contain enough ' 'information to update a Django project.'.format(django_dir)) if not tool_requirements.check_and_handle_requirements(console, backend): return workflow_manager = workflow.WorkflowManager( actual_parameters['credentials']) workflow_manager.update_project( django_directory_path=actual_parameters[ 'django_directory_path_update'], database_password=actual_parameters['database_password'], cluster_name=actual_parameters['cluster_name'], database_instance_name=actual_parameters['database_instance_name'])
def main(args: argparse.Namespace, console: io.IO = io.ConsoleIO()): if not tool_requirements.check_and_handle_requirements( console, args.backend): return actual_parameters = { 'project_creation_mode': workflow.ProjectCreationMode.CREATE, 'bucket_name': getattr(args, 'bucket_name', None), 'service_accounts': getattr(args, 'service_accounts', None), 'services': getattr(args, 'services', None), 'appengine_service_name': getattr(args, 'appengine_service_name', None), 'cluster_name': getattr(args, 'cluster_name', None), 'database_instance_name': getattr(args, 'database_instance_name', None), } prompt_args = {**vars(args), **actual_parameters} root_prompt = prompt.RootPrompt() actual_parameters = root_prompt.prompt(prompt.Command.CLOUDIFY, console, prompt_args) workflow_manager = workflow.WorkflowManager( actual_parameters['credentials']) django_directory_path = actual_parameters['django_directory_path_cloudify'] django_project_name = utils.get_django_project_name(django_directory_path) try: admin_url = workflow_manager.create_and_deploy_new_project( project_name=actual_parameters['project_name'], project_id=actual_parameters['project_id'], project_creation_mode=actual_parameters['project_creation_mode'], billing_account_name=actual_parameters['billing_account_name'], django_project_name=django_project_name, django_superuser_name=actual_parameters['django_superuser_login'], django_superuser_email=actual_parameters['django_superuser_email'], django_superuser_password=actual_parameters[ 'django_superuser_password'], django_directory_path=django_directory_path, django_requirements_path=actual_parameters.get( 'django_requirements_path'), django_settings_path=actual_parameters['django_settings_path'], database_password=actual_parameters['database_password'], cluster_name=actual_parameters['cluster_name'], database_instance_name=actual_parameters['database_instance_name'], required_services=actual_parameters['services'], required_service_accounts=actual_parameters['service_accounts'], appengine_service_name=actual_parameters['appengine_service_name'], cloud_storage_bucket_name=actual_parameters['bucket_name'], backend=args.backend, deploy_existing_django_project=True) except workflow.ProjectExistsError: console.error('A project with id "{}" already exists'.format( actual_parameters['project_id'])) survey.prompt_for_survey(console) return admin_url
def main(args: argparse.Namespace, console: io.IO = io.ConsoleIO()): if not tool_requirements.check_and_handle_requirements( console, args.backend): return prompt_order = [ 'credentials', 'project_id', 'project_name', 'billing_account_name', 'database_password', 'django_directory_path', 'django_project_name', 'django_app_name', 'django_superuser_login', 'django_superuser_password', 'django_superuser_email', ] required_parameters_to_prompt = { 'credentials': prompt.CredentialsPrompt, 'project_id': prompt.ProjectIdPrompt, 'project_name': prompt.GoogleCloudProjectNamePrompt, 'billing_account_name': prompt.BillingPrompt, 'database_password': prompt.PostgresPasswordPrompt, 'django_directory_path': prompt.DjangoFilesystemPath, 'django_project_name': prompt.DjangoProjectNamePrompt, 'django_app_name': prompt.DjangoAppNamePrompt, 'django_superuser_login': prompt.DjangoSuperuserLoginPrompt, 'django_superuser_password': prompt.DjangoSuperuserPasswordPrompt, 'django_superuser_email': prompt.DjangoSuperuserEmailPrompt } # Parameters that were *not* provided as command flags. remaining_parameters_to_prompt = {} actual_parameters = { 'project_creation_mode': workflow.ProjectCreationMode.CREATE, 'bucket_name': getattr(args, 'bucket_name', None), 'service_accounts': getattr(args, 'service_accounts', None), 'services': getattr(args, 'services', None) } for parameter_name, prompter in required_parameters_to_prompt.items(): value = getattr(args, parameter_name, None) if value is not None: try: prompter.validate(value) except ValueError as e: print(e, file=sys.stderr) sys.exit(1) actual_parameters[parameter_name] = value else: remaining_parameters_to_prompt[parameter_name] = prompter if args.use_existing_project: actual_parameters['project_creation_mode'] = ( workflow.ProjectCreationMode.MUST_EXIST) remaining_parameters_to_prompt['project_name'] = ( prompt.GoogleCloudProjectNamePrompt) remaining_parameters_to_prompt['project_id'] = ( prompt.ExistingProjectIdPrompt) if remaining_parameters_to_prompt: num_steps = len(remaining_parameters_to_prompt) console.tell( '<b>{} steps to setup your new project</b>'.format(num_steps)) console.tell() parameter_and_prompt = sorted(remaining_parameters_to_prompt.items(), key=lambda i: prompt_order.index(i[0])) for step, (parameter_name, prompter) in enumerate(parameter_and_prompt): step = '<b>[{}/{}]</b>'.format(step + 1, num_steps) actual_parameters[parameter_name] = prompter.prompt( console, step, actual_parameters, actual_parameters.get('credentials', None)) workflow_manager = workflow.WorkflowManager( actual_parameters['credentials'], args.backend) try: admin_url = workflow_manager.create_and_deploy_new_project( project_name=actual_parameters['project_name'], project_id=actual_parameters['project_id'], project_creation_mode=actual_parameters['project_creation_mode'], billing_account_name=actual_parameters['billing_account_name'], django_project_name=actual_parameters['django_project_name'], django_app_name=actual_parameters['django_app_name'], django_superuser_name=actual_parameters['django_superuser_login'], django_superuser_email=actual_parameters['django_superuser_email'], django_superuser_password=actual_parameters[ 'django_superuser_password'], django_directory_path=actual_parameters['django_directory_path'], database_password=actual_parameters['database_password'], required_services=actual_parameters['services'], required_service_accounts=actual_parameters['service_accounts'], cloud_storage_bucket_name=actual_parameters['bucket_name'], backend=args.backend) return admin_url except workflow.ProjectExistsError: console.error('A project with id "{}" already exists'.format( actual_parameters['project_id']))
def has_requirement(self, req: tool_requirements.Requirement): try: tool_requirements._REQUIREMENTS = [req] tool_requirements.check_and_handle_requirements(self.test_console) except tool_requirements.MissingRequirementsError: self.fail('Not suppose to be missing {}'.format(req.Name))
def has_requirement(self, req: tool_requirements.Requirement): tool_requirements._REQUIREMENTS = {'test': [req]} self.assertTrue( tool_requirements.check_and_handle_requirements( self.test_console, 'test'))
def requirement_missing(self, req: tool_requirements.Requirement): tool_requirements._REQUIREMENTS = {'test': [req]} self.assertFalse( tool_requirements.check_and_handle_requirements( self.test_console, 'test'))