def main(target): prlsdkapi.init_server_sdk() distant = prlsdkapi.Server() distant.login("10.30.25.115", "root", "1q2w3e").wait() local = prlsdkapi.Server() local.login("127.0.0.1", "root", "1q2w3e").wait() # PVMT_SWITCH_TEMPLATE : applable just in clone mode - lets to clone remotely VM to template # PVMT_CHANGE_SID : for Windows VMs/containers lets to change SID after remote clone # PVMT_CLONE_MODE : preserves source VM flags = consts.PVMT_SWITCH_TEMPLATE | consts.PVMT_CHANGE_SID | consts.PVMT_CLONE_MODE #for vm in local.get_vm_list_ex(consts.PVTF_VM).wait(): for vm in distant.get_vm_list_ex(consts.PVTF_VM).wait(): if vm.get_name() != target: continue #job = vm.migrate(distant, "", flags) job = vm.migrate(local, "", flags) mthread = Migrate(job) mthread.start() # lthread = Listen(job) # lthread.start() mthread.join() # lthread.join() print "Finished!" break
def __init__(self): prlsdkapi.init_desktop_sdk() self.server = prlsdkapi.Server() result = self.server.login_local('', 0, consts.PSL_NORMAL_SECURITY).wait() login_response = result.get_param() self.current_path = os.path.dirname(os.path.abspath(__file__)) self.vmlist = [] self.runningVm = [] file_path = os.path.join(self.current_path + "/vmlist") if not os.path.exists(file_path): print("file path not exist", file_path) raise if not os.path.isfile(file_path): print("file not exist", file_path) raise with open("vmlist", "r") as f: for line in f: self.vmlist.append(line.strip())
def init(): try: prlsdkapi.init_server_sdk() server = prlsdkapi.Server() server.login_local().wait() return server except RuntimeError, e: print(str(e)) exit(-1)
def __enter__(self): self.server = prlsdkapi.Server() if self.host == "localhost": try: # The call returns a prlsdkapi.Result object on success. result = self.server.login_local('', 0, self.security_level).wait() except prlsdkapi.PrlSDKError, e: print "Login error: %s" % e raise Halt
def test_CreateImage(): res = 1 # return value # First we need to connect to the server server = prlsdkapi.Server() job = server.login_local() job.wait(max_wait_timeout) vm = server.create_vm() # raw_input ("press any key") vm.set_uuid(CommonTestsUtils.gen_random_guid()) vm.set_name("createImage_" + vm.get_uuid()[:20]) job = vm.reg('') job.wait(max_wait_timeout) try: try: job = vm.begin_edit() job.wait(max_wait_timeout) # raw_input ("press any key") image_path = vm.get_home_path() image_path = os.path.dirname(image_path) + "/image.hdd" # create image dev = vm.create_vm_dev(prlsdkapi.consts.PDE_HARD_DISK) dev.set_image_path(image_path) dev.set_sys_name(image_path) dev.set_disk_size(20) job = dev.create_image(0) job.wait(max_wait_timeout) job = vm.commit() job.wait(max_wait_timeout) # raw_input ("press any key") finally: # print "vm name = %s" % vm.get_name() job = vm.delete() job.wait(max_wait_timeout) except: res = 2 try: # test to server crashes ( if crashes - logoff was failed ) job = server.logoff() job.wait(max_wait_timeout) finally: res = 0 return res
def migrate(ct): slave = prlsdkapi.Server() login_server(slave, host_slicer(dest_node)[2], host_slicer(dest_node)[0], host_slicer(dest_node)[1], consts.PSL_NORMAL_SECURITY) try: ct.migrate(slave).wait() except: pass
def main(): prlsdkapi.init_server_sdk() local = prlsdkapi.Server() local.login("127.0.0.1", "root", "1q2w3e").wait() targets = [] names = [ "ssVM_1", "ssVM_2", "ssVM_3", "ssVM_4", "ssVM_5", "ssVM_6", "Ubuntu" ] for vm in local.get_vm_list_ex(consts.PVTF_VM).wait(): if not vm.get_name() in names: continue targets.append(vm) print "Got %s" % vm.get_name() if not targets or len(targets) != len(names): print "Failed to find all needed Vms!" return try: cthread1 = Configure(1, targets[0]) cthread2 = Configure(2, targets[1]) cthread3 = Report(3, targets[2]) cthread4 = Configure(4, targets[3]) cthread5 = Configure(5, targets[4]) cthread6 = Report(6, targets[5]) cthread7 = Dump(6, targets[6]) cthread1.start() cthread2.start() cthread3.start() cthread4.start() cthread5.start() cthread6.start() cthread7.start() cthread1.join() cthread2.join() cthread3.join() cthread4.join() cthread5.join() cthread6.join() cthread7.join() except prlsdkapi.PrlSDKError, e: print "Exception caught! Error: %s" % e return
def api_vm_change_description(HOST, USER, PASSW, VM, DESCRIPTION): prlsdkapi.init_server_sdk() server = prlsdkapi.Server() server.login(HOST, USER, PASSW, '', 0, 0, consts.PSL_NORMAL_SECURITY).wait() vm = api_get_vm(server, VM) vm.begin_edit().wait() vm.set_description(DESCRIPTION.encode("utf_8")) vm.commit().wait() server.logoff() prlsdkapi.deinit_sdk()
def api_get_vm_desc(HOST, USER, PASSW, VM): prlsdkapi.init_server_sdk() server = prlsdkapi.Server() server.login(HOST, USER, PASSW, '', 0, 0, consts.PSL_NORMAL_SECURITY).wait() vm = api_get_vm(server, VM) vm_config = vm.get_config() st = str(vm_config.get_description()) server.logoff() prlsdkapi.deinit_sdk() return st
def main(name): prlsdkapi.init_server_sdk() local = prlsdkapi.Server() local.login("127.0.0.1", "root", "1q2w3e").wait() target = None for vm in local.get_vm_list_ex(consts.PVTF_VM).wait(): if vm.get_name() != name: continue target = vm break if not target: print "Failed to find Vm named %s" % name return try: #config = target.get_config() target.start().wait() time.sleep(10) #cmd = "prlctl internal {%s} dbgdump --name mem.dmp" % config.get_uuid() print "Dump" cmd = "prlctl internal {7cdda423-0868-4d1e-a81b-1790efce5508} dbgdump --name mem.dmp" os.system(cmd) print "Suspend" target.suspend().wait() time.sleep(10) print "Resume" target.resume().wait() time.sleep(10) target.stop().wait() except prlsdkapi.PrlSDKError, e: print "Error: %s" % e return
def __init__(self): self.current_path = os.getcwd() path = sys.argv[0] self.current_path = "/".join(path.split("/")[:-1]) + "/" self.vmlist = [] self.runningVm = [] self.log = [] prlsdkapi.init_desktop_sdk() print(prlsdkapi.is_sdk_initialized()) self.server = prlsdkapi.Server() result = self.server.login_local('', 0, consts.PSL_NORMAL_SECURITY).wait() login_response = result.get_param() product_version = login_response.get_product_version() print("product_version:", product_version) host_os_version = login_response.get_host_os_version() print("host_os_version:", host_os_version) host_uuid = login_response.get_server_uuid() print("host_uuid:", host_uuid) result = self.server.get_srv_config().wait() srv_config = result.get_param() file_path = os.path.join(self.current_path + "/vmlist") if not os.path.exists(file_path): print("file path not exist", file_path) raise if not os.path.isfile(file_path): print("file not exist", file_path) raise with open(file_path, "r") as f: for line in f: self.vmlist.append(line.strip())
def main(target): prlsdkapi.init_server_sdk() local = prlsdkapi.Server() # local.login("127.0.0.1", "root", "1q2w3e").wait() job = local.login("127.0.0.1", "root", "1q2w3e") if job.get_status() == consts.PJS_FINISHED: print "Finished" job = local.create_vm_backup(target, force_operation = True, \ reserved_flags = 0, nTargetPort = 0, strDescription = "", \ sTargetHost = "localhost", backup_flags = 2048, sTargetSessionId = "") time.sleep(2) # while (job.get_status() == consts.PJS_RUNNING): # print "Running" if job.get_status() == consts.PJS_FINISHED: print "Finished"
def main(self): ret = 0 methods = [ 'Test_GetLicenseInfo_Basic', 'Test_bugs3115_2511_CantRecreateImage' # 'Test_GetLicenseInfo_Basic' ] for func_name in methods: # print 'func name = [%s]' % func_name func = getattr(self, func_name) try: server = prlsdkapi.Server() job = server.login_local() job.wait(max_wait_timeout) fret = 1 try: fret = func(server) except Exception, e: print 'some error catched: error e=%s' % e if 0 == fret: print 'PASSED [ %s ]' % func_name else: print 'FAILED! [ %s ]' % func_name ret += 1 # raw_input ("press any key") job = server.logoff() job.wait(max_wait_timeout) except Exception, e: print 'some error catched: error e=%s' % e ret += 1
def test(vm_type): res = 1 # return value new_vm_uuid = CommonTestsUtils.gen_random_guid() # First we need to connect to the server server = prlsdkapi.Server() job = server.login_local() job.wait( max_wait_timeout ) # 0. Create cache in advance in order to avoid timeouts later during actual test if vm_type == prlsdkapi.consts.PVT_CT: create_default_cache(server) # 1. Create VM vm = server.create_vm() vm.refresh_config() vm.set_vm_type( vm_type ) vm.set_uuid ( new_vm_uuid ) vm.set_name ( "reg" + vm_type_str[vm_type] + "_" + vm.get_uuid().strip('{}')[:20] ) print "Create " + vm_type_str[vm_type] + " done."
def test(): res = 1 # return value i = 0; try: while i< 1000: if i%20 == 0: print "%d " % i if i%200 == 0: print "\n" i += 1 srv = prlsdkapi.Server() job = srv.login_local( ) job.wait( max_wait_timeout ) job = srv.get_vm_list() job.wait( max_wait_timeout ) except prlsdkapi.PrlSDKError, e: print 'error caught! count = %d' % i print e
# Release or press state = sys.argv[3] print "Sending keyname '%(keyname)s' to VM '%(vm_name)s'" % { "keyname": keyname, "vm_name": vm_name } prlsdk = prlsdkapi.prlsdk consts = prlsdkapi.prlsdk.consts # Initialize the Parallels API Library prlsdk.InitializeSDK(consts.PAM_DESKTOP_MAC) # Obtain a server object identifying the Parallels Service. server = prlsdkapi.Server() # Log in. (local as we do Parallels Desktop login_job = server.login_local() login_job.wait() # Get a list of virtual machines. # Find the specified virtual machine and # obtain an object identifying it. vm_list = server.get_vm_list() result = vm_list.wait() print prlsdkapi.prlsdk.consts.ScanCodesList # Look for the VM with the name speficied on the CLI found = False
Actions.SWITCH: { "action": switch_to_snapshot, "command": "--switch" }, Actions.REMOVE: { "action": remove_snapshot, "command": "--remove" }, Actions.TREE: snapshot_tree, } if (actions.get(action) is None): raise NotImplementedError("action %s is not implemented" % str(action)) init() server = prl.Server() server.login_local().wait() vm_list = server.get_vm_list_ex(prl.consts.PVTF_VM | prl.consts.PVTF_CT).wait() if action == Actions.TREE: vm_list_filtered = filter(filter_by_query(query), vm_list) snapshot_tree(vm_list_filtered) exit(0) if perform: vm_list_filtered = filter(filter_by_query(query), vm_list) actions[action]["action"](vm_list_filtered, tag) else: vm_list_filtered = filter(filter_by_query(query), vm_list) vm_full_names = [vm.get_name() for vm in vm_list_filtered] command = actions[action]["command"]
import sys import prlsdkapi import prlsdkapi.prlsdk.consts as consts prlsdkapi.init_server_sdk() local = prlsdkapi.Server() local.login("127.0.0.1", "root", "1q2w3eQAZ").wait() # sys.argv[1] - VM name. # sys.argv[2] - new hdd size. target = None for i in local.get_vm_list_ex(consts.PVTF_VM).wait(): if i.get_name() != sys.argv[1]: continue target = i break target.lock(0) target.begin_edit() cfg = target.get_config() hdd0 = cfg.get_dev_by_type(consts.PDE_HARD_DISK, 0) hdd0.resize_image(int(sys.argv[2]), consts.PACF_NON_INTERACTIVE_MODE).wait() target.commit_ex(consts.PVCF_WAIT_FOR_APPLY).wait() target.unlock(0)
def main(): logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', filename="checklist.log", filemode='w', level=logging.DEBUG) prlsdkapi.init_server_sdk() # Initialize the library. server = prlsdkapi.Server() # Create a Server object login_server(server, host_slicer(source_node)[2], host_slicer(source_node)[0], host_slicer(source_node)[1], consts.PSL_NORMAL_SECURITY) # get_vm_list(server) print bcolors.HEADER + '\nCreating containers...' + bcolors.ENDC for r in xrange(1, 5): create_ct(server) logging.debug(CT) print bcolors.HEADER + '\nCreating content...' + bcolors.ENDC create_bigfile() print bcolors.OKGREEN + 'Done.' + bcolors.ENDC logging.debug('[VE] %s' % CT_MD5_list.items()) #create snapshot CT#2 # print bcolors.HEADER + '\nTaking snapshot' + bcolors.ENDC # try: # CT[CT.keys()[1]].create_snapshot('testfile') # print bcolors.OKGREEN + "Snapshot created" + bcolors.ENDC # logging.info('Snapshot for CT %s created' %CT.keys()[1]) # except: # print bcolors.FAIL + "Snapshot creation failure" + bcolors.ENDC # logging.error('Snapshot creation for CT %s FAILED' %CT.keys()[1]) print '\nBase checks:' scope1(CT[CT.keys()[0]]) print '' print bcolors.HEADER + '\nCreate CLONE and check MD5 for test content...' + bcolors.ENDC clone(CT[CT.keys()[2]]) if dest_node != "": print bcolors.HEADER + "\nMigrating..." + bcolors.ENDC try: migrate(CT[CT.keys()[3]]) print bcolors.OKGREEN + 'Migrated, let\'s check MD5 inside..' + bcolors.ENDC logging.info('CT %s migrated' % CT.keys()[3]) #raw_input() mig_md5_check(CT.keys()[3]) except: print bcolors.FAIL + "Migration FAILED" + bcolors.ENDC else: print bcolors.BOLD + '\nNo slave node provided, migration test skiped' + bcolors.ENDC # print CT[CT.keys()[1]].get_uuid() # job=CT[CT.keys()[1]].get_snapshots_tree() # job.wait() # result=job.get_result() # print CT.keys()[1] # print result.get_param_as_string() cleanup() server.logoff() #log off prlsdkapi.deinit_sdk() # deinitialize the library.
def main(): COGREEN = '\33[92m' ENDC = '\33[0m' usage = ''' prlsearch [-H] [HOST] [options] -H, --host Default is localhost -n, --vmname=NAME Name of virtual machine -s, --state running, stopped, paused, suspened -m, --memsize="<|>|==|<=|>=NUMBER" Memory of VM (MB) -c, --cpucount="<|>|==|<=|>=NUMBER" Amount cpu of VM -e, --exec Excute prlctl command Example: - Find all VM with start name test prlsearch --vmname *test - Find all VM have memory less than 512MB prlsearch --memsize "<512" - Find all VM is running prlsearch --state running - Find all VM is running and stop them. prlsearch --state stopped --exec "prlctl stop %s" ''' # get arg parser = optparse.OptionParser(usage=usage, version="%prog 1.0 beta") parser.add_option('-H', '--host', dest="host", default="localhost", type="str") parser.add_option('-n', '--vmname', dest="name", default="", type="str") parser.add_option('-s', '--state', dest="status", default="", type="str") parser.add_option('-m', '--memsize', dest="memsize", default="", type="str") parser.add_option('-c', '--cpucount', dest="cpucount", default="", type="str") parser.add_option('-e', '--exec', dest="cmd", default='', type="str") options, remainder = parser.parse_args() host = options.host name = options.name status = options.status memsize = options.memsize cpucount = options.cpucount cmd = options.cmd # validation argv match_host = fnmatch.fnmatch(host, "*:*:*") if not match_host and host != "localhost": print usage sys.exit(0) match_memsize = re.match(r'(>|==|<|<=|>=)(\d+\Z)', memsize) if not match_memsize and not memsize is "": print usage sys.exit(0) match_cpu = re.match(r'(>|==|<|<=|>=)(\d+\Z)', cpucount) if not match_cpu and not cpucount is "": print usage sys.exit(0) match_cmd = re.match(r'^prlctl\s\w*\s%s', cmd) if not match_cmd and not cmd is '': print usage sys.exit(0) # END prlsdkapi.init_server_sdk() server = prlsdkapi.Server() if host == "localhost": login = server.login_local('', 0, consts.PSL_NORMAL_SECURITY) else: host, user, passwd = host.split(':') login = server.login(host, user, passwd, '', 0, 0, consts.PSL_NORMAL_SECURITY).wait() result = search_vm(server, name, status, memsize, cpucount) if result: for item in result: try: if cmd is '': print "%10s | %15s | %5s | %4d | %d" % ( item[0], item[1], item[2], item[3], item[4]) else: cmd_exec = cmd % item[0] print COGREEN + cmd_exec + ENDC print '----------------------------------------------------------' os.system(cmd_exec) print '----------------------------------------------------------' except Exception, e: print "[-]Error: %s" % e
def bug115494(self): ''' bug: https://bugzilla.sw.ru/show_bug.cgi?id=115494 After connect/disconnect device device info doesn't store in config.pvs ''' curr_dir = os.path.dirname(os.path.abspath(__file__)) # print "curr_dir=%s, file=%s" % (curr_dir, __file__ ) iso_path_1 = os.path.join(curr_dir, "1.iso") iso_path_2 = os.path.join(curr_dir, "2.iso") s = prlsdkapi.Server() s.login_local().wait() # create vm vm = s.create_vm() vm.set_default_config(s.server_config, prlsdkapi.consts.PVS_GUEST_VER_LIN_REDHAT, False) vm.name = str(uuid.uuid1()) vm.reg("", True).wait() # create auto deletter auto_rm = VmAutoRemover(vm) # create device dev_type = prlsdkapi.consts.PDE_OPTICAL_DISK vm.begin_edit() # .wait() dev = vm.create_device(dev_type) dev.image_path = iso_path_1 dev.sys_name = dev.image_path dev.enabled = True dev.connected = False vm.commit().wait() dev_index = dev.index # start vm vm.start().wait() # MAJOR point 1: check that 'connected' state stored dev.connect().wait() vm.refresh_config().wait() ## find device dev = vm.get_device(dev_type, dev_index) if dev.connected != True: raise Exception, "Device connected state not stored!" # MAJOR point 1 end. # MAJOR point 2: check that connect/disconnect store all parameters dev.disconnect().wait() dev.image_path = iso_path_2 dev.sys_name = dev.image_path dev.connect().wait() vm.refresh_config().wait() ## find device dev = vm.get_device(dev_type, dev_index) if dev.connected != True: raise Exception, "Step2: Device connected state not stored!" if dev.sys_name != iso_path_2: raise Exception, "Step2: Device sys_name not stored!"
import time import prlsdkapi import prlsdkapi.prlsdk.consts as consts prlsdkapi.init_server_sdk() srv = prlsdkapi.Server() job = srv.login("127.0.0.1", "root", "1q2w3e") if job.get_status() == consts.PJS_RUNNING: print "Running" time.sleep(2) if job.get_status() == consts.PJS_FINISHED: print "Finished"