Exemple #1
0
def __virtual__():
    '''
    Set up the libcloud functions and check for JOYENT configs
    '''
    if get_configured_provider() is False:
        return False

    global script
    conn = None
    script = namespaced_function(script, globals(), (conn,))
    return True
Exemple #2
0
def __virtual__():
    """
    Set up the libcloud functions and check for JOYENT configs
    """
    if get_configured_provider() is False:
        log.debug("There is no Joyent cloud provider configuration available. Not " "loading module.")
        return False

    log.debug("Loading Joyent cloud module")

    global script
    conn = None
    script = namespaced_function(script, globals(), (conn,))
    return True
Exemple #3
0
def __virtual__():
    '''
    Only works on Windows systems
    '''
    if salt.utils.is_windows():
        if HAS_WINDOWS_MODULES:
            global check_perms, get_managed, makedirs_perms, manage_file
            global source_list, mkdir, __clean_tmp, makedirs, _is_bin

            check_perms = namespaced_function(check_perms, globals())
            get_managed = namespaced_function(get_managed, globals())
            makedirs_perms = namespaced_function(makedirs_perms, globals())
            makedirs = namespaced_function(makedirs, globals())
            manage_file = namespaced_function(manage_file, globals())
            source_list = namespaced_function(source_list, globals())
            mkdir = namespaced_function(mkdir, globals())
            __clean_tmp = namespaced_function(__clean_tmp, globals())
            _is_bin = namespaced_function(_is_bin, globals())
            
            return 'file'
        log.warn(salt.utils.required_modules_error(__file__, __doc__))
    return False
Exemple #4
0
 def parse_rpm(path):
     try:
         from salt.modules.yumpkg5 import __QUERYFORMAT, _parse_pkginfo
         from salt.utils import namespaced_function
         _parse_pkginfo = namespaced_function(_parse_pkginfo, globals())
     except ImportError:
         log.critical('Error importing helper functions. This is almost '
                      'certainly a bug.')
         return '', ''
     pkginfo = __salt__['cmd.run_all'](
         'rpm -qp --queryformat {0!r} {1!r}'.format(__QUERYFORMAT, path)
     ).get('stdout', '').strip()
     pkginfo = _parse_pkginfo(pkginfo)
     if pkginfo is None:
         return '', ''
     else:
         return pkginfo.name, pkginfo.version
Exemple #5
0
def __virtual__():
    '''
    Confine this module to yum based systems
    '''
    # Work only on RHEL/Fedora based distros with python 2.5 and below
    try:
        os_grain = __grains__['os']
        os_family = __grains__['os_family']
        os_major_version = int(__grains__['osrelease'].split('.')[0])
    except Exception:
        return False

    valid = False
    # Fedora <= 10 need to use this module
    if os_grain == 'Fedora' and os_major_version < 11:
        valid = True
    # XCP == 1.x uses a CentOS 5 base
    elif os_grain == 'XCP':
        if os_major_version == 1:
            valid = True
    # XenServer 6 and earlier uses a CentOS 5 base
    elif os_grain == 'XenServer':
        if os_major_version <= 6:
            valid = True
    else:
        # RHEL <= 5 and all variants need to use this module
        if os_family == 'RedHat' and os_major_version <= 5:
            valid = True
    if valid:
        global mod_repo, _parse_repo_file, list_repos, get_repo
        global expand_repo_def, del_repo
        mod_repo = namespaced_function(mod_repo, globals())
        _parse_repo_file = namespaced_function(_parse_repo_file, globals())
        list_repos = namespaced_function(list_repos, globals())
        get_repo = namespaced_function(get_repo, globals())
        expand_repo_def = namespaced_function(expand_repo_def, globals())
        del_repo = namespaced_function(del_repo, globals())
        return 'pkg'
    return False
Exemple #6
0
import logging

# Import salt libs
import salt.utils
from salt.utils import namespaced_function
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

# 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__)

__func_alias__ = {'list_': 'list'}
                    vm_['name']
                )
            )

    log.info('Created Cloud VM {0[name]!r}'.format(vm_))
    log.debug(
        '{0[name]!r} VM creation details:\n{1}'.format(
            vm_, pprint.pformat(node.__dict__)
        )
    )

    ret.update(node.__dict__)

    salt.utils.cloud.fire_event(
        'event',
        'created instance',
        'salt/cloud/{0}/created'.format(vm_['name']),
        {
            'name': vm_['name'],
            'profile': vm_['profile'],
            'provider': vm_['provider'],
        },
    )

    return ret


list_nodes = namespaced_function(list_nodes, globals())
script = namespaced_function(script, globals())

