def set_with_cmo(wlst_name, wlst_value, masked=False):
    """
    Set the specified attribute using the corresponding cmo set method (e.g., cmo.setListenPort()).
    :param wlst_name: the WLST attribute name
    :param wlst_value: the WLST value
    :param masked: whether or not to mask the wlst_value from the log files.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'set_with_cmo'
    value = wlst_value
    if masked:
        value = '<masked>'

    _logger.finest('WLSDPLY-00010', wlst_name, value, class_name=_class_name, method_name=_method_name)

    set_method_name = 'set' + wlst_name
    _logger.finest('WLSDPLY-00011', set_method_name, class_name=_class_name, method_name=_method_name)

    current_cmo = get_cmo()
    if current_cmo is None:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00012', set_method_name, value, _get_wlst_mode())
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe

    try:
        set_method = getattr(current_cmo, set_method_name)
        set_method(wlst_value)
    except AttributeError, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00013', set_method_name, _get_exception_mode(e),
                                                       _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
def create(name, folder, base_provider_type=None):
    """
    Create the mbean folder with the provided name at the current location.

    :param name: to create under the folder
    :param folder: name of the mbean folder
    :param base_provider_type: the name of the security provider base type
    :return: the MBean object returned by the underlying WLST create() method
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'create'
    _logger.finest('WLSDPLY-00016', name, folder, base_provider_type, class_name=_class_name, method_name=_method_name)

    try:
        if base_provider_type is None:
            result = wlst.create(name, folder)
        else:
            if not wlst.WLS_ON.isConnected():
                result = wlst.WLS.create(name, folder, base_provider_type)
            else:
                result = wlst.create(name, folder, base_provider_type)
    except (wlst.WLSTException, offlineWLSTException), e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00017', name, folder, base_provider_type,
                                                       _get_exception_mode(e), _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
def _ls(method_name, ls_type, path=None, log_throwing=True):
    """
    Private helper method shared by various API methods
    :param method_name: calling method name
    :param ls_type: the WLST return type requested
    :param path: the path (default is the current path)
    :param log_throwing: whether or not to log the throwing message if the path location is not found
    :return: the result of the WLST ls(returnMap='true') call
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = method_name
    _logger.finest('WLSDPLY-00028', method_name, ls_type, path, class_name=_class_name, method_name=_method_name)

    if path is not None:
        # ls(path, returnMap='true') is busted in earlier versions of WLST so go ahead and
        # change directories to the specified path to workaround this
        current_path = get_pwd()
        cd(path)
        try:
            result = wlst.ls(ls_type, returnMap='true', returnType=ls_type)
        except (wlst.WLSTException, offlineWLSTException), e:
            pwe = exception_helper.create_pywlst_exception('WLSDPLY-00029', path, ls_type, _get_exception_mode(e),
                                                           _format_exception(e), error=e)
            if log_throwing:
                _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
            cd(current_path)
            raise pwe
        cd(current_path)
def apply_jrf(jrf_target, domain_home=None, should_update=False):
    """
    For installs that need to connect extension template server groups to servers

    :param jrf_target: entity (cluster, server) to target JRF applications and service
    :param domain_home: the domain home directory
    :param should_update: If true, update the domain - it will check if in online or offline mode
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'apply_jrf'
    _logger.entering(jrf_target,
                     domain_home,
                     should_update,
                     class_name=_class_name,
                     method_name=_method_name)
    _logger.fine('WLSDPLY-00073',
                 jrf_target,
                 domain_home,
                 should_update,
                 class_name=_class_name,
                 method_name=_method_name)
    applyJRF = _load_global('applyJRF')
    try:
        applyJRF(jrf_target, domain_home, should_update)
    except (WLSTException, Exception), e:
        raise exception_helper.create_pywlst_exception('WLSDPLY-00071',
                                                       jrf_target,
                                                       domain_home,
                                                       should_update,
                                                       _format_exception(e),
                                                       error=e)
