File 632.patch of Package fence-agents.42844
diff -urp fence-agents-4.12.1+git.1677142927.bf55c675-orig/agents/aws/fence_aws.py fence-agents-4.12.1+git.1677142927.bf55c675/agents/aws/fence_aws.py
--- fence-agents-4.12.1+git.1677142927.bf55c675-orig/agents/aws/fence_aws.py 2023-02-23 10:02:07.000000000 +0100
+++ fence-agents-4.12.1+git.1677142927.bf55c675/agents/aws/fence_aws.py 2025-09-23 17:31:31.176460277 +0200
@@ -12,7 +12,7 @@ from requests import HTTPError
try:
import boto3
- from botocore.exceptions import ConnectionError, ClientError, EndpointConnectionError, NoRegionError
+ from botocore.exceptions import ConnectionError, ClientError, EndpointConnectionError, NoRegionError, ParamValidationError
except ImportError:
pass
@@ -102,14 +102,28 @@ def get_self_power_status(conn, instance
def set_power_status(conn, options):
my_instance = get_instance_id()
try:
+ if options.get("--skip-os-shutdown", "false").lower() in ["1", "yes", "on", "true"]:
+ shutdown_option = {
+ "SkipOsShutdown": True,
+ "Force": True
+ }
+ else:
+ shutdown_option = {
+ "SkipOsShutdown": False,
+ "Force": True
+ }
if (options["--action"]=="off"):
if (get_self_power_status(conn,my_instance) == "ok"):
- conn.instances.filter(InstanceIds=[options["--plug"]]).stop(Force=True)
+ conn.instances.filter(InstanceIds=[options["--plug"]]).stop(**shutdown_option)
logger.info("Called StopInstance API call for %s", options["--plug"])
else:
logger.info("Skipping fencing as instance is not in running status")
elif (options["--action"]=="on"):
conn.instances.filter(InstanceIds=[options["--plug"]]).start()
+ except ParamValidationError:
+ if (options["--action"] == "off"):
+ logger.warning(f"SkipOsShutdown not supported with the current boto3 version {boto3.__version__} - falling back to graceful shutdown")
+ conn.instances.filter(InstanceIds=[options["--plug"]]).stop(Force=True)
except Exception as e:
logger.error("Failed to power %s %s: %s", \
options["--action"], options["--plug"], e)
@@ -156,12 +170,21 @@ def define_new_opts():
"default": "False",
"order": 6
}
+ all_opt["skip_os_shutdown"] = {
+ "getopt": ":",
+ "longopt": "skip-os-shutdown",
+ "help": "--skip-os-shutdown=[on|off] Uses SkipOsShutdown flag",
+ "shortdesc": "Use SkipOsShutdown flag to stop the EC2 instance",
+ "required": "0",
+ "default": "true",
+ "order": 8
+ }
# Main agent method
def main():
conn = None
- device_opt = ["port", "no_password", "region", "access_key", "secret_key", "filter", "boto3_debug"]
+ device_opt = ["port", "no_password", "region", "access_key", "secret_key", "filter", "boto3_debug", "skip_os_shutdown"]
atexit.register(atexit_handler)
diff -urp fence-agents-4.12.1+git.1677142927.bf55c675-orig/tests/data/metadata/fence_aws.xml fence-agents-4.12.1+git.1677142927.bf55c675/tests/data/metadata/fence_aws.xml
--- fence-agents-4.12.1+git.1677142927.bf55c675-orig/tests/data/metadata/fence_aws.xml 2023-02-23 10:02:07.000000000 +0100
+++ fence-agents-4.12.1+git.1677142927.bf55c675/tests/data/metadata/fence_aws.xml 2025-09-23 17:31:54.616640212 +0200
@@ -46,6 +46,11 @@ For instructions see: https://boto3.read
<content type="string" default="False" />
<shortdesc lang="en">Boto Lib debug</shortdesc>
</parameter>
+ <parameter name="skip_os_shutdown" unique="0" required="0">
+ <getopt mixed="--skip-os-shutdown=[on|off]" />
+ <content type="string" default="true" />
+ <shortdesc lang="en">Use SkipOsShutdown flag to stop the EC2 instance</shortdesc>
+ </parameter>
<parameter name="quiet" unique="0" required="0">
<getopt mixed="-q, --quiet" />
<content type="boolean" />