def create_mssql_vdb(engine, jobs, vdb_group, vdb_name, environment_obj, container_obj): """ Create a MSSQL VDB engine: jobs: vdb_group: vdb_name, environment_obj: container_obj: """ vdb_obj = find_database_by_name_and_group_name( engine, dx_session_obj.server_session, vdb_group.name, vdb_name ) if vdb_obj == None: vdb_params = MSSqlProvisionParameters() vdb_params.container = MSSqlDatabaseContainer() vdb_params.container.group = vdb_group.reference vdb_params.container.name = vdb_name vdb_params.source = MSSqlVirtualSource() vdb_params.source.allow_auto_vdb_restart_on_host_reboot = False vdb_params.source_config = MSSqlSIConfig() vdb_params.source_config.database_name = arguments["--db"] vdb_params.source_config.repository = find_dbrepo( dx_session_obj.server_session, "MSSqlInstance", environment_obj.reference, arguments["--envinst"], ).reference vdb_params.timeflow_point_parameters = set_timeflow_point( engine, dx_session_obj.server_session, container_obj ) if not vdb_params.timeflow_point_parameters: return vdb_params.timeflow_point_parameters.container = container_obj.reference print_info(engine["hostname"] + ":Provisioning " + vdb_name) database.provision(dx_session_obj.server_session, vdb_params) # Add the job into the jobs dictionary so we can track its progress jobs[engine["hostname"]] = dx_session_obj.server_session.last_job # return the job object to the calling statement so that we can tell if # a job was created or not (will return None, if no job) return dx_session_obj.server_session.last_job else: print_info(engine["hostname"] + ": " + vdb_name + " already exists.") return vdb_obj.reference
def create_mssql_vdb(engine, jobs, vdb_group, vdb_name, environment_obj, container_obj): ''' Create a MSSQL VDB engine: jobs: vdb_group: vdb_name, environment_obj: container_obj: ''' vdb_obj = find_database_by_name_and_group_name(engine, dx_session_obj.server_session, vdb_group.name, vdb_name) if vdb_obj == None: vdb_params = MSSqlProvisionParameters() vdb_params.container = MSSqlDatabaseContainer() vdb_params.container.group = vdb_group.reference vdb_params.container.name = vdb_name vdb_params.source = MSSqlVirtualSource() vdb_params.source.allow_auto_vdb_restart_on_host_reboot = False vdb_params.source_config = MSSqlSIConfig() vdb_params.source_config.database_name = arguments['--db'] vdb_params.source_config.repository = find_dbrepo( dx_session_obj.server_session, 'MSSqlInstance', environment_obj.reference, arguments['--envinst']).reference vdb_params.timeflow_point_parameters = set_timeflow_point(engine, dx_session_obj.server_session, container_obj) if not vdb_params.timeflow_point_parameters: return vdb_params.timeflow_point_parameters.container = \ container_obj.reference print_info(engine["hostname"] + ":Provisioning " + vdb_name) database.provision(dx_session_obj.server_session, vdb_params) #Add the job into the jobs dictionary so we can track its progress jobs[engine["hostname"]] = dx_session_obj.server_session.last_job #return the job object to the calling statement so that we can tell if # a job was created or not (will return None, if no job) return dx_session_obj.server_session.last_job else: print_info(engine["hostname"] + ": " + vdb_name + " already exists.") return vdb_obj.reference
def link_mssql_dsource(engine_name): """ Link an MSSQL dSource """ link_params = LinkParameters() link_params.name = arguments['--dsource_name'] link_params.link_data = MSSqlLinkData() try: env_obj_ref = find_obj_by_name(dx_session_obj.server_session, environment, arguments['--stage_env']).reference link_params.link_data.ppt_repository = find_dbrepo( dx_session_obj.server_session, 'MSSqlInstance', env_obj_ref, arguments['--stage_instance']).reference link_params.link_data.config = find_obj_by_name( dx_session_obj.server_session, sourceconfig, arguments['--dsource_name']).reference link_params.group = find_obj_by_name(dx_session_obj.server_session, group, arguments['--dx_group']).reference except DlpxException as e: print_exception('Could not link {}: {}\n'.format( arguments['--dsource_name'], e)) sys.exit(1) if arguments['--backup_path'] != "auto": link_params.link_data.shared_backup_location = arguments['--backup_path'] if arguments['--backup_loc_passwd']: link_params.link_data.backup_location_credentials = {'type': 'PasswordCredential', 'password': arguments['--backup_loc_passwd']} link_params.link_data.backup_location_user = \ arguments['--backup_loc_user'] link_params.link_data.db_credentials = {'type': 'PasswordCredential', 'password': arguments['--db_passwd']} link_params.link_data.db_user = arguments['--db_user'] link_params.link_data.sourcing_policy = SourcingPolicy() if arguments['--load_from_backup']: link_params.link_data.sourcing_policy.load_from_backup = True if arguments['--logsync']: link_params.link_data.sourcing_policy.logsync_enabled = True try: database.link(dx_session_obj.server_session, link_params) dx_session_obj.jobs[engine_name] = dx_session_obj.server_session.last_job dx_session_obj.jobs[engine_name + 'snap'] = get_running_job( dx_session_obj.server_session, find_obj_by_name( dx_session_obj.server_session, database, arguments['--dsource_name']).reference) except (HttpError, RequestError, JobError) as e: print_exception('Database link failed for {}:\n{}\n'.format( arguments['--dsource_name'], e))
def create_ora_sourceconfig(engine_name, port_num=1521): """ :param ip_addr: :param db_name: :return: """ create_ret = None env_obj = find_obj_by_name(dx_session_obj.server_session, environment, arguments['--env_name']) try: sourceconfig_ref = find_obj_by_name(dx_session_obj.server_session, sourceconfig, arguments['--db_name']).reference except DlpxException: sourceconfig_ref = None repo_ref = find_dbrepo(dx_session_obj.server_session, 'OracleInstall', env_obj.reference, arguments['--db_install_path']).reference dsource_params = OracleSIConfig() connect_str = ('jdbc:oracle:thin:@' + arguments['--ip_addr'] + ':' + str(port_num) + ':' + arguments['--db_name']) dsource_params.database_name = arguments['--db_name'] dsource_params.unique_name = arguments['--db_name'] dsource_params.repository = repo_ref dsource_params.instance = OracleInstance() dsource_params.instance.instance_name = arguments['--db_name'] dsource_params.instance.instance_number = 1 dsource_params.services = [{'type': 'OracleService', 'jdbcConnectionString': connect_str}] try: if sourceconfig_ref is None: create_ret = link_ora_dsource(sourceconfig.create( dx_session_obj.server_session, dsource_params), env_obj.primary_user) elif sourceconfig_ref is not None: create_ret = link_ora_dsource(sourceconfig_ref, env_obj.primary_user) print_info('Created and linked the dSource {} with reference {}.\n'.format( arguments['--db_name'], create_ret)) link_job_ref = dx_session_obj.server_session.last_job link_job_obj = job.get(dx_session_obj.server_session, link_job_ref) while link_job_obj.job_state not in ["CANCELED", "COMPLETED", "FAILED"]: print_info('Waiting three seconds for link job to complete, and sync to begin') sleep(3) link_job_obj = job.get(dx_session_obj.server_session, link_job_ref) #Add the snapsync job to the jobs dictionary dx_session_obj.jobs[engine_name + 'snap'] = get_running_job( dx_session_obj.server_session, find_obj_by_name( dx_session_obj.server_session, database, arguments['--dsource_name']).reference) print_debug('Snapshot Job Reference: {}.\n'.format( dx_session_obj.jobs[engine_name + 'snap'])) except (HttpError, RequestError) as e: print_exception('ERROR: Could not create the sourceconfig:\n' '{}'.format(e)) sys.exit(1)
def link_mssql_dsource(engine_name): """ Link an MSSQL dSource """ link_params = LinkParameters() link_params.name = arguments["--dsource_name"] link_params.link_data = MSSqlLinkData() try: env_obj_ref = find_obj_by_name(dx_session_obj.server_session, environment, arguments["--stage_env"]).reference link_params.link_data.ppt_repository = find_dbrepo( dx_session_obj.server_session, "MSSqlInstance", env_obj_ref, arguments["--stage_instance"], ).reference link_params.link_data.config = find_obj_by_name( dx_session_obj.server_session, sourceconfig, arguments["--dsource_name"]).reference link_params.group = find_obj_by_name(dx_session_obj.server_session, group, arguments["--dx_group"]).reference except DlpxException as e: print_exception("Could not link {}: {}\n".format( arguments["--dsource_name"], e)) sys.exit(1) if arguments["--backup_path"] != "auto": link_params.link_data.shared_backup_location = arguments[ "--backup_path"] if arguments["--backup_loc_passwd"]: link_params.link_data.backup_location_credentials = { "type": "PasswordCredential", "password": arguments["--backup_loc_passwd"], } link_params.link_data.backup_location_user = arguments[ "--backup_loc_user"] link_params.link_data.db_credentials = { "type": "PasswordCredential", "password": arguments["--db_passwd"], } link_params.link_data.db_user = arguments["--db_user"] link_params.link_data.sourcing_policy = SourcingPolicy() if arguments["--load_from_backup"]: link_params.link_data.sourcing_policy.load_from_backup = True if arguments["--sync_mode"]: link_params.link_data.validated_sync_mode = arguments["sync_mode"] if arguments["--logsync"]: link_params.link_data.sourcing_policy.logsync_enabled = True try: database.link(dx_session_obj.server_session, link_params) dx_session_obj.jobs[ engine_name] = dx_session_obj.server_session.last_job dx_session_obj.jobs[engine_name + "snap"] = get_running_job( dx_session_obj.server_session, find_obj_by_name(dx_session_obj.server_session, database, arguments["--dsource_name"]).reference, ) except (HttpError, RequestError, JobError) as e: print_exception("Database link failed for {}:\n{}\n".format( arguments["--dsource_name"], e))
def link_mssql_dsource(engine_name): """ Link an MSSQL dSource """ link_params = LinkParameters() link_params.name = arguments['--dsource_name'] link_params.link_data = MSSqlLinkData() try: env_obj_ref = find_obj_by_name(dx_session_obj.server_session, environment, arguments['--stage_env']).reference link_params.link_data.ppt_repository = find_dbrepo( dx_session_obj.server_session, 'MSSqlInstance', env_obj_ref, arguments['--stage_instance']).reference link_params.link_data.config = find_obj_by_name( dx_session_obj.server_session, sourceconfig, arguments['--dsource_name']).reference link_params.group = find_obj_by_name(dx_session_obj.server_session, group, arguments['--dx_group']).reference except DlpxException as e: print_exception('Could not link {}: {}\n'.format( arguments['--dsource_name'], e)) sys.exit(1) if arguments['--backup_path'] != "auto": link_params.link_data.shared_backup_location = arguments['--backup_path'] if arguments['--backup_loc_passwd']: link_params.link_data.backup_location_credentials = {'type': 'PasswordCredential', 'password': arguments['--backup_loc_passwd']} link_params.link_data.backup_location_user = \ arguments['--backup_loc_user'] link_params.link_data.db_credentials = {'type': 'PasswordCredential', 'password': arguments['--db_passwd']} link_params.link_data.db_user = arguments['--db_user'] link_params.link_data.sourcing_policy = SourcingPolicy() if arguments['--load_from_backup']: link_params.link_data.sourcing_policy.load_from_backup = True if arguments['--sync_mode']: link_params.link_data.validated_sync_mode = arguments['sync_mode'] if arguments['--logsync']: link_params.link_data.sourcing_policy.logsync_enabled = True try: database.link(dx_session_obj.server_session, link_params) dx_session_obj.jobs[engine_name] = dx_session_obj.server_session.last_job dx_session_obj.jobs[engine_name + 'snap'] = get_running_job( dx_session_obj.server_session, find_obj_by_name( dx_session_obj.server_session, database, arguments['--dsource_name']).reference) except (HttpError, RequestError, JobError) as e: print_exception('Database link failed for {}:\n{}\n'.format( arguments['--dsource_name'], e))