def init(self, conf, force_deploy=False): LOGGER.info("Vagrant provider") enoslib_conf = _build_enoslib_conf(conf) _conf = Configuration.from_dictionnary(enoslib_conf) vagrant = enoslib_vagrant.Enos_vagrant(_conf) roles, networks = vagrant.init(force_deploy) return roles, networks
def vagrant(config, force, env=None, **kwargs): conf = VagrantConf.from_dictionnary(config["vagrant"]) provider = Enos_vagrant(conf) roles, networks = provider.init(force_deploy=force) env["config"] = config env["roles"] = roles env["networks"] = networks env["context"] = "vagrant"
def up(force, env=None, **kwargs): """Starts a new experiment using vagrant""" inventory = os.path.join(os.getcwd(), "hosts") conf = Configuration.from_dictionnary(provider_conf) provider = Enos_vagrant(conf) roles, networks = provider.init(force_deploy=force) check_networks(roles, networks) env["roles"] = roles env["networks"] = networks
def up(force=True, env=None, **kwargs): "Starts a new experiment" inventory = os.path.join(os.getcwd(), "hosts") conf = Configuration.from_dictionnary(provider_conf) provider = Enos_vagrant(conf) roles, networks = provider.init() discover_networks(roles, networks) env["roles"] = roles env["networks"] = networks
def test_from_dictionnary_custom_backend(self): d = { "backend": "virtualbox", "resources": { "machines": [], "networks": [] } } conf = Configuration.from_dictionnary(d) self.assertEqual("virtualbox", conf.backend)
def test_missing_flavour_and_flavour_desc(self): d = { "backend": "virtualbox", "resources": { "machines": [{ "roles": ["role1"] }], "networks": [] }, } with self.assertRaises(ValidationError) as e: conf = Configuration.from_dictionnary(d)
"roles": ["compute"], "flavour": "tiny", "number": 1 }, ], "networks": [{ "cidr": "192.168.20.0/24", "roles": ["mynetwork"] }], } } 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], })
"networks": ["n1"] }] } } tc = { "enable": True, "default_delay": "20ms", "default_rate": "1gbit", } # path to the inventory inventory = os.path.join(os.getcwd(), "hosts") # claim the resources conf = Configuration.from_dictionnary(provider_conf) provider = Enos_vagrant(conf) roles, networks = provider.init() generate_inventory(roles, networks, inventory, check_networks=True) # apply network constraints emulate_network(roles, inventory, tc) # validate network constraints validate_network(roles, inventory) # reset network constraints reset_network(roles, inventory) # validate network constraints and saving in an alternative
def test_from_dictionnary_minimal(self): d = {"resources": {"machines": [], "networks": []}} conf = Configuration.from_dictionnary(d) self.assertEqual(constants.DEFAULT_BACKEND, conf.backend) self.assertEqual(constants.DEFAULT_BOX, conf.box) self.assertEqual(constants.DEFAULT_USER, conf.user)
# -*- coding: utf-8 -*- # Imports import os from pprint import pformat import yaml from enoslib.infra.enos_vagrant.configuration import Configuration from utils import infra, LOG # Fig Code (Load the yaml file) YAML_PATH = 'fig5.yaml' YAML_DICT = None with open(YAML_PATH) as yaml_file: YAML_DICT = yaml.safe_load(yaml_file) # Test It! # Define the infrastructure: 2 database machines, 2 # database/client machines, 1 net CONF = Configuration.from_dictionnary(YAML_DICT) # Setup the infra and call the `contextualize` function LOG.info(f'Provisionning of {YAML_PATH}:\n{pformat(CONF.to_dict())}') with infra(CONF): pass