How to use describe_maintenance_windows method in localstack

Best Python code snippet using localstack_python

test_ssm_maintenance_windows.py

Source:test_ssm_maintenance_windows.py Github

copy

Full Screen

...3from moto import mock_ssm4@mock_ssm5def test_describe_maintenance_window():6 ssm = boto3.client("ssm", region_name="us-east-1")7 resp = ssm.describe_maintenance_windows()8 resp.should.have.key("WindowIdentities").equals([])9 resp = ssm.describe_maintenance_windows(10 Filters=[{"Key": "Name", "Values": ["fake-maintenance-window-name"]}]11 )12 resp.should.have.key("WindowIdentities").equals([])13@mock_ssm14def test_create_maintenance_windows_simple():15 ssm = boto3.client("ssm", region_name="us-east-1")16 resp = ssm.create_maintenance_window(17 Name="simple-window",18 Schedule="cron(15 12 * * ? *)",19 Duration=2,20 Cutoff=1,21 AllowUnassociatedTargets=False,22 )23 resp.should.have.key("WindowId")24 _id = resp["WindowId"] # mw-01d6bbfdf6af2c39a25 resp = ssm.describe_maintenance_windows()26 resp.should.have.key("WindowIdentities").have.length_of(1)27 my_window = resp["WindowIdentities"][0]28 my_window.should.have.key("WindowId").equal(_id)29 my_window.should.have.key("Name").equal("simple-window")30 my_window.should.have.key("Enabled").equal(True)31 my_window.should.have.key("Duration").equal(2)32 my_window.should.have.key("Cutoff").equal(1)33 my_window.should.have.key("Schedule").equal("cron(15 12 * * ? *)")34 # my_window.should.have.key("NextExecutionTime")35 my_window.shouldnt.have.key("Description")36 my_window.shouldnt.have.key("ScheduleTimezone")37 my_window.shouldnt.have.key("ScheduleOffset")38 my_window.shouldnt.have.key("EndDate")39 my_window.shouldnt.have.key("StartDate")40@mock_ssm41def test_create_maintenance_windows_advanced():42 ssm = boto3.client("ssm", region_name="us-east-1")43 resp = ssm.create_maintenance_window(44 Name="simple-window",45 Description="French windows are just too fancy",46 Schedule="cron(15 12 * * ? *)",47 ScheduleTimezone="Europe/London",48 ScheduleOffset=1,49 Duration=5,50 Cutoff=4,51 AllowUnassociatedTargets=False,52 StartDate="2021-11-01",53 EndDate="2021-12-31",54 )55 resp.should.have.key("WindowId")56 _id = resp["WindowId"] # mw-01d6bbfdf6af2c39a57 resp = ssm.describe_maintenance_windows()58 resp.should.have.key("WindowIdentities").have.length_of(1)59 my_window = resp["WindowIdentities"][0]60 my_window.should.have.key("WindowId").equal(_id)61 my_window.should.have.key("Name").equal("simple-window")62 my_window.should.have.key("Enabled").equal(True)63 my_window.should.have.key("Duration").equal(5)64 my_window.should.have.key("Cutoff").equal(4)65 my_window.should.have.key("Schedule").equal("cron(15 12 * * ? *)")66 # my_window.should.have.key("NextExecutionTime")67 my_window.should.have.key("Description").equals("French windows are just too fancy")68 my_window.should.have.key("ScheduleTimezone").equals("Europe/London")69 my_window.should.have.key("ScheduleOffset").equals(1)70 my_window.should.have.key("StartDate").equals("2021-11-01")71 my_window.should.have.key("EndDate").equals("2021-12-31")72@mock_ssm73def test_get_maintenance_windows():74 ssm = boto3.client("ssm", region_name="us-east-1")75 resp = ssm.create_maintenance_window(76 Name="my-window",77 Schedule="cron(15 12 * * ? *)",78 Duration=2,79 Cutoff=1,80 AllowUnassociatedTargets=False,81 )82 resp.should.have.key("WindowId")83 _id = resp["WindowId"] # mw-01d6bbfdf6af2c39a84 my_window = ssm.get_maintenance_window(WindowId=_id)85 my_window.should.have.key("WindowId").equal(_id)86 my_window.should.have.key("Name").equal("my-window")87 my_window.should.have.key("Enabled").equal(True)88 my_window.should.have.key("Duration").equal(2)89 my_window.should.have.key("Cutoff").equal(1)90 my_window.should.have.key("Schedule").equal("cron(15 12 * * ? *)")91 # my_window.should.have.key("NextExecutionTime")92 my_window.shouldnt.have.key("Description")93 my_window.shouldnt.have.key("ScheduleTimezone")94 my_window.shouldnt.have.key("ScheduleOffset")95 my_window.shouldnt.have.key("EndDate")96 my_window.shouldnt.have.key("StartDate")97@mock_ssm98def test_describe_maintenance_windows():99 ssm = boto3.client("ssm", region_name="us-east-1")100 for idx in range(0, 4):101 ssm.create_maintenance_window(102 Name=f"window_{idx}",103 Schedule="cron(15 12 * * ? *)",104 Duration=2,105 Cutoff=1,106 AllowUnassociatedTargets=False,107 )108 resp = ssm.describe_maintenance_windows()109 resp.should.have.key("WindowIdentities").have.length_of(4)110 resp = ssm.describe_maintenance_windows(111 Filters=[{"Key": "Name", "Values": ["window_0", "window_2"]}]112 )113 resp.should.have.key("WindowIdentities").have.length_of(2)114@mock_ssm115def test_delete_maintenance_windows():116 ssm = boto3.client("ssm", region_name="us-east-1")117 resp = ssm.create_maintenance_window(118 Name="simple-window",119 Schedule="cron(15 12 * * ? *)",120 Duration=2,121 Cutoff=1,122 AllowUnassociatedTargets=False,123 )124 ssm.delete_maintenance_window(WindowId=(resp["WindowId"]))125 resp = ssm.describe_maintenance_windows()...

