How to use create_patch_baseline method in localstack

Best Python code snippet using localstack_python

ssm_patching_setup.py

Source:ssm_patching_setup.py Github

copy

Full Screen

...25 logging.basicConfig(level=args.loglevel)26 region = get_region(args.region)27 logging.info('Using region %s', region)28 ssm_client = boto3.client('ssm', region_name=region)29 baseline_id = create_patch_baseline(ssm_client, args.baseline_file)30 for week in args.weeks:31 for day in args.days:32 for hour in args.hours:33 # String formatting for 'Patch Group' tag34 patch_group = "Week {0} Day {1} - Unattended - {2}:00".format(35 str(week), str(day), str(hour).zfill(2))36 # String formatting for Maintenance Window name37 mw_name = "Week{0}Day{1}Unattended{2}00".format(38 str(week), str(day), str(hour).zfill(2))39 # String formatting for Maintenance Window cron schedule40 mw_schedule = "cron(00 {2} ? * {1}#{0} *)".format(41 str(week), calendar.day_abbr[day-1].upper(), str(hour).zfill(2))42 mw_timezone = args.timezone43 register_baseline_patch_group(ssm_client, baseline_id, patch_group)44 mw_id = create_maintenance_window(ssm_client, mw_name, mw_schedule, mw_timezone)45 target_id = register_patch_group_maintenance_window(ssm_client, mw_id, patch_group)46 register_task(ssm_client, mw_id, target_id)47def parse_args():48 """Create arguments and populate variables from args.49 Return args namespace"""50 parser = argparse.ArgumentParser()51 parser.add_argument('-w', '--weeks', type=int, choices=range(1, 6), nargs='+', default=[1, 2],52 help='Weeks to create maintenance windows (Note: Not full week)')53 parser.add_argument('-d', '--days', type=int, choices=range(0, 8), nargs='+', default=[2, 3],54 help='Days to create maintenance windows (0 = Sunday)')55 parser.add_argument('-t', '--hours', type=int, choices=range(0, 24), nargs='+', default=[3, 4],56 help='Hours (time) to create maintenance windows (0 = Midnight)')57 parser.add_argument('-z', '--timezone', type=str, default=False,58 help='Timezone for maintenance window schedules (TZ database name)')59 parser.add_argument('-r', '--region', type=str, help='AWS region', default=False)60 parser.add_argument('-b', '--baseline-file', type=str, required=True,61 help='File containing Patch Baseline properties')62 parser.add_argument('-l', '--loglevel', type=str,63 choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],64 help='Logging/output verbosity')65 return parser.parse_args()66def create_patch_baseline(ssm_client, baseline_file):67 """Create Patch Baseline.68 Return Baseline ID69 """70 logging.info('Creating Patch Baseline from file %s', baseline_file)71 # Let natural exception be raised if the file cannot be read72 with open(baseline_file, "r") as baseline_file_handle:73 baseline_data = json.load(baseline_file_handle)74 baseline = ssm_client.create_patch_baseline(**baseline_data)75 if baseline['BaselineId']:76 print("Created Patch Baseline {0}".format(baseline['BaselineId']))77 else:78 raise Exception('Failed to create Patch Baseline')79 return baseline['BaselineId']80def register_baseline_patch_group(ssm_client, baseline_id, patch_group):81 """Register Patch Baseline for Patch Group."""82 response = ssm_client.register_patch_baseline_for_patch_group(BaselineId=baseline_id,83 PatchGroup=patch_group)84 if response['PatchGroup']:85 print('Registered Patch Baseline {0} for Patch Group {1}'.format(baseline_id, patch_group))86 else:87 logging.warning('Failed to register Patch Baseline %s for Patch Group %s',88 baseline_id, patch_group)...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...15 return BaselineID16 17def CreateLinuxBaseline(ssm, OS, group, product, severity, classification, rejectpatches):18 try:19 Baseline = ssm.create_patch_baseline(20 OperatingSystem=OS,21 Name=group,22 ApprovalRules={23 'PatchRules': [24 {25 'PatchFilterGroup': {26 'PatchFilters': [27 {28 'Key': 'PRODUCT',29 'Values': product30 },31 {32 'Key': 'CLASSIFICATION',33 'Values': classification34 },35 {36 'Key': 'SEVERITY',37 'Values': severity38 }39 ]40 },41 'ApproveAfterDays': 0,42 'EnableNonSecurity': True43 }44 ]45 },46 ApprovedPatchesEnableNonSecurity=True,47 RejectedPatches=rejectpatches,48 RejectedPatchesAction='BLOCK'49 )50 print("Create %s Baseline Successfully!" %group)51 BaselineID = Baseline['BaselineId']52 return BaselineID53 except:54 print("Create %s Baseline Failed!" %group)55 e=sys.exc_info()[1]56 print("%s" %e)57 58def CreateWindowsBaseline(ssm, OS, group, product, severity, classification, rejectpatches):59 try:60 Baseline = ssm.create_patch_baseline(61 OperatingSystem=OS,62 Name=group,63 ApprovalRules={64 'PatchRules': [65 {66 'PatchFilterGroup': {67 'PatchFilters': [68 {69 'Key': 'PRODUCT',70 'Values': product71 },72 {73 'Key': 'CLASSIFICATION',74 'Values': classification...

Full Screen

Full Screen

patchbaseline-datasource.py

Source:patchbaseline-datasource.py Github

copy

Full Screen

1# ==============Create Ptach Baseline===================================================2response = client.create_patch_baseline(3 OperatingSystem='WINDOWS'|'AMAZON_LINUX'|'AMAZON_LINUX_2'|'UBUNTU'|'REDHAT_ENTERPRISE_LINUX'|'SUSE'|'CENTOS'|'ORACLE_LINUX'|'DEBIAN',4 Name='string',5 GlobalFilters={6 'PatchFilters': [7 {8 'Key': 'PATCH_SET'|'PRODUCT'|'PRODUCT_FAMILY'|'CLASSIFICATION'|'MSRC_SEVERITY'|'PATCH_ID'|'SECTION'|'PRIORITY'|'SEVERITY',9 'Values': [10 'string',11 ]12 },13 ]14 },15 ApprovalRules={16 'PatchRules': [...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful