support all cluster update option
[escalator.git] / api / escalator / api / v1 / install.py
1 # Copyright 2013 OpenStack Foundation
2 # All Rights Reserved.
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 #    not use this file except in compliance with the License. You may obtain
6 #    a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 #    License for the specific language governing permissions and limitations
14 #    under the License.
15
16
17 """
18 /hosts endpoint for Daisy v1 API
19 """
20
21 from oslo_log import log as logging
22 from webob.exc import HTTPBadRequest
23
24 from escalator import i18n
25 from escalator import notifier
26
27 from escalator.api import policy
28 import escalator.api.v1
29 from escalator.common import exception
30 from escalator.common import utils
31 from escalator.common import wsgi
32 from escalator.api.v1 import controller
33 import escalator.installer.daisy.api as daisy_api
34
35 LOG = logging.getLogger(__name__)
36 _ = i18n._
37 _LE = i18n._LE
38 _LI = i18n._LI
39 _LW = i18n._LW
40 SUPPORTED_PARAMS = escalator.api.v1.SUPPORTED_PARAMS
41 SUPPORTED_FILTERS = escalator.api.v1.SUPPORTED_FILTERS
42 ACTIVE_IMMUTABLE = escalator.api.v1.ACTIVE_IMMUTABLE
43
44
45 # if some backends have order constraint, please add here
46 # if backend not in the next three order list, we will be
47 # think it does't have order constraint.
48 BACKENDS_INSTALL_ORDER = ['proton', 'zenic', 'tecs', 'kolla']
49 BACKENDS_UPGRADE_ORDER = ['proton', 'zenic', 'tecs', 'kolla']
50 BACKENDS_UNINSTALL_ORDER = []
51
52
53 class InstallTask(object):
54
55     """
56     Class for install OS and TECS.
57     """
58     """ Definition for install states."""
59
60     def __init__(self, req, cluster_id, skip_pxe_ipmi):
61         self.req = req
62         self.cluster_id = cluster_id
63         self.skip_pxe_ipmi = skip_pxe_ipmi
64
65
66 class Controller(controller.BaseController):
67
68     """
69     WSGI controller for hosts resource in Daisy v1 API
70
71     The hosts resource API is a RESTful web service for host data. The API
72     is as follows::
73
74         GET  /hosts -- Returns a set of brief metadata about hosts
75         GET  /hosts/detail -- Returns a set of detailed metadata about
76                               hosts
77         HEAD /hosts/<ID> -- Return metadata about an host with id <ID>
78         GET  /hosts/<ID> -- Return host data for host with id <ID>
79         POST /hosts -- Store host data and return metadata about the
80                         newly-stored host
81         PUT  /hosts/<ID> -- Update host metadata and/or upload host
82                             data for a previously-reserved host
83         DELETE /hosts/<ID> -- Delete the host with id <ID>
84     """
85
86     def __init__(self):
87         self.notifier = notifier.Notifier()
88         self.policy = policy.Enforcer()
89
90     @utils.mutating
91     def update_cluster(self, req, cluster_id, install_meta):
92         """
93         upgrade cluster.
94         """
95         self._enforce(req, 'update_cluster')
96         try:
97             status = daisy_api.update(req.context)
98         except exception.Invalid as e:
99             raise HTTPBadRequest(explanation=e.msg, request=req)
100         return status
101
102
103 class InstallDeserializer(wsgi.JSONRequestDeserializer):
104     """Handles deserialization of specific controller method requests."""
105
106     def _deserialize(self, request):
107         result = {}
108         result["install_meta"] = utils.get_dict_meta(request)
109         return result
110
111     def update_cluster(self, request):
112         return self._deserialize(request)
113
114
115 class InstallSerializer(wsgi.JSONResponseSerializer):
116     """Handles serialization of specific controller method responses."""
117
118     def __init__(self):
119         self.notifier = notifier.Notifier()
120
121     def update_cluster(self, response, result):
122         response.status = 201
123         response.headers['Content-Type'] = 'application/json'
124         response.body = self.to_json(result)
125         return response
126
127
128 def create_resource():
129     """Image members resource factory method"""
130     deserializer = InstallDeserializer()
131     serializer = InstallSerializer()
132     return wsgi.Resource(Controller(), deserializer, serializer)