예제 #1
0
def main():
	parser = argparse.ArgumentParser(description='vCenter login')
	parser.add_argument('-s', '--host', required=True, action='store', help='vSphere IP')
	parser.add_argument('-o', '--port', type=int, default=443, action='store', help='vSphere Port')
	parser.add_argument('-u', '--user', required=True, action='store', help='User name')
	parser.add_argument('-p', '--password', required=True, action='store', help='Password')

	args = parser.parse_args()

	try:
		service_instance = connect.SmartConnect(host=args.host,
												user=args.user,
												pwd=args.password,
												port=int(args.port))
		atexit.register(connect.Disconnect, service_instance)

		content=service_instance.RetrieveContent()
		for respool in libvmtask.get_vim_objects(content,vim.ResourcePool):
			#pprint(getmembers(respool))
			vmliststr = ''
			sys.stdout.write("name=" + str(respool.name))
			sys.stdout.write("|parent=" + str(respool.parent.name))
			sys.stdout.write("|overallStatus=" + str(respool.overallStatus))
			sys.stdout.write("|cpuexpandablereservation=" + str(respool.summary.config.cpuAllocation.expandableReservation))
			sys.stdout.write("|cpureservation=" + str(respool.summary.config.cpuAllocation.reservation))
			sys.stdout.write("|cpulimit=" + str(respool.summary.config.cpuAllocation.limit))
			sys.stdout.write("|cpushares=" + str(respool.summary.config.cpuAllocation.shares.shares))
			sys.stdout.write("|cpulevel=" + str(respool.summary.config.cpuAllocation.shares.level))
			sys.stdout.write("|cpuoverallusage=" + str(respool.summary.runtime.cpu.overallUsage))
			sys.stdout.write("|cpumaxusage=" + str(respool.summary.runtime.cpu.maxUsage))
			sys.stdout.write("|memoryexpandablereservation=" + str(respool.summary.config.memoryAllocation.expandableReservation))
			sys.stdout.write("|memoryreservation=" + str(respool.summary.config.memoryAllocation.reservation))
			sys.stdout.write("|memorylimit=" + str(respool.summary.config.memoryAllocation.limit))
			sys.stdout.write("|memoryshares=" + str(respool.summary.config.memoryAllocation.shares.shares))
			sys.stdout.write("|memorylevel=" + str(respool.summary.config.memoryAllocation.shares.level))
			sys.stdout.write("|memoryoverallusage=" + str(respool.summary.runtime.memory.overallUsage))
			sys.stdout.write("|memorymaxusage=" + str(respool.summary.runtime.memory.maxUsage))
			sys.stdout.write("|vm=")
			for vm in respool.vm:
				vmliststr = vmliststr + vm.name + ","
			vmliststr = vmliststr[:-1]
			sys.stdout.write(vmliststr)

			print

		return 0

	except vmodl.MethodFault as error:
		print("ERROR: " + error.msg)
		sys.exit(1)
예제 #2
0
def main():
	parser = argparse.ArgumentParser(description='vCenter login')
	parser.add_argument('-s', '--host', required=True, action='store', help='vSphere IP')
	parser.add_argument('-o', '--port', type=int, default=443, action='store', help='vSphere Port')
	parser.add_argument('-u', '--user', required=True, action='store', help='User name')
	parser.add_argument('-p', '--password', required=True, action='store', help='Password')
	parser.add_argument('-n', '--name', required=True, action='store', help='ESX Host name')

	args = parser.parse_args()

	try:
		service_instance = connect.SmartConnect(host=args.host,
												user=args.user,
												pwd=args.password,
												port=int(args.port))
		atexit.register(connect.Disconnect, service_instance)
	
		content=service_instance.RetrieveContent()
		for Host in libvmtask.get_vim_objects(content,vim.HostSystem):
			if Host.name == args.name:
				datastore = Host.configManager.storageSystem
				host_volumes = datastore.fileSystemVolumeInfo.mountInfo
				for v in host_volumes:
					#print v
					#print v.volume
					if v.volume.name:
						sys.stdout.write("name=" + str(v.volume.name))
						sys.stdout.write("|type=" + str(v.volume.type))
						sys.stdout.write("|capacity=" + str(v.volume.capacity/1024/1024))
						sys.stdout.write("|remoteHost=" + str(v.volume.remoteHost))
						sys.stdout.write("|remotePath=" + str(v.volume.remotePath))
						print

		return 0

	except vmodl.MethodFault as error:
		print("ERROR: " + error.msg)
		sys.exit(1)
예제 #3
0
def main():
    parser = argparse.ArgumentParser(description='vCenter login')
    parser.add_argument('-s',
                        '--host',
                        required=True,
                        action='store',
                        help='vSphere IP')
    parser.add_argument('-o',
                        '--port',
                        type=int,
                        default=443,
                        action='store',
                        help='vSphere Port')
    parser.add_argument('-u',
                        '--user',
                        required=True,
                        action='store',
                        help='User name')
    parser.add_argument('-p',
                        '--password',
                        required=True,
                        action='store',
                        help='Password')
    parser.add_argument('-n',
                        '--name',
                        required=True,
                        action='store',
                        help='VM name')
    parser.add_argument('-q',
                        '--resourcepool',
                        required=True,
                        action='store',
                        help='ResourcePool name')
    parser.add_argument('-d',
                        '--datastore',
                        required=False,
                        action='store',
                        help='Datastore name')
    args = parser.parse_args()

    try:
        service_instance = connect.SmartConnect(host=args.host,
                                                user=args.user,
                                                pwd=args.password,
                                                port=int(args.port))
        atexit.register(connect.Disconnect, service_instance)

        content = service_instance.content
        objView = content.viewManager.CreateContainerView(
            content.rootFolder, [vim.VirtualMachine], True)
        vmlist = objView.view
        objView.Destroy()

        for vm in vmlist:
            if vm.name == args.name:
                #print vm.name
                spec = vim.VirtualMachineRelocateSpec()

                for respool in libvmtask.get_vim_objects(
                        content, vim.ResourcePool):
                    if respool.name == args.resourcepool:
                        resourcepool = respool

                if not resourcepool:
                    sys.exit(0)
                spec.pool = resourcepool

                if args.datastore:
                    for ds in libvmtask.get_vim_objects(
                            content, vim.Datastore):
                        if ds.name == args.datastore:
                            spec.datastore = ds

                #print spec
                task = vm.RelocateVM_Task(spec)
                libvmtask.WaitForTasks([task], service_instance)

        return 0

    except vmodl.MethodFault as error:
        print("ERROR: " + error.msg)
        sys.exit(1)
예제 #4
0
def main():
    parser = argparse.ArgumentParser(description='vCenter login')
    parser.add_argument('-s',
                        '--host',
                        required=True,
                        action='store',
                        help='vSphere IP')
    parser.add_argument('-o',
                        '--port',
                        type=int,
                        default=443,
                        action='store',
                        help='vSphere Port')
    parser.add_argument('-u',
                        '--user',
                        required=True,
                        action='store',
                        help='User name')
    parser.add_argument('-p',
                        '--password',
                        required=True,
                        action='store',
                        help='Password')

    args = parser.parse_args()

    try:
        service_instance = connect.SmartConnect(host=args.host,
                                                user=args.user,
                                                pwd=args.password,
                                                port=int(args.port))
        atexit.register(connect.Disconnect, service_instance)

        content = service_instance.RetrieveContent()
        # vswitches
        for Host in libvmtask.get_vim_objects(content, vim.HostSystem):
            for vswitch in Host.config.network.vswitch:
                #print(vswitch.name)
                #print(vswitch)
                for portgroup in vswitch.portgroup:
                    #print str(portgroup)
                    #t = str(portgroup.split("key-vim.host.PortGroup-",1))
                    #print portgroup.split("-",2)[2]
                    pgname = str(portgroup.split("-", 2)[2])
                    pgname = pgname.replace(" ", "@")
                    sys.stdout.write("t=vs")
                    sys.stdout.write("|name=" + pgname)
                    sys.stdout.write("|vswitch=" + str(vswitch.name))
                    sys.stdout.write("|numPorts=" + str(vswitch.numPorts))
                    sys.stdout.write("|numPortsAvailable=" +
                                     str(vswitch.numPortsAvailable))
                    sys.stdout.write("|mtu=" + str(vswitch.mtu))
                    sys.stdout.write("|key=" + str(vswitch.key))

                    print

            datastore = Host.configManager.storageSystem
            host_volumes = datastore.fileSystemVolumeInfo.mountInfo
            for v in host_volumes:
                #print v
                #print v.volume
                if v.volume.name:
                    sys.stdout.write("t=ds")
                    sys.stdout.write("|name=" + str(v.volume.name))
                    sys.stdout.write("|type=" + str(v.volume.type))
                    sys.stdout.write("|capacity=" +
                                     str(v.volume.capacity / 1024 / 1024))
                    sys.stdout.write("|remoteHost=" + str(v.volume.remoteHost))
                    sys.stdout.write("|remotePath=" + str(v.volume.remotePath))
                    print

        # resource pools
        for respool in libvmtask.get_vim_objects(content, vim.ResourcePool):
            #print(respool.summary.name)
            #print(respool.name)
            sys.stdout.write("t=rs")
            sys.stdout.write("|name=" + str(respool.summary.name))
            print

        # datacenter
        content = service_instance.RetrieveContent()
        for dc in content.rootFolder.childEntity:
            sys.stdout.write("t=dc")
            sys.stdout.write("|name=" + str(dc.name))
            print

        return 0

    except vmodl.MethodFault as error:
        print("ERROR: " + error.msg)
        sys.exit(1)
