Beispiel #1
0
def test_deprecated_preserve_context_kwarg(preserve_context):
    def foo():
        pass

    with warnings.catch_warnings(record=True) as w:
        # Cause all warnings to always be triggered.
        warnings.simplefilter("always")
        namespaced_function(foo, globals(), preserve_context=preserve_context)

    assert str(w[-1].message) == (
        "Passing 'preserve_context' to 'namespaced_function' is deprecated, slated "
        "for removal in 3008 and no longer does anything for the function "
        "being namespaced.")
Beispiel #2
0
def install(*args, **kwargs):
    '''
    Winrepo install that can install packages without a win_repo, the package
    definition can passed to install via a win_repo keyword argument.
    '''
    global _get_package_info
    _orig_get_package_info = salt.modules.win_pkg._get_package_info
    pkg_install = namespaced_function(salt.modules.win_pkg.install, globals())
    try:
        _get_package_info = functools.partial(
            _get_package_info_partial,
            win_repo=kwargs.get('win_repo', {}),
            orig_func=namespaced_function(_orig_get_package_info, globals()),
        )
        return pkg_install(*args, **kwargs)
    finally:
        _get_package_info = _orig_get_package_info
Beispiel #3
0
def install(*args, **kwargs):
    '''
    Winrepo install that can install packages without a win_repo, the package
    definition can passed to install via a win_repo keyword argument.
    '''
    global _get_package_info
    _orig_get_package_info = salt.modules.win_pkg._get_package_info
    pkg_install = namespaced_function(salt.modules.win_pkg.install, globals())
    try:
        _get_package_info = functools.partial(
            _get_package_info_partial,
            win_repo=kwargs.get('win_repo', {}),
            orig_func=namespaced_function(_orig_get_package_info, globals()),
        )
        return pkg_install(*args, **kwargs)
    finally:
        _get_package_info = _orig_get_package_info
Beispiel #4
0
import time

import salt.config as config
import salt.utils.cloud
from salt.cloud.libcloudfuncs import get_image, get_size, script, show_instance
from salt.exceptions import SaltCloudException, SaltCloudSystemExit
from salt.utils.functools import namespaced_function

try:
    import packet

    HAS_PACKET = True
except ImportError:
    HAS_PACKET = False

get_size = namespaced_function(get_size, globals())
get_image = namespaced_function(get_image, globals())

script = namespaced_function(script, globals())

show_instance = namespaced_function(show_instance, globals())

# Get logging started
log = logging.getLogger(__name__)

__virtualname__ = "packet"


