Best Python code snippet using localstack_python
dellemc_isilon_snapshotschedule.py
Source:dellemc_isilon_snapshotschedule.py  
...424                format(snapshot_schedule_details['schedules'][0]['name'],425                       error_msg)426            LOG.error(error_message)427            self.module.fail_json(msg=error_message)428    def modify_snapshot_schedule(self, name,429                                 snapshot_schedule_modification_details):430        """Modify snapshot schedule"""431        snapshot_schedule_update_param = self.isi_sdk.SnapshotSchedule()432        try:433            if 'alias' in snapshot_schedule_modification_details:434                snapshot_schedule_update_param.alias = \435                    snapshot_schedule_modification_details['alias']436            if 'pattern' in snapshot_schedule_modification_details:437                snapshot_schedule_update_param.pattern = \438                    snapshot_schedule_modification_details['pattern']439            if 'schedule' in snapshot_schedule_modification_details:440                snapshot_schedule_update_param.schedule = \441                    snapshot_schedule_modification_details['schedule']442            if 'duration' in snapshot_schedule_modification_details:443                snapshot_schedule_update_param.duration = \444                    snapshot_schedule_modification_details['duration']445            self.api_instance.update_snapshot_schedule(446                snapshot_schedule_update_param, name)447            return True448        except Exception as e:449            error_msg = self.determine_error(error_obj=e)450            error_message = 'Failed to modify snapshot schedule {0} with ' \451                            'error : {1}'.format(name, error_msg)452            LOG.error(error_message)453            self.module.fail_json(msg=error_message)454    def delete_snapshot_schedule(self, name):455        """Delete snapshot schedule"""456        try:457            self.api_instance.delete_snapshot_schedule(name)458            return True459        except Exception as e:460            error_msg = self.determine_error(error_obj=e)461            error_message = 'Failed to delete snapshot schedule: {0} with ' \462                            'error: {1}'.format(name, error_msg)463            LOG.error(error_message)464            self.module.fail_json(msg=error_message)465    def determine_error(self, error_obj):466        """Determine the error message to return"""467        if isinstance(error_obj, utils.ApiException):468            error = re.sub("[\n \"]+", ' ', str(error_obj.body))469        else:470            error = error_obj471        return error472    def perform_module_operation(self):473        """474        Perform different actions on snapshot schedule module based on475        parameters chosen in playbook476        """477        name = self.module.params['name']478        state = self.module.params['state']479        access_zone = self.module.params['access_zone']480        path = self.module.params['path']481        new_name = self.module.params['new_name']482        pattern = self.module.params['pattern']483        schedule = self.module.params['schedule']484        desired_retention = self.module.params['desired_retention']485        retention_unit = self.module.params['retention_unit']486        alias = self.module.params['alias']487        # result is a dictionary that contains changed status and snapshot488        # schedule details489        result = dict(490            changed=False,491            snapshot_schedule_details=''492        )493        effective_path = None494        if access_zone is not None:495            if access_zone.lower() == 'system':496                effective_path = path497            else:498                if path:499                    effective_path = self.get_zone_base_path(access_zone) + \500                        path501        if desired_retention:502            self.validate_desired_retention(desired_retention)503        snapshot_schedule_details = self.get_details(name)504        is_schedule_modified = False505        snapshot_schedule_modification_details = dict()506        if snapshot_schedule_details is not None:507            is_schedule_modified, snapshot_schedule_modification_details = \508                self.check_snapshot_schedule_modified(509                    snapshot_schedule_details, alias, desired_retention,510                    retention_unit, effective_path, pattern, schedule)511        if state == 'present' and not snapshot_schedule_details:512            LOG.info("Creating new snapshot schedule: %s for path: %s",513                     name, effective_path)514            result['changed'] = self.create_snapshot_schedule(515                name, alias, effective_path, desired_retention,516                retention_unit, pattern, schedule) or result['changed']517        if state == 'present' and new_name is not None:518            if len(new_name) == 0:519                self.module.fail_json(msg="Please provide valid string for "520                                          "new_name")521            if snapshot_schedule_details is None:522                self.module.fail_json(msg="Snapshot schedule not found.")523            if new_name != snapshot_schedule_details['schedules'][0]['name']:524                self.validate_new_name(new_name)525                LOG.info("Renaming snapshot schedule %s to new name %s",526                         name, new_name)527                result['changed'] = self.rename_snapshot_schedule(528                    snapshot_schedule_details, new_name) or result['changed']529                name = new_name530        if state == 'present' and is_schedule_modified:531            LOG.info("Modifying snapshot schedule %s", name)532            result['changed'] = self.modify_snapshot_schedule(533                name, snapshot_schedule_modification_details) or \534                result['changed']535        if state == 'absent' and snapshot_schedule_details:536            LOG.info("Deleting snapshot schedule %s", name)537            result['changed'] = self.delete_snapshot_schedule(name) or \538                result['changed']539        snapshot_schedule_details = self.get_details(name)540        result['snapshot_schedule_details'] = snapshot_schedule_details541        self.module.exit_json(**result)542def get_isilon_snapshotschedule_parameters():543    """This method provide parameters required for the ansible snapshot544    schedule module on Isilon"""545    return dict(546        name=dict(required=True, type='str'),...snapshotschedule.py
Source:snapshotschedule.py  
...408                format(snapshot_schedule_details['schedules'][0]['name'],409                       error_msg)410            LOG.error(error_message)411            self.module.fail_json(msg=error_message)412    def modify_snapshot_schedule(self, name,413                                 snapshot_schedule_modification_details):414        """Modify snapshot schedule"""415        snapshot_schedule_update_param = self.isi_sdk.SnapshotSchedule()416        try:417            if 'alias' in snapshot_schedule_modification_details:418                snapshot_schedule_update_param.alias = \419                    snapshot_schedule_modification_details['alias']420            if 'pattern' in snapshot_schedule_modification_details:421                snapshot_schedule_update_param.pattern = \422                    snapshot_schedule_modification_details['pattern']423            if 'schedule' in snapshot_schedule_modification_details:424                snapshot_schedule_update_param.schedule = \425                    snapshot_schedule_modification_details['schedule']426            if 'duration' in snapshot_schedule_modification_details:427                snapshot_schedule_update_param.duration = \428                    snapshot_schedule_modification_details['duration']429            self.api_instance.update_snapshot_schedule(430                snapshot_schedule_update_param, name)431            return True432        except Exception as e:433            error_msg = self.determine_error(error_obj=e)434            error_message = 'Failed to modify snapshot schedule {0} with ' \435                            'error : {1}'.format(name, error_msg)436            LOG.error(error_message)437            self.module.fail_json(msg=error_message)438    def delete_snapshot_schedule(self, name):439        """Delete snapshot schedule"""440        try:441            self.api_instance.delete_snapshot_schedule(name)442            return True443        except Exception as e:444            error_msg = self.determine_error(error_obj=e)445            error_message = 'Failed to delete snapshot schedule: {0} with ' \446                            'error: {1}'.format(name, error_msg)447            LOG.error(error_message)448            self.module.fail_json(msg=error_message)449    def determine_error(self, error_obj):450        """Determine the error message to return"""451        if isinstance(error_obj, utils.ApiException):452            error = re.sub("[\n \"]+", ' ', str(error_obj.body))453        else:454            error = error_obj455        return error456    def perform_module_operation(self):457        """458        Perform different actions on snapshot schedule module based on459        parameters chosen in playbook460        """461        name = self.module.params['name']462        state = self.module.params['state']463        access_zone = self.module.params['access_zone']464        path = self.module.params['path']465        new_name = self.module.params['new_name']466        pattern = self.module.params['pattern']467        schedule = self.module.params['schedule']468        desired_retention = self.module.params['desired_retention']469        retention_unit = self.module.params['retention_unit']470        alias = self.module.params['alias']471        # result is a dictionary that contains changed status and snapshot472        # schedule details473        result = dict(474            changed=False,475            snapshot_schedule_details=''476        )477        effective_path = None478        if path:479            if access_zone.lower() == 'system':480                effective_path = path.rstrip("/")481            else:482                effective_path = self.get_zone_base_path(access_zone) + \483                    path.rstrip("/")484        if desired_retention:485            self.validate_desired_retention(desired_retention)486        snapshot_schedule_details = self.get_details(name)487        is_schedule_modified = False488        snapshot_schedule_modification_details = dict()489        if snapshot_schedule_details is not None:490            is_schedule_modified, snapshot_schedule_modification_details = \491                self.check_snapshot_schedule_modified(492                    snapshot_schedule_details, alias, desired_retention,493                    retention_unit, effective_path, pattern, schedule)494        if state == 'present' and not snapshot_schedule_details:495            LOG.debug("Creating new snapshot schedule: %s for path: %s",496                      name, effective_path)497            result['changed'] = self.create_snapshot_schedule(498                name, alias, effective_path, desired_retention,499                retention_unit, pattern, schedule) or result['changed']500        if state == 'present' and new_name is not None:501            if len(new_name) == 0:502                self.module.fail_json(msg="Please provide valid string for "503                                          "new_name")504            if snapshot_schedule_details is None:505                self.module.fail_json(msg="Snapshot schedule not found.")506            if new_name != snapshot_schedule_details['schedules'][0]['name']:507                self.validate_new_name(new_name)508                LOG.info("Renaming snapshot schedule %s to new name %s",509                         name, new_name)510                result['changed'] = self.rename_snapshot_schedule(511                    snapshot_schedule_details, new_name) or result['changed']512                name = new_name513        if state == 'present' and is_schedule_modified:514            LOG.info("Modifying snapshot schedule %s", name)515            result['changed'] = self.modify_snapshot_schedule(516                name, snapshot_schedule_modification_details) or \517                result['changed']518        if state == 'absent' and snapshot_schedule_details:519            LOG.info("Deleting snapshot schedule %s", name)520            result['changed'] = self.delete_snapshot_schedule(name) or \521                result['changed']522        snapshot_schedule_details = self.get_details(name)523        result['snapshot_schedule_details'] = snapshot_schedule_details524        self.module.exit_json(**result)525def get_snapshotschedule_parameters():526    """This method provide parameters required for the ansible snapshot527    schedule module on PowerScale"""528    return dict(529        name=dict(required=True, type='str'),...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!!
