def test_build_resources(self): resources = { "machines":[{ "address": "ip1", "roles": ["role1", "role2"] },{ "address": "ip2", "roles": ["role1"] }], "networks": [{ "cidr": "", "roles": ["net2"], "start": "2.2.3.100", "end": "2.2.3.252", "gateway": "2.2.3.254", "dns": "2.2.3.253" },{ "cidr": "1.2.3.4/24", "roles": ["net1"], "start": "1.2.3.100", "end": "1.2.3.252", "gateway": "1.2.3.254", "dns": "1.2.3.253" }] } conf = Configuration.from_dictionnary({"resources": resources}) s = Static(conf) roles, networks = s.init() self.assertCountEqual(["role1", "role2"], roles.keys()) self.assertEqual(2, len(roles["role1"])) self.assertEqual(1, len(roles["role2"])) self.assertEqual(2, len(networks)) self.assertTrue(networks[0]["cidr"] in ["1.2.3.4/24", ""])
def test_build_resources(self): resources = { "machines":[{ "address": "ip1", "roles": ["role1", "role2"] },{ "address": "ip2", "role": "role1" }], "networks": [{ "cidr": "cidr1", "roles": ["net1", "net2"] },{ "cidr": "cidr2", "role": "net1" }] } s = Static({"resources": resources}) roles, _ = s.init() self.assertItemsEqual(["role1", "role2"], roles.keys()) self.assertEquals(2, len(roles["role1"])) self.assertEquals(1, len(roles["role2"]))
"machines": [{ "roles": ["control"], "address": "localhost", "alias": "test_machine", "extra": { "ansible_connection": "local" } }], "networks": [{ "roles": ["local"], "start": "172.17.0.0", "end": "172.17.255.255", "cidr": "172.17.0.0/16", "gateway": "172.17.0.1", "dns": "172.17.0.1", }] } } inventory = os.path.join(os.getcwd(), "hosts") conf = Configuration.from_dictionnary(provider_conf) provider = Static(conf) roles, networks = provider.init() with play_on("all", roles=roles) as p: p.shell("date > /tmp/date") with open("/tmp/date") as f: print(f.readlines())
def up(env=None, **kwargs): conf = Configuration.from_dictionnary(provider_conf) provider = Static(conf) roles, networks = provider.init() env["roles"] = roles env["networks"] = networks