Exemplo n.º 1
0
    def Run(self, args):
        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        guest_policy_name = ''
        if args.organization:
            guest_policy_name = osconfig_command_utils.GetGuestPolicyUriPath(
                'organizations', args.organization, args.POLICY_ID)
            request = messages.OsconfigOrganizationsGuestPoliciesDeleteRequest(
                name=guest_policy_name)
            service = client.organizations_guestPolicies
        elif args.folder:
            guest_policy_name = osconfig_command_utils.GetGuestPolicyUriPath(
                'folders', args.folder, args.POLICY_ID)
            request = messages.OsconfigFoldersGuestPoliciesDeleteRequest(
                name=guest_policy_name)
            service = client.folders_guestPolicies
        else:
            project = properties.VALUES.core.project.GetOrFail()
            guest_policy_name = osconfig_command_utils.GetGuestPolicyUriPath(
                'projects', project, args.POLICY_ID)
            request = messages.OsconfigProjectsGuestPoliciesDeleteRequest(
                name=guest_policy_name)
            service = client.projects_guestPolicies

        response = service.Delete(request)
        log.DeletedResource(guest_policy_name)
        return response
Exemplo n.º 2
0
  def Run(self, args):
    project = properties.VALUES.core.project.GetOrFail()

    release_track = self.ReleaseTrack()
    client = osconfig_api_utils.GetClientInstance(release_track)
    messages = osconfig_api_utils.GetClientMessages(release_track)

    duration = _GetDuration(args)
    patch_config = _CreatePatchConfig(args, messages)
    patch_rollout = _CreatePatchRollout(args, messages)

    request = _CreateExecuteRequest(
        messages,
        project,
        args.description,
        args.dry_run,
        duration,
        patch_config,
        patch_rollout,
        args.display_name,
        args.instance_filter_all,
        args.instance_filter_group_labels
        if args.instance_filter_group_labels else [],
        args.instance_filter_zones if args.instance_filter_zones else [],
        args.instance_filter_names if args.instance_filter_names else [],
        args.instance_filter_name_prefixes
        if args.instance_filter_name_prefixes else [],
    )
    return _CreateExecuteResponse(client, messages, request, args.async_,
                                  self._command_prefix)
    def Run(self, args):
        """See base class."""

        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(
            release_track, api_version_override='v1beta')
        messages = osconfig_api_utils.GetClientMessages(
            release_track, api_version_override='v1beta')
        ops_agents_policy = agent_policy.CreateOpsAgentPolicy(
            args.description, args.agent_rules, args.group_labels,
            args.os_types, args.zones, args.instances)
        validator.ValidateOpsAgentsPolicy(ops_agents_policy)
        guest_policy = to_guest_policy.ConvertOpsAgentPolicyToGuestPolicy(
            messages, ops_agents_policy)
        project = properties.VALUES.core.project.GetOrFail()
        parent_path = osconfig_command_utils.GetProjectUriPath(project)
        request = messages.OsconfigProjectsGuestPoliciesCreateRequest(
            guestPolicy=guest_policy,
            guestPolicyId=args.POLICY_ID,
            parent=parent_path,
        )
        service = client.projects_guestPolicies
        complete_guest_policy = service.Create(request)
        ops_agents_policy = to_ops_agents.ConvertGuestPolicyToOpsAgentPolicy(
            complete_guest_policy)
        return ops_agents_policy
Exemplo n.º 4
0
  def Run(self, args):
    release_track = self.ReleaseTrack()
    client = osconfig_api_utils.GetClientInstance(release_track)
    messages = osconfig_api_utils.GetClientMessages(release_track)

    if args.organization:
      request = messages.OsconfigOrganizationsGuestPoliciesListRequest(
          pageSize=args.page_size,
          parent=osconfig_command_utils.GetOrganizationUriPath(
              args.organization),
      )
      service = client.organizations_guestPolicies
    elif args.folder:
      request = messages.OsconfigFoldersGuestPoliciesListRequest(
          pageSize=args.page_size,
          parent=osconfig_command_utils.GetFolderUriPath(args.folder),
      )
      service = client.folders_guestPolicies
    else:
      project = properties.VALUES.core.project.GetOrFail()
      request = messages.OsconfigProjectsGuestPoliciesListRequest(
          pageSize=args.page_size,
          parent=osconfig_command_utils.GetProjectUriPath(project),
      )
      service = client.projects_guestPolicies

    return list_pager.YieldFromList(
        service,
        request,
        limit=args.limit,
        batch_size=args.page_size,
        field='guestPolicies',
        batch_size_attribute='pageSize',
    )
Exemplo n.º 5
0
  def Run(self, args):
    """See base class."""
    release_track = self.ReleaseTrack()

    project = properties.VALUES.core.project.GetOrFail()
    guest_policy_uri_path = osconfig_command_utils.GetGuestPolicyUriPath(
        'projects', project, args.POLICY_ID)
    client = osconfig_api_utils.GetClientInstance(
        release_track, api_version_override='v1beta')
    service = client.projects_guestPolicies
    messages = osconfig_api_utils.GetClientMessages(
        release_track, api_version_override='v1beta')

    get_request = messages.OsconfigProjectsGuestPoliciesGetRequest(
        name=guest_policy_uri_path)
    try:
      get_response = service.Get(get_request)
    except apitools_exceptions.HttpNotFoundError:
      raise ops_agents_exceptions.PolicyNotFoundError(
          policy_id=args.POLICY_ID)
    if not guest_policy_validator.IsOpsAgentPolicy(get_response):
      raise ops_agents_exceptions.PolicyNotFoundError(
          policy_id=args.POLICY_ID)
    try:
      ops_agents_policy = to_ops_agents.ConvertGuestPolicyToOpsAgentPolicy(
          get_response)
    except calliope_exceptions.BadArgumentException:
      raise ops_agents_exceptions.PolicyMalformedError(
          policy_id=args.POLICY_ID)
    return ops_agents_policy
Exemplo n.º 6
0
    def Run(self, args):
        """See base class."""
        release_track = self.ReleaseTrack()

        holder = base_classes.ComputeApiHolder(release_track)
        instance_ref = self._GetInstanceRef(holder, args)

        guest_attributes = self._GetGuestInventoryGuestAttributes(instance_ref)
        os_info = self._GetOsInfo(guest_attributes)
        os_architecture = os_info.get(self._OS_ARCHITECTURE_KEY)
        os_shortname = os_info.get(self._OS_SHORTNAME_KEY)
        os_version = os_info.get(self._OS_VERSION_KEY)

        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        request = self._CreateRequest(messages, instance_ref.RelativeName(),
                                      os_architecture, os_shortname,
                                      os_version)
        response = self._GetResponse(client.projects_zones_instances, request)

        if not any([
                response.packages, response.packageRepositories,
                response.softwareRecipes
        ]):
            log.status.Print(
                'No effective guest policy found for [{}].'.format(
                    instance_ref.RelativeName()))

        return response
Exemplo n.º 7
0
  def Run(self, args):
    """See base class."""
    release_track = self.ReleaseTrack()
    client = osconfig_api_utils.GetClientInstance(
        release_track, api_version_override='v1beta')
    messages = osconfig_api_utils.GetClientMessages(
        release_track, api_version_override='v1beta')
    project = properties.VALUES.core.project.GetOrFail()
    guest_policy_uri_path = osconfig_command_utils.GetGuestPolicyUriPath(
        'projects', project, args.POLICY_ID)
    service = client.projects_guestPolicies

    get_request = messages.OsconfigProjectsGuestPoliciesGetRequest(
        name=guest_policy_uri_path)
    try:
      get_response = service.Get(get_request)
    except apitools_exceptions.HttpNotFoundError:
      raise ops_agents_exceptions.PolicyNotFoundError(
          policy_id=args.POLICY_ID)
    if not guest_policy_validator.IsOpsAgentPolicy(get_response):
      raise ops_agents_exceptions.PolicyNotFoundError(
          policy_id=args.POLICY_ID)

    delete_request = messages.OsconfigProjectsGuestPoliciesDeleteRequest(
        name=guest_policy_uri_path)
    delete_response = service.Delete(delete_request)

    log.DeletedResource(args.POLICY_ID)
    return delete_response
Exemplo n.º 8
0
    def Run(self, args):
        patch_job_ref = args.CONCEPTS.patch_job.Parse()

        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        request = messages.OsconfigProjectsPatchJobsGetRequest(
            name=patch_job_ref.RelativeName())
        return client.projects_patchJobs.Get(request)
Exemplo n.º 9
0
  def Run(self, args):
    project = properties.VALUES.core.project.GetOrFail()
    patch_job_ref = args.CONCEPTS.patch_job.Parse()

    release_track = self.ReleaseTrack()
    client = osconfig_api_utils.GetClientInstance(release_track)
    messages = osconfig_api_utils.GetClientMessages(release_track)

    request = messages.OsconfigProjectsPatchJobsGetRequest(
        name=osconfig_command_utils.GetPatchJobUriPath(project,
                                                       patch_job_ref.Name()))
    return client.projects_patchJobs.Get(request)
Exemplo n.º 10
0
    def Run(self, args):
        """See base class."""
        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        project = properties.VALUES.core.project.GetOrFail()
        request = messages.OsconfigProjectsGuestPoliciesGetRequest(
            name=osconfig_command_utils.GetGuestPolicyUriPath(
                'projects', project, args.POLICY_ID))
        service = client.projects_guestPolicies

        return service.Get(request)
Exemplo n.º 11
0
 def SetUp(self):
   self.messages = osconfig_api_utils.GetClientMessages(
       None, api_version_override='v1beta')
   self.expected_ops_agents_policy = agent_policy.OpsAgentPolicy(
       assignment=AGENT_RULE_ASSIGNMENT,
       agent_rules=OPS_AGENT_POLICY_AGENT_RULES,
       description=OPS_AGENT_DESCRIPTION,
       etag=ETAG,
       name=POLICY_NAME,
       update_time=UPDATE_TIME,
       create_time=CREATE_TIME)
   self.guest_policy = self._LoadMessage(
       GUEST_POLICY_YAML, self.messages.GuestPolicy)
    def Run(self, args):
        patch_deployment_ref = args.CONCEPTS.patch_deployment.Parse()
        patch_deployment_name = patch_deployment_ref.RelativeName()

        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        request = messages.OsconfigProjectsPatchDeploymentsResumeRequest(
            name=patch_deployment_name)

        response = client.projects_patchDeployments.Resume(request)
        return response
Exemplo n.º 13
0
    def Run(self, args):
        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        update_fields = []
        if args.file:
            (guest_policy,
             _) = osconfig_command_utils.GetResourceAndUpdateFieldsFromFile(
                 args.file, messages.GuestPolicy)
        else:
            guest_policy = messages.GuestPolicy()

        if args.description:
            guest_policy.description = args.description
            if not args.file:
                update_fields.append('description')
        if args.etag:
            guest_policy.etag = args.etag
            if not args.file:
                update_fields.append('etag')
        update_mask = (','.join(sorted(list(update_fields)))
                       if update_fields else None)

        if args.organization:
            request = messages.OsconfigOrganizationsGuestPoliciesPatchRequest(
                guestPolicy=guest_policy,
                name=osconfig_command_utils.GetGuestPolicyUriPath(
                    'organizations', args.organization, args.POLICY_ID),
                updateMask=update_mask,
            )
            service = client.organizations_guestPolicies
        elif args.folder:
            request = messages.OsconfigFoldersGuestPoliciesPatchRequest(
                guestPolicy=guest_policy,
                name=osconfig_command_utils.GetGuestPolicyUriPath(
                    'folders', args.folder, args.POLICY_ID),
                updateMask=update_mask,
            )
            service = client.folders_guestPolicies
        else:
            project = properties.VALUES.core.project.GetOrFail()
            request = messages.OsconfigProjectsGuestPoliciesPatchRequest(
                guestPolicy=guest_policy,
                name=osconfig_command_utils.GetGuestPolicyUriPath(
                    'projects', project, args.POLICY_ID),
                updateMask=update_mask,
            )
            service = client.projects_guestPolicies

        return service.Patch(request)
Exemplo n.º 14
0
    def Run(self, args):
        project = properties.VALUES.core.project.GetOrFail()
        patch_deployment_ref = args.CONCEPTS.patch_deployment.Parse()
        patch_deployment_name = osconfig_command_utils.GetPatchDeploymentUriPath(
            project, patch_deployment_ref.Name())

        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        request = messages.OsconfigProjectsPatchDeploymentsDeleteRequest(
            name=patch_deployment_name)

        response = client.projects_patchDeployments.Delete(request)
        log.DeletedResource(patch_deployment_name)
        return response
