def check_status(vos_ret,config,config_name,config_id): if vos_ret.status_code == 200: vos.log_write("INFO","%s %s ID: %s Created Successfully" %(config,config_name,config_id),log_file) vos.log_write("INFO","\n %s \n" %vos_ret.text,log_file) else: vos.log_write("ERROR","%s %s failed to create... ABORTING SCRIPT !!!" %(config,config_name) ,log_file) vos.log_write("ERROR","\n %s \n" %vos_ret,log_file) vos.log_write("ERROR","\n %s \n" %vos_ret.text,log_file) sys.exit(2)
def main(argv): parser = argparse.ArgumentParser(description='***VOS Cloud Helper***', epilog = 'Usage example:\n'+sys.argv[0]+' --cloud_url=https://hkvpurple-01.nebula.video --cloud_username=USERNAME', formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--cloud_url', dest='cloud_url', action='store', help='Cloud url', required=True) parser.add_argument('--service', dest='service', action='store_true', help='Delete Service', required=False) parser.add_argument('--destination', dest='destination', action='store_true', help='Delete Destination', required=False) parser.add_argument('--source', dest='source', action='store_true', help='Delete Source', required=False) parser.add_argument('--all', dest='all', action='store_true', help='Delete All', required=False) parser.add_argument('--id', dest='id', action='store', help='Delete by ID', required=False) args = parser.parse_args() if not args.service and not args.source and not args.destination: print "Please enter an option for Deletion. --service or --destination or --source" sys.exit(2) if not args.all and not args.id: print "You need to specify either --all or --id option" sys.exit(2) if args.all and args.id: print "You need to specify either --all or --id option" sys.exit(2) vos_session = vos.vos_get_session() vosrt = args.cloud_url # Delete Services if args.service: if args.source or args.destination: print "You can only pick one Option for Deletion ! Pick either --source or --service or --destination" sys.exit(2) #Delete all Services on RT if args.all: if not continue_check("ALL SERVICES",vosrt): sys.exit(2) servs = vos.vos_get_service_all(vosrt,vos_session) for serv in servs.json(): vos.log_write("INFO","Deleting Service %s ID: %s" %(serv['name'],serv['id']),log_file) vos_ret = vos.vos_service_delete(serv['id'],vosrt,vos_session) if vos_ret.status_code == 200: vos.log_write("INFO","\n%s" %json.dumps(serv),log_file) time.sleep(4) else: vos.log_write("ERROR","Failed to Delete Service %s. Error: %s - %s " %(serv['name'],vos_ret,vos_ret.text),log_file) # Delete Destinations if args.destination: if args.source or args.service: print "You can only pick one Option for Deletion ! Pick either --source or --service or --destination" sys.exit(2) #Delete all Destinations on RT if args.all: if not continue_check("ALL DESTINATIONS",vosrt): sys.exit(2) dests = vos.vos_get_destination_all(vosrt,vos_session) for dest in dests.json(): vos.log_write("INFO","Deleting Destination %s ID: %s" %(dest['name'],dest['id']),log_file) vos_ret = vos.vos_destination_delete(dest['id'],vosrt,vos_session) if vos_ret.status_code == 200: vos.log_write("INFO","\n%s" %json.dumps(dest),log_file) time.sleep(4) else: vos.log_write("ERROR","Failed to Delete Destination %s. Error: %s - %s " %(dest['name'],vos_ret,vos_ret.text),log_file) # Delete Sources if args.source: if args.destination or args.service: print "You can only pick one Option for Deletion ! Pick either --source or --service or --destination" sys.exit(2) #Delete all Sources on RT if args.all: if not continue_check("ALL SOURCES",vosrt): sys.exit(2) srcs = vos.vos_get_source_all(vosrt,vos_session) for src in srcs.json(): vos.log_write("INFO","Deleting Source %s ID: %s" %(src['name'],src['id']),log_file) vos_ret = vos.vos_source_delete(src['id'],vosrt,vos_session) if vos_ret.status_code == 200: vos.log_write("INFO","\n%s" %json.dumps(src),log_file) time.sleep(4) else: vos.log_write("ERROR","Failed to Delete Source %s. Error: %s - %s " %(src['name'],vos_ret,vos_ret.text),log_file)
for serv in vos_services.json(): # Test URLs for url_type in url_types: for mds in mds_nodes: urls = build_url(serv['name'], url_type, mds['nodeip']) for test_url in urls: print "Testing URL: %s" % test_url url_error = False for n in range(ntries): req = vos_session.get(test_url) if not req.status_code == 200: vos.log_write( 'ERROR', "CODE: %s - URL %s" % (str(req.status_code), test_url), log_file) url_error = True if not url_error: vos.log_write( 'INFO', "URL GOOD: %s - URL %s" % (str(req.status_code), test_url), log_file) nurls += 1 vos.log_write('INFO', "%s URLs TESTED" % (str(nurls)), log_file)
def main(argv): parser = argparse.ArgumentParser(description='***VOS User Backup/Restore***', epilog = 'Usage example:\n'+sys.argv[0]+' --cloud_url=https://hkvpurple-01.nebula.video --cloud_username=USERNAME', formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--cloud_url', dest='cloud_url', action='store', help='RT from where to export Configuration.', required=True) parser.add_argument('--user_file', dest='user_file', action='store', help='JSON File for Users', required=True) parser.add_argument('--backup', dest='backup', action='store_true', help='Backup Configuration', required=False) parser.add_argument('--restore', dest='restore', action='store_true', help='Restore Configuration', required=False) args = parser.parse_args() if args.backup and args.restore: print "Please use either --backup or --restore but not both :-)" sys.exit(2) #Creates VOS Requests Session. It will prompt for user and password. vos_session = vos.vos_get_session() vosrt = args.cloud_url # Backup Configuration if args.backup: #Backup Sources f_users = open(args.user_file,'w') vos_users = vos.vos_get_user_all(vosrt,vos_session) json.dump(vos_users.json(),f_users) f_users.close() #Restores Configuration if args.restore: #Checks if file exists if not os.path.isfile(args.user_file): print "File %s does not exist !!" %args.user_file sys.exit(2) #Restore Users with open(args.user_file) as user_data: usr_y = yaml.safe_load(user_data) for usr in usr_y: chk_usr = vos.vos_get_user_name(usr['username'],vosrt,vos_session) if not chk_usr.status_code == 200: param = json.dumps(usr) vos_ret = vos.vos_add_user(param,vosrt,vos_session) check_status(vos_ret,"User",usr['name'],usr['username']) else: vos.log_write("INFO","User %s already Exists !!!" %usr['username'],log_file)
def convert_single_prof(srv_file, sp_file, vosrt, vos_session): sp_trans = {} sp_origin = {} for sp in sp_file: spl = sp.strip().split(',') if "origin" in spl[0]: if "gmott" in spl[0]: sp_origin['gmott'] = spl[1] else: sp_origin['dfw'] = spl[1] else: if "480" in spl[0]: sp_trans['480'] = spl[1] elif "720" in spl[0]: sp_trans['720'] = spl[1] elif "1080" in spl[0]: sp_trans['1080'] = spl[1] print sp_trans print sp_origin for srv in srv_file: srv_name = srv.strip() srv_namesp = srv_name.split('.') srv_namesp.pop() srv_namesp = (".").join(srv_namesp) vos_serv = vos.vos_get_service_name(srv_name, vosrt, vos_session) if vos_serv.status_code == 200: serv_yaml = yaml.safe_load(vos_serv.text) serv_yaml[0]['name'] = srv_namesp if "480" in srv_namesp: serv_yaml[0]['profileId'] = sp_trans['480'] elif "720" in srv_namesp: serv_yaml[0]['profileId'] = sp_trans['720'] elif "1080" in srv_namesp: serv_yaml[0]['profileId'] = sp_trans['1080'] else: vos.log_write( "ERROR", "No Transcode Profile for Service %s Skipping service" % srv_name, log_file) continue param = json.dumps(serv_yaml[0]) vos_ret = vos.vos_mod_service(serv_yaml[0]['id'], param, vosrt, vos_session) if vos_ret.status_code == 200: vos.log_write( "INFO", "Service %s has been changed to %s" % (srv_name, vos_ret.json()['name']), log_file) vos.log_write("INFO", "\n %s \n" % vos_ret.text, log_file) else: vos.log_write( "ERROR", "Failed to Modify Service %s !!!! Fix Issue and Rerun Script." % srv_name, log_file) vos.log_write("ERROR", "\n %s \n" % vos_ret, log_file) vos.log_write("ERROR", "\n %s \n" % vos_ret.text, log_file) sys.exit(2)
def main(argv): parser = argparse.ArgumentParser( description='***VOS Service Migration***', epilog='Usage example:\n' + sys.argv[0] + ' --cloud_url=https://hkvpurple-01.nebula.video --cloud_username=USERNAME', formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--cloud_url', dest='cloud_url', action='store', help='RT from where to export Configuration.', required=False) parser.add_argument('--srv_file', dest='srv_file', action='store', help='JSON File for Services', required=False) parser.add_argument('--src_file', dest='src_file', action='store', help='JSON File for Sources', required=False) parser.add_argument('--dst_file', dest='dst_file', action='store', help='JSON File for Destinations', required=False) parser.add_argument('--img_file', dest='img_file', action='store', help='JSON File for Images', required=False) parser.add_argument('--drm_file', dest='drm_file', action='store', help='JSON File for DRM Systems/Settings', required=False) parser.add_argument('--backup', dest='backup', action='store_true', help='Backup Configuration', required=False) parser.add_argument('--restore', dest='restore', action='store_true', help='Restore Configuration', required=False) parser.add_argument('--srv_off', dest='srv_off', action='store_true', help='Restore with Service Offline', required=False) args = parser.parse_args() if args.backup and args.restore: print "Please use either --backup or --restore but not both :-)" sys.exit(2) #Creates VOS Requests Session. It will prompt for user and password. vos_session = vos.vos_get_session() vosrt = args.cloud_url # Backup Configuration if args.backup: #Backup Sources f_src = open(args.src_file, 'w') vos_srcs = vos.vos_get_source_all(vosrt, vos_session) json.dump(vos_srcs.json(), f_src) f_src.close() #Backup Destinations f_dst = open(args.dst_file, 'w') vos_dsts = vos.vos_get_destination_all(vosrt, vos_session) json.dump(vos_dsts.json(), f_dst) f_dst.close() #Backup Services f_srv = open(args.srv_file, 'w') vos_srvs = vos.vos_get_service_all(vosrt, vos_session) json.dump(vos_srvs.json(), f_srv) f_srv.close() #Backup Images f_img = open(args.img_file, 'w') vos_imgs = vos.vos_get_image_all(vosrt, vos_session) json.dump(vos_imgs.json(), f_img) f_img.close() #Backup DRM Systems if args.drm_file: f_drm = open(args.drm_file, 'w') vos_drms = vos.vos_get_drmsys_all(vosrt, vos_session) json.dump(vos_drms.json(), f_drm) f_drm.close() #Backup DRM Settings drm_sets_file = args.drm_file + '_settings' f_drm_sets = open(drm_sets_file, 'w') vos_drm_sets = vos.vos_get_drm_settings(vosrt, vos_session) json.dump(vos_drm_sets.json(), f_drm_sets) f_drm_sets.close() #Restores Configuration if args.restore: #Restores DRM Configuration if args.drm_file: #Checks if file exists if not os.path.isfile(args.drm_file): print "File %s does not exist !!" % args.drm_file sys.exit(2) #Restores DRM Settings drm_sets_file = args.drm_file + '_settings' #Checks if file exists if not os.path.isfile(drm_sets_file): print "File %s does not exist !!" % drm_sets_file sys.exit(2) with open(args.drm_file) as drm_data: drm = yaml.safe_load(drm_data) for drm_item in drm: param = json.dumps(drm_item) vos_ret = vos.vos_drmsys_add(param, vosrt, vos_session) check_status(vos_ret, "DRM System", drm_item['name'], drm_item['id']) with open(drm_sets_file) as drm_set: for param in drm_set: vos_ret = vos.vos_mod_drm_settings(param, vosrt, vos_session) if not vos_ret.status_code == 200: vos.log_write( "ERROR", "Failed to Update DRM Settings with the following settings:\n%s" % param, log_file) #Restore Images if args.img_file: #Checks if file exists if not os.path.isfile(args.img_file): print "File %s does not exist !!" % args.img_file sys.exit(2) with open(args.img_file) as img_data: i = yaml.safe_load(img_data) for img_item in i: param = json.dumps(img_item) vos_ret = vos.vos_add_image(param, vosrt, vos_session) check_status(vos_ret, "Image", img_item['url'], img_item['id']) #Restore Sources if args.src_file: #Checks if file exists if not os.path.isfile(args.src_file): print "File %s does not exist !!" % args.src_file sys.exit(2) with open(args.src_file) as src_data: s = yaml.safe_load(src_data) for src_item in s: param = json.dumps(src_item) vos_ret = vos.vos_add_source(param, vosrt, vos_session) check_status(vos_ret, "Source", src_item['name'], src_item['id']) time.sleep(4) #Restore Destinations if args.dst_file: #Checks if file exists if not os.path.isfile(args.dst_file): print "File %s does not exist !!" % args.dst_file sys.exit(2) with open(args.dst_file) as dst_data: d = yaml.safe_load(dst_data) for dst_item in d: param = json.dumps(dst_item) vos_ret = vos.vos_add_destination(param, vosrt, vos_session) check_status(vos_ret, "Destination", dst_item['name'], dst_item['id']) time.sleep(4) #Restore Services if args.srv_file: #Checks if file exists if not os.path.isfile(args.srv_file): print "File %s does not exist !!" % args.srv_file sys.exit(2) with open(args.srv_file) as srv_data: sv = yaml.safe_load(srv_data) for srv_item in sv: if args.srv_off: srv_item['controlState'] = "OFF" param = json.dumps(srv_item) vos_ret = vos.vos_service_add(param, vosrt, vos_session) check_status(vos_ret, "Service", srv_item['name'], srv_item['id']) time.sleep(10)