def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:m:", ["host=","user="******"password="******"https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) job_data = { 'managedNetwork': netld_network, 'jobName': job_name, 'jobType': 'Script Tool Job', 'description': '', 'jobParameters': { 'tool': 'org.ziptie.tools.scripts.commandRunner', 'managedNetwork': netld_network, 'backupOnCompletion': 'false', 'ipResolutionScheme': _resolution_scheme(device), 'ipResolutionData': device, 'input.commandList': commands } } try: execution = _netld_svc.call('Scheduler.runNow', job_data) except JsonError as ex: print 'JsonError: ' + str(ex.value) try: result = _wait_for_completion(execution) _print_job_ouptut(execution, device) except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser')
def main(*args): ### Create a JSON-RPC proxy for the inventory service ### netld = JsonRpcProxy.fromHost("192.168.20.203", "admin", "password") ### use the inventory service to query for devices query = raw_input('Enter an individual IP address or IP/CIDR (eg. 10.0.0.0/24): ') pageData= {'offset': 0, 'pageSize': 500} # Inventory.search parameters: # network, search scheme, query data, paging data, sort column, descending pageData = netld.call('Inventory.search', ['Default'], 'ipAddress', query, pageData, 'ipAddress', False) print "Search found " + str(pageData['total']) + " devices."; print "----------------------------------------------"; for device in pageData['devices']: hostname = device['hostname'] if (hostname is None): hostname = 'Not available' print device['ipAddress'] + " " + hostname ### Logout using the security service to be nice to the server ### netld.call('Security.logoutCurrentUser')
def main(*args): ### Create a JSON-RPC proxy for the inventory service ### netld = JsonRpcProxy.fromHost("192.168.20.203", "admin", "password") ### use the inventory service to query for devices query = raw_input( 'Enter an individual IP address or IP/CIDR (eg. 10.0.0.0/24): ') pageData = {'offset': 0, 'pageSize': 500} # Inventory.search parameters: # network, search scheme, query data, paging data, sort column, descending pageData = netld.call('Inventory.search', ['Default'], 'ipAddress', query, pageData, 'ipAddress', False) print "Search found " + str(pageData['total']) + " devices." print "----------------------------------------------" for device in pageData['devices']: hostname = device['hostname'] if (hostname is None): hostname = 'Not available' print device['ipAddress'] + " " + hostname ### Logout using the security service to be nice to the server ### netld.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt( argv, "h:u:p:f:e:x:", ["host=", "user="******"password="******"excel=", "export", "exec"]) except getopt.GetoptError as err: print "Error: " + str(err) usage_and_exit(argv) global netld_host, netld_user, netld_pass, excel_file excel_file = None export_action = False exec_action = False if os.path.exists('junifort.ini'): config = ConfigParser.RawConfigParser() config.read('junifort.ini') for section in config.sections(): netld_host = config.get(section, 'host') netld_user = config.get(section, 'username') netld_pass = config.get(section, 'password') for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-f', '--excel'): excel_file = arg if opt in ('-e', '--export'): export_action = True if opt in ('-x', '--exec'): exec_action = True if excel_file is None or (not export_action and not exec_action): usage_and_exit(argv) try: global netld_svc netld_svc = JsonRpcProxy.fromHost(netld_host, netld_user, netld_pass) devices = NetLdExcel(netld_svc).resolve_from_excel( excelFile=excel_file, adapters=['Juniper::ScreenOS', 'Fortinet::FortiGate']) if export_action: export_to_excel(devices) else: exec_from_excel(devices, excel_file) except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:f:e:x:", ["host=","user="******"password="******"excel=","export","exec"]) except getopt.GetoptError as err: print "Error: " + str(err) usage_and_exit(argv) global netld_host, netld_user, netld_pass, excel_file excel_file = None export_action = False exec_action = False if os.path.exists('junifort.ini'): config = ConfigParser.RawConfigParser() config.read('junifort.ini') for section in config.sections(): netld_host = config.get(section, 'host') netld_user = config.get(section, 'username') netld_pass = config.get(section, 'password') for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-f', '--excel'): excel_file = arg if opt in ('-e', '--export'): export_action = True if opt in ('-x', '--exec'): exec_action = True if excel_file is None or (not export_action and not exec_action): usage_and_exit(argv) try: global netld_svc netld_svc = JsonRpcProxy.fromHost(netld_host, netld_user, netld_pass) devices = NetLdExcel(netld_svc).resolve_from_excel( excelFile=excel_file, adapters=['Juniper::ScreenOS', 'Fortinet::FortiGate'] ) if export_action: export_to_excel(devices) else: exec_from_excel(devices, excel_file) except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt(argv, "o:c:", ["output=", "config="]) except getopt.GetoptError: usageAndExit() output = '' configFile = '' for opt, arg in opts: if opt in ('-o', '--output'): output = arg if opt in ('-c', '--config'): configFile = arg if output == '': usageAndExit() if configFile == '': usageAndExit() if not os.path.exists(configFile): print 'Configuration file does not exist: ' + configFile sys.exit(3) config = ConfigParser.RawConfigParser() config.read(configFile) global host, user, password for section in config.sections(): host = config.get(section, HOST) user = config.get(section, USERNAME) password = config.get(section, PASSWORD) if config.has_option(section, LAST_SESSION_END): lastSessionEnd = config.getint(section, LAST_SESSION_END) else: lastSessionEnd = 0 try: global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(host), user, password) lastSessionEnd = exportTermLogs(output, lastSessionEnd) config.set(section, LAST_SESSION_END, lastSessionEnd) except urllib2.URLError as e: print "Error exporting terminal logs for host: " + host print str(e) file = open(configFile, 'w') config.write(file) file.close()
def main(argv): try: opts, args = getopt.getopt(argv,"o:c:",["output=","config="]) except getopt.GetoptError: usageAndExit() outputFile = '' configFile = '' for opt, arg in opts: if opt in ('-o', '--output'): outputFile = arg if opt in ('-c', '--config'): configFile = arg if outputFile == '': outputFile = "JobHistory" + strftime("%y%m%d-%H%M%S", localtime()) + ".txt" if not os.path.exists(configFile): print 'Configuration file does not exist: ' + configFile sys.exit(3) config = ConfigParser.RawConfigParser() config.read(configFile) global host, user, password for section in config.sections(): host = config.get(section, HOST) user = config.get(section, USERNAME) password = config.get(section, PASSWORD) if config.has_option(section, LAST_END_TIME): inilastEndTime = config.getint(section, LAST_END_TIME) else: inilastEndTime = 0 try: global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(host), user, password) inilastEndTime = exportJobHistory(outputFile, inilastEndTime) config.set(section, LAST_END_TIME, inilastEndTime) except urllib2.URLError as e: print "Error exporting Job History for host: " + host print str(e) file = open(configFile, 'w') config.write(file) file.close()
import sys import json import urllib2 import base64 import datetime import pprint from jsonrpc import JsonRpcProxy, JsonError netld_host = 'localhost' netld_user = '******' netld_pass = '******' netld_network = 'Default' ### Create a JSON-RPC proxy ### netld = JsonRpcProxy("https://{0}/rest".format(netld_host), netld_user, netld_pass) ### use the configuration service to retrieve a page of change logs ipAddress = raw_input( 'Enter an individual IP address or IP/CIDR (eg. 10.0.0.0/24): ') archivePath = raw_input( 'Enter the configuration archive path as it appears in NetLD: ') print "Snapshot Path Timestamp Size User" print "==============================================================================" changeLog = netld.call('Configuration.retrieveArchiveChangeLog', netld_network, ipAddress, archivePath, None) snapShot = changeLog['timestamp']
def main(argv): try: opts, args = getopt.getopt(argv,"h:u:p:m:o:", ["host=","user="******"password="******"--managed-network=","output="]) except getopt.GetoptError: usageAndExit() global netld_host, netld_user, netld_pass, netld_network outputFile = '' netld_network = 'Default' for opt, arg in opts: if opt in ('-o', '--output'): outputFile = arg if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-m', '--managed-network'): netld_network = arg if outputFile == '': outputFile = "InventoryReport" + strftime("%y%m%d-%H%M%S", localtime()) + ".csv" _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) pageData = {'offset': 0, 'pageSize': 500} while True: pageData = _netld_svc.call('Inventory.search', ['Default'], 'ipAddress', "", pageData, 'ipAddress', False) csvfile = open(outputFile, 'w') cw = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) for device in pageData['devices']: cw.writerow([ noneSafe(device['backupStatus']), noneSafe(device['ipAddress']), noneSafe(device['hostname']), noneSafe(device['hardwareVendor']), noneSafe(device['model']), noneSafe(device['deviceType']), noneSafe(device['serialNumber']), noneSafe(device['adapterId']), noneSafe(device['osVersion']), noneSafe(device['softwareVendor']), noneSafe(device['backupElapsed']), noneSafe(device['memoSummary']), noneSafe(device['custom1']), noneSafe(device['custom2']), noneSafe(device['custom3']), noneSafe(device['custom4']), noneSafe(device['custom5']) ]) if pageData['offset'] + pageData['pageSize'] >= pageData['total']: break; pageData['offset'] += pageData['pageSize'] if pageData['total'] == 0: quit _netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:s:m:w", [ "host=", "user="******"password="******"snmp-ro=", '--managed-network=', '--no-wait' ]) except getopt.GetoptError: usage_and_exit() global netld_host, netld_user, netld_pass, snmp_ro, netld_network no_wait = None for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-s', '--snmp-ro'): snmp_ro = arg if opt in ('-m', '--managed-network'): netld_network = arg if opt in ('-w', '--no-wait'): no_wait = True if (len(args) < 1): usage_and_exit() ip_host_file = _resolve_ipaddrs(args[0]) ### Create a JSON-RPC proxy for the inventory service ### global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) job_data = { 'managedNetwork': netld_network, 'jobName': 'Discovery', 'jobType': 'Discover Devices', 'description': '', 'jobParameters': { 'addresses': ip_host_file, 'managedNetwork': netld_network, 'crawl': 'false', 'boundaryNetworks': '10.0.0.0/8,192.168.0.0/16,172.16.0.0/12', 'includeInventory': 'false', 'communityStrings': snmp_ro } } try: execution = _netld_svc.call('Scheduler.runNow', job_data) except JsonError as ex: print 'JsonError: ' + str(ex.value) try: if (no_wait is None): result = _wait_for_completion(execution) print 'Job status: ' + result['status'] print 'Start time: ' + time.strftime( "%a, %d %b %Y %H:%M:%S", time.localtime(result['startTime'] / 1000)) print 'End time : ' + time.strftime( "%a, %d %b %Y %H:%M:%S", time.localtime(result['endTime'] / 1000)) print except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt(argv,"h:u:p:m:o:", ["host=","user="******"password="******"--managed-network=","output="]) except getopt.GetoptError: usageAndExit() global netld_host, netld_user, netld_pass, netld_network outputFile = '' netld_network = 'Default' for opt, arg in opts: if opt in ('-o', '--output'): outputFile = arg if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-m', '--managed-network'): netld_network = arg if outputFile == '': outputFile = "HardwareReport" + strftime("%y%m%d-%H%M%S", localtime()) + ".csv" _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) job = { 'managedNetwork': netld_network, 'jobName': 'Hardware Report', 'jobType': 'Report', 'description': '', 'jobParameters': { 'tool': 'ziptie.reports.hardware', 'ipResolutionScheme': 'ipAddress', 'ipResolutionData': '', 'managedNetwork': netld_network, 'format': 'csv' }, } execution = _netld_svc.call('Scheduler.runNow', job) print "** executing job **" execution_id = execution['id'] opener = urllib2.build_opener(_netld_svc._cookie_processor, _netld_svc._https_handler) while not execution['endTime']: if execution['completionState'] == 1 or execution['completionState'] == 2: print '** execution canceled **' break time.sleep(1) execution = _netld_svc.call('Scheduler.getExecutionDataById', execution_id) url = 'https://{0}/servlet/pluginDetail?executionId={1}'.format(netld_host, str(execution_id)) response = opener.open(url) if response.headers.get('content-encoding', '') == 'deflate': resp = zlib.decompressobj(-zlib.MAX_WBITS).decompress(response.read()) else: resp = response.read() file = open(outputFile, 'w') file.write(resp) file.close() print "** Hardware Report Export execution complete **" _netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt( argv, "h:u:p:m:o:", ["host=", "user="******"password="******"--managed-network=", "output="]) except getopt.GetoptError: usageAndExit() global netld_host, netld_user, netld_pass, netld_network outputFile = '' netld_network = 'Default' for opt, arg in opts: if opt in ('-o', '--output'): outputFile = arg if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-m', '--managed-network'): netld_network = arg if outputFile == '': outputFile = "InventoryReport" + strftime("%y%m%d-%H%M%S", localtime()) + ".csv" _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) pageData = {'offset': 0, 'pageSize': 500} while True: pageData = _netld_svc.call('Inventory.search', ['Default'], 'ipAddress', "", pageData, 'ipAddress', False) csvfile = open(outputFile, 'w') cw = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) for device in pageData['devices']: cw.writerow([ noneSafe(device['backupStatus']), noneSafe(device['ipAddress']), noneSafe(device['hostname']), noneSafe(device['hardwareVendor']), noneSafe(device['model']), noneSafe(device['deviceType']), noneSafe(device['serialNumber']), noneSafe(device['adapterId']), noneSafe(device['osVersion']), noneSafe(device['softwareVendor']), noneSafe(device['backupElapsed']), noneSafe(device['memoSummary']), noneSafe(device['custom1']), noneSafe(device['custom2']), noneSafe(device['custom3']), noneSafe(device['custom4']), noneSafe(device['custom5']) ]) if pageData['offset'] + pageData['pageSize'] >= pageData['total']: break pageData['offset'] += pageData['pageSize'] if pageData['total'] == 0: quit _netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:s:m:w", ["host=","user="******"password="******"snmp-ro=",'--managed-network=','--no-wait']) except getopt.GetoptError: usage_and_exit() global netld_host, netld_user, netld_pass, snmp_ro, netld_network no_wait = None for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-s', '--snmp-ro'): snmp_ro = arg if opt in ('-m', '--managed-network'): netld_network = arg if opt in ('-w', '--no-wait'): no_wait = True if (len(args) < 1): usage_and_exit() ip_host_file = _resolve_ipaddrs(args[0]) ### Create a JSON-RPC proxy for the inventory service ### global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) job_data = { 'managedNetwork': netld_network, 'jobName': 'Discovery', 'jobType': 'Discover Devices', 'description': '', 'jobParameters': { 'addresses': ip_host_file, 'managedNetwork': netld_network, 'crawl': 'false', 'boundaryNetworks': '10.0.0.0/8,192.168.0.0/16,172.16.0.0/12', 'includeInventory': 'false', 'communityStrings': snmp_ro } } try: execution = _netld_svc.call('Scheduler.runNow', job_data) except JsonError as ex: print 'JsonError: ' + str(ex.value) try: if (no_wait is None): result = _wait_for_completion(execution) print 'Job status: ' + result['status'] print 'Start time: ' + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(result['startTime'] / 1000)) print 'End time : ' + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(result['endTime'] / 1000)) print except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser')
def run(host, user, password, network, csv_file, job_name, credential_config_name): with open(csv_file, 'rb') as f: reader = csv.reader(f) for row in reader: print row target_tag = '' # TODO lbayer: use user inputed values... new_password = '******' new_enable_password = '******' global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(host), user, password) job = { 'managedNetwork': network, 'jobName': job_name, 'jobType': 'Script Tool Job', 'description': '', 'jobParameters': { 'tool': 'org.ziptie.tools.scripts.changemultipassword', 'ipResolutionScheme': 'tag', 'ipResolutionData': target_tag, 'managedNetwork': network, 'backupOnCompletion': 'false', 'input.newPassword': new_password, 'input.newEnablePassword': new_enable_password, }, } execution = _netld_svc.call('Scheduler.runNow', job) print '** executing job **' execution_id = execution['id'] x = 0 # wait for completion while not execution['endTime']: if execution['completionState'] == 1 or execution[ 'completionState'] == 2: print '** execution canceled **' break x += .1 time.sleep( math.atan(x) ) # gradually increase wait time, so we don't have to wait very long for short jobs, but we don't make too many calls for long jobs execution = _netld_svc.call('Scheduler.getExecutionDataById', execution_id) ips_to_update = {} # print individual script run details... tool_run_details = _netld_svc.call('Plugins.getExecutionDetails', executionId) for detail in tool_run_details: print_details(host, executionId, detail) ips_to_update[detail.ipAddress] = True update_credentials(network, credential_config_name, ips_to_update, new_password, new_enable_password) _netld_svc.call('Security.logoutCurrentUser') print "** password change execution complete **"
#!/usr/bin/env python import sys import json import urllib2 from jsonrpc import JsonRpcProxy, JsonError ### Create a JSON-RPC proxy for the inventory service ### netld = JsonRpcProxy.fromHost("localhost", "admin", "password") ### use the inventory service to create a device error = netld.call('Inventory.createDevice', 'Default', '10.10.10.10', 'Cisco::IOS') print "Create device result: " + ("Created" if (error is None) else error) ### get the device we just created and print it's address from the returned object device = netld.call('Inventory.getDevice', 'Default', '10.10.10.10') if device is not None: print 'Retrieved device: ' + device['ipAddress'] else: print 'Device does not exist!' ### now delete the device netld.call('Inventory.deleteDevice', 'Default', '10.10.10.10') print "Device deleted." ### Logout using the security service to be nice to the server ###
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:j:m:w"), ["host=","user="******"password="******"job=",'--managed-network=','--no-wait']) except getopt.GetoptError as err: print "Error: " + str(err) usage_and_exit() global netld_host, netld_user, netld_pass, job_name, netld_network no_wait = None job_name = None for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-j', '--job'): job_name = arg if opt in ('-m', '--managed-network'): netld_network = (arg) if opt in ('-w', '--no-wait'): no_wait = True if (job_name is None): usage_and_exit() ### Create a JSON-RPC proxy ### global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) pageData = {'offset': 0, 'pageSize': 1000} try: pageData = _netld_svc.call('Scheduler.searchJobs', pageData, [netld_network], None, True) except JsonError as ex: print 'JsonError: ' + str(ex.value) jobId = -1 for job in pageData['jobData']: if (job['jobName'] == job_name): jobId = job['jobId']; break if (jobId == -1): print "No matching job found." exit(1) try: jobData = _netld_svc.call('Scheduler.getJob', jobId) if (jobData): execution = _netld_svc.call('Scheduler.runNow', jobData) else: print "Unexpected error, job with ID " + str(jobId) + " could not be retreived" exit(1) except JsonError as ex: print 'JsonError: ' + str(ex.value) exit(1) exit_code = 0; try: if (no_wait is None): result = _wait_for_completion(execution) exit_code = 0 if result['status'] == 'OK' else 1 print 'Job status: ' + result['status'] print 'Start time: ' + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(result['startTime'] / 1000)) print 'End time : ' + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(result['endTime'] / 1000)) print except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser') return exit_code
#!/usr/bin/env python import sys import json import urllib2 from jsonrpc import JsonRpcProxy, JsonError ### Create a JSON-RPC proxy for the inventory service ### netld = JsonRpcProxy.fromHost("localhost", "admin", "password") ### use the inventory service to create a device error = netld.call('Inventory.createDevice', 'Default', '10.10.10.10', 'Cisco::IOS') print "Create device result: " + ("Created" if (error is None) else error) ### get the device we just created and print it's address from the returned object device = netld.call('Inventory.getDevice', 'Default', '10.10.10.10'); if device is not None: print 'Retrieved device: ' + device['ipAddress']; else: print 'Device does not exist!' ### now delete the device netld.call('Inventory.deleteDevice', 'Default', '10.10.10.10') print "Device deleted." ### Logout using the security service to be nice to the server ### netld.call('Security.logoutCurrentUser')
import sys import json import urllib2 import base64 import datetime from jsonrpc import JsonRpcProxy, JsonError netld_host = '192.168.20.215' netld_user = '******' netld_pass = '******' netld_network = 'Core' ### Create a JSON-RPC proxy ### netld = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) ### use the configuration service to retrieve a page of change logs ipAddress = raw_input( 'Enter an individual IP address or IP/CIDR (eg. 10.0.0.0/24): ') print "Snapshot Path Timestamp Size User" print "==============================================================================" pageData = {'offset': 0, 'pageSize': 10} while True: pageData = netld.call('Configuration.retrieveSnapshotChangeLog', netld_network, ipAddress, pageData) for changeLog in pageData['changeLogs']:
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:m:w:c:t:", ['host=','user='******'password='******'managed-network=','--no-wait','config=','timestamp=']) except getopt.GetoptError: _usage_and_exit() global netld_host, netld_user, netld_pass, netld_network no_wait = None for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-m', '--managed-network'): netld_network = arg if opt in ('-w', '--no-wait'): no_wait = True if opt in ('-c', '--config'): configPath = arg if opt in ('-t', '--timestamp'): timestamp = arg if (len(args) > 0): device = args[0] else: _usage_and_exit() ### Create a JSON-RPC proxy for the inventory service ### global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) pageData = _netld_svc.call('Configuration.retrieveSnapshotChangeLog', 'Default', device, {'offset': 0, 'pageSize': 1000}) for changeLog in pageData['changeLogs']: snapShot = datetime.fromtimestamp(changeLog['timestamp'] / 1000) if (snapShot.strftime('%Y-%m-%d %H:%M:%S') > timestamp): targetTime = datetime.utcfromtimestamp(changeLog['timestamp'] / 1000) localTargetTime = snapShot else: print "Restoring configuration from snapshot: " + str(localTargetTime) break job_data = { 'managedNetwork': netld_network, 'jobName': job_name, 'jobType': 'Restore Configuration', 'description': '', 'jobParameters': { 'managedNetwork': netld_network, 'ipResolutionScheme': _resolution_scheme(device), 'ipResolutionData': device, 'configPath': configPath, 'configTimestamp': targetTime.strftime('%Y-%m-%dT%H:%M:%S') } } try: execution = _netld_svc.call('Scheduler.runNow', job_data) except JsonError as ex: print 'JsonError: ' + str(ex.value) try: if (no_wait is None): result = _wait_for_completion(execution) except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:m:w:c:t:", [ 'host=', 'user='******'password='******'managed-network=', '--no-wait', 'config=', 'timestamp=' ]) except getopt.GetoptError: _usage_and_exit() global netld_host, netld_user, netld_pass, netld_network no_wait = None for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-m', '--managed-network'): netld_network = arg if opt in ('-w', '--no-wait'): no_wait = True if opt in ('-c', '--config'): configPath = arg if opt in ('-t', '--timestamp'): timestamp = arg if (len(args) > 0): device = args[0] else: _usage_and_exit() ### Create a JSON-RPC proxy for the inventory service ### global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) pageData = _netld_svc.call('Configuration.retrieveSnapshotChangeLog', 'Default', device, { 'offset': 0, 'pageSize': 1000 }) for changeLog in pageData['changeLogs']: snapShot = datetime.fromtimestamp(changeLog['timestamp'] / 1000) if (snapShot.strftime('%Y-%m-%d %H:%M:%S') > timestamp): targetTime = datetime.utcfromtimestamp(changeLog['timestamp'] / 1000) localTargetTime = snapShot else: print "Restoring configuration from snapshot: " + str( localTargetTime) break job_data = { 'managedNetwork': netld_network, 'jobName': job_name, 'jobType': 'Restore Configuration', 'description': '', 'jobParameters': { 'managedNetwork': netld_network, 'ipResolutionScheme': _resolution_scheme(device), 'ipResolutionData': device, 'configPath': configPath, 'configTimestamp': targetTime.strftime('%Y-%m-%dT%H:%M:%S') } } try: execution = _netld_svc.call('Scheduler.runNow', job_data) except JsonError as ex: print 'JsonError: ' + str(ex.value) try: if (no_wait is None): result = _wait_for_completion(execution) except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser')
import sys import json import urllib2 import base64 import datetime from jsonrpc import JsonRpcProxy, JsonError netld_host = '192.168.20.215' netld_user = '******' netld_pass = '******' netld_network = 'Core' ### Create a JSON-RPC proxy ### netld = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) ### use the configuration service to retrieve a page of change logs ipAddress = raw_input('Enter an individual IP address or IP/CIDR (eg. 10.0.0.0/24): ') print "Snapshot Path Timestamp Size User" print "==============================================================================" pageData= {'offset': 0, 'pageSize': 10} while True: pageData = netld.call('Configuration.retrieveSnapshotChangeLog', netld_network, ipAddress, pageData) for changeLog in pageData['changeLogs']: snapShot = changeLog['timestamp']
import sys import json import urllib2 import base64 import datetime import pprint from jsonrpc import JsonRpcProxy, JsonError netld_host = 'localhost' netld_user = '******' netld_pass = '******' netld_network = 'Default' ### Create a JSON-RPC proxy ### netld = JsonRpcProxy("https://{0}/rest".format(netld_host), netld_user, netld_pass) ### use the configuration service to retrieve a page of change logs ipAddress = raw_input('Enter an individual IP address or IP/CIDR (eg. 10.0.0.0/24): ') archivePath = raw_input('Enter the configuration archive path as it appears in NetLD: ') print "Snapshot Path Timestamp Size User" print "==============================================================================" changeLog = netld.call('Configuration.retrieveArchiveChangeLog', netld_network, ipAddress, archivePath, None) snapShot = changeLog['timestamp'] firstLine = True for change in changeLog['changes']: if firstLine: