Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import subprocess
- from requests.auth import HTTPBasicAuth
- import threading
- import sys, os
- import time
- def Api():
- proc = subprocess.Popen([r"C:\Program Files (x86)\VMware\VMware Workstation\vmrest.exe"])
- time.sleep(650)
- proc.kill()
- print("Cerrando el primer hilo")
- os._exit(0)
- def Main():
- vms = {}
- headers = {
- 'Content-Type': 'application/vnd.vmware.vmw.rest-v1+json',
- 'Accept': 'application/vnd.vmware.vmw.rest-v1+json',
- }
- print(sys.argv)
- o = str(sys.argv[1]).lower()
- data = ''
- if o == 'on':
- data = 'on'
- elif o == 'off':
- data = 'off'
- else:
- sys.exit(0)
- for p in vms.values():
- time.sleep(30)
- r = requests.put('http://localhost:8697/api/vms/'+p+'/power', auth=HTTPBasicAuth('user', 'pass@'),data=data, headers=headers)
- print(r.status_code)
- while r.status_code != 200:
- r = requests.put('http://localhost:8697/api/vms/'+p+'/power',
- auth=HTTPBasicAuth('user', 'pass@'), data=data, headers=headers)
- if r.status_code == 200:
- print("Succesfully Started: "+p)
- continue
- print("cerrando el segundo hilo")
- os._exit(0)
- thread1 = threading.Thread(target=Api)
- thread2 = threading.Thread(target=Main)
- # Will execute both in parallel
- thread1.start()
- thread2.start()
- # Joins threads back to the parent process, which is this
- # program
- thread1.join()
- thread2.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement