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