def associate_address(self): instance = eni = None if "InstanceId" in self.querystring: instance = ec2_backend.get_instance(self.querystring['InstanceId'][0]) elif "NetworkInterfaceId" in self.querystring: eni = ec2_backend.get_network_interface(self.querystring['NetworkInterfaceId'][0]) else: ec2_backend.raise_error("MissingParameter", "Invalid request, expect InstanceId/NetworkId parameter.") reassociate = False if "AllowReassociation" in self.querystring: reassociate = self.querystring['AllowReassociation'][0] == "true" if instance or eni: if "PublicIp" in self.querystring: eip = ec2_backend.associate_address(instance=instance, eni=eni, address=self.querystring['PublicIp'][0], reassociate=reassociate) elif "AllocationId" in self.querystring: eip = ec2_backend.associate_address(instance=instance, eni=eni, allocation_id=self.querystring['AllocationId'][0], reassociate=reassociate) else: ec2_backend.raise_error("MissingParameter", "Invalid request, expect PublicIp/AllocationId parameter.") else: ec2_backend.raise_error("MissingParameter", "Invalid request, expect either instance or ENI.") template = Template(ASSOCIATE_ADDRESS_RESPONSE) return template.render(address=eip)
def associate_address(self): if "InstanceId" in self.querystring: instance = ec2_backend.get_instance( self.querystring['InstanceId'][0]) elif "NetworkInterfaceId" in self.querystring: raise NotImplementedError( "Lookup by allocation id not implemented") else: return "Invalid request, expect InstanceId/NetworkId parameter.", dict( status=400) reassociate = False if "AllowReassociation" in self.querystring: reassociate = self.querystring['AllowReassociation'][0] == "true" if "PublicIp" in self.querystring: eip = ec2_backend.associate_address( instance, address=self.querystring['PublicIp'][0], reassociate=reassociate) elif "AllocationId" in self.querystring: eip = ec2_backend.associate_address( instance, allocation_id=self.querystring['AllocationId'][0], reassociate=reassociate) else: return "Invalid request, expect PublicIp/AllocationId parameter.", dict( status=400) if eip: template = Template(ASSOCIATE_ADDRESS_RESPONSE) return template.render(address=eip) else: return "Failed to associate address.", dict(status=400)
def associate_address(self): if "InstanceId" in self.querystring: instance = ec2_backend.get_instance(self.querystring['InstanceId'][0]) elif "NetworkInterfaceId" in self.querystring: raise NotImplementedError("Lookup by allocation id not implemented") else: return "Invalid request, expect InstanceId/NetworkId parameter.", dict(status=400) reassociate = False if "AllowReassociation" in self.querystring: reassociate = self.querystring['AllowReassociation'][0] == "true" if "PublicIp" in self.querystring: eip = ec2_backend.associate_address(instance, address=self.querystring['PublicIp'][0], reassociate=reassociate) elif "AllocationId" in self.querystring: eip = ec2_backend.associate_address(instance, allocation_id=self.querystring['AllocationId'][0], reassociate=reassociate) else: return "Invalid request, expect PublicIp/AllocationId parameter.", dict(status=400) if eip: template = Template(ASSOCIATE_ADDRESS_RESPONSE) return template.render(address=eip) else: return "Failed to associate address.", dict(status=400)