in awsbatch-cli/src/awsbatch/common.py [0:0]
def __init_from_stack(self, cluster, log): # noqa: C901 FIXME
"""
Init object attributes by asking to the stack.
:param cluster: cluster name
:param log: log
"""
try:
self.stack_name = cluster
log.info("Describing stack (%s)" % self.stack_name)
# get required values from the output of the describe-stack command
# don't use proxy because we are in the client and use default region
boto3_factory = Boto3ClientFactory(region=self.region)
cfn_client = boto3_factory.get_client("cloudformation")
stack = cfn_client.describe_stacks(StackName=self.stack_name).get("Stacks")[0]
log.debug(stack)
if self.region is None:
self.region = get_region_by_stack_id(stack.get("StackId"))
self.proxy = "NONE"
scheduler = None
stack_status = stack.get("StackStatus")
if stack_status in ["CREATE_COMPLETE", "UPDATE_COMPLETE"]:
for output in stack.get("Outputs", []):
output_key = output.get("OutputKey")
output_value = output.get("OutputValue")
if output_key == "BatchComputeEnvironmentArn":
self.compute_environment = output_value
elif output_key == "BatchJobQueueArn":
self.job_queue = output_value
elif output_key == "BatchJobDefinitionArn":
self.job_definition = output_value
elif output_key == "HeadNodePrivateIP":
self.head_node_ip = output_value
elif output_key == "BatchJobDefinitionMnpArn":
self.job_definition_mnp = output_value
elif output_key == "BatchCliRequirements":
self.batch_cli_requirements = output_value
for parameter in stack.get("Parameters", []):
parameter_key = parameter.get("ParameterKey")
parameter_value = parameter.get("ParameterValue")
if parameter_key == "ProxyServer":
self.proxy = parameter_value
if self.proxy != "NONE":
log.info("Configured proxy is: %s" % self.proxy)
elif parameter_key == "ResourcesS3Bucket":
self.s3_bucket = parameter_value
elif parameter_key == "ArtifactS3RootDirectory":
self.artifact_directory = parameter_value
elif parameter_key == "Scheduler":
scheduler = parameter_value
else:
fail(f"The cluster is in the ({stack_status}) status.")
if scheduler is None:
fail("Unable to retrieve cluster's scheduler. Double check CloudFormation stack parameters.")
elif scheduler != "awsbatch":
fail(f"This command cannot be used with a {scheduler} cluster.")
except (ClientError, ParamValidationError) as e:
fail("Error getting cluster information from AWS CloudFormation. Failed with exception: %s" % e)