def _machine_opts(parser): parser.add_argument( "--constraints", default="", help="Machine allocation criteria") parser.add_argument( "--series", default="trusty", choices=SERIES_MAP.values(), help="OS Release for machine.")
def bootstrap_jenv(self, host): """Bootstrap an environment in a sandbox. Manual provider config keeps transient state in the form of bootstrap-host for its config. A temporary JUJU_HOME is used to modify environments.yaml """ env_name = self.config.get_env_name() # Prep a new juju home boot_home = os.path.join(self.config.juju_home, "boot-%s" % env_name) if not os.path.exists(boot_home): os.makedirs(os.path.join(boot_home, 'environments')) # Check that this installation has been used before. jenv_dir = os.path.join(self.config.juju_home, 'environments') if not os.path.exists(jenv_dir): os.mkdir(jenv_dir) ssh_key_dir = os.path.join(self.config.juju_home, 'ssh') # If no keys, create juju ssh keys via side effect. if not os.path.exists(ssh_key_dir): self._run(["switch"]) # Use existing juju ssh keys when bootstrapping shutil.copytree(ssh_key_dir, os.path.join(boot_home, 'ssh')) # Updated env config with the bootstrap host. with open(self.config.get_env_conf()) as fh: data = yaml.safe_load(fh.read()) env_conf = data['environments'].get(env_name) env_conf['bootstrap-host'] = host with open(os.path.join(boot_home, 'environments.yaml'), 'w') as fh: fh.write(yaml.safe_dump({'environments': {env_name: env_conf}})) # Change JUJU_ENV env = dict(os.environ) env['JUJU_HOME'] = boot_home env['JUJU_LOGGING'] = "<root>=DEBUG" cmd = ['bootstrap', '--debug'] if self.config.upload_tools: cmd.append("--upload-tools") cmd.append('--series') cmd.append("%s" % (",".join(sorted(SERIES_MAP.values())))) capture_err = self.config.verbose and True or False try: self._run(cmd, env=env, capture_err=capture_err) # Copy over the jenv shutil.copy( os.path.join(boot_home, "environments", "%s.jenv" % env_name), os.path.join(self.config.juju_home, "environments", "%s.jenv" % env_name)) finally: shutil.rmtree(boot_home)
def bootstrap_jenv(self, host): """Bootstrap an environment in a sandbox. Manual provider config keeps transient state in the form of bootstrap-host for its config. A temporary JUJU_HOME is used to modify environments.yaml """ env_name = self.config.get_env_name() # Prep a new juju home boot_home = os.path.join( self.config.juju_home, "boot-%s" % env_name) if not os.path.exists(boot_home): os.makedirs(os.path.join(boot_home, 'environments')) # Check that this installation has been used before. jenv_dir = os.path.join(self.config.juju_home, 'environments') if not os.path.exists(jenv_dir): os.mkdir(jenv_dir) ssh_key_dir = os.path.join(self.config.juju_home, 'ssh') # If no keys, create juju ssh keys via side effect. if not os.path.exists(ssh_key_dir): self._run(["switch"]) # Use existing juju ssh keys when bootstrapping shutil.copytree( ssh_key_dir, os.path.join(boot_home, 'ssh')) # Updated env config with the bootstrap host. with open(self.config.get_env_conf()) as fh: data = yaml.safe_load(fh.read()) env_conf = data['environments'].get(env_name) env_conf['bootstrap-host'] = host with open(os.path.join( boot_home, 'environments.yaml'), 'w') as fh: fh.write(yaml.safe_dump({'environments': {env_name: env_conf}})) # Change JUJU_ENV env = dict(os.environ) env['JUJU_HOME'] = boot_home env['JUJU_LOGGING'] = "<root>=DEBUG" cmd = ['bootstrap', '--debug'] if self.config.upload_tools: cmd.append("--upload-tools") cmd.append('--series') cmd.append("%s" % (",".join(sorted(SERIES_MAP.values())))) capture_err = self.config.verbose and True or False try: self._run(cmd, env=env, capture_err=capture_err) # Copy over the jenv shutil.copy( os.path.join( boot_home, "environments", "%s.jenv" % env_name), os.path.join( self.config.juju_home, "environments", "%s.jenv" % env_name)) finally: shutil.rmtree(boot_home)