本文整理汇总了Python中hm.model.host.Host.list方法的典型用法代码示例。如果您正苦于以下问题:Python Host.list方法的具体用法?Python Host.list怎么用?Python Host.list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hm.model.host.Host
的用法示例。
在下文中一共展示了Host.list方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_alternatives
# 需要导入模块: from hm.model.host import Host [as 别名]
# 或者: from hm.model.host.Host import list [as 别名]
def test_create_alternatives(self):
conf = {"HM_ALTERNATIVE_CONFIG_COUNT": "3"}
conf.update({"HOST_ID": "fake-1"})
host = Host.create('fake', 'my-group', conf)
self.assertEqual(host.alternative_id, 0)
conf.update({"HOST_ID": "fake-2"})
host = Host.create('fake', 'my-group', conf)
self.assertEqual(host.alternative_id, 1)
conf.update({"HOST_ID": "fake-3"})
host = Host.create('fake', 'my-group', conf)
self.assertEqual(host.alternative_id, 2)
conf.update({"HOST_ID": "fake-4"})
host = Host.create('fake', 'my-group', conf)
self.assertEqual(host.alternative_id, 0)
conf.update({"HOST_ID": "fake-5"})
host = Host.create('fake', 'my-group', conf)
self.assertEqual(host.alternative_id, 1)
conf.update({"HOST_ID": "fake-6"})
host = Host.create('fake', 'another-group', conf)
self.assertEqual(host.alternative_id, 0)
hosts = Host.list(filters={'alternative_id': 0})
self.assertEqual(len(hosts), 3)
hosts = Host.list(filters={'alternative_id': 1})
self.assertEqual(len(hosts), 2)
hosts = Host.list(filters={'alternative_id': 2})
self.assertEqual(len(hosts), 1)
示例2: test_list
# 需要导入模块: from hm.model.host import Host [as 别名]
# 或者: from hm.model.host.Host import list [as 别名]
def test_list(self):
h1 = Host.create('fake', 'my-group1', {"HOST_ID": "fake-id-1"})
h2 = Host.create('fake', 'my-group1', {"HOST_ID": "fake-id-2"})
h3 = Host.create('fake', 'my-group2', {"HOST_ID": "fake-id-3"})
conf = {'MY_CONF': 1}
hosts = Host.list(conf=conf)
self.assertDictEqual(hosts[0].config, conf)
self.assertDictEqual(hosts[1].config, conf)
self.assertDictEqual(hosts[2].config, conf)
self.assertItemsEqual([h.to_json() for h in hosts], [h1.to_json(), h2.to_json(), h3.to_json()])
hosts = Host.list({'group': 'my-group1'})
self.assertItemsEqual([h.to_json() for h in hosts], [h1.to_json(), h2.to_json()])