Advertisement
kmajumder

Untitled

Apr 26th, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. from connection import get_connection
  2. from config_variables import *
  3.  
  4. connection = get_connection()
  5.  
  6.  
  7. def remove_attached_vm_disk():
  8. vms_service = connection.system_service().vms_service()
  9. vm = vms_service.list(search='name=' + "km-disk-remove-check")[0]
  10.  
  11.  
  12. disk_attachments_service = vms_service.vm_service(vm.id)\
  13. .disk_attachments_service()
  14.  
  15. disk_attachments = disk_attachments_service.list()
  16. attachment =find_disk_attachment(connection, disk_attachments)
  17. print(attachment)
  18. if attachment:
  19. attachment.remove(detach_only=False)
  20. print("Disk removed")
  21.  
  22.  
  23. def find_disk_attachment(connection, disk_attachments):
  24. for disk_attachment in disk_attachments:
  25. disk = connection.follow_link(disk_attachment.disk)
  26. if disk.name == template_name+'-disk':
  27. print(disk.name)
  28. return disk_attachment
  29.  
  30.  
  31. def main():
  32. remove_attached_vm_disk()
  33.  
  34.  
  35. if __name__ == '__main__':
  36. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement