Ejemplo n.º 1
0
    def _ConstructPatch(self,
                        env_ref,
                        args,
                        support_environment_upgrades=False,
                        support_web_server_access_control=False):

        params = dict(
            env_ref=env_ref,
            node_count=args.node_count,
            update_pypi_packages_from_file=args.update_pypi_packages_from_file,
            clear_pypi_packages=args.clear_pypi_packages,
            remove_pypi_packages=args.remove_pypi_packages,
            update_pypi_packages=dict(
                command_util.SplitRequirementSpecifier(r)
                for r in args.update_pypi_package),
            clear_labels=args.clear_labels,
            remove_labels=args.remove_labels,
            update_labels=args.update_labels,
            clear_airflow_configs=args.clear_airflow_configs,
            remove_airflow_configs=args.remove_airflow_configs,
            update_airflow_configs=args.update_airflow_configs,
            clear_env_variables=args.clear_env_variables,
            remove_env_variables=args.remove_env_variables,
            update_env_variables=args.update_env_variables,
            release_track=self.ReleaseTrack())

        if support_environment_upgrades:
            params['update_image_version'] = args.image_version
        if support_web_server_access_control:
            params['update_web_server_access_control'] = (
                environments_api_util.BuildWebServerAllowedIps(
                    args.update_web_server_allow_ip, args.web_server_allow_all,
                    args.web_server_deny_all))

        return patch_util.ConstructPatch(**params)
Ejemplo n.º 2
0
  def ParseWebServerAccessControlConfigOptions(self, args):
    if (args.enable_private_environment and not args.web_server_allow_ip and
        not args.web_server_allow_all and not args.web_server_deny_all):
      raise command_util.InvalidUserInputError(
          'Cannot specify --enable-private-environment without one of: ' +
          '--web-server-allow-ip, --web-server-allow-all ' +
          'or --web-server-deny-all')

    # Default to allow all if no flag is specified.
    self.web_server_access_control = (
        environments_api_util.BuildWebServerAllowedIps(
            args.web_server_allow_ip, args.web_server_allow_all or
            not args.web_server_allow_ip, args.web_server_deny_all))
    flags.ValidateIpRanges(
        [acl['ip_range'] for acl in self.web_server_access_control])
Ejemplo n.º 3
0
 def ParseWebServerAccessControlConfigOptions(self, args):
     self.web_server_access_control = environments_api_util.BuildWebServerAllowedIps(
         args.web_server_allow_ip, not args.web_server_allow_ip,
         args.web_server_deny_all)
     flags.ValidateIpRanges(
         [acl['ip_range'] for acl in self.web_server_access_control])
