Esempio n. 1
0
def runServerScript(script_id,username,jobNotify,devices,scriptArgs,twist,timeout=10):
	jobStarted = False
	time_offset = 5
	while not jobStarted:
		ssref = ServerScriptRef(script_id)
		ssService = twist.script.ServerScriptService
		ssJobArgs = ServerScriptJobArgs()
		ssJobArgs.targets = map(lambda x: ServerRef(x),devices)
		ssJobArgs.timeOut = timeout
		ssJobArgs.parameters = scriptArgs
		jobSchedule = JobSchedule()
		jobSchedule.startDate = int(time.time() + time_offset)
		try:
			jobId = ssService.startServerScript(	ssref,
								ssJobArgs,
								username,
								jobNotify,
								jobSchedule).id
			jobStarted = True
		except PastScheduledDateException:
			print "Server Script (%s) is being rescheduled" % \
				ssService.getServerScriptVO(ssref).name 
			jobStarted = False 
			time_offset = time_offset + 5
	return jobId
Esempio n. 2
0
def runServerScript(script_id,
                    username,
                    jobNotify,
                    devices,
                    scriptArgs,
                    twist,
                    timeout=10):
    jobStarted = False
    time_offset = 5
    while not jobStarted:
        ssref = ServerScriptRef(script_id)
        ssService = twist.script.ServerScriptService
        ssJobArgs = ServerScriptJobArgs()
        ssJobArgs.targets = map(lambda x: ServerRef(x), devices)
        ssJobArgs.timeOut = timeout
        ssJobArgs.parameters = scriptArgs
        jobSchedule = JobSchedule()
        jobSchedule.startDate = int(time.time() + time_offset)
        try:
            jobId = ssService.startServerScript(ssref, ssJobArgs, username,
                                                jobNotify, jobSchedule).id
            jobStarted = True
        except PastScheduledDateException:
            print "Server Script (%s) is being rescheduled" % \
             ssService.getServerScriptVO(ssref).name
            jobStarted = False
            time_offset = time_offset + 5
    return jobId

    server_filter = Filter()
    print opts.filter
    server_filter.expression="(%s)&(%s)" % (opts.filter,platform_filter)
    print server_filter.expression
    server_refs=server_service.findServerRefs(server_filter)


    server_array=[]
    for srv in server_refs:
        server_array.append(srv)
    filtered_refs=auth_service.filterSingleTypeResourceList(OperationConstants.EXECUTE_SERVER_SCRIPT, server_array)
    ssja=ServerScriptJobArgs()
    ssja.targets=filtered_refs
    ssja.timeOut=3600
    if opts.args:
        ssja.parameters=opts.args
    if opts.runas_user and opts.runas_pwd and opts.runas_domain:
        ssja.username=opts.runas_user
        ssja.password=opts.runas_pwd
        ssja.loginDomain=opts.runas_domain
    if int(opts.debug)!=1:
        job_ref=server_script_service.startServerScript(script_ref,ssja,'Script from pytwist',default_notify(opts.email),None)
        print job_ref
    else:
        print filtered_refs

    if int(opts.debug)!=1:
        wait_count=0
        while(True and wait_count<9000):
Esempio n. 4
0
        platform_filter = "device_platform_name NOT_CONTAINS Win"

    server_filter = Filter()
    print opts.filter
    server_filter.expression = "(%s)&(%s)" % (opts.filter, platform_filter)
    print server_filter.expression
    server_refs = server_service.findServerRefs(server_filter)

    server_array = []
    for srv in server_refs:
        server_array.append(srv)
    filtered_refs = auth_service.filterSingleTypeResourceList(
        OperationConstants.EXECUTE_SERVER_SCRIPT, server_array)
    ssja = ServerScriptJobArgs()
    ssja.targets = filtered_refs
    ssja.timeOut = 3600
    if opts.args:
        ssja.parameters = opts.args
    if opts.runas_user and opts.runas_pwd and opts.runas_domain:
        ssja.username = opts.runas_user
        ssja.password = opts.runas_pwd
        ssja.loginDomain = opts.runas_domain
    if int(opts.debug) != 1:
        job_ref = server_script_service.startServerScript(
            script_ref, ssja, 'Script from pytwist',
            default_notify(opts.email), None)
        print job_ref
    else:
        print filtered_refs

    if int(opts.debug) != 1: