Add license to the release documentation and requirements doc
[promise.git] / docs / requirements / schemas.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3
4 .. _yang_schema:
5
6 ANNEX B: Promise YANG schema based on YangForge
7 ===============================================
8
9 .. code::
10
11   module opnfv-promise {
12   namespace "urn:opnfv:promise";
13   prefix promise;
14
15   import complex-types { prefix ct; }
16   import ietf-yang-types { prefix yang; }
17   import ietf-inet-types { prefix inet; }
18   import access-control-models { prefix acm; }
19   import nfv-infrastructure { prefix nfvi; }
20   import nfv-mano { prefix mano; }
21
22   description
23     "OPNFV Promise Resource Reservation/Allocation controller module";
24
25   revision 2015-10-05 {
26     description "Complete coverage of reservation related intents";
27   }
28
29   revision 2015-08-06 {
30     description "Updated to incorporate YangForge framework";
31   }
32
33   revision 2015-04-16 {
34     description "Initial revision.";
35   }
36
37   feature reservation-service {
38     description "When enabled, provides resource reservation service";
39   }
40
41   feature multi-provider {
42     description "When enabled, provides resource management across multiple providers";
43   }
44
45   typedef reference-identifier {
46     description "defines valid formats for external reference id";
47     type union {
48       type yang:uuid;
49       type inet:uri;
50       type uint32;
51     }
52   }
53
54   grouping resource-utilization {
55     container capacity {
56       container total     { description 'Conceptual container that should be extended'; }
57       container reserved  { description 'Conceptual container that should be extended';
58                             config false; }
59       container usage     { description 'Conceptual container that should be extended';
60                             config false; }
61       container available { description 'Conceptual container that should be extended';
62                             config false; }
63     }
64   }
65
66   grouping temporal-resource-collection {
67     description
68       "Information model capturing resource-collection with start/end time window";
69
70     leaf start { type yang:date-and-time; }
71     leaf end   { type yang:date-and-time; }
72
73     uses nfvi:resource-collection;
74   }
75
76   grouping resource-usage-request {
77     description
78       "Information model capturing available parameters to make a resource
79        usage request.";
80     reference "OPNFV-PROMISE, Section 3.4.1";
81
82     uses temporal-resource-collection {
83       refine elements {
84         description
85           "Reference to a list of 'pre-existing' resource elements that are
86          required for fulfillment of the resource-usage-request.
87
88          It can contain any instance derived from ResourceElement,
89          such as ServerInstances or even other
90          ResourceReservations. If the resource-usage-request is
91          accepted, the ResourceElement(s) listed here will be placed
92          into 'protected' mode as to prevent accidental removal.
93
94          If any of these resource elements become 'unavailable' due to
95          environmental or administrative activity, a notification will
96          be issued informing of the issue.";
97       }
98     }
99
100     leaf zone {
101       description "Optional identifier to an Availability Zone";
102       type instance-identifier { ct:instance-type nfvi:AvailabilityZone; }
103     }
104   }
105
106   grouping query-start-end-window {
107     container window {
108       description "Matches entries that are within the specified start/end time window";
109       leaf start { type yang:date-and-time; }
110       leaf end   { type yang:date-and-time; }
111       leaf scope {
112         type enumeration {
113           enum "exclusive" {
114             description "Matches entries that start AND end within the window";
115           }
116           enum "inclusive" {
117             description "Matches entries that start OR end within the window";
118           }
119         }
120         default "inclusive";
121       }
122     }
123   }
124
125   grouping query-resource-collection {
126     uses query-start-end-window {
127       description "Match for ResourceCollection(s) that are within the specified
128                    start/end time window";
129     }
130     leaf-list without {
131       description "Excludes specified collection identifiers from the result";
132       type instance-identifier { ct:instance-type ResourceCollection; }
133     }
134     leaf show-utilization { type boolean; default true; }
135     container elements {
136       leaf-list some {
137         description "Query for ResourceCollection(s) that contain some or more of
138                      these element(s)";
139         type instance-identifier { ct:instance-type nfvi:ResourceElement; }
140       }
141       leaf-list every {
142         description "Query for ResourceCollection(s) that contain all of
143                      these element(s)";
144         type instance-identifier { ct:instance-type nfvi:ResourceElement; }
145       }
146     }
147   }
148
149   grouping common-intent-output {
150     leaf result {
151       type enumeration {
152         enum "ok";
153         enum "conflict";
154         enum "error";
155       }
156     }
157     leaf message { type string; }
158   }
159
160   grouping utilization-output {
161     list utilization {
162       key 'timestamp';
163       leaf timestamp { type yang:date-and-time; }
164       leaf count { type int16; }
165       container capacity { uses nfvi:resource-capacity; }
166     }
167   }
168
169   ct:complex-type ResourceCollection {
170     ct:extends nfvi:ResourceContainer;
171     ct:abstract true;
172
173     description
174       "Describes an abstract ResourceCollection data model, which represents
175        a grouping of capacity and elements available during a given
176        window in time which must be extended by other resource
177        collection related models";
178
179     leaf start { type yang:date-and-time; }
180     leaf end   { type yang:date-and-time; }
181
182     leaf active {
183       config false;
184       description
185         "Provides current state of this record whether it is enabled and within
186          specified start/end time";
187       type boolean;
188     }
189   }
190
191   ct:complex-type ResourcePool {
192     ct:extends ResourceCollection;
193
194     description
195       "Describes an instance of an active ResourcePool record, which
196        represents total available capacity and elements from a given
197        source.";
198
199     leaf source {
200       type instance-identifier {
201         ct:instance-type nfvi:ResourceContainer;
202         require-instance true;
203       }
204       mandatory true;
205     }
206
207     refine elements {
208       // following 'must' statement applies to each element
209       // NOTE: just a non-working example for now...
210       must "boolean(/source/elements/*[@id=id])" {
211         error-message "One or more of the ResourceElement(s) does not exist in
212                        the provider to be reserved";
213       }
214     }
215   }
216
217   ct:complex-type ResourceReservation {
218     ct:extends ResourceCollection;
219
220     description
221       "Describes an instance of an accepted resource reservation request,
222        created usually as a result of 'create-reservation' request.
223
224        A ResourceReservation is a derived instance of a generic
225        ResourceCollection which has additional parameters to map the
226        pool(s) that were referenced to accept this reservation as well
227        as to track allocations made referencing this reservation.
228
229        Contains the capacities of various resource attributes being
230        reserved along with any resource elements that are needed to be
231        available at the time of allocation(s).";
232
233     reference "OPNFV-PROMISE, Section 3.4.1";
234
235     leaf created-on  { type yang:date-and-time; config false; }
236     leaf modified-on { type yang:date-and-time; config false; }
237
238     leaf-list pools {
239       config false;
240       description
241         "Provides list of one or more pools that were referenced for providing
242          the requested resources for this reservation.  This is an
243          important parameter for informing how/where allocation
244          requests can be issued using this reservation since it is
245          likely that the total reserved resource capacity/elements are
246          made availble from multiple sources.";
247       type instance-identifier {
248         ct:instance-type ResourcePool;
249         require-instance true;
250       }
251     }
252
253     container remaining {
254       config false;
255       description
256         "Provides visibility into total remaining capacity for this
257          reservation based on allocations that took effect utilizing
258          this reservation ID as a reference.";
259
260       uses nfvi:resource-capacity;
261     }
262
263     leaf-list allocations {
264       config false;
265       description
266         "Reference to a collection of consumed allocations referencing
267          this reservation.";
268       type instance-identifier {
269         ct:instance-type ResourceAllocation;
270         require-instance true;
271       }
272     }
273   }
274
275   ct:complex-type ResourceAllocation {
276     ct:extends ResourceCollection;
277
278     description
279       "A ResourceAllocation record denotes consumption of resources from a
280        referenced ResourcePool.
281
282        It does not reflect an accepted request but is created to
283        represent the actual state about the ResourcePool. It is
284        created once the allocation(s) have successfully taken effect
285        on the 'source' of the ResourcePool.
286
287        The 'priority' state indicates the classification for dealing
288        with resource starvation scenarios. Lower priority allocations
289        will be forcefully terminated to allow for higher priority
290        allocations to be fulfilled.
291
292        Allocations without reference to an existing reservation will
293        receive the lowest priority.";
294
295     reference "OPNFV-PROMISE, Section 3.4.3";
296
297     leaf reservation {
298       description "Reference to an existing reservation identifier (optional)";
299
300       type instance-identifier {
301         ct:instance-type ResourceReservation;
302         require-instance true;
303       }
304     }
305
306     leaf pool {
307       description "Reference to an existing resource pool from which allocation is drawn";
308
309       type instance-identifier {
310         ct:instance-type ResourcePool;
311         require-instance true;
312       }
313     }
314
315     container instance-ref {
316       config false;
317       description
318         "Reference to actual instance identifier of the provider/server
319         for this allocation";
320       leaf provider {
321         type instance-identifier { ct:instance-type ResourceProvider; }
322       }
323       leaf server { type yang:uuid; }
324     }
325
326     leaf priority {
327       config false;
328       description
329         "Reflects current priority level of the allocation according to
330          classification rules";
331       type enumeration {
332         enum "high"   { value 1; }
333         enum "normal" { value 2; }
334         enum "low"    { value 3; }
335       }
336       default "normal";
337     }
338   }
339
340   ct:complex-type ResourceProvider {
341     ct:extends nfvi:ResourceContainer;
342
343     key "name";
344     leaf token { type string; mandatory true; }
345
346     container services { // read-only
347       config false;
348       container compute {
349         leaf endpoint { type inet:uri; }
350         ct:instance-list flavors { ct:instance-type nfvi:ComputeFlavor; }
351       }
352     }
353
354     leaf-list pools {
355       config false;
356       description
357         "Provides list of one or more pools that are referencing this provider.";
358
359       type instance-identifier {
360         ct:instance-type ResourcePool;
361         require-instance true;
362       }
363     }
364   }
365
366   // MAIN CONTAINER
367   container promise {
368
369     uses resource-utilization {
370       description "Describes current state info about capacity utilization info";
371
372       augment "capacity/total"     { uses nfvi:resource-capacity; }
373       augment "capacity/reserved"  { uses nfvi:resource-capacity; }
374       augment "capacity/usage"     { uses nfvi:resource-capacity; }
375       augment "capacity/available" { uses nfvi:resource-capacity; }
376     }
377
378     ct:instance-list providers {
379       if-feature multi-provider;
380       description "Aggregate collection of all registered ResourceProvider instances
381                    for Promise resource management service";
382       ct:instance-type ResourceProvider;
383     }
384
385     ct:instance-list pools {
386       if-feature reservation-service;
387       description "Aggregate collection of all ResourcePool instances";
388       ct:instance-type ResourcePool;
389     }
390
391     ct:instance-list reservations {
392       if-feature reservation-service;
393       description "Aggregate collection of all ResourceReservation instances";
394       ct:instance-type ResourceReservation;
395     }
396
397     ct:instance-list allocations {
398       description "Aggregate collection of all ResourceAllocation instances";
399       ct:instance-type ResourceAllocation;
400     }
401
402     container policy {
403       container reservation {
404         leaf max-future-start-range {
405           description
406             "Enforce reservation request 'start' time is within allowed range from now";
407           type uint16 { range 0..365; }
408           units "days";
409         }
410         leaf max-future-end-range {
411           description
412             "Enforce reservation request 'end' time is within allowed range from now";
413           type uint16 { range 0..365; }
414           units "days";
415         }
416         leaf max-duration {
417           description
418             "Enforce reservation duration (end-start) does not exceed specified threshold";
419           type uint16;
420           units "hours";
421           default 8760; // for now cap it at max one year as default
422         }
423         leaf expiry {
424           description
425             "Duration in minutes from start when unallocated reserved resources
426              will be released back into the pool";
427           type uint32;
428           units "minutes";
429         }
430       }
431     }
432   }
433
434   //-------------------
435   // INTENT INTERFACE
436   //-------------------
437
438   // RESERVATION INTENTS
439   rpc create-reservation {
440     if-feature reservation-service;
441     description "Make a request to the reservation system to reserve resources";
442     input {
443       uses resource-usage-request;
444     }
445     output {
446       uses common-intent-output;
447       leaf reservation-id {
448         type instance-identifier { ct:instance-type ResourceReservation; }
449       }
450     }
451   }
452
453   rpc update-reservation {
454     description "Update reservation details for an existing reservation";
455     input {
456       leaf reservation-id {
457         type instance-identifier {
458           ct:instance-type ResourceReservation;
459           require-instance true;
460         }
461         mandatory true;
462       }
463       uses resource-usage-request;
464     }
465     output {
466       uses common-intent-output;
467     }
468   }
469
470   rpc cancel-reservation {
471     description "Cancel the reservation and be a good steward";
472     input {
473       leaf reservation-id {
474         type instance-identifier { ct:instance-type ResourceReservation; }
475         mandatory true;
476       }
477     }
478     output {
479       uses common-intent-output;
480     }
481   }
482
483   rpc query-reservation {
484     if-feature reservation-service;
485     description "Query the reservation system to return matching reservation(s)";
486     input {
487       leaf zone { type instance-identifier { ct:instance-type nfvi:AvailabilityZone; } }
488       uses query-resource-collection;
489     }
490     output {
491       leaf-list reservations { type instance-identifier
492                                { ct:instance-type ResourceReservation; } }
493       uses utilization-output;
494     }
495   }
496
497   // CAPACITY INTENTS
498   rpc increase-capacity {
499     description "Increase total capacity for the reservation system
500                  between a window in time";
501     input {
502       uses temporal-resource-collection;
503       leaf source {
504         type instance-identifier {
505           ct:instance-type nfvi:ResourceContainer;
506         }
507       }
508     }
509     output {
510       uses common-intent-output;
511       leaf pool-id {
512         type instance-identifier { ct:instance-type ResourcePool; }
513       }
514     }
515   }
516
517   rpc decrease-capacity {
518     description "Decrease total capacity for the reservation system
519                  between a window in time";
520     input {
521       uses temporal-resource-collection;
522       leaf source {
523         type instance-identifier {
524           ct:instance-type nfvi:ResourceContainer;
525         }
526       }
527     }
528     output {
529       uses common-intent-output;
530       leaf pool-id {
531         type instance-identifier { ct:instance-type ResourcePool; }
532       }
533     }
534   }
535
536   rpc query-capacity {
537     description "Check available capacity information about a specified
538                  resource collection";
539     input {
540       leaf capacity {
541         type enumeration {
542           enum 'total';
543           enum 'reserved';
544           enum 'usage';
545           enum 'available';
546         }
547         default 'available';
548       }
549       leaf zone { type instance-identifier { ct:instance-type nfvi:AvailabilityZone; } }
550       uses query-resource-collection;
551       // TBD: additional parameters for query-capacity
552     }
553     output {
554       leaf-list collections { type instance-identifier
555                               { ct:instance-type ResourceCollection; } }
556       uses utilization-output;
557     }
558   }
559
560   // ALLOCATION INTENTS (should go into VIM module in the future)
561   rpc create-instance {
562     description "Create an instance of specified resource(s) utilizing capacity
563                  from the pool";
564     input {
565       leaf provider-id {
566         if-feature multi-provider;
567         type instance-identifier { ct:instance-type ResourceProvider;
568                                    require-instance true; }
569       }
570       leaf name   { type string; mandatory true; }
571       leaf image  {
572         type reference-identifier;
573         mandatory true;
574       }
575       leaf flavor {
576         type reference-identifier;
577         mandatory true;
578       }
579       leaf-list networks {
580         type reference-identifier;
581         description "optional, will assign default network if not provided";
582       }
583
584       // TODO: consider supporting a template-id (such as HEAT) for more complex instantiation
585
586       leaf reservation-id {
587         type instance-identifier { ct:instance-type ResourceReservation;
588                                    require-instance true; }
589       }
590     }
591     output {
592       uses common-intent-output;
593       leaf instance-id {
594         type instance-identifier { ct:instance-type ResourceAllocation; }
595       }
596     }
597   }
598
599   rpc destroy-instance {
600     description "Destroy an instance of resource utilization and release it
601                  back to the pool";
602     input {
603       leaf instance-id {
604         type instance-identifier { ct:instance-type ResourceAllocation;
605                                    require-instance true; }
606       }
607     }
608     output {
609       uses common-intent-output;
610     }
611   }
612
613   // PROVIDER INTENTS (should go into VIM module in the future)
614   rpc add-provider {
615     description "Register a new resource provider into reservation system";
616     input {
617       leaf provider-type {
618         description "Select a specific resource provider type";
619         mandatory true;
620         type enumeration {
621           enum openstack;
622           enum hp;
623           enum rackspace;
624           enum amazon {
625             status planned;
626           }
627           enum joyent {
628             status planned;
629           }
630           enum azure {
631             status planned;
632           }
633         }
634         default openstack;
635       }
636       uses mano:provider-credentials {
637         refine endpoint {
638           default "http://localhost:5000/v2.0/tokens";
639         }
640       }
641       container tenant {
642         leaf id { type string; }
643         leaf name { type string; }
644       }
645     }
646     output {
647       uses common-intent-output;
648       leaf provider-id {
649         type instance-identifier { ct:instance-type ResourceProvider; }
650       }
651     }
652   }
653
654   // TODO...
655   notification reservation-event;
656   notification capacity-event;
657   notification allocation-event;
658   }