lib/sles4sap/sap_deployment_automation_framework/subscription_cleanup.pm

new

my $cleanup_state = sles4sap::sap_deployment_automation_framework::subscription_cleanup->new();

Class is used to hold data structure containing all information regarding orphaned resources cleanup. Content of this object is preserved between calls of new() using state.

Structure:

_time_test

_time_test($input_time, $retention_sec);

Checks $input_time against $retention_sec. Returns '1' (true) if time is older than retention period, otherwise 0 (false).

_kql_query

my @kql = _kql_query(
    search_target => 'resourcecontainers',
    name_regex => '^SDAF-OpenQA-sap_system');

Returns an ARRAY of KQL statements for az_graph_query() which help finding resources matching following cleanup criteria:

Returned fields: id, name, deployment_id, openqa_created_date.

search_target Azure Resource Graph table to search. Mandatory.
name_regex RE2 regular expression for the resource name. Mandatory.

get_orphaned_resource_groups

my $cleanup_result = sles4sap::sap_deployment_automation_framework::subscription_cleanup->new();
$cleanup_result->get_orphaned_resource_groups();

Queries for all orphaned SDAF resource groups not meeting retention criteria and updates main class data. A workload zone is added only if a 'sap_system' resource group with the same deployment_id is already in the deletion list $self->{results}{sap_systems} or does not exist at all.

get_orphaned_resources

my $cleanup_result = sles4sap::sap_deployment_automation_framework::subscription_cleanup->new();
$cleanup_result->get_orphaned_resources();

Queries for all orphaned SDAF deployer VM resources not meeting retention criteria.

destroy_orphaned_groups

my $cleanup_result = sles4sap::sap_deployment_automation_framework::subscription_cleanup->new();
$cleanup_result->destroy_orphaned_groups();

Destroys all 'sap_system' and 'workload_zone' resource groups which were marked as orphaned by `get_orphaned_resource_groups()`. If 'sap_system' group fails to be deleted corresponding 'workload_zone' deletion is skipped to avoid unnecessary failure. With OpenQA setting 'SDAF_CLEANUP_DRYRUN' enabled, no resource group is deleted.

destroy_orphaned_resources

my $cleanup_result = sles4sap::sap_deployment_automation_framework::subscription_cleanup->new();
$cleanup_result->destroy_orphaned_resources();

Destroys all Deployer VM resources marked as orphaned. Resources are destroyed always in a batch according to a resource group they belong to. With OpenQA setting 'SDAF_CLEANUP_DRYRUN' enabled, no resource group is deleted.

_update_summary

$self->_update_summary();

Counts resources in all categories of $self->{results} and writes the counters into $self->{summary}.

export_cleanup_report

my $cleanup_result = sles4sap::sap_deployment_automation_framework::subscription_cleanup->new();
$cleanup_result->export_cleanup_report();

Updates summary counter to keep data up to date. Converts report data structure to json and uploads it as a log file.