def do_command(self): app_name = self.get_app_name() env_name = self.get_env_name(cmd_example='eb labs setup-ssl') certfile = self.app.pargs.cert_file privatekey = self.app.pargs.private_key certchain = self.app.pargs.cert_chain cert_name = self.app.pargs.name # Make sure arguments are valid if certfile or privatekey or certfile: if not (certfile and privatekey): raise InvalidOptionsError( 'When providing your own certificate the --cert-file ' 'and --private-key options are both required.') _validate_files_exists(certfile, privatekey, certchain) if not cert_name: cert_name = env_name # Check environment is not single instance if _is_single_instance(app_name, env_name): raise NotSupportedError('This command is currently not supported ' 'for single instance environments. \n' 'For more information please see ' 'http://docs.aws.amazon.com/elasticbeanstalk/' 'latest/dg/SSL.SingleInstance.html') # Generate cert if not provided if not certfile: privatekey, certfile = generate_self_signed_cert(cert_name) certfile = fileoperations.read_from_text_file(certfile) privatekey = fileoperations.read_from_text_file(privatekey) if certchain: certchain = fileoperations.read_from_text_file(certchain) result = iam.upload_server_certificate(cert_name + '.crt', certfile, privatekey, chain=certchain) arn = result['Arn'] # Update environment option_settings = [ elasticbeanstalk.create_option_setting( namespaces.LOAD_BALANCER, option_names.LOAD_BALANCER_HTTP_PORT, 'OFF' ), elasticbeanstalk.create_option_setting( namespaces.LOAD_BALANCER, option_names.LOAD_BALANCER_HTTPS_PORT, '443' ), elasticbeanstalk.create_option_setting( namespaces.LOAD_BALANCER, option_names.SSL_CERT_ID, arn ), ] commonops.update_environment(env_name, changes=option_settings, nohang=False)
def open_console(app_name, env_name): if utils.is_ssh(): raise NotSupportedError('The console command is not supported' ' in an ssh type session') env = None if env_name is not None: env = elasticbeanstalk.get_environment(app_name=app_name, env_name=env_name) region = aws.get_region_name() if env is not None: page = 'environment/dashboard' else: page = 'application/overview' app_name = utils.url_encode(app_name) console_url = 'console.aws.amazon.com/elasticbeanstalk/home?' console_url += 'region=' + region console_url += '#/' + page + '?applicationName=' + app_name if env is not None: console_url += '&environmentId=' + env.id commonops.open_webpage_in_browser(console_url, ssl=True)
def do_command(self): dockerrun_location = os.path.join(os.getcwd(), DOCKERRUN_FILENAME) v1_json = dockerrun.get_dockerrun(dockerrun_location) if not v1_json: raise NotFoundError( 'Dockerrun.aws.json file not found in current directory.') if v1_json['AWSEBDockerrunVersion'] == 2: raise NotSupportedError('Dockerrun file already at version 2') fileoperations.write_json_dict(v1_json, dockerrun_location + '_backup') io.echo('Version 1 file saved as Dockerrun.aws.json_backup.') v2_json = get_dockerrun_v2(v1_json) fileoperations.write_json_dict(v2_json, dockerrun_location) io.echo('Dockerrun.aws.json successfully converted to Version 2.') io.echo() io.echo('To change your default platform, type "eb platform select".')
def do_command(self): app_name = self.get_app_name() source_env = self.get_env_name() destination_env = self.app.pargs.destination_name if not destination_env: envs = elasticbeanstalk.get_environment_names(app_name) if len(envs) < 2: raise NotSupportedError(strings['swap.unsupported']) envs = [e for e in envs if e != source_env] if len(envs) == 1: destination_env = envs[0] else: io.echo() io.echo(prompts['swap.envprompt']) destination_env = utils.prompt_for_item_in_list(envs) swapops.cname_swap(source_env, destination_env)
def make_container(envvars_str=None, host_port=None, allow_insecure_ssl=False, pathconfig=PathConfig): """ Factory function for making a container or multicontainer. :param envvars_str: str: key=val str of environment variables :param host_port: str: optional host port mapped to container port :param allow_insecure_ssl: bool: allow insecure connection to docker registry :param pathconfig: PathConfig: Holds path/existence info :return Container/MultiContainer """ soln_stk = _determine_platform() container_cfg = containerops.get_configuration() opt_env = EnvvarCollector.from_str(envvars_str) if containerops.is_multi(soln_stk, container_cfg): return MultiContainer( fs_handler=make_multicontainer_fs_handler(pathconfig), opt_env=opt_env, allow_insecure_ssl=allow_insecure_ssl, soln_stk=soln_stk) elif containerops.is_generic(soln_stk, container_cfg): return GenericContainer( fs_handler=make_container_fs_handler(pathconfig), soln_stk=soln_stk, container_cfg=container_cfg, opt_env=opt_env, host_port=host_port) elif containerops.is_preconfigured(soln_stk, container_cfg): return PreconfiguredContainer( fs_handler=make_container_fs_handler(pathconfig), soln_stk=soln_stk, container_cfg=container_cfg, opt_env=opt_env, host_port=host_port) else: raise NotSupportedError(strings['local.unsupported'])
def _get_public_ssh_key(keypair_name): key_file = fileoperations.get_ssh_folder() + keypair_name if os.path.exists(key_file): file_name = key_file elif os.path.exists(key_file + '.pem'): file_name = key_file + '.pem' else: raise NotSupportedError(strings['ssh.filenotfound'].replace( '{key-name}', keypair_name)) try: stdout, stderr, returncode = exec_cmd( ['ssh-keygen', '-y', '-f', file_name]) if returncode != 0: raise CommandError('An error occurred while trying ' 'to get ssh public key') key_material = stdout return key_material except OSError: raise CommandError(strings['ssh.notpresent'])
def do_command(self): app_name = self.get_app_name() source_env = self.get_env_name() destination_env = self.app.pargs.destination_name if not destination_env: # Ask interactively for an env to swap with envs = elasticbeanstalk.get_environment_names(app_name) if len(envs) < 2: raise NotSupportedError(strings['swap.unsupported']) # Filter out current env envs = [e for e in envs if e != source_env] if len(envs) == 1: # Don't ask for env, just swap with only other environment destination_env = envs[0] else: # Ask for env to swap with io.echo() io.echo(prompts['swap.envprompt']) destination_env = utils.prompt_for_item_in_list(envs) swapops.cname_swap(source_env, destination_env)
def _raise_if_error_event(message): if message == responses['event.redmessage']: raise ServiceError(message) if message == responses['event.failedlaunch']: raise ServiceError(message) if message == responses['event.faileddeploy']: raise ServiceError(message) if message == responses['event.failedupdate']: raise ServiceError(message) if message == responses['event.updatefailed']: raise ServiceError(message) if message.startswith(responses['event.launchbad']): raise ServiceError(message) if message.startswith(responses['event.updatebad']): raise ServiceError(message) if message.startswith(responses['event.platformdeletefailed']): raise ServiceError(message) if message.startswith(responses['event.platformcreatefailed']): raise ServiceError(message) if message.startswith(responses['event.completewitherrors']): raise ServiceError(message) if message.startswith(responses['event.platform_ami_region_service_region_mismatch']): raise ServiceError(message) if ( message.startswith(responses['event.launched_environment']) and 'However, there were issues during launch.' in message ): raise ServiceError(message) if responses['tags.no_tags_to_update'] in message: raise ServiceError(message) if message.startswith(responses['logs.fail']): raise ServiceError(message) if message.startswith(responses['create.ecsdockerrun1']): raise NotSupportedError(prompts['create.dockerrunupgrade']) if message.startswith(responses['appversion.finished']) and message.endswith('FAILED.'): raise ServiceError(message)