Exemple #1
0
    def update(self, json_snippet=None):
        '''
        update the resource. Subclasses should provide a handle_update() method
        to customise update, the base-class handle_update will fail by default.
        '''
        if self.state in (self.CREATE_IN_PROGRESS, self.UPDATE_IN_PROGRESS):
            return 'Resource update already requested'

        if not json_snippet:
            return 'Must specify json snippet for resource update!'

        logger.info('updating %s' % str(self))

        result = self.UPDATE_NOT_IMPLEMENTED
        try:
            self.state_set(self.UPDATE_IN_PROGRESS)
            self.t = self.stack.resolve_static_data(json_snippet)
            self.properties = checkeddict.Properties(self.name,
                                                     self.properties_schema)
            self.calculate_properties()
            self.properties.validate()
            if callable(getattr(self, 'handle_update', None)):
                result = self.handle_update()
        except Exception as ex:
            logger.exception('update %s : %s' % (str(self), str(ex)))
            self.state_set(self.UPDATE_FAILED, str(ex))
            return str(ex)
        else:
            # If resource was updated (with or without interruption),
            # then we set the resource to UPDATE_COMPLETE
            if not result == self.UPDATE_REPLACE:
                self.state_set(self.UPDATE_COMPLETE)
            return result
Exemple #2
0
    def __init__(self, name, json_snippet, stack):
        self.references = []
        self.stack = stack
        self.context = stack.context
        self.name = name
        self.t = stack.resolve_static_data(json_snippet)
        self.properties = checkeddict.Properties(name, self.properties_schema)

        resource = db_api.resource_get_by_name_and_stack(
            self.context, name, stack.id)
        if resource:
            self.instance_id = resource.nova_instance
            self.state = resource.state
            self.state_description = resource.state_description
            self.id = resource.id
        else:
            self.instance_id = None
            self.state = None
            self.state_description = ''
            self.id = None
        self._nova = {}
        self._keystone = None
        self._swift = None
Exemple #3
0
    def test_nested_paramerters(self):
        listeners_schema = {
            'InstancePort': {
                'Type': 'Integer',
                'Required': True
            },
            'LoadBalancerPort': {
                'Type': 'Integer',
                'Required': True
            }
        }

        healthcheck_schema = {
            'HealthyThreshold': {
                'Type': 'Number',
                'Required': True
            },
            'Interval': {
                'Type': 'Number',
                'Required': True
            }
        }

        properties_schema = {
            'HealthCheck': {
                'Type': 'Map',
                'Implemented': False,
                'Schema': healthcheck_schema
            },
            'Listeners': {
                'Type': 'List',
                'Schema': listeners_schema
            }
        }

        cd = checkeddict.Properties('nested', properties_schema)

        hc = {'HealthyThreshold': 'bla', 'Interval': '45'}
        self.assertRaises(ValueError, cd.__setitem__, 'HealthCheck', hc)

        hc = {'HealthyThreshold': '246', 'Interval': '45'}
        cd['HealthCheck'] = hc
        self.assertTrue(cd['HealthCheck']['HealthyThreshold'] == '246')
        self.assertTrue(cd['HealthCheck']['Interval'] == '45')

        li = [{
            'InstancePort': 'bla',
            'LoadBalancerPort': '45'
        }, {
            'InstancePort': '66',
            'LoadBalancerPort': '775'
        }]
        self.assertRaises(ValueError, cd.__setitem__, 'Listeners', li)

        li2 = [{
            'InstancePort': '674',
            'LoadBalancerPort': '45'
        }, {
            'InstancePort': '66',
            'LoadBalancerPort': '775'
        }]
        cd['Listeners'] = li2

        self.assertTrue(cd['Listeners'][0]['LoadBalancerPort'] == '45')
        self.assertTrue(cd['Listeners'][1]['LoadBalancerPort'] == '775')