4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain 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,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # pylint: disable=invalid-name, missing-docstring, too-few-public-methods,
17 # pylint: disable=logging-not-lazy, too-many-locals
22 from cmframework.apis import cmvalidator
23 from cmdatahandlers.api import validation
26 class OpenstackValidationError(validation.ValidationError):
30 class OpenstackValidation(cmvalidator.CMValidator):
31 domain = "cloud.openstack"
33 def get_subscription_info(self): # pylint: disable=no-self-use
34 logging.debug('get_subscription info called')
35 return r'^cloud\.openstack$'
37 def validate_set(self, dict_key_value):
38 logging.debug('validate_set called with %s' % str(dict_key_value))
40 client = self.get_plugin_client()
42 for key, value in dict_key_value.iteritems():
44 value_dict = json.loads(value_str)
46 if key == self.domain:
47 openstack_config = value_dict
48 if not isinstance(value_dict, dict):
49 raise validation.ValidationError('%s value is not a dict' % self.domain)
51 raise validation.ValidationError('Unexpected configuration %s' % key)
52 self.validate_openstack(openstack_config)
54 def validate_delete(self, properties):
55 logging.debug('validate_delete called with %s' % str(properties))
56 if self.domain in properties:
57 raise validation.ValidationError('%s cannot be deleted' % self.domain)
59 raise validation.ValidationError('References in %s, cannot be deleted' % self.domain)
61 def validate_openstack(self, openstack_config):
62 if not openstack_config:
63 raise validation.ValidationError('No value for %s' % self.domain)
65 self.validate_admin_password(openstack_config)
68 def validate_admin_password(openstack_config):
69 password = 'admin_password'
70 passwd = openstack_config.get(password)
72 raise validation.ValidationError('Missing %s' % password)