Exemplo n.º 15
0
    def Run(self, args):
        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        (patch_deployment,
         _) = osconfig_command_utils.GetResourceAndUpdateFieldsFromFile(
             args.file, messages.PatchDeployment)

        project = properties.VALUES.core.project.GetOrFail()
        parent_path = osconfig_command_utils.GetProjectUriPath(project)
        request = messages.OsconfigProjectsPatchDeploymentsCreateRequest(
            patchDeployment=patch_deployment,
            patchDeploymentId=args.PATCH_DEPLOYMENT_ID,
            parent=parent_path,
        )

        return client.projects_patchDeployments.Create(request)
Exemplo n.º 16
0
  def Run(self, args):
    """See base class."""
    release_track = self.ReleaseTrack()
    client = osconfig_api_utils.GetClientInstance(
        release_track, api_version_override='v1beta')
    messages = osconfig_api_utils.GetClientMessages(
        release_track, api_version_override='v1beta')

    project = properties.VALUES.core.project.GetOrFail()
    request = messages.OsconfigProjectsGuestPoliciesListRequest(
        pageSize=args.page_size,
        parent=osconfig_command_utils.GetProjectUriPath(project),
    )
    service = client.projects_guestPolicies

    for guest_policy in list_pager.YieldFromList(
        service,
        request,
        limit=args.limit,
        predicate=guest_policy_validator.IsOpsAgentPolicy,
        batch_size=osconfig_command_utils.GetListBatchSize(args),
        field='guestPolicies',
        batch_size_attribute='pageSize',
    ):
      try:
        yield converter.ConvertGuestPolicyToOpsAgentPolicy(guest_policy)
      except exceptions.BadArgumentException:
        log.warning(
            'Encountered a malformed policy. The Ops Agents policy [%s] may '
            'have been modified directly by the OS Config guest policy API / '
            'gcloud commands. If so, please delete and re-create with the Ops '
            'Agents policy gcloud commands. If not, this may be an internal '
            'error.',
            guest_policy.name,
        )
        yield agent_policy.OpsAgentPolicy(
            assignment=None,
            agent_rules=None,
            description='<MALFORMED>',
            etag=None,
            name=guest_policy.name,
            update_time=guest_policy.updateTime,
            create_time=guest_policy.createTime
        )
Exemplo n.º 17
0
    def Run(self, args):
        patch_job_ref = args.CONCEPTS.patch_job.Parse()

        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        request = messages.OsconfigProjectsPatchJobsInstanceDetailsListRequest(
            pageSize=args.page_size, parent=patch_job_ref.RelativeName())

        results = list(
            list_pager.YieldFromList(client.projects_patchJobs_instanceDetails,
                                     request,
                                     limit=args.limit,
                                     batch_size=args.page_size,
                                     field='patchJobInstanceDetails',
                                     batch_size_attribute='pageSize'), )

        return _PostProcessListResult(results)
Exemplo n.º 18
0
  def Run(self, args):
    project = properties.VALUES.core.project.GetOrFail()

    release_track = self.ReleaseTrack()
    client = osconfig_api_utils.GetClientInstance(release_track)
    messages = osconfig_api_utils.GetClientMessages(release_track)

    request = messages.OsconfigProjectsPatchJobsListRequest(
        pageSize=args.page_size,
        parent=osconfig_command_utils.GetProjectUriPath(project))

    return list_pager.YieldFromList(
        client.projects_patchJobs,
        request,
        limit=args.limit,
        batch_size=args.page_size,
        field='patchJobs',
        batch_size_attribute='pageSize',
    )
    def Run(self, args):
        """See base class."""
        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        (patch_deployment,
         _) = osconfig_command_utils.GetResourceAndUpdateFieldsFromFile(
             args.file, messages.PatchDeployment)

        project = properties.VALUES.core.project.GetOrFail()
        request = messages.OsconfigProjectsPatchDeploymentsPatchRequest(
            patchDeployment=patch_deployment,
            name=osconfig_command_utils.GetPatchDeploymentUriPath(
                project, args.PATCH_DEPLOYMENT_ID),
            updateMask=None,
        )
        service = client.projects_patchDeployments

        return service.Patch(request)
