def create_mssql_vdb(dlpx_obj, group_ref, vdb_name, environment_obj, source_obj, env_inst, timestamp, timestamp_type='SNAPSHOT' ): """ Create a MSSQL VDB :param dlpx_obj: DDP session object :type dlpx_obj: lib.GetSession.GetSession object :param group_ref: Reference of Group name where the VDB will be created :type group_ref: str :param vdb_name: Name of the VDB :type vdb_name: str :param environment_obj: Environment object where the VDB will be created :type environment_obj: class 'delphixpy.v1_10_2.web.objects :param source_obj: Database object of the source :type source_obj: :param env_inst: Environment installation identifier in Delphix. EX: "/u01/app/oracle/product/11.2.0/dbhome_1" EX: ASETARGET :type env_inst: str :param timestamp: The Delphix semantic for the point in time on the source from which to refresh the VDB :type timestamp: str :param timestamp_type: The Delphix semantic for the point in time on the source from which you want to refresh your VDB either SNAPSHOT or TIME :type timestamp_type: str :return: """ engine_name = list(dlpx_obj.dlpx_ddps)[0] timeflow_obj = dx_timeflow.DxTimeflow(dlpx_obj.server_session) try: vdb_obj = get_references.find_obj_by_name( dlpx_obj.server_session, database, vdb_name) raise dlpx_exceptions.DlpxObjectExists(f'{vdb_obj} exists.') except dlpx_exceptions.DlpxObjectNotFound: pass vdb_params = vo.MSSqlProvisionParameters() vdb_params.container = vo.MSSqlDatabaseContainer() vdb_params.container.group = group_ref vdb_params.container.name = vdb_name vdb_params.source = vo.MSSqlVirtualSource() vdb_params.source.allow_auto_vdb_restart_on_host_reboot = False vdb_params.source_config = vo.MSSqlSIConfig() vdb_params.source_config.database_name = vdb_name vdb_params.source_config.environment_user = \ environment_obj.primary_user vdb_params.source_config.repository = get_references.find_obj_by_name( dlpx_obj.server_session, repository, env_inst).reference vdb_params.timeflow_point_parameters = \ timeflow_obj.set_timeflow_point(source_obj, timestamp_type, timestamp) vdb_params.timeflow_point_parameters.container = source_obj.reference dx_logging.print_info(f'{engine_name} provisioning {vdb_name}') print(type(source_obj), type(environment_obj)) database.provision(dlpx_obj.server_session, vdb_params) # Add the job into the jobs dictionary so we can track its progress dlpx_obj.jobs[ dlpx_obj.server_session.address ] = dlpx_obj.server_session.last_job
def main_workflow(engine, dlpx_obj, single_thread): """ This function is where we create our main workflow. Use the @run_async decorator to run this function asynchronously. The @run_async decorator allows us to run against multiple Delphix Engine simultaneously :param engine: Dictionary of engines :type engine: dictionary :param dlpx_obj: DDP session object :type dlpx_obj: lib.GetSession.GetSession object :param single_thread: True - run single threaded, False - run multi-thread :type single_thread: bool """ try: # Setup the connection to the Delphix DDP dlpx_obj.dlpx_session( engine['ip_address'], engine['username'], engine['password']) except dlpx_exceptions.DlpxException as err: dx_logging.print_exception( f'ERROR: dx_provision_vdb encountered an error authenticating to ' f' {engine["ip_address"]} :\n{err}') group_ref = get_references.find_obj_by_name( dlpx_obj.server_session, group, ARGUMENTS['--target_grp']).reference environment_obj = get_references.find_obj_by_name( dlpx_obj.server_session, environment, ARGUMENTS['--env_name']) source_obj = get_references.find_obj_by_name( dlpx_obj.server_session, database, ARGUMENTS['--source']) thingstodo = ["thingstodo"] try: with dlpx_obj.job_mode(single_thread): while dlpx_obj.jobs or thingstodo: if thingstodo: arg_type = ARGUMENTS['--type'].lower() if arg_type == "oracle": create_oracle_si_vdb( dlpx_obj, group_ref, ARGUMENTS['--db'], environment_obj, source_obj, ARGUMENTS['--envinst'], ARGUMENTS['--timestamp'], ARGUMENTS['--timestamp_type'], ARGUMENTS['--prerefresh'], ARGUMENTS['--postrefresh'], ARGUMENTS['--prerollback'], ARGUMENTS['--postrollback'], ARGUMENTS['--configure-clone'] ) elif arg_type == "ase": create_ase_vdb(dlpx_obj, group_ref, ARGUMENTS['--db'], environment_obj, source_obj, ARGUMENTS['--envinst'], ARGUMENTS['--timestamp'], ARGUMENTS['--timestamp_type'], ARGUMENTS['--no_truncate_log'] ) elif arg_type == "mssql": create_mssql_vdb( dlpx_obj, group_ref, ARGUMENTS['--db'], environment_obj, source_obj, ARGUMENTS['--envinst'], ARGUMENTS['--timestamp'], ARGUMENTS['--timestamp_type'] ) elif arg_type == "vfiles": create_vfiles_vdb( dlpx_obj, group_ref, ARGUMENTS['--db'], environment_obj, source_obj, ARGUMENTS['--prerefresh'], ARGUMENTS['--postrefresh'], ARGUMENTS['--prerollback'], ARGUMENTS['--postrollback'], ARGUMENTS['--configure-clone'] ) thingstodo.pop() run_job.find_job_state(engine, dlpx_obj) except ( dlpx_exceptions.DlpxException, dlpx_exceptions.DlpxObjectNotFound, exceptions.RequestError, exceptions.JobError, exceptions.HttpError, ) as err: dx_logging.print_exception(f'Error in dx_rewind_vdb: ' f'{engine["ip_address"]}\n{err}')
def create_oracle_si_vdb(dlpx_obj, group_ref, vdb_name, environment_obj, source_obj, env_inst, timestamp, timestamp_type='SNAPSHOT', pre_refresh=None, post_refresh=None, pre_rollback=None, post_rollback=None, configure_clone=None): """ Create an Oracle SI VDB :param dlpx_obj: DDP session object :type dlpx_obj: lib.GetSession.GetSession object :param group_ref: Group name where the VDB will be created :type group_ref: str :param vdb_name: Name of the VDB :type vdb_name: str :param source_obj: Database object of the source :type source_obj: class delphixpy.v1_10_2.web.objects.OracleDatabaseContainer.OracleDatabaseContainer :param environment_obj: Environment object where the VDB will be created :type environment_obj: class 'delphixpy.v1_10_2.web.objects :param env_inst: Environment installation identifier in Delphix. EX: "/u01/app/oracle/product/11.2.0/dbhome_1" EX: ASETARGET :type env_inst: str :param timestamp: The Delphix semantic for the point in time on the source from which to refresh the VDB :type timestamp: str :param timestamp_type: The Delphix semantic for the point in time on the source from which you want to refresh your VDB either SNAPSHOT or TIME :type timestamp_type: str """ engine_name = list(dlpx_obj.dlpx_ddps)[0] try: vdb_obj = get_references.find_obj_by_name( dlpx_obj.server_session, database, vdb_name) raise dlpx_exceptions.DlpxObjectExists(f'{vdb_obj} exists.') except dlpx_exceptions.DlpxObjectNotFound: pass vdb_params = vo.OracleProvisionParameters() vdb_params.open_resetlogs = True vdb_params.container = vo.OracleDatabaseContainer() vdb_params.container.group = group_ref vdb_params.container.name = vdb_name vdb_params.source = vo.OracleVirtualSource() vdb_params.source.allow_auto_vdb_restart_on_host_reboot = False vdb_params.source.mount_base = ARGUMENTS['--mntpoint'] vdb_params.source_config = vo.OracleSIConfig() vdb_params.source_config.environment_user = \ environment_obj.primary_user vdb_params.source.operations = vo.VirtualSourceOperations() if pre_refresh: vdb_params.source.operations.pre_refresh = \ vo.RunCommandOnSourceOperation() vdb_params.source.operations.pre_refresh.command = pre_refresh if post_refresh: vdb_params.source.operations.post_refresh = \ vo.RunCommandOnSourceOperation() vdb_params.source.operations.post_refresh.command = post_refresh if pre_rollback: vdb_params.source.operations.pre_rollback = \ vo.RunCommandOnSourceOperation vdb_params.source.operations.pre_rollback.command = pre_rollback if post_rollback: vdb_params.source.operations.post_rollback = \ vo.RunCommandOnSourceOperation() vdb_params.source.operations.post_rollback.command = post_rollback if configure_clone: vdb_params.source.operations.configure_clone = \ vo.RunCommandOnSourceOperation() vdb_params.source.operations.configure_clone.command = \ configure_clone vdb_params.source_config.database_name = vdb_name vdb_params.source_config.unique_name = vdb_name vdb_params.source_config.instance = vo.OracleInstance() vdb_params.source_config.instance.instance_name = vdb_name vdb_params.source_config.instance.instance_number = 1 vdb_params.source_config.repository = get_references.find_db_repo( dlpx_obj.server_session, 'OracleInstall', environment_obj.reference, env_inst ) timeflow_obj = dx_timeflow.DxTimeflow(dlpx_obj.server_session) vdb_params.timeflow_point_parameters = \ timeflow_obj.set_timeflow_point(source_obj, timestamp_type, timestamp) dx_logging.print_info(f'{engine_name}: Provisioning {vdb_name}') try: database.provision(dlpx_obj.server_session, vdb_params) except (exceptions.RequestError, exceptions.HttpError) as err: raise dlpx_exceptions.DlpxException( f'ERROR: Could not provision the database {vdb_name}\n{err}') # Add the job into the jobs dictionary so we can track its progress dlpx_obj.jobs[ dlpx_obj.server_session.address ] = dlpx_obj.server_session.last_job
def create_vfiles_vdb(dlpx_obj, group_ref, vfiles_name, environment_obj, source_obj, env_inst, timestamp, timestamp_type='SNAPSHOT', pre_refresh=None, post_refresh=None, pre_rollback=None, post_rollback=None, configure_clone=None): """ Create a vfiles VDB :param dlpx_obj: DDP session object :type dlpx_obj: lib.GetSession.GetSession object :param group_ref: Reference of group name where the VDB will be created :type group_ref: str :param vfiles_name: Name of the vfiles VDB :type vfiles_name: str :param environment_obj: Environment object where the VDB will be created :type environment_obj: class 'delphixpy.v1_10_2.web.objects :param source_obj: vfiles object of the source :type source_obj: class delphixpy.v1_10_2.web.objects.OracleDatabaseContainer.OracleDatabaseContainer :param env_inst: Environment installation identifier in Delphix. EX: "/u01/app/oracle/product/11.2.0/dbhome_1" EX: ASETARGET :type env_inst: str :param timestamp: The Delphix semantic for the point in time on the source from which to refresh the VDB :type timestamp: str :param timestamp_type: The Delphix semantic for the point in time on the source from which you want to refresh your VDB either SNAPSHOT or TIME :type timestamp_type: str :param pre_refresh: Pre-Hook commands before a refresh :type pre_refresh: str :param post_refresh: Post-Hook commands after a refresh :type post_refresh: str :param pre_rollback: Commands before a rollback :type pre_rollback: str :param post_rollback: Commands after a rollback :type post_rollback: str :param configure_clone: Configure clone commands :type configure_clone: str """ engine_name = list(dlpx_obj.dlpx_ddps)[0] timeflow_obj = dx_timeflow.DxTimeflow(dlpx_obj.server_session) try: vdb_obj = get_references.find_obj_by_name( dlpx_obj.server_session, database, vfiles_name) raise dlpx_exceptions.DlpxObjectExists(f'{vdb_obj} exists.') except dlpx_exceptions.DlpxObjectNotFound: pass vfiles_params = vo.AppDataProvisionParameters() vfiles_params.source = vo.AppDataVirtualSource() vfiles_params.source_config = vo.AppDataDirectSourceConfig() vfiles_params.source.allow_auto_vdb_restart_on_host_reboot = True vfiles_params.container = vo.AppDataContainer() vfiles_params.group = group_ref vfiles_params.name = vfiles_name vfiles_params.source_config.name = ARGUMENTS['--target'] vfiles_params.source_config.path = ARGUMENTS['--vfiles_path'] vfiles_params.source_config.environment_user = environment_obj.primary_user vfiles_params.source_config.repository = get_references.find_obj_by_name( dlpx_obj.server_session, repository, env_inst).reference vfiles_params.source.name = vfiles_name vfiles_params.source.name = vfiles_name vfiles_params.source.operations = vo.VirtualSourceOperations() if pre_refresh: vfiles_params.source.operations.pre_refresh = \ vo.RunCommandOnSourceOperation() vfiles_params.source.operations.pre_refresh.command = pre_refresh if post_refresh: vfiles_params.source.operations.post_refresh = \ vo.RunCommandOnSourceOperation() vfiles_params.source.operations.post_refresh.command = post_refresh if pre_rollback: vfiles_params.source.operations.pre_rollback = \ vo.RunCommandOnSourceOperation vfiles_params.source.operations.pre_rollback.command = pre_rollback if post_rollback: vfiles_params.source.operations.post_rollback = \ vo.RunCommandOnSourceOperation() vfiles_params.source.operations.post_rollback.command = post_rollback if configure_clone: vfiles_params.source.operations.configure_clone = \ vo.RunCommandOnSourceOperation() vfiles_params.source.operations.configure_clone.command = \ configure_clone if timestamp_type is None: vfiles_params.timeflow_point_parameters = vo.TimeflowPointSemantic() vfiles_params.timeflow_point_parameters.container = \ source_obj.reference, vfiles_params.timeflow_point_parameters.location = 'LATEST_POINT' elif timestamp_type.upper() == 'SNAPSHOT': try: dx_snap_params = timeflow_obj.set_timeflow_point( source_obj, timestamp_type, timestamp) except exceptions.RequestError as err: raise dlpx_exceptions.DlpxException( f'Could not set the timeflow point:\n{err}') if dx_snap_params.type == 'TimeflowPointSemantic': vfiles_params.timeflow_point_parameters = vo.TimeflowPointSemantic() vfiles_params.timeflow_point_parameters.container = \ dx_snap_params.container vfiles_params.timeflow_point_parameters.location = \ dx_snap_params.location elif dx_snap_params.type == 'TimeflowPointTimestamp': vfiles_params.timeflow_point_parameters = \ vo.TimeflowPointTimestamp() vfiles_params.timeflow_point_parameters.timeflow = \ dx_snap_params.timeflow vfiles_params.timeflow_point_parameters.timestamp = \ dx_snap_params.timestamp dx_logging.print_info(f'{engine_name}: Provisioning {vfiles_name}\n') try: database.provision(dlpx_obj.server_session, vfiles_params) except (exceptions.RequestError, exceptions.HttpError) as err: raise dlpx_exceptions.DlpxException( f'ERROR: Could not provision the database {vfiles_name}\n{err}') # Add the job into the jobs dictionary so we can track its progress dlpx_obj.jobs[ dlpx_obj.server_session.address ] = dlpx_obj.server_session.last_job
def create_ase_vdb(dlpx_obj, vdb_group, vdb_name, environment_obj, source_obj, env_inst, timestamp, timestamp_type='SNAPSHOT', no_truncate_log=False): """ Create a Sybase ASE VDB :param dlpx_obj: DDP session object :type dlpx_obj: lib.GetSession.GetSession object :param vdb_group: Group name where the VDB will be created :type vdb_group: str :param vdb_name: Name of the VDB :type vdb_name: str :param environment_obj: Environment object where the VDB will be created :type environment_obj: class 'delphixpy.v1_10_2.web.objects :param source_obj: Database object of the source :type source_obj: class delphixpy.v1_10_2.web.objects.UnixHostEnvironment.UnixHostEnvironment :param env_inst: Environment installation identifier in Delphix. EX: "/u01/app/oracle/product/11.2.0/dbhome_1" EX: ASETARGET :type env_inst: str :param timestamp: The Delphix semantic for the point in time on the source from which to refresh the VDB :type timestamp: str :param timestamp_type: The Delphix semantic for the point in time on the source from which you want to refresh your VDB either SNAPSHOT or TIME :type timestamp_type: str :param no_truncate_log: Don't truncate log on checkpoint :type no_truncate_log: bool :return: """ engine_name = list(dlpx_obj.dlpx_ddps)[0] dx_timeflow_obj = dx_timeflow.DxTimeflow(dlpx_obj.server_session) try: vdb_obj = get_references.find_obj_by_name( dlpx_obj.server_session, database, vdb_name) raise dlpx_exceptions.DlpxObjectExists(f'{vdb_obj} exists.') except dlpx_exceptions.DlpxObjectNotFound: pass vdb_group_ref = get_references.find_obj_by_name( dlpx_obj.server_session, group, vdb_group) vdb_params = vo.ASEProvisionParameters() vdb_params.container = vo.ASEDBContainer() if no_truncate_log: vdb_params.truncate_log_on_checkpoint = False else: vdb_params.truncate_log_on_checkpoint = True vdb_params.container.group = vdb_group_ref vdb_params.container.name = vdb_name vdb_params.source = vo.ASEVirtualSource() vdb_params.source_config = vo.ASESIConfig() vdb_params.source_config.database_name = vdb_name vdb_params.source_config.repository = get_references.find_obj_by_name( dlpx_obj.server_session, repository, env_inst).reference vdb_params.timeflow_point_parameters = dx_timeflow_obj.set_timeflow_point( source_obj, timestamp_type, timestamp) vdb_params.timeflow_point_parameters.container = source_obj.reference dx_logging.print_info(f'{engine_name} provisioning {vdb_name}') database.provision(dlpx_obj.server_session, vdb_params) # Add the job into the jobs dictionary so we can track its progress dlpx_obj.jobs[ dlpx_obj.server_session.address ] = dlpx_obj.server_session.last_job