module yuma-system {

    namespace "http://netconfcentral.org/ns/yuma-system";

    //prefix "sys";
    prefix "ypsys";

    import ietf-inet-types { prefix inet; }

    import ietf-netconf { prefix nc; }

    import ietf-yang-types { prefix yang; }

    import yuma-app-common { prefix yumaapp; }

    import yuma-types { prefix nt; }

    import yuma-ncx { prefix ncx; }

    // choose ietf-netconf-acm or yuma-nacm
    import ietf-netconf-acm { prefix nacm; }
    //import yuma-nacm { prefix nacm; }

    organization  "Netconf Central";

    contact "Andy Bierman <andy@netconfcentral.org>.";

    description 
      "NETCONF Basic System Group.

     Copyright (c) 2009 - 2013 Andy Bierman and the persons
     identified as authors of the code.  All rights reserved.

     Redistribution and use in source and binary forms, with or
     without modification, is permitted pursuant to, and subject
     to the license terms contained in, the BSD 3-Clause License
     http://opensource.org/licenses/BSD-3-Clause";

    revision 2013-07-15 {
        description  
          "Add sysNetconfStartupSource leaf.
           Add sysNetconfStartupFilespec leaf.
           Add sysNetconfStartupTxidFilespec leaf.";
    }

    revision 2013-03-15 {
        description  
          "Move sequence-id to notifications.yang to prevent
           advertising the notifications module and therefore
           the create-subscription operation.  Need to disable
           when with-notifications=false CLI parameter set.";
    }

    revision 2012-11-15 {
        description  
          "Use inline yuma-netconf definitions instead 
           of yuma-netconf so that module does not need
           to be advertised to the client.  
           Import of ietf-netconf is done instead."; 
    }

    revision 2012-10-05 {
        description  
          "Updated EditOperationType to edit-operation-type.
           Converged nacm extension usage.";
    }

    revision 2012-01-15 {
        description  
          "Add sysNetconfServerCLI monitoring data.";
    }

    revision 2010-05-24 {
        description  
          "Change SessionId to standard session-id-type.";
    }

    revision 2009-12-27 {
        description  
          "Initial version.";
    }

   typedef Language2 {
     description "XML language type for LangString";
     type string {
       pattern '[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*';
     }
   }

   typedef LangString2 {
     description "XML string with a language attribute.";
     type string;
     ncx:metadata "Language2 lang";
   }

    grouping SysCommonSessionParms {
       leaf userName {
          description
             "Name of the user for the session.";
          type string;
       }

       leaf sessionId {
          description
             "Identifier of the session.";
          type nc:session-id-type;
          mandatory true;
       }

       leaf remoteHost {
          description
             "Address of the remote host for the session.";
          type inet:ip-address;
       }
    }


    container system {
        description
          "Basic objects for NETCONF system status.";

        config false;

        leaf sysName {
            description
              "The system name.";
            type string;
            reference "RFC 3418, sysName object";
        }

        leaf sysCurrentDateTime {
            description
              "The current system date and time.";
            type yang:date-and-time;
        }

        leaf sysBootDateTime {
            description
              "The system date and time when the system 
               last restarted.";
            type yang:date-and-time;
        }

        leaf sysLogLevel {
            description
              "The current system logging verbosity level.";
            type nt:NcDebugType;
        }

        leaf sysNetconfServerId {
            description
              "The name and version ID for the NETCONF server
               running on this system.";
            type string;
        }

        leaf sysNetconfStartupSource {
            description
              "The startup config source used at boot-time.";
            type enumeration {
               enum no-startup {
                 description
                   "The --no-startup CLI option was used.";
               }
               enum factory-startup {
                 description
                   "The --factory-startup CLI option was used.";
               }
               enum startup {
                 description
                   "The --startup=filespec CLI option was used
                    or the default startup file was used.";
               }
            }
        }

        leaf sysNetconfStartupFilespec {
            description
              "The filespec that is used (if any) to save the
               running config to NV storage. If this object
               contains an empty string then the startup file
               has not been set yet, or it is not used."; 
            type string;
        }

        leaf sysNetconfStartupTxidFilespec {
            description
              "The filespec that is used (if any) to save the
                latest transaction-id NV storage.";
            type string;
        }

        anyxml sysNetconfServerCLI {
            nacm:default-deny-all;
            description
              "The boot-time CLI and configuration parameters that
               were used by the server running on this system.
               The format is the 'netconfd' container, defined in
               netconfd.yang.  By default, only client-set
               parameters are shown.  Use with-defaults=report-all
               to see all CLI parameter values in effect.";
        }

        container uname {
          description
            "Contains the broken out fields from the 
             output of the 'uname' command on this machine.";

          leaf sysname {
            description
              "The name of the operating system in use.";
            type string;
          }

          leaf release {
            description
              "The current release level of the operating 
                system in use.";
            type string;
          }

          leaf version {
            description
              "The current version level of the operating 
                system in use.";
            type string;
          }

          leaf machine {
            description
              "A description of the hardware in use.";
            type string;
          }

          leaf nodename {
            description
              "The host name of this system, as reported by
               the uname command.";
            type string;
          }

        }
    }

