def main():
    #args = GetArgs()
    try:
        si = None
        try:
            print "Trying to connect to VCENTER SERVER . . ."
            si = connect.Connect(inputs['vcenter_ip'], 443, inputs['vcenter_user'], inputs['vcenter_password'])
        except __HOLE__, e:
            pass
            atexit.register(Disconnect, si)

        print "Connected to VCENTER SERVER !"
        
        content = si.RetrieveContent()
        
        #vm_name = args.vm
        vm_name = inputs['vm_name']      
        vm = get_obj(content, [vim.VirtualMachine], vm_name)

        if vm.runtime.powerState != 'poweredOff':
            print "WARNING:: Power off your VM before reconfigure"
            sys.exit()

        adaptermap = vim.vm.customization.AdapterMapping()
        globalip = vim.vm.customization.GlobalIPSettings()
        adaptermap.adapter = vim.vm.customization.IPSettings()
        
        isDHDCP = inputs['isDHCP']
        if not isDHDCP:
            """Static IP Configuration"""
            adaptermap.adapter.ip = vim.vm.customization.FixedIp()
            adaptermap.adapter.ip.ipAddress = inputs['vm_ip']
            adaptermap.adapter.subnetMask = inputs['subnet']
            adaptermap.adapter.gateway = inputs['gateway']  
            globalip.dnsServerList = inputs['dns']
            
        else:
            """DHCP Configuration"""
            adaptermap.adapter.ip = vim.vm.customization.DhcpIpGenerator()
            
        adaptermap.adapter.dnsDomain = inputs['domain']
        
        globalip = vim.vm.customization.GlobalIPSettings()
        
        #For Linux . For windows follow sysprep
        ident = vim.vm.customization.LinuxPrep(domain=inputs['domain'], hostName=vim.vm.customization.FixedName(name=vm_name))        
        
        customspec = vim.vm.customization.Specification()
        #For only one adapter
        customspec.identity = ident
        customspec.nicSettingMap = [adaptermap]
        customspec.globalIPSettings = globalip
        
        #Configuring network for a single NIC
        #For multipple NIC configuration contact me.

        print "Reconfiguring VM Networks . . ."
        
        task = vm.Customize(spec=customspec)

        # Wait for Network Reconfigure to complete
        wait_for_task(task, si)        
        
    except vmodl.MethodFault, e:
        print "Caught vmodl fault: %s" % e.msg
        return 1
    except Exception, e:
        print "Caught exception: %s" % str(e)
        return 1
    
# Start program
dataset/ETHPy150Open rreubenur/vmware-pyvmomi-examples/network_configure.py/main