Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 def create(self):
     dcos_launch.util.set_from_env('ARM_SUBSCRIPTION_ID')
     dcos_launch.util.set_from_env('ARM_CLIENT_ID')
     dcos_launch.util.set_from_env('ARM_CLIENT_SECRET')
     dcos_launch.util.set_from_env('ARM_TENANT_ID')
     # if azure region is nowhere to be found, the default value in terraform-dcos will be used
     if 'azure_region' not in self.config[
             'terraform_config'] and 'AZURE_LOCATION' in os.environ:
         self.config['terraform_config'][
             'azure_region'] = util.set_from_env('AZURE_LOCATION')
     return super().create()
Ejemplo n.º 3
0
 def create(self):
     # if gcp region is nowhere to be found, the default value in terraform-dcos will be used
     if 'gcp_zone' not in self.config[
             'terraform_config'] and 'GCE_ZONE' in os.environ:
         self.config['terraform_config']['gcp_zone'] = util.set_from_env(
             'GCE_ZONE')[-1]
     if 'gcp_credentials_key_file' not in self.config['terraform_config']:
         creds_string, creds_path = gcp.get_credentials(os.environ)
         if not creds_path:
             creds_path = os.path.join(os.getcwd(), '.gcp_creds.json')
             with open(creds_path, 'w') as f:
                 f.write(creds_string)
         self.config['terraform_config'][
             'gcp_credentials_key_file'] = creds_path
     if 'gcp_project' not in self.config['terraform_config']:
         with open(self.config['terraform_config']
                   ['gcp_credentials_key_file']) as f:
             self.config['terraform_config']['gcp_project'] = json.load(
                 f)['project_id']
     return super().create()
Ejemplo n.º 4
0
def get_validated_config(user_config: dict, config_dir: str) -> dict:
    """ Returns validated a finalized argument dictionary for dcos-launch
    Given the huge range of configuration space provided by this configuration
    file, it must be processed in three steps (common, provider-specifc,
    platform-specific)
    Args:
        use_config: options (perhaps incomplete) provided by the user
        config_dir: path for the config file for resolving relative
            file links
    """
    # validate against the fields common to all configs
    validator = LaunchValidator(COMMON_SCHEMA, config_dir=config_dir, allow_unknown=True)
    if not validator.validate(user_config):
        _raise_errors(validator)

    # add provider specific information to the basic validator
    provider = validator.normalized(user_config)['provider']
    if provider == 'onprem':
        validator.schema.update(ONPREM_DEPLOY_COMMON_SCHEMA)
    else:
        validator.schema.update(TEMPLATE_DEPLOY_COMMON_SCHEMA)

    # validate again before attempting to add platform information
    if not validator.validate(user_config):
        _raise_errors(validator)

    # use the intermediate provider-validated config to add the platform schema
    platform = validator.normalized(user_config)['platform']
    if platform == 'aws':
        validator.schema.update({
            'aws_region': {
                'type': 'string',
                'required': True,
                'default_setter': lambda doc: util.set_from_env('AWS_REGION')},
            'disable_rollback': {
                'type': 'boolean',
                'required': False,
                'default': False}})
        if provider == 'onprem':
            validator.schema.update(AWS_ONPREM_SCHEMA)
    elif platform == 'gce':
        validator.schema.update({
            'gce_zone': {
                'type': 'string',
                'required': True,
                'default_setter': lambda doc: util.set_from_env('GCE_ZONE')}})
        if provider == 'onprem':
            validator.schema.update(GCE_ONPREM_SCHEMA)
    elif platform == 'azure':
        validator.schema.update({
            'azure_location': {
                'type': 'string',
                'required': True,
                'default_setter': lambda doc: util.set_from_env('AZURE_LOCATION')}})
    else:
        raise NotImplementedError()

    # do final validation
    validator.allow_unknown = False
    if not validator.validate(user_config):
        _raise_errors(validator)
    return validator.normalized(user_config)
