Beispiel #1
0
    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", ""])
Beispiel #2
0
 def init(self, conf, force_deploy=False):
     LOGGER.info("Static provider")
     enoslib_conf = _build_enoslib_conf(conf)
     _conf = Configuration.from_dictionnary(enoslib_conf)
     static = enos_static.Static(_conf)
     roles, networks = static.init(force_deploy)
     return roles, networks
Beispiel #3
0
 def test_from_dictionnary_minimal(self):
     d = {
         "resources": {
             "machines": [],
             "networks": []
         }
     }
     conf = Configuration.from_dictionnary(d)
     self.assertEqual([], conf.machines)
     self.assertEqual([], conf.networks)
Beispiel #4
0
 def test_programmatic(self):
     conf = Configuration()
     conf.add_machine_conf(MachineConfiguration(roles=["role"],
                                                address="1.2.3.4"))
     conf.add_network_conf(NetworkConfiguration(roles=["nrole"],
                                                start="1.2.3.10",
                                                end="1.2.3.15",
                                                cidr="1.2.3.4/24",
                                                gateway="1.2.3.254",
                                                dns="1.2.3.253"))
     conf.finalize()
     self.assertEqual(1, len(conf.machines))
Beispiel #5
0
        "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())
Beispiel #6
0
    }
}

tc = {"enable": True, "default_delay": "20ms", "default_rate": "1gbit"}
inventory = os.path.join(os.getcwd(), "hosts")
print("Starting ressources with the provider vagrant")
provider = Enos_vagrant(VagrantConf.from_dictionnary(provider_conf))
roles, networks = provider.init()
print("Building the machine list")
resources = {"machines": [], "networks": []}

for role, machines in roles.items():
    for machine in machines:
        resources["machines"].append({
            "address": machine.address,
            "alias": machine.alias,
            "user": machine.user,
            "port": int(machine.port),
            "keyfile": machine.keyfile,
            "roles": [role],
        })

resources["networks"] = networks

provider = Static(StaticConf.from_dictionnary({"resources": resources}))
roles, networks = provider.init()
discover_networks(roles, networks)
netem = Netem(tc, roles=roles)
netem.deploy()
netem.validate()
    "resources": {
        "machines": [{
            "roles": ["control"],
            "alias": "test_machine",
            "address": "localhost",
            "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")
provider = Static(Configuration.from_dictionnary(provider_conf))
roles, networks = provider.init()
generate_inventory(roles, networks, inventory, check_networks=True)
# using an inventory
result = run_command("date", pattern_hosts="control", inventory_path=inventory)
print(json.dumps(result))
# using the roles
result = run_command("date", pattern_hosts="control", roles=roles)
print(json.dumps(result))
Beispiel #8
0
 def test_programmatic_missing_address(self):
     conf = Configuration()
     conf.add_machine_conf(MachineConfiguration(roles=["plop"]))
     with self.assertRaises(jsonschema.exceptions.ValidationError) as _:
         conf.finalize()
Beispiel #9
0
def up(env=None, **kwargs):
    conf = Configuration.from_dictionnary(provider_conf)
    provider = Static(conf)
    roles, networks = provider.init()
    env["roles"] = roles
    env["networks"] = networks
Beispiel #10
0
import logging
import os

logging.basicConfig(level=logging.INFO)

# path to the inventory
inventory = os.path.join(os.getcwd(), "hosts")

# claim the resources
conf = Configuration.from_settings()\
    .add_machine(roles=["control"],
                 address="192.168.42.245",
                 alias="static-0",
                 user="******")\
    .add_machine(roles=["compute"],
                 address="192.168.42.244",
                 alias="static-1",
                 user="******")\
    .add_network(roles=["mynetwork"],
                 cidr="192.168.42.0/24",
                 start="192.168.42.100",
                 end="192.168.42.200",
                 gateway="192.168.42.1",
                 dns="8.8.8.8")\
    .finalize()
provider = Static(conf)

roles, networks = provider.init()
print(roles)
print(networks)