| 1090 | |
| 1091 | |
| 1092 | Try<Resources> getConsumedResources(const Offer::Operation& operation) |
| 1093 | { |
| 1094 | switch (operation.type()) { |
| 1095 | case Offer::Operation::CREATE_DISK: |
| 1096 | return operation.create_disk().source(); |
| 1097 | case Offer::Operation::DESTROY_DISK: |
| 1098 | return operation.destroy_disk().source(); |
| 1099 | case Offer::Operation::RESERVE: |
| 1100 | case Offer::Operation::UNRESERVE: |
| 1101 | case Offer::Operation::CREATE: |
| 1102 | case Offer::Operation::DESTROY: |
| 1103 | case Offer::Operation::GROW_VOLUME: |
| 1104 | case Offer::Operation::SHRINK_VOLUME: { |
| 1105 | Try<vector<ResourceConversion>> conversions = |
| 1106 | getResourceConversions(operation); |
| 1107 | |
| 1108 | if (conversions.isError()) { |
| 1109 | return Error(conversions.error()); |
| 1110 | } |
| 1111 | |
| 1112 | Resources consumed; |
| 1113 | foreach (const ResourceConversion& conversion, conversions.get()) { |
| 1114 | consumed += conversion.consumed; |
| 1115 | } |
| 1116 | |
| 1117 | return consumed; |
| 1118 | } |
| 1119 | case Offer::Operation::LAUNCH: |
| 1120 | case Offer::Operation::LAUNCH_GROUP: |
| 1121 | // TODO(bbannier): Consider adding support for 'LAUNCH' and |
| 1122 | // 'LAUNCH_GROUP' operations. |
| 1123 | case Offer::Operation::UNKNOWN: |
| 1124 | return Error("Unsupported operation"); |
| 1125 | } |
| 1126 | |
| 1127 | UNREACHABLE(); |
| 1128 | } |
| 1129 | |
| 1130 | |
| 1131 | namespace slave { |