Beispiel #1
0
    async def init(self, cfg, metadata):
        """Initialize transformer."""
        self._hosts = []
        self._config = cfg
        self._metadata = metadata
        if self._config_key:
            self.validate_config()

        self._provider = providers.get(self._config_key)
        await self.init_provider()
Beispiel #2
0
def host_from_json(host_data):
    """Reverse method to Host.__json__() after json.loads()."""
    provider_name = host_data["provider"]
    provider = providers.get(provider_name)
    host = Host(
        provider,
        host_data["host_id"],
        host_data["name"],
        host_data["ip_addrs"],
        host_data["status"],
        host_data["rawdata"],
        host_data["username"],
        host_data["password"],
        host_data["error"],
    )
    return host
Beispiel #3
0
    async def provision(self):
        """Execute the up action."""
        logger.info("Provisioning started")
        prov_aws = []
        for provider_name, transformer in self._transformers.items():
            reqs = transformer.create_host_requirements()
            provider = providers.get(provider_name)
            awaitable = provider.provision_hosts(reqs)
            prov_aws.append(awaitable)
        provisioning_results = await asyncio.gather(*prov_aws)
        hosts = []
        for results in provisioning_results:
            hosts.extend(results)

        self._db_driver.add_hosts(hosts)
        logger.info("Provisioning done")
        return hosts