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