Exemple #1
0
def main():
    dry_run = False
    verbose = False
    args = sys.argv[1:]

    while ((len(args) > 0) and (args[0].startswith("-"))):
        arg = args[0]

        if (arg.startswith("-d") or (arg.startswith("--d"))):
            dry_run = True
        elif (arg.startswith("-v") or (arg.startswith("--v"))):
            verbose = True
        else:
            print("Unrecognized option \"" + arg + "\"")
            args = args[0:0]  # Hack - force the Usage line to come up next

        args = args[1:]

    if (len(args) != 2):
        print("Usage: [--dry-run] [--verbose] <server> <file>")
        sys.exit(1)

    server = args[0]
    infile = open(args[1])

    context = loginutils.netlablogin(server)
    all_roles = vmwareutils.get_all_roles(context)

    role_file = load_role_file(infile)
    handle_all_roles(role_file, context, all_roles, dry_run, verbose)

    sambautils.disable_user(ADMIN_SVC_ACCT)
Exemple #2
0
def main():
	really_do_it = False

	args = sys.argv

	if (len(args) < 2):
		print("Usage: <server>")
		sys.exit(1)

	server = args[1]

	context = loginutils.netlablogin(server)
	vmwareutils.get_all_roles(context)

	# Get all objects with any permissions
	all_perms = context.authorizationManager.RetrieveAllPermissions()

	for p in all_perms:
		name = full_name(p.entity,context.rootFolder)

		if (p.group):
			type = "GROUP"
		else:
			type = "USER"
		
		if (p.propagate):
			prop = "TRUE"
		else:
			prop = "FALSE"
	
		print(name,type,p.principal,
			prop,vmwareutils.get_rolename(p.roleId),sep="\t")
def main():
    really_do_it = False

    args = sys.argv[1:]  # Ignore the name

    if (len(args) != 2):
        print("Usage: <server> <file>")
        sys.exit(1)

    i = 0
    server = args[i]
    i += 1

    infile = open(args[i])
    i += 1

    context = loginutils.netlablogin(server)
    vmwareutils.get_all_roles(context)

    vmwareutils.get_all_objects(context)

    for line in infile:
        if (line.startswith("#")):
            continue

        line = line.rstrip()

        (shortname, fullname, type) = line.split("\t")

        if (type == "vim.Folder"):
            check_folder(fullname)

    sambautils.disable_user(ADMIN_SVC_ACCT)
def main():
    really_do_it = False

    args = sys.argv

    if (len(args) < 5):
        print(
            "Usage: [-y] <server> <folder-name> <suspend-days> <poweroff-days>"
        )
        sys.exit(1)

    i = 1

    if (args[i] == "-y"):
        really_do_it = True
        i += 1

    server = args[i]
    i += 1
    folderName = args[i]
    i += 1
    suspendDays = int(args[i])
    i += 1
    powerOffDays = int(args[i])
    i += 1

    context = loginutils.netlablogin(server)
    #vmwareutils.get_all_roles(context)

    #all_groups = sambautils.get_all_groups()

    folder = vmwareutils.get_folder(context, folderName)

    poweredon_vms = vmwareutils.get_all_vms(folder, 10, "poweredOn")
    suspended_vms = vmwareutils.get_all_vms(folder, 10, "suspended")

    # If the user doesn't want to suspend systems, then lump all non-poweredoff systems together
    if (suspendDays <= 0):
        suspended_vms = suspended_vms + poweredon_vms

    if (suspendDays > 0):
        for v in poweredon_vms:
            if (not has_recent_events(context, v, 7)):
                print("Suspend", v.summary.config.name)

                if (really_do_it):
                    v.SuspendVM_Task()

    if (powerOffDays > 0):
        for v in suspended_vms:
            if (not has_recent_events(context, v, 14)):
                print("Shutdown", v.summary.config.name)

                if (really_do_it):
                    #v.ShutdownGuest()
                    v.PowerOffVM_Task()

    sambautils.disable_user(ADMIN_SVC_ACCT)
Exemple #5
0
def main():
    args = sys.argv

    server = args[1]

    context = loginutils.netlablogin(server)
    vmwareutils.get_all_roles(context)

    get_all_objects(context)
