1
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2
# not use this file except in compliance with the License. You may obtain
3
# a copy of the License at
5
# http://www.apache.org/licenses/LICENSE-2.0
7
# Unless required by applicable law or agreed to in writing, software
8
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
# License for the specific language governing permissions and limitations
16
from django.utils.translation import ugettext_lazy as _
18
from horizon import exceptions
19
from horizon import forms
20
from horizon import messages
22
from openstack_dashboard import api
25
class UpdateMetadataForm(forms.SelfHandlingForm):
27
def handle(self, request, data):
28
id = self.initial['id']
29
old_metadata = self.initial['metadata']
32
new_metadata = json.loads(self.data['metadata'])
35
(item['key'], str(item['value']))
36
for item in new_metadata
38
api.nova.flavor_extra_set(request, id, metadata)
40
remove_keys = [key for key in old_metadata if key not in metadata]
42
api.nova.flavor_extra_delete(request, id, remove_keys)
44
message = _('Metadata successfully updated.')
45
messages.success(request, message)
47
exceptions.handle(request,
48
_('Unable to update the flavor metadata.'))