Пример #1
0
    def renderer(self, obj):
        header = {}
        link_value = ''
        link_param = ''

        if isinstance(obj, Link):
            _location_registry = location_registry()
            _location_of_obj = _location_registry.get_location(obj)

            _source = obj.occi_core_source
            _target_location = obj.occi_core_target

            _target_object = _location_registry.get_object(_target_location)

            logger.debug('the Target location of this link is: ' + _target_location)
            logger.debug('the Target object of this link is: ' + _target_object.__repr__())

            link_value += '<' + _target_location + '>;\nrel="' + _target_object.kind.__repr__() + '";\nself="' + _location_of_obj + '";\n'

            link_param += 'category="' + obj.kind.__repr__() + '";'

            for attribute in obj.kind.attributes:
                link_param += '\n' + attribute.name + '="' + obj.__getattribute__(
                    re.sub('\.', '_', attribute.name)) + '";'

        else:
            logger.warning("Object bad type: Only a Link can be rendered")
            raise ("Object bad type: Only a Link can be rendered")

        header[header_link] = link_value + link_param

        return header
Пример #2
0
    def renderer(self, obj):
        header = {}
        category_value = ''
        category_param = ''

        if isinstance(obj, Kind):
            _category = obj
            _classe = 'kind'
        elif isinstance(obj, Mixin):
            _category = obj
            _classe = 'mixin'
        elif isinstance(obj, Action):
            _category = obj.category
            _classe = 'action'
        else:
            logger.warning("Object bad type: Only a kind, mixin or an action can be rendered as a category")
            raise ("Object bad type: Only a kind, mixin or an action can be rendered as a category")

        category_value += _category.term + ';\nscheme="' + _category.scheme + '";\nclass="' + _classe + '";\n'

        if _category.title != '':
            category_param += 'title="' + _category.title + '";\n'

        if _category.related.__len__() > 0:
            __related_objects = ''
            for rel in _category.related:
                __related_objects += rel.__repr__() + " "
            category_param += 'rel="' + __related_objects + '";\n'

        _location_registry = location_registry()
        _location = _location_registry.get_location(_category)
        category_param += 'location=' + str(_location) + ';\n'

        if _classe == 'kind' or _classe == 'mixin':
            __attributes = ''
            for __attribute in _category.attributes:
                __attributes += __attribute.name + ' '
            category_param += 'attributes="' + __attributes + '";\n'

        if _classe == 'kind' or _classe == 'mixin':
            __actions = ''
            for __action in _category.actions:
                __actions += __action.__repr__() + ' '
            category_param += 'actions="' + __actions + '";'

        header[header_category] = category_value + category_param

        return header
Пример #3
0
    def renderer(self, obj, action):
        header = {}
        link_value = ''

        if isinstance(obj, Resource):
            _location_registry = location_registry()
            _location_of_obj = _location_registry.get_location(obj)

            _location_of_action = _location_of_obj + '?action=' + action.category.term

            link_value += '<' + _location_of_action + '>;\nrel="' + action.__repr__() + '"'
        else:
            logger.warning("Object bad type: Only a Resource can be rendered")
            raise ("Object bad type: Only a Resource can be rendered")

        header[header_link] = link_value

        return header
Пример #4
0
# register OCCI Infrastructure kinds
category_registry.register_kind(Compute._kind)
category_registry.register_kind(Network._kind)
category_registry.register_kind(Storage._kind)
category_registry.register_kind(NetworkInterface._kind)
category_registry.register_kind(StorageLink._kind)

# register OCCI Infrastructure mixins
category_registry.register_mixin(IPNetworking())
category_registry.register_mixin(IPNetworkInterface())

# ======================================================================================
# the location registry
# ======================================================================================

location_registry = location_registry()

# register OCCI Core kind locations
location_registry.register_location("/resource/", Resource._kind)
location_registry.register_location("/link/", Link._kind)

# register OCCI Infrastructure kind locations
location_registry.register_location("/compute/", Compute._kind)
location_registry.register_location("/network/", Network._kind)
location_registry.register_location("/storage/", Storage._kind)
location_registry.register_location("/networkinterface/", NetworkInterface._kind)
location_registry.register_location("/storagelink/", StorageLink._kind)

# register OCCI Infrastructure mixin locations
location_registry.register_location("/ipnetworking/", IPNetworking())
location_registry.register_location("/ipnetworkinterface/", IPNetworkInterface())