Răsfoiți Sursa

xdrtest script now accepts wildcards and/or multiple instance names

Fred Damstra [afs macbook] 3 ani în urmă
părinte
comite
824071f936
1 a modificat fișierele cu 11 adăugiri și 2 ștergeri
  1. 11 2
      bin/xdrtest

+ 11 - 2
bin/xdrtest

@@ -17,6 +17,7 @@
 #   xdrtest start openvpn
 import argparse
 import boto3
+import fnmatch
 import json
 import logging
 import os
@@ -117,7 +118,7 @@ if __name__ == "__main__":
     parser.add_argument('--profile', help='Profile to Use', default=None)
     parser.add_argument('--tagname', help='Tag Name to Filter On', default='Schedule')
     parser.add_argument('--tagvalue', help='Tag Value to Filter On', default='MSOC')
-    parser.add_argument('instancename', help='Instance Name or ID to action on', nargs='?', default=None)
+    parser.add_argument('instancename', help='One or more instance names or IDs to action on. Wildcards are allowed.', nargs='*', default=None)
     parser.add_argument('--commercial', help='Include Commercial Accounts', action='store_true')
     parser.add_argument('--dry-run', help='Dry Run', action='store_true')
     parser.add_argument('--debug', help='Output Debug Information', action='store_true')
@@ -158,7 +159,15 @@ if __name__ == "__main__":
        
         instances[p] = list()
         for instance in gather_instances(ec2[p], args.tagname, args.tagvalue, exclude_state):
-            if args.instancename is None or args.instancename == instance['name'] or args.instancename == instance['instance_id']:
+            if args.instancename:
+                # At least one instance name was specified, so go through and match
+                for i in args.instancename:
+                    if fnmatch.fnmatch(instance['name'], i):
+                        print(f'{p:<30}\t{ instance["instance_id"] }\t{instance["state"]:<10}\t{instance["name"]}')
+                        instances[p].append(instance['instance_id'])
+                        instance_count += 1
+            else:
+                # No instance name specified, we add everything
                 print(f'{p:<30}\t{ instance["instance_id"] }\t{instance["state"]:<10}\t{instance["name"]}')
                 instances[p].append(instance['instance_id'])
                 instance_count += 1