Skip to content

Commit

Permalink
Merge pull request #46 from lkubb/fix/utils-clouds-nameerror
Browse files Browse the repository at this point in the history
Fixes #45
  • Loading branch information
lkubb authored Nov 7, 2024
2 parents 1ee7530 + f8ddf66 commit fa5d12b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
1 change: 1 addition & 0 deletions changelog/45.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed profile error: name '__opts__' is not defined
20 changes: 9 additions & 11 deletions src/saltext/proxmox/clouds/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"],
Expand All @@ -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"],
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions src/saltext/proxmox/loader.py

This file was deleted.

5 changes: 5 additions & 0 deletions tests/unit/clouds/test_proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__": "",
}
}
Expand Down

0 comments on commit fa5d12b

Please sign in to comment.