Exemple #8
0
# Import libcloud
from libcloud.compute.base import NodeAuthPassword

# Import salt cloud libs
import salt.config as config
from salt.cloud.libcloudfuncs import *   # pylint: disable=W0614,W0401
from salt.utils import namespaced_function


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


# Redirect linode functions to 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())
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())


# Only load in this module if the LINODE configurations are in place
def __virtual__():
    '''
Exemple #9
0
    SaltCloudExecutionTimeout
)

# Import netaddr IP matching
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')

# namespace libcloudfuncs
get_salt_interface = namespaced_function(get_salt_interface, globals())


# 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 is the OPENSTACK configurations are in place
def __virtual__():
    '''
    Check for Nova configurations
    '''
    request_log.setLevel(getattr(logging, __opts__.get('requests_log_level', 'warning').upper()))
Exemple #10
0
def __virtual__():
    '''
    Set up the libcloud funcstions and check for AWS configs
    '''
    if not HAS_LIBCLOUD:
        return False

    try:
        # Import botocore
        import botocore.session
    except ImportError:
        # Botocore is not available, the Libcloud AWS module will be loaded
        # instead.
        return False

    # "Patch" the imported libcloud_aws to have the current __opts__
    libcloud_aws.__opts__ = __opts__
    libcloudfuncs.__opts__ = __opts__

    if get_configured_provider() is False:
        return False

    for provider, details in six.iteritems(__opts__['providers']):
        if 'provider' not in details or details['provider'] != 'aws':
            continue

        if not os.path.exists(details['private_key']):
            raise SaltCloudException(
                'The AWS key file {0!r} used in the {1!r} provider '
                'configuration does not exist\n'.format(
                    details['private_key'],
                    provider
                )
            )

        keymode = str(
            oct(stat.S_IMODE(os.stat(details['private_key']).st_mode))
        )
        if keymode not in ('0400', '0600'):
            raise SaltCloudException(
                'The AWS key file {0!r} used in the {1!r} provider '
                'configuration needs to be set to mode 0400 or 0600\n'.format(
                    details['private_key'],
                    provider
                )
            )

    # Let's bring the functions imported from libcloud_aws to the current
    # namespace.
    keysdiff = set(POST_IMPORT_LOCALS_KEYS).difference(
        PRE_IMPORT_LOCALS_KEYS
    )
    for key in keysdiff:
        # only import callables that actually have __code__ (this includes
        # functions but excludes Exception classes)
        if (callable(POST_IMPORT_LOCALS_KEYS[key]) and
                hasattr(POST_IMPORT_LOCALS_KEYS[key], "__code__")):
            globals().update(
                {
                    key: namespaced_function(
                        POST_IMPORT_LOCALS_KEYS[key], globals(), ()
                    )
                }
            )

    global avail_images, avail_sizes, avail_locations, script
    global list_nodes, list_nodes_full, list_nodes_select

    # open a connection in a specific region
    conn = get_conn(**{'location': get_location()})

    # Init the libcloud functions
    avail_locations = namespaced_function(avail_locations, globals(), (conn,))
    avail_images = namespaced_function(avail_images, globals(), (conn,))
    avail_sizes = namespaced_function(avail_sizes, globals(), (conn,))
    script = namespaced_function(script, globals(), (conn,))
    list_nodes = namespaced_function(list_nodes, globals(), (conn,))
    list_nodes_full = namespaced_function(list_nodes_full, globals(), (conn,))
    list_nodes_select = namespaced_function(
        list_nodes_select, globals(), (conn,)
    )

    return 'aws'
Exemple #11
0
# Import saltcloud libs
import salt.utils.cloud
import salt.config as config
from salt.cloud.libcloudfuncs import *  # pylint: disable=W0401,W0614
from salt.cloud.exceptions import (
    SaltCloudException,
    SaltCloudSystemExit,
)


# pylint: disable=C0103,E0602,E0102
# Get logging started
log = logging.getLogger(__name__)

# Redirect GCE functions to this module namespace
avail_locations = namespaced_function(avail_locations, globals())
script = namespaced_function(script, globals())
destroy = namespaced_function(destroy, 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())


# Only load in this module if the GCE configurations are in place
def __virtual__():
    '''
    Set up the libcloud functions and check for GCE configurations.
    '''
    if get_configured_provider() is False:
        log.debug(
            'There is no GCE cloud provider configuration available. Not '
Exemple #12
0
import salt.utils

# Import salt.cloud libs
import salt.utils.cloud
import salt.config as config
from salt.utils import namespaced_function
from salt.exceptions import (SaltCloudSystemExit, SaltCloudExecutionFailure,
                             SaltCloudExecutionTimeout)

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

# 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())
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_salt_interface = namespaced_function(get_salt_interface, globals())


# Only load in this module is the RACKSPACE configurations are in place
def __virtual__():
Exemple #13
0
# Import python libs
import logging
import os
import re

# Import salt libs
import salt.utils

if salt.utils.is_windows():
    from salt.utils import namespaced_function
    from salt.modules.win_pkg import _get_package_info
    from salt.modules.win_pkg import get_repo_data
    from salt.modules.win_pkg import _get_latest_pkg_version
    from salt.modules.win_pkg import _reverse_cmp_pkg_versions
    _get_package_info = namespaced_function(_get_package_info, globals())
    get_repo_data = namespaced_function(get_repo_data, globals())
    _get_latest_pkg_version = namespaced_function(_get_latest_pkg_version, globals())
    _reverse_cmp_pkg_versions = namespaced_function(_reverse_cmp_pkg_versions, globals())
    # The following imports are used by the namespaced win_pkg funcs
    # and need to be included in their globals.
    import msgpack
    from distutils.version import LooseVersion

log = logging.getLogger(__name__)


def __gen_rtag():
    '''
    Return the location of the refresh tag
    '''
Exemple #14
0
def __virtual__():
    """
    Set up the libcloud funcstions and check for AWS configs
    """
    try:
        # Import botocore
        import botocore.session
    except ImportError:
        # Botocore is not available, the Libcloud AWS module will be loaded
        # instead.
        log.debug("The 'botocore' library is not installed. The libcloud AWS " "support will be loaded instead.")
        return False

    # "Patch" the imported libcloud_aws to have the current __opts__
    libcloud_aws.__opts__ = __opts__
    libcloudfuncs.__opts__ = __opts__

    if get_configured_provider() is False:
        log.debug("There is no AWS cloud provider configuration available. Not " "loading module")
        return False

    for provider, details in __opts__["providers"].iteritems():
        if "provider" not in details or details["provider"] != "aws":
            continue

        if not os.path.exists(details["private_key"]):
            raise SaltCloudException(
                "The AWS key file {0!r} used in the {1!r} provider "
                "configuration does not exist\n".format(details["private_key"], provider)
            )

        keymode = str(oct(stat.S_IMODE(os.stat(details["private_key"]).st_mode)))
        if keymode not in ("0400", "0600"):
            raise SaltCloudException(
                "The AWS key file {0!r} used in the {1!r} provider "
                "configuration needs to be set to mode 0400 or 0600\n".format(details["private_key"], provider)
            )

    # Let's bring the functions imported from libcloud_aws to the current
    # namespace.
    keysdiff = set(POST_IMPORT_LOCALS_KEYS.keys()).difference(PRE_IMPORT_LOCALS_KEYS)
    for key in keysdiff:
        # only import callables that actually have __code__ (this includes
        # functions but excludes Exception classes)
        if callable(POST_IMPORT_LOCALS_KEYS[key]) and hasattr(POST_IMPORT_LOCALS_KEYS[key], "__code__"):
            globals().update({key: namespaced_function(POST_IMPORT_LOCALS_KEYS[key], globals(), ())})

    global avail_images, avail_sizes, avail_locations, script
    global list_nodes, list_nodes_full, list_nodes_select

    # open a connection in a specific region
    conn = get_conn(**{"location": get_location()})

    # Init the libcloud functions
    avail_locations = namespaced_function(avail_locations, globals(), (conn,))
    avail_images = namespaced_function(avail_images, globals(), (conn,))
    avail_sizes = namespaced_function(avail_sizes, globals(), (conn,))
    script = namespaced_function(script, globals(), (conn,))
    list_nodes = namespaced_function(list_nodes, globals(), (conn,))
    list_nodes_full = namespaced_function(list_nodes_full, globals(), (conn,))
    list_nodes_select = namespaced_function(list_nodes_select, globals(), (conn,))

    log.debug("Loading AWS botocore cloud module")
    return "aws"
Exemple #15
0
# Import salt.cloud libs
import salt.utils.cloud
import salt.config as config
from salt.utils import namespaced_function
from salt.utils.cloud import is_public_ip
from salt.exceptions import (
    SaltCloudSystemExit,
    SaltCloudExecutionFailure,
    SaltCloudExecutionTimeout
)

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

# namespace libcloudfuncs
get_salt_interface = namespaced_function(get_salt_interface, globals())

JOYENT_API_HOST_SUFFIX = '.api.joyentcloud.com'
JOYENT_API_VERSION = '~6.5'

JOYENT_LOCATIONS = {
    'us-east-1': 'North Virginia, USA',
    'us-west-1': 'Bay Area, California, USA',
    'us-sw-1': 'Las Vegas, Nevada, USA',
    'eu-ams-1': 'Amsterdam, Netherlands'
}
DEFAULT_LOCATION = 'us-east-1'

# joyent no longer reports on all data centers, so setting this value to true
# causes the list_nodes function to get information on machines from all
# data centers
Exemple #16
0
    '-2': 'Boot Failed (not in use)',
    '-1': 'Being Created',
    '0': 'Brand New',
    '1': 'Running',
    '2': 'Powered Off',
    '3': 'Shutting Down (not in use)',
    '4': 'Saved to Disk (not in use)',
}

# Redirect linode functions to 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_distributions, globals())
# avail_sizes = namespaced_function(avail_sizes, globals())
script = namespaced_function(script, globals())
# destroy = namespaced_function(destroy, 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())


# Borrowed from Apache Libcloud
class NodeAuthSSHKey(object):
    """
    An SSH key to be installed for authentication to a node.
    This is the actual contents of the users ssh public key which will
    normally be installed as root's public key on the node.
Exemple #17
0
# Import saltcloud libs
import salt.utils.cloud
import salt.config as config
from salt.cloud.libcloudfuncs import *  # pylint: disable=W0401,W0614
from salt.cloud.exceptions import (
    SaltCloudException,
    SaltCloudSystemExit,
)


# pylint: disable=C0103,E0602,E0102
# Get logging started
log = logging.getLogger(__name__)

# Redirect GCE functions to this module namespace
avail_locations = namespaced_function(avail_locations, globals())
script = namespaced_function(script, globals())
destroy = namespaced_function(destroy, 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())


# Only load in this module if the GCE configurations are in place
def __virtual__():
    '''
    Set up the libcloud functions and check for GCE configurations.
    '''
    if get_configured_provider() is False:
        log.debug(
            'There is no GCE cloud provider configuration available. Not '
Exemple #18
0
def __virtual__():
    '''
    Set up the libcloud funcstions and check for AWS configs
    '''
    try:
        # Import botocore
        import botocore.session
    except ImportError:
        # Botocore is not available, the Libcloud AWS module will be loaded
        # instead.
        return False

    # "Patch" the imported libcloud_aws to have the current __opts__
    libcloud_aws.__opts__ = __opts__
    libcloudfuncs.__opts__ = __opts__

    if get_configured_provider() is False:
        return False

    if get_dependencies() is False:
        return False

    for provider, details in six.iteritems(__opts__['providers']):
        if 'aws' not in details:
            continue

        parameters = details['aws']
        if salt.utils.cloud.check_key_path_and_mode(
                provider, parameters['private_key']
        ) is False:
            return False

    # Let's bring the functions imported from libcloud_aws to the current
    # namespace.
    keysdiff = set(POST_IMPORT_LOCALS_KEYS).difference(
        PRE_IMPORT_LOCALS_KEYS
    )
    for key in keysdiff:
        # only import callables that actually have __code__ (this includes
        # functions but excludes Exception classes)
        if (callable(POST_IMPORT_LOCALS_KEYS[key]) and
                hasattr(POST_IMPORT_LOCALS_KEYS[key], "__code__")):
            globals().update(
                {
                    key: namespaced_function(
                        POST_IMPORT_LOCALS_KEYS[key], globals(), ()
                    )
                }
            )

    global avail_images, avail_sizes, avail_locations, script
    global list_nodes, list_nodes_full, list_nodes_select

    # open a connection in a specific region
    conn = get_conn(**{'location': get_location()})

    # Init the libcloud functions
    avail_locations = namespaced_function(avail_locations, globals(), (conn,))
    avail_images = namespaced_function(avail_images, globals(), (conn,))
    avail_sizes = namespaced_function(avail_sizes, globals(), (conn,))
    script = namespaced_function(script, globals(), (conn,))
    list_nodes = namespaced_function(list_nodes, globals(), (conn,))
    list_nodes_full = namespaced_function(list_nodes_full, globals(), (conn,))
    list_nodes_select = namespaced_function(
        list_nodes_select, globals(), (conn,)
    )

    log.warning('This driver has been deprecated and will be removed in the '
                'Boron release of Salt. Please use the ec2 driver instead.')

    return __virtualname__
Exemple #19
0
from salt.exceptions import SaltCloudSystemExit
from salt.cloud.libcloudfuncs import *  # pylint: disable=W0614,W0401
from salt.utils import namespaced_function

# Attempt to import softlayer lib
try:
    import SoftLayer
    HAS_SLLIBS = True
except ImportError:
    HAS_SLLIBS = False

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

# Redirect SoftLayer functions to this module namespace
script = namespaced_function(script, globals())


# Only load in this module if the SoftLayer configurations are in place
def __virtual__():
    '''
    Set up the libcloud functions and check for SoftLayer configurations.
    '''
    if not HAS_SLLIBS:
        return False

    if get_configured_provider() is False:
        return False

    return True
Exemple #20
0
def __virtual__():
    '''
    Set up the libcloud funcstions and check for AWS configs
    '''
    try:
        import botocore
        # Since we have botocore, we won't load the libcloud AWS module
        log.debug(
            'The \'botocore\' library is installed. The libcloud AWS support '
            'will not be loaded.')
        return False
    except ImportError:
        pass

    if get_configured_provider() is False:
        log.debug(
            'There is no AWS cloud provider configuration available. Not '
            'loading module')
        return False

    for provider, details in __opts__['providers'].iteritems():
        if 'provider' not in details or details['provider'] != 'aws':
            continue

        if not os.path.exists(details['private_key']):
            raise SaltCloudException(
                'The AWS key file {0!r} used in the {1!r} provider '
                'configuration does not exist\n'.format(
                    details['private_key'], provider))

        keymode = str(
            oct(stat.S_IMODE(os.stat(details['private_key']).st_mode)))
        if keymode not in ('0400', '0600'):
            raise SaltCloudException(
                'The AWS key file {0!r} used in the {1!r} provider '
                'configuration needs to be set to mode 0400 or 0600\n'.format(
                    details['private_key'], provider))

    global avail_images, avail_sizes, script, list_nodes
    global avail_locations, list_nodes_full, list_nodes_select, get_image
    global get_size, libcloudfuncs_destroy, show_instance

    # open a connection in a specific region
    conn = get_conn(**{'location': get_location()})

    # Init the libcloud functions
    get_size = namespaced_function(get_size, globals(), (conn, ))
    get_image = namespaced_function(get_image, globals(), (conn, ))
    avail_locations = namespaced_function(avail_locations, globals(), (conn, ))
    avail_images = namespaced_function(avail_images, globals(), (conn, ))
    avail_sizes = namespaced_function(avail_sizes, globals(), (conn, ))
    script = namespaced_function(script, globals(), (conn, ))
    list_nodes = namespaced_function(list_nodes, globals(), (conn, ))
    list_nodes_full = namespaced_function(list_nodes_full, globals(), (conn, ))
    list_nodes_select = namespaced_function(list_nodes_select, globals(),
                                            (conn, ))
    libcloudfuncs_destroy = namespaced_function(libcloudfuncs_destroy,
                                                globals(), (conn, ))
    show_instance = namespaced_function(show_instance, globals())

    log.debug('Loading Libcloud AWS cloud module')
    return __virtualname__
Exemple #21
0
# Import netaddr IP matching
try:
    from netaddr import all_matching_cidrs
    HAS_NETADDR = True
except ImportError:
    HAS_NETADDR = False

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


# 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
avail_locations = namespaced_function(avail_locations, globals())
script = namespaced_function(script, globals())
destroy = namespaced_function(destroy, globals())
reboot = namespaced_function(reboot, globals())


# Only load in this module is the OPENSTACK configurations are in place
def __virtual__():
    '''
    Check for Nova configurations
    '''
    if get_configured_provider() is False:
        log.debug(
            'There is no Nova cloud provider configuration available. '
            'Not loading module.'
        )
Exemple #22
0
# Import netaddr IP matching
try:
    from netaddr import all_matching_cidrs

    HAS_NETADDR = True
except ImportError:
    HAS_NETADDR = False

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


# 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())
script = namespaced_function(script, globals())
destroy = namespaced_function(destroy, globals())
reboot = namespaced_function(reboot, globals())


# Only load in this module is the OPENSTACK configurations are in place
def __virtual__():
    """
    Check for Nova configurations
    """
    if get_configured_provider() is False:
        log.debug("There is no Nova cloud provider configuration available. " "Not loading module.")
        return False
Exemple #23
0
                                   SaltCloudExecutionTimeout)

# Import netaddr IP matching
try:
    from netaddr import all_matching_cidrs
    HAS_NETADDR = True
except ImportError:
    HAS_NETADDR = False

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

# 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())
script = namespaced_function(script, globals())
destroy = namespaced_function(destroy, globals())
reboot = namespaced_function(reboot, globals())


# Only load in this module is the OPENSTACK configurations are in place
def __virtual__():
    '''
    Check for Nova configurations
    '''
    if get_configured_provider() is False:
        return False
Exemple #24
0
import salt.config as config

from salt.ext.six.moves import range

from salt.exceptions import (
    SaltCloudException,
    SaltCloudSystemExit
)

# Import Salt-Cloud Libs
import salt.utils.cloud

from salt.cloud.libcloudfuncs import get_size, get_image, script, show_instance
from salt.utils import namespaced_function

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__():
    '''
