Advertisement
Guest User

Untitled

a guest
Jun 14th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. import requests
  2. import subprocess
  3. from requests.auth import HTTPBasicAuth
  4. import threading
  5. import sys, os
  6. import time
  7.  
  8. def Api():
  9.     proc = subprocess.Popen([r"C:\Program Files (x86)\VMware\VMware Workstation\vmrest.exe"])
  10.     time.sleep(650)
  11.     proc.kill()
  12.     print("Cerrando el primer hilo")
  13.     os._exit(0)
  14. def Main():
  15.     vms = {}
  16.  
  17.     headers = {
  18.     'Content-Type': 'application/vnd.vmware.vmw.rest-v1+json',
  19.     'Accept': 'application/vnd.vmware.vmw.rest-v1+json',
  20.     }
  21.     print(sys.argv)
  22.     o = str(sys.argv[1]).lower()
  23.     data = ''
  24.     if o == 'on':
  25.         data = 'on'
  26.     elif o == 'off':
  27.         data = 'off'
  28.     else:
  29.  
  30.         sys.exit(0)
  31.     for p in vms.values():
  32.  
  33.              
  34.                 time.sleep(30)
  35.            
  36.                 r = requests.put('http://localhost:8697/api/vms/'+p+'/power', auth=HTTPBasicAuth('user', 'pass@'),data=data, headers=headers)
  37.                 print(r.status_code)
  38.                 while r.status_code != 200:
  39.                       r = requests.put('http://localhost:8697/api/vms/'+p+'/power',
  40.                                 auth=HTTPBasicAuth('user', 'pass@'), data=data, headers=headers)
  41.                 if r.status_code == 200:
  42.  
  43.                     print("Succesfully Started: "+p)
  44.                     continue
  45.     print("cerrando el segundo hilo")
  46.     os._exit(0)
  47.  
  48.  
  49.  
  50. thread1 = threading.Thread(target=Api)
  51. thread2 = threading.Thread(target=Main)
  52. # Will execute both in parallel
  53. thread1.start()
  54. thread2.start()
  55.  
  56. # Joins threads back to the parent process, which is this
  57.     # program
  58. thread1.join()
  59. thread2.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement