Home Scripting - All Others Python - Add Portgroup
Python - Add Portgroup PDF Print E-mail
Written by Siva   
Sunday, 07 January 2018 05:58

def AddHostsPortgroup(hosts, vswitchName, portgroupName, vlanId):

for host in hosts:

AddHostPortgroup(host, vswitchName, portgroupName, vlanId)



def AddHostPortgroup(host, vswitchName, portgroupName, vlanId):

portgroup_spec = vim.host.PortGroup.Specification()

portgroup_spec.vswitchName = vswitchName

portgroup_spec.name = portgroupName

portgroup_spec.vlanId = int(vlanId)

network_policy = vim.host.NetworkPolicy()

network_policy.security = vim.host.NetworkPolicy.SecurityPolicy()

network_policy.security.allowPromiscuous = True

network_policy.security.macChanges = False

network_policy.security.forgedTransmits = False

portgroup_spec.policy = network_policy


host.configManager.networkSystem.AddPortGroup(portgroup_spec)



def main():

args = get_args()

if args.skip_verification:

serviceInstance = SmartConnectNoSSL(host=args.host,

user=args.user,

pwd=args.password,

port=443)

else:

serviceInstance = SmartConnect(host=args.host,

user=args.user,

pwd=args.password,

port=443)

atexit.register(Disconnect, serviceInstance)

content = serviceInstance.RetrieveContent()


hosts = GetVMHosts(content, args.regex_esxi)

AddHostsPortgroup(hosts, args.vswitch, args.portgroup, args.vlanid)

 
 

Advertisement

Featured Links:
HREmail.com
Looking for job? Try HREmail.com
Want to have CMS based Websites?
Try siliconwebcreators.com to CMS based websites.
VM Solutions Inc
For best VM solutions..
Digital Procedure Inc.
Looking for Oracle /SAP /Weblogic Consulting services? visit digitalprocedure.com