Advertisement
ol_x

ESXI VM Switching

Sep 13th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. import socket
  2. import time
  3. from pysphere import VIServer
  4.  
  5. active = True
  6. majorVM = ""
  7. minorVM = ""
  8. activeVM = majorVM
  9. port = 80
  10.  
  11. esxi_major_host = ""
  12. esxi_minor_host = ""
  13. esxi_user = ""
  14. esxi_pass = ""
  15.  
  16. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  17. sock.settimeout(2)
  18. while active:
  19.     try:
  20.         result = sock.connect_ex((activeVM, port))
  21.         if result == 0:
  22.             print 'port OPEN'
  23.         else:
  24.             if activeVM == majorVM:
  25.                 # подключиться к дублирующему серверу esxi
  26.                 server = VIServer()
  27.                 server.connect(esxi_minor_host, esxi_user, esxi_pass)
  28.                 vm = server.get_vm_by_name(minorVM)
  29.                 vm.start_process() # вызвать команту, которая поменяет ип
  30.                 server.disconnect()
  31.  
  32.                 server.connect(esxi_major_host, esxi_user, esxi_pass)
  33.                 vm = server.get_vm_by_name(majorVM)
  34.                 vm.power_off()
  35.                 server.disconnect()
  36.  
  37.                 activeVM = minorVM
  38.                 # запустить уведомление
  39.  
  40.     except  Exception as e:
  41.         # обработать ошибку
  42.         print "socket error"
  43.  
  44.     time.sleep(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement