Wrap windows related imports in a try/except to properly handle module loading.

This commit is contained in:
Pedro Algarvio 2013-07-28 17:43:41 +01:00
parent 0d3218ec2b
commit 5715e30c38

View File

@ -7,15 +7,22 @@ NOTE: This currently only works with local user accounts, not domain accounts
# Import salt libs
import salt.utils
from salt._compat import string_types
import win32net
import win32netcon
try:
import win32net
import win32netcon
HAS_WIN32NET_MODS = True
except ImportError:
HAS_WIN32NET_MODS = False
def __virtual__():
'''
Set the user module if the kernel is Windows
'''
return 'user' if salt.utils.is_windows() else False
if HAS_WIN32NET_MODS is True and salt.utils.is_windows():
return 'user'
return False
def add(name,
@ -151,6 +158,7 @@ def chprofile(name, profile):
return post_info['profile'] == profile
return False
def chfullname(name, fullname):
'''
Change the full name of the user
@ -302,6 +310,7 @@ def getent():
__context__['user.getent'] = ret
return ret
def list_users():
'''
Return a list of users on Windows