def check(indent="", shellError=False): print indent + "checking OpenVZ element type..." indent += "\t" try: id = checkCreate(indent=indent) id1 = checkCreateInterface(id, indent=indent) checkAction(id, "prepare", assertState="prepared", indent=indent) id2 = checkCreateInterface(id, indent=indent) print indent + "checking attribute changes in state prepared..." element_modify(id, {"ram": 128, "diskspace": 10000, "template": None}) checkAction(id, "start", assertState="started", indent=indent) print indent + "checking VNC server..." info = element_info(id) assert "attrs" in info and "vncport" in info["attrs"] assert lib.tcpPortOpen(__hostname__, info["attrs"]["vncport"]), "VNC Port not open" print indent + "checking execute..." res = element_action(id, "execute", {"cmd":"whoami"}) assert res.strip() == "root", "Result of whoami was %s" % res print indent + "checking attribute changes in state started..." element_modify(id1, {"ip4address": "10.0.0.1/24", "ip6address": "fdb2:a935:f0f5:b82b::1/64"}) element_modify(id, {"rootpassword": "******", "hostname": "test", "gateway4": "10.0.0.254", "gateway6": "fdb2:a935:f0f5:b82b::ffff"}) element_modify(id1, {"use_dhcp": True}) checkAction(id, "stop", assertState="prepared", indent=indent) print indent + "checking disk download and upload..." fileserver_port = host_info()["fileserver_port"] assert fileserver_port grant = element_action(id, "download_grant") assert grant lib.download("http://%s:%d/%s/download" % (__hostname__, fileserver_port, grant), "disk.tar.gz") assert os.path.exists("disk.tar.gz") grant = element_action(id, "upload_grant") assert grant lib.upload("http://%s:%d/%s/upload" % (__hostname__, fileserver_port, grant), "disk.tar.gz") element_action(id, "upload_use") checkRemove(id1, indent=indent) checkAction(id, "destroy", assertState="created", indent=indent) checkRemove(id, indent=indent) except: import traceback traceback.print_exc() if shellError: shell() finally: if os.path.exists("disk.tar.gz"): os.remove("disk.tar.gz") tearDown(id, indent)
def query_packageinfo(conn,template,tech,packages): res=None #first, create the rextfv archive which will fetch the package info print 'creating query archive...' f1=create_query_archive({ 'paclist':packages, 'mode':'get_urls' }) #create the fetcher topology t = packetman_urlgetter(conn) try: print 'creating topology' err = t.create_target_topology(tech,template) if not err['success']: print 'Error: '+err['message'] return top = t.get_target()['topology'] el = t.get_target()['element'] #prepare topology print 'preparing topology' t.topology_action('prepare') #upload query archive print 'uploading query archive' grant = t.element_action('rextfv_upload_grant') with open(f1,"r") as file: lib.upload(get_upload_url(conn,el,grant),file) #start topology, wait for rextfv to finish print 'starting topology' t.topology_action('start') print 'waiting for query archive to finish' elinfo = conn.element_info(el) sleepdelay=1 while not (elinfo['attrs']['rextfv_run_status']['readable'] and elinfo['attrs']['rextfv_run_status']['done']): time.sleep(sleepdelay) sleepdelay += 1 elinfo = conn.element_info(el) #download and read result ---- TODO: if this becomes easier by better rextfv integration of json into rextfv_run_status, use this way instead print 'downloading query result' wdir = get_workingdir() targetfile = os.path.join(wdir,'res.tar.gz') grant = t.element_action('rextfv_download_grant') with open(targetfile,'w+') as file: lib.download(get_download_url(conn,el,grant),file) with tarfile.open(targetfile,'r:gz') as tar: tar.extractall(wdir) with open(os.path.join(wdir,'result.json','r')) as f: res = json.load(f) finally: t.clean_up() return res
def check(indent="", shellError=False): print indent + "checking KVMQM element type..." indent += "\t" try: id = checkCreate(indent=indent) id1 = checkCreateInterface(id, indent=indent) checkAction(id, "prepare", assertState="prepared", indent=indent) id2 = checkCreateInterface(id, indent=indent) print indent + "checking attribute changes in state prepared..." element_modify(id, {"cpus": 2, "ram": 128, "usbtablet": False, "kblang": "de", "template": None}) checkAction(id, "start", assertState="started", indent=indent) print indent + "checking VNC server..." info = element_info(id) assert "attrs" in info and "vncport" in info["attrs"] assert lib.tcpPortOpen(__hostname__, info["attrs"]["vncport"]), "VNC Port not open" checkAction(id, "stop", assertState="prepared", indent=indent) print indent + "checking disk download and upload..." fileserver_port = host_info()["fileserver_port"] assert fileserver_port grant = element_action(id, "download_grant") assert grant lib.download("http://%s:%d/%s/download" % (__hostname__, fileserver_port, grant), "disk.qcow2") assert os.path.exists("disk.qcow2") grant = element_action(id, "upload_grant") assert grant lib.upload("http://%s:%d/%s/upload" % (__hostname__, fileserver_port, grant), "disk.qcow2") element_action(id, "upload_use") checkRemove(id1, indent=indent) checkAction(id, "destroy", assertState="created", indent=indent) checkRemove(id, indent=indent) except: import traceback traceback.print_exc() if shellError: shell() finally: if os.path.exists("disk.qcow2"): os.remove("disk.qcow2") tearDown(id, indent)
def check(indent="", shellError=False): print indent + "checking Repy element type..." indent += "\t" try: id = checkCreate(indent=indent) id1 = checkCreateInterface(id, indent=indent) id2 = checkCreateInterface(id, indent=indent) print indent + "checking attribute changes in state created..." element_modify(id, {"cpus": 0.5, "ram": 128, "bandwidth": 1000000, "args": ["id=1000"], "template": None}) checkAction(id, "start", assertState="started", indent=indent) print indent + "checking VNC server..." info = element_info(id) assert "attrs" in info and "vncport" in info["attrs"] assert lib.tcpPortOpen(__hostname__, info["attrs"]["vncport"]), "VNC Port not open" checkAction(id, "stop", assertState="prepared", indent=indent) print indent + "checking disk download and upload..." fileserver_port = host_info()["fileserver_port"] assert fileserver_port grant = element_action(id, "download_grant") assert grant lib.download("http://%s:%d/%s/download" % (__hostname__, fileserver_port, grant), "disk.repy") assert os.path.exists("disk.repy") grant = element_action(id, "upload_grant") assert grant lib.upload("http://%s:%d/%s/upload" % (__hostname__, fileserver_port, grant), "disk.repy") element_action(id, "upload_use") checkRemove(id1, indent=indent) checkRemove(id, indent=indent) except: import traceback traceback.print_exc() if shellError: shell() finally: if os.path.exists("disk.repy"): os.remove("disk.repy") tearDown(id, indent)
def uploadAndUseArchive(self,filename): elinfo=self.api.element_info(self.el_id) grant = self.api.element_action(self.el_id,"rextfv_upload_grant") upload_url = "http://%(hostname)s:%(port)s/%(grant)s/upload" % {"hostname":elinfo['attrs']['host_info']["address"], "port":elinfo['attrs']['host_info']["fileserver_port"], "grant":grant } upload(upload_url,filename) self.api.element_action(self.el_id,"rextfv_upload_use")
def query_packageinfo(conn,template,tech,packages,site): res=None #first, create the rextfv archive which will fetch the package info print 'creating query archive' f1=create_query_archive(packages) #create the fetcher topology t = packetman_urlgetter(conn) try: print 'creating topology' err = t.create_target_topology(tech,template,site) if not err['success']: print 'Error: '+err['message'] return top = t.get_target()['topology'] el = t.get_target()['element'] #prepare topology print 'preparing topology' t.topology_action('prepare') #upload query archive print 'uploading query archive' grant = t.element_action('rextfv_upload_grant') #with open(f1,"r") as file: lib.upload(get_upload_url(conn,el,grant),f1) print 'using upload' t.element_action('rextfv_upload_use') #start topology, wait for rextfv to finish print 'starting topology' t.topology_action('start') print 'waiting for query archive to finish' elinfo = conn.element_info(el) sleepdelay=1 while not (elinfo['attrs']['rextfv_run_status']['readable'] and elinfo['attrs']['rextfv_run_status']['done']): time.sleep(sleepdelay) sleepdelay += 1 elinfo = conn.element_info(el) #download and read result ---- TODO: if this becomes easier by better rextfv integration of json into rextfv_run_status, use this way instead print 'fetching query result' wdir = get_workingdir() targetfile = os.path.join(wdir,'res.tar.gz') grant = t.element_action('rextfv_download_grant') custominfo_splitted = elinfo['attrs']['rextfv_run_status']['custom'].split(".",2) ident = custominfo_splitted[0] os_id = custominfo_splitted[1] lines = custominfo_splitted[2] def interpret_lines_aptget(lines_string): lines = lines_string.splitlines() urlList = [] order = [] for line in lines: l = line.split() urlList.append(l[0]) order.append(l[1]) return { 'urls':urlList, 'order':order} if ident == "aptget": res = interpret_lines_aptget(lines) res['os_id'] = os_id finally: t.clean_up() return res
def main(args): #handle the argument passed on the command line parser = argparse.ArgumentParser( description='FTP client for download and upload') parser.add_argument('-f', '--name', type=str, nargs='+', help="file_name") parser.add_argument('-s', '--server', default="speedtest.tele2.net", type=str, help='host_server') parser.add_argument('-o', '--output', default='Downloads', type=str, help="destination") parser.add_argument('-d', '--down', action='store_true', help="download mode") parser.add_argument('-u', '--upload', action='store_true', help="upload mode") parser.add_argument('-l', '--listing', action='store_true', help="listing files") args = parser.parse_args() # create an ftp object ftp = ftplib.FTP(args.server) #login with anonymous mode ftp.login() #get files in the download directory files = ftp.nlst(d_path) #printing files in the download directory if args.listing: print "Listing Files:" for f in files: print f #download mode if args.down: files = ftp.nlst(d_path) for f in args.name: #check if the file exist in the download directory if d_path + f in files: lib.download(f, ftp, args.output, d_path) else: print f + " doesn't exist " print "use python -B ftp_client -l to list files" #upload mode if args.upload: for f in args.name: #extract the file name from the path, #in anonymous mode the server prevent creating directories in upload just files f = ntpath.basename(f) lib.upload(f, ftp, u_path) #close the ftp connection object ftp.quit()