def _getProfileARN(cls, ctx): def addRoleErrors(e): return e.status == 404 def throttleError(e): return isinstance( e, BotoServerError ) and e.status == 400 and e.error_code == 'Throttling' for attempt in retry(delays=truncExpBackoff(), predicate=throttleError): with attempt: roleName = 'toil' policy = dict(iam_full=iamFullPolicy, ec2_full=ec2FullPolicy, s3_full=s3FullPolicy, sbd_full=sdbFullPolicy) iamRoleName = ctx.setup_iam_ec2_role(role_name=roleName, policies=policy) try: profile = ctx.iam.get_instance_profile(iamRoleName) except BotoServerError as e: if e.status == 404: profile = ctx.iam.create_instance_profile(iamRoleName) profile = profile.create_instance_profile_response.create_instance_profile_result else: raise else: profile = profile.get_instance_profile_response.get_instance_profile_result profile = profile.instance_profile profile_arn = profile.arn if len(profile.roles) > 1: raise RuntimeError( 'Did not expect profile to contain more than one role') elif len(profile.roles) == 1: # this should be profile.roles[0].role_name if profile.roles.member.role_name == iamRoleName: return profile_arn else: ctx.iam.remove_role_from_instance_profile( iamRoleName, profile.roles.member.role_name) for attempt in retry(predicate=addRoleErrors): with attempt: ctx.iam.add_role_to_instance_profile( iamRoleName, iamRoleName) return profile_arn
def wrapper(*args, **kwargs): for attempt in old_retry(delays=truncExpBackoff(), timeout=300, predicate=googleRetryPredicate): with attempt: return f(*args, **kwargs)