Ejemplo n.º 5
0
def get_validated_config(user_config: dict, config_dir: str) -> dict:
    """ Returns validated a finalized argument dictionary for dcos-launch
    Given the huge range of configuration space provided by this configuration
    file, it must be processed in three steps (common, provider-specifc,
    platform-specific)
    Args:
        use_config: options (perhaps incomplete) provided by the user
        config_dir: path for the config file for resolving relative
            file links
    """
    owner = os.environ.get('USER')
    if owner:
        user_config.setdefault('tags', {'owner': owner})
    if 'dcos_version' in user_config:
        user_config['dcos_version'] = str(user_config['dcos_version'])
    # validate against the fields common to all configs
    user_config['config_dir'] = config_dir
    validator = LaunchValidator(COMMON_SCHEMA,
                                config_dir=config_dir,
                                allow_unknown=True)
    if not validator.validate(user_config):
        _raise_errors(validator)

    # add provider specific information to the basic validator
    provider = validator.normalized(user_config)['provider']
    if provider == 'onprem':
        validator.schema.update(ONPREM_DEPLOY_COMMON_SCHEMA)
    elif provider == 'terraform':
        validator.schema.update(TERRAFORM_COMMON_SCHEMA)
    elif provider in ('aws', 'azure'):
        validator.schema.update(TEMPLATE_DEPLOY_COMMON_SCHEMA)
    elif provider == 'dcos-engine':
        validator.schema.update(DCOS_ENGINE_SCHEMA)
    else:
        raise Exception('Unknown provider!: {}'.format(provider))

    # validate again before attempting to add platform information
    if not validator.validate(user_config):
        _raise_errors(validator)

    # use the intermediate provider-validated config to add the platform schema
    platform = validator.normalized(user_config)['platform']
    if provider == 'terraform' and 'ssh_user' in user_config[
            'terraform_config']:
        if platform in ('gcp', 'gce'):
            user_config['terraform_config']['gcp_ssh_user'] = user_config[
                'ssh_user']
        else:
            raise Exception('Cannot currently set ssh_user parameter for ' +
                            platform)

    if platform == 'aws':
        region = None
        if provider == 'terraform':
            region = user_config['terraform_config'].get('aws_region')
        else:
            validator.schema.update({
                'disable_rollback': {
                    'type': 'boolean',
                    'required': False,
                    'default': False
                },
                'zen_helper': {
                    'type': 'boolean',
                    'default': False
                }
            })
        validator.schema.update({
            'aws_region': {
                'type':
                'string',
                'required':
                True,
                'default_setter':
                lambda doc: region if region else os.environ['AWS_REGION']
                if 'AWS_REGION' in os.environ else util.set_from_env(
                    'AWS_DEFAULT_REGION')
            }
        })
        if provider == 'onprem':
            if user_config.get(
                    'os_name',
                    'cent-os-7-dcos-prereqs') == 'cent-os-7-dcos-prereqs':
                user_config['install_prereqs'] = True
                user_config[
                    'prereqs_script_filename'] = 'run_centos74_prereqs.sh'
            validator.schema.update(AWS_ONPREM_SCHEMA)
    elif platform in ('gcp', 'gce'):
        if provider != 'terraform':
            validator.schema.update({
                'gce_zone': {
                    'type': 'string',
                    'required': True,
                    'default_setter': lambda doc: util.set_from_env('GCE_ZONE')
                }
            })
        # only use gcp here on out
        user_config['platform'] = 'gcp'
        if provider == 'onprem':
            validator.schema.update(GCP_ONPREM_SCHEMA)
    elif platform == 'azure':
        if provider != 'terraform':
            validator.schema.update({
                'azure_location': {
                    'type':
                    'string',
                    'required':
                    True,
                    'default_setter':
                    lambda doc: util.set_from_env('AZURE_LOCATION')
                }
            })
    else:
        raise NotImplementedError()

    # do final validation
    validator.allow_unknown = False
    if not validator.validate(user_config):
        _raise_errors(validator)
    if 'genconf_dir' in user_config:
        if 'dcos_config' in user_config:
            genconf_dir = expand_path(user_config['genconf_dir'],
                                      user_config['config_dir'])
            _validate_genconf_scripts(genconf_dir, user_config['dcos_config'])
    return validator.normalized(user_config)