[Bps-public-commit] rt-extension-aws-assets branch sync-utility updated. 11fd2c2412c0dead768c70586fe982bbf6a78ac7

BPS Git Server git at git.bestpractical.com
Fri Mar 8 21:22:08 UTC 2024


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt-extension-aws-assets".

The branch, sync-utility has been updated
       via  11fd2c2412c0dead768c70586fe982bbf6a78ac7 (commit)
       via  e65c701671791bd1d3b3b0116d8fe672a7bc054a (commit)
       via  fb69a2ed8e0fa9577d7248a0341723db64f02355 (commit)
      from  9501e28e6a6762ca41fc827176e9cfa7491d7947 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 11fd2c2412c0dead768c70586fe982bbf6a78ac7
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Mar 8 16:09:24 2024 -0500

    Fix permissions on bin files

diff --git a/bin/rt-import-aws-assets.in b/bin/rt-import-aws-assets.in
old mode 100644
new mode 100755
diff --git a/bin/rt-unlink-retired-reservations.in b/bin/rt-unlink-retired-reservations.in
old mode 100644
new mode 100755
commit e65c701671791bd1d3b3b0116d8fe672a7bc054a
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Mar 8 15:52:46 2024 -0500

    Add script to unlink retired reservations

diff --git a/.gitignore b/.gitignore
index 4c72c95..f60c482 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,4 @@ pod2htm*.tmp
 /t/tmp
 /xt/tmp
 rt-import-aws-assets
+rt-unlink-retired-reservations
diff --git a/Changes b/Changes
index a63b939..fd5a0bd 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,8 @@
 Revision history for RT-Extension-AWS-Assets
 
+0.02 2024-03-08
+ - Add asset lifecycle config for reservations
+ - Add script to unlink retired reservations
+
 0.01 2024-02-13
  - Initial version
diff --git a/MANIFEST b/MANIFEST
index 4d54687..ef4ada6 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,5 +1,8 @@
 bin/rt-import-aws-assets.in
+bin/rt-unlink-retired-reservations.in
 Changes
+etc/AWSAssets_Config.pm
+etc/sample-initialdata.json
 html/AWS/LinkAsset.html
 html/Callbacks/RT-Extension-AWS-Assets/Asset/Display.html/BeforeProcessArguments
 html/Callbacks/RT-Extension-AWS-Assets/Elements/Tabs/Privileged
diff --git a/META.yml b/META.yml
index 143ceb3..c2ee531 100644
--- a/META.yml
+++ b/META.yml
@@ -16,6 +16,7 @@ meta-spec:
 name: RT-Extension-AWS-Assets
 no_index:
   directory:
+    - etc
     - html
     - inc
 requires:
@@ -24,7 +25,7 @@ requires:
 resources:
   license: http://opensource.org/licenses/gpl-license.php
   repository: https://github.com/bestpractical/rt-extension-aws-assets
-version: '0.01'
+version: '0.02'
 x_module_install_rtx_version: '0.43'
 x_requires_rt: 5.0.0
 x_rt_too_new: 5.2.0
diff --git a/Makefile.PL b/Makefile.PL
index 2438bf5..5c8cd86 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -31,7 +31,7 @@ substitute(
            {
         sufix => '.in'
     },
-           qw(bin/rt-import-aws-assets),
+           qw(bin/rt-import-aws-assets bin/rt-unlink-retired-reservations),
 );
 
 sign;
