コード例 #1
0
ファイル: import.py プロジェクト: saranraju90/multik8s
def _Run(args, holder, url_map_arg, release_track):
    """Issues requests necessary to import URL maps."""
    client = holder.client

    url_map_ref = url_map_arg.ResolveAsResource(
        args,
        holder.resources,
        default_scope=compute_scope.ScopeEnum.GLOBAL,
        scope_lister=compute_flags.GetDefaultScopeLister(client))

    data = console_io.ReadFromFileOrStdin(args.source or '-', binary=False)

    try:
        url_map = export_util.Import(message_type=client.messages.UrlMap,
                                     stream=data,
                                     schema_path=_GetSchemaPath(release_track))
    except yaml_validator.ValidationError as e:
        raise exceptions.ToolException(str(e))

    # Get existing URL map.
    try:
        url_map_old = url_maps_utils.SendGetRequest(client, url_map_ref)
    except apitools_exceptions.HttpError as error:
        if error.status_code != 404:
            raise error
        # Url Map does not exist, create a new one.
        return _SendInsertRequest(client, url_map_ref, url_map)

    # No change, do not send requests to server.
    if url_map_old == url_map:
        return

    console_io.PromptContinue(
        message=('Url Map [{0}] will be overwritten.').format(
            url_map_ref.Name()),
        cancel_on_no=True)

    # Populate id and fingerprint fields. These two fields are manually
    # removed from the schema files.
    url_map.id = url_map_old.id
    url_map.fingerprint = url_map_old.fingerprint

    return _SendPatchRequest(client, url_map_ref, url_map)
コード例 #2
0
ファイル: export.py プロジェクト: superina5/first_app
  def Run(self, args):
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client

    url_map_ref = self.URL_MAP_ARG.ResolveAsResource(
        args,
        holder.resources,
        scope_lister=compute_flags.GetDefaultScopeLister(client))

    url_map = url_maps_utils.SendGetRequest(client, url_map_ref)

    if args.destination:
      with files.FileWriter(args.destination) as stream:
        export_util.Export(message=url_map,
                           stream=stream,
                           schema_path=self.GetSchemaPath())
    else:
      export_util.Export(message=url_map,
                         stream=sys.stdout,
                         schema_path=self.GetSchemaPath())
コード例 #3
0
def _Run(args, holder, url_map_arg, release_track):
    """Issues requests necessary to export URL maps."""
    client = holder.client

    url_map_ref = url_map_arg.ResolveAsResource(
        args,
        holder.resources,
        scope_lister=compute_flags.GetDefaultScopeLister(client))

    url_map = url_maps_utils.SendGetRequest(client, url_map_ref)

    codecs.RegisterL7TrafficControlCodecs(_GetApiVersion(release_track))
    if args.destination:
        with files.FileWriter(args.destination) as stream:
            export_util.Export(message=url_map,
                               stream=stream,
                               schema_path=_GetSchemaPath(release_track))
    else:
        export_util.Export(message=url_map,
                           stream=sys.stdout,
                           schema_path=_GetSchemaPath(release_track))
コード例 #4
0
def _Run(args, holder, url_map_arg, release_track):
    """Issues requests necessary to import URL maps."""
    client = holder.client
    resources = holder.resources

    url_map_ref = url_map_arg.ResolveAsResource(
        args,
        resources,
        default_scope=compute_scope.ScopeEnum.GLOBAL,
        scope_lister=compute_flags.GetDefaultScopeLister(client))

    data = console_io.ReadFromFileOrStdin(args.source or '-', binary=False)

    try:
        url_map = export_util.Import(message_type=client.messages.UrlMap,
                                     stream=data,
                                     schema_path=_GetSchemaPath(release_track))
    except yaml_validator.ValidationError as e:
        raise compute_exceptions.ValidationError(str(e))

    if url_map.name != url_map_ref.Name():
        # Replace warning and raise error after 10/01/2021
        log.warning(
            'The name of the Url Map must match the value of the ' +
            '\'name\' attribute in the YAML file. Future versions of ' +
            'gcloud will fail with an error.')
    # Get existing URL map.
    try:
        url_map_old = url_maps_utils.SendGetRequest(client, url_map_ref)
    except apitools_exceptions.HttpError as error:
        if error.status_code != 404:
            raise error
        # Url Map does not exist, create a new one.
        return _SendInsertRequest(client, resources, url_map_ref, url_map)

    # No change, do not send requests to server.
    if url_map_old == url_map:
        return

    console_io.PromptContinue(
        message=('Url Map [{0}] will be overwritten.').format(
            url_map_ref.Name()),
        cancel_on_no=True)

    # Populate id and fingerprint fields when YAML files don't contain them.
    if not url_map.id:
        url_map.id = url_map_old.id
    if url_map.fingerprint:
        # Replace warning and raise error after 10/01/2021
        log.warning(
            'An up-to-date fingerprint must be provided to ' +
            'update the Url Map. Future versions of gcloud will fail ' +
            'with an error \'412 conditionNotMet\'')
        url_map.fingerprint = url_map_old.fingerprint
    # Unspecified fields are assumed to be cleared.
    # TODO(b/182287403) Replace with proto reflection and update scenario tests.
    cleared_fields = []
    if not url_map.description:
        cleared_fields.append('description')
    if not url_map.hostRules:
        cleared_fields.append('hostRules')
    if not url_map.pathMatchers:
        cleared_fields.append('pathMatchers')
    if not url_map.tests:
        cleared_fields.append('tests')
    if not url_map.defaultService:
        cleared_fields.append('defaultService')
    if not url_map.defaultRouteAction:
        cleared_fields.append('defaultRouteAction')
    else:
        cleared_fields = cleared_fields + _GetClearedFieldsForRoutAction(
            url_map.defaultRouteAction, 'defaultRouteAction.')
    if not url_map.defaultUrlRedirect:
        cleared_fields.append('defaultUrlRedirect')
    else:
        cleared_fields = cleared_fields + _GetClearedFieldsForUrlRedirect(
            url_map.defaultUrlRedirect, 'defaultUrlRedirect.')
    if not url_map.headerAction:
        cleared_fields.append('headerAction')
    else:
        cleared_fields = cleared_fields + _GetClearedFieldsForHeaderAction(
            url_map.headerAction, 'headerAction.')

    with client.apitools_client.IncludeFields(cleared_fields):
        return _SendPatchRequest(client, resources, url_map_ref, url_map)