Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def init():
    try:
        prlsdkapi.init_server_sdk()
        server = prlsdkapi.Server()
        server.login_local().wait()
        return server
    except RuntimeError, e:
        print(str(e))
        exit(-1)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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"
Ejemplo n.º 8
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.
Ejemplo n.º 9
0
def init():
	if not prl.is_sdk_initialized():
		prl.init_server_sdk()
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
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.
Ejemplo n.º 12
0
 def __enter__(self):
     prlsdkapi.init_server_sdk()
Ejemplo n.º 13
0
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