# Only load this module if the Packet configuration is in place.
def __virtual__():
    """
Beispiel #5
0
    from salt.utils import namespaced_function
try:
    from salt.utils.platform import is_windows
except (ImportError, AttributeError):
    from salt.utils import is_windows
import salt.modules.win_pkg
from salt.modules.win_pkg import *  # pylint: disable=wildcard-import,unused-wildcard-import
from salt.modules.win_pkg import install as win_pkg_install

# Import 3rd Party libs
import salt.ext.six as six
# pylint: disable=import-error,no-name-in-module
from salt.ext.six.moves.urllib.parse import urlparse as _urlparse, urlsplit, uses_params, ParseResult

# Let's namespace the pip_install function
win_pkg_install = namespaced_function(win_pkg_install, globals())  # pylint: disable=invalid-name

# Let's namespace all other functions from the pip module
for name in dir(salt.modules.win_pkg):
    attr = getattr(salt.modules.win_pkg, name)
    if isinstance(attr, types.FunctionType):
        if attr in ('install', ):
            continue
        globals()[name] = namespaced_function(attr, globals())

__virtualname__ = 'pkg'


def __virtual__():
    '''
    Set the virtual pkg module if the os is Windows
except ImportError:
    HAS_LIBCLOUD = False


try:
    from netaddr import all_matching_cidrs  # pylint: disable=unused-import

    HAS_NETADDR = True
except ImportError:
    HAS_NETADDR = False


# Some of the libcloud functions need to be in the same namespace as the
# functions defined in the module, so we create new function objects inside
# this module namespace
get_size = namespaced_function(get_size, globals())
get_image = namespaced_function(get_image, globals())
avail_locations = namespaced_function(avail_locations, globals())
avail_images = namespaced_function(avail_images, globals())
avail_sizes = namespaced_function(avail_sizes, globals())
script = namespaced_function(script, globals())
destroy = namespaced_function(destroy, globals())
reboot = namespaced_function(reboot, globals())
list_nodes = namespaced_function(list_nodes, globals())
list_nodes_full = namespaced_function(list_nodes_full, globals())
list_nodes_select = namespaced_function(list_nodes_select, globals())
show_instance = namespaced_function(show_instance, globals())
get_node = namespaced_function(get_node, globals())

# Get logging started
log = logging.getLogger(__name__)
Beispiel #7
0
# Import python libs
from __future__ import absolute_import
import os
import types
import pkg_resources

# Import salt libs
from salt.utils.functools import namespaced_function
import salt.utils.args
import salt.states.pip_state
from salt.states.pip_state import *  # pylint: disable=wildcard-import,unused-wildcard-import
from salt.states.pip_state import installed as pip_state_installed

# Let's namespace the pip_state_installed function
pip_state_installed = namespaced_function(pip_state_installed, globals())  # pylint: disable=invalid-name

# Let's namespace all other functions from the pip_state module
for name in dir(salt.states.pip_state):
    attr = getattr(salt.states.pip_state, name)
    if isinstance(attr, types.FunctionType):
        if attr in ('installed', ):
            continue
        if attr in globals():
            continue
        globals()[name] = namespaced_function(attr, globals())

__virtualname__ = 'pip'


def __virtual__():
Beispiel #8
0
try:
    import salt.utils.winapi

    HAS_DEPENDENCIES = True
except ImportError:
    HAS_DEPENDENCIES = False

try:
    import wmi  # pylint: disable=import-error
except ImportError:
    HAS_DEPENDENCIES = False

if salt.utils.platform.is_windows() and HAS_DEPENDENCIES:

    wol = namespaced_function(wol, globals())
    get_hostname = namespaced_function(get_hostname, globals())
    interface = namespaced_function(interface, globals())
    interface_ip = namespaced_function(interface_ip, globals())
    subnets6 = namespaced_function(subnets6, globals())
    ip_in_subnet = namespaced_function(ip_in_subnet, globals())
    convert_cidr = namespaced_function(convert_cidr, globals())
    calc_net = namespaced_function(calc_net, globals())
    get_fqdn = namespaced_function(get_fqdn, globals())
    ifacestartswith = namespaced_function(ifacestartswith, globals())
    iphexval = namespaced_function(iphexval, globals())

# Define the module's virtual name
__virtualname__ = "network"

Beispiel #9
0
try:
    from netaddr import all_matching_cidrs
    HAS_NETADDR = True
except ImportError:
    HAS_NETADDR = False

# Get logging started
log = logging.getLogger(__name__)
request_log = logging.getLogger('requests')

__virtualname__ = 'nova'

# Some of the libcloud functions need to be in the same namespace as the
# functions defined in the module, so we create new function objects inside
# this module namespace
script = namespaced_function(script, globals())
reboot = namespaced_function(reboot, globals())


# Only load in this module if the Nova configurations are in place
def __virtual__():
    '''
    Check for Nova configurations
    '''
    request_log.setLevel(
        getattr(logging,
                __opts__.get('requests_log_level', 'warning').upper()))

    if get_configured_provider() is False:
        return False
Beispiel #10
0
import salt.utils.platform
from salt.utils.functools import namespaced_function
from salt.utils.versions import LooseVersion
from salt.exceptions import CommandNotFoundError
import salt.modules.pip
from salt.modules.pip import *  # pylint: disable=wildcard-import,unused-wildcard-import
from salt.modules.pip import install as pip_install
from salt.modules.pip import freeze as pip_freeze
from salt.modules.pip import list_ as pip_list
from salt.modules.pip import _get_pip_bin as __get_pip_bin

# Import 3rd Party libs
import salt.ext.six as six

# Let's namespace the pip_install function
pip_install = namespaced_function(pip_install, globals())  # pylint: disable=invalid-name
pip_freeze = namespaced_function(pip_freeze, globals())  # pylint: disable=invalid-name
pip_list = namespaced_function(pip_list, globals())  # pylint: disable=invalid-name
__get_pip_bin = namespaced_function(__get_pip_bin, globals())

# Let's namespace all other functions from the pip module
for name in dir(salt.modules.pip):
    attr = getattr(salt.modules.pip, name)
    if isinstance(attr, types.FunctionType):
        if attr in ('install', 'freeze', 'list', 'list_', __get_pip_bin):
            continue
        globals()[name] = namespaced_function(attr, globals())

log = logging.getLogger(__name__)

__func_alias__ = {'list_': 'list'}
Beispiel #11
0
'''

# Import python libs
from __future__ import absolute_import
import types

# Import salt libs
from salt.utils.functools import namespaced_function
import salt.states.pip_state
from salt.states.pip_state import *  # pylint: disable=wildcard-import,unused-wildcard-import
from salt.states.pip_state import installed as pip_state_installed

log = logging.getLogger(__name__)

# Let's namespace the pip_state_installed function
pip_state_installed = namespaced_function(pip_state_installed, globals())  # pylint: disable=invalid-name

# Let's namespace all other functions from the pip_state module
for name in dir(salt.states.pip_state):
    attr = getattr(salt.states.pip_state, name)
    if isinstance(attr, types.FunctionType):
        if attr in ('installed',):
            continue
        if attr in globals():
            continue
        globals()[name] = namespaced_function(attr, globals())

__virtualname__ = 'pip2'


def __virtual__():
Beispiel #12
0
from salt.modules.win_pkg import *
from salt.ext.six.moves.urllib.parse import urlparse as _urlparse

PKG_DATA = {}
NAMESPACE_FUNCS = [
    '_get_repo_details',
    '_get_msiexec',
    '_get_latest_pkg_version',
    'get_repo_data',
]

for name in dir(salt.modules.win_pkg):
    attr = getattr(salt.modules.win_pkg, name)
    if isinstance(attr, types.FunctionType):
        if name in NAMESPACE_FUNCS:
            globals()[name] = namespaced_function(attr, globals())


def __virtual__():
    if salt.utils.platform.is_windows():
        return True
    return (False, 'This module only works on Windows.')


def refresh_db(*args, **kwargs):
    '''
    Override refresh db and peform a no-op
    '''
    return

Beispiel #13
0

PKG_DATA = {}
NAMESPACE_FUNCS = [
	'_get_repo_details',
	'_get_msiexec',
	'_get_latest_pkg_version',
	'get_repo_data',
]


for name in dir(salt.modules.win_pkg):
    attr = getattr(salt.modules.win_pkg, name)
    if isinstance(attr, types.FunctionType):
        if name in NAMESPACE_FUNCS:
            globals()[name] = namespaced_function(attr, globals())


def __virtual__():
    if salt.utils.platform.is_windows():
        return True
    return (False, 'This module only works on Windows.')


def refresh_db(*args, **kwargs):
    '''
    Override refresh db and peform a no-op
    '''
    return

Beispiel #14
0
from salt.utils.versions import LooseVersion
from salt.exceptions import CommandNotFoundError
import salt.modules.pip
from salt.modules.pip import *  # pylint: disable=wildcard-import,unused-wildcard-import
from salt.modules.pip import install as pip_install
from salt.modules.pip import list_ as pip_list
try:
    from salt.utils.versions import LooseVersion
except ImportError:
    from distutils.version import LooseVersion

# Import 3rd Party libs
import salt.ext.six as six

# Let's namespace the pip_install function
pip_install = namespaced_function(pip_install, globals())  # pylint: disable=invalid-name
pip_list = namespaced_function(pip_list, globals())  # pylint: disable=invalid-name

# Let's namespace all other functions from the pip module
for name in dir(salt.modules.pip):
    attr = getattr(salt.modules.pip, name)
    if isinstance(attr, types.FunctionType):
        if attr == 'install':
            continue
        if attr in globals():
            continue
        globals()[name] = namespaced_function(attr, globals())


log = logging.getLogger(__name__)
Beispiel #15
0
        HAS_WMI = True
    else:
        HAS_WMI = False
except ImportError:
    HAS_WMI = False

try:
    import psutil

    HAS_PSUTIL = True
except ImportError:
    HAS_PSUTIL = False

if salt.utils.platform.is_windows():
    ping_master = namespaced_function(ping_master, globals())
    time_ = namespaced_function(time_, globals())

__virtualname__ = "status"


# Taken from https://www.geoffchappell.com/studies/windows/km/ntoskrnl/api/ex/sysinfo/performance.htm
class SYSTEM_PERFORMANCE_INFORMATION(ctypes.Structure):
    _fields_ = [
        ("IdleProcessTime", ctypes.c_int64),
        ("IoReadTransferCount", ctypes.c_int64),
        ("IoWriteTransferCount", ctypes.c_int64),
        ("IoOtherTransferCount", ctypes.c_int64),
        ("IoReadOperationCount", ctypes.c_ulong),
        ("IoWriteOperationCount", ctypes.c_ulong),
        ("IoOtherOperationCount", ctypes.c_ulong),