Best Python code snippet using tempest_python
purefb_snap.py
Source:purefb_snap.py  
...116            changed = True117        except Exception:118            changed = False119    module.exit_json(changed=changed)120def update_snapshot(module, blade):121    """Update Snapshot"""122    changed = False123    module.exit_json(changed=changed)124def delete_snapshot(module, blade):125    """ Delete Snapshot"""126    if not module.check_mode:127        snapname = module.params['name'] + "." + module.params['suffix']128        new_attr = FileSystemSnapshot(destroyed=True)129        try:130            blade.file_system_snapshots.update_file_system_snapshots(name=snapname, attributes=new_attr)131            changed = True132            if module.params['eradicate']:133                try:134                    blade.file_system_snapshots.delete_file_system_snapshots(name=snapname)135                    changed = True136                except Exception:137                    changed = False138        except Exception:139            changed = False140    module.exit_json(changed=changed)141def eradicate_snapshot(module, blade):142    """ Eradicate Snapshot"""143    if not module.check_mode:144        snapname = module.params['name'] + "." + module.params['suffix']145        try:146            blade.file_system_snapshots.delete_file_system_snapshots(name=snapname)147            changed = True148        except Exception:149            changed = False150    module.exit_json(changed=changed)151def main():152    argument_spec = purefb_argument_spec()153    argument_spec.update(154        dict(155            name=dict(required=True),156            suffix=dict(type='str'),157            eradicate=dict(default='false', type='bool'),158            state=dict(default='present', choices=['present', 'absent'])159        )160    )161    module = AnsibleModule(argument_spec,162                           supports_check_mode=True)163    if not HAS_PURITY_FB:164        module.fail_json(msg='purity_fb sdk is required for this module')165    if module.params['suffix'] is None:166        suffix = "snap-" + str((datetime.utcnow() - datetime(1970, 1, 1, 0, 0, 0, 0)).total_seconds())167        module.params['suffix'] = suffix.replace(".", "")168    state = module.params['state']169    blade = get_blade(module)170    fs = get_fs(module, blade)171    snap = get_fssnapshot(module, blade)172    if state == 'present' and fs and not fs.destroyed and not snap:173        create_snapshot(module, blade)174    elif state == 'present' and fs and not fs.destroyed and snap and not snap.destroyed:175        update_snapshot(module, blade)176    elif state == 'present' and fs and not fs.destroyed and snap and snap.destroyed:177        recover_snapshot(module, blade)178    elif state == 'present' and fs and fs.destroyed:179        update_snapshot(module, blade)180    elif state == 'present' and not fs:181        update_snapshot(module, blade)182    elif state == 'absent' and snap and not snap.destroyed:183        delete_snapshot(module, blade)184    elif state == 'absent' and snap and snap.destroyed:185        eradicate_snapshot(module, blade)186    elif state == 'absent' and not snap:187        module.exit_json(changed=False)188if __name__ == '__main__':...purefa_snap.py
Source:purefa_snap.py  
...136                              overwrite=module.params['overwrite'])137    elif tgt is not None and not module.params['overwrite']:138        changed = False139    module.exit_json(changed=changed)140def update_snapshot(module, array):141    """Update Snapshot"""142    changed = False143    module.exit_json(changed=changed)144def delete_snapshot(module, array):145    """ Delete Snapshot"""146    changed = True147    if not module.check_mode:148        snapname = module.params['name'] + "." + module.params['suffix']149        try:150            array.destroy_volume(snapname)151            if module.params['eradicate']:152                try:153                    array.eradicate_volume(snapname)154                except Exception:155                    changed = False156        except Exception:157            changed = False158    module.exit_json(changed=changed)159def main():160    argument_spec = purefa_argument_spec()161    argument_spec.update(dict(162        name=dict(type='str', required=True),163        suffix=dict(type='str'),164        target=dict(type='str'),165        overwrite=dict(type='bool', default=False),166        eradicate=dict(type='bool', default=False),167        state=dict(type='str', default='present', choices=['absent', 'copy', 'present']),168    ))169    required_if = [('state', 'copy', ['target', 'suffix'])]170    module = AnsibleModule(argument_spec,171                           required_if=required_if,172                           supports_check_mode=True)173    if not HAS_PURESTORAGE:174        module.fail_json(msg='purestorage sdk is required for this module in volume')175    if module.params['suffix'] is None:176        suffix = "snap-" + str((datetime.utcnow() - datetime(1970, 1, 1, 0, 0, 0, 0)).total_seconds())177        module.params['suffix'] = suffix.replace(".", "")178    state = module.params['state']179    array = get_system(module)180    volume = get_volume(module, array)181    target = get_target(module, array)182    snap = get_snapshot(module, array)183    if state == 'present' and volume and not snap:184        create_snapshot(module, array)185    elif state == 'present' and volume and snap:186        update_snapshot(module, array)187    elif state == 'present' and not volume:188        update_snapshot(module, array)189    elif state == 'copy' and snap:190        create_from_snapshot(module, array)191    elif state == 'copy' and not snap:192        update_snapshot(module, array)193    elif state == 'absent' and snap:194        delete_snapshot(module, array)195    elif state == 'absent' and not snap:196        module.exit_json(changed=False)197if __name__ == '__main__':...urls.py
Source:urls.py  
1# urls.py2from datetime import datetime3from django.urls import path, register_converter4from . import views5class DateConverter:6    regex = r'[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}'7    format = '%Y-%m-%d'8    def to_python(self, value):9        return datetime.strptime(value, self.format).date()10    def to_url(self, value):11        return value.strftime(self.format)12register_converter(DateConverter, 'date')13class FloatConverter:14    regex = r'-?(?:[0-9]*\.[0-9]+)|(?:[0-9]+)'15    def to_python(self, value):16        return float(value)17    def to_url(self, value):18        return str(value)19register_converter(FloatConverter, 'float')20urlpatterns = [21    path('', views.index, name='index'),22    path('clear_history/<date:start_date>/<date:end_date>',23         views.clear_history, name='clear_history'),24    path('load_fund_history', views.load_fund_history,25         name='load_all_fund_history'),26    path('load_fund_history/<ticker>', views.load_fund_history,27         name='load_fund_history'),28    path('load_transactions/<date:end_date>', views.load_transactions),29    path('load_transactions/<date:end_date>/<filename>',30         views.load_transactions, name='load_transactions'),31    path('dates', views.dates, name='dates'),32    path('account/<int:account_id>/<date:date>', views.account, name='account'),33    path('account/<int:account_id>/<date:date>/tags/<tags>', views.account, name='account'),34    path('check_structure', views.check_structure, name='check_structure'),35    path('get_plan/<cat_name>', views.get_plan),36    path('get_plan/<cat_name>/tags/<tags>', views.get_plan),37    path('get_plan/<cat_name>/<int:account_id>', views.get_plan),38    path('get_plan/<cat_name>/<int:account_id>/tags/<tags>', views.get_plan),39    path('get_fund/<cat_name>', views.get_fund),40    path('get_fund/<cat_name>/<int:account_id>', views.get_fund),41    path('get_children/<cat_name>', views.get_children),42    path('get_children/<cat_name>/tags/<tags>', views.get_children),43    path('get_children/<cat_name>/<int:account_id>', views.get_children),44    path('get_children/<cat_name>/<int:account_id>/tags/<tags>', views.get_children),45    path('get_tree/<int:account_id>', views.get_tree),46    path('get_tree/<int:account_id>/tags/<tags>', views.get_tree),47    path('get_tags', views.get_tags, name='get_tags'),48    #path('update_snapshot', views.update_snapshot),49    #path('update_snapshot/<date:start_date>', views.update_snapshot),50    #path('update_snapshot/<int:reload>', views.update_snapshot),51    #path('update_snapshot/<date:start_date>/<int:reload>',52    #     views.update_snapshot),53    path('update_shares', views.update_shares, name='update_shares'),54    path('update_shares/<int:reload>', views.update_shares,55         name='reload_shares'),56    path('shares/<int:account_id>/<date:date>', views.shares),57    path('help', views.help, name='help'),58    path('rebalance/<int:owner_id>', views.rebalance, name='default_rebalance'),59    path('rebalance/<int:owner_id>/tags/<tags>', views.rebalance, name='default_rebalance'),60    path('rebalance/<int:owner_id>/<float:adj_pct>', views.rebalance,61         name='adj_rebalance'),62    path('rebalance/<int:owner_id>/<float:adj_pct>/tags/<tags>', views.rebalance,63         name='adj_rebalance'),64    path('rebalance/<int:owner_id>/<float:adj_pct>/<filename>', views.rebalance,65         name='adj_rebalance_filename'),66    path('rebalance/<int:owner_id>/<float:adj_pct>/<filename>/tags/<tags>', views.rebalance,67         name='adj_rebalance_filename'),68    path('rebalanced/<int:owner_id>', views.rebalanced, name='rebalanced'),...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!!
