From 1ecc553616d43aca98aebf48092802d42ef104d6 Mon Sep 17 00:00:00 2001 From: Jose Caballero Bejar Date: Wed, 17 Jun 2026 08:44:28 +0100 Subject: [PATCH 1/2] Write first draft to find long term shutdown servers This implementation is just a first draft. For the time being, it just prints out the list of Servers found being in SHUTOFF state for longer than a given number of days. The main purpose of this is to validate the call to the query API. This function does not require unit testing, at least not yet. --- config.schema.yaml | 10 ++++++++ lib/workflows/find_shutdown_servers.py | 33 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/workflows/find_shutdown_servers.py diff --git a/config.schema.yaml b/config.schema.yaml index cc29826e3..ead285feb 100644 --- a/config.schema.yaml +++ b/config.schema.yaml @@ -207,6 +207,16 @@ hypervisor_sensor: type: "integer" description: "Number of seconds before forcefully deleting previous state to update hypervisors stuck in a state" +openstack_server_sensor: + description: "OpenStack Server sensors specific settings" + type: "object" + required: false + additionalProperties: false + properties: + shutoff_limit: + type: "number" + description: "Number of days a StackStorm server can be in SHUTOFF state before triggering the sensor" + flavor_sensor: description: "Flavor sensor specific settings." type: "object" diff --git a/lib/workflows/find_shutdown_servers.py b/lib/workflows/find_shutdown_servers.py new file mode 100644 index 000000000..d11e2048d --- /dev/null +++ b/lib/workflows/find_shutdown_servers.py @@ -0,0 +1,33 @@ +import logging + +from openstack.connection import Connection +from apis.openstack_query_api.server_queries import find_shutoff_servers + +logger = logging.getLogger(__name__) + + +def find_shutdown_servers( + conn: Connection, + minimum_days: int, +) -> None: + """ + Find servers in SHUTOFF state + + :param conn: openstack connection object + :type conn: Connection + :param minimum_days: minimum number of days a Server must be SHUTOFF to be included in the results + :type minimum_days: int + :return: None + :rtype: None + """ + logger.info( + "Finding all servers in SHUTOFF state for longer than %s days", minimum_days + ) + + servers_q = find_shutoff_servers( + cloud_account=conn.name, days_threshold=minimum_days + ) + # servers_q is an object of class ServerQuery + servers = servers_q.to_objects() + for server in servers: + logger.info("Found server with ID %s and Name %s", server.id, server.name) From 78d0f03962afd1e92878f50766d3e3318017bec1 Mon Sep 17 00:00:00 2001 From: Jose Caballero Bejar Date: Wed, 17 Jun 2026 09:06:25 +0100 Subject: [PATCH 2/2] write the action yaml config file --- actions/server.find.shutoff.yaml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 actions/server.find.shutoff.yaml diff --git a/actions/server.find.shutoff.yaml b/actions/server.find.shutoff.yaml new file mode 100644 index 000000000..796fd8beb --- /dev/null +++ b/actions/server.find.shutoff.yaml @@ -0,0 +1,29 @@ +--- +description: Find Servers in SHUTOFF state +enabled: true +entry_point: src/openstack_actions.py +name: server.find.shutoff +parameters: + lib_entry_point: + default: workflows.find_shutdown_servers.find_shutdown_servers + immutable: true + type: string + cloud_account: + description: The clouds.yaml account to use whilst performing this action + required: true + type: string + default: "dev" + enum: + - "dev" + - "prod" + minimum_days: + description: minimum number of days a server needs to be in SHUTOFF state to be included + required: true + type: integer + default: 30 + requires_openstack: + default: true + immutable: true + type: boolean + +runner_type: python-script