/*
  Copyright 2020 Whitestack LLC

  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.
*/

module scaling {
    yang-version 1.1;
    namespace "urn:etsi:osm:yang:augments:scaling";
    prefix "scaling";

    import etsi-nfv-vnfd {
        prefix vnfd;
    }

    import common-augments {
        prefix common;
    }

    import day1-2 {
        prefix day1-2;
    }

    grouping extended-scaling {
        list scaling-policy {

            key "name";

            leaf name {
                description
                  "Name of the scaling policy";
                type string;
            }

            leaf scaling-type {
                description
                  "Type of scaling";
                type common:scaling-policy-type;
            }

            leaf enabled {
                description
                  "Specifies if the scaling policy can be applied";
                type boolean;
                default true;
            }

            leaf scale-in-operation-type {
                description
                  "Operation to be applied to check between scaling criterias to
                   check if the scale in threshold condition has been met.
                   Defaults to AND";
                type common:scaling-criteria-operation;
                default AND;
            }

            leaf scale-out-operation-type {
                description
                  "Operation to be applied to check between scaling criterias to
                   check if the scale out threshold condition has been met.
                   Defauls to OR";
                type common:scaling-criteria-operation;
                default OR;
            }

            leaf threshold-time {
                description
                  "The duration for which the criteria must hold true";
                type uint32;
                mandatory true;
            }

            leaf cooldown-time {
                description
                  "The duration after a scaling-in/scaling-out action has been
                   triggered, for which there will be no further optional";
                type uint32;
                mandatory true;
            }

            list scaling-criteria {
                description
                  "list of conditions to be met for generating scaling
                     requests";
                key "name";

                leaf name {
                    type string;
                }

                leaf scale-in-threshold {
                    description
                      "Value below which scale-in requests are generated";
                    type decimal64{
                        fraction-digits 10;
                    }
                }

                leaf scale-in-relational-operation {
                    description
                      "The relational operator used to compare the monitoring param
                       against the scale-in-threshold.";
                    type common:relational-operation-type;
                    default LE;
                }

                leaf scale-out-threshold {
                    description
                      "Value above which scale-out requests are generated";
                    type decimal64{
                        fraction-digits 10;
                    }
                }

                leaf scale-out-relational-operation {
                    description
                      "The relational operator used to compare the monitoring param
                       against the scale-out-threshold.";
                    type common:relational-operation-type;
                    default GE;
                }

                leaf vnf-monitoring-param-ref {
                    description
                      "Reference to the VNF level monitoring parameter
                       that is aggregated";
                    type string;
                    
                }
            }
        }

        list scaling-config-action {
            description
              "List of scaling config actions";
            key "trigger";

            leaf trigger {
                description
                  "scaling trigger";
                type common:scaling-trigger;
            }

            leaf vnf-config-primitive-name-ref {
                description
                  "Reference to the VNF config primitive";
                type leafref {
                    path "/vnfd:vnfd/vnfd:df/vnfd:lcm-operations-configuration/vnfd:operate-vnf-op-config/day1-2:day1-2/day1-2:config-primitive/day1-2:name";
                }
            }
        }
    }

    augment "/vnfd:vnfd/vnfd:df/vnfd:scaling-aspect" {
        uses extended-scaling;
    }
}
