Пример #1
0
def update_user(user_name, user_password=None, user_email=None, jsonly=None):
    """
    This function updates the user
    """

    if user_email:
        updated_user_obj = User()
        updated_user_obj.email_address = user_email

        try:
          user.update(dx_session_obj.server_session,find_obj_by_name(dx_session_obj.server_session,
                                     user, user_name).reference,updated_user_obj)
          print('Attempting to update {}'.format(user_name))
        except (DlpxException, RequestError) as e:
          print_exception('\nERROR: Updating the user {} '
                          'encountered an error:\n{}'.format(user_name, e))
          sys.exit(1)

    if user_password:
        new_password_obj = CredentialUpdateParameters()
        new_password_obj.new_credential = PasswordCredential()
        new_password_obj.new_credential.password = user_password

        try:
          user.update_credential(dx_session_obj.server_session,find_obj_by_name(dx_session_obj.server_session,
                                     user, user_name).reference,new_password_obj)
          print('Attempting to update {} password'.format(user_name))
        except (DlpxException, RequestError) as e:
          print_exception('\nERROR: Updating the user {} password '
                          'encountered an error:\n{}'.format(user_name, e))
          sys.exit(1)

    js_only(user_name, jsonly)
def create_template(dlpx_obj, template_name, database_name):
    """
    Create the JS Template

    dlpx_obj: Virtualization Engine session object
    template_name: Name of the template to create
    database_name: Name of the database(s) to use in the template
    """

    js_template_params = JSDataTemplateCreateParameters()
    js_template_params.name = template_name
    template_ds_lst = []
    engine_name = dlpx_obj.dlpx_engines.keys()[0]

    for db in database_name.split(':'):
            template_ds_lst.append(build_ds_params(dlpx_obj, database, db))
    try:
        js_template_params.data_sources = template_ds_lst
        js_template_params.type = 'JSDataTemplateCreateParameters'
        template.create(dlpx_obj.server_session, js_template_params)
        dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job
        print_info('Template {} was created successfully.\n'.format(
            template_name))
    except (DlpxException, RequestError, HttpError) as e:
        print_exception('\nThe template {} was not created. The error '
                        'was:\n\n{}'.format(template_name, e))
def refresh_env(dlpx_obj, env_name):
    """
    Refresh the environment

    engine: Dictionary of engines
    env_name: Name of the environment to refresh
    """
    engine_name = dlpx_obj.dlpx_engines.keys()[0]

    if env_name == "all":
      env_list = find_all_objects(dlpx_obj.server_session, environment)
      for env_obj in env_list:
        try:
          environment.refresh(dlpx_obj.server_session, env_obj.reference)
          dlpx_obj.jobs[engine_name] = \
                                     dlpx_obj.server_session.last_job

        except (DlpxException, RequestError) as e:
          print_exception('\nERROR: Refreshing the environment {} '
                          'encountered an error:\n{}'.format(env_name, e))
          sys.exit(1)
    else:

      try:
          env_obj = find_obj_by_name(dlpx_obj.server_session, environment,
                                     env_name)

          environment.refresh(dlpx_obj.server_session, env_obj.reference)
          dlpx_obj.jobs[engine_name] = \
                                     dlpx_obj.server_session.last_job

      except (DlpxException, RequestError) as e:
          print_exception('\nERROR: Refreshing the environment {} '
                          'encountered an error:\n{}'.format(env_name, e))
          sys.exit(1)
Пример #4
0
def rewind_database(dlpx_obj, vdb_name, timestamp, timestamp_type='SNAPSHOT'):
    """
    This function performs the rewind (rollback)

    dlpx_obj: Virtualization Engine session object
    vdb_name: VDB to be rewound
    timestamp: Point in time to rewind the VDB
    timestamp_type: The type of timestamp being used for the rewind
    """

    engine_name = dlpx_obj.dlpx_engines.keys()[0]
    dx_timeflow_obj = DxTimeflow(dlpx_obj.server_session)
    container_obj = find_obj_by_name(dlpx_obj.server_session, database,
                                     vdb_name)
    # Sanity check to make sure our container object has a reference
    if container_obj.reference:
        try:
            if container_obj.virtual is not True:
                raise DlpxException('{} in engine {} is not a virtual object. '
                                    'Skipping.\n'.format(container_obj.name,
                                    engine_name))
            elif container_obj.staging is True:
                raise DlpxException('{} in engine {} is a virtual object. '
                                    'Skipping.\n'.format(container_obj.name,
                                    engine_name))
            elif container_obj.runtime.enabled == "ENABLED":
                print_info('\nINFO: {} Rewinding {} to {}\n'.format(
                           engine_name, container_obj.name, timestamp))

        # This exception is raised if rewinding a vFiles VDB
        # since AppDataContainer does not have virtual, staging or
        # enabled attributes.
        except AttributeError:
            pass

        print_debug('{}: Type: {}'.format(engine_name, container_obj.type))

        # If the vdb is a Oracle type, we need to use a OracleRollbackParameters
        if str(container_obj.reference).startswith("ORACLE"):
            rewind_params = OracleRollbackParameters()
        else:
            rewind_params = RollbackParameters()
        rewind_params.timeflow_point_parameters = \
            dx_timeflow_obj.set_timeflow_point(container_obj, timestamp_type,
                                               timestamp)
        print_debug('{}: {}'.format(engine_name, str(rewind_params)))
        try:
            # Rewind the VDB
            database.rollback(dlpx_obj.server_session, container_obj.reference,
                              rewind_params)
            dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job
            print_info('VDB {} was rolled back.'.format(container_obj.name))
        except (RequestError, HttpError, JobError) as e:
            print_exception('ERROR: {} encountered an error on {}'
                            ' during the rewind process:\n{}'.format(
                engine_name, container_obj.name, e))
    # Don't do anything if the database is disabled
    else:
        print_info('{}: {} is not enabled. Skipping sync.'.format(engine_name,
                                                            container_obj.name))
def link_ora_dsource(srcconfig_ref, primary_user_ref):
    """
    :param srcconfig_ref: Reference to the sourceconfig object
    :param primary_user_ref: Reference to the environment user
    :return: Reference of the linked dSource
    """

    link_params = LinkParameters()
    link_params.link_data = OracleLinkData()
    link_params.link_data.sourcing_policy = OracleSourcingPolicy()
    link_params.name = arguments['--dsource_name']
    link_params.group = find_obj_by_name(dx_session_obj.server_session, group,
                                         arguments['--dx_group']).reference
    link_params.link_data.compressedLinkingEnabled = True
    link_params.link_data.environment_user = primary_user_ref
    link_params.link_data.db_user = arguments['--db_user']
    link_params.link_data.number_of_connections = \
        int(arguments['--num_connections'])
    link_params.link_data.link_now = bool(arguments['--link_now'])
    link_params.link_data.files_per_set = int(arguments['--files_per_set'])
    link_params.link_data.rman_channels = int(arguments['--rman_channels'])
    link_params.link_data.db_credentials = {'type': 'PasswordCredential',
                                            'password':
                                                arguments['--db_passwd']}
    link_params.link_data.sourcing_policy.logsync_enabled = True
    #link_params.link_data.sourcing_policy.logsync_mode = 'ARCHIVE_REDO_MODE'
    link_params.link_data.config = srcconfig_ref
    try:
        return database.link(dx_session_obj.server_session, link_params)
    except (RequestError, HttpError) as e:
        print_exception('Database link failed for {}:\n{}\n'.format(
            arguments['--dsource_name'], e))
        sys.exit(1)
Пример #6
0
def list_branches(dlpx_obj):
    """
    List all branches on a given engine

    :param dlpx_obj: Virtualization Engine session object
    """

    try:
        header = '\nBranch Name, Data Layout, Reference, End Time'
        js_data_layout = ''
        js_branches = branch.get_all(dlpx_obj.server_session)

        print header
        for js_branch in js_branches:
            js_end_time = operation.get(dlpx_obj.server_session,
                                        js_branch.first_operation).end_time
            if re.search('TEMPLATE', js_branch.data_layout):
                js_data_layout = find_obj_name(dlpx_obj.server_session,
                                               template, js_branch.data_layout)
            elif re.search('CONTAINER', js_branch.data_layout):
                js_data_layout = find_obj_name(dlpx_obj.server_session,
                                               container, js_branch.data_layout)
            print_info('{} {}, {}, {}'.format(js_branch._name[0],
                                              js_data_layout,
                                              js_branch.reference,
                                              js_end_time))
    except (DlpxException, HttpError, RequestError) as e:
        print_exception('\nERROR: JS Branches could not be listed. The '
                        'error was:\n\n{}'.format(e))
def create_authorization(dlpx_obj, role_name, target_type, target_name,
                         user_name):
    """
    Function to start, stop, enable or disable a VDB

    :param dlpx_obj: Virtualization Engine session object
    :type dlpx_obj: lib.GetSession.GetSession
    :param role_name: Name of the role
    :param target_type: Supports snapshot, group and database target types
    :param target_name: Name of the target
    :param user_name: User for the authorization
    """

    authorization_obj = Authorization()
    print_debug('Searching for {}, {} and {} references.\n'.format(
                role_name, target_name, user_name))
    try:
        authorization_obj.role = find_obj_by_name(dlpx_obj.server_session, role,
                                    role_name).reference
        authorization_obj.target = find_target_type(dlpx_obj, target_type,
                                      target_name).reference
        authorization_obj.user = find_obj_by_name(dlpx_obj.server_session, user,
                                    user_name).reference
        authorization.create(dlpx_obj.server_session, authorization_obj)
    except (RequestError, HttpError, JobError) as e:
        print_exception('An error occurred while creating authorization:\n'
                        '{}'.format(e))
    print 'Authorization successfully created for {}.'.format(user_name)
def find_target_type(dlpx_obj, target_type, target_name):
    """
    Function to find the target authorization

    :param dlpx_obj: Virtualization Engine session object
    :type dlpx_obj: lib.GetSession.GetSession
    :param target_type: Type of target for authorization
    :param target_name: Name of the target
    """

    target_obj = None
    try:
        if target_type.lower() == 'group':
            target_obj = find_obj_by_name(dlpx_obj.server_session, group,
                                          target_name)
        elif target_type.lower() == 'database':
            target_obj = find_obj_by_name(dlpx_obj.server_session, database,
                                          target_name)
        elif target_type.lower() == 'snapshot':
            target_obj = find_obj_by_name(dlpx_obj.server_session, snapshot,
                                          target_name)
    except (DlpxException, RequestError, HttpError) as e:
        print_exception('Could not find authorization target type '
                        '{}:\n{}'.format(target_type, e))
    return target_obj
def list_authorization(dlpx_obj):
    """
    Function to list authorizations for a given engine

    :param dlpx_obj: Virtualization Engine session object
    """
    target_obj = None

    try:
        auth_objs = authorization.get_all(dlpx_obj.server_session)
        print_info('User, Role, Target, Reference')
        for auth_obj in auth_objs:
            role_obj = role.get(dlpx_obj.server_session, auth_obj.role)
            user_obj = user.get(dlpx_obj.server_session, auth_obj.user)
            if auth_obj.target.startswith('USER'):
                target_obj = user.get(dlpx_obj.server_session, auth_obj.target)
            elif auth_obj.target.startswith('GROUP'):
                target_obj = group.get(dlpx_obj.server_session, auth_obj.target)
            elif auth_obj.target.startswith('DOMAIN'):
                target_obj = User()
                target_obj.name = 'DOMAIN'
            print '{}, {}, {}, {}'.format(user_obj.name, role_obj.name,
                                               target_obj.name,
                                               auth_obj.reference)
    except (RequestError, HttpError, JobError, AttributeError) as e:
        print_exception('An error occurred while listing authorizations.:\n'
                        '{}\n'.format((e)))
def create_replication_job():
    """
    Create a replication job
    :return: Reference to the spec object
    """
    rep_spec = ReplicationSpec()
    rep_spec.name = arguments['--rep_name']
    rep_spec.target_host = arguments['--target_host']
    rep_spec.target_principal = arguments['--target_user']
    rep_spec.target_credential = {'type': 'PasswordCredential', 'password':
        arguments['--target_pw']}
    rep_spec.object_specification = ReplicationList()
    rep_spec.schedule = arguments['--schedule']
    rep_spec.encrypted = True

    if arguments['--num_cons']:
        rep_spec.number_of_connections = int(arguments['--num_cons'])
    if arguments['--bandwidth']:
        rep_spec.bandwidth_limit = int(arguments['--bandwidth'])
    if arguments['--enabled']:
        rep_spec.enabled = True
    try:
        rep_spec.object_specification.objects = find_obj_specs(
            dx_session_obj.server_session, arguments['--rep_objs'].split(','))

        ref = spec.create(dx_session_obj.server_session, rep_spec)
        if dx_session_obj.server_session.last_job:
            dx_session_obj.jobs[dx_session_obj.server_session.address] = \
                dx_session_obj.server_session.last_job
        print_info('Successfully created {} with reference '
                   '{}\n'.format(arguments['--rep_name'], ref))

    except (HttpError, RequestError, DlpxException) as e:
        print_exception('Could not create replication job {}:\n{}'.format(
            arguments['--rep_name'], e))
def refresh_env(dlpx_obj, env_name):
    """
    Refresh the environment

    engine: Dictionary of engines
    env_name: Name of the environment to refresh
    """
    engine_name = dlpx_obj.dlpx_engines.keys()[0]

    if env_name == "all":
        env_list = find_all_objects(dlpx_obj.server_session, environment)
        for env_obj in env_list:
            try:
                environment.refresh(dlpx_obj.server_session, env_obj.reference)
                dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job

            except (DlpxException, RequestError) as e:
                print_exception("\nERROR: Refreshing the environment {} "
                                "encountered an error:\n{}".format(
                                    env_name, e))
                sys.exit(1)
    else:

        try:
            env_obj = find_obj_by_name(dlpx_obj.server_session, environment,
                                       env_name)

            environment.refresh(dlpx_obj.server_session, env_obj.reference)
            dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job

        except (DlpxException, RequestError) as e:
            print_exception("\nERROR: Refreshing the environment {} "
                            "encountered an error:\n{}".format(env_name, e))
            sys.exit(1)
Пример #12
0
def create_container(dlpx_obj, template_name, container_name, database_name):
    """
    Create the JS container

    dlpx_obj: Virtualization Engine session object
    container_name: Name of the container to create
    database_name: Name of the database(s) to use in the container
    """

    js_container_params = JSDataContainerCreateParameters()
    container_ds_lst = []
    engine_name = dlpx_obj.dlpx_engines.keys()[0]
    for db in database_name.split(":"):
        container_ds_lst.append(build_ds_params(dlpx_obj, database, db))

    try:
        js_template_obj = find_obj_by_name(dlpx_obj.server_session, template,
                                           template_name)
        js_container_params.template = js_template_obj.reference
        js_container_params.timeline_point_parameters = {
            "sourceDataLayout": js_template_obj.reference,
            "type": "JSTimelinePointLatestTimeInput",
        }
        js_container_params.data_sources = container_ds_lst
        js_container_params.name = container_name
        container.create(dlpx_obj.server_session, js_container_params)
        dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job
        print_info(
            "JS Container {} was created successfully.".format(container_name))
    except (DlpxException, RequestError, HttpError) as e:
        print_exception("Container {} was not created. The error "
                        "was:\n{}\n".format(container_name, e))
Пример #13
0
def main_workflow(engine):
    """
    This function actually runs the jobs.
    Use the @run_async decorator to run this function asynchronously.
    This allows us to run against multiple Delphix Engine simultaneously

    engine: Dictionary of engines
    """
    try:
        # Setup the connection to the Delphix Engine
        dx_session_obj.serversess(engine["ip_address"], engine["username"],
                                  engine["password"])

    except DlpxException as e:
        print_exception("\nERROR: Engine {} encountered an error while"
                        "{}:\n{}\n".format(engine["hostname"],
                                           arguments["--target"], e))
        sys.exit(1)

    thingstodo = ["thingtodo"]
    try:
        with dx_session_obj.job_mode(single_thread):
            while len(dx_session_obj.jobs) > 0 or len(thingstodo) > 0:
                if len(thingstodo) > 0:
                    if arguments["--add"]:
                        add_group(arguments["--group_name"])
                    elif arguments["--delete"]:
                        delete_group(arguments["--group_name"])
                    elif arguments["--list"]:
                        list_groups()
                    thingstodo.pop()
                # get all the jobs, then inspect them
                i = 0
                for j in dx_session_obj.jobs.keys():
                    job_obj = job.get(dx_session_obj.server_session,
                                      dx_session_obj.jobs[j])
                    print_debug(job_obj)
                    print_info("{}: Group: {}".format(engine["hostname"],
                                                      job_obj.job_state))
                    if job_obj.job_state in [
                            "CANCELED", "COMPLETED", "FAILED"
                    ]:
                        # If the job is in a non-running state, remove it
                        # from the
                        # running jobs list.
                        del dx_session_obj.jobs[j]
                    elif job_obj.job_state in "RUNNING":
                        # If the job is in a running state, increment the
                        # running job count.
                        i += 1
                    print_info("{}: {:d} jobs running.".format(
                        engine["hostname"], i))
                    # If we have running jobs, pause before repeating the
                    # checks.
                    if len(dx_session_obj.jobs) > 0:
                        sleep(float(arguments["--poll"]))

    except (HttpError, RequestError, JobError, DlpxException) as e:
        print_exception("ERROR: Could not complete group "
                        "operation: {}".format(e))
def create_template(dlpx_obj, template_name, database_name):
    """
    Create the JS Template

    dlpx_obj: Virtualization Engine session object
    template_name: Name of the template to create
    database_name: Name of the database(s) to use in the template
    """

    js_template_params = JSDataTemplateCreateParameters()
    js_template_params.name = template_name
    template_ds_lst = []
    engine_name = dlpx_obj.dlpx_engines.keys()[0]

    for db in database_name.split(":"):
        template_ds_lst.append(build_ds_params(dlpx_obj, database, db))
    try:
        js_template_params.data_sources = template_ds_lst
        js_template_params.type = "JSDataTemplateCreateParameters"
        template.create(dlpx_obj.server_session, js_template_params)
        dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job
        print_info(
            "Template {} was created successfully.\n".format(template_name))
    except (DlpxException, RequestError, HttpError) as e:
        print_exception("\nThe template {} was not created. The error "
                        "was:\n\n{}".format(template_name, e))
def delete_authorization(dlpx_obj, role_name, target_type, target_name, user_name):
    """
    Function to delete a given authorization

    :param dlpx_obj: Virtualization Engine session object
    :type dlpx_obj: lib.GetSession.GetSession
    :param role_name: Name of the role
    :type role_name: basestring
    :param target_type: Supports snapshot, group and database target types
    :type target_type basestring
    :param target_name: Name of the target
    :type target_name: basestring
    :param user_name: User for the authorization
    :type user_name: basestring
    """
    target_obj = find_target_type(dlpx_obj, target_type, target_name)
    user_obj = find_obj_by_name(dlpx_obj.server_session, user, user_name)
    role_obj = find_obj_by_name(dlpx_obj.server_session, role, role_name)
    auth_objs = authorization.get_all(dlpx_obj.server_session)

    try:

        del_auth_str = "({}, {}, {})".format(
            user_obj.reference, role_obj.reference, target_obj.reference
        )
        for auth_obj in auth_objs:
            if auth_obj.name == del_auth_str:
                authorization.delete(dlpx_obj.server_session, auth_obj.reference)
    except DlpxException as e:
        print_exception("ERROR: Could not delete authorization:\n{}".format(e))
    print("{} for user {} was deleted successfully".format(target_name, user_name))
Пример #16
0
def delete_container(dlpx_obj, container_name, keep_vdbs=False):
    """
    Deletes a container

    dlpx_obj: Virtualization Engine session object
    container_name: Container to delete
    """

    try:
        if keep_vdbs:
            js_container_params = JSDataContainerDeleteParameters()
            js_container_params.delete_data_sources = False
            container.delete(
                dlpx_obj.server_session,
                get_obj_reference(dlpx_obj.server_session, container,
                                  container_name).pop(),
                js_container_params,
            )
        elif keep_vdbs is False:
            container.delete(
                dlpx_obj.server_session,
                get_obj_reference(dlpx_obj.server_session, container,
                                  container_name).pop(),
            )
    except (DlpxException, RequestError, HttpError) as e:
        print_exception("\nContainer {} was not deleted. The error "
                        "was:\n{}\n".format(container_name, e))
Пример #17
0
def add_owner(dlpx_obj, owner_name, container_name):
    """
    Adds an owner to a container

    dlpx_obj: Virtualization Engine session object
    owner_name: Grant authorizations for the given user on this container and
        parent template
    container_name: Name of the container
    """

    owner_params = JSDataContainerModifyOwnerParameters()
    try:
        owner_params.owner = get_obj_reference(dlpx_obj.server_session, user,
                                               owner_name).pop()
        container.add_owner(
            dlpx_obj.server_session,
            get_obj_reference(dlpx_obj.server_session, container,
                              container_name).pop(),
            owner_params,
        )
        print_info("User {} was granted access to {}".format(
            owner_name, container_name))
    except (DlpxException, RequestError, HttpError) as e:
        print_exception("The user was not added to container {}. The error"
                        " was:\n{}\n".format(container_name, e))
Пример #18
0
def create_replication_job():
    """
    Create a replication job
    :return: Reference to the spec object
    """
    rep_spec = ReplicationSpec()
    rep_spec.name = arguments['--rep_name']
    rep_spec.target_host = arguments['--target_host']
    rep_spec.target_principal = arguments['--target_user']
    rep_spec.target_credential = {'type': 'PasswordCredential', 'password':
        arguments['--target_pw']}
    rep_spec.object_specification = ReplicationList()
    rep_spec.schedule = arguments['--schedule']
    rep_spec.encrypted = True

    if arguments['--num_cons']:
        rep_spec.number_of_connections = int(arguments['--num_cons'])
    if arguments['--bandwidth']:
        rep_spec.bandwidth_limit = int(arguments['--bandwidth'])
    if arguments['--enabled']:
        rep_spec.enabled = True
    try:
        rep_spec.object_specification.objects = find_obj_specs(
            dx_session_obj.server_session, arguments['--rep_objs'].split(','))

        ref = spec.create(dx_session_obj.server_session, rep_spec)
        if dx_session_obj.server_session.last_job:
            dx_session_obj.jobs[dx_session_obj.server_session.address] = \
                dx_session_obj.server_session.last_job
        print_info('Successfully created {} with reference '
                   '{}\n'.format(arguments['--rep_name'], ref))

    except (HttpError, RequestError, DlpxException) as e:
        print_exception('Could not create replication job {}:\n{}'.format(
            arguments['--rep_name'], e))
Пример #19
0
def list_containers(dlpx_obj):
    """
    List all containers on a given engine

    dlpx_obj: Virtualization Engine session object
    """

    header = "Name, Active Branch, Owner, Reference, Template, Last Updated"
    js_containers = container.get_all(dlpx_obj.server_session)
    try:
        print(header)
        for js_container in js_containers:
            last_updated = convert_timestamp(dlpx_obj.server_session,
                                             js_container.last_updated[:-5])
            print_info("{}, {}, {}, {}, {}, {}".format(
                js_container.name,
                js_container.active_branch,
                str(js_container.owner),
                str(js_container.reference),
                str(js_container.template),
                last_updated,
            ))
    except (DlpxException, HttpError, RequestError) as e:
        print_exception("\nERROR: JS Containers could not be listed. The "
                        "error was:\n\n{}".format(e))