Full Screen

Full Screen

tag_instance.py

Source:tag_instance.py Github

copy

Full Screen

...11ssm = boto3.client('ssm')12tags ={'Key': os.environ['Tagname'], 'Value': os.environ['Tagvalue']}13def find_viable_window ():14 #checks if the Tag Key value pair matches with an existing Maintenance Window15 wins = ssm.describe_maintenance_windows()['WindowIdentities']16 for win in wins:17 tgts = ssm.describe_maintenance_window_targets(WindowId=win['WindowId'])['Targets']18 for tgt in tgts:19 t = tgt['Targets'][0]['Key'].split(':')20 v = tgt['Targets'][0]['Values'][0]21 if len(t) > 1 and t[0] == 'tag' and t[1] == tags['Key'] and v == tags['Value']:22 return True;23 return False;24def lambda_handler(event, context):25 volume =(event['resources'][0].split('/')[1])26 if event['detail']['result'] == 'completed':27 attach=ec2.describe_volumes(VolumeIds=[volume])['Volumes'][0]['Attachments']28 if attach: 29 instance = attach[0]['InstanceId']...

Full Screen

Full Screen

describe_ssm_maintenance_windows.py

Source:describe_ssm_maintenance_windows.py Github

copy

Full Screen

...14 ssm_client = boto3.client('ssm', region_name = j )15 16 next_token = None17 while True:18 response6 = ssm_client.describe_maintenance_windows(NextToken= next_token) if next_token else ssm_client.describe_maintenance_windows()19 print(response6['WindowIdentities']) 20 for p in response6['WindowIdentities']:21 status_var6 = p['Enabled']22 print(status_var6)23 stat = "Enabled"24 rank = 025 if status_var6 == True:26 rank = 2*827 stat = "Enabled"28 if status_var6== False:29 rank = 0.25*830 stat = "Disabled"31 32 ...

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