Exemple #25
0
def __virtual__():
    '''
    Set up the libcloud funcstions and check for AWS configs
    '''
    try:
        # Import botocore
        import botocore.session
    except ImportError:
        # Botocore is not available, the Libcloud AWS module will be loaded
        # instead.
        log.debug(
            'The \'botocore\' library is not installed. The libcloud AWS '
            'support will be loaded instead.')
        return False

    # "Patch" the imported libcloud_aws to have the current __opts__
    libcloud_aws.__opts__ = __opts__
    libcloudfuncs.__opts__ = __opts__

    if get_configured_provider() is False:
        log.debug(
            'There is no AWS cloud provider configuration available. Not '
            'loading module')
        return False

    for provider, details in __opts__['providers'].iteritems():
        if 'provider' not in details or details['provider'] != 'aws':
            continue

        if not os.path.exists(details['private_key']):
            raise SaltCloudException(
                'The AWS key file {0!r} used in the {1!r} provider '
                'configuration does not exist\n'.format(
                    details['private_key'], provider))

        keymode = str(
            oct(stat.S_IMODE(os.stat(details['private_key']).st_mode)))
        if keymode not in ('0400', '0600'):
            raise SaltCloudException(
                'The AWS key file {0!r} used in the {1!r} provider '
                'configuration needs to be set to mode 0400 or 0600\n'.format(
                    details['private_key'], provider))

    # Let's bring the functions imported from libcloud_aws to the current
    # namespace.
    keysdiff = set(
        POST_IMPORT_LOCALS_KEYS.keys()).difference(PRE_IMPORT_LOCALS_KEYS)
    for key in keysdiff:
        # only import callables that actually have __code__ (this includes
        # functions but excludes Exception classes)
        if (callable(POST_IMPORT_LOCALS_KEYS[key])
                and hasattr(POST_IMPORT_LOCALS_KEYS[key], "__code__")):
            globals().update({
                key:
                namespaced_function(POST_IMPORT_LOCALS_KEYS[key], globals(),
                                    ())
            })

    global avail_images, avail_sizes, avail_locations, script
    global list_nodes, list_nodes_full, list_nodes_select

    # open a connection in a specific region
    conn = get_conn(**{'location': get_location()})

    # Init the libcloud functions
    avail_locations = namespaced_function(avail_locations, globals(), (conn, ))
    avail_images = namespaced_function(avail_images, globals(), (conn, ))
    avail_sizes = namespaced_function(avail_sizes, globals(), (conn, ))
    script = namespaced_function(script, globals(), (conn, ))
    list_nodes = namespaced_function(list_nodes, globals(), (conn, ))
    list_nodes_full = namespaced_function(list_nodes_full, globals(), (conn, ))
    list_nodes_select = namespaced_function(list_nodes_select, globals(),
                                            (conn, ))

    log.debug('Loading AWS botocore cloud module')
    return 'aws'
