Commit 5e4851c2 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Also destroy all Slaves allocated at the instance

This is helpfull to allow instances be re-requested and allocated by their respective Slave Instances
parent d1c03593
...@@ -5,8 +5,8 @@ portal = context.getPortalObject() ...@@ -5,8 +5,8 @@ portal = context.getPortalObject()
if portal.portal_membership.isAnonymousUser(): if portal.portal_membership.isAnonymousUser():
raise Unauthorized("You cannot invoke this API as Annonymous") raise Unauthorized("You cannot invoke this API as Annonymous")
#if context.SoftwareInstance_isUserAllowedToDestroy(): if not context.SoftwareInstance_isUserAllowedToDestroy():
# raise Unauthorized("You cannot destroy this %s." % context.getPortalType()) raise Unauthorized("You cannot destroy this %s." % context.getPortalType())
if context.getSlapState() not in ["start_requested", "stop_requested"]: if context.getSlapState() not in ["start_requested", "stop_requested"]:
return context.Base_redirect(keep_items={"portal_status_message": "This %s is on %s state and cannot be destroyed." \ return context.Base_redirect(keep_items={"portal_status_message": "This %s is on %s state and cannot be destroyed." \
...@@ -16,4 +16,13 @@ if context.getSlapState() not in ["start_requested", "stop_requested"]: ...@@ -16,4 +16,13 @@ if context.getSlapState() not in ["start_requested", "stop_requested"]:
# from a python script # from a python script
context.SoftwareInstance_renameAndRequestDestroy() context.SoftwareInstance_renameAndRequestDestroy()
# Request Destroy on all Slaves allocated on the same partition
computer_partition = context.getAggregateValue(
portal_type="Computer Partition")
if computer_partition is not None:
for slave in computer_partition.getAggregateRelatedValueList(
portal_type="Slave Instance"):
slave.SoftwareInstance_renameAndRequestDestroy()
return context.Base_redirect(keep_items={"portal_status_message": "Destroy requested."}) return context.Base_redirect(keep_items={"portal_status_message": "Destroy requested."})
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment