def setUp(self): super(LxcHostTestCase, self).setUp() sample_config = {"network": "10.1.1.0/24", "forward_ssh": True, "tunnel_to": ["1.1.1.1", "2.2.2.2"]} self.server = mock.Mock() self.server.host = "fake_server_ip" self.server.get_credentials.return_value = {"ip": "3.3.3.3"} self.host = lxc.LxcHost(self.server, sample_config)
def cleanup(self): resources = self.deployment.get_resources() for resource in resources: server = provider.Server.from_credentials(resource.info["host"]) lxc_host = lxc.LxcHost(server, resource.info["config"]) lxc_host.containers = resource.info["containers"] lxc_host.destroy_containers() lxc_host.destroy_ports(resource.info["forwarded_ports"]) lxc_host.delete_tunnels() self.deployment.delete_resource(resource.id) self._get_provider().destroy_servers()
def deploy(self): name = self.config["container_name"] start_script = self.config.get("start_script", get_script_path(START_SCRIPT)) distribution = self.config["distribution"] release = self.config.get("release") network = self.config.get("start_lxc_network") if network: network = netaddr.IPNetwork(network) else: ip = "0" self.provider = self._get_provider() for server in self.provider.create_servers(): config = {"tunnel_to": self.config.get("tunnel_to", [])} if network: config["network"] = str(network) ip = str(network.ip).replace(".", "-") else: ip = "0" name_prefix = "%s-%s" % (name, ip) first_name = name_prefix + "-000" lxc_host = lxc.LxcHost(server, config) self._deploy_first(lxc_host, first_name, distribution, release) for i in range(1, self.config["containers_per_host"]): clone_name = "%s-%03d" % (name_prefix, i) lxc_host.create_clone(clone_name, first_name) lxc_host.start_containers() info = { "host": server.get_credentials(), "containers": lxc_host.containers, "forwarded_ports": lxc_host._port_cache.items(), "config": config } self.deployment.add_resource(provider_name="LxcEngine", info=info) for container in lxc_host.get_server_objects(): container.ssh.run("/bin/sh -e", stdin=open(start_script, "rb")) if network: network += 1 admin = objects.Credential("", "", "", "").to_dict(include_permission=True) return {"openstack": [{"admin": admin, "users": []}]}