Exemple #26
0
# Import netaddr IP matching
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')


# 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 is the OPENSTACK configurations are in place
def __virtual__():
    '''
    Check for Nova configurations
    '''
    request_log.setLevel(getattr(logging, __opts__.get('requests_log_level', 'warning').upper()))
    return nova.HAS_NOVA


def get_configured_provider():
    '''
    Return the first configured instance.
Exemple #27
0
def __virtual__():
    '''
    Set up the libcloud funcstions and check for AWS configs
    '''
    try:
        import botocore
        # Since we have botocore, we won't load the libcloud AWS module
        return False
    except ImportError:
        pass

    if get_configured_provider() is False:
        return False

    if get_dependencies() is False:
        return False

    for provider, details in six.iteritems(__opts__['providers']):
        if 'provider' not in details or details['provider'] != 'aws':
            continue

        if not os.path.exists(details['private_key']):
            raise SaltCloudException(
                'The AWS key file {0!r} used in the {1!r} provider '
                'configuration does not exist\n'.format(
                    details['private_key'], provider))

        keymode = str(
            oct(stat.S_IMODE(os.stat(details['private_key']).st_mode)))
        if keymode not in ('0400', '0600'):
            raise SaltCloudException(
                'The AWS key file {0!r} used in the {1!r} provider '
                'configuration needs to be set to mode 0400 or 0600\n'.format(
                    details['private_key'], provider))

    global avail_images, avail_sizes, script, list_nodes
    global avail_locations, list_nodes_full, list_nodes_select, get_image
    global get_size, libcloudfuncs_destroy, show_instance

    # open a connection in a specific region
    conn = get_conn(**{'location': get_location()})

    # Init the libcloud functions
    get_size = namespaced_function(get_size, globals(), (conn, ))
    get_image = namespaced_function(get_image, globals(), (conn, ))
    avail_locations = namespaced_function(avail_locations, globals(), (conn, ))
    avail_images = namespaced_function(avail_images, globals(), (conn, ))
    avail_sizes = namespaced_function(avail_sizes, globals(), (conn, ))
    script = namespaced_function(script, globals(), (conn, ))
    list_nodes = namespaced_function(list_nodes, globals(), (conn, ))
    list_nodes_full = namespaced_function(list_nodes_full, globals(), (conn, ))
    list_nodes_select = namespaced_function(list_nodes_select, globals(),
                                            (conn, ))
    libcloudfuncs_destroy = namespaced_function(libcloudfuncs_destroy,
                                                globals(), (conn, ))
    show_instance = namespaced_function(show_instance, globals())

    log.warning('This driver has been deprecated and will be removed in the '
                'Boron release of Salt. Please use the ec2 driver instead.')

    return __virtualname__
Exemple #28
0
# Import netaddr IP matching
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')

# 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()))
    return HAS_NOVA


def get_configured_provider():
Exemple #29
0
import packet

# Import Salt Libs
import salt.config as config

from salt.ext.six.moves import range

from salt.exceptions import (SaltCloudException, SaltCloudSystemExit)

# Import Salt-Cloud Libs
import salt.utils.cloud

from salt.cloud.libcloudfuncs import get_size, get_image, script, show_instance
from salt.utils import namespaced_function

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__():
    '''
