f00d276 Nov 24, 2017
1 contributor

Users who have contributed to this file

33 lines (26 sloc) 1.13 KB
# Author: Vikas Shitole
# Website:
# Product: vCenter server
# Description: Python module for vCenter server REST APIs
# Reference:
# How to setup vCenter REST API environment?: Just have VM with python and install "requests" python library using pip
import requests
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Function to get the vCenter server session
def get_vc_session(vcip,username,password):'https://'+vcip+'/rest/com/vmware/cis/session',auth=(username,password))
return s
# Function to get all the VMs from vCenter inventory
def get_vms(vcip):
return vms
#Function to power on particular VM
def poweron_vm(vmmoid,vcip):'https://'+vcip+'/rest/vcenter/vm/'+vmmoid+'/power/start')
# Function to power off particular VM
def poweroff_vm(vmmoid,vcip):'https://'+vcip+'/rest/vcenter/vm/'+vmmoid+'/power/stop')