def get_singleton_name(path=None):
    """
    Return the name at the current location or at the provided path. This location represents
    the name of an MBean that is a singleton. None will be returned if a location is provided and
    it does not exist.
    :param path: location to retrieve the singleton name, or the current location if no path is provided
    :return: name of the MBean
    :throws: PyWLSTException: if there is either no name or more than one name found at the location
                              or if a WLST error occurs
    """
    _method_name = 'get_singleton_name'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    mbean_name = None
    if path is None or path_exists(path):
        print_path = path
        if path is None:
            print_path = get_pwd()
        name_list = lsc(path)
        nbr_names = 0
        if name_list is not None:
            nbr_names = len(name_list)
        if not nbr_names == 1:
            pwe = exception_helper.create_pywlst_exception('WLSDPLY-00031', print_path, nbr_names, name_list)
            _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
            raise pwe
        mbean_name = name_list[0]
        _logger.finest('WLSDPLY-00032', print_path, mbean_name, class_name=_class_name, method_name=_method_name)

    _logger.exiting(class_name=_class_name, method_name=_method_name, result=mbean_name)
    return mbean_name
Exemplo n.º 6
0
def _load_global(global_name):
    member = None
    if wlst_functions is not None and global_name in wlst_functions:
        member = wlst_functions[global_name]

    if member is None:
        raise exception_helper.create_pywlst_exception('WLSDPLY-00087', global_name)
    return member
Exemplo n.º 7
0
def global_update_domain():
    _method_name = 'global_update_domain'
    _logger.entering(class_name=_class_name, method_name=_method_name)
    updateDomain = _load_global('updateDomain')
    try:
        updateDomain()
    except (WLSTException, Exception), e:
        raise exception_helper.create_pywlst_exception('WLSDPLY-00086', 'updateDomain()', _format_exception(e), error=e)
Exemplo n.º 8
0
def global_disconnect():
    _method_name = 'global_disconnect'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    disconnect = _load_global('disconnect')
    try:
        disconnect()
    except (WLSTException, Exception), e:
        raise exception_helper.create_pywlst_exception('WLSDPLY-00086', 'disconnect()', _format_exception(e), error=e)
Exemplo n.º 9
0
def global_activate():
    _method_name = 'global_activate'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    activate = _load_global('activate')
    try:
        activate()
    except (WLSTException, Exception), e:
        raise exception_helper.create_pywlst_exception('WLSDPLY-00086', 'activate()', _format_exception(e), error=e)
Exemplo n.º 10
0
def global_read_domain(domain_home):
    _method_name = 'global_read_domain'
    _logger.entering(class_name=_class_name, method_name=_method_name)
    readDomain = _load_global('readDomain')
    try:
        readDomain(domain_home)
    except (WLSTException, Exception), e:
        read_string = 'readDomain(' + domain_home + ')'
        raise exception_helper.create_pywlst_exception('WLSDPLY-00086', read_string, _format_exception(e), error=e)
Exemplo n.º 11
0
def global_start_edit():
    _method_name = 'global_start_edit'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    startEdit = _load_global('startEdit')
    try:
        startEdit()
    except (WLSTException, Exception), e:
        raise exception_helper.create_pywlst_exception('WLSDPLY-00086', 'startEdit()', _format_exception(e), error=e)
Exemplo n.º 12
0
def _load_global(global_name):
    _method_name = '_load_global'
    member = None
    if wlst_functions is not None and global_name in wlst_functions:
        member = wlst_functions[global_name]
    if member is None:
        raise exception_helper.create_pywlst_exception(
            'WLSDPLY-00072', class_name=_class_name, method_name=_method_name)
    return member
Exemplo n.º 13
0
def global_connect(user, upass, url):
    _method_name = 'global_connect'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    connect = _load_global('connect')
    try:
        connect(user, upass, url)
    except (WLSTException, Exception), e:
        connect_string = 'connect(' + user + ', password hidden, ' + url + ')'
        raise exception_helper.create_pywlst_exception('WLSDPLY-00086', connect_string, _format_exception(e), error=e)
Exemplo n.º 14
0
def server_config():
    """
    Change to the serverConfig MBean tree.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'server_config'
    try:
        wlst.serverConfig()
    except wlst.WLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00065', _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 15
0
def domain_runtime():
    """
    Change to the domainRuntime MBean tree.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'domain_runtime'
    try:
        wlst.domainRuntime()
    except wlst.WLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00066', _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 16
0
def custom():
    """
    Change to the custom MBean tree.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'custom'
    try:
        wlst.custom()
    except wlst.WLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00067', _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 17
0
def get_database_defaults():
    """
    sets the database defaults indicated by RCU.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'get_database_defaults'
    _logger.entering(class_name=_class_name, method_name=_method_name)
    try:
        wlst.getDatabaseDefaults()
    except offlineWLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00022', e.getLocalizedMessage(), error=e)
        _logger.throwing(pwe, class_name=_class_name, method_name=_method_name)
        raise pwe
Exemplo n.º 18
0
def activate():
    """
    Activate changes saved during the current edit session but not yet deployed.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'activate'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.activate()
    except wlst.WLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00053', _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 19
0
def save():
    """
    Save the outstanding Weblogic Server configuration changes for the current edit session.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'save'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.save()
    except wlst.WLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00052', _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 20
0
def undo():
    """
    Revert all unsaved or unactivated edits.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'undo'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.undo('true', 'y')
    except wlst.WLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00069', _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 21
0
def stop_edit():
    """
    Stop the current edit session and discard all unsaved changes.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'stop_edit'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.stopEdit('y')
    except wlst.WLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00051', _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 22
0
def start_edit():
    """
    Start an edit session with the Weblogic Server for the currently connected user.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'start_edit'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.startEdit()
    except wlst.WLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00050', _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 23
0
def disconnect():
    """
    Disconnects WLST from the current connected WebLogic Server instance.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'disconnect'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.disconnect()
    except wlst.WLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00048', _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 24
0
def close_domain():
    """
    Close the domain currently loaded into the offline wlst session.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'close_domain'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.closeDomain()
    except offlineWLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00046', e.getLocalizedMessage(), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 25
0
def update_domain():
    """
    Update the existing domain configuration with the edits made during the offline session.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'update_domain'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.updateDomain()
    except offlineWLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00045', e.getLocalizedMessage(), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 26
0
def load_templates():
    """
    Load all the selected templates.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'load_templates'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.loadTemplates()
    except offlineWLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00041', e.getLocalizedMessage(), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
Exemplo n.º 27
0
def close_template():
    """
    Close the template that is currently loaded for domain creation.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'close_template'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.closeTemplate()
    except offlineWLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00039', e.getLocalizedMessage(), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe
def get_cmo():
    """
    update the Current Management Object (cmo) to current mbean in wlst.
    :return: updated cmo
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'get_cmo'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    if is_connected():
        if wlst.cmo is None:
            pwe = exception_helper.create_pywlst_exception('WLSDPLY-00070')
            _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
            raise pwe
    else:
        try:
            wlst.updateCmo()
        except (wlst.WLSTException, offlineWLSTException), e:
            pwe = exception_helper.create_pywlst_exception('WLSDPLY-00036', get_pwd(), _get_exception_mode(e),
                                                           _format_exception(e), error=e)
            _logger.throwing(class_name=_class_name, method_name='get_cmo', error=pwe)
            raise pwe
        _logger.exiting(class_name=_class_name, method_name=_method_name, result=wlst.cmo)
Exemplo n.º 29
0
    def calculate_changed_model(self):
        """
        Calculate the changed model.
        """
        _method_name = 'calculate_changed_model'

        # This is the top level of changes only
        #  e.g. from no appDeployments to have appDeployments
        #       from no resources to have resources
        #
        #  changed, added, removed are keys in the dictionary
        #   i.e. resources, domainInfo, appDeployments, topology
        #
        try:
            changed = self.changed()
            added = self.added()
            removed = self.removed()

            #
            #  Call recursive for each key (i.e. appDeployments, topology, resources etc..)
            #
            for s in changed:
                self.recursive_changed_detail(s, s, s)
                self._add_results(all_changes)
                self._add_results(all_added)
                self._add_results(all_removed, True)

            for s in added:
                self.recursive_changed_detail(s, s, s)
                self._add_results(all_changes)
                self._add_results(all_added)

            # Clean up previous delete first
            for x in all_removed:
                all_removed.remove(x)

            # Top level:  e.g. delete all resources, all appDeployments

            for s in removed:
                self.recursive_changed_detail(s, token, s)
                self._add_results(all_removed, True)

        except (KeyError, IndexError), ke:
            __logger.severe('WLSDPLY-05709', str(ke)),
            ex = exception_helper.create_pywlst_exception(
                'WLSDPLY-05709', str(ke))
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
Exemplo n.º 30
0
def edit():
    """
    Edit the current Weblogic Server configuration.
    :raises: PyWLSTException: if a WLST error occurs
    """
    _method_name = 'edit'
    _logger.entering(class_name=_class_name, method_name=_method_name)

    try:
        wlst.edit()
    except wlst.WLSTException, e:
        pwe = exception_helper.create_pywlst_exception('WLSDPLY-00049', _format_exception(e), error=e)
        _logger.throwing(class_name=_class_name, method_name=_method_name, error=pwe)
        raise pwe