Skip to content

Commit bac847f

Browse files
authored
PNP workflow - Re claim device with new site implemented (#190)
2 parents 4c32685 + 06ce5f0 commit bac847f

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

plugins/modules/pnp_workflow_manager.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ class instance for further use.
16381638
# Check the device already added and claimed for idempotent or import devices
16391639
if self.want.get("pnp_params"):
16401640
devices_exists, devices_not_exist, reset_devices = [], [], []
1641-
device_updated_list = []
1641+
device_updated_list, devices_reclaimed = [], []
16421642
site = self.want.get("site_name")
16431643
template_name = self.want.get("template_name")
16441644
image_name = self.want.get("image_params", {}).get("image_name")
@@ -1760,6 +1760,39 @@ class instance for further use.
17601760
"DEBUG",
17611761
)
17621762

1763+
if claim_stat in ("Claimed", "Planned") and site:
1764+
device_site = device_info.get("siteName")
1765+
if site != device_site:
1766+
self.log(
1767+
"Device '{0}' site mismatch: expected '{1}', got '{2}'. Updating site.".format(
1768+
serial_number, site, device_site
1769+
),
1770+
"DEBUG",
1771+
)
1772+
self.log(
1773+
"Device '{0}' is eligible for reclaiming (State: '{1}').".format(
1774+
serial_number, claim_stat
1775+
),
1776+
"DEBUG",
1777+
)
1778+
claim_params = self.get_claim_params()
1779+
claim_response = self.claim_device_site(claim_params)
1780+
self.log(
1781+
"Response from API 'claim a device to a site' for a single claiming: {0}".format(
1782+
str(claim_response)
1783+
),
1784+
"DEBUG",
1785+
)
1786+
1787+
if claim_response.get("response") == "Device Claimed":
1788+
self.log(
1789+
"Device '{0}' reclaimed successfully to site '{1}'.".format(
1790+
serial_number, site
1791+
),
1792+
"INFO",
1793+
)
1794+
devices_reclaimed.append(serial_number)
1795+
17631796
if claim_stat in ("Provisioned", "Claimed", "Planned") or (
17641797
claim_stat in ("Unclaimed", "Error") and not site
17651798
):
@@ -1804,6 +1837,10 @@ class instance for further use.
18041837
changed = True
18051838
self.msg += " and Device information updated successfully."
18061839

1840+
if devices_reclaimed:
1841+
changed = True
1842+
self.msg += " and Devices reclaimed successfully to the new site."
1843+
18071844
self.set_operation_result(
18081845
"success", changed, self.msg, "INFO", devices_exists
18091846
).check_return_status()

0 commit comments

Comments
 (0)