Skip to content

Commit

Permalink
Merge pull request #24684 from techhat/getsaltinterface
Browse files Browse the repository at this point in the history
Move get_salt_interface() to salt.utils.cloud
  • Loading branch information
Nicole Thomas committed Jun 16, 2015
2 parents 9dff54a + 2974473 commit 211bf36
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 39 deletions.
7 changes: 1 addition & 6 deletions salt/cloud/clouds/ec2.py
Expand Up @@ -114,8 +114,6 @@
# Import salt libs
import salt.utils
from salt import syspaths
from salt.utils import namespaced_function
from salt.cloud.libcloudfuncs import get_salt_interface
from salt._compat import ElementTree as ET
import salt.utils.http as http
import salt.utils.aws as aws
Expand All @@ -134,9 +132,6 @@
# Get logging started
log = logging.getLogger(__name__)

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

SIZE_MAP = {
'Micro Instance': 't1.micro',
'Small Instance': 'm1.small',
Expand Down Expand Up @@ -2250,7 +2245,7 @@ def create(vm_=None, call=None):
log.info('Salt node data. Public_ip: {0}'.format(ip_address))
vm_['ssh_host'] = ip_address

if get_salt_interface(vm_) == 'private_ips':
if salt.utils.cloud.get_salt_interface(vm_, __opts__) == 'private_ips':
salt_ip_address = instance['privateIpAddress']
log.info('Salt interface set to: {0}'.format(salt_ip_address))
else:
Expand Down
5 changes: 1 addition & 4 deletions salt/cloud/clouds/libcloud_aws.py
Expand Up @@ -78,9 +78,6 @@
# Get logging started
log = logging.getLogger(__name__)

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

# Define the module's virtual name
__virtualname__ = 'aws'

Expand Down Expand Up @@ -424,7 +421,7 @@ def __get_node_data(conn, vm_name):
log.info('Salt node data. Public_ip: {0}'.format(data.public_ips[0]))
ip_address = data.public_ips[0]

if get_salt_interface(vm_) == 'private_ips':
if salt.utils.cloud.get_salt_interface(vm_, __opts__) == 'private_ips':
salt_ip_address = data.private_ips[0]
log.info('Salt interface set to: {0}'.format(salt_ip_address))
else:
Expand Down
8 changes: 2 additions & 6 deletions salt/cloud/clouds/nova.py
Expand Up @@ -149,10 +149,6 @@
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
Expand Down Expand Up @@ -723,10 +719,10 @@ def __query_node_data(vm_, data):
ip_address = preferred_ip(vm_, data.public_ips)
log.debug('Using IP address {0}'.format(ip_address))

if get_salt_interface(vm_) == 'private_ips':
if salt.utils.cloud.get_salt_interface(vm_, __opts__) == 'private_ips':
salt_ip_address = preferred_ip(vm_, data.private_ips)
log.info('Salt interface set to: {0}'.format(salt_ip_address))
elif rackconnect(vm_) is True and get_salt_interface(vm_) != 'private_ips':
elif rackconnect(vm_) is True and salt.utils.cloud.get_salt_interface(vm_, __opts__) != 'private_ips':
salt_ip_address = data.public_ips
else:
salt_ip_address = preferred_ip(vm_, data.public_ips)
Expand Down
3 changes: 1 addition & 2 deletions salt/cloud/clouds/openstack.py
Expand Up @@ -190,7 +190,6 @@
list_nodes_select = namespaced_function(list_nodes_select, globals())
show_instance = namespaced_function(show_instance, globals())
get_node = namespaced_function(get_node, globals())
get_salt_interface = namespaced_function(get_salt_interface, globals())


# Only load in this module is the OPENSTACK configurations are in place
Expand Down Expand Up @@ -785,7 +784,7 @@ def __query_node_data(vm_, data, floating):
ip_address = preferred_ip(vm_, data.public_ips)
log.debug('Using IP address {0}'.format(ip_address))

if get_salt_interface(vm_) == 'private_ips':
if salt.utils.cloud.get_salt_interface(vm_, __opts__) == 'private_ips':
salt_ip_address = preferred_ip(vm_, data.private_ips)
log.info('Salt interface set to: {0}'.format(salt_ip_address))
else:
Expand Down
3 changes: 1 addition & 2 deletions salt/cloud/clouds/rackspace.py
Expand Up @@ -80,7 +80,6 @@
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
Expand Down Expand Up @@ -310,7 +309,7 @@ def __query_node_data(vm_, data):
ip_address = preferred_ip(vm_, data.public_ips)
log.debug('Using IP address {0}'.format(ip_address))

if get_salt_interface(vm_) == 'private_ips':
if salt.utils.cloud.get_salt_interface(vm_, __opts__) == 'private_ips':
salt_ip_address = preferred_ip(vm_, data.private_ips)
log.info('Salt interface set to: {0}'.format(salt_ip_address))
else:
Expand Down
19 changes: 0 additions & 19 deletions salt/cloud/libcloudfuncs.py
Expand Up @@ -500,22 +500,3 @@ def conn_has_method(conn, method_name):
)
)
return False


def get_salt_interface(vm_):
'''
Return the salt_interface type to connect to. Either 'public_ips' (default)
or 'private_ips'.
'''
salt_host = config.get_cloud_config_value(
'salt_interface', vm_, __opts__, default=False,
search_global=False
)

if salt_host is False:
salt_host = config.get_cloud_config_value(
'ssh_interface', vm_, __opts__, default='public_ips',
search_global=False
)

return salt_host
19 changes: 19 additions & 0 deletions salt/utils/cloud.py
Expand Up @@ -2905,3 +2905,22 @@ def run_func_until_ret_arg(fun, kwargs, fun_call=None,
time.sleep(5)

return True


def get_salt_interface(vm_, opts):
'''
Return the salt_interface type to connect to. Either 'public_ips' (default)
or 'private_ips'.
'''
salt_host = salt.config.get_cloud_config_value(
'salt_interface', vm_, opts, default=False,
search_global=False
)

if salt_host is False:
salt_host = salt.config.get_cloud_config_value(
'ssh_interface', vm_, opts, default='public_ips',
search_global=False
)

return salt_host

0 comments on commit 211bf36

Please sign in to comment.