def create_container_and_wait(self): """ Creates container and waits for cloud-init to finish """ self.tasker.start_task("Creating Container", self.read_container_status) Container.create(self.container_name, self.userdata) with open(os.path.join(self.container_abspath, 'fstab'), 'w') as f: f.write("{0} {1} none bind,create=dir\n".format( self.config.cfg_path, 'home/ubuntu/.cloud-install')) f.write("/var/cache/lxc var/cache/lxc none bind,create=dir\n") # Detect additional charm plugins and make available to the # container. charm_plugin_dir = self.config.getopt('charm_plugin_dir') if charm_plugin_dir \ and self.config.cfg_path not in charm_plugin_dir: plug_dir = os.path.abspath( self.config.getopt('charm_plugin_dir')) plug_base = os.path.basename(plug_dir) f.write("{d} home/ubuntu/{m} " "none bind,create=dir\n".format(d=plug_dir, m=plug_base)) extra_mounts = os.getenv("EXTRA_BIND_DIRS", None) if extra_mounts: for d in extra_mounts.split(','): mountpoint = os.path.basename(d) f.write("{d} home/ubuntu/{m} " "none bind,create=dir\n".format(d=d, m=mountpoint)) # update container config with open(os.path.join(self.container_abspath, 'config'), 'a') as f: f.write("lxc.mount.auto = cgroup:mixed\n" "lxc.start.auto = 1\n" "lxc.start.delay = 5\n" "lxc.mount = {}/fstab\n".format(self.container_abspath)) lxc_logfile = os.path.join(self.config.cfg_path, 'lxc.log') Container.start(self.container_name, lxc_logfile) Container.wait_checked(self.container_name, lxc_logfile) self.tasker.start_task("Initializing Container", self.read_cloud_init_output) tries = 0 while not self.cloud_init_finished(tries): time.sleep(1) tries += 1 # we do this here instead of using cloud-init, for greater # control over ordering log.debug("Container started, cloud-init done.") lxc_network = self.write_lxc_net_config() self.add_static_route(lxc_network) self.tasker.start_task("Installing Dependencies", self.read_progress_output) log.debug("Installing openstack & openstack-single directly, " "and juju-local, libvirt-bin and lxc via deps") Container.run(self.container_name, "env DEBIAN_FRONTEND=noninteractive apt-get -qy " "-o Dpkg::Options::=--force-confdef " "-o Dpkg::Options::=--force-confold " "install openstack openstack-single ", output_cb=self.set_progress_output) log.debug("done installing deps")