diff --git a/changelog/45.fixed.md b/changelog/45.fixed.md new file mode 100644 index 0000000..70c8536 --- /dev/null +++ b/changelog/45.fixed.md @@ -0,0 +1 @@ +Fixed profile error: name '__opts__' is not defined diff --git a/src/saltext/proxmox/clouds/proxmox.py b/src/saltext/proxmox/clouds/proxmox.py index 9c8c721..2183429 100644 --- a/src/saltext/proxmox/clouds/proxmox.py +++ b/src/saltext/proxmox/clouds/proxmox.py @@ -16,8 +16,6 @@ import time from ipaddress import ip_interface -import salt.utils.cloud -import salt.utils.json from salt import config from salt.exceptions import SaltCloudExecutionTimeout from salt.exceptions import SaltCloudNotFound @@ -79,11 +77,11 @@ def create(vm_): """ Create a single Proxmox VM. """ - salt.utils.cloud.fire_event( + __utils__["cloud.fire_event"]( # pylint: disable=undefined-variable "event", "starting create", - "salt/cloud/{}/creating".format(vm_["name"]), # pylint: disable=consider-using-f-string - args=salt.utils.cloud.filter_event( + f"salt/cloud/{vm_['name']}/creating", + args=__utils__["cloud.filter_event"]( # pylint: disable=undefined-variable "creating", vm_, ["name", "profile", "provider", "driver"] ), sock_dir=__opts__["sock_dir"], @@ -104,15 +102,15 @@ def create(vm_): # cloud.bootstrap expects the ssh_password to be set in vm_["password"] vm_["password"] = vm_.get("ssh_password") - ret = salt.utils.cloud.bootstrap(vm_, __opts__) + ret = __utils__["cloud.bootstrap"](vm_, __opts__) # pylint: disable=undefined-variable ret.update(show_instance(call="action", name=vm_["name"])) - salt.utils.cloud.fire_event( + __utils__["cloud.fire_event"]( # pylint: disable=undefined-variable "event", "created instance", f"salt/cloud/{vm_['name']}/created", - args=salt.utils.cloud.filter_event( + args=__utils__["cloud.filter_event"]( # pylint: disable=undefined-variable "created", vm_, ["name", "profile", "provider", "driver"] ), sock_dir=__opts__["sock_dir"], @@ -214,7 +212,7 @@ def destroy(name=None, kwargs=None, call=None): "The destroy action must be called with -d, --destroy, -a or --action." ) - salt.utils.cloud.fire_event( + __utils__["cloud.fire_event"]( # pylint: disable=undefined-variable "event", "destroying instance", f"salt/cloud/{name}/destroying", @@ -227,7 +225,7 @@ def destroy(name=None, kwargs=None, call=None): _query("DELETE", f"nodes/{vm['node']}/{vm['type']}/{vm['vmid']}", kwargs) - salt.utils.cloud.fire_event( + __utils__["cloud.fire_event"]( # pylint: disable=undefined-variable "event", "destroyed instance", f"salt/cloud/{name}/destroyed", @@ -372,7 +370,7 @@ def list_nodes_select(call=None): """ Return a list of the VMs that are managed by the provder, with select fields """ - return salt.utils.cloud.list_nodes_select( + return __utils__["cloud.list_nodes_select"]( # pylint: disable=undefined-variable list_nodes_full(), __opts__["query.selection"], call, diff --git a/src/saltext/proxmox/loader.py b/src/saltext/proxmox/loader.py deleted file mode 100644 index 9bb9539..0000000 --- a/src/saltext/proxmox/loader.py +++ /dev/null @@ -1,13 +0,0 @@ -""" -Define the required entry-points functions in order for Salt to know -what and from where it should load this extension's loaders -""" - -from . import PACKAGE_ROOT # pylint: disable=unused-import - - -def get_cloud_dirs(): - """ - Return a list of paths from where salt should load cloud modules - """ - return [str(PACKAGE_ROOT / "clouds")] diff --git a/tests/unit/clouds/test_proxmox.py b/tests/unit/clouds/test_proxmox.py index df2c7b6..f37b4fe 100644 --- a/tests/unit/clouds/test_proxmox.py +++ b/tests/unit/clouds/test_proxmox.py @@ -29,6 +29,11 @@ def configure_loader_modules(): "sock_dir": True, "transport": True, }, + "__utils__": { + "cloud.filter_event": MagicMock(), + "cloud.fire_event": MagicMock(), + "cloud.bootstrap": MagicMock(), + }, "__active_provider_name__": "", } }