summaryrefslogtreecommitdiff
path: root/web-server/opendc/api/v2/portfolios/portfolioId/scenarios/endpoint.py
blob: ab32aae2551a21323ce5799adca57b01e6cbddf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from opendc.models.portfolio import Portfolio
from opendc.util.rest import Response


def POST(request):
    """Add a new Scenario for this Portfolio."""

    request.check_required_parameters(path={'portfolioId': 'string'},
                                      body={
                                          'scenario': {
                                              'name': 'string',
                                              'trace': {
                                                  'traceId': 'string',
                                                  'loadSamplingFraction': 'float',
                                              },
                                              'topology': {
                                                  'topologyId': 'string',
                                              },
                                              'operational': {
                                                  'failuresEnabled': 'bool',
                                                  'performanceInterferenceEnabled': 'bool',
                                                  'schedulerName': 'string',
                                              },
                                          }
                                      })

    portfolio = Portfolio.from_id(request.params_path['portfolioId'])

    portfolio.check_exists()
    portfolio.check_user_access(request.google_id, True)

    scenario = Portfolio(request.params_body['scenario'])

    scenario.set_property('portfolioId', request.params_path['portfolioId'])
    scenario.set_property('simulationState', 'QUEUED')

    scenario.insert()

    portfolio.obj['portfolioIds'].append(portfolio.get_id())
    portfolio.update()

    return Response(200, 'Successfully added Portfolio.', portfolio.obj)