    rpc set-log-level {
        nacm:default-deny-all;

        description
            "Sets the server log verbosity level";
        input {
            ncx:default-parm log-level;

            leaf log-level {
                description
                 "The desired verbosity level for system logging
                  messages generated by the server.
                  The current value can be obtained by retrieving
                  the /system/sysLogLevel object.";
                type nt:NcDebugType;
                mandatory true;
            }
        }
    }

    notification sysStartup {
       description
          "Generated when the system restarts.
           Used for logging purposes, since no
           sessions are actually active when
           the system restarts.";

       leaf startupSource {
          description
             "The filespec used to load the running configuration.
              This leaf will only be present if there was a startup
              configuration file used.";
          type string;
       }

       list bootError {
          description
             "There will be one entry for each <rpc-error>
              encountered during the load config operation.
              The <rpc-error> fields are used directly.
              There is no particular order, so no key is defined.";

          // this is really defined in yuma-netconf.yang, 
          // not ietf-netconf.yang!!
          // expanding this uses inline!!!!
          // uses nc:RpcErrorType;

          leaf error-type {
            description 
              "Defines the conceptual layer that the error occurred.";
            type enumeration {
              enum transport;
              enum rpc;
              enum protocol;
              enum application;
            }
            mandatory true;
          }

          leaf error-tag {
            description
              "Contains a string identifying the error condition.";
            type nc:error-tag-type;
            mandatory true;
          }

          leaf error-severity {
            description
              "Contains a string identifying the error severity, as
               determined by the device.";
             type nc:error-severity-type;
            mandatory true;
          }

          leaf error-app-tag {
            description
              "Contains a string identifying the data-model-specific
               or implementation-specific error condition, if one exists.
               This element will not be present if no appropriate 
               application error tag can be associated with a particular
               error condition.";
            type string;
          }

          leaf error-path {
            description
            "Contains the absolute XPath [2] expression identifying
             the element path to the node that is associated with the 
             error being reported in a particular rpc-error element.";
            type yang:xpath1.0;
          }

          leaf error-message {
            description
            "Contains a string suitable for human display that
            describes the error condition.  This element will not be 
            present if no appropriate message is provided for a 
            particular error condition.  This element SHOULD i
            nclude an xml:lang attribute.";
            //type LangString;
            type LangString2;
          }

          anyxml error-info {
          description
          "Contains protocol- or data-model-specific error content.
           This element will not be present if no such error content is
           provided for a particular error condition.  The list in 
           RFC 4741, Appendix A, defines any mandatory error-info content 
           for each error.  After any protocol-mandated content, a 
           data model definition may mandate that certain application-layer
           error information be included in the error-info container. 
           An implementation may include additional elements to 
           provide extended and/or implementation-specific debugging 
           information.";
          }
      }  
   }


    /*
    notification sysShutdown {
       description
          "Generated when the system is about to shutdown.";

       leaf timeLeft {
          description
             "Number of seconds left before the system is
              shutdown.";
          type uint32;
          units seconds;
       }

       leaf mode {
          description
             "Indicates the type of shutdown mode and 
              restart (if any) requested.";
          type enumeration {
             enum halt {
                description "System will power down and halt.";
             }
             enum restart {
                description 
                   "System will restart, but the image
                    will not be reloaded.";
             }
             enum reload {
                description 
                   "System will restart, and the image
                    will be reloaded.";
             }
          }
       }
    }
    */