def link_ase_dsource(engine_name):
    """
    Link an ASE dSource
    """

    link_params = LinkParameters()
    link_params.name = arguments['--dsource_name']
    link_params.link_data = ASELinkData()
    link_params.link_data.db_credentials = {'type': 'PasswordCredential',
                                            'password':
                                                arguments['--ase_passwd']}
    link_params.link_data.db_user = arguments['--ase_user']
    link_params.link_data.load_backup_path = arguments['--backup_path']

    if arguments['--bck_file']:
        link_params.link_data.sync_parameters = \
            ASESpecificBackupSyncParameters()
        bck_files = (arguments['--bck_file']).split(' ')
        link_params.link_data.sync_parameters.backup_files = bck_files

    elif arguments['--create_bckup']:
        link_params.link_data.sync_parameters = ASENewBackupSyncParameters()

    else:
        link_params.link_data.sync_parameters = ASELatestBackupSyncParameters()

    try:
        link_params.group = find_obj_by_name(
            dx_session_obj.server_session, group,
            arguments['--dx_group']).reference
        env_user_ref = link_params.link_data.stage_user = find_obj_by_name(
            dx_session_obj.server_session, environment,
            arguments['--env_name']).primary_user
        link_params.link_data.staging_host_user = env_user_ref
        link_params.link_data.source_host_user = env_user_ref

        link_params.link_data.config = find_obj_by_name(
            dx_session_obj.server_session, sourceconfig,
            arguments['--src_config']).reference
        link_params.link_data.staging_repository = find_obj_by_name(
            dx_session_obj.server_session, repository,
            arguments['--stage_repo']).reference

    except DlpxException as e:
        print_exception('Could not link {}: {}\n'.format(
            arguments['--dsource_name'], e))
        sys.exit(1)

    try:
        dsource_ref = 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)
        print '{} sucessfully linked {}'.format(dsource_ref,
                                                arguments['--dsource_name'])
    except (RequestError, HttpError) as e:
        print_exception('Database link failed for {}:\n{}'.format(
            arguments['--dsource_name'], e))
def dx_obj_operation(dlpx_obj, vdb_name, operation):
    """
    Function to start, stop, enable or disable a VDB

    :param dlpx_obj: Virtualization Engine session object
    :type dlpx_obj: lib.GetSession.GetSession
    :param vdb_name: Name of the object to stop/start/enable/disable
    :type vdb_name: str
    :param operation: enable or disable dSources and VDBs
    :type operation: str
    """

    print_debug("Searching for {} reference.\n".format(vdb_name))
    engine_name = dlpx_obj.dlpx_engines.keys()[0]
    vdb_obj = find_obj_by_name(dlpx_obj.server_session, source, vdb_name)
    try:
        if vdb_obj:
            if operation == "start":
                source.start(dlpx_obj.server_session, vdb_obj.reference)
            elif operation == "stop":
                source.stop(dlpx_obj.server_session, vdb_obj.reference)
            elif operation == "enable":
                source.enable(dlpx_obj.server_session, vdb_obj.reference)
            elif operation == "disable":
                source.disable(dlpx_obj.server_session, vdb_obj.reference)
            elif operation == "force_disable":
                disable_params = SourceDisableParameters()
                disable_params.attempt_cleanup = False
                source.disable(dlpx_obj.server_session, vdb_obj.reference,
                               disable_params)
            dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job
    except (RequestError, HttpError, JobError, AttributeError) as e:
        print_exception("An error occurred while performing {} on {}:\n"
                        "{}".format(operation, vdb_name, e))
    print("{} was successfully performed on {}.".format(operation, vdb_name))
def find_target_type(dlpx_obj, target_type, target_name):
    """
    Function to find the target authorization

    :param dlpx_obj: Virtualization Engine session object
    :type dlpx_obj: lib.GetSession.GetSession
    :param target_type: Type of target for authorization
    :param target_name: Name of the target
    """

    target_obj = None
    try:
        if target_type.lower() == "group":
            target_obj = find_obj_by_name(dlpx_obj.server_session, group, target_name)
        elif target_type.lower() == "database":
            target_obj = find_obj_by_name(
                dlpx_obj.server_session, database, target_name
            )
        elif target_type.lower() == "snapshot":
            target_obj = find_obj_by_name(
                dlpx_obj.server_session, snapshot, target_name
            )
    except (DlpxException, RequestError, HttpError) as e:
        print_exception(
            "Could not find authorization target type " "{}:\n{}".format(target_type, e)
        )
    return target_obj
def rewind_database(dlpx_obj, vdb_name, timestamp, timestamp_type='SNAPSHOT'):
    """
    This function performs the rewind (rollback)

    dlpx_obj: Virtualization Engine session object
    vdb_name: VDB to be rewound
    timestamp: Point in time to rewind the VDB
    timestamp_type: The type of timestamp being used for the rewind
    """

    engine_name = dlpx_obj.dlpx_engines.keys()[0]
    dx_timeflow_obj = DxTimeflow(dlpx_obj.server_session)
    container_obj = find_obj_by_name(dlpx_obj.server_session, database,
                                     vdb_name)
    # Sanity check to make sure our container object has a reference
    if container_obj.reference:
        try:
            if container_obj.virtual is not True:
                raise DlpxException('{} in engine {} is not a virtual object. '
                                    'Skipping.\n'.format(container_obj.name,
                                    engine_name))
            elif container_obj.staging is True:
                raise DlpxException('{} in engine {} is a virtual object. '
                                    'Skipping.\n'.format(container_obj.name,
                                    engine_name))
            elif container_obj.runtime.enabled == "ENABLED":
                print_info('\nINFO: {} Rewinding {} to {}\n'.format(
                           engine_name, container_obj.name, timestamp))

        # This exception is raised if rewinding a vFiles VDB
        # since AppDataContainer does not have virtual, staging or
        # enabled attributes.
        except AttributeError:
            pass

        print_debug('{}: Type: {}'.format(engine_name, container_obj.type))

        # If the vdb is a Oracle type, we need to use a OracleRollbackParameters
        if str(container_obj.reference).startswith("ORACLE"):
            rewind_params = OracleRollbackParameters()
        else:
            rewind_params = RollbackParameters()
        rewind_params.timeflow_point_parameters = \
            dx_timeflow_obj.set_timeflow_point(container_obj, timestamp_type,
                                               timestamp)
        print_debug('{}: {}'.format(engine_name, str(rewind_params)))
        try:
            # Rewind the VDB
            database.rollback(dlpx_obj.server_session, container_obj.reference,
                              rewind_params)
            dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job
            print_info('VDB {} was rolled back.'.format(container_obj.name))
        except (RequestError, HttpError, JobError) as e:
            print_exception('ERROR: {} encountered an error on {}'
                            ' during the rewind process:\n{}'.format(
                engine_name, container_obj.name, e))
    # Don't do anything if the database is disabled
    else:
        print_info('{}: {} is not enabled. Skipping sync.'.format(engine_name,
                                                            container_obj.name))
def list_authorization(dlpx_obj):
    """
    Function to list authorizations for a given engine

    :param dlpx_obj: Virtualization Engine session object
    """
    target_obj = None

    try:
        auth_objs = authorization.get_all(dlpx_obj.server_session)
        print_info("User, Role, Target, Reference")
        for auth_obj in auth_objs:
            role_obj = role.get(dlpx_obj.server_session, auth_obj.role)
            user_obj = user.get(dlpx_obj.server_session, auth_obj.user)
            if auth_obj.target.startswith("USER"):
                target_obj = user.get(dlpx_obj.server_session, auth_obj.target)
            elif auth_obj.target.startswith("GROUP"):
                target_obj = group.get(dlpx_obj.server_session, auth_obj.target)
            elif auth_obj.target.startswith("DOMAIN"):
                target_obj = User()
                target_obj.name = "DOMAIN"
            print(
                "{}, {}, {}, {}".format(
                    user_obj.name, role_obj.name, target_obj.name, auth_obj.reference
                )
            )
    except (RequestError, HttpError, JobError, AttributeError) as e:
        print_exception(
            "An error occurred while listing authorizations.:\n" "{}\n".format((e))
        )
def link_ora_dsource(srcconfig_ref, primary_user_ref):
    """
    :param srcconfig_ref: Reference to the sourceconfig object
    :param primary_user_ref: Reference to the environment user
    :return: Reference of the linked dSource
    """

    link_params = LinkParameters()
    link_params.link_data = OracleLinkData()
    link_params.link_data.sourcing_policy = OracleSourcingPolicy()
    link_params.name = arguments['--dsource_name']
    link_params.group = find_obj_by_name(dx_session_obj.server_session, group,
                                         arguments['--dx_group']).reference
    link_params.link_data.compressedLinkingEnabled = True
    link_params.link_data.environment_user = primary_user_ref
    link_params.link_data.db_user = arguments['--db_user']
    link_params.link_data.number_of_connections = \
        int(arguments['--num_connections'])
    link_params.link_data.link_now = bool(arguments['--link_now'])
    link_params.link_data.files_per_set = int(arguments['--files_per_set'])
    link_params.link_data.rman_channels = int(arguments['--rman_channels'])
    link_params.link_data.db_credentials = {'type': 'PasswordCredential',
                                            'password':
                                                arguments['--db_passwd']}
    link_params.link_data.sourcing_policy.logsync_enabled = True
    #link_params.link_data.sourcing_policy.logsync_mode = 'ARCHIVE_REDO_MODE'
    link_params.link_data.config = srcconfig_ref
    try:
        return database.link(dx_session_obj.server_session, link_params)
    except (RequestError, HttpError) as e:
        print_exception('Database link failed for {}:\n{}\n'.format(
            arguments['--dsource_name'], e))
        sys.exit(1)
def create_authorization(dlpx_obj, role_name, target_type, target_name, user_name):
    """
    Function to start, stop, enable or disable a VDB

    :param dlpx_obj: Virtualization Engine session object
    :type dlpx_obj: lib.GetSession.GetSession
    :param role_name: Name of the role
    :param target_type: Supports snapshot, group and database target types
    :param target_name: Name of the target
    :param user_name: User for the authorization
    """

    authorization_obj = Authorization()
    print_debug(
        "Searching for {}, {} and {} references.\n".format(
            role_name, target_name, user_name
        )
    )
    try:
        authorization_obj.role = find_obj_by_name(
            dlpx_obj.server_session, role, role_name
        ).reference
        authorization_obj.target = find_target_type(
            dlpx_obj, target_type, target_name
        ).reference
        authorization_obj.user = find_obj_by_name(
            dlpx_obj.server_session, user, user_name
        ).reference
        authorization.create(dlpx_obj.server_session, authorization_obj)
    except (RequestError, HttpError, JobError) as e:
        print_exception(
            "An error occurred while creating authorization:\n" "{}".format(e)
        )
    print("Authorization successfully created for {}.".format(user_name))
def link_ase_dsource(engine_name):
    """
    Link an ASE dSource
    """

    link_params = LinkParameters()
    link_params.name = arguments['--dsource_name']
    link_params.link_data = ASELinkData()
    link_params.link_data.db_credentials = {'type': 'PasswordCredential',
                                            'password':
                                                arguments['--ase_passwd']}
    link_params.link_data.db_user = arguments['--ase_user']
    link_params.link_data.load_backup_path = arguments['--backup_path']

    if arguments['--bck_file']:
        link_params.link_data.sync_parameters = \
            ASESpecificBackupSyncParameters()
        bck_files = (arguments['--bck_file']).split(' ')
        link_params.link_data.sync_parameters.backup_files = bck_files

    elif arguments['--create_bckup']:
        link_params.link_data.sync_parameters = ASENewBackupSyncParameters()

    else:
        link_params.link_data.sync_parameters = ASELatestBackupSyncParameters()

    try:
        link_params.group = find_obj_by_name(
            dx_session_obj.server_session, group,
            arguments['--dx_group']).reference
        env_user_ref = link_params.link_data.stage_user = find_obj_by_name(
            dx_session_obj.server_session, environment,
            arguments['--env_name']).primary_user
        link_params.link_data.staging_host_user = env_user_ref
        link_params.link_data.source_host_user = env_user_ref

        link_params.link_data.config = find_obj_by_name(
            dx_session_obj.server_session, sourceconfig,
            arguments['--src_config']).reference
        link_params.link_data.staging_repository = find_obj_by_name(
            dx_session_obj.server_session, repository,
            arguments['--stage_repo']).reference

    except DlpxException as e:
        print_exception('Could not link {}: {}\n'.format(
            arguments['--dsource_name'], e))
        sys.exit(1)

    try:
        dsource_ref = 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)
        print '{} sucessfully linked {}'.format(dsource_ref,
                                                arguments['--dsource_name'])
    except (RequestError, HttpError) as e:
        print_exception('Database link failed for {}:\n{}'.format(
            arguments['--dsource_name'], e))
Пример #28
0
def restore_container(dlpx_obj, container_name, bookmark_name):
    """
    Restores a container to a given JS bookmark

    dlpx_obj: Virtualization Engine session object
    container_name: Name of the container
    bookmark_name: Name of the bookmark to restore
    """
    bookmark_params = JSTimelinePointBookmarkInput()
    bookmark_params.bookmark = get_obj_reference(dlpx_obj.server_session,
                                                 bookmark,
                                                 bookmark_name).pop()
    engine_name = dlpx_obj.dlpx_engines.keys()[0]
    try:
        container.restore(
            dlpx_obj.server_session,
            get_obj_reference(dlpx_obj.server_session, container,
                              container_name).pop(),
            bookmark_params,
        )
        dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job
        print_info("Container {} was restored successfully with "
                   "bookmark {}".format(container_name, bookmark_name))
    except (DlpxException, RequestError, HttpError) as e:
        print_exception("The user was not added to container {}. The "
                        "error was:\n{}\n".format(container_name, e))
Пример #29
0
def main_workflow(engine):
    """
    This function actually runs the jobs.
    Use the @run_async decorator to run this function asynchronously.
    This allows us to run against multiple Delphix Engine simultaneously

    engine: Dictionary of engines
    """
    try:
        #Setup the connection to the Delphix Engine
        dx_session_obj.serversess(engine['ip_address'], engine['username'],
                                  engine['password'])

    except DlpxException as e:
        print_exception('\nERROR: Engine {} encountered an error while' 
                        '{}:\n{}\n'.format(engine['hostname'],
                        arguments['--target'], e))
        sys.exit(1)

    thingstodo = ["thingtodo"]
    try:
        with dx_session_obj.job_mode(single_thread):
            while (len(dx_session_obj.jobs) > 0 or len(thingstodo)> 0):
                if len(thingstodo) > 0:
                    if arguments['--add'] :
                        add_user(arguments['--user_name'], arguments['--password'], arguments['--email'], arguments['--jsonly'])
                    elif arguments['--update'] :
                        update_user(arguments['--user_name'], arguments['--password'], arguments['--email'], arguments['--jsonly'])
                    elif arguments['--delete']:
                        delete_user(arguments['--user_name'])
                    elif arguments['--list']:
                        list_users()
                    thingstodo.pop()
                # get all the jobs, then inspect them
                i = 0
                for j in dx_session_obj.jobs.keys():
                    job_obj = job.get(dx_session_obj.server_session,
                                      dx_session_obj.jobs[j])
                    print_debug(job_obj)
                    print_info('{}: User: {}'.format(
                        engine['hostname'], job_obj.job_state))
                    if job_obj.job_state in ["CANCELED", "COMPLETED", "FAILED"]:
                        # If the job is in a non-running state, remove it
                        # from the
                        # running jobs list.
                        del dx_session_obj.jobs[j]
                    elif job_obj.job_state in 'RUNNING':
                        # If the job is in a running state, increment the
                        # running job count.
                        i += 1
                    print_info('{}: {:d} jobs running.'.format(
                               engine['hostname'], i))
                    # If we have running jobs, pause before repeating the
                    # checks.
                    if len(dx_session_obj.jobs) > 0:
                        sleep(float(arguments['--poll']))

    except (HttpError, RequestError, JobError, DlpxException) as e:
        print_exception('ERROR: Could not complete user '
                        'operation: {}'.format(e))
Пример #30
0
def list_bookmarks(dlpx_obj, tag_filter=None):
    """
    List all bookmarks on a given engine

    :param dlpx_obj: Virtualization Engine session object
    :param tag_filter: Only list bookmarks with given tag

    """

    header = '\nName, Reference, Branch Name, Template Name, Tags'
    try:
        js_bookmarks = bookmark.get_all(dlpx_obj.server_session)
        print header
        for js_bookmark in js_bookmarks:
            branch_name = find_obj_name(dlpx_obj.server_session, branch,
                                        js_bookmark.branch)
            if tag_filter in js_bookmark.tags:
                print '{}, {}, {}, {}, {}'.format(
                    js_bookmark.name, js_bookmark.reference, branch_name,
                    js_bookmark.template_name,
                    ", ".join(tag for tag in js_bookmark.tags))
            elif tag_filter is None:
                tag = js_bookmark.tags if js_bookmark.tags else None
                if tag:
                    tag = ", ".join(tag for tag in js_bookmark.tags)
                print '{}, {}, {}, {}, {}'.format(js_bookmark.name,
                                                  js_bookmark.reference,
                                                  branch_name,
                                                  js_bookmark.template_name,
                                                  tag)
        print '\n'

    except (DlpxException, HttpError, RequestError) as e:
        print_exception('\nERROR: The bookmarks on could not be listed. The '
                        'error was:\n\n{}'.format(e))
def main_workflow(engine, dlpx_obj):
    """
    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: Virtualization Engine session object
    :type dlpx_obj: lib.GetSession.GetSession
    """

    try:
        #Setup the connection to the Delphix Engine
        dlpx_obj.serversess(engine['ip_address'], engine['username'],
                                  engine['password'])
    except DlpxException as e:
        print_exception('ERROR: Engine {} encountered an error while'
                        'rewinding {}:\n{}\n'.format(engine['hostname'],
                                                     arguments['--target'], e))

    thingstodo = ["thingtodo"]
    try:
        with dlpx_obj.job_mode(single_thread):
            while len(dlpx_obj.jobs) > 0 or len(thingstodo) > 0:
                if len(thingstodo) > 0:
                    rewind_database(dlpx_obj, arguments['--vdb'],
                                    arguments['--timestamp'],
                                    arguments['--timestamp_type'])
                    thingstodo.pop()

                # get all the jobs, then inspect them
                i = 0
                for j in dlpx_obj.jobs.keys():
                    job_obj = job.get(dlpx_obj.server_session,
                                      dlpx_obj.jobs[j])
                    print_debug(job_obj)
                    print_info('{}: Refresh of {}: {}'.format(
                        engine['hostname'], arguments['--vdb'],
                        job_obj.job_state))
                    if job_obj.job_state in ['CANCELED', 'COMPLETED', 'FAILED']:
                        # If the job is in a non-running state, remove it
                        # from the running jobs list.
                        del dlpx_obj.jobs[j]
                    elif job_obj.job_state in 'RUNNING':
                        # If the job is in a running state, increment the
                        # running job count.
                        i += 1
                    print_info('{}: {:d} jobs running.'.format(
                        engine['hostname'], i))
                    # If we have running jobs, pause before repeating the
                    # checks.
                    if len(dlpx_obj.jobs) > 0:
                        sleep(float(arguments['--poll']))
    except (DlpxException, RequestError, JobError, HttpError) as e:
        print_exception('Error in dx_rewind_vdb: {}\n{}'.format(
            engine['hostname'], e))
        sys.exit(1)
Пример #32
0
def main_workflow(engine, dlpx_obj):
    """
    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: Virtualization Engine session object
    :type dlpx_obj: lib.GetSession.GetSession
    """

    try:
        #Setup the connection to the Delphix Engine
        dlpx_obj.serversess(engine['ip_address'], engine['username'],
                                  engine['password'])
    except DlpxException as e:
        print_exception('ERROR: Engine {} encountered an error while'
                        'rewinding {}:\n{}\n'.format(engine['hostname'],
                                                     arguments['--target'], e))

    thingstodo = ["thingtodo"]
    try:
        with dlpx_obj.job_mode(single_thread):
            while len(dlpx_obj.jobs) > 0 or len(thingstodo) > 0:
                if len(thingstodo) > 0:
                    rewind_database(dlpx_obj, arguments['--vdb'],
                                    arguments['--timestamp'],
                                    arguments['--timestamp_type'])
                    thingstodo.pop()

                # get all the jobs, then inspect them
                i = 0
                for j in dlpx_obj.jobs.keys():
                    job_obj = job.get(dlpx_obj.server_session,
                                      dlpx_obj.jobs[j])
                    print_debug(job_obj)
                    print_info('{}: Refresh of {}: {}'.format(
                        engine['hostname'], arguments['--vdb'],
                        job_obj.job_state))
                    if job_obj.job_state in ['CANCELED', 'COMPLETED', 'FAILED']:
                        # If the job is in a non-running state, remove it
                        # from the running jobs list.
                        del dlpx_obj.jobs[j]
                    elif job_obj.job_state in 'RUNNING':
                        # If the job is in a running state, increment the
                        # running job count.
                        i += 1
                    print_info('{}: {:d} jobs running.'.format(
                        engine['hostname'], i))
                    # If we have running jobs, pause before repeating the
                    # checks.
                    if len(dlpx_obj.jobs) > 0:
                        sleep(float(arguments['--poll']))
    except (DlpxException, RequestError, JobError, HttpError) as e:
        print_exception('Error in dx_rewind_vdb: {}\n{}'.format(
            engine['hostname'], e))
        sys.exit(1)
Пример #33
0
def main_workflow(engine):
    """
    This function actually runs the jobs.
    Use the @run_async decorator to run this function asynchronously.
    This allows us to run against multiple Delphix Engine simultaneously

    engine: Dictionary of engines
    """
    jobs = {}

    try:
        #Setup the connection to the Delphix Engine
        dx_session_obj.serversess(engine['ip_address'], engine['username'],
                                  engine['password'])

    except DlpxException as e:
        print_exception('\nERROR: Engine %s encountered an error while'
                        '%s:\n%s\n' %
                        (engine['hostname'], arguments['--target'], e))
        sys.exit(1)

    thingstodo = ["thingtodo"]
    #reset the running job count before we begin
    i = 0
    with dx_session_obj.job_mode(single_thread):
        while (len(jobs) > 0 or len(thingstodo) > 0):
            if len(thingstodo) > 0:
                if arguments['--pw']:
                    update_ase_db_pw()

                #elif OPERATION:
                #    method_call

                thingstodo.pop()

            #get all the jobs, then inspect them
            i = 0
            for j in jobs.keys():
                job_obj = job.get(dx_session_obj.server_session, jobs[j])
                print_debug(job_obj)
                print_info(engine["hostname"] + ": VDB Operations: " +
                           job_obj.job_state)

                if job_obj.job_state in ["CANCELED", "COMPLETED", "FAILED"]:
                    #If the job is in a non-running state, remove it from the
                    # running jobs list.
                    del jobs[j]
                else:
                    #If the job is in a running state, increment the running
                    # job count.
                    i += 1

            print_info(engine["hostname"] + ": " + str(i) + " jobs running. ")
            #If we have running jobs, pause before repeating the checks.
            if len(jobs) > 0:
                sleep(float(arguments['--poll']))
def main_workflow(engine):
    """
    This function actually runs the jobs.
    Use the @run_async decorator to run this function asynchronously.
    This allows us to run against multiple Delphix Engine simultaneously

    engine: Dictionary of engines
    """
    jobs = {}

    try:
        #Setup the connection to the Delphix Engine
        dx_session_obj.serversess(engine['ip_address'], engine['username'],
                                  engine['password'])

    except DlpxException as e:
        print_exception('\nERROR: Engine {} encountered an error while'
                        '{}:\n{}\n'.format(engine['hostname'],
                        arguments['--target'], e))
        sys.exit(1)

    thingstodo = ["thingtodo"]
    #reset the running job count before we begin
    i = 0
    with dx_session_obj.job_mode(single_thread):
        while (len(jobs) > 0 or len(thingstodo)> 0):
            if len(thingstodo)> 0:

                #if OPERATION:
                find_missing_archivelogs(engine['hostname'])

                thingstodo.pop()

            #get all the jobs, then inspect them
            i = 0
            for j in jobs.keys():
                job_obj = job.get(dx_session_obj.server_session, jobs[j])
                print_debug(job_obj)
                print_info('{}: VDB Operations:{}\n'.format(engine['hostname'],
                           job_obj.job_state))

                if job_obj.job_state in ["CANCELED", "COMPLETED", "FAILED"]:
                    #If the job is in a non-running state, remove it from the
                    # running jobs list.
                    del jobs[j]
                else:
                    #If the job is in a running state, increment the running
                    # job count.
                    i += 1

            print_info(engine["hostname"] + ": " + str(i) + " jobs running. ")
            #If we have running jobs, pause before repeating the checks.
            if len(jobs) > 0:
                sleep(float(arguments['--poll']))
def main_workflow(engine):
    """
    This function actually runs the jobs.
    Use the @run_async decorator to run this function asynchronously.
    This allows us to run against multiple Delphix Engine simultaneously

    engine: Dictionary of engines
    """
    jobs = {}

    try:
        #Setup the connection to the Delphix Engine
        dx_session_obj.serversess(engine['ip_address'], engine['username'],
                                  engine['password'])

    except DlpxException as e:
        print_exception('\nERROR: Engine {} encountered an error while' 
                        '{}:\n{}\n'.format(engine['hostname'],
                        arguments['--target'], e))
        sys.exit(1)

    thingstodo = ["thingtodo"]
    with dx_session_obj.job_mode(single_thread):
        while len(dx_session_obj.jobs) > 0 or len(thingstodo) > 0:
            if len(thingstodo)> 0:
                refresh_database(arguments['--vdb'],
                                    arguments['--timestamp'],
                                    arguments['--timestamp_type'])
                thingstodo.pop()

            #get all the jobs, then inspect them
            i = 0
            for j in dx_session_obj.jobs.keys():
                job_obj = job.get(dx_session_obj.server_session,
                                  dx_session_obj.jobs[j])
                print_debug(job_obj)
                print_info('{}: Operations: {}'.format(engine['hostname'],
                                                       job_obj.job_state))
                if job_obj.job_state in ["CANCELED", "COMPLETED", "FAILED"]:
                    #If the job is in a non-running state, remove it from the
                    # running jobs list.
                    del dx_session_obj.jobs[j]
                elif job_obj.job_state in 'RUNNING':
                    #If the job is in a running state, increment the running
                    # job count.
                    i += 1

                print_info('{}: {:d} jobs running.'.format(
                    engine['hostname'], i))

            #If we have running jobs, pause before repeating the checks.
            if len(dx_session_obj.jobs) > 0:
                sleep(float(arguments['--poll']))
Пример #36
0
def main_workflow(engine):
    """
    This function actually runs the jobs.
    Use the @run_async decorator to run this function asynchronously.
    This allows us to run against multiple Delphix Engine simultaneously

    engine: Dictionary of engines
    """
    jobs = {}

    try:
        #Setup the connection to the Delphix Engine
        dx_session_obj.serversess(engine['ip_address'], engine['username'],
                                  engine['password'])

    except DlpxException as e:
        print_exception('\nERROR: Engine {} encountered an error while'
                        '{}:\n{}\n'.format(engine['hostname'],
                                           arguments['--target'], e))
        sys.exit(1)

    thingstodo = ["thingtodo"]
    with dx_session_obj.job_mode(single_thread):
        while len(dx_session_obj.jobs) > 0 or len(thingstodo) > 0:
            if len(thingstodo) > 0:

                if arguments['--list']:
                    list_jobs()
                thingstodo.pop()

            # get all the jobs, then inspect them
            i = 0
            for j in dx_session_obj.jobs.keys():
                job_obj = job.get(dx_session_obj.server_session,
                                  dx_session_obj.jobs[j])
                print_debug(job_obj)
                print_info('{}: Operations: {}'.format(engine['hostname'],
                                                       job_obj.job_state))
                if job_obj.job_state in ["CANCELED", "COMPLETED", "FAILED"]:
                    # If the job is in a non-running state, remove it from the
                    # running jobs list.
                    del dx_session_obj.jobs[j]
                elif job_obj.job_state in 'RUNNING':
                    # If the job is in a running state, increment the running
                    # job count.
                    i += 1

                print_info('{}: {:d} jobs running.'.format(
                    engine['hostname'], i))

            # If we have running jobs, pause before repeating the checks.
            if len(dx_session_obj.jobs) > 0:
                sleep(float(arguments['--poll']))
Пример #37
0
def reset_container(dlpx_obj, container_name):
    """
    Undo the last refresh or restore operation
    :param dlpx_obj: Virtualization Engine session object
    :param container_name: Name of the container to reset
    """
    try:
        container.reset(dlpx_obj.server_session, find_obj_by_name(
            dlpx_obj.server_session, container, container_name).reference)
    except RequestError as e:
        print_exception('\nERROR: JS Container was not reset. The '
                        'error was:\n\n{}'.format(e))
    print 'Container {} was reset.\n'.format(container_name)
Пример #38
0
def delete_user(user_name):
    """
    This function adds the user
    """
    user_obj = find_obj_by_name(dx_session_obj.server_session, user, user_name)

    try:
        user.delete(dx_session_obj.server_session, user_obj.reference)
        print('Attempting to delete {}'.format(user_name))
    except (DlpxException, RequestError) as e:
        print_exception('\nERROR: Deleting the user {} '
                        'encountered an error:\n{}'.format(user_name, e))
        sys.exit(1)
Пример #39
0
def delete_group(group_name):
    """
    This function adds the group
    """
    group_obj = find_obj_by_name(dx_session_obj.server_session, group,
                                 group_name)

    try:
        group.delete(dx_session_obj.server_session, group_obj.reference)
        print("Attempting to delete {}".format(group_name))
    except (DlpxException, RequestError) as e:
        print_exception("\nERROR: Deleting the group {} "
                        "encountered an error:\n{}".format(group_name, e))
        sys.exit(1)
Пример #40
0
def add_group(group_name):
    """
    This function adds the group
    """
    group_obj = Group()
    group_obj.name = group_name

    try:
        group.create(dx_session_obj.server_session, group_obj)
        print("Attempting to create {}".format(group_name))
    except (DlpxException, RequestError) as e:
        print_exception("\nERROR: Creating the group {} "
                        "encountered an error:\n{}".format(group_name, e))
        sys.exit(1)
Пример #41
0
def delete_branch(dlpx_obj, branch_name):
    """
    Deletes a branch
    :param dlpx_obj: Virtualization Engine session object
    :param branch_name: Branch to delete
    """

    try:
        branch_obj = find_obj_by_name(dlpx_obj.server_session,
                                      branch, branch_name)
        branch.delete(dlpx_obj.server_session, branch_obj.reference)
    except (DlpxException, HttpError, RequestError) as e:
        print_exception('\nERROR: The branch was not deleted. The '
                            'error was:\n\n{}'.format(e.message))
def disable_environment(dlpx_obj, env_name):
    """
    Enable the given host
    """
    engine_name = dlpx_obj.dlpx_engines.keys()[0]
    env_obj = find_obj_by_name(dlpx_obj.server_session, environment, env_name)

    try:
        environment.disable(dlpx_obj.server_session, env_obj.reference)
        print("Attempting to disable {}".format(env_name))
    except (DlpxException, RequestError) as e:
        print_exception("\nERROR: Disabling the host {} "
                        "encountered an error:\n{}".format(env_name, e))
        sys.exit(1)
Пример #43
0
def execute_replication_job(obj_name):
    """
    Execute a replication job immediately.
    :param obj_name: name of object to execute.
    """
    try:
        spec.execute(dx_session_obj.server_session,
                     find_obj_by_name(dx_session_obj.server_session,
                                      spec, obj_name).reference)
        if dx_session_obj.server_session.last_job:
            dx_session_obj.jobs[dx_session_obj.server_session.address] = \
                dx_session_obj.server_session.last_job
        print_info('Successfully executed {}.\n'.format(obj_name))
    except (HttpError, RequestError, DlpxException, JobError) as e:
        print_exception('Could not execute job {}:\n{}'.format(obj_name, e))
def disable_environment(dlpx_obj,env_name):
    """
    Enable the given host
    """
    engine_name = dlpx_obj.dlpx_engines.keys()[0]
    env_obj = find_obj_by_name(dlpx_obj.server_session,
                                 environment, env_name)

    try:
      environment.disable(dlpx_obj.server_session,env_obj.reference)
      print('Attempting to disable {}'.format(env_name))
    except (DlpxException, RequestError) as e:
      print_exception('\nERROR: Disabling the host {} '
                      'encountered an error:\n{}'.format(env_name, e))
      sys.exit(1)    
Пример #45
0
def delete_user(user_name):
    """
    This function adds the user
    """
    user_obj = find_obj_by_name(dx_session_obj.server_session,
                                 user, user_name)
    

    try:
      user.delete(dx_session_obj.server_session,user_obj.reference)
      print('Attempting to delete {}'.format(user_name))
    except (DlpxException, RequestError) as e:
      print_exception('\nERROR: Deleting the user {} '
                      'encountered an error:\n{}'.format(user_name, e))
      sys.exit(1)
def execute_replication_job(obj_name):
    """
    Execute a replication job immediately.
    :param obj_name: name of object to execute.
    """
    try:
        spec.execute(dx_session_obj.server_session,
                     find_obj_by_name(dx_session_obj.server_session,
                                      spec, obj_name).reference)
        if dx_session_obj.server_session.last_job:
            dx_session_obj.jobs[dx_session_obj.server_session.address] = \
                dx_session_obj.server_session.last_job
        print_info('Successfully executed {}.\n'.format(obj_name))
    except (HttpError, RequestError, DlpxException, JobError) as e:
        print_exception('Could not execute job {}:\n{}'.format(obj_name, e))
Пример #47
0
def build_ds_params(dlpx_obj, obj, db):
    """
    Builds the datasource parameters

    dlpx_obj: Virtualization Engine session object
    obj: object type to use when finding db
    db: Name of the database to use when building the parameters
    """
    ds_params = JSDataSourceCreateParameters()
    ds_params.source = {"type": "JSDataSource", "name": db}
    try:
        db_obj = find_obj_by_name(dlpx_obj.server_session, obj, db)
        ds_params.container = db_obj.reference
        return ds_params
    except RequestError as e:
        print_exception("\nCould not find {}\n{}".format(db, e.message))
Пример #48
0
def delete_template(dlpx_obj, template_name):
    """
    Deletes a template

    dlpx_obj: Virtualization Engine session object
    template_name: Template to delete
    """

    try:
        template_obj = find_obj_by_name(dlpx_obj.server_session,
                                        template, template_name)
        template.delete(dlpx_obj.server_session,
                        template_obj.reference)
        print 'Template {} is deleted.'.format(template_name)
    except (DlpxException, HttpError, RequestError) as e:
        print_exception('\nERROR: The template {} was not deleted. The'
                        ' error was:\n\n{}'.format(template_name, e.message))
Пример #49
0
def share_bookmark(dlpx_obj, bookmark_name):
    """
    Share a bookmark

    :param dlpx_obj: Virtualization Engine session object
    :param bookmark_name: Name of the bookmark to share
    """

    try:
        bookmark.share(dlpx_obj.server_session,
                       get_obj_reference(dlpx_obj.server_session,
                                         bookmark, bookmark_name).pop())
        print_info('JS Bookmark {} was shared successfully.'.format(
            bookmark_name))
    except (DlpxException, HttpError, RequestError) as e:
        print_exception('\nERROR: The bookmark {} could not be shared. The '
                        'error was:\n\n{}'.format(bookmark_name, e))
def delete_replication_job():
    """
    Delete a replication job.
    :return: Reference to the spec object
    """
    try:
        spec.delete(dx_session_obj.server_session,
                    find_obj_by_name(dx_session_obj.server_session, spec,
                                     arguments['--delete']).reference)
        if dx_session_obj.server_session.last_job:
            dx_session_obj.jobs[dx_session_obj.server_session.address] = \
                dx_session_obj.server_session.last_job
        print_info('Successfully deleted {}.\n'.format(arguments['--delete']))

    except (HttpError, RequestError, DlpxException) as e:
        print_exception('Was not able to delete {}:\n{}'.format(
            arguments['--delete'], e))
Пример #51
0
def build_ds_params(dlpx_obj, obj, db):
    """
    Builds the datasource parameters

    dlpx_obj: Virtualization Engine session object
    obj: object type to use when finding db
    db: Name of the database to use when building the parameters
    """

    try:
        db_obj = find_obj_by_name(dlpx_obj.server_session,
                                  obj, db)
        ds_params = JSDataSourceCreateParameters()
        ds_params.source = {'type':'JSDataSource', 'name': db}
        ds_params.container = db_obj.reference
        return ds_params
    except RequestError as e:
        print_exception('\nCould not find {}\n{}'.format(db, e.message))
Пример #52
0
def add_user(user_name, user_password, user_email, jsonly=None):
    """
    This function adds the user
    """
    user_obj = User()
    user_obj.name = user_name
    user_obj.email_address = user_email
    user_obj.credential = PasswordCredential()
    user_obj.credential.password = user_password

    try:
      user.create(dx_session_obj.server_session,user_obj)
      print('Attempting to create {}'.format(user_name))
    except (DlpxException, RequestError) as e:
      print_exception('\nERROR: Creating the user {} '
                      'encountered an error:\n{}'.format(user_name, e))
      sys.exit(1)

    js_only(user_name, jsonly)
Пример #53
0
def update_bookmark(dlpx_obj, bookmark_name):
    """
    Updates a bookmark

    :param dlpx_obj: Virtualization Engine session object
    :param bookmark_name: Name of the bookmark to update
    """

    js_bookmark_obj = JSBookmark()
    
    try:
        bookmark.update(dlpx_obj.server_session,
                        get_obj_reference(dlpx_obj.server_session,
                                          bookmark, bookmark_name).pop(),
                        js_bookmark_obj)

    except (DlpxException, HttpError, RequestError) as e:
        print_exception('ERROR: The bookmark {} could not be updated. The '
                        'error was:\n{}'.format(bookmark_name, e))
Пример #54
0
def delete_bookmark(dlpx_obj, bookmark_name):
    """
    Deletes a bookmark

    :param dlpx_obj: Virtualization Engine session object
    :type dlpx_obj: lib.GetSession.GetSession
    :param bookmark_name: Bookmark to delete
    :type bookmark_name: str
    """

    try:
        bookmark.delete(dlpx_obj.server_session,
                        get_obj_reference(dlpx_obj.server_session,
                                          bookmark, bookmark_name).pop())
        print_info('The bookmark {} was deleted successfully.'.format(
            bookmark_name))
    except (DlpxException, HttpError, RequestError) as e:
        print_exception('\nERROR: The bookmark {} was not deleted. The '
                        'error was:\n\n{}'.format(bookmark_name, e.message))
def update_ase_username(dlpx_obj):
    """
    Update the ASE database user password
    """
    engine_name = dlpx_obj.dlpx_engines.keys()[0]

    env_obj = UnixHostEnvironment()
    env_obj.ase_host_environment_parameters = ASEHostEnvironmentParameters()
    env_obj.ase_host_environment_parameters.db_user = \
        arguments['--update_ase_user']

    try:
        environment.update(dlpx_obj.server_session, find_obj_by_name(
            dlpx_obj.server_session, environment, arguments['--env_name'],
            env_obj).reference, env_obj)

    except (HttpError, RequestError) as e:
        print_exception('\nERROR: Updating the ASE DB password '
                        'failed:\n{}\n'.format(e))
Пример #56
0
def update_branch(dlpx_obj, branch_name):
    """
    Updates a branch

    :param dlpx_obj: Virtualization Engine session object
    :param branch_name: Name of the branch to update
    """

    js_branch_obj = JSBranch()
    try:
        branch_obj = find_obj_by_name(dlpx_obj.server_session,
                                      branch, branch_name)
        branch.update(dlpx_obj.server_session, branch_obj.reference,
                      js_branch_obj)
        print_info('The branch {} was updated successfully.'.format(
            branch_name))
    except (DlpxException, HttpError, RequestError) as e:
        print_exception('\nERROR: The branch could not be updated. The '
                        'error was:\n\n{}'.format(e))
Пример #57
0
def activate_branch(dlpx_obj, branch_name):
    """
    Activates a branch

    :param dlpx_obj: Virtualization Engine session object
    :param branch_name: Name of the branch to activate
    """

    engine_name = dlpx_obj.dlpx_engines.keys()[0]
    try:
        branch_obj = find_obj_by_name(dlpx_obj.server_session,
                                      branch, branch_name)
        branch.activate(dlpx_obj.server_session, branch_obj.reference)
        dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job
        print_info('The branch {} was activated successfully.'.format(
            branch_name))
    except RequestError as e:
        print_exception('\nAn error occurred activating the '
                        'branch:\n{}'.format(e))
def update_host_address(dlpx_obj, old_host_address, new_host_address):
    """
    Update the given host
    """
    engine_name = dlpx_obj.dlpx_engines.keys()[0]
    old_host_obj = find_obj_by_name(dlpx_obj.server_session,
                                 host, old_host_address)
    if old_host_obj.type == "WindowsHost":
      host_obj = WindowsHost()
    else:
      host_obj = UnixHost()
    host_obj.address = new_host_address
    try:
      host.update(dlpx_obj.server_session, old_host_obj.reference, host_obj)

      print('Attempting to update {} to {}'.format(old_host_address, new_host_address))

    except (DlpxException, RequestError) as e:
      print_exception('\nERROR: Updating the host {} '
                      'encountered an error:\n{}'.format(env_name, e))
      sys.exit(1)