/*
 *
 *   Copyright 2016 RIFT.IO Inc
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 *
 */

/**
 * @file rw-staging-mgmt.yang
 * @author Varun Prasad
 * @date 2016/09/21
 * @brief Pacakage Management Yang
 */

module rw-staging-mgmt
{
  namespace "http://riftio.com/ns/riftware-1.0/rw-staging-mgmt";
  prefix "rw-staging-mgmt";

  import ietf-yang-types {
    prefix "yang";
  }

  import rw-pb-ext {
    prefix "rwpb";
  }

  import rw-cli-ext {
    prefix "rwcli";
  }

  import rw-cloud {
    prefix "rwcloud";
  }

  import rwcal {
    prefix "rwcal";
  }

  import mano-types {
    prefix "manotypes";
  }

  revision 2016-06-01 {
    description
      "Initial revision.";
  }

  typedef staging-area-status {
    type enumeration {
      enum LIVE;
      enum EXPIRED;
    }
  }

  grouping staging-area-config {
    leaf package-type {
      mandatory true;
      type manotypes:package-type;
    }

    leaf name {
      description "name of the binary";
      type string;
    }

    leaf validity-time {
      description "lifetime of the staging area (in seconds)";
      type uint64;
      default 3600;
    }
  }

  grouping staging-area-meta {

    leaf status {
      description "The status of the staging area";
      type staging-area-status;
    }

    leaf created-time {
      description "start time (unix epoch)";
      type uint32;
    }

    leaf deleted-time {
      description "stop time (unix epoch)";
      type uint32;
    }

    leaf size {
      description "size of the binary in bytes";
      type uint64;
    }

    leaf path {
      description "Path of the staging area";
      type string;
    }

  }

  container staging-areas {
    rwpb:msg-new StagingAreas;
    description "Staging Areas";
    config false;

    list staging-area {
      rwpb:msg-new StagingArea;
      key "area-id";

      leaf area-id {
        description "Staging Area ID";
        type string;
      }

      uses staging-area-config;
      uses staging-area-meta;
    }
  }


  rpc create-staging-area {
    description "Creates a staging area for the upload.";

    input {
      uses staging-area-config;
    }

    output {
      leaf port {
        type uint32;
      }

      leaf endpoint {
        description "Endpoint that contains all the package-related data";
        type string;
      }
    }
  }
}