Exemplo n.º 20
0
  def Run(self, args):
    """See base class."""
    release_track = self.ReleaseTrack()
    client = osconfig_api_utils.GetClientInstance(release_track)
    messages = osconfig_api_utils.GetClientMessages(release_track)

    (guest_policy,
     _) = osconfig_command_utils.GetResourceAndUpdateFieldsFromFile(
         args.file, messages.GuestPolicy)

    project = properties.VALUES.core.project.GetOrFail()
    request = messages.OsconfigProjectsGuestPoliciesPatchRequest(
        guestPolicy=guest_policy,
        name=osconfig_command_utils.GetGuestPolicyUriPath(
            'projects', project, args.POLICY_ID),
        updateMask=None,
    )
    service = client.projects_guestPolicies

    return service.Patch(request)
Exemplo n.º 21
0
  def Run(self, args):
    """See base class."""

    release_track = self.ReleaseTrack()
    client = osconfig_api_utils.GetClientInstance(release_track)
    messages = osconfig_api_utils.GetClientMessages(release_track)

    (guest_policy,
     _) = osconfig_command_utils.GetResourceAndUpdateFieldsFromFile(
         args.file, messages.GuestPolicy)

    project = properties.VALUES.core.project.GetOrFail()
    parent_path = osconfig_command_utils.GetProjectUriPath(project)
    request = messages.OsconfigProjectsGuestPoliciesCreateRequest(
        guestPolicy=guest_policy,
        guestPolicyId=args.POLICY_ID,
        parent=parent_path,
    )
    service = client.projects_guestPolicies

    return service.Create(request)
Exemplo n.º 22
0
    def Run(self, args):
        """See base class."""
        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(release_track)
        messages = osconfig_api_utils.GetClientMessages(release_track)

        project = properties.VALUES.core.project.GetOrFail()
        request = messages.OsconfigProjectsGuestPoliciesListRequest(
            pageSize=args.page_size,
            parent=osconfig_command_utils.GetProjectUriPath(project),
        )
        service = client.projects_guestPolicies

        return list_pager.YieldFromList(
            service,
            request,
            limit=args.limit,
            batch_size=osconfig_command_utils.GetListBatchSize(args),
            field='guestPolicies',
            batch_size_attribute='pageSize',
        )
Exemplo n.º 23
0
  def Run(self, args):
    release_track = self.ReleaseTrack()
    client = osconfig_api_utils.GetClientInstance(release_track)
    messages = osconfig_api_utils.GetClientMessages(release_track)

    (guest_policy,
     _) = osconfig_command_utils.GetResourceAndUpdateFieldsFromFile(
         args.file, messages.GuestPolicy)

    if args.organization:
      parent_path = osconfig_command_utils.GetOrganizationUriPath(
          args.organization)
      request = messages.OsconfigOrganizationsGuestPoliciesCreateRequest(
          guestPolicy=guest_policy,
          guestPolicyId=args.POLICY_ID,
          parent=parent_path,
      )
      service = client.organizations_guestPolicies
    elif args.folder:
      parent_path = osconfig_command_utils.GetFolderUriPath(args.folder)
      request = messages.OsconfigFoldersGuestPoliciesCreateRequest(
          guestPolicy=guest_policy,
          guestPolicyId=args.POLICY_ID,
          parent=parent_path,
      )
      service = client.folders_guestPolicies
    else:
      project = properties.VALUES.core.project.GetOrFail()
      parent_path = osconfig_command_utils.GetProjectUriPath(project)
      request = messages.OsconfigProjectsGuestPoliciesCreateRequest(
          guestPolicy=guest_policy,
          guestPolicyId=args.POLICY_ID,
          parent=parent_path,
      )
      service = client.projects_guestPolicies

    return service.Create(request)
Exemplo n.º 24
0
    def Run(self, args):
        """See base class."""
        release_track = self.ReleaseTrack()
        client = osconfig_api_utils.GetClientInstance(
            release_track, api_version_override='v1beta')
        messages = osconfig_api_utils.GetClientMessages(
            release_track, api_version_override='v1beta')

        project = properties.VALUES.core.project.GetOrFail()
        request = messages.OsconfigProjectsGuestPoliciesGetRequest(
            name=osconfig_command_utils.GetGuestPolicyUriPath(
                'projects', project, args.POLICY_ID))
        service = client.projects_guestPolicies
        current_guest_policy = service.Get(request)
        current_ops_agents_policy = guest_policy_to_ops_agents_policy_converter.ConvertGuestPolicyToOpsAgentPolicy(
            current_guest_policy)
        updated_ops_agents_policy = ops_agents_policy.UpdateOpsAgentsPolicy(
            current_ops_agents_policy, args.description, args.etag,
            args.agent_rules, args.os_types,
            [] if args.clear_group_labels else args.group_labels,
            [] if args.clear_zones else args.zones,
            [] if args.clear_instances else args.instances)
        ops_agents_policy_validator.ValidateOpsAgentsPolicy(
            updated_ops_agents_policy)
        updated_os_config_policy = ops_agents_policy_to_guest_policy_converter.ConvertOpsAgentPolicyToGuestPolicy(
            messages, updated_ops_agents_policy, current_guest_policy.recipes)
        request = messages.OsconfigProjectsGuestPoliciesPatchRequest(
            guestPolicy=updated_os_config_policy,
            name=osconfig_command_utils.GetGuestPolicyUriPath(
                'projects', project, args.POLICY_ID),
            updateMask=None,
        )
        complete_os_config_policy = service.Patch(request)
        complete_ops_agent_policy = guest_policy_to_ops_agents_policy_converter.ConvertGuestPolicyToOpsAgentPolicy(
            complete_os_config_policy)
        return complete_ops_agent_policy
Exemplo n.º 25
0
 def SetUp(self):
     self.maxDiff = None  # pylint: disable=invalid-name
     self.messages = osconfig_api_utils.GetClientMessages(
         None, api_version_override='v1beta')
Exemplo n.º 26
0
 def SetUp(self):
   self.messages = osconfig_api_utils.GetClientMessages(
       None, api_version_override='v1beta')
Exemplo n.º 27
0
  def Run(self, args):
    project = properties.VALUES.core.project.GetOrFail()

    release_track = self.ReleaseTrack()
    client = osconfig_api_utils.GetClientInstance(release_track)
    messages = osconfig_api_utils.GetClientMessages(release_track)

    duration = six.text_type(args.duration) + 's' if args.duration else None
    filter_arg = 'id=*' if not args.instance_filter else args.instance_filter
    reboot_config = getattr(
        messages.PatchConfig.RebootConfigValueValuesEnum,
        args.reboot_config.upper()) if args.reboot_config else None
    retry_strategy = messages.RetryStrategy(
        enabled=True) if args.retry else None
    patch_config = messages.PatchConfig(
        rebootConfig=reboot_config,
        retryStrategy=retry_strategy,
        apt=_GetAptSettings(args, messages),
        windowsUpdate=_GetWindowsUpdateSettings(args, messages),
        yum=_GetYumSettings(args, messages),
        zypper=_GetZypperSettings(args, messages),
        preStep=_GetPrePostPatchStepSettings(
            args, messages, is_pre_patch_step=True),
        postStep=_GetPrePostPatchStepSettings(
            args, messages, is_pre_patch_step=False),
    )

    request = messages.OsconfigProjectsPatchJobsExecuteRequest(
        executePatchJobRequest=messages.ExecutePatchJobRequest(
            description=args.description,
            dryRun=args.dry_run,
            duration=duration,
            filter=filter_arg,
            patchConfig=patch_config,
        ),
        parent=osconfig_command_utils.GetProjectUriPath(project))
    async_response = client.projects_patchJobs.Execute(request)

    patch_job_name = osconfig_command_utils.GetPatchJobName(async_response.name)

    if args.async_:
      log.status.Print(
          'Execution in progress for patch job [{}]'.format(patch_job_name))
      log.status.Print(
          'Run the [{} describe] command to check the status of this execution.'
          .format(self._command_prefix))
      return async_response

    # Execute the patch job synchronously.
    patch_job_poller = osconfig_api_utils.Poller(client, messages)
    get_request = messages.OsconfigProjectsPatchJobsGetRequest(
        name=async_response.name)
    sync_response = waiter.WaitFor(
        patch_job_poller,
        get_request,
        custom_tracker=_GetProgressTracker(patch_job_name),
        tracker_update_func=_UpdateProgressTracker,
        pre_start_sleep_ms=5000,
        exponential_sleep_multiplier=1,  # Constant poll rate of 5s.
        sleep_ms=5000,
    )
    log.status.Print(
        'Execution for patch job [{}] has completed with status [{}].'.format(
            patch_job_name, sync_response.state))
    log.status.Print('Run the [{} list-instance-details] command to view any '
                     'instance failure reasons.'.format(self._command_prefix))
    return sync_response