def import_key_pair(keyname, key_material): try: result = _make_api_call('import_key_pair', KeyName=keyname, PublicKeyMaterial=key_material) except ServiceError as e: if e.message.endswith('already exists.'): raise AlreadyExistsError(e.message) else: raise return result
def _handle_response_code(response_data, attempt, aggregated_error_message): max_attempts = 10 LOG.debug('Response: ' + str(response_data)) status = response_data['ResponseMetadata']['HTTPStatusCode'] LOG.debug('API call finished, status = ' + str(status)) try: message = str(response_data['Error']['Message']) except KeyError: message = "" if status == 400: error = _get_400_error(response_data, message) if isinstance(error, ThrottlingError): LOG.debug('Received throttling error') if attempt > max_attempts: raise MaxRetriesError('Max retries exceeded for ' 'throttling error') else: raise error elif status == 403: LOG.debug('Received a 403') if not message: message = 'Are your permissions correct?' if _region_name == 'cn-north-1': raise NotAuthorizedInRegionError( 'Operation Denied. ' + message + '\n' + strings['region.china.credentials']) else: raise NotAuthorizedError('Operation Denied. ' + message) elif status == 404: LOG.debug('Received a 404') raise NotFoundError(message) elif status == 409: LOG.debug('Received a 409') raise AlreadyExistsError(message) elif status in (500, 503, 504): LOG.debug('Received 5XX error') retry_failure_message = \ 'Received 5XX error during attempt #{0}\n {1}\n'.format( str(attempt), message ) aggregated_error_message.insert(attempt, retry_failure_message) if attempt > max_attempts: _handle_500_error(('\n').join(aggregated_error_message)) else: raise ServiceError('API Call unsuccessful. ' 'Status code returned ' + str(status))
def create_application(app_name, descrip): LOG.debug('Inside create_application api wrapper') try: result = _make_api_call('create_application', ApplicationName=app_name, Description=descrip) except InvalidParameterValueError as e: string = responses['app.exists'].replace('{app-name}', app_name) if e.message == string: raise AlreadyExistsError(e) else: raise e return result
def create_configuration_template(app_name, env_name, template_name, description): kwargs = { 'TemplateName': template_name, 'ApplicationName': app_name, 'Description': description, 'TemplateSpecification': {'TemplateSource': {'EnvironmentName': env_name}}, } try: result = _make_api_call('create_configuration_template', **kwargs) except InvalidParameterValueError as e: if e.message == responses['cfg.nameexists'].replace('{name}', template_name): raise AlreadyExistsError(e.message) else: raise return result
def do_command(self): env_name = self.app.pargs.environment_name modules = self.app.pargs.modules if modules and len(modules) > 0: self.compose_multiple_apps() return group = self.app.pargs.env_group_suffix cname = self.app.pargs.cname tier = self.app.pargs.tier itype = self.app.pargs.instance_type platform = self.app.pargs.platform single = self.app.pargs.single iprofile = self.app.pargs.instance_profile service_role = self.app.pargs.service_role label = self.app.pargs.version branch_default = self.app.pargs.branch_default key_name = self.app.pargs.keyname sample = self.app.pargs.sample nohang = self.app.pargs.nohang tags = self.app.pargs.tags envvars = self.app.pargs.envvars scale = self.app.pargs.scale timeout = self.app.pargs.timeout cfg = self.app.pargs.cfg elb_type = self.app.pargs.elb_type source = self.app.pargs.source process = self.app.pargs.process enable_spot = self.app.pargs.enable_spot spot_max_price = self.app.pargs.spot_max_price instance_types = self.app.pargs.instance_types on_demand_base_capacity = self.app.pargs.on_demand_base_capacity on_demand_above_base_capacity = self.app.pargs.on_demand_above_base_capacity max_instances = self.app.pargs.max_instances min_instances = self.app.pargs.min_instances interactive = False if env_name else True provided_env_name = env_name if sample and label: raise InvalidOptionsError(strings['create.sampleandlabel']) if single and scale: raise InvalidOptionsError(strings['create.singleandsize']) if (max_instances or min_instances) and scale: raise InvalidOptionsError(strings['create.scaleandminmax']) if (max_instances or min_instances) and single: raise InvalidOptionsError(strings['create.singleandminmax']) if single and elb_type: raise InvalidOptionsError(strings['create.single_and_elb_type']) if cname and tier and Tier.looks_like_worker_tier(tier): raise InvalidOptionsError(strings['worker.cname']) if cname and not elasticbeanstalk.is_cname_available(cname): raise AlreadyExistsError(strings['cname.unavailable'].replace( '{cname}', cname)) if tier and Tier.looks_like_worker_tier(tier): if self.app.pargs.vpc_elbpublic or self.app.pargs.vpc_elbsubnets or self.app.pargs.vpc_publicip: raise InvalidOptionsError( strings['create.worker_and_incompatible_vpc_arguments']) if (not tier or Tier.looks_like_webserver_tier(tier)) and single: if self.app.pargs.vpc_elbpublic or self.app.pargs.vpc_elbsubnets: raise InvalidOptionsError( strings['create.single_and_elbpublic_or_elb_subnet']) if (spot_max_price or on_demand_base_capacity or on_demand_above_base_capacity) and not enable_spot: raise InvalidOptionsError(strings['create.missing_enable_spot']) if instance_types is "": raise InvalidOptionsError( strings['spot.instance_types_validation']) if itype and instance_types: raise InvalidOptionsError(strings['create.itype_and_instances']) platform = _determine_platform(platform, iprofile) app_name = self.get_app_name() tags = tagops.get_and_validate_tags(tags) envvars = get_and_validate_envars(envvars) process_app_version = fileoperations.env_yaml_exists() or process template_name = get_template_name(app_name, cfg) tier = get_environment_tier(tier) env_name = provided_env_name or get_environment_name(app_name, group) cname = cname or get_environment_cname(env_name, provided_env_name, tier) key_name = key_name or commonops.get_default_keyname() elb_type = elb_type or get_elb_type_from_customer( interactive, single, tier) enable_spot = enable_spot or spotops.get_spot_request_from_customer( interactive) instance_types = instance_types or spotops.get_spot_instance_types_from_customer( interactive, enable_spot) database = self.form_database_object() vpc = self.form_vpc_object(tier, single) if not timeout and database: timeout = 15 env_request = CreateEnvironmentRequest( app_name=app_name, env_name=env_name, group_name=group, cname=cname, template_name=template_name, platform=platform, tier=tier, instance_type=itype, version_label=label, instance_profile=iprofile, service_role=service_role, single_instance=single, key_name=key_name, sample_application=sample, tags=tags, scale=scale, database=database, vpc=vpc, elb_type=elb_type, enable_spot=enable_spot, instance_types=instance_types, spot_max_price=spot_max_price, on_demand_base_capacity=on_demand_base_capacity, on_demand_above_base_capacity=on_demand_above_base_capacity, min_instances=min_instances, max_instances=max_instances) env_request.option_settings += envvars createops.make_new_env(env_request, branch_default=branch_default, process_app_version=process_app_version, nohang=nohang, interactive=interactive, timeout=timeout, source=source)
def do_command(self): app_name = self.get_app_name() env_name = self.get_env_name() clone_name = self.app.pargs.clone_name cname = self.app.pargs.cname scale = self.app.pargs.scale nohang = self.app.pargs.nohang tags = self.app.pargs.tags envvars = self.app.pargs.envvars exact = self.app.pargs.exact timeout = self.app.pargs.timeout provided_clone_name = clone_name is not None platform = None env = elasticbeanstalk.get_environment(app_name=app_name, env_name=env_name) tier = env.tier if 'worker' in tier.name.lower() and cname: raise InvalidOptionsError(strings['worker.cname']) if cname: if not elasticbeanstalk.is_cname_available(cname): raise AlreadyExistsError(strings['cname.unavailable'].replace( '{cname}', cname)) tags = tagops.get_and_validate_tags(tags) envvars = get_and_validate_envars(envvars) if not clone_name: if len(env_name) < 16: unique_name = env_name + '-clone' else: unique_name = 'my-cloned-env' env_list = elasticbeanstalk.get_environment_names(app_name) unique_name = utils.get_unique_name(unique_name, env_list) clone_name = io.prompt_for_environment_name( default_name=unique_name, prompt_text='Enter name for Environment Clone') if tier.name.lower() == 'webserver': if not cname and not provided_clone_name: cname = get_cname_from_customer(clone_name) elif not cname: cname = None if not exact: if not provided_clone_name: latest = solution_stack_ops.find_solution_stack_from_string( env.platform.name, find_newer=True) if latest != env.platform: io.echo() io.echo(prompts['clone.latest']) lst = [ 'Latest (' + str(latest) + ')', 'Same (' + str(env.platform) + ')' ] result = utils.prompt_for_item_in_list(lst) if result == lst[0]: platform = latest else: platform = latest else: platform = solution_stack_ops.find_solution_stack_from_string( env.platform.name, find_newer=True) if platform != env.platform: io.log_warning(prompts['clone.latestwarn']) clone_request = CloneEnvironmentRequest( app_name=app_name, env_name=clone_name, original_name=env_name, cname=cname, platform=platform, scale=scale, tags=tags, ) clone_request.option_settings += envvars cloneops.make_cloned_env(clone_request, nohang=nohang, timeout=timeout)
def do_command(self): # save command line args env_name = self.app.pargs.environment_name modules = self.app.pargs.modules if modules and len(modules) > 0: self.compose_multiple_apps() return group = self.app.pargs.env_group_suffix cname = self.app.pargs.cname tier = self.app.pargs.tier itype = self.app.pargs.instance_type solution_string = self.app.pargs.platform or solution_stack_ops.get_default_solution_stack( ) single = self.app.pargs.single iprofile = self.app.pargs.instance_profile service_role = self.app.pargs.service_role label = self.app.pargs.version branch_default = self.app.pargs.branch_default key_name = self.app.pargs.keyname sample = self.app.pargs.sample nohang = self.app.pargs.nohang tags = self.app.pargs.tags envvars = self.app.pargs.envvars scale = self.app.pargs.scale timeout = self.app.pargs.timeout cfg = self.app.pargs.cfg elb_type = self.app.pargs.elb_type source = self.app.pargs.source process = self.app.pargs.process region = self.app.pargs.region interactive = False if env_name else True provided_env_name = env_name if sample and label: raise InvalidOptionsError(strings['create.sampleandlabel']) if single and scale: raise InvalidOptionsError(strings['create.singleandsize']) if single and elb_type: raise InvalidOptionsError(strings['create.single_and_elb_type']) if cname and tier and Tier.looks_like_worker_tier(tier): raise InvalidOptionsError(strings['worker.cname']) if cname and not elasticbeanstalk.is_cname_available(cname): raise AlreadyExistsError(strings['cname.unavailable'].replace( '{cname}', cname)) if tier and Tier.looks_like_worker_tier(tier): if self.app.pargs.vpc_elbpublic or self.app.pargs.vpc_elbsubnets or self.app.pargs.vpc_publicip: raise InvalidOptionsError( strings['create.worker_and_incompatible_vpc_arguments']) if (not tier or Tier.looks_like_webserver_tier(tier)) and single: if self.app.pargs.vpc_elbpublic or self.app.pargs.vpc_elbsubnets: raise InvalidOptionsError( strings['create.single_and_elbpublic_or_elb_subnet']) app_name = self.get_app_name() tags = createops.get_and_validate_tags(tags) envvars = get_and_validate_envars(envvars) process_app_version = fileoperations.env_yaml_exists() or process platform = get_platform(solution_string, iprofile) template_name = get_template_name(app_name, cfg) tier = get_environment_tier(tier) env_name = provided_env_name or get_environment_name(app_name, group) cname = cname or get_environment_cname(env_name, provided_env_name, tier) key_name = key_name or commonops.get_default_keyname() elb_type = elb_type or get_elb_type_from_customer( interactive, single, region, tier) database = self.form_database_object() vpc = self.form_vpc_object(tier, single) # avoid prematurely timing out in the CLI when an environment is launched with a RDS DB if not timeout and database: timeout = 15 env_request = CreateEnvironmentRequest(app_name=app_name, env_name=env_name, group_name=group, cname=cname, template_name=template_name, platform=platform, tier=tier, instance_type=itype, version_label=label, instance_profile=iprofile, service_role=service_role, single_instance=single, key_name=key_name, sample_application=sample, tags=tags, scale=scale, database=database, vpc=vpc, elb_type=elb_type) env_request.option_settings += envvars createops.make_new_env(env_request, branch_default=branch_default, process_app_version=process_app_version, nohang=nohang, interactive=interactive, timeout=timeout, source=source)