Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ include_package_data = True
package_dir =
=src
packages = find_namespace:
python_requires = >= 3.10
python_requires = >= 3.9
setup_requires =
wheel
setuptools<69.0,>=65.6.3
Expand Down
13 changes: 10 additions & 3 deletions src/saltext/vmware/grains/esxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@


def __virtual__():

# import salt.utils.proxy again
# so it is available for tests.
import salt.utils.proxy

try:
if salt.utils.proxy.is_proxytype(__opts__, "esxi"):
import salt.modules.vsphere

return __virtualname__
except KeyError:
pass
Expand All @@ -37,6 +38,12 @@ def esxi():
return _grains()


def osfinger():
if not GRAINS_CACHE:
GRAINS_CACHE.update(_grains())
return {"osfinger": f'{GRAINS_CACHE["name"]}-{GRAINS_CACHE["version"]}'}


def kernel():
return {"kernel": "proxy"}

Expand Down Expand Up @@ -72,7 +79,7 @@ def _find_credentials(host):
for password in passwords:
try:
# Try to authenticate with the given user/password combination
ret = __salt__["vmware_info.system_info"](
ret = salt.modules.vsphere.system_info(
host=host, username=user, password=password, verify_ssl=verify_ssl
)
except SaltSystemExit:
Expand All @@ -96,7 +103,7 @@ def _grains():
protocol = __pillar__["proxy"].get("protocol")
port = __pillar__["proxy"].get("port")
verify_ssl = __pillar__["proxy"].get("verify_ssl")
ret = __salt__["vmware_info.system_info"](
ret = salt.modules.vsphere.system_info(
host=host,
username=username,
password=password,
Expand Down
7 changes: 5 additions & 2 deletions src/saltext/vmware/modules/compliance_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

import salt.exceptions
import saltext.vmware.utils.compliance_control as compliance_control_util
from config_modules_vmware.interfaces.controller_interface import ControllerInterface

log = logging.getLogger(__name__)

__virtualname__ = "vmware_compliance_control"


def __virtual__():
return __virtualname__
try:
from config_modules_vmware.interfaces.controller_interface import ControllerInterface
return __virtualname__
except ImportError:
return False


def control_config_compliance_check(control_config, product, auth_context=None):
Expand Down
7 changes: 5 additions & 2 deletions src/saltext/vmware/modules/controller_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
import logging

import salt.exceptions
from config_modules_vmware.interfaces.metadata_interface import ControllerMetadataInterface

log = logging.getLogger(__name__)

__virtualname__ = "vmware_controller_metadata"


def __virtual__():
return __virtualname__
try:
from config_modules_vmware.interfaces.metadata_interface import ControllerMetadataInterface
return __virtualname__
except ImportError:
return False


def validate(controller_metadata):
Expand Down
1 change: 1 addition & 0 deletions src/saltext/vmware/modules/esxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
HAS_PYVMOMI = False


__proxyenabled__ = ["vmware_esxi", "esxi"]
__virtualname__ = "vmware_esxi"

DEFAULT_EXCEPTIONS = (
Expand Down
2 changes: 2 additions & 0 deletions src/saltext/vmware/modules/vsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os

import salt.exceptions
import salt.utils.dictupdate as dictupdate
import saltext.vmware.utils.common as utils_common
import saltext.vmware.utils.connect as utils_connect
import saltext.vmware.utils.esxi as utils_esxi
Expand All @@ -20,6 +21,7 @@
HAS_PYVMOMI = False


__proxyenabled__ = ["vmware_esxi", "esxi"]
__virtualname__ = "vmware_vsphere"

DEFAULT_EXCEPTIONS = (
Expand Down
43 changes: 22 additions & 21 deletions src/saltext/vmware/proxy/esxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,15 @@
"""
import logging
import os
import ssl

from salt.exceptions import InvalidConfigError
from salt.exceptions import SaltSystemExit
from salt.utils.dictupdate import merge
from saltext.vmware.config.schemas.esxi import EsxiProxySchema
import saltext.vmware.modules.vsphere

from pyVim import connect

# This must be present or the Salt loader won't load this module.
__proxyenabled__ = ["esxi"]
Expand Down Expand Up @@ -443,20 +447,14 @@ def ping():

salt esxi-host test.ping
"""
log.debug("==== details %s ====", DETAILS)
if DETAILS.get("esxi_host"):
return True
else:
# TODO Check connection if mechanism is SSPI
if DETAILS["mechanism"] == "userpass":
find_credentials(DETAILS["host"])
try:
__salt__["vmware_info.system_info"](
host=DETAILS["host"],
username=DETAILS["username"],
password=DETAILS["password"],
verify_ssl=DETAILS["verify_ssl"],
)
saltext.vmware.modules.vsphere.system_info(service_instance=DETAILS["service_instance"])
except SaltSystemExit as err:
log.warning(err)
return False
Expand Down Expand Up @@ -508,6 +506,19 @@ def ch_config(cmd, *args, **kwargs):
return __salt__["vsphere." + cmd](*args, **kwargs)


def _get_service_instance(host, user, password, verify_ssl=False):
ssl_ctx = None
if not verify_ssl:
ssl_ctx = ssl._create_unverified_context()
service_instance = connect.SmartConnect(
host=host,
user=user,
pwd=password,
sslContext=ssl_ctx,
)
return service_instance


def find_credentials(host):
"""
Cycle through all the possible credentials and return the first one that
Expand All @@ -520,16 +531,16 @@ def find_credentials(host):
for password in passwords:
try:
# Try to authenticate with the given user/password combination
ret = __salt__["vmware_info.system_info"](
host=host, username=user, password=password, verify_ssl=verify_ssl
)
service_instance = _get_service_instance(host=host, user=user, password=password, verify_ssl=verify_ssl)
ret = saltext.vmware.modules.vsphere.system_info(service_instance=service_instance)
except SaltSystemExit:
# If we can't authenticate, continue on to try the next password.
continue
# If we have data returned from above, we've successfully authenticated.
if ret:
DETAILS["username"] = user
DETAILS["password"] = password
DETAILS["service_instance"] = service_instance
return user, password
# We've reached the end of the list without successfully authenticating.
raise SaltSystemExit("Cannot complete login due to an incorrect user name or password.")
Expand All @@ -539,17 +550,7 @@ def _grains(host, protocol=None, port=None, verify_ssl=None):
"""
Helper function to the grains from the proxied device.
"""
username, password = find_credentials(DETAILS["host"])
verify_ssl = DETAILS["verify_ssl"]

ret = __salt__["vmware_info.system_info"](
host=host,
username=username,
password=password,
protocol=protocol,
port=port,
verify_ssl=verify_ssl,
)
ret = saltext.vmware.modules.vsphere.system_info(service_instance=DETAILS["service_instance"])
GRAINS_CACHE.update(ret)
return GRAINS_CACHE

Expand Down
7 changes: 3 additions & 4 deletions src/saltext/vmware/utils/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_config(config, profile=None, esxi_host=None):
config.get("saltext.vmware")
or config.get("grains", {}).get("saltext.vmware")
or config.get("pillar", {}).get("saltext.vmware")
or config.get("proxy", {})
or {}
)
if not conf:
Expand All @@ -54,8 +55,8 @@ def get_config(config, profile=None, esxi_host=None):
ssl_thumbprint = credentials.get("ssl_thumbprint")
else:
host = os.environ.get("SALTEXT_VMWARE_HOST") or credentials.get("host")
password = os.environ.get("SALTEXT_VMWARE_PASSWORD") or credentials.get("password")
user = os.environ.get("SALTEXT_VMWARE_USER") or credentials.get("user")
password = os.environ.get("SALTEXT_VMWARE_PASSWORD") or credentials.get("password") or credentials.get("passwords")[0]
user = os.environ.get("SALTEXT_VMWARE_USER") or credentials.get("user") or credentials.get("username")
ssl_thumbprint = credentials.get("ssl_thumbprint")

if host is None or password is None or user is None:
Expand Down Expand Up @@ -132,9 +133,7 @@ def get_service_instance(*, config, esxi_host=None, profile=None):
"""
ctx = ssl._create_unverified_context()
config = config or {}

config = get_config(config=config, profile=profile, esxi_host=esxi_host)

service_instance = connect.SmartConnect(
host=config.get("host"),
user=config.get("user"),
Expand Down
3 changes: 3 additions & 0 deletions src/saltext/vmware/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pylint: skip-file

__version__ = "24.10.9.0rc2.dev1+gcb32a1f.d20250327"
Loading