Ejemplo n.º 4
0
    def _ConstructPatch(self,
                        env_ref,
                        args,
                        support_environment_upgrades=False):
        env_obj = environments_api_util.Get(env_ref,
                                            release_track=self.ReleaseTrack())
        is_composer_v1 = image_versions_command_util.IsImageVersionStringComposerV1(
            env_obj.config.softwareConfig.imageVersion)

        params = dict(
            is_composer_v1=is_composer_v1,
            env_ref=env_ref,
            node_count=args.node_count,
            update_pypi_packages_from_file=args.update_pypi_packages_from_file,
            clear_pypi_packages=args.clear_pypi_packages,
            remove_pypi_packages=args.remove_pypi_packages,
            update_pypi_packages=dict(
                command_util.SplitRequirementSpecifier(r)
                for r in args.update_pypi_package),
            clear_labels=args.clear_labels,
            remove_labels=args.remove_labels,
            update_labels=args.update_labels,
            clear_airflow_configs=args.clear_airflow_configs,
            remove_airflow_configs=args.remove_airflow_configs,
            update_airflow_configs=args.update_airflow_configs,
            clear_env_variables=args.clear_env_variables,
            remove_env_variables=args.remove_env_variables,
            update_env_variables=args.update_env_variables,
            release_track=self.ReleaseTrack())

        if support_environment_upgrades:
            params['update_image_version'] = args.image_version
        params['update_web_server_access_control'] = (
            environments_api_util.BuildWebServerAllowedIps(
                args.update_web_server_allow_ip, args.web_server_allow_all,
                args.web_server_deny_all))

        if (args.cloud_sql_machine_type and not is_composer_v1):
            raise command_util.InvalidUserInputError(
                _INVALID_OPTION_FOR_V2_ERROR_MSG.format(
                    opt='cloud-sql-machine-type'))
        if (args.web_server_machine_type and not is_composer_v1):
            raise command_util.InvalidUserInputError(
                _INVALID_OPTION_FOR_V2_ERROR_MSG.format(
                    opt='web-server-machine-type'))
        params['cloud_sql_machine_type'] = args.cloud_sql_machine_type
        params['web_server_machine_type'] = args.web_server_machine_type
        params['scheduler_count'] = args.scheduler_count

        if self._support_environment_size:
            if (args.environment_size and is_composer_v1):
                raise command_util.InvalidUserInputError(
                    _INVALID_OPTION_FOR_V1_ERROR_MSG.format(
                        opt='environment-size'))
            if self.ReleaseTrack() == base.ReleaseTrack.GA:
                params[
                    'environment_size'] = flags.ENVIRONMENT_SIZE_GA.GetEnumForChoice(
                        args.environment_size)
            elif self.ReleaseTrack() == base.ReleaseTrack.BETA:
                params[
                    'environment_size'] = flags.ENVIRONMENT_SIZE_BETA.GetEnumForChoice(
                        args.environment_size)
            elif self.ReleaseTrack() == base.ReleaseTrack.ALPHA:
                params[
                    'environment_size'] = flags.ENVIRONMENT_SIZE_ALPHA.GetEnumForChoice(
                        args.environment_size)
        if self._support_autoscaling:
            if (is_composer_v1 and
                (args.scheduler_cpu or args.worker_cpu or args.web_server_cpu
                 or args.scheduler_memory or args.worker_memory
                 or args.web_server_memory or args.scheduler_storage
                 or args.worker_storage or args.web_server_storage
                 or args.min_workers or args.max_workers)):
                raise command_util.InvalidUserInputError(
                    'Workloads Config flags introduced in Composer 2.X'
                    ' cannot be used when creating Composer 1.X environments.')
            params['scheduler_cpu'] = args.scheduler_cpu
            params['worker_cpu'] = args.worker_cpu
            params['web_server_cpu'] = args.web_server_cpu
            params[
                'scheduler_memory_gb'] = environments_api_util.MemorySizeBytesToGB(
                    args.scheduler_memory)
            params[
                'worker_memory_gb'] = environments_api_util.MemorySizeBytesToGB(
                    args.worker_memory)
            params[
                'web_server_memory_gb'] = environments_api_util.MemorySizeBytesToGB(
                    args.web_server_memory)
            params[
                'scheduler_storage_gb'] = environments_api_util.MemorySizeBytesToGB(
                    args.scheduler_storage)
            params[
                'worker_storage_gb'] = environments_api_util.MemorySizeBytesToGB(
                    args.worker_storage)
            params[
                'web_server_storage_gb'] = environments_api_util.MemorySizeBytesToGB(
                    args.web_server_storage)
            params['min_workers'] = args.min_workers
            params['max_workers'] = args.max_workers
        if self._support_maintenance_window:
            params['maintenance_window_start'] = args.maintenance_window_start
            params['maintenance_window_end'] = args.maintenance_window_end
            params[
                'maintenance_window_recurrence'] = args.maintenance_window_recurrence
        if self.ReleaseTrack() != base.ReleaseTrack.GA:
            if args.enable_master_authorized_networks and args.disable_master_authorized_networks:
                raise command_util.InvalidUserInputError(
                    'Cannot specify --enable-master-authorized-networks with --disable-master-authorized-networks'
                )
            if args.disable_master_authorized_networks and args.master_authorized_networks:
                raise command_util.InvalidUserInputError(
                    'Cannot specify --disable-master-authorized-networks with --master-authorized-networks'
                )
            if args.enable_master_authorized_networks is None and args.master_authorized_networks:
                raise command_util.InvalidUserInputError(
                    'Cannot specify --master-authorized-networks without --enable-master-authorized-networks'
                )
            if args.enable_master_authorized_networks or args.disable_master_authorized_networks:
                params[
                    'master_authorized_networks_enabled'] = True if args.enable_master_authorized_networks else False
            command_util.ValidateMasterAuthorizedNetworks(
                args.master_authorized_networks)
            params[
                'master_authorized_networks'] = args.master_authorized_networks
        return patch_util.ConstructPatch(**params)