Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 def get_console_output(self):
     instance_id = self.instance_ids[0]
     instance = ec2_backend.get_instance(instance_id)
     if instance:
         template = Template(GET_CONSOLE_OUTPUT_RESULT)
         return template.render(instance=instance)
     else:
         return "", dict(status=404)
Ejemplo n.º 4
0
 def get_console_output(self):
     self.instance_ids = instance_ids_from_querystring(self.querystring)
     instance_id = self.instance_ids[0]
     instance = ec2_backend.get_instance(instance_id)
     if instance:
         template = Template(GET_CONSOLE_OUTPUT_RESULT)
         return template.render(instance=instance)
     else:
         return "", dict(status=404)
Ejemplo n.º 5
0
def test_modify_attribute_blockDeviceMapping():
    """
    Reproduces the missing feature explained at [0], where we want to mock a
    call to modify an instance attribute of type: blockDeviceMapping.

    [0] https://github.com/spulec/moto/issues/160
    """
    conn = boto.connect_ec2('the_key', 'the_secret')

    reservation = conn.run_instances('ami-1234abcd')

    instance = reservation.instances[0]

    instance.modify_attribute('blockDeviceMapping', {'/dev/sda1': True})

    instance = ec2_backend.get_instance(instance.id)
    instance.block_device_mapping.should.have.key('/dev/sda1')
    instance.block_device_mapping['/dev/sda1'].delete_on_termination.should.be(True)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
 def get_console_output(self):
     self.instance_ids = instance_ids_from_querystring(self.querystring)
     instance_id = self.instance_ids[0]
     instance = ec2_backend.get_instance(instance_id)
     template = Template(GET_CONSOLE_OUTPUT_RESULT)
     return template.render(instance=instance)