コード例 #1
0
def main():
    """
    This sample script will show how to work with the device configurations using NETCONF and RESTCONF
    """

    # retrieve the device capabilities using RESTCONF
    print('Device Capabilities via RESTCONF: ')
    capabilities = netconf_restconf.restconf_get_capabilities(
        IOS_XE_HOST, IOS_XE_USER, IOS_XE_PASS)
    print(json.dumps(capabilities, indent=4, separators=(' , ', ' : ')))

    # retrieve the device hostname using RESTCONF
    device_hostname = netconf_restconf.restconf_get_hostname(
        IOS_XE_HOST, IOS_XE_USER, IOS_XE_PASS)
    print(str('\nDevice Hostname via RESTCONF: \n' + device_hostname))

    # retrieve interface operationla state using NETCONF
    interface_state = netconf_restconf.netconf_get_int_oper_status(
        'GigabitEthernet1', IOS_XE_HOST, IOS_XE_PORT, IOS_XE_USER, IOS_XE_PASS)
    print(
        str('\nInterface Operational Status via NETCONF: \n' +
            interface_state))

    # retrieve the interface statistics using RESTCONF
    interface_statistics = netconf_restconf.restconf_get_int_oper_data(
        'GigabitEthernet1', IOS_XE_HOST, IOS_XE_USER, IOS_XE_PASS)
    print('\nGigabitEthernet1 Interface Statistics via RESTCONF: \n')
    print(json.dumps(interface_statistics, indent=4,
                     separators=(' , ', ' : ')))

    # save running configuration to startup configuration using RESTCONF
    save_result = netconf_restconf.restconf_save_running_config(
        IOS_XE_HOST, IOS_XE_USER, IOS_XE_PASS)
    print('\nRunning Config saved to device using RESTCONF: ', save_result)

    # save running configuration to file using NETCONF
    save_file = 'flash:/CONFIG_FILES/base_config'
    save_file_result = netconf_restconf.netconf_save_running_config_to_file(
        save_file, IOS_XE_HOST, IOS_XE_PORT, IOS_XE_USER, IOS_XE_PASS)
    print('\nRunning Config saved to file using NETCONF: ',
          save_file_result[1])

    # rollback configuration to saved file using RESTCONF
    rollback_file = 'flash:/CONFIG_FILES/base_config'
    rollback_result = netconf_restconf.restconf_rollback_to_saved_config(
        rollback_file, IOS_XE_HOST, IOS_XE_USER, IOS_XE_PASS)
    print('\nRollback of Config from saved file using RESTCONF: ',
          rollback_result)
コード例 #2
0
                             headers=headers)
    print('\nServiceNow REST API call response: ' + str(response.status_code))
    incident_json = response.json()
    incident_number = incident_json['result']['number']
    logging.debug('Incident created: ' + incident_number)
    return incident_number


# main application

logging.basicConfig(
    filename='application_run.log',
    level=logging.DEBUG,
    format=
    '%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S')

device_name = netconf_restconf.restconf_get_hostname(IOS_XE_HOST, IOS_XE_USER,
                                                     IOS_XE_PASS)

comment = '\n\nThe device with the management IP address: ' + IOS_XE_HOST + ' has the name: ' + device_name

print(comment)

incident = create_incident('Device Notification - ' + str(device_name),
                           comment, SNOW_DEV, 3)

print('Created ServiceNow Incident with the number: ', str(incident))

print('\nEnd Application Run')