Best Python code snippet using localstack_python
ec2_asg_scheduled_action.py
Source:ec2_asg_scheduled_action.py
...97 request['StartTime'] = module.params.get('start_time')98 if module.params.get('end_time') != None:99 request['EndTime'] = module.params.get('end_time')100 return request101def delete_scheduled_action(client, module):102 changed = False103 actions = describe_scheduled_actions(client, module)104 if not "ScheduledUpdateGroupActions" in actions:105 return changed, actions106 xx = actions.get("ScheduledUpdateGroupActions")107 if len(xx) == 0:108 return changed, actions109 changed = True110 params = dict()111 params['AutoScalingGroupName'] = module.params.get('autoscaling_group_name')112 params['ScheduledActionName'] = module.params.get('scheduled_action_name')113 try:114 actions = client.delete_scheduled_action(**params)115 except botocore.exceptions.ClientError as e:116 module.fail_json(msg=str(e))117 return changed, actions118def describe_scheduled_actions(client, module):119 actions = dict()120 try:121 actions = client.describe_scheduled_actions(122 AutoScalingGroupName=module.params.get('autoscaling_group_name'),123 ScheduledActionNames=[module.params.get('scheduled_action_name')]124 )125 except botocore.exceptions.ClientError as e:126 pass127 return actions128def put_scheduled_update_group_action(client, module):129 changed = False130 params = format_request(module)131 exists = describe_scheduled_actions(client, module)132 xx = exists.get("ScheduledUpdateGroupActions")133 try:134 status = client.put_scheduled_update_group_action(**params)135 except botocore.exceptions.ClientError as e:136 module.fail_json(msg=str(e))137 if len(xx) == 0:138 changed = True139 else:140 xx = xx[0]141 exists = describe_scheduled_actions(client, module)142 yy = exists.get("ScheduledUpdateGroupActions")[0]143 if xx != yy:144 changed = True145 return changed, status146def main():147 argument_spec = ec2_argument_spec()148 argument_spec.update(dict(149 autoscaling_group_name=dict(default=None),150 scheduled_action_name=dict(default=None),151 start_time=dict(default=None),152 end_time=dict(default=None),153 recurrence=dict(default=None),154 min_size=dict(default=None, type='int'),155 max_size=dict(default=None, type='int'),156 desired_capacity=dict(default=None, type='int'),157 state=dict(default='present', choices=['present', 'absent'])158 )159 )160 module = AnsibleModule(argument_spec=argument_spec)161 state = module.params.get('state').lower()162 if not HAS_BOTO3:163 module.fail_json(msg='json and boto3 are required.')164 try:165 region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)166 client = boto3_conn(module, conn_type='client', resource='autoscaling', region=region, endpoint=ec2_url, **aws_connect_kwargs)167 except botocore.exceptions.NoCredentialsError, e:168 module.fail_json(msg="Can't authorize connection - " + str(e))169 if state == 'present':170 (changed, results) = put_scheduled_update_group_action(client, module)171 module.exit_json(changed=changed, results=results)172 else:173 (changed, results) = delete_scheduled_action(client, module)174 module.exit_json(changed=changed, results=results)175# import module snippets176from ansible.module_utils.basic import *177from ansible.module_utils.ec2 import *178if __name__ == '__main__':...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!