in lib/muchos/ec2.py [0:0]
def init_request(self, hostname, services, sg_id):
associate_public_ip = True
if self.config.has_option("ec2", "associate_public_ip"):
associate_public_ip = (
self.config.get("ec2", "associate_public_ip").strip().lower()
== "true"
)
request = {
"NetworkInterfaces": [
{
"DeviceIndex": 0,
"AssociatePublicIpAddress": associate_public_ip,
"Groups": [sg_id],
}
]
}
if self.config.has_option("ec2", "subnet_id"):
request["NetworkInterfaces"][0]["SubnetId"] = self.config.get(
"ec2", "subnet_id"
)
if "worker" in services:
instance_type = self.config.get("ec2", "worker_instance_type")
else:
instance_type = self.config.get("ec2", "default_instance_type")
request["InstanceType"] = instance_type
request["InstanceInitiatedShutdownBehavior"] = self.config.get(
"ec2", "shutdown_behavior"
)
if not self.config.has_option("ec2", "aws_ami"):
exit("aws_ami property must be set!")
image_id = self.config.get("ec2", "aws_ami")
if not image_id:
exit("aws_ami property was not properly")
request["ImageId"] = image_id
request["BlockDeviceMappings"] = get_block_device_map(instance_type)
if self.config.has_option("ec2", "key_name"):
request["KeyName"] = self.config.get("ec2", "key_name")
return request