Beispiel #1
0
def serialize_host(host: watolib.CREHost, effective_attributes: bool):
    if effective_attributes:
        attributes = host.effective_attributes()
    else:
        attributes = host.attributes()

    if 'meta_data' in attributes:
        attributes = attributes.copy()
        del attributes['meta_data']

    return constructors.domain_object(
        domain_type='host_config',
        identifier=host.id(),
        title=host.alias(),
        links=[
            constructors.link_rel(
                rel='cmk/folder_config',
                href=constructors.object_href('folder_config',
                                              folder_slug(host.folder())),
                method='get',
                title='The folder config of the host.',
            ),
        ],
        extensions={
            'attributes': attributes,
            'is_cluster': host.is_cluster(),
            'is_offline': host.is_offline(),
            'cluster_nodes': host.cluster_nodes(),
        },
    )
Beispiel #2
0
def _folders_collection(
    folders: List[CREFolder],
    show_hosts: bool,
):
    folders_ = []
    for folder in folders:
        members = {}
        if show_hosts:
            members["hosts"] = constructors.object_collection(
                name="hosts",
                domain_type="folder_config",
                entries=[
                    constructors.collection_item("host_config", {
                        "title": host,
                        "id": host
                    }) for host in folder.hosts()
                ],
                base="",
            )
        folders_.append(
            constructors.domain_object(
                domain_type="folder_config",
                identifier=folder_slug(folder),
                title=folder.title(),
                extensions={
                    "path": "/" + folder.path(),
                    "attributes": folder.attributes().copy(),
                },
                members=members,
            ))
    return constructors.collection_object(
        domain_type="folder_config",
        value=folders_,
    )
Beispiel #3
0
def serialize_host(host: watolib.CREHost, effective_attributes: bool):
    extensions = {
        "folder":
        host.folder().path(),
        "attributes":
        host.attributes(),
        "effective_attributes":
        host.effective_attributes() if effective_attributes else None,
        "is_cluster":
        host.is_cluster(),
        "is_offline":
        host.is_offline(),
        "cluster_nodes":
        host.cluster_nodes(),
    }
    return constructors.domain_object(
        domain_type="host_config",
        identifier=host.id(),
        title=host.alias() or host.name(),
        links=[
            constructors.link_rel(
                rel="cmk/folder_config",
                href=constructors.object_href("folder_config",
                                              folder_slug(host.folder())),
                method="get",
                title="The folder config of the host.",
            ),
        ],
        extensions=extensions,
    )
Beispiel #4
0
def serialize_host(host: watolib.CREHost, effective_attributes: bool):
    extensions = {
        'folder':
        host.folder().path(),
        'attributes':
        host.attributes(),
        'effective_attributes':
        host.effective_attributes() if effective_attributes else None,
        'is_cluster':
        host.is_cluster(),
        'is_offline':
        host.is_offline(),
        'cluster_nodes':
        host.cluster_nodes(),
    }
    return constructors.domain_object(
        domain_type='host_config',
        identifier=host.id(),
        title=host.alias() or host.name(),
        links=[
            constructors.link_rel(
                rel='cmk/folder_config',
                href=constructors.object_href('folder_config',
                                              folder_slug(host.folder())),
                method='get',
                title='The folder config of the host.',
            ),
        ],
        extensions=extensions,
    )
Beispiel #5
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
Beispiel #6
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
Beispiel #7
0
def serialize_host(host: watolib.CREHost, effective_attributes: bool):
    extensions = {
        "folder":
        host.folder().path(),
        "attributes":
        host.attributes(),
        "effective_attributes":
        host.effective_attributes() if effective_attributes else None,
        "is_cluster":
        host.is_cluster(),
        "is_offline":
        host.is_offline(),
        "cluster_nodes":
        host.cluster_nodes(),
    }

    agent_links = []
    if not cmk_version.is_raw_edition():
        import cmk.gui.cee.agent_bakery as agent_bakery  # pylint: disable=no-name-in-module

        for agent_type in sorted(agent_bakery.agent_package_types().keys()):
            agent_links.append(
                constructors.link_rel(
                    rel="cmk/download",
                    href="{}?{}".format(
                        constructors.domain_type_action_href(
                            "agent", "download"),
                        urlencode({
                            "os_type": agent_type,
                            "host_name": host.id()
                        }),
                    ),
                    method="get",
                    title=f"Download the {agent_type} agent of the host.",
                ))

    return constructors.domain_object(
        domain_type="host_config",
        identifier=host.id(),
        title=host.alias() or host.name(),
        links=[
            constructors.link_rel(
                rel="cmk/folder_config",
                href=constructors.object_href("folder_config",
                                              folder_slug(host.folder())),
                method="get",
                title="The folder config of the host.",
            ),
        ] + agent_links,
        extensions=extensions,
    )