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 download(*args, **kwargs): return lib.download(*args, **dict(kwargs, agent=AGENT))
def check(indent="", shellError=False): print indent + "checking Bridge connection type..." indent += "\t" try: print indent+"creating two openvz devices with one interface each..." dev0 = element_create("openvz")["id"] print indent+"\tID: %d" % dev0 eth0 = element_create("openvz_interface", dev0, {"use_dhcp": False, "ip4address": "10.0.0.1/24"})["id"] print indent+"\tID: %d" % eth0 dev1 = element_create("openvz")["id"] print indent+"\tID: %d" % dev1 eth1 = element_create("openvz_interface", dev1, {"use_dhcp": False, "ip4address": "10.0.0.2/24"})["id"] print indent+"\tID: %d" % eth1 print indent+"creating bridge between interfaces..." id = checkCreate(eth0, eth1, indent=indent) print indent+"starting openvz devices..." element_action(dev0, "prepare") element_action(dev1, "prepare") element_action(dev0, "start") element_action(dev1, "start") print indent+"starting bridge..." checkAction(id, "start", assertState="started", indent=indent) print indent+"checking connectivity..." time.sleep(5) element_action(dev0, "execute", {"cmd": "ping -I eth0 -A -c 10 -n -q 10.0.0.2"}) print indent+"changing link emulation values..." connection_modify(id, {"emulation": True, "delay_to": 5.0, "delay_from": 2.0, "jitter_to": 0.0, "jitter_from": 0.0, "distribution_to": "uniform", "distribution_from": "uniform", "bandwidth_to": 10000, "bandwidth_from": 10000, "lossratio_to": 0.0, "lossratio_from": 0.0, "duplicate_to": 0.0, "duplicate_from": 0.0, "corrupt_to": 0.0, "corrupt_from": 0.0}) print indent+"checking connectivity..." element_action(dev0, "execute", {"cmd": "ping -I eth0 -A -c 10 -n -q 10.0.0.2"}) print indent+"checking file capture..." connection_modify(id, {"capturing": True, "capture_mode": "file", "capture_filter": "icmp"}) element_action(dev0, "execute", {"cmd": "ping -I eth0 -A -c 10 -n -q 10.0.0.2"}) print indent+"checking capture download..." fileserver_port = host_info()["fileserver_port"] assert fileserver_port grant = connection_action(id, "download_grant") assert grant lib.download("http://%s:%d/%s/download" % (__hostname__, fileserver_port, grant), "capture.pcap") assert os.path.exists("capture.pcap") print indent+"checking live capture..." connection_modify(id, {"capture_mode": "net"}) info = connection_info(id) assert "attrs" in info and "capture_port" in info["attrs"] assert lib.tcpPortOpen(__hostname__, info["attrs"]["capture_port"]), "Capture port not open" print indent+"stopping bridge..." checkAction(id, "stop", assertState="created", indent=indent) print indent+"removing bridge..." checkRemove(id, indent=indent) print indent+"tearing down openvz devices..." openvzTearDown(dev0, indent=indent) openvzTearDown(dev1, indent=indent) except: import traceback traceback.print_exc() if shellError: shell() finally: if os.path.exists("capture.pcap"): os.remove("capture.pcap") tearDown(id, indent) openvzTearDown(dev0, indent=indent) openvzTearDown(dev1, indent=indent)
def check(indent="", shellError=False): print indent + "checking Bridge connection type..." indent += "\t" try: print indent + "creating two openvz devices with one interface each..." dev0 = element_create("openvz")["id"] print indent + "\tID: %d" % dev0 eth0 = element_create("openvz_interface", dev0, { "use_dhcp": False, "ip4address": "10.0.0.1/24" })["id"] print indent + "\tID: %d" % eth0 dev1 = element_create("openvz")["id"] print indent + "\tID: %d" % dev1 eth1 = element_create("openvz_interface", dev1, { "use_dhcp": False, "ip4address": "10.0.0.2/24" })["id"] print indent + "\tID: %d" % eth1 print indent + "creating bridge between interfaces..." id = checkCreate(eth0, eth1, indent=indent) print indent + "starting openvz devices..." element_action(dev0, "prepare") element_action(dev1, "prepare") element_action(dev0, "start") element_action(dev1, "start") print indent + "starting bridge..." checkAction(id, "start", assertState="started", indent=indent) print indent + "checking connectivity..." time.sleep(5) element_action(dev0, "execute", {"cmd": "ping -I eth0 -A -c 10 -n -q 10.0.0.2"}) print indent + "changing link emulation values..." connection_modify( id, { "emulation": True, "delay_to": 5.0, "delay_from": 2.0, "jitter_to": 0.0, "jitter_from": 0.0, "distribution_to": "uniform", "distribution_from": "uniform", "bandwidth_to": 10000, "bandwidth_from": 10000, "lossratio_to": 0.0, "lossratio_from": 0.0, "duplicate_to": 0.0, "duplicate_from": 0.0, "corrupt_to": 0.0, "corrupt_from": 0.0 }) print indent + "checking connectivity..." element_action(dev0, "execute", {"cmd": "ping -I eth0 -A -c 10 -n -q 10.0.0.2"}) print indent + "checking file capture..." connection_modify(id, { "capturing": True, "capture_mode": "file", "capture_filter": "icmp" }) element_action(dev0, "execute", {"cmd": "ping -I eth0 -A -c 10 -n -q 10.0.0.2"}) print indent + "checking capture download..." fileserver_port = host_info()["fileserver_port"] assert fileserver_port grant = connection_action(id, "download_grant") assert grant lib.download( "http://%s:%d/%s/download" % (__hostname__, fileserver_port, grant), "capture.pcap") assert os.path.exists("capture.pcap") print indent + "checking live capture..." connection_modify(id, {"capture_mode": "net"}) info = connection_info(id) assert "attrs" in info and "capture_port" in info["attrs"] assert lib.tcpPortOpen( __hostname__, info["attrs"]["capture_port"]), "Capture port not open" print indent + "stopping bridge..." checkAction(id, "stop", assertState="created", indent=indent) print indent + "removing bridge..." checkRemove(id, indent=indent) print indent + "tearing down openvz devices..." openvzTearDown(dev0, indent=indent) openvzTearDown(dev1, indent=indent) except: import traceback traceback.print_exc() if shellError: shell() finally: if os.path.exists("capture.pcap"): os.remove("capture.pcap") tearDown(id, indent) openvzTearDown(dev0, indent=indent) openvzTearDown(dev1, indent=indent)
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()