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 iana-crypt-hash { prefix ianach; }
14   import ietf-inet-types { prefix inet; }
15   import ietf-yang-types { prefix yang; }
16   import opnfv-promise-vim { prefix vim; }
17
18   feature multi-provider {
19     description "";
20   }
21
22   description
23     "OPNFV Promise Resource Reservation/Allocation controller module";
24
25   revision 2015-04-16 {
26     description "Initial revision.";
27   }
28
29   revision 2015-08-06 {
30     description "Updated to incorporate YangForge framework";
31   }
32
33   grouping resource-capacity {
34     container capacity {
35       container quota { description 'Conceptual container that should be extended'; }
36       container usage { description 'Conceptual container that should be extended';
37                         config false; }
38       container reserved { description 'Conceptual container that should be extended';
39                            config false; }
40       container available { description 'Conceptual container that should be extended';
41                             config false; }
42     }
43   }
44
45   grouping compute-capacity {
46     leaf cores { type number; }
47     leaf ram { type number; }
48     leaf instances { type number; }
49   }
50
51   grouping networking-capacity {
52     leaf network { type number; }
53     leaf port { type number; }
54     leaf router { type number; }
55     leaf subnet { type number; }
56     leaf address { type number; }
57   }
58
59   ct:complex-type ResourceReservation {
60     ct:extends vim:ResourceElement;
61
62     description
63       "Contains the capacities of various resource services being reserved
64        along with any resource elements needed to be available at
65        the time of allocation(s).";
66
67     reference "OPNFV-PROMISE, Section 3.4.1";
68
69     leaf start { type yang:date-and-time; }
70     leaf end   { type yang:date-and-time; }
71     leaf expiry {
72       description "Duration in seconds from start when unallocated reserved resources
73                    will be released back into the pool";
74       type number; units "seconds";
75     }
76     leaf zone { type instance-identifier { ct:instance-type vim:AvailabilityZone; } }
77     container capacity {
78       uses vim:compute-capacity;
79       uses vim:networking-capcity;
80       uses vim:storage-capacity;
81     }
82     leaf-list resources {
83       description
84         "Reference to a collection of existing resource elements required by
85          this reservation. It can contain any instance derived from
86          ResourceElement, such as ServerInstances or even other
87          ResourceReservations. If the ResourceReservation request is
88          accepted, the ResourceElement(s) listed here will be placed
89          into 'protected' mode as to prevent accidental delete.";
90       type instance-identifier {
91         ct:instance-type vim:ResourceElement;
92       }
93       // following 'must' statement applies to each element
94       must "boolean(/provider/elements/*[@id=id])" {
95         error-message "One or more of the ResourceElement(s) does not exist in
96                        the provider to be reserved";
97       }
98     }
99
100     leaf provider {
101       if-feature multi-provider;
102       config false;
103
104       description
105         "Reference to a specified existing provider from which this reservation
106          will be drawn if used in the context of multi-provider
107          environment.";
108       type instance-identifier {
109         ct:instance-type vim:ResourceProvider;
110         require-instance true;
111       }
112     }
113
114     container remaining {
115       config false;
116       description
117         "Provides visibility into total remaining capacity for this
118          reservation based on allocations that took effect utilizing
119          this reservation ID as a reference.";
120
121       uses vim:compute-capacity;
122       uses vim:networking-capcity;
123       uses vim:storage-capacity;
124     }
125
126     leaf-list allocations {
127       config false;
128       description
129         "Reference to a collection of consumed allocations referencing
130          this reservation.";
131       type instance-identifier {
132         ct:instance-type ResourceAllocation;
133       }
134     }
135   }
136
137   ct:complex-type ResourceAllocation {
138     ct:extends vim:ResourceElement;
139
140     description
141        "Contains a list of resources to be allocated with optional reference
142        to an existing reservation.
143
144        If reservation is specified but this request is received prior
145        to reservation start timestamp, then it will be rejected unless
146        'allocate-on-start' is set to true.  'allocate-on-start' allows
147        the allocation to be auto-initiated and scheduled to run in the
148        future.
149
150        The 'priority' state indicates the classification for dealing
151        with resource starvation scenarios. Lower priority allocations
152        will be forcefully terminated to allow for higher priority
153        allocations to be fulfilled.
154
155        Allocations without reference to an existing reservation will
156        receive the lowest priority.";
157
158     reference "OPNFV-PROMISE, Section 3.4.3";
159
160     leaf reservation {
161       description "Reference to an existing reservation identifier";
162
163       type instance-identifier {
164         ct:instance-type ResourceReservation;
165         require-instance true;
166       }
167     }
168
169     leaf allocate-on-start {
170       description
171        "If 'allocate-on-start' is set to true, the 'planned' allocations will
172        take effect automatically at the reservation 'start' date/time.";
173       type boolean; default false;
174     }
175
176     ct:instance-list resources {
177       description "Contains list of new ResourceElements that will be allocated";
178       ct:instance-type vim:ResourceElement;
179     }
180
181     leaf priority {
182       description
183         "Reflects current priority level of the allocation according to classification rules";
184       type number;
185       config false;
186     }
187   }
188
189   // MAIN CONTAINER
190   container promise {
191     ct:instance-list providers {
192       description "Aggregate collection of all registered ResourceProvider instances";
193       ct:instance-type vim:ResourceProvider;
194       config false;
195
196      // augment compute container with capacity elements
197      augment "compute" {
198        uses resource-capacity {
199          augment "capacity/quota" { uses compute-capacity; }
200          augment "capacity/usage" { uses compute-capacity; }
201          augment "capacity/reserved" { uses compute-capacity; }
202          augment "capacity/available" { uses compute-capacity; }
203        }
204      }
205
206      // augment networking container with capacity elements
207      augment "networking" {
208        uses resource-capacity {
209          if-feature has-networking-capacity;
210          augment "capacity/quota" { uses networking-capacity; }
211          augment "capacity/usage" { uses networking-capacity; }
212          augment "capacity/reserved" { uses networking-capacity; }
213          augment "capacity/available" { uses networking-capacity; }
214        }
215      }
216
217      // track references to reservations for this resource provider
218      leaf-list reservations {
219        type instance-identifier {
220          ct:instance-type ResourceReservation;
221        }
222      }
223     }
224
225     ct:instance-list reservations {
226       description "Aggregate collection of all registered ResourceReservation instances";
227       ct:instance-type ResourceReservation;
228     }
229
230     ct:instance-list allocations {
231       description "Aggregate collection of all active ResourceAllocation instances";
232       ct:instance-type ResourceAllocation;
233     }
234   }
235
236   rpc add-provider {
237     description "This operation allows you to register a new ResourceProvider
238                  into promise management service";
239     input {
240       leaf provider {
241         description "Select a specific resource provider";
242         mandatory true;
243         type enumeration {
244           enum openstack;
245           enum hp;
246           enum rackspace;
247           enum amazon {
248             status planned;
249           }
250           enum joyent {
251             status planned;
252           }
253           enum azure {
254             status planned;
255           }
256         }
257       }
258       leaf username {
259         type string;
260         mandatory true;
261       }
262       leaf password {
263         type ianach:crypt-hash;
264         mandatory true;
265       }
266       leaf endpoint {
267         type inet:uri;
268         description "The target URL endpoint for the resource provider";
269         mandatory true;
270       }
271       leaf region {
272         type string;
273         description "Optional specified regsion for the provider";
274       }
275     }
276     output {
277       leaf id {
278         description "Unique identifier for the newly added provider found in /promise/providers";
279         type instance-identifier {
280           ct:instance-type ResourceProvider;
281         }
282       }
283       leaf result {
284         type enumeration {
285           enum success;
286           enum error;
287         }
288       }
289     }
290   }
291   rpc remove-provider;
292   rpc list-providers;
293
294   rpc check-capacity;
295
296   rpc list-reservations;
297   rpc create-reservation;
298   rpc update-reservation;
299   rpc cancel-reservation;
300
301   rpc list-allocations;
302   rpc create-allocation;
303
304   notification reservation-event;
305   notification capacity-event;
306   notification allocation-event;
307   }