def __init__(self, config: dict): """ For this to work, you must set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your json file that contains the credentials for your Google service account """ credentials_path = util.set_from_env('GOOGLE_APPLICATION_CREDENTIALS') credentials = util.read_file(credentials_path) self.gce_wrapper = gce.GceWrapper(json.loads(credentials), credentials_path) self.config = config
def __init__(self, config: dict, env=None): if env is None: env = os.environ.copy() if 'GCE_CREDENTIALS' in env: json_credentials = env['GCE_CREDENTIALS'] elif 'GCE_CREDENTIALS_PATH' in env: json_credentials = util.read_file(env['GCE_CREDENTIALS_PATH']) elif 'GOOGLE_APPLICATION_CREDENTIALS' in env: json_credentials = util.read_file( env['GOOGLE_APPLICATION_CREDENTIALS']) else: raise util.LauncherError( 'MissingParameter', 'Either GCE_CREDENTIALS or GCE_CREDENTIALS_PATH must be set in env' ) credentials_dict = json.loads(json_credentials) self.gcp_wrapper = gcp.GcpWrapper(credentials_dict) self.config = config
def get_credentials(env) -> tuple: path = None if env is None: env = os.environ.copy() if 'GCE_CREDENTIALS' in env: json_credentials = env['GCE_CREDENTIALS'] elif 'GOOGLE_APPLICATION_CREDENTIALS' in env: path = env['GOOGLE_APPLICATION_CREDENTIALS'] json_credentials = util.read_file(path) else: raise util.LauncherError( 'MissingParameter', 'Either GCE_CREDENTIALS or GOOGLE_APPLICATION_CREDENTIALS must be set in env' ) return json_credentials, path
def install_dcos(cluster: onprem.OnpremCluster, node_client: ssh_client.SshClient, prereqs_script_path: str, bootstrap_script_url: str, parallelism: int): """ Args: cluster: cluster abstraction for handling network addresses node_client: SshClient that can access all non-bootstrap nodes in `cluster` prereqs_script_path: if given, this will be run before preflight on any nodes bootstrap_script_url: where the installation script will be pulled from (see do_genconf) parallelism: how many concurrent SSH tunnels to run """ # Check to make sure we can talk to the cluster for host in cluster.cluster_hosts: node_client.wait_for_ssh_connection(host.public_ip) # do genconf and configure bootstrap if necessary all_client = get_client(cluster, 'cluster_hosts', node_client, parallelism=parallelism) # install prereqs if enabled if prereqs_script_path: log.info('Installing prerequisites on cluster hosts') check_results( all_client.run_command('run', [util.read_file(prereqs_script_path)]), node_client, 'install_prereqs') log.info('Prerequisites installed.') # download install script from boostrap host and run it remote_script_path = '/tmp/install_dcos.sh' log.info('Starting preflight') check_results( do_preflight(all_client, remote_script_path, bootstrap_script_url), node_client, 'preflight') log.info('Preflight check succeeded; moving onto deploy') check_results( do_deploy(cluster, node_client, parallelism, remote_script_path), node_client, 'deploy') log.info('Deploy succeeded; moving onto postflight') check_results(do_postflight(all_client), node_client, 'postflight') log.info('Postflight succeeded')
def load_ssh_private_key(doc): if doc.get('key_helper') == 'true': return 'unset' if 'ssh_private_key_filename' not in doc: return util.NO_TEST_FLAG return util.read_file(doc['ssh_private_key_filename'])
}, 'num_masters': { 'type': 'integer', 'allowed': [1, 3, 5, 7, 9], 'required': True }, 'dcos_config': { 'type': 'dict', 'required': True, 'allow_unknown': True, 'default_setter': lambda doc: yaml.load( util.read_file(os.path.join(doc['genconf_dir'], 'config.yaml'))), 'schema': { 'ip_detect_filename': { 'excludes': 'ip_detect_contents' }, 'ip_detect_public_filename': { 'excludes': 'ip_detect_public_contents' }, 'fault_domain_detect_filename': { 'excludes': 'fault_domain_detect_contents' }, 'license_key_filename': { 'excludes': 'license_key_contents' }, # the following are fields that will be injected by dcos-launch 'agent_list': {
'required': False, 'min': 0, # note: cannot assume nested schema values will be populated with defaults # when the default setter runs 'default_setter': lambda doc: sum([v.get('num_public_agents', 0) for v in doc['fault_domain_helper'].values()]) if 'fault_domain_helper' in doc else 0}, 'num_masters': { 'type': 'integer', 'allowed': [1, 3, 5, 7, 9], 'required': True}, 'dcos_config': { 'type': 'dict', 'required': True, 'allow_unknown': True, 'default_setter': lambda doc: yaml.load(util.read_file(os.path.join(doc['genconf_dir'], 'config.yaml'))), 'schema': { 'ip_detect_filename': { 'coerce': 'expand_local_path', 'excludes': 'ip_detect_contents'}, 'ip_detect_public_filename': { 'coerce': 'expand_local_path', 'excludes': 'ip_detect_public_contents'}, 'fault_domain_detect_filename': { 'coerce': 'expand_local_path', 'excludes': 'fault_domain_detect_contents'}, 'license_key_filename': { 'coerce': 'expand_local_path', 'excludes': 'license_key_contents'}, # the following are fields that will be injected by dcos-launch 'agent_list': {'readonly': True},