예제 #5
0
def main():
    parser = argparse.ArgumentParser(description='vCenter login')
    parser.add_argument('-s',
                        '--host',
                        required=True,
                        action='store',
                        help='vSphere IP')
    parser.add_argument('-o',
                        '--port',
                        type=int,
                        default=443,
                        action='store',
                        help='vSphere Port')
    parser.add_argument('-u',
                        '--user',
                        required=True,
                        action='store',
                        help='User name')
    parser.add_argument('-p',
                        '--password',
                        required=True,
                        action='store',
                        help='Password')
    parser.add_argument('-n',
                        '--name',
                        required=True,
                        action='store',
                        help='ESX Host name')

    args = parser.parse_args()

    try:
        service_instance = connect.SmartConnect(host=args.host,
                                                user=args.user,
                                                pwd=args.password,
                                                port=int(args.port))
        atexit.register(connect.Disconnect, service_instance)

        content = service_instance.RetrieveContent()
        pnics_used = ''
        pnics_avail = ''
        for Host in libvmtask.get_vim_objects(content, vim.HostSystem):
            if Host.name == args.name:
                #print getmembers(Host)
                for vswitch in Host.config.network.vswitch:
                    #print getmembers(vswitch)
                    sys.stdout.write("type=vs")
                    sys.stdout.write("|name=" + str(vswitch.name))
                    sys.stdout.write("|numPorts=" + str(vswitch.numPorts))
                    sys.stdout.write("|numPortsAvailable=" +
                                     str(vswitch.numPortsAvailable))
                    sys.stdout.write("|mtu=" + str(vswitch.mtu))
                    pnics = ''

                    # debugging
                    #f = []
                    #if vswitch.name == 'vSwitch0':
                    #	f.append('vmnic0')
                    #	f.append('vmnic1')
                    #	f.append('vmnic2')
                    #	f.append('vmnic3')
                    #for vn in f:

                    for vn in vswitch.spec.policy.nicTeaming.nicOrder.activeNic:
                        pnics = pnics + vn + ','
                        pnics_used = pnics_used + vn + ','
                    pnics = pnics[:-1]
                    sys.stdout.write("|pnic=" + str(pnics))
                    print

                    for portgroup in vswitch.portgroup:
                        pgname = str(portgroup.split("-", 2)[2])
                        pgname = pgname.replace(" ", "@")
                        sys.stdout.write("type=pg")
                        sys.stdout.write("|name=" + pgname)
                        sys.stdout.write("|vswitch=" + str(vswitch.name))
                        sys.stdout.write("|numPorts=" + str(vswitch.numPorts))
                        sys.stdout.write("|numPortsAvailable=" +
                                         str(vswitch.numPortsAvailable))
                        sys.stdout.write("|mtu=" + str(vswitch.mtu))
                        sys.stdout.write("|key=" + str(vswitch.key))
                        print

                #print Host.config.network.pnic
                #f = []
                #f.append('vmnic0')
                #f.append('vmnic1')
                #f.append('vmnic2')
                #f.append('vmnic3')
                #for phys_net in f:
                #	pnics_avail = pnics_avail + str(phys_net) + ','

                for phys_net in Host.config.network.pnic:
                    pnics_avail = pnics_avail + str(phys_net.device) + ','

        pnics_used = pnics_used[:-1]
        pnics_avail = pnics_avail[:-1]
        sys.stdout.write("type=pnic")
        sys.stdout.write("|pnic_used=" + str(pnics_used))
        sys.stdout.write("|pnic_avail=" + str(pnics_avail))
        print
        return 0

    except vmodl.MethodFault as error:
        print("ERROR: " + error.msg)
        sys.exit(1)