    notification sysConfigChange {
       description
          "Generated when the <running> configuration is changed.";

       uses SysCommonSessionParms;

       list edit {
          description
             "An edit record will be present for each distinct
              edit operation on the running config.";
          leaf target {
             description
               "Topmost node associated with the configuration change.";
             type instance-identifier;
          }
          leaf operation {
             description
               "Type of edit operation performed.";
               type nc:edit-operation-type;
          }
       }
    }

    notification sysCapabilityChange {
       description
          "Generated when a <capability> is added or deleted.";

       container changed-by {
          description
            "Indicates who caused this capability change.
             If caused by internal action, then the
             empty leaf 'server' will be present.
             If caused by a management session, then
             the name, remote host address, and session ID
             of the session that made the change will be reported.";
          choice server-or-user {
            leaf server {
              description
                "The capability change was caused by the server.";
              type empty;
            }
            case by-user {
              uses SysCommonSessionParms;
            }
          }
       }

       leaf-list added-capability {
          description
            "List of capabilities that have been just added.";
	  type inet:uri;
       }

       leaf-list deleted-capability {
          description
            "List of capabilities that have been just deleted.";
	  type inet:uri;
       }
    }

    notification sysSessionStart {
       description
          "Generated when a new management session is started.";

       uses SysCommonSessionParms;
    }


    notification sysSessionEnd {
       description
          "Generated when a management session is terminated.";

       uses SysCommonSessionParms;

       leaf killedBy {
          when "../terminationReason = 'killed'";
          description
             "Session ID that issued the <kill-session>,
              if the session was terminated by this operation.";
          type nc:session-id-type;
       }

       leaf terminationReason {
          description
             "Reason the session was terminated.";
          mandatory true;
          type enumeration {
             enum closed {
                description
                   "The session was terminated with 
                    the <close-session> operation.";
             }
             enum killed {
                description
                   "The session was terminated with 
                    the <kill-session> operation.";
             }
             enum dropped {
                description
                   "The session was terminated because
                    the SSH session or TCP connection was
                    unexpectedly closed.";
             }
             enum timeout {
                description
                   "The session was terminated because
                    of inactivity, either waiting for
                    the <hello> or <rpc> PDUs.";
             }
             enum bad-start {
                description
                   "The session startup sequence failed.";
             }
             enum bad-hello {
                description
                   "The client's <hello> message was 
                    bad or never arrived.";
             }
             enum other {
                description
                   "The session was terminated for
                    some other reason.";
             }
          }
       }
    }

    notification sysConfirmedCommit {
       description
          "Generated when a confirmed-commit event occurs.";

       uses SysCommonSessionParms;

       leaf confirmEvent {
          description
             "Indicates the event that caused the notification.";
          mandatory true;
          type enumeration {
             enum start {
                description
                   "The confirm-commit procedure has started.";
             }
             enum cancel {
                description
                   "The confirm-commit procedure has been canceled,
                    due to the session being terminated.";
             }
             enum timeout {
                description
                   "The confirm-commit procedure has been canceled,
                    due to the confirm-timeout interval expiring.
                    The common session parameters will not be present
                    in this sub-mode.";
             }
             enum extend {
                description
                   "The confirm-commit timeout has been extended.";
             }
             enum complete {
                description
                   "The confirm-commit procedure has been completed.";
             }
          }
       }
    }

    rpc load {
      nacm:default-deny-all;
      description 
        "Load a module into the server, if it is not already loaded.
         Returns the module revision date (or today's date if none),
         of the module that was loaded, or an error if not found
         or the module found had errors and was not loaded
         successfully.  If the module is already loaded, then the
         revision date will simply be returned.";

      input {
        ncx:default-parm module;
        leaf module {
          description "Name of the module to load.";
          mandatory true;
          type nt:NcxName;
        }
        leaf revision {
          description
             "Module revision to load.";
          type nt:Date;
        }
        uses yumaapp:DeviationParm;
      }

      output {
        leaf mod-revision {
          description  
            "Revision date of the module in use by the server.
             Will only be present if the module has a version";
          type nt:Date;
        }
      }

    }

    rpc restart {
      description 
        "Restart the server. Does not reload the software image..";
        nacm:default-deny-all;
    }

    rpc shutdown {
      description 
        "Shutdown the server.";
      nacm:default-deny-all;
    }

    rpc no-op {
      description 
        "Just returns 'ok'. Used for debugging
         or relative performance measurements.";
    }

}