Exemple #6
0
def main():
	really_do_it = False

	args = sys.argv

	if (len(args) < 4):
		print("Usage: [--dry_run|-d] <server> <group|user> [-n #] " + \
			"<pool-name> [<subpool-name>]")

		sys.exit(1)

	i = 1

	if ((args[i].startswith("--d")) or (args[i].startswith("-d"))):
		i += 1
		dry_run = True
	else:
		dry_run = False

	server = args[i]; i += 1
	userorgroup = args[i]; i += 1

	if (args[i].startswith("-n")):
		i += 1
		count = int(args[i]); i += 1
	else:
		count = 1

	poolname = args[i].lower(); i += 1
	if (len(args) > i):
		altpoolname = args[i].lower(); i += 1
	else:
		altpoolname = poolname

	vmwareutils.set_domain("NETLAB\\")
	sambautils.set_domain("NETLAB\\")

	users = sambautils.get_userlist_for_user_or_group(userorgroup)

	if (len(users) == 0):
		print("No such user or group '" + userorgroup + "'")
		sys.exit(1)

	context = loginutils.netlablogin(server)

	vmwareutils.get_all_roles(context)

	(free_nets,user_count) = get_nets_and_users(context,poolname,altpoolname)

	assign_to_users(context, users, count, free_nets, user_count, dry_run)
Exemple #7
0
def main():
    dry_run = False
    verbose = False
    args = sys.argv[1:]

    while ((len(args) > 0) and (args[0].startswith("-"))):
        arg = args[0]

        if (arg.startswith("-d") or (arg.startswith("--d"))):
            dry_run = True
        elif (arg.startswith("-v") or (arg.startswith("--v"))):
            verbose = True
        else:
            print("Unrecognized option \"" + arg + "\"")
            args = args[0:0]  # Hack - force the Usage line to come up next

        args = args[1:]

    if (len(args) != 3):
        print("Usage: [--dry-run] [--verbose] <server> <source-folder> <file>")
        sys.exit(1)

    server = args[0]
    folder = args[1]
    infile = open(args[2])

    vmwareutils.set_domain("NETLAB\\")
    sambautils.set_domain("NETLAB\\")

    context = loginutils.netlablogin(server)

    desired_locs = load_desired_locations(infile)
    vmwareutils.get_all_objects(context, filter=pyVmomi.vim.Folder)

    if (folder == ""):
        source_folder = context.rootFolder
    else:
        source_folder = vmwareutils.get_obj(
            context, [pyVmomi.vim.Folder, pyVmomi.vim.Datacenter], folder)

        # If this is a DC, then look for the special vmFolder within it
        if (isinstance(source_folder, pyVmomi.vim.Datacenter)):
            source_folder = source_folder.vmFolder

    if (source_folder is None):
        print("No such folder '" + folder + "' on ", server, file=sys.stderr)
        sys.exit(1)

    move_systems(source_folder, desired_locs, dry_run, verbose)
Exemple #8
0
def main():
	really_do_it = False

	args = sys.argv[1:]   # Ignore the name

	ignore_missing = False
	dry_run = False
	remove_extra = False


	while ((len(args) > 0) and (args[0].startswith("-"))):
		arg = args[0]

		if (arg.startswith("-d") or (arg.startswith("--d"))):
			dry_run = True
		elif (arg.startswith("-r") or (arg.startswith("--r"))):
			remove_extra = True
		elif (arg.startswith("-i") or (arg.startswith("--i"))):
			ignore_missing = True
		else:
			print("Unrecognized option \"" + arg + "\"")
			args = args[0:0]  # Hack - force the Usage line to come up next

		args = args[1:]

	if (len(args) != 2):
		print("Usage: [--dry-run] [--remove-extra] [--ignore-missing] <server> <file>")
		sys.exit(1)

	server = args[0]
	infile = open(args[1])

	context = loginutils.netlablogin(server)
	vmwareutils.get_all_roles(context)
	
	get_all_objects(context)
	get_live_perms(context)
	get_file_perms(infile, dry_run, ignore_missing)

	compare_perms(context,dry_run,remove_extra, ignore_missing)

	sambautils.disable_user(ADMIN_SVC_ACCT)
def main():
	args = sys.argv

	if (len(args) < 2):
		print("Usage: <server>")
		sys.exit(1)

	server = args[1]

	context = loginutils.netlablogin(server)
	all_roles = vmwareutils.get_all_roles(context)

	for r in all_roles:
		# Ignore the system roles
		if (r.roleId < 1):
			continue

		for p in r.privilege:
			if (not p.startswith("System.")):
				print(r.name,r.info.label,p,sep="\t")
def main():
    global OUTPUT_LEVEL

    ignore_path = []

    args = parse_args()

    OUTPUT_LEVEL = args.output_level
    server = args.server

    if (args.default_ignore):
        #print("Adding default ignore list")

        ignore_path.append(
            r": \[[^\]]+\] ?\.")  # Any file in / staring with a .
        ignore_path.append(r"\.[iI][Ss][oO]$")  # ISO files
        ignore_path.append(r"\.[zZ][Ii][Pp]$")  # Zip files

        ignore_path.append(r"/\.lck-[01-9a-f]+$")  # VMWare Lock files
        ignore_path.append(r"\] vmkdump/")  # ESXi dumpfiles

        ignore_path.append(r"\] @Recently-Snapshot/")  # QNAP snapshot location

        ignore_path.append(r": \[Install Media\] ")  # My location for .iso's
        ignore_path.append(
            r": \[CyberSecurity SW\] ")  # My location for (special) .iso's
        ignore_path.append(
            r": \[[^\]]*Content Library\] ")  # My locartion for pushed .vmdk's
    # Fix the type if type=both was not specified
    if (args.type == 'no-vm'):
        ignore_path.append(r"\(Has VM\)")

    if (args.type == 'has-vm'):
        ignore_path.append(r"\(No VM\)")

    for regx in args.ignore_list:
        #print("Will ignore",reg)
        ignore_path.append(regx)

    show_options = args.show
    # Take the default if no "--show" given
    if (show_options is None):
        show_options = arg_show_options("")

    output(2, "::Logging level = " + str(OUTPUT_LEVEL))

    output(2, "::Logging into server " + server)

    context = loginutils.netlablogin(server)

    output(2, "::Finding all VM files...")
    find_all_vm_files(context, ignore_path, 'diffname' in show_options)

    output(2, "::Finding all Datastores...")
    stores = find_all_datastores(context)

    output(2, "::Finding all files...")
    for ds in stores:
        get_store_files(ds, ignore_path)

    output(2, "::Checking for orphaned files...")
    find_orphaned(ignore_path, show_options)

    if ('missing' in show_options):
        output(2, "::Checking for missing files...")
        show_missing(ignore_path)

    if ('empty-dirs' in show_options):
        output(2, "::Checking for empty directories...")
        show_empty_directories(ignore_path)
Exemple #11
0
def main():
	pools = {}

	args = parse_args()

	server = args.server
	verbose = args.verbose or True		# Force true for now
	dry_run = args.dry_run
	vm_selection = args.select
	info_only = args.info_only

	# Try to load the balance-goals, error out if necessary
	print("Balance Goals: ",args.balance_goals)

	goals = datastoreScore.WholeScore(args.balance_goals)

	#(has_size,has_num) = goals.score_types()
	set_sorting_style(args.vm_select_mode,args.vm_size_select,args.vm_status_select)

	if (not goals.is_ok()):
		show_error_balance_weight()
		sys.exit(1)

	for p in args.pools:
		weight = 1.0

		if (":" in p):
			(p,weight) = p.split(":")
			weight = float(weight)

		pools[p] = { 'weight' : weight, 'name' : p }

	context = loginutils.netlablogin(server)
	
	# Get the objects from the names, exit if one or more is not found
	ok = find_all_pools(context,pools)

	if (not ok):
		sys.exit(1)

	gather_pool_info(pools,vm_selection, folders=args.vm_folders)
	compute_totals(pools)

	all_vms = find_all_vms(pools)

	# Show ahead of time
	if (verbose):
		print_pools(pools,"BEFORE", vm_selection, goals)

	# Prune the list if necessary
	pools = remove_nonready_pools(pools)

	# Recompute totals (if pools were removed)
	compute_totals(pools)
	compute_pool_weights(pools)
	compute_pool_scores(pools, goals)

	#
	# You need at least two pools to do migrations
	#
	if (len(pools) > 1):
		#sort_pool_vms(pools)

		max_imbalance = args.imbalance_goal / 100.0	# Convert to a float 0..1

		move_servers(pools,all_vms, goals, args.max_moves, max_imbalance, dry_run, 
			     verbose,args.max_concurrent_moves)

		# Wait for last tasks to end
		if (not dry_run):
			wait_for_n_tasks(verbose=verbose)

		# Show after
		if ((verbose) and (not dry_run)):
			print_pools(pools,"AFTER",vm_selection, goals,True)

	else:
		print("No enough pools to migrate (need at least 2 available)")


	sambautils.disable_user(ADMIN_SVC_ACCT)