Skip to content

Commit

Permalink
fix: vlan clearing on cloud objects when terminating schedule
Browse files Browse the repository at this point in the history
fixes: #410

Change-Id: I42936aabe49b4afc14caa8445e6697d426a3776d
  • Loading branch information
grafuls authored and sadsfae committed Jul 13, 2022
1 parent 20568e8 commit 57dab39
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions quads/tools/move_and_rebuild_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ async def move_and_rebuild(host, new_cloud, semaphore, rebuild=False, loop=None)
logger.error("No way...")
return False

_new_cloud_obj = Cloud.objects(name=new_cloud).first()
_target_cloud = Cloud.objects(name=new_cloud).first()

ipmi_new_pass = (
f"{Config['infra_location']}@{_new_cloud_obj.ticket}"
if _new_cloud_obj.ticket
f"{Config['infra_location']}@{_target_cloud.ticket}"
if _target_cloud.ticket
else Config["ipmi_password"]
)

Expand All @@ -180,7 +180,7 @@ async def move_and_rebuild(host, new_cloud, semaphore, rebuild=False, loop=None)
await execute_ipmi(host, arguments=ipmi_set_operator, semaphore=new_semaphore)

badfish = None
if rebuild and _new_cloud_obj.name != _host_obj.default_cloud.name:
if rebuild and _target_cloud.name != _host_obj.default_cloud.name:
if Config.pdu_management:
# TODO: pdu management
pass
Expand Down Expand Up @@ -292,7 +292,7 @@ async def move_and_rebuild(host, new_cloud, semaphore, rebuild=False, loop=None)
f"There was something wrong setting PXE flag or resetting IPMI on {host}."
)

if _new_cloud_obj.name == _host_obj.default_cloud.name:
if _target_cloud.name == _host_obj.default_cloud.name:
if not badfish:
try:
badfish = await badfish_factory(
Expand All @@ -308,14 +308,18 @@ async def move_and_rebuild(host, new_cloud, semaphore, rebuild=False, loop=None)
return False

await badfish.set_power_state("off")
source_cloud_schedule = Schedule.current_schedule(cloud=_host_obj.cloud.name)
if not source_cloud_schedule:
_old_cloud_obj = Cloud.objects(name=_host_obj.cloud.name).first()
_old_cloud_obj.update(vlan=None)

schedule = Schedule.current_schedule(cloud=_new_cloud_obj, host=_host_obj).first()
schedule = Schedule.current_schedule(cloud=_target_cloud, host=_host_obj).first()
if schedule:
schedule.update(build_start=build_start, build_end=datetime.now())
schedule.save()

logger.debug("Updating host: %s")
_host_obj.update(
cloud=_new_cloud_obj, build=False, last_build=datetime.now(), validated=False
cloud=_target_cloud, build=False, last_build=datetime.now(), validated=False
)
return True

0 comments on commit 57dab39

Please sign in to comment.