module yumaworks-sesmgr {
    yang-version 1.1;
    namespace "http://yumaworks.com/ns/yumaworks-sesmgr";
    prefix "ysmgr";

    import ietf-yang-types { prefix yang; }
    import ietf-inet-types { prefix inet; }
    import yuma-ncx { prefix ncx; }
    import yuma-types { prefix nt; }
    import yuma-app-common { prefix appcmn; }
    import yumaworks-app-common { prefix ywapp; }
    import yumaworks-types { prefix ywt; }

    organization "YumaWorks, Inc.";

    contact
        "Support <support at yumaworks.com>";

    description
       "yp-controller session manager

     Copyright (c) 2018 YumaWorks, Inc. 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 2018-04-28 {
        description
          "Initial version";
    }

    typedef sesmgr-device-ref {
      type leafref {
        path "/ysmgr:sesmgr/ysmgr:devices/ysmgr:device/ysmgr:name";
      }
    }

    typedef sesmgr-user-ref {
      type leafref {
        path "/ysmgr:sesmgr/ysmgr:users/ysmgr:user/ysmgr:name";
      }
    }

    typedef sesmgr-session-ref {
      type leafref {
        path "/ysmgr:sesmgr/ysmgr:sessions/ysmgr:session/ysmgr:name";
      }
    }

    grouping device-cmn {
      description "one device endpoint configuration contents";

      leaf server {
        type inet:host;
        mandatory true;
        description
          "IP address or DNS name of the NETCONF server target.";
      }

      leaf port {
        type inet:port-number;
        description "NETCONF over SSH port number to use.";
      }

      leaf rc-entry-point {
        type string;
        description
          "RESTCONF entry point. Use this string instead of
           retrieving the XRD from the RESTCONF server to
           discover the entry point.";
      }

      uses appcmn:ProtocolsParm;

      leaf transport {
        type ywt:transport-type;
        description "transport protocol to use";
      }
    }

    grouping session-cmn {
      leaf name {
        type nt:NcxName;
        description "The name of the saved session.";
      }

      leaf user-ref {
        type sesmgr-user-ref;
        mandatory true;
        description "The user to use for this session";
      }
    }  // grouping session-cmn

    grouping session-state {
      container state {
        config false;

        leaf connected {
          type boolean;
          description
            "Indicates if session currently connected";
        }

        leaf connect-time {
          type yang:date-and-time;
          description
            "Date and time the session connected.";
        }

        container counters {
          leaf out-rpcs {
            type yang:zero-based-counter32;
            description "Number of <rpc> messages sent.";
          }
          leaf in-rpc-errors {
            type yang:zero-based-counter32;
            description
              "Number of <rpc-reply> messages received
               that contained an <rpc-error>";
          }
          leaf in-notifications {
            type yang:zero-based-counter32;
            description
              "Number of <notification> messages received.";
          }
          leaf in-octets {
            type yang:zero-based-counter32;
            description
              "Number of octets received by netconfd-pro
               for this session.";
          }
          leaf out-octets {
            type yang:zero-based-counter32;
            description
              "Number of octets sent by netconfd-pro
               for this session.";
           }
         }
       }  // end container state
    }  // grouping session-state

    container sesmgr {
      ncx:sil-delete-children-first;
      description
        "yp-controller session management configuration";

      container devices {
        ncx:sil-delete-children-first;
        description
          "yp-controller device configuration";

        list device {
          description "one device endpoint configuration";
          key name;

          leaf name {
            type nt:NcxName;
            description "The name of the saved device.";
          }

          uses device-cmn;
        }
      }

      container users {
        ncx:sil-delete-children-first;
        description
          "yp-controller user configuration";

        list user {
          description "one user configuration";
          key name;

          leaf name {
            type nt:NcxName;
            description "The name of the saved user.";
          }

          leaf user {
            type nt:NcxName;
            mandatory true;
            description "The user name of the session.";
          }

          choice pass {
            mandatory true;
            leaf password {
              type string;
              ncx:password;
              description
                "User password to use for NETCONF users.
                 If none, then user will be prompted before connecting.";
            }
            leaf no-password { type empty; }
          }

          uses ywapp:SshKeyParms;

          uses ywapp:SslKeyParms;

          leaf-list admin-group {
            type nt:NcxName;
            description
              "The name of an allowed admin group for the saved user.";
          }

        }
      }

      container sessions {
        ncx:sil-delete-children-first;
        description
          "yp-controller session configuration";

        list session {
          description "one session configuration";
          key name;
          uses session-cmn;

          leaf device-ref {
            type sesmgr-device-ref;
            mandatory true;
            description "The device to use for this session";
          }

          uses session-state;
        }

        list callhome-session {
          description "one callhome session added by sesmgr";
          key name;
          config false;
          uses session-cmn;

          container device {
            uses device-cmn;
          }

          uses session-state;
        }

      }  // end container sessions

    }  // end container sesmgr

}
