コード例 #1
0
def detach_instance_volume(
    client: boto3.client, force: bool, asg_name: str, volume_data: Dict[str, str]
) -> AWSResponse:
    try:
        response = client.detach_volume(
            Device=volume_data["DeviceName"],
            InstanceId=volume_data["InstanceId"],
            VolumeId=volume_data["VolumeId"],
            Force=force,
        )

        # tag volume with instance information (to reattach on rollback)
        client.create_tags(
            Resources=[volume_data["VolumeId"]],
            Tags=[
                {
                    "Key": "ChaosToolkitDetached",
                    "Value": "DeviceName=%s;InstanceId=%s;ASG=%s"
                    % (volume_data["DeviceName"], volume_data["InstanceId"], asg_name),
                }
            ],
        )
        return response
    except ClientError as e:
        raise FailedActivity(
            "unable to detach volume %s from %s: %s"
            % (
                volume_data["VolumeId"],
                volume_data["InstanceId"],
                e.response["Error"]["Message"],
            )
        )
コード例 #2
0
ファイル: actions.py プロジェクト: xpdable/chaostoolkit-aws
def detach_instance_volume(client: boto3.client,
                           force: bool,
                           volume: Dict[str, str]) -> AWSResponse:
    """
    Detach volume from an instance
    """
    try:
        response = client.detach_volume(
            Device=volume['DeviceName'],
            InstanceId=volume['InstanceId'],
            VolumeId=volume['VolumeId'],
            Force=force)

        # tag volume with instance information (to reattach on rollback)
        client.create_tags(
            Resources=[volume['VolumeId']],
            Tags=[
                {
                    'Key': 'ChaosToolkitDetached',
                    'Value': 'DeviceName=%s;InstanceId=%s' % (
                        volume['DeviceName'], volume['InstanceId'])
                }])
        return response
    except ClientError as e:
        raise FailedActivity('unable to detach volume %s from %s: %s' % (
            volume['VolumeId'], volume['InstanceId'],
            e.response['Error']['Message']))