Ejemplo n.º 1
0
    def test_update_hosts_dockers_status(self, session, _session):
        _dockers_status = [
            {
                "Container ID": "4c01db0b339c",
                "Image": "ubuntu:12.04",
                "Command": "bash",
                "Created": "17 seconds ago",
                "Status": "Up 16 seconds",
                "Ports": "3300-3310/tcp",
                "Names": "webapp"
            }
        ]
        _commit = mock.Mock()
        _session.commit = _commit
        _insert_data = HostMeta(hostname="Marvin", ip="123.456.78.9")
        session.add(_insert_data)

        with mock.patch.object(
            HostMeta, "query", session.query_property()
        ) as _query:
            HostMeta.update_host_dockers_status(
                ip="123.456.78.9", dockers_status=_dockers_status
            )
            _commit.called_once_with()
            _query_data = session.query(HostMeta).filter_by(
                hostname="Marvin"
            ).first()
            self.assertEqual(
                _query_data.dockers_status, json.dumps(_dockers_status)
            )
Ejemplo n.º 2
0
def cron_get_host_docker_status():
    hosts_status = HostMeta.get_all_hosts_status()
    for host_id in hosts_status:
        host_ip = hosts_status[host_id]["IP"]
        dockers_status = get_host_docker_status(host_ip)
        for docker_status in dockers_status:
            docker_status.update({
                "IP": hosts_status[host_id]["IP"],
                "Hostname": hosts_status[host_id]["Hostname"],
            })
        HostMeta.update_host_dockers_status(ip=host_ip,
                                            dockers_status=dockers_status)