Exemple #30
0
from salt.utils.cloud import is_public_ip
from salt.exceptions import (
    SaltCloudSystemExit,
    SaltCloudExecutionFailure,
    SaltCloudExecutionTimeout
)

# Import 3rd-party libs
import salt.ext.six as six
from salt.ext.six.moves import http_client  # pylint: disable=import-error,no-name-in-module

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

# namespace libcloudfuncs
get_salt_interface = namespaced_function(get_salt_interface, globals())

JOYENT_API_HOST_SUFFIX = '.api.joyentcloud.com'
JOYENT_API_VERSION = '~7.2'

JOYENT_LOCATIONS = {
    'us-east-1': 'North Virginia, USA',
    'us-west-1': 'Bay Area, California, USA',
    'us-sw-1': 'Las Vegas, Nevada, USA',
    'eu-ams-1': 'Amsterdam, Netherlands'
}
DEFAULT_LOCATION = 'us-east-1'

# joyent no longer reports on all data centers, so setting this value to true
# causes the list_nodes function to get information on machines from all
# data centers
Exemple #31
0
                             SaltCloudSystemExit, SaltCloudExecutionFailure,
                             SaltCloudExecutionTimeout)

# Import netaddr IP matching
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')

# namespace libcloudfuncs
get_salt_interface = namespaced_function(get_salt_interface, globals())

# 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 is the OPENSTACK configurations are in place
def __virtual__():
    '''
    Check for Nova configurations
    '''
    request_log.setLevel(
        getattr(logging,
Exemple #32
0
from salt.cloud.libcloudfuncs import *   # pylint: disable=W0614,W0401
from salt.utils import namespaced_function

# Attempt to import softlayer lib
try:
    import SoftLayer
    HAS_SLLIBS = True
except ImportError:
    HAS_SLLIBS = False

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


# Redirect SoftLayer functions to this module namespace
script = namespaced_function(script, globals())


# Only load in this module if the SoftLayer configurations are in place
def __virtual__():
    '''
    Set up the libcloud functions and check for SoftLayer configurations.
    '''
    if not HAS_SLLIBS:
        log.debug(
            'The SoftLayer Python Library needs to be installed in ordere to '
            'use the SoftLayer HW salt.cloud module. See: '
            'https://pypi.python.org/pypi/SoftLayer'
        )
        return False
Exemple #33
0
import logging

# Import salt libs
from salt.utils import namespaced_function
from salt.exceptions import CommandNotFoundError
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

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

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())


def _get_pip_bin(bin_env):
    '''
    Locate the pip binary, either from `bin_env` as a virtualenv, as the
Exemple #34
0
def __virtual__():
    '''
    Set up the libcloud funcstions and check for AWS configs
    '''
    try:
        import botocore
        # Since we have botocore, we won't load the libcloud AWS module
        return False
    except ImportError:
        pass

    if get_configured_provider() is False:
        return False

    for provider, details in __opts__['providers'].iteritems():
        if 'provider' not in details or details['provider'] != 'aws':
            continue

        if not os.path.exists(details['private_key']):
            raise SaltCloudException(
                'The AWS key file {0!r} used in the {1!r} provider '
                'configuration does not exist\n'.format(
                    details['private_key'],
                    provider
                )
            )

        keymode = str(
            oct(stat.S_IMODE(os.stat(details['private_key']).st_mode))
        )
        if keymode not in ('0400', '0600'):
            raise SaltCloudException(
                'The AWS key file {0!r} used in the {1!r} provider '
                'configuration needs to be set to mode 0400 or 0600\n'.format(
                    details['private_key'],
                    provider
                )
            )

    global avail_images, avail_sizes, script, list_nodes
    global avail_locations, list_nodes_full, list_nodes_select, get_image
    global get_size, libcloudfuncs_destroy, show_instance

    # open a connection in a specific region
    conn = get_conn(**{'location': get_location()})

    # Init the libcloud functions
    get_size = namespaced_function(get_size, globals(), (conn,))
    get_image = namespaced_function(get_image, globals(), (conn,))
    avail_locations = namespaced_function(avail_locations, globals(), (conn,))
    avail_images = namespaced_function(avail_images, globals(), (conn,))
    avail_sizes = namespaced_function(avail_sizes, globals(), (conn,))
    script = namespaced_function(script, globals(), (conn,))
    list_nodes = namespaced_function(list_nodes, globals(), (conn,))
    list_nodes_full = namespaced_function(list_nodes_full, globals(), (conn,))
    list_nodes_select = namespaced_function(
        list_nodes_select, globals(), (conn,)
    )
    libcloudfuncs_destroy = namespaced_function(
        libcloudfuncs_destroy, globals(), (conn,)
    )
    show_instance = namespaced_function(show_instance, globals())

    return __virtualname__
def __virtual__():
    '''
    Set up the libcloud funcstions and check for AWS configs
    '''
    try:
        # Import botocore
        import botocore.session
    except ImportError:
        # Botocore is not available, the Libcloud AWS module will be loaded
        # instead.
        return False

    # "Patch" the imported libcloud_aws to have the current __opts__
    libcloud_aws.__opts__ = __opts__
    libcloudfuncs.__opts__ = __opts__

    if get_configured_provider() is False:
        return False

    if get_dependencies() is False:
        return False

    for provider, details in six.iteritems(__opts__['providers']):
        if 'aws' not in details:
            continue

        parameters = details['aws']
        if salt.utils.cloud.check_key_path_and_mode(
                provider, parameters['private_key']) is False:
            return False

    # Let's bring the functions imported from libcloud_aws to the current
    # namespace.
    keysdiff = set(POST_IMPORT_LOCALS_KEYS).difference(PRE_IMPORT_LOCALS_KEYS)
    for key in keysdiff:
        # only import callables that actually have __code__ (this includes
        # functions but excludes Exception classes)
        if (callable(POST_IMPORT_LOCALS_KEYS[key])
                and hasattr(POST_IMPORT_LOCALS_KEYS[key], "__code__")):
            globals().update({
                key:
                namespaced_function(POST_IMPORT_LOCALS_KEYS[key], globals(),
                                    ())
            })

    global avail_images, avail_sizes, avail_locations, script
    global list_nodes, list_nodes_full, list_nodes_select

    # open a connection in a specific region
    conn = get_conn(**{'location': get_location()})

    # Init the libcloud functions
    avail_locations = namespaced_function(avail_locations, globals(), (conn, ))
    avail_images = namespaced_function(avail_images, globals(), (conn, ))
    avail_sizes = namespaced_function(avail_sizes, globals(), (conn, ))
    script = namespaced_function(script, globals(), (conn, ))
    list_nodes = namespaced_function(list_nodes, globals(), (conn, ))
    list_nodes_full = namespaced_function(list_nodes_full, globals(), (conn, ))
    list_nodes_select = namespaced_function(list_nodes_select, globals(),
                                            (conn, ))

    log.warning('This driver has been deprecated and will be removed in the '
                'Boron release of Salt. Please use the ec2 driver instead.')

    return __virtualname__