1 # Copyright 2012 OpenStack Foundation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
19 from escalatorclient.common import utils
20 from escalatorclient.openstack.common.apiclient import base
23 'cluster_id', 'version_id', 'version_patch_id', 'hosts',
24 'update_object', 'update_script')
26 OS_REQ_ID_HDR = 'x-openstack-request-id'
29 class Update(base.Resource):
31 return "<Update %s>" % self._info
33 def update(self, **fields):
34 self.manager.update(self, **fields)
36 def data(self, **kwargs):
37 return self.manager.data(self, **kwargs)
40 class UpdateManager(base.ManagerWithFind):
41 resource_class = Update
43 def _Update_meta_to_headers(self, fields):
45 fields_copy = copy.deepcopy(fields)
47 # NOTE(flaper87): Convert to str, headers
48 # that are not instance of basestring. All
49 # headers will be encoded later, before the
52 for key, value in six.iteritems(fields_copy):
53 headers['%s' % key] = utils.to_str(value)
57 def _format_update_meta_for_user(meta):
58 for key in ['size', 'min_ram', 'min_disk']:
61 meta[key] = int(meta[key]) if meta[key] else 0
66 def list(self, **kwargs):
69 def query_progress(self, **kwargs):
72 if field in CREATE_PARAMS:
73 fields[field] = kwargs[field]
75 msg = 'update() got an unexpected argument \'%s\''
76 raise TypeError(msg % field)
78 if "cluster" in fields:
79 url = '/v1/update/%s' % fields['cluster_id']
81 resp, body = self.client.get(url)
82 return Update(self, self._format_update_meta_for_user(body))
84 def update(self, **kwargs):
87 TODO(bcwaldon): document accepted params
92 if field in CREATE_PARAMS:
93 fields[field] = kwargs[field]
94 elif field == 'return_req_id':
97 msg = 'update() got an unexpected argument \'%s\''
98 raise TypeError(msg % field)
100 if "cluster_id" in fields:
101 url = '/v1/update/%s' % fields['cluster_id']
103 hdrs = self._Update_meta_to_headers(fields)
104 resp, body = self.client.post(url, headers=None, data=hdrs)
105 return Update(self, self._format_update_meta_for_user(body))