Exemplo n.º 1
0
def _serialize_folder(folder: CREFolder, show_hosts):
    links = []

    if not folder.is_root():
        links.append(
            constructors.link_rel(
                rel="cmk/move",
                href=constructors.object_action_href(
                    "folder_config",
                    folder_slug(folder),
                    action_name="move",
                ),
                method="post",
                title="Move the folder",
            )
        )

    rv = constructors.domain_object(
        domain_type="folder_config",
        identifier=folder_slug(folder),
        title=folder.title(),
        extensions={
            "path": "/" + folder.path(),
            "attributes": folder.attributes().copy(),
        },
        links=links,
    )
    if show_hosts:
        rv["members"]["hosts"] = constructors.collection_property(
            name="hosts",
            base=constructors.object_href("folder_config", folder_slug(folder)),
            value=[
                constructors.collection_item(
                    domain_type="host_config",
                    obj={
                        "id": host.id(),
                        "title": host.name(),
                    },
                )
                for host in folder.hosts().values()
            ],
        )
    return rv
Exemplo n.º 2
0
def _serialize_folder(folder: CREFolder, show_hosts):
    links = []

    if not folder.is_root():
        links.append(
            constructors.link_rel(
                rel='cmk/move',
                href=constructors.object_action_href(
                    "folder_config",
                    folder_slug(folder),
                    action_name='move',
                ),
                method='post',
                title='Move the folder',
            ))

    rv = constructors.domain_object(
        domain_type='folder_config',
        identifier=folder_slug(folder),
        title=folder.title(),
        extensions={
            'path': '/' + folder.path(),
            'attributes': folder.attributes().copy(),
        },
        links=links,
    )
    if show_hosts:
        rv['members']['hosts'] = constructors.collection_property(
            name='hosts',
            base=constructors.object_href('folder_config',
                                          folder_slug(folder)),
            value=[
                constructors.collection_item(
                    domain_type='host_config',
                    obj={
                        'id': host.id(),
                        'title': host.name(),
                    },
                ) for host in folder.hosts().values()
            ],
        )
    return rv
Exemplo n.º 3
0
def _serialize_folder(folder: CREFolder) -> DomainObject:
    uri = constructors.object_href('folder_config', folder.id())
    return constructors.domain_object(
        domain_type='folder_config',
        identifier=folder.id(),
        title=folder.title(),
        members={
            'hosts':
            constructors.object_collection(
                name='hosts',
                domain_type='host_config',
                entries=[
                    constructors.link_rel(
                        rel='.../value',
                        parameters={'collection': "items"},
                        href=constructors.object_href('host_config', host),
                    ) for host in folder.hosts().values()
                ],
                base=uri,
            ),
            'move':
            constructors.object_action(
                name='move',
                base=uri,
                parameters=dict([
                    constructors.action_parameter(
                        action='move',
                        parameter='destination',
                        friendly_name=
                        'The destination folder of this move action',
                        optional=False,
                        pattern="[0-9a-fA-F]{32}|root",
                    ),
                ]),
            ),
        },
        extensions={
            'attributes': folder.attributes(),
        },
    )