diff --git a/bin/rt-unlink-retired-reservations.in b/bin/rt-unlink-retired-reservations.in
new file mode 100644
index 0000000..ddab9ce
--- /dev/null
+++ b/bin/rt-unlink-retired-reservations.in
@@ -0,0 +1,91 @@
+#!/usr/bin/env perl
+### before: #!@PERL@
+
+use strict;
+use warnings;
+
+package RT::AWS::Assets::Run;
+
+BEGIN {
+### after:     use lib qw(@RT_LIB_PATH@);
+use lib '/opt/rt5/local/lib /opt/rt5/lib';
+use RT;
+}
+
+use RT::Interface::CLI  qw(GetCurrentUser loc);
+
+__PACKAGE__->run(@ARGV) unless caller;
+
+sub run{
+    my ($class, @args) = @_;
+
+    my %args = $class->process_args(@args);
+    require RT::Extension::AWS::Assets;
+
+    my $assets = RT::Assets->new(RT->SystemUser);
+    $assets->FromSQL("Catalog = 'AWS Reserved Instances' AND 'CF.{Reservation End}' < 'now' AND DependedOnBy IS NOT NULL");
+
+    while ( my $asset = $assets->Next ) {
+        my $depended_on_by = $asset->DependedOnBy;
+
+        while ( my $link = $depended_on_by->Next ) {
+            my ($ok, $msg) = $asset->DeleteLink( Type => 'DependsOn', Base => $link->Base );
+
+            RT->Logger->error("Unable to delete link for asset " . $asset->Id . ", $msg") unless $ok;
+        }
+    }
+
+    return;
+}
+
+sub process_args {
+    require Getopt::Long;
+    local @ARGV = @_;
+
+    my %opt;
+    RT::Interface::CLI::Init( \%opt, 'help|h' );
+
+    if ( delete $opt{help} ) {
+        require Pod::Usage;
+        Pod::Usage::pod2usage( { verbose => 2 } );
+        exit;
+    }
+
+    return %opt;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+rt-unlink-retired-reservations - remove links for retired reservations
+
+=head1 SYNOPSIS
+
+    rt-unlink-retired-reservations
+
+=head1 DESCRIPTION
+
+When a reservation is past its end date, it no longer provides a discount in
+AWS. This script runs the following query to find any reservations that are
+past the end date, but are still linked to an AWS resource asset:
+
+"Catalog = 'AWS Reserved Instances' AND 'CF.{Reservation End}' < 'now' AND DependedOnBy IS NOT NULL"
+
+It unlinks all found assets so it's clear those AWS resources may need a new
+reservation.
+
+=head1 OPTIONS
+
+=over
+
+=item B<--debug>
+
+Override the RT log settings and show log messages in the terminal at the
+debug level.
+
+=back
+
+=cut
diff --git a/lib/RT/Extension/AWS/Assets.pm b/lib/RT/Extension/AWS/Assets.pm
index 6702f3a..447fba8 100644
--- a/lib/RT/Extension/AWS/Assets.pm
+++ b/lib/RT/Extension/AWS/Assets.pm
@@ -7,7 +7,7 @@ use Paws::Credential::Explicit;
 
 use Data::Printer;
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 NAME
 
commit fb69a2ed8e0fa9577d7248a0341723db64f02355
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri Mar 8 15:51:12 2024 -0500

    Add asset lifecycle config for reservations

diff --git a/etc/AWSAssets_Config.pm b/etc/AWSAssets_Config.pm
new file mode 100644
index 0000000..193d8a4
--- /dev/null
+++ b/etc/AWSAssets_Config.pm
@@ -0,0 +1,85 @@
+
+Set(%Lifecycles,
+    'aws-assets' => {
+        type     => "asset",
+        initial  => [ 
+            'new' # loc
+        ],
+        active   => [ 
+            'running', # loc
+            'not-found', # loc
+        ],
+        inactive => [ 
+            'deleted' # loc
+        ],
+
+        defaults => {
+            on_create => 'new',
+        },
+
+        transitions => {
+            ''        => [qw(new running)],
+            new       => [qw(running not-found deleted)],
+            running   => [qw(new not-found deleted)],
+            'not-found' => [qw(new running deleted)],
+            deleted   => [qw(new running)],
+        },
+        rights => {
+            '* -> *'        => 'ModifyAsset',
+        },
+        actions => [
+            '* -> running' => { 
+                label => "Running" # loc
+            },
+            '* -> not-found'    => { 
+                label => "Not Found" # loc
+            },
+            '* -> deleted'  => { 
+                label => "Delete" # loc
+            },
+        ],
+    },
+    'aws-reservations' => {
+        type     => "asset",
+        initial  => [ 
+            'new' # loc
+        ],
+        active   => [ 
+            'payment-pending', # loc
+            'active' # loc
+        ],
+        inactive => [ 
+            'retired', # loc
+            'deleted' # loc
+        ],
+
+        defaults => {
+            on_create => 'new',
+        },
+
+        transitions => {
+            ''        => [qw(new payment-pending active)],
+            new       => [qw(payment-pending active retired deleted)],
+            'payment-pending' => [qw(new active retired deleted)],
+            active    => [qw(new payment-pending retired deleted)],
+            retired   => [qw(new payment-pending active deleted)],
+            deleted   => [qw(active retired)],
+        },
+        rights => {
+            '* -> *'        => 'ModifyAsset',
+        },
+        actions => [
+            '* -> active' => { 
+                label => "Activate" # loc
+            },
+            '* -> retired'    => { 
+                label => "Retire" # loc
+            },
+            '* -> deleted'  => { 
+                label => "Delete" # loc
+            },
+        ],
+    },
+);
+
+1;
-----------------------------------------------------------------------

Summary of changes:
 .gitignore                            |  1 +
 Changes                               |  4 ++
 MANIFEST                              |  3 ++
 META.yml                              |  3 +-
 Makefile.PL                           |  2 +-
 bin/rt-import-aws-assets.in           |  0
 bin/rt-unlink-retired-reservations.in | 91 +++++++++++++++++++++++++++++++++++
 etc/AWSAssets_Config.pm               | 85 ++++++++++++++++++++++++++++++++
 lib/RT/Extension/AWS/Assets.pm        |  2 +-
 9 files changed, 188 insertions(+), 3 deletions(-)
 mode change 100644 => 100755 bin/rt-import-aws-assets.in
 create mode 100755 bin/rt-unlink-retired-reservations.in
 create mode 100644 etc/AWSAssets_Config.pm


hooks/post-receive
-- 
rt-extension-aws-assets


More information